mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
feat: add get functions
This commit is contained in:
parent
701a0ba97e
commit
a3f3aaaecc
@ -220,6 +220,25 @@
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "isSigner",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
@ -340,6 +359,30 @@
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "_account",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "_epoch",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "registeredEpoch",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
|
File diff suppressed because one or more lines are too long
@ -26,6 +26,8 @@ const (
|
||||
DASignersFunctionUpdateSocket = "updateSocket"
|
||||
DASignersFunctionRegisterNextEpoch = "registerNextEpoch"
|
||||
DASignersFunctionGetAggPkG1 = "getAggPkG1"
|
||||
DASignersFunctionIsSigner = "isSigner"
|
||||
DASignersFunctionRegisteredEpoch = "registeredEpoch"
|
||||
)
|
||||
|
||||
var RequiredGasBasic = map[string]uint64{
|
||||
@ -37,6 +39,8 @@ var RequiredGasBasic = map[string]uint64{
|
||||
DASignersFunctionUpdateSocket: 50000,
|
||||
DASignersFunctionRegisterNextEpoch: 100000,
|
||||
DASignersFunctionGetAggPkG1: 1000000,
|
||||
DASignersFunctionIsSigner: 10000,
|
||||
DASignersFunctionRegisteredEpoch: 10000,
|
||||
}
|
||||
|
||||
var KVGasConfig storetypes.GasConfig = storetypes.GasConfig{
|
||||
@ -121,6 +125,10 @@ func (d *DASignersPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly b
|
||||
bz, err = d.GetQuorum(ctx, evm, method, args)
|
||||
case DASignersFunctionGetAggPkG1:
|
||||
bz, err = d.GetAggPkG1(ctx, evm, method, args)
|
||||
case DASignersFunctionIsSigner:
|
||||
bz, err = d.IsSigner(ctx, evm, method, args)
|
||||
case DASignersFunctionRegisteredEpoch:
|
||||
bz, err = d.RegisteredEpoch(ctx, evm, method, args)
|
||||
// txs
|
||||
case DASignersFunctionRegisterSigner:
|
||||
bz, err = d.RegisterSigner(ctx, evm, stateDB, method, args)
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dasigners
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
precopmiles_common "github.com/0glabs/0g-chain/precompiles/common"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -19,6 +21,9 @@ func (d *DASignersPrecompile) EpochNumber(ctx sdk.Context, _ *vm.EVM, method *ab
|
||||
|
||||
func (d *DASignersPrecompile) QuorumCount(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
req, err := NewQueryQuorumCountRequest(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := d.dasignersKeeper.QuorumCount(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -42,6 +47,31 @@ func (d *DASignersPrecompile) GetSigner(ctx sdk.Context, _ *vm.EVM, method *abi.
|
||||
return method.Outputs.Pack(signers)
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) IsSigner(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 1, len(args))
|
||||
}
|
||||
account := ToLowerHexWithoutPrefix(args[0].(common.Address))
|
||||
_, found, err := d.dasignersKeeper.GetSigner(ctx, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack(found)
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) RegisteredEpoch(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf(precopmiles_common.ErrInvalidNumberOfArgs, 2, len(args))
|
||||
}
|
||||
account := ToLowerHexWithoutPrefix(args[0].(common.Address))
|
||||
epoch := args[1].(*big.Int).Uint64()
|
||||
_, found, err := d.dasignersKeeper.GetRegistration(ctx, epoch, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method.Outputs.Pack(found)
|
||||
}
|
||||
|
||||
func (d *DASignersPrecompile) GetQuorum(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
|
||||
req, err := NewQueryEpochQuorumRequest(args)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user