github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stake_composite_bucketsbyvoter.go (about) 1 package ethabi 2 3 import ( 4 "github.com/ethereum/go-ethereum/accounts/abi" 5 "github.com/ethereum/go-ethereum/common" 6 "google.golang.org/protobuf/proto" 7 8 "github.com/iotexproject/iotex-address/address" 9 "github.com/iotexproject/iotex-proto/golang/iotexapi" 10 "github.com/iotexproject/iotex-proto/golang/iotextypes" 11 12 "github.com/iotexproject/iotex-core/action/protocol" 13 "github.com/iotexproject/iotex-core/action/protocol/abiutil" 14 ) 15 16 var _compositeBucketsByVoterInterfaceABI = `[ 17 { 18 "inputs": [ 19 { 20 "internalType": "address", 21 "name": "voter", 22 "type": "address" 23 }, 24 { 25 "internalType": "uint32", 26 "name": "offset", 27 "type": "uint32" 28 }, 29 { 30 "internalType": "uint32", 31 "name": "limit", 32 "type": "uint32" 33 } 34 ], 35 "name": "compositeBucketsByVoter", 36 "outputs": [ 37 { 38 "components": [ 39 { 40 "internalType": "uint64", 41 "name": "index", 42 "type": "uint64" 43 }, 44 { 45 "internalType": "address", 46 "name": "candidateAddress", 47 "type": "address" 48 }, 49 { 50 "internalType": "uint256", 51 "name": "stakedAmount", 52 "type": "uint256" 53 }, 54 { 55 "internalType": "uint32", 56 "name": "stakedDuration", 57 "type": "uint32" 58 }, 59 { 60 "internalType": "int64", 61 "name": "createTime", 62 "type": "int64" 63 }, 64 { 65 "internalType": "int64", 66 "name": "stakeStartTime", 67 "type": "int64" 68 }, 69 { 70 "internalType": "int64", 71 "name": "unstakeStartTime", 72 "type": "int64" 73 }, 74 { 75 "internalType": "bool", 76 "name": "autoStake", 77 "type": "bool" 78 }, 79 { 80 "internalType": "address", 81 "name": "owner", 82 "type": "address" 83 }, 84 { 85 "internalType": "address", 86 "name": "contractAddress", 87 "type": "address" 88 }, 89 { 90 "internalType": "uint64", 91 "name": "stakedDurationBlockNumber", 92 "type": "uint64" 93 }, 94 { 95 "internalType": "uint64", 96 "name": "createBlockHeight", 97 "type": "uint64" 98 }, 99 { 100 "internalType": "uint64", 101 "name": "stakeStartBlockHeight", 102 "type": "uint64" 103 }, 104 { 105 "internalType": "uint64", 106 "name": "unstakeStartBlockHeight", 107 "type": "uint64" 108 } 109 ], 110 "internalType": "struct IStaking.CompositeVoteBucket[]", 111 "name": "", 112 "type": "tuple[]" 113 } 114 ], 115 "stateMutability": "view", 116 "type": "function" 117 } 118 ]` 119 120 var _compositeBucketsByVoterMethod abi.Method 121 122 func init() { 123 _compositeBucketsByVoterMethod = abiutil.MustLoadMethod(_compositeBucketsByVoterInterfaceABI, "compositeBucketsByVoter") 124 } 125 126 // CompositeBucketsByVoterStateContext context for BucketsByVoter 127 type CompositeBucketsByVoterStateContext struct { 128 *protocol.BaseStateContext 129 } 130 131 func newCompositeBucketsByVoterStateContext(data []byte) (*CompositeBucketsByVoterStateContext, error) { 132 paramsMap := map[string]interface{}{} 133 ok := false 134 if err := _compositeBucketsByVoterMethod.Inputs.UnpackIntoMap(paramsMap, data); err != nil { 135 return nil, err 136 } 137 var voter common.Address 138 if voter, ok = paramsMap["voter"].(common.Address); !ok { 139 return nil, errDecodeFailure 140 } 141 voterAddress, err := address.FromBytes(voter[:]) 142 if err != nil { 143 return nil, err 144 } 145 var offset, limit uint32 146 if offset, ok = paramsMap["offset"].(uint32); !ok { 147 return nil, errDecodeFailure 148 } 149 if limit, ok = paramsMap["limit"].(uint32); !ok { 150 return nil, errDecodeFailure 151 } 152 153 method := &iotexapi.ReadStakingDataMethod{ 154 Method: iotexapi.ReadStakingDataMethod_COMPOSITE_BUCKETS_BY_VOTER, 155 } 156 methodBytes, err := proto.Marshal(method) 157 if err != nil { 158 return nil, err 159 } 160 arguments := &iotexapi.ReadStakingDataRequest{ 161 Request: &iotexapi.ReadStakingDataRequest_BucketsByVoter{ 162 BucketsByVoter: &iotexapi.ReadStakingDataRequest_VoteBucketsByVoter{ 163 VoterAddress: voterAddress.String(), 164 Pagination: &iotexapi.PaginationParam{ 165 Offset: offset, 166 Limit: limit, 167 }, 168 }, 169 }, 170 } 171 argumentsBytes, err := proto.Marshal(arguments) 172 if err != nil { 173 return nil, err 174 } 175 return &CompositeBucketsByVoterStateContext{ 176 &protocol.BaseStateContext{ 177 Parameter: &protocol.Parameters{ 178 MethodName: methodBytes, 179 Arguments: [][]byte{argumentsBytes}, 180 }, 181 }, 182 }, nil 183 } 184 185 // EncodeToEth encode proto to eth 186 func (r *CompositeBucketsByVoterStateContext) EncodeToEth(resp *iotexapi.ReadStateResponse) (string, error) { 187 var result iotextypes.VoteBucketList 188 if err := proto.Unmarshal(resp.Data, &result); err != nil { 189 return "", err 190 } 191 192 return encodeVoteBucketListToEth(_compositeBucketsByVoterMethod.Outputs, &result) 193 }