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