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