github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/rewarding/ethabi/totalbalance.go (about) 1 package ethabi 2 3 import ( 4 "encoding/hex" 5 "math/big" 6 7 "github.com/ethereum/go-ethereum/accounts/abi" 8 "github.com/iotexproject/iotex-proto/golang/iotexapi" 9 proto "github.com/iotexproject/iotex-proto/golang/protocol" 10 11 "github.com/iotexproject/iotex-core/action/protocol" 12 "github.com/iotexproject/iotex-core/action/protocol/abiutil" 13 ) 14 15 const _totalBalanceInterfaceABI = `[ 16 { 17 "inputs": [], 18 "name": "totalBalance", 19 "outputs": [ 20 { 21 "internalType": "uint256", 22 "name": "", 23 "type": "uint256" 24 } 25 ], 26 "stateMutability": "view", 27 "type": "function" 28 } 29 ]` 30 31 var _totalBalanceMethod abi.Method 32 33 func init() { 34 _totalBalanceMethod = abiutil.MustLoadMethod(_totalBalanceInterfaceABI, "totalBalance") 35 } 36 37 // TotalBalanceStateContext context for TotalBalance 38 type TotalBalanceStateContext struct { 39 *protocol.BaseStateContext 40 } 41 42 func newTotalBalanceStateContext() (*TotalBalanceStateContext, error) { 43 return &TotalBalanceStateContext{ 44 &protocol.BaseStateContext{ 45 Parameter: &protocol.Parameters{ 46 MethodName: []byte(proto.ReadTotalBalanceMethodName), 47 Arguments: nil, 48 }, 49 }, 50 }, nil 51 } 52 53 // EncodeToEth encode proto to eth 54 func (r *TotalBalanceStateContext) EncodeToEth(resp *iotexapi.ReadStateResponse) (string, error) { 55 total, ok := new(big.Int).SetString(string(resp.Data), 10) 56 if !ok { 57 return "", errConvertBigNumber 58 } 59 60 data, err := _totalBalanceMethod.Outputs.Pack(total) 61 if err != nil { 62 return "", nil 63 } 64 65 return hex.EncodeToString(data), nil 66 }