github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stake_bucketsbyindexes.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 _bucketsByIndexesInterfaceABI = `[ 14 { 15 "inputs": [ 16 { 17 "internalType": "uint64[]", 18 "name": "indexes", 19 "type": "uint64[]" 20 } 21 ], 22 "name": "bucketsByIndexes", 23 "outputs": [ 24 { 25 "components": [ 26 { 27 "internalType": "uint64", 28 "name": "index", 29 "type": "uint64" 30 }, 31 { 32 "internalType": "address", 33 "name": "candidateAddress", 34 "type": "address" 35 }, 36 { 37 "internalType": "uint256", 38 "name": "stakedAmount", 39 "type": "uint256" 40 }, 41 { 42 "internalType": "uint32", 43 "name": "stakedDuration", 44 "type": "uint32" 45 }, 46 { 47 "internalType": "int64", 48 "name": "createTime", 49 "type": "int64" 50 }, 51 { 52 "internalType": "int64", 53 "name": "stakeStartTime", 54 "type": "int64" 55 }, 56 { 57 "internalType": "int64", 58 "name": "unstakeStartTime", 59 "type": "int64" 60 }, 61 { 62 "internalType": "bool", 63 "name": "autoStake", 64 "type": "bool" 65 }, 66 { 67 "internalType": "address", 68 "name": "owner", 69 "type": "address" 70 } 71 ], 72 "internalType": "struct IStaking.VoteBucket[]", 73 "name": "", 74 "type": "tuple[]" 75 } 76 ], 77 "stateMutability": "view", 78 "type": "function" 79 } 80 ]` 81 82 var _bucketsByIndexesMethod abi.Method 83 84 func init() { 85 _bucketsByIndexesMethod = abiutil.MustLoadMethod(_bucketsByIndexesInterfaceABI, "bucketsByIndexes") 86 } 87 88 // BucketsByIndexesStateContext context for BucketsByIndexes 89 type BucketsByIndexesStateContext struct { 90 *protocol.BaseStateContext 91 } 92 93 func newBucketsByIndexesStateContext(data []byte) (*BucketsByIndexesStateContext, error) { 94 paramsMap := map[string]interface{}{} 95 ok := false 96 if err := _bucketsByIndexesMethod.Inputs.UnpackIntoMap(paramsMap, data); err != nil { 97 return nil, err 98 } 99 var index []uint64 100 if index, ok = paramsMap["indexes"].([]uint64); !ok { 101 return nil, errDecodeFailure 102 } 103 104 method := &iotexapi.ReadStakingDataMethod{ 105 Method: iotexapi.ReadStakingDataMethod_BUCKETS_BY_INDEXES, 106 } 107 methodBytes, err := proto.Marshal(method) 108 if err != nil { 109 return nil, err 110 } 111 arguments := &iotexapi.ReadStakingDataRequest{ 112 Request: &iotexapi.ReadStakingDataRequest_BucketsByIndexes{ 113 BucketsByIndexes: &iotexapi.ReadStakingDataRequest_VoteBucketsByIndexes{ 114 Index: index, 115 }, 116 }, 117 } 118 argumentsBytes, err := proto.Marshal(arguments) 119 if err != nil { 120 return nil, err 121 } 122 return &BucketsByIndexesStateContext{ 123 &protocol.BaseStateContext{ 124 Parameter: &protocol.Parameters{ 125 MethodName: methodBytes, 126 Arguments: [][]byte{argumentsBytes}, 127 }, 128 }, 129 }, nil 130 } 131 132 // EncodeToEth encode proto to eth 133 func (r *BucketsByIndexesStateContext) EncodeToEth(resp *iotexapi.ReadStateResponse) (string, error) { 134 var result iotextypes.VoteBucketList 135 if err := proto.Unmarshal(resp.Data, &result); err != nil { 136 return "", err 137 } 138 139 return encodeVoteBucketListToEth(_bucketsByIndexesMethod.Outputs, &result) 140 }