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