refactor: staking

This commit is contained in:
MiniFrenchBread 2024-12-12 20:15:37 +08:00
parent ac57a9b4b4
commit e3c17a030a
13 changed files with 534 additions and 452 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
dasignerskeeper "github.com/0glabs/0g-chain/x/dasigners/v1/keeper" dasignerskeeper "github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
storetypes "github.com/cosmos/cosmos-sdk/store/types" storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
@ -109,7 +109,7 @@ func (d *DASignersPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly b
// get state db and context // get state db and context
stateDB, ok := evm.StateDB.(*statedb.StateDB) stateDB, ok := evm.StateDB.(*statedb.StateDB)
if !ok { if !ok {
return nil, fmt.Errorf(precopmiles_common.ErrGetStateDB) return nil, fmt.Errorf(precompiles_common.ErrGetStateDB)
} }
ctx := stateDB.GetContext() ctx := stateDB.GetContext()
// reset gas config // reset gas config

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -60,9 +60,9 @@ func (d *DASignersPrecompile) GetSigner(ctx sdk.Context, _ *vm.EVM, method *abi.
func (d *DASignersPrecompile) IsSigner(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { func (d *DASignersPrecompile) IsSigner(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
account := precopmiles_common.ToLowerHexWithoutPrefix(args[0].(common.Address)) account := precompiles_common.ToLowerHexWithoutPrefix(args[0].(common.Address))
_, found, err := d.dasignersKeeper.GetSigner(ctx, account) _, found, err := d.dasignersKeeper.GetSigner(ctx, account)
if err != nil { if err != nil {
return nil, err return nil, err
@ -72,9 +72,9 @@ func (d *DASignersPrecompile) IsSigner(ctx sdk.Context, _ *vm.EVM, method *abi.M
func (d *DASignersPrecompile) RegisteredEpoch(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { func (d *DASignersPrecompile) RegisteredEpoch(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
account := precopmiles_common.ToLowerHexWithoutPrefix(args[0].(common.Address)) account := precompiles_common.ToLowerHexWithoutPrefix(args[0].(common.Address))
epoch := args[1].(*big.Int).Uint64() epoch := args[1].(*big.Int).Uint64()
_, found, err := d.dasignersKeeper.GetRegistration(ctx, epoch, account) _, found, err := d.dasignersKeeper.GetRegistration(ctx, epoch, account)
if err != nil { if err != nil {

View File

@ -8,7 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/x/evm/statedb" "github.com/evmos/ethermint/x/evm/statedb"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
) )
func (d *DASignersPrecompile) RegisterSigner( func (d *DASignersPrecompile) RegisterSigner(
@ -24,12 +24,12 @@ func (d *DASignersPrecompile) RegisterSigner(
return nil, err return nil, err
} }
// validation // validation
sender := precopmiles_common.ToLowerHexWithoutPrefix(evm.Origin) sender := precompiles_common.ToLowerHexWithoutPrefix(evm.Origin)
if sender != msg.Signer.Account { if sender != msg.Signer.Account {
return nil, fmt.Errorf(ErrInvalidSender, sender, msg.Signer.Account) return nil, fmt.Errorf(ErrInvalidSender, sender, msg.Signer.Account)
} }
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
// execute // execute
_, err = d.dasignersKeeper.RegisterSigner(sdk.WrapSDKContext(ctx), msg) _, err = d.dasignersKeeper.RegisterSigner(sdk.WrapSDKContext(ctx), msg)
@ -52,13 +52,13 @@ func (d *DASignersPrecompile) RegisterNextEpoch(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgRegisterNextEpoch(args, precopmiles_common.ToLowerHexWithoutPrefix(evm.Origin)) msg, err := NewMsgRegisterNextEpoch(args, precompiles_common.ToLowerHexWithoutPrefix(evm.Origin))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
// execute // execute
_, err = d.dasignersKeeper.RegisterNextEpoch(sdk.WrapSDKContext(ctx), msg) _, err = d.dasignersKeeper.RegisterNextEpoch(sdk.WrapSDKContext(ctx), msg)
@ -76,13 +76,13 @@ func (d *DASignersPrecompile) UpdateSocket(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgUpdateSocket(args, precopmiles_common.ToLowerHexWithoutPrefix(evm.Origin)) msg, err := NewMsgUpdateSocket(args, precompiles_common.ToLowerHexWithoutPrefix(evm.Origin))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
// execute // execute
_, err = d.dasignersKeeper.UpdateSocket(sdk.WrapSDKContext(ctx), msg) _, err = d.dasignersKeeper.UpdateSocket(sdk.WrapSDKContext(ctx), msg)

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
dasignerstypes "github.com/0glabs/0g-chain/x/dasigners/v1/types" dasignerstypes "github.com/0glabs/0g-chain/x/dasigners/v1/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
@ -72,7 +72,7 @@ func SerializeG2(p BN254G2Point) []byte {
func NewQueryQuorumCountRequest(args []interface{}) (*dasignerstypes.QueryQuorumCountRequest, error) { func NewQueryQuorumCountRequest(args []interface{}) (*dasignerstypes.QueryQuorumCountRequest, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
return &dasignerstypes.QueryQuorumCountRequest{ return &dasignerstypes.QueryQuorumCountRequest{
@ -82,21 +82,21 @@ func NewQueryQuorumCountRequest(args []interface{}) (*dasignerstypes.QueryQuorum
func NewQuerySignerRequest(args []interface{}) (*dasignerstypes.QuerySignerRequest, error) { func NewQuerySignerRequest(args []interface{}) (*dasignerstypes.QuerySignerRequest, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
accounts := args[0].([]common.Address) accounts := args[0].([]common.Address)
req := dasignerstypes.QuerySignerRequest{ req := dasignerstypes.QuerySignerRequest{
Accounts: make([]string, len(accounts)), Accounts: make([]string, len(accounts)),
} }
for i, account := range accounts { for i, account := range accounts {
req.Accounts[i] = precopmiles_common.ToLowerHexWithoutPrefix(account) req.Accounts[i] = precompiles_common.ToLowerHexWithoutPrefix(account)
} }
return &req, nil return &req, nil
} }
func NewQueryEpochQuorumRequest(args []interface{}) (*dasignerstypes.QueryEpochQuorumRequest, error) { func NewQueryEpochQuorumRequest(args []interface{}) (*dasignerstypes.QueryEpochQuorumRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
return &dasignerstypes.QueryEpochQuorumRequest{ return &dasignerstypes.QueryEpochQuorumRequest{
@ -107,7 +107,7 @@ func NewQueryEpochQuorumRequest(args []interface{}) (*dasignerstypes.QueryEpochQ
func NewQueryEpochQuorumRowRequest(args []interface{}) (*dasignerstypes.QueryEpochQuorumRowRequest, error) { func NewQueryEpochQuorumRowRequest(args []interface{}) (*dasignerstypes.QueryEpochQuorumRowRequest, error) {
if len(args) != 3 { if len(args) != 3 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 3, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 3, len(args))
} }
return &dasignerstypes.QueryEpochQuorumRowRequest{ return &dasignerstypes.QueryEpochQuorumRowRequest{
@ -119,7 +119,7 @@ func NewQueryEpochQuorumRowRequest(args []interface{}) (*dasignerstypes.QueryEpo
func NewQueryAggregatePubkeyG1Request(args []interface{}) (*dasignerstypes.QueryAggregatePubkeyG1Request, error) { func NewQueryAggregatePubkeyG1Request(args []interface{}) (*dasignerstypes.QueryAggregatePubkeyG1Request, error) {
if len(args) != 3 { if len(args) != 3 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 3, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 3, len(args))
} }
return &dasignerstypes.QueryAggregatePubkeyG1Request{ return &dasignerstypes.QueryAggregatePubkeyG1Request{
@ -140,13 +140,13 @@ func NewIDASignersSignerDetail(signer *dasignerstypes.Signer) IDASignersSignerDe
func NewMsgRegisterSigner(args []interface{}) (*dasignerstypes.MsgRegisterSigner, error) { func NewMsgRegisterSigner(args []interface{}) (*dasignerstypes.MsgRegisterSigner, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
signer := args[0].(IDASignersSignerDetail) signer := args[0].(IDASignersSignerDetail)
return &dasignerstypes.MsgRegisterSigner{ return &dasignerstypes.MsgRegisterSigner{
Signer: &dasignerstypes.Signer{ Signer: &dasignerstypes.Signer{
Account: precopmiles_common.ToLowerHexWithoutPrefix(signer.Signer), Account: precompiles_common.ToLowerHexWithoutPrefix(signer.Signer),
Socket: signer.Socket, Socket: signer.Socket,
PubkeyG1: SerializeG1(signer.PkG1), PubkeyG1: SerializeG1(signer.PkG1),
PubkeyG2: SerializeG2(signer.PkG2), PubkeyG2: SerializeG2(signer.PkG2),
@ -157,7 +157,7 @@ func NewMsgRegisterSigner(args []interface{}) (*dasignerstypes.MsgRegisterSigner
func NewMsgRegisterNextEpoch(args []interface{}, account string) (*dasignerstypes.MsgRegisterNextEpoch, error) { func NewMsgRegisterNextEpoch(args []interface{}, account string) (*dasignerstypes.MsgRegisterNextEpoch, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
return &dasignerstypes.MsgRegisterNextEpoch{ return &dasignerstypes.MsgRegisterNextEpoch{
@ -168,7 +168,7 @@ func NewMsgRegisterNextEpoch(args []interface{}, account string) (*dasignerstype
func NewMsgUpdateSocket(args []interface{}, account string) (*dasignerstypes.MsgUpdateSocket, error) { func NewMsgUpdateSocket(args []interface{}, account string) (*dasignerstypes.MsgUpdateSocket, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
return &dasignerstypes.MsgUpdateSocket{ return &dasignerstypes.MsgUpdateSocket{

View File

@ -34,7 +34,7 @@ struct Commission {
* @dev Validator defines a validator. * @dev Validator defines a validator.
*/ */
struct Validator { struct Validator {
string operatorAddress; address operatorAddress;
string consensusPubkey; string consensusPubkey;
bool jailed; bool jailed;
BondStatus status; BondStatus status;
@ -53,8 +53,8 @@ struct Validator {
* @dev Delegation represents the bond with tokens held by an account. * @dev Delegation represents the bond with tokens held by an account.
*/ */
struct Delegation { struct Delegation {
string delegatorAddress; address delegatorAddress;
string validatorAddress; address validatorAddress;
uint shares; // 18 decimals uint shares; // 18 decimals
} }
@ -85,8 +85,8 @@ struct UnbondingDelegationEntry {
* for a single validator in an time-ordered list. * for a single validator in an time-ordered list.
*/ */
struct UnbondingDelegation { struct UnbondingDelegation {
string delegatorAddress; address delegatorAddress;
string validatorAddress; address validatorAddress;
UnbondingDelegationEntry[] entries; UnbondingDelegationEntry[] entries;
} }
@ -105,9 +105,9 @@ struct RedelegationResponse {
* from a particular source validator to a particular destination validator. * from a particular source validator to a particular destination validator.
*/ */
struct Redelegation { struct Redelegation {
string delegatorAddress; address delegatorAddress;
string validatorSrcAddress; address validatorSrcAddress;
string validatorDstAddress; address validatorDstAddress;
RedelegationEntry[] entries; RedelegationEntry[] entries;
} }
@ -204,7 +204,7 @@ interface IStaking {
* cosmos grpc: rpc Delegate(MsgDelegate) returns (MsgDelegateResponse); * cosmos grpc: rpc Delegate(MsgDelegate) returns (MsgDelegateResponse);
*/ */
function delegate( function delegate(
string memory validatorAddress, address validatorAddress,
uint amount // in bond denom uint amount // in bond denom
) external; ) external;
@ -215,8 +215,8 @@ interface IStaking {
* cosmos grpc: rpc BeginRedelegate(MsgBeginRedelegate) returns (MsgBeginRedelegateResponse); * cosmos grpc: rpc BeginRedelegate(MsgBeginRedelegate) returns (MsgBeginRedelegateResponse);
*/ */
function beginRedelegate( function beginRedelegate(
string memory validatorSrcAddress, address validatorSrcAddress,
string memory validatorDstAddress, address validatorDstAddress,
uint amount // in bond denom uint amount // in bond denom
) external returns (uint completionTime); ) external returns (uint completionTime);
@ -227,7 +227,7 @@ interface IStaking {
* cosmos grpc: rpc Undelegate(MsgUndelegate) returns (MsgUndelegateResponse); * cosmos grpc: rpc Undelegate(MsgUndelegate) returns (MsgUndelegateResponse);
*/ */
function undelegate( function undelegate(
string memory validatorAddress, address validatorAddress,
uint amount // in bond denom uint amount // in bond denom
) external returns (uint completionTime); ) external returns (uint completionTime);
@ -239,7 +239,7 @@ interface IStaking {
* cosmos grpc: rpc CancelUnbondingDelegation(MsgCancelUnbondingDelegation) returns (MsgCancelUnbondingDelegationResponse); * cosmos grpc: rpc CancelUnbondingDelegation(MsgCancelUnbondingDelegation) returns (MsgCancelUnbondingDelegationResponse);
*/ */
function cancelUnbondingDelegation( function cancelUnbondingDelegation(
string memory validatorAddress, address validatorAddress,
uint amount, // in bond denom uint amount, // in bond denom
uint creationHeight uint creationHeight
) external; ) external;
@ -273,7 +273,7 @@ interface IStaking {
* cosmos grpc: rpc Validator(QueryValidatorRequest) returns (QueryValidatorResponse); * cosmos grpc: rpc Validator(QueryValidatorRequest) returns (QueryValidatorResponse);
*/ */
function validator( function validator(
string memory validatorAddress address validatorAddress
) external view returns (Validator memory validator); ) external view returns (Validator memory validator);
/** /**
@ -281,7 +281,7 @@ interface IStaking {
* cosmos grpc: rpc ValidatorDelegations(QueryValidatorDelegationsRequest) returns (QueryValidatorDelegationsResponse); * cosmos grpc: rpc ValidatorDelegations(QueryValidatorDelegationsRequest) returns (QueryValidatorDelegationsResponse);
*/ */
function validatorDelegations( function validatorDelegations(
string memory validatorAddr, address validatorAddr,
PageRequest memory pagination PageRequest memory pagination
) )
external external
@ -297,7 +297,7 @@ interface IStaking {
*/ */
// //
function validatorUnbondingDelegations( function validatorUnbondingDelegations(
string memory validatorAddr, address validatorAddr,
PageRequest memory pagination PageRequest memory pagination
) )
external external
@ -312,8 +312,8 @@ interface IStaking {
* cosmos grpc: rpc Delegation(QueryDelegationRequest) returns (QueryDelegationResponse); * cosmos grpc: rpc Delegation(QueryDelegationRequest) returns (QueryDelegationResponse);
*/ */
function delegation( function delegation(
string memory delegatorAddr, address delegatorAddr,
string memory validatorAddr address validatorAddr
) external view returns (Delegation memory delegation, uint balance); ) external view returns (Delegation memory delegation, uint balance);
/** /**
@ -321,8 +321,8 @@ interface IStaking {
* cosmos grpc: rpc UnbondingDelegation(QueryUnbondingDelegationRequest) returns (QueryUnbondingDelegationResponse); * cosmos grpc: rpc UnbondingDelegation(QueryUnbondingDelegationRequest) returns (QueryUnbondingDelegationResponse);
*/ */
function unbondingDelegation( function unbondingDelegation(
string memory delegatorAddr, address delegatorAddr,
string memory validatorAddr address validatorAddr
) external view returns (UnbondingDelegation memory unbond); ) external view returns (UnbondingDelegation memory unbond);
/** /**
@ -331,7 +331,7 @@ interface IStaking {
* cosmos grpc: rpc DelegatorDelegations(QueryDelegatorDelegationsRequest) returns (QueryDelegatorDelegationsResponse); * cosmos grpc: rpc DelegatorDelegations(QueryDelegatorDelegationsRequest) returns (QueryDelegatorDelegationsResponse);
*/ */
function delegatorDelegations( function delegatorDelegations(
string memory delegatorAddr, address delegatorAddr,
PageRequest memory pagination PageRequest memory pagination
) )
external external
@ -346,7 +346,7 @@ interface IStaking {
* cosmos grpc: rpc DelegatorUnbondingDelegations(QueryDelegatorUnbondingDelegationsRequest) * cosmos grpc: rpc DelegatorUnbondingDelegations(QueryDelegatorUnbondingDelegationsRequest)
*/ */
function delegatorUnbondingDelegations( function delegatorUnbondingDelegations(
string memory delegatorAddr, address delegatorAddr,
PageRequest memory pagination PageRequest memory pagination
) )
external external
@ -362,9 +362,9 @@ interface IStaking {
* grpc: rpc Redelegations(QueryRedelegationsRequest) returns (QueryRedelegationsResponse); * grpc: rpc Redelegations(QueryRedelegationsRequest) returns (QueryRedelegationsResponse);
*/ */
function redelegations( function redelegations(
string memory delegatorAddress, address delegatorAddress,
string memory srcValidatorAddress, address srcValidatorAddress,
string memory dstValidatorAddress, address dstValidatorAddress,
PageRequest calldata pageRequest PageRequest calldata pageRequest
) )
external external
@ -379,7 +379,7 @@ interface IStaking {
* cosmos grpc: rpc DelegatorValidators(QueryDelegatorValidatorsRequest) returns (QueryDelegatorValidatorsResponse); * cosmos grpc: rpc DelegatorValidators(QueryDelegatorValidatorsRequest) returns (QueryDelegatorValidatorsResponse);
*/ */
function delegatorValidators( function delegatorValidators(
string memory delegatorAddr, address delegatorAddr,
PageRequest memory pagination PageRequest memory pagination
) )
external external
@ -394,8 +394,8 @@ interface IStaking {
* cosmos grpc: rpc DelegatorValidator(QueryDelegatorValidatorRequest) returns (QueryDelegatorValidatorResponse); * cosmos grpc: rpc DelegatorValidator(QueryDelegatorValidatorRequest) returns (QueryDelegatorValidatorResponse);
*/ */
function delegatorValidator( function delegatorValidator(
string memory delegatorAddr, address delegatorAddr,
string memory validatorAddr address validatorAddr
) external view returns (Validator memory validator); ) external view returns (Validator memory validator);
/** /**

View File

@ -2,14 +2,14 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorSrcAddress", "name": "validatorSrcAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorDstAddress", "name": "validatorDstAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -31,9 +31,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -131,9 +131,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -149,14 +149,14 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddr", "name": "validatorAddr",
"type": "string" "type": "address"
} }
], ],
"name": "delegation", "name": "delegation",
@ -164,14 +164,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -195,9 +195,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -239,14 +239,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -292,9 +292,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -334,14 +334,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -409,14 +409,14 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddr", "name": "validatorAddr",
"type": "string" "type": "address"
} }
], ],
"name": "delegatorValidator", "name": "delegatorValidator",
@ -424,9 +424,9 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "operatorAddress", "name": "operatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "string",
@ -556,9 +556,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -598,9 +598,9 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "operatorAddress", "name": "operatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "string",
@ -884,19 +884,19 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "srcValidatorAddress", "name": "srcValidatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "dstValidatorAddress", "name": "dstValidatorAddress",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -938,19 +938,19 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorSrcAddress", "name": "validatorSrcAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorDstAddress", "name": "validatorDstAddress",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -1072,14 +1072,14 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddr", "name": "delegatorAddr",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddr", "name": "validatorAddr",
"type": "string" "type": "address"
} }
], ],
"name": "unbondingDelegation", "name": "unbondingDelegation",
@ -1087,14 +1087,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -1145,9 +1145,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -1169,9 +1169,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
} }
], ],
"name": "validator", "name": "validator",
@ -1179,9 +1179,9 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "operatorAddress", "name": "operatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "string",
@ -1311,9 +1311,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddr", "name": "validatorAddr",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -1355,14 +1355,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
@ -1408,9 +1408,9 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddr", "name": "validatorAddr",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -1450,14 +1450,14 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "delegatorAddress", "name": "delegatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "address",
"name": "validatorAddress", "name": "validatorAddress",
"type": "string" "type": "address"
}, },
{ {
"components": [ "components": [
@ -1567,9 +1567,9 @@
{ {
"components": [ "components": [
{ {
"internalType": "string", "internalType": "address",
"name": "operatorAddress", "name": "operatorAddress",
"type": "string" "type": "address"
}, },
{ {
"internalType": "string", "internalType": "string",

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,10 @@ func (s *StakingPrecompile) Validators(ctx sdk.Context, _ *vm.EVM, method *abi.M
validators := make([]Validator, len(response.Validators)) validators := make([]Validator, len(response.Validators))
for i, v := range response.Validators { for i, v := range response.Validators {
validators[i] = convertValidator(v) validators[i], err = convertValidator(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -36,7 +39,12 @@ func (s *StakingPrecompile) Validator(ctx sdk.Context, _ *vm.EVM, method *abi.Me
return nil, err return nil, err
} }
return method.Outputs.Pack(convertValidator(response.Validator)) res, err := convertValidator(response.Validator)
if err != nil {
return nil, err
}
return method.Outputs.Pack(res)
} }
func (s *StakingPrecompile) ValidatorDelegations(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { func (s *StakingPrecompile) ValidatorDelegations(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
@ -51,7 +59,10 @@ func (s *StakingPrecompile) ValidatorDelegations(ctx sdk.Context, _ *vm.EVM, met
delegationResponses := make([]DelegationResponse, len(response.DelegationResponses)) delegationResponses := make([]DelegationResponse, len(response.DelegationResponses))
for i, v := range response.DelegationResponses { for i, v := range response.DelegationResponses {
delegationResponses[i] = convertDelegationResponse(v) delegationResponses[i], err = convertDelegationResponse(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -70,7 +81,10 @@ func (s *StakingPrecompile) ValidatorUnbondingDelegations(ctx sdk.Context, _ *vm
unbondingResponses := make([]UnbondingDelegation, len(response.UnbondingResponses)) unbondingResponses := make([]UnbondingDelegation, len(response.UnbondingResponses))
for i, v := range response.UnbondingResponses { for i, v := range response.UnbondingResponses {
unbondingResponses[i] = convertUnbondingDelegation(v) unbondingResponses[i], err = convertUnbondingDelegation(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -86,7 +100,10 @@ func (s *StakingPrecompile) Delegation(ctx sdk.Context, _ *vm.EVM, method *abi.M
if err != nil { if err != nil {
return nil, err return nil, err
} }
delegation := convertDelegation(response.DelegationResponse.Delegation) delegation, err := convertDelegation(response.DelegationResponse.Delegation)
if err != nil {
return nil, err
}
balance := response.DelegationResponse.Balance.Amount.BigInt() balance := response.DelegationResponse.Balance.Amount.BigInt()
return method.Outputs.Pack(delegation, balance) return method.Outputs.Pack(delegation, balance)
@ -102,7 +119,12 @@ func (s *StakingPrecompile) UnbondingDelegation(ctx sdk.Context, _ *vm.EVM, meth
return nil, err return nil, err
} }
return method.Outputs.Pack(convertUnbondingDelegation(response.Unbond)) res, err := convertUnbondingDelegation(response.Unbond)
if err != nil {
return nil, err
}
return method.Outputs.Pack(res)
} }
func (s *StakingPrecompile) DelegatorDelegations(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { func (s *StakingPrecompile) DelegatorDelegations(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
@ -117,7 +139,10 @@ func (s *StakingPrecompile) DelegatorDelegations(ctx sdk.Context, _ *vm.EVM, met
delegationResponses := make([]DelegationResponse, len(response.DelegationResponses)) delegationResponses := make([]DelegationResponse, len(response.DelegationResponses))
for i, v := range response.DelegationResponses { for i, v := range response.DelegationResponses {
delegationResponses[i] = convertDelegationResponse(v) delegationResponses[i], err = convertDelegationResponse(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -136,7 +161,10 @@ func (s *StakingPrecompile) DelegatorUnbondingDelegations(ctx sdk.Context, _ *vm
unbondingResponses := make([]UnbondingDelegation, len(response.UnbondingResponses)) unbondingResponses := make([]UnbondingDelegation, len(response.UnbondingResponses))
for i, v := range response.UnbondingResponses { for i, v := range response.UnbondingResponses {
unbondingResponses[i] = convertUnbondingDelegation(v) unbondingResponses[i], err = convertUnbondingDelegation(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -155,7 +183,10 @@ func (s *StakingPrecompile) Redelegations(ctx sdk.Context, _ *vm.EVM, method *ab
redelegationResponses := make([]RedelegationResponse, len(response.RedelegationResponses)) redelegationResponses := make([]RedelegationResponse, len(response.RedelegationResponses))
for i, v := range response.RedelegationResponses { for i, v := range response.RedelegationResponses {
redelegationResponses[i] = convertRedelegationResponse(v) redelegationResponses[i], err = convertRedelegationResponse(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -174,7 +205,10 @@ func (s *StakingPrecompile) DelegatorValidators(ctx sdk.Context, _ *vm.EVM, meth
validators := make([]Validator, len(response.Validators)) validators := make([]Validator, len(response.Validators))
for i, v := range response.Validators { for i, v := range response.Validators {
validators[i] = convertValidator(v) validators[i], err = convertValidator(v)
if err != nil {
return nil, err
}
} }
paginationResult := convertPageResponse(response.Pagination) paginationResult := convertPageResponse(response.Pagination)
@ -191,7 +225,12 @@ func (s *StakingPrecompile) DelegatorValidator(ctx sdk.Context, _ *vm.EVM, metho
return nil, err return nil, err
} }
return method.Outputs.Pack(convertValidator(response.Validator)) res, err := convertValidator(response.Validator)
if err != nil {
return nil, err
}
return method.Outputs.Pack(res)
} }
func (s *StakingPrecompile) Pool(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) { func (s *StakingPrecompile) Pool(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {

View File

@ -72,7 +72,7 @@ func (s *StakingTestSuite) TestValidator() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(operatorAddress string) []byte malleate func(operatorAddress common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -80,7 +80,7 @@ func (s *StakingTestSuite) TestValidator() {
}{ }{
{ {
"success", "success",
func(operatorAddress string) []byte { func(operatorAddress common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
operatorAddress, operatorAddress,
@ -94,7 +94,7 @@ func (s *StakingTestSuite) TestValidator() {
operatorAddress, err := s.firstBondedValidator() operatorAddress, err := s.firstBondedValidator()
s.Require().NoError(err) s.Require().NoError(err)
validator := out[0].(stakingprecompile.Validator) validator := out[0].(stakingprecompile.Validator)
s.Require().EqualValues(common.HexToAddress(validator.OperatorAddress), common.BytesToAddress(operatorAddress.Bytes())) s.Require().EqualValues(validator.OperatorAddress, common.BytesToAddress(operatorAddress.Bytes()))
}, },
100000, 100000,
false, false,
@ -108,7 +108,7 @@ func (s *StakingTestSuite) TestValidator() {
operatorAddress, err := s.firstBondedValidator() operatorAddress, err := s.firstBondedValidator()
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -127,7 +127,7 @@ func (s *StakingTestSuite) TestValidatorDelegations() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(operatorAddress string) []byte malleate func(operatorAddress common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -135,7 +135,7 @@ func (s *StakingTestSuite) TestValidatorDelegations() {
}{ }{
{ {
"success", "success",
func(operatorAddress string) []byte { func(operatorAddress common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
operatorAddress, operatorAddress,
@ -170,7 +170,7 @@ func (s *StakingTestSuite) TestValidatorDelegations() {
operatorAddress, err := s.firstBondedValidator() operatorAddress, err := s.firstBondedValidator()
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -189,7 +189,7 @@ func (s *StakingTestSuite) TestValidatorUnbondingDelegations() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(operatorAddress string) []byte malleate func(operatorAddress common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -197,7 +197,7 @@ func (s *StakingTestSuite) TestValidatorUnbondingDelegations() {
}{ }{
{ {
"success", "success",
func(operatorAddress string) []byte { func(operatorAddress common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
operatorAddress, operatorAddress,
@ -234,7 +234,7 @@ func (s *StakingTestSuite) TestValidatorUnbondingDelegations() {
_, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1)) _, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1))
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -253,7 +253,7 @@ func (s *StakingTestSuite) TestDelegation() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr, valAddr string) []byte malleate func(delAddr, valAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -261,7 +261,7 @@ func (s *StakingTestSuite) TestDelegation() {
}{ }{
{ {
"success", "success",
func(delAddr, valAddr string) []byte { func(delAddr, valAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -298,7 +298,7 @@ func (s *StakingTestSuite) TestDelegation() {
delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress) delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress)
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String(), operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes()), common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -317,7 +317,7 @@ func (s *StakingTestSuite) TestUnbondingDelegation() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr, valAddr string) []byte malleate func(delAddr, valAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -325,7 +325,7 @@ func (s *StakingTestSuite) TestUnbondingDelegation() {
}{ }{
{ {
"success", "success",
func(delAddr, valAddr string) []byte { func(delAddr, valAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -359,7 +359,7 @@ func (s *StakingTestSuite) TestUnbondingDelegation() {
_, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1)) _, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1))
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String(), operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes()), common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -378,7 +378,7 @@ func (s *StakingTestSuite) TestDelegatorDelegations() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr string) []byte malleate func(delAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -386,7 +386,7 @@ func (s *StakingTestSuite) TestDelegatorDelegations() {
}{ }{
{ {
"success", "success",
func(delAddr string) []byte { func(delAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -423,7 +423,7 @@ func (s *StakingTestSuite) TestDelegatorDelegations() {
delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress) delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress)
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -442,7 +442,7 @@ func (s *StakingTestSuite) TestDelegatorUnbondingDelegations() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr string) []byte malleate func(delAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -450,7 +450,7 @@ func (s *StakingTestSuite) TestDelegatorUnbondingDelegations() {
}{ }{
{ {
"success", "success",
func(delAddr string) []byte { func(delAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -489,7 +489,7 @@ func (s *StakingTestSuite) TestDelegatorUnbondingDelegations() {
_, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1)) _, err = s.stakingKeeper.Undelegate(s.Ctx, delAddr, operatorAddress, sdk.NewDec(1))
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -508,7 +508,7 @@ func (s *StakingTestSuite) TestRedelegations() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr, srcValAddr, dstValAddr string) []byte malleate func(delAddr, srcValAddr, dstValAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -516,7 +516,7 @@ func (s *StakingTestSuite) TestRedelegations() {
}{ }{
{ {
"success", "success",
func(delAddr, srcValAddr, dstValAddr string) []byte { func(delAddr, srcValAddr, dstValAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -559,7 +559,7 @@ func (s *StakingTestSuite) TestRedelegations() {
_, err = s.stakingKeeper.BeginRedelegation(s.Ctx, delAddr, operatorAddress, s.signerOne.ValAddr, sdk.NewDec(1)) _, err = s.stakingKeeper.BeginRedelegation(s.Ctx, delAddr, operatorAddress, s.signerOne.ValAddr, sdk.NewDec(1))
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String(), operatorAddress.String(), s.signerOne.ValAddr.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes()), common.Address(operatorAddress.Bytes()), common.Address(s.signerOne.ValAddr.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -578,7 +578,7 @@ func (s *StakingTestSuite) TestDelegatorValidators() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr string) []byte malleate func(delAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -586,7 +586,7 @@ func (s *StakingTestSuite) TestDelegatorValidators() {
}{ }{
{ {
"success", "success",
func(delAddr string) []byte { func(delAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -623,7 +623,7 @@ func (s *StakingTestSuite) TestDelegatorValidators() {
delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress) delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress)
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)
@ -642,7 +642,7 @@ func (s *StakingTestSuite) TestDelegatorValidator() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(delAddr, valAddr string) []byte malleate func(delAddr, valAddr common.Address) []byte
postCheck func(bz []byte) postCheck func(bz []byte)
gas uint64 gas uint64
expErr bool expErr bool
@ -650,7 +650,7 @@ func (s *StakingTestSuite) TestDelegatorValidator() {
}{ }{
{ {
"success", "success",
func(delAddr, valAddr string) []byte { func(delAddr, valAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
delAddr, delAddr,
@ -682,7 +682,7 @@ func (s *StakingTestSuite) TestDelegatorValidator() {
delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress) delAddr, err := sdk.AccAddressFromBech32(d[0].DelegatorAddress)
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(delAddr.String(), operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(delAddr.Bytes()), common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expErr { if tc.expErr {
s.Require().Error(err) s.Require().Error(err)

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
"github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/store/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
@ -84,7 +84,7 @@ func (s *StakingPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly boo
// get state db and context // get state db and context
stateDB, ok := evm.StateDB.(*statedb.StateDB) stateDB, ok := evm.StateDB.(*statedb.StateDB)
if !ok { if !ok {
return nil, fmt.Errorf(precopmiles_common.ErrGetStateDB) return nil, fmt.Errorf(precompiles_common.ErrGetStateDB)
} }
ctx := stateDB.GetContext() ctx := stateDB.GetContext()
// reset gas config // reset gas config

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
@ -20,13 +20,13 @@ func (s *StakingPrecompile) CreateValidator(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgCreateValidator(args, evm.Origin, s.stakingKeeper.BondDenom(ctx)) msg, err := NewMsgCreateValidator(args, contract.CallerAddress, s.stakingKeeper.BondDenom(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
// execute // execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).CreateValidator(ctx, msg) _, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).CreateValidator(ctx, msg)
@ -45,13 +45,13 @@ func (s *StakingPrecompile) EditValidator(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgEditValidator(args, evm.Origin) msg, err := NewMsgEditValidator(args, contract.CallerAddress)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
// execute // execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).EditValidator(ctx, msg) _, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).EditValidator(ctx, msg)
@ -70,14 +70,16 @@ func (s *StakingPrecompile) Delegate(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgDelegate(args, evm.Origin, s.stakingKeeper.BondDenom(ctx)) msg, err := NewMsgDelegate(args, contract.CallerAddress, s.stakingKeeper.BondDenom(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
/*
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
*/
// execute // execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Delegate(ctx, msg) _, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Delegate(ctx, msg)
if err != nil { if err != nil {
@ -95,14 +97,16 @@ func (s *StakingPrecompile) BeginRedelegate(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgBeginRedelegate(args, evm.Origin, s.stakingKeeper.BondDenom(ctx)) msg, err := NewMsgBeginRedelegate(args, contract.CallerAddress, s.stakingKeeper.BondDenom(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
/*
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
*/
// execute // execute
response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).BeginRedelegate(ctx, msg) response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).BeginRedelegate(ctx, msg)
if err != nil { if err != nil {
@ -120,14 +124,16 @@ func (s *StakingPrecompile) Undelegate(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgUndelegate(args, evm.Origin, s.stakingKeeper.BondDenom(ctx)) msg, err := NewMsgUndelegate(args, contract.CallerAddress, s.stakingKeeper.BondDenom(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
/*
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
*/
// execute // execute
response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Undelegate(ctx, msg) response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Undelegate(ctx, msg)
if err != nil { if err != nil {
@ -145,14 +151,16 @@ func (s *StakingPrecompile) CancelUnbondingDelegation(
method *abi.Method, method *abi.Method,
args []interface{}, args []interface{},
) ([]byte, error) { ) ([]byte, error) {
msg, err := NewMsgCancelUnbondingDelegation(args, evm.Origin, s.stakingKeeper.BondDenom(ctx)) msg, err := NewMsgCancelUnbondingDelegation(args, contract.CallerAddress, s.stakingKeeper.BondDenom(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
// validation // validation
/*
if contract.CallerAddress != evm.Origin { if contract.CallerAddress != evm.Origin {
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin) return nil, fmt.Errorf(precompiles_common.ErrSenderNotOrigin)
} }
*/
// execute // execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).CancelUnbondingDelegation(ctx, msg) _, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).CancelUnbondingDelegation(ctx, msg)
if err != nil { if err != nil {

View File

@ -224,7 +224,7 @@ func (s *StakingTestSuite) TestDelegate() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(valAddr string) []byte malleate func(valAddr common.Address) []byte
gas uint64 gas uint64
callerAddress *common.Address callerAddress *common.Address
postCheck func(valAddr sdk.ValAddress) postCheck func(valAddr sdk.ValAddress)
@ -233,7 +233,7 @@ func (s *StakingTestSuite) TestDelegate() {
}{ }{
{ {
"success", "success",
func(valAddr string) []byte { func(valAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
valAddr, valAddr,
@ -265,7 +265,7 @@ func (s *StakingTestSuite) TestDelegate() {
operatorAddress, err := s.firstBondedValidator() operatorAddress, err := s.firstBondedValidator()
s.Require().NoError(err) s.Require().NoError(err)
bz, err := s.runTx(tc.malleate(operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(common.Address(operatorAddress)), s.signerOne, 10000000)
if tc.expError { if tc.expError {
s.Require().ErrorContains(err, tc.errContains) s.Require().ErrorContains(err, tc.errContains)
@ -283,7 +283,7 @@ func (s *StakingTestSuite) TestBeginRedelegate() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(srcAddr, dstAddr string) []byte malleate func(srcAddr, dstAddr common.Address) []byte
gas uint64 gas uint64
callerAddress *common.Address callerAddress *common.Address
postCheck func(data []byte, srcAddr, dstAddr sdk.ValAddress) postCheck func(data []byte, srcAddr, dstAddr sdk.ValAddress)
@ -292,7 +292,7 @@ func (s *StakingTestSuite) TestBeginRedelegate() {
}{ }{
{ {
"success", "success",
func(srcAddr, dstAddr string) []byte { func(srcAddr, dstAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
srcAddr, srcAddr,
@ -337,7 +337,7 @@ func (s *StakingTestSuite) TestBeginRedelegate() {
s.setupValidator(s.signerOne) s.setupValidator(s.signerOne)
bz, err := s.runTx(tc.malleate(s.signerOne.ValAddr.String(), operatorAddress.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(s.signerOne.Addr, common.Address(operatorAddress.Bytes())), s.signerOne, 10000000)
if tc.expError { if tc.expError {
s.Require().ErrorContains(err, tc.errContains) s.Require().ErrorContains(err, tc.errContains)
@ -355,7 +355,7 @@ func (s *StakingTestSuite) TestUndelegate() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(valAddr string) []byte malleate func(valAddr common.Address) []byte
gas uint64 gas uint64
callerAddress *common.Address callerAddress *common.Address
postCheck func(data []byte, valAddr sdk.ValAddress) postCheck func(data []byte, valAddr sdk.ValAddress)
@ -364,7 +364,7 @@ func (s *StakingTestSuite) TestUndelegate() {
}{ }{
{ {
"success", "success",
func(valAddr string) []byte { func(valAddr common.Address) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
valAddr, valAddr,
@ -405,7 +405,7 @@ func (s *StakingTestSuite) TestUndelegate() {
s.setupValidator(s.signerOne) s.setupValidator(s.signerOne)
bz, err := s.runTx(tc.malleate(s.signerOne.ValAddr.String()), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(s.signerOne.Addr), s.signerOne, 10000000)
if tc.expError { if tc.expError {
s.Require().ErrorContains(err, tc.errContains) s.Require().ErrorContains(err, tc.errContains)
@ -423,7 +423,7 @@ func (s *StakingTestSuite) TestCancelUnbondingDelegation() {
testCases := []struct { testCases := []struct {
name string name string
malleate func(valAddr string, height *big.Int) []byte malleate func(valAddr common.Address, height *big.Int) []byte
gas uint64 gas uint64
callerAddress *common.Address callerAddress *common.Address
postCheck func(valAddr sdk.ValAddress) postCheck func(valAddr sdk.ValAddress)
@ -432,7 +432,7 @@ func (s *StakingTestSuite) TestCancelUnbondingDelegation() {
}{ }{
{ {
"success", "success",
func(valAddr string, height *big.Int) []byte { func(valAddr common.Address, height *big.Int) []byte {
input, err := s.abi.Pack( input, err := s.abi.Pack(
method, method,
valAddr, valAddr,
@ -471,7 +471,7 @@ func (s *StakingTestSuite) TestCancelUnbondingDelegation() {
u, _ := s.stakingKeeper.GetUnbondingDelegation(s.Ctx, s.signerOne.AccAddr, s.signerOne.ValAddr) u, _ := s.stakingKeeper.GetUnbondingDelegation(s.Ctx, s.signerOne.AccAddr, s.signerOne.ValAddr)
height := u.Entries[0].CreationHeight height := u.Entries[0].CreationHeight
bz, err := s.runTx(tc.malleate(s.signerOne.ValAddr.String(), big.NewInt(height)), s.signerOne, 10000000) bz, err := s.runTx(tc.malleate(s.signerOne.Addr, big.NewInt(height)), s.signerOne, 10000000)
if tc.expError { if tc.expError {
s.Require().ErrorContains(err, tc.errContains) s.Require().ErrorContains(err, tc.errContains)

View File

@ -7,7 +7,7 @@ import (
"math/big" "math/big"
"cosmossdk.io/math" "cosmossdk.io/math"
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common" precompiles_common "github.com/0glabs/0g-chain/precompiles/common"
codectypes "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
@ -29,8 +29,8 @@ type CommissionRates = struct {
} }
type Delegation = struct { type Delegation = struct {
DelegatorAddress string `json:"delegatorAddress"` DelegatorAddress common.Address `json:"delegatorAddress"`
ValidatorAddress string `json:"validatorAddress"` ValidatorAddress common.Address `json:"validatorAddress"`
Shares *big.Int `json:"shares"` Shares *big.Int `json:"shares"`
} }
@ -75,9 +75,9 @@ type Params = struct {
} }
type Redelegation = struct { type Redelegation = struct {
DelegatorAddress string `json:"delegatorAddress"` DelegatorAddress common.Address `json:"delegatorAddress"`
ValidatorSrcAddress string `json:"validatorSrcAddress"` ValidatorSrcAddress common.Address `json:"validatorSrcAddress"`
ValidatorDstAddress string `json:"validatorDstAddress"` ValidatorDstAddress common.Address `json:"validatorDstAddress"`
Entries []RedelegationEntry `json:"entries"` Entries []RedelegationEntry `json:"entries"`
} }
@ -101,8 +101,8 @@ type RedelegationResponse = struct {
} }
type UnbondingDelegation = struct { type UnbondingDelegation = struct {
DelegatorAddress string `json:"delegatorAddress"` DelegatorAddress common.Address `json:"delegatorAddress"`
ValidatorAddress string `json:"validatorAddress"` ValidatorAddress common.Address `json:"validatorAddress"`
Entries []UnbondingDelegationEntry `json:"entries"` Entries []UnbondingDelegationEntry `json:"entries"`
} }
@ -116,7 +116,7 @@ type UnbondingDelegationEntry = struct {
} }
type Validator = struct { type Validator = struct {
OperatorAddress string `json:"operatorAddress"` OperatorAddress common.Address `json:"operatorAddress"`
ConsensusPubkey string `json:"consensusPubkey"` ConsensusPubkey string `json:"consensusPubkey"`
Jailed bool `json:"jailed"` Jailed bool `json:"jailed"`
Status uint8 `json:"status"` Status uint8 `json:"status"`
@ -131,14 +131,13 @@ type Validator = struct {
UnbondingIds []uint64 `json:"unbondingIds"` UnbondingIds []uint64 `json:"unbondingIds"`
} }
func convertValidator(v stakingtypes.Validator) Validator { func convertValidator(v stakingtypes.Validator) (Validator, error) {
validator := Validator{} validator := Validator{}
operatorAddress, err := sdk.ValAddressFromBech32(v.OperatorAddress) operatorAddress, err := sdk.ValAddressFromBech32(v.OperatorAddress)
if err != nil { if err != nil {
validator.OperatorAddress = v.OperatorAddress return validator, err
} else {
validator.OperatorAddress = common.BytesToAddress(operatorAddress.Bytes()).String()
} }
validator.OperatorAddress = common.BytesToAddress(operatorAddress.Bytes())
ed25519pk, ok := v.ConsensusPubkey.GetCachedValue().(cryptotypes.PubKey) ed25519pk, ok := v.ConsensusPubkey.GetCachedValue().(cryptotypes.PubKey)
if !ok { if !ok {
@ -167,7 +166,7 @@ func convertValidator(v stakingtypes.Validator) Validator {
validator.MinSelfDelegation = v.MinSelfDelegation.BigInt() validator.MinSelfDelegation = v.MinSelfDelegation.BigInt()
validator.UnbondingOnHoldRefCount = v.UnbondingOnHoldRefCount validator.UnbondingOnHoldRefCount = v.UnbondingOnHoldRefCount
validator.UnbondingIds = v.UnbondingIds validator.UnbondingIds = v.UnbondingIds
return validator return validator, nil
} }
func convertQueryPageRequest(pagination PageRequest) *query.PageRequest { func convertQueryPageRequest(pagination PageRequest) *query.PageRequest {
@ -205,9 +204,9 @@ func convertStakingDescription(description Description) stakingtypes.Description
func convertStakingCommissionRates(commission CommissionRates) stakingtypes.CommissionRates { func convertStakingCommissionRates(commission CommissionRates) stakingtypes.CommissionRates {
return stakingtypes.CommissionRates{ return stakingtypes.CommissionRates{
Rate: precopmiles_common.BigIntToLegacyDec(commission.Rate), Rate: precompiles_common.BigIntToLegacyDec(commission.Rate),
MaxRate: precopmiles_common.BigIntToLegacyDec(commission.MaxRate), MaxRate: precompiles_common.BigIntToLegacyDec(commission.MaxRate),
MaxChangeRate: precopmiles_common.BigIntToLegacyDec(commission.MaxChangeRate), MaxChangeRate: precompiles_common.BigIntToLegacyDec(commission.MaxChangeRate),
} }
} }
@ -219,19 +218,31 @@ func convertCommissionRates(commission stakingtypes.CommissionRates) CommissionR
} }
} }
func convertDelegation(delegation stakingtypes.Delegation) Delegation { func convertDelegation(delegation stakingtypes.Delegation) (Delegation, error) {
return Delegation{ delegatorAddress, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
DelegatorAddress: delegation.DelegatorAddress, if err != nil {
ValidatorAddress: delegation.ValidatorAddress, return Delegation{}, err
Shares: delegation.Shares.BigInt(),
} }
validatorAddress, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
return Delegation{}, err
}
return Delegation{
DelegatorAddress: common.BytesToAddress(delegatorAddress.Bytes()),
ValidatorAddress: common.BytesToAddress(validatorAddress.Bytes()),
Shares: delegation.Shares.BigInt(),
}, nil
} }
func convertDelegationResponse(response stakingtypes.DelegationResponse) DelegationResponse { func convertDelegationResponse(response stakingtypes.DelegationResponse) (DelegationResponse, error) {
return DelegationResponse{ delegation, err := convertDelegation(response.Delegation)
Delegation: convertDelegation(response.Delegation), if err != nil {
Balance: response.Balance.Amount.BigInt(), return DelegationResponse{}, err
} }
return DelegationResponse{
Delegation: delegation,
Balance: response.Balance.Amount.BigInt(),
}, nil
} }
func convertUnbondingDelegationEntry(entry stakingtypes.UnbondingDelegationEntry) UnbondingDelegationEntry { func convertUnbondingDelegationEntry(entry stakingtypes.UnbondingDelegationEntry) UnbondingDelegationEntry {
@ -245,16 +256,24 @@ func convertUnbondingDelegationEntry(entry stakingtypes.UnbondingDelegationEntry
} }
} }
func convertUnbondingDelegation(response stakingtypes.UnbondingDelegation) UnbondingDelegation { func convertUnbondingDelegation(response stakingtypes.UnbondingDelegation) (UnbondingDelegation, error) {
entries := make([]UnbondingDelegationEntry, len(response.Entries)) entries := make([]UnbondingDelegationEntry, len(response.Entries))
for i, v := range response.Entries { for i, v := range response.Entries {
entries[i] = convertUnbondingDelegationEntry(v) entries[i] = convertUnbondingDelegationEntry(v)
} }
return UnbondingDelegation{ delegatorAddress, err := sdk.AccAddressFromBech32(response.DelegatorAddress)
DelegatorAddress: response.DelegatorAddress, if err != nil {
ValidatorAddress: response.ValidatorAddress, return UnbondingDelegation{}, err
Entries: entries,
} }
validatorAddress, err := sdk.ValAddressFromBech32(response.ValidatorAddress)
if err != nil {
return UnbondingDelegation{}, err
}
return UnbondingDelegation{
DelegatorAddress: common.BytesToAddress(delegatorAddress.Bytes()),
ValidatorAddress: common.BytesToAddress(validatorAddress.Bytes()),
Entries: entries,
}, nil
} }
func convertRedelegationEntry(entry stakingtypes.RedelegationEntry) RedelegationEntry { func convertRedelegationEntry(entry stakingtypes.RedelegationEntry) RedelegationEntry {
@ -268,17 +287,29 @@ func convertRedelegationEntry(entry stakingtypes.RedelegationEntry) Redelegation
} }
} }
func convertRedelegation(redelegation stakingtypes.Redelegation) Redelegation { func convertRedelegation(redelegation stakingtypes.Redelegation) (Redelegation, error) {
entries := make([]RedelegationEntry, len(redelegation.Entries)) entries := make([]RedelegationEntry, len(redelegation.Entries))
for i, v := range redelegation.Entries { for i, v := range redelegation.Entries {
entries[i] = convertRedelegationEntry(v) entries[i] = convertRedelegationEntry(v)
} }
return Redelegation{ delegatorAddress, err := sdk.AccAddressFromBech32(redelegation.DelegatorAddress)
DelegatorAddress: redelegation.DelegatorAddress, if err != nil {
ValidatorSrcAddress: redelegation.ValidatorSrcAddress, return Redelegation{}, err
ValidatorDstAddress: redelegation.ValidatorDstAddress,
Entries: entries,
} }
validatorSrcAddress, err := sdk.ValAddressFromBech32(redelegation.ValidatorSrcAddress)
if err != nil {
return Redelegation{}, err
}
validatorDstAddress, err := sdk.ValAddressFromBech32(redelegation.ValidatorDstAddress)
if err != nil {
return Redelegation{}, err
}
return Redelegation{
DelegatorAddress: common.BytesToAddress(delegatorAddress.Bytes()),
ValidatorSrcAddress: common.BytesToAddress(validatorSrcAddress.Bytes()),
ValidatorDstAddress: common.BytesToAddress(validatorDstAddress.Bytes()),
Entries: entries,
}, nil
} }
func convertRedelegationEntryResponse(response stakingtypes.RedelegationEntryResponse) RedelegationEntryResponse { func convertRedelegationEntryResponse(response stakingtypes.RedelegationEntryResponse) RedelegationEntryResponse {
@ -288,15 +319,19 @@ func convertRedelegationEntryResponse(response stakingtypes.RedelegationEntryRes
} }
} }
func convertRedelegationResponse(response stakingtypes.RedelegationResponse) RedelegationResponse { func convertRedelegationResponse(response stakingtypes.RedelegationResponse) (RedelegationResponse, error) {
entries := make([]RedelegationEntryResponse, len(response.Entries)) entries := make([]RedelegationEntryResponse, len(response.Entries))
for i, v := range response.Entries { for i, v := range response.Entries {
entries[i] = convertRedelegationEntryResponse(v) entries[i] = convertRedelegationEntryResponse(v)
} }
return RedelegationResponse{ redelegation, err := convertRedelegation(response.Redelegation)
Redelegation: convertRedelegation(response.Redelegation), if err != nil {
Entries: entries, return RedelegationResponse{}, nil
} }
return RedelegationResponse{
Redelegation: redelegation,
Entries: entries,
}, nil
} }
func convertParams(params stakingtypes.Params) Params { func convertParams(params stakingtypes.Params) Params {
@ -312,7 +347,7 @@ func convertParams(params stakingtypes.Params) Params {
func NewMsgCreateValidator(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgCreateValidator, error) { func NewMsgCreateValidator(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgCreateValidator, error) {
if len(args) != 5 { if len(args) != 5 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 5, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 5, len(args))
} }
description := args[0].(Description) description := args[0].(Description)
commission := args[1].(CommissionRates) commission := args[1].(CommissionRates)
@ -349,14 +384,14 @@ func NewMsgCreateValidator(args []interface{}, sender common.Address, denom stri
func NewMsgEditValidator(args []interface{}, sender common.Address) (*stakingtypes.MsgEditValidator, error) { func NewMsgEditValidator(args []interface{}, sender common.Address) (*stakingtypes.MsgEditValidator, error) {
if len(args) != 3 { if len(args) != 3 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 3, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 3, len(args))
} }
description := args[0].(Description) description := args[0].(Description)
commissionRateNullable := args[1].(NullableUint) commissionRateNullable := args[1].(NullableUint)
var commissionRate *sdk.Dec var commissionRate *sdk.Dec
if !commissionRateNullable.IsNull { if !commissionRateNullable.IsNull {
value := precopmiles_common.BigIntToLegacyDec(commissionRateNullable.Value) value := precompiles_common.BigIntToLegacyDec(commissionRateNullable.Value)
commissionRate = &value commissionRate = &value
} }
@ -378,14 +413,14 @@ func NewMsgEditValidator(args []interface{}, sender common.Address) (*stakingtyp
func NewMsgDelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgDelegate, error) { func NewMsgDelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgDelegate, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
validatorAddress := args[0].(string) validatorAddress := args[0].(common.Address)
amount := args[1].(*big.Int) amount := args[1].(*big.Int)
msg := &stakingtypes.MsgDelegate{ msg := &stakingtypes.MsgDelegate{
DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(), DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(),
ValidatorAddress: validatorAddress, ValidatorAddress: sdk.ValAddress(validatorAddress.Bytes()).String(),
Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)}, Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)},
} }
return msg, msg.ValidateBasic() return msg, msg.ValidateBasic()
@ -393,16 +428,16 @@ func NewMsgDelegate(args []interface{}, sender common.Address, denom string) (*s
func NewMsgBeginRedelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgBeginRedelegate, error) { func NewMsgBeginRedelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgBeginRedelegate, error) {
if len(args) != 3 { if len(args) != 3 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 3, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 3, len(args))
} }
validatorSrcAddress := args[0].(string) validatorSrcAddress := args[0].(common.Address)
validatorDstAddress := args[1].(string) validatorDstAddress := args[1].(common.Address)
amount := args[2].(*big.Int) amount := args[2].(*big.Int)
msg := &stakingtypes.MsgBeginRedelegate{ msg := &stakingtypes.MsgBeginRedelegate{
DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(), DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(),
ValidatorSrcAddress: validatorSrcAddress, ValidatorSrcAddress: sdk.ValAddress(validatorSrcAddress.Bytes()).String(),
ValidatorDstAddress: validatorDstAddress, ValidatorDstAddress: sdk.ValAddress(validatorDstAddress.Bytes()).String(),
Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)}, Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)},
} }
return msg, msg.ValidateBasic() return msg, msg.ValidateBasic()
@ -410,14 +445,14 @@ func NewMsgBeginRedelegate(args []interface{}, sender common.Address, denom stri
func NewMsgUndelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgUndelegate, error) { func NewMsgUndelegate(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgUndelegate, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
validatorAddress := args[0].(string) validatorAddress := args[0].(common.Address)
amount := args[1].(*big.Int) amount := args[1].(*big.Int)
msg := &stakingtypes.MsgUndelegate{ msg := &stakingtypes.MsgUndelegate{
DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(), DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(),
ValidatorAddress: validatorAddress, ValidatorAddress: sdk.ValAddress(validatorAddress.Bytes()).String(),
Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)}, Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)},
} }
return msg, msg.ValidateBasic() return msg, msg.ValidateBasic()
@ -425,15 +460,15 @@ func NewMsgUndelegate(args []interface{}, sender common.Address, denom string) (
func NewMsgCancelUnbondingDelegation(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgCancelUnbondingDelegation, error) { func NewMsgCancelUnbondingDelegation(args []interface{}, sender common.Address, denom string) (*stakingtypes.MsgCancelUnbondingDelegation, error) {
if len(args) != 3 { if len(args) != 3 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 3, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 3, len(args))
} }
validatorAddress := args[0].(string) validatorAddress := args[0].(common.Address)
amount := args[1].(*big.Int) amount := args[1].(*big.Int)
creationHeight := args[2].(*big.Int) creationHeight := args[2].(*big.Int)
msg := &stakingtypes.MsgCancelUnbondingDelegation{ msg := &stakingtypes.MsgCancelUnbondingDelegation{
DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(), DelegatorAddress: sdk.AccAddress(sender.Bytes()).String(),
ValidatorAddress: validatorAddress, ValidatorAddress: sdk.ValAddress(validatorAddress.Bytes()).String(),
Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)}, Amount: sdk.Coin{Denom: denom, Amount: math.NewIntFromBigInt(amount)},
CreationHeight: creationHeight.Int64(), CreationHeight: creationHeight.Int64(),
} }
@ -442,7 +477,7 @@ func NewMsgCancelUnbondingDelegation(args []interface{}, sender common.Address,
func NewQueryValidatorsRequest(args []interface{}) (*stakingtypes.QueryValidatorsRequest, error) { func NewQueryValidatorsRequest(args []interface{}) (*stakingtypes.QueryValidatorsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
status := args[0].(string) status := args[0].(string)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
@ -455,139 +490,139 @@ func NewQueryValidatorsRequest(args []interface{}) (*stakingtypes.QueryValidator
func NewQueryValidatorRequest(args []interface{}) (*stakingtypes.QueryValidatorRequest, error) { func NewQueryValidatorRequest(args []interface{}) (*stakingtypes.QueryValidatorRequest, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 1, len(args))
} }
validatorAddress := args[0].(string) validatorAddress := args[0].(common.Address)
return &stakingtypes.QueryValidatorRequest{ return &stakingtypes.QueryValidatorRequest{
ValidatorAddr: validatorAddress, ValidatorAddr: sdk.ValAddress(validatorAddress.Bytes()).String(),
}, nil }, nil
} }
func NewQueryValidatorDelegationsRequest(args []interface{}) (*stakingtypes.QueryValidatorDelegationsRequest, error) { func NewQueryValidatorDelegationsRequest(args []interface{}) (*stakingtypes.QueryValidatorDelegationsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
validatorAddr := args[0].(string) validatorAddr := args[0].(common.Address)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
return &stakingtypes.QueryValidatorDelegationsRequest{ return &stakingtypes.QueryValidatorDelegationsRequest{
ValidatorAddr: validatorAddr, ValidatorAddr: sdk.ValAddress(validatorAddr.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryValidatorUnbondingDelegationsRequest(args []interface{}) (*stakingtypes.QueryValidatorUnbondingDelegationsRequest, error) { func NewQueryValidatorUnbondingDelegationsRequest(args []interface{}) (*stakingtypes.QueryValidatorUnbondingDelegationsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
validatorAddr := args[0].(string) validatorAddr := args[0].(common.Address)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
return &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ return &stakingtypes.QueryValidatorUnbondingDelegationsRequest{
ValidatorAddr: validatorAddr, ValidatorAddr: sdk.ValAddress(validatorAddr.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryDelegationRequest(args []interface{}) (*stakingtypes.QueryDelegationRequest, error) { func NewQueryDelegationRequest(args []interface{}) (*stakingtypes.QueryDelegationRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
validatorAddr := args[1].(string) validatorAddr := args[1].(common.Address)
return &stakingtypes.QueryDelegationRequest{ return &stakingtypes.QueryDelegationRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
ValidatorAddr: validatorAddr, ValidatorAddr: sdk.ValAddress(validatorAddr.Bytes()).String(),
}, nil }, nil
} }
func NewQueryUnbondingDelegationRequest(args []interface{}) (*stakingtypes.QueryUnbondingDelegationRequest, error) { func NewQueryUnbondingDelegationRequest(args []interface{}) (*stakingtypes.QueryUnbondingDelegationRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
validatorAddr := args[1].(string) validatorAddr := args[1].(common.Address)
return &stakingtypes.QueryUnbondingDelegationRequest{ return &stakingtypes.QueryUnbondingDelegationRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
ValidatorAddr: validatorAddr, ValidatorAddr: sdk.ValAddress(validatorAddr.Bytes()).String(),
}, nil }, nil
} }
func NewQueryDelegatorDelegationsRequest(args []interface{}) (*stakingtypes.QueryDelegatorDelegationsRequest, error) { func NewQueryDelegatorDelegationsRequest(args []interface{}) (*stakingtypes.QueryDelegatorDelegationsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
return &stakingtypes.QueryDelegatorDelegationsRequest{ return &stakingtypes.QueryDelegatorDelegationsRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryDelegatorUnbondingDelegationsRequest(args []interface{}) (*stakingtypes.QueryDelegatorUnbondingDelegationsRequest, error) { func NewQueryDelegatorUnbondingDelegationsRequest(args []interface{}) (*stakingtypes.QueryDelegatorUnbondingDelegationsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
return &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{ return &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryRedelegationsRequest(args []interface{}) (*stakingtypes.QueryRedelegationsRequest, error) { func NewQueryRedelegationsRequest(args []interface{}) (*stakingtypes.QueryRedelegationsRequest, error) {
if len(args) != 4 { if len(args) != 4 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 4, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 4, len(args))
} }
delegatorAddress := args[0].(string) delegatorAddress := args[0].(common.Address)
validatorSrcAddress := args[1].(string) validatorSrcAddress := args[1].(common.Address)
validatorDstAddress := args[2].(string) validatorDstAddress := args[2].(common.Address)
pagination := args[3].(PageRequest) pagination := args[3].(PageRequest)
return &stakingtypes.QueryRedelegationsRequest{ return &stakingtypes.QueryRedelegationsRequest{
DelegatorAddr: delegatorAddress, DelegatorAddr: sdk.AccAddress(delegatorAddress.Bytes()).String(),
SrcValidatorAddr: validatorSrcAddress, SrcValidatorAddr: sdk.ValAddress(validatorSrcAddress.Bytes()).String(),
DstValidatorAddr: validatorDstAddress, DstValidatorAddr: sdk.ValAddress(validatorDstAddress.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryDelegatorValidatorsRequest(args []interface{}) (*stakingtypes.QueryDelegatorValidatorsRequest, error) { func NewQueryDelegatorValidatorsRequest(args []interface{}) (*stakingtypes.QueryDelegatorValidatorsRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
pagination := args[1].(PageRequest) pagination := args[1].(PageRequest)
return &stakingtypes.QueryDelegatorValidatorsRequest{ return &stakingtypes.QueryDelegatorValidatorsRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
Pagination: convertQueryPageRequest(pagination), Pagination: convertQueryPageRequest(pagination),
}, nil }, nil
} }
func NewQueryDelegatorValidatorRequest(args []interface{}) (*stakingtypes.QueryDelegatorValidatorRequest, error) { func NewQueryDelegatorValidatorRequest(args []interface{}) (*stakingtypes.QueryDelegatorValidatorRequest, error) {
if len(args) != 2 { if len(args) != 2 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 2, len(args))
} }
delegatorAddr := args[0].(string) delegatorAddr := args[0].(common.Address)
validatorAddr := args[1].(string) validatorAddr := args[1].(common.Address)
return &stakingtypes.QueryDelegatorValidatorRequest{ return &stakingtypes.QueryDelegatorValidatorRequest{
DelegatorAddr: delegatorAddr, DelegatorAddr: sdk.AccAddress(delegatorAddr.Bytes()).String(),
ValidatorAddr: validatorAddr, ValidatorAddr: sdk.ValAddress(validatorAddr.Bytes()).String(),
}, nil }, nil
} }
func NewQueryPoolRequest(args []interface{}) (*stakingtypes.QueryPoolRequest, error) { func NewQueryPoolRequest(args []interface{}) (*stakingtypes.QueryPoolRequest, error) {
if len(args) != 0 { if len(args) != 0 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 0, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 0, len(args))
} }
return &stakingtypes.QueryPoolRequest{}, nil return &stakingtypes.QueryPoolRequest{}, nil
@ -595,7 +630,7 @@ func NewQueryPoolRequest(args []interface{}) (*stakingtypes.QueryPoolRequest, er
func NewQueryParamsRequest(args []interface{}) (*stakingtypes.QueryParamsRequest, error) { func NewQueryParamsRequest(args []interface{}) (*stakingtypes.QueryParamsRequest, error) {
if len(args) != 0 { if len(args) != 0 {
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 0, len(args)) return nil, fmt.Errorf(precompiles_common.ErrInvalidNumberOfArgs, 0, len(args))
} }
return &stakingtypes.QueryParamsRequest{}, nil return &stakingtypes.QueryParamsRequest{}, nil