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