feat: add get functions

This commit is contained in:
MiniFrenchBread 2024-05-18 23:01:28 +08:00 committed by 0g-wh
parent 86cfde7e71
commit 2468ab5c31
4 changed files with 144 additions and 1 deletions

View File

@ -220,6 +220,25 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [
{
"internalType": "address",
"name": "_account",
"type": "address"
}
],
"name": "isSigner",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
@ -340,6 +359,30 @@
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "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": [ "inputs": [
{ {

File diff suppressed because one or more lines are too long

View File

@ -26,6 +26,8 @@ const (
DASignersFunctionUpdateSocket = "updateSocket" DASignersFunctionUpdateSocket = "updateSocket"
DASignersFunctionRegisterNextEpoch = "registerNextEpoch" DASignersFunctionRegisterNextEpoch = "registerNextEpoch"
DASignersFunctionGetAggPkG1 = "getAggPkG1" DASignersFunctionGetAggPkG1 = "getAggPkG1"
DASignersFunctionIsSigner = "isSigner"
DASignersFunctionRegisteredEpoch = "registeredEpoch"
) )
var RequiredGasBasic = map[string]uint64{ var RequiredGasBasic = map[string]uint64{
@ -37,6 +39,8 @@ var RequiredGasBasic = map[string]uint64{
DASignersFunctionUpdateSocket: 50000, DASignersFunctionUpdateSocket: 50000,
DASignersFunctionRegisterNextEpoch: 100000, DASignersFunctionRegisterNextEpoch: 100000,
DASignersFunctionGetAggPkG1: 1000000, DASignersFunctionGetAggPkG1: 1000000,
DASignersFunctionIsSigner: 10000,
DASignersFunctionRegisteredEpoch: 10000,
} }
var KVGasConfig storetypes.GasConfig = storetypes.GasConfig{ 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) bz, err = d.GetQuorum(ctx, evm, method, args)
case DASignersFunctionGetAggPkG1: case DASignersFunctionGetAggPkG1:
bz, err = d.GetAggPkG1(ctx, evm, method, args) 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 // txs
case DASignersFunctionRegisterSigner: case DASignersFunctionRegisterSigner:
bz, err = d.RegisterSigner(ctx, evm, stateDB, method, args) bz, err = d.RegisterSigner(ctx, evm, stateDB, method, args)

View File

@ -1,8 +1,10 @@
package dasigners package dasigners
import ( import (
"fmt"
"math/big" "math/big"
precopmiles_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"
@ -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) { func (d *DASignersPrecompile) QuorumCount(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
req, err := NewQueryQuorumCountRequest(args) req, err := NewQueryQuorumCountRequest(args)
if err != nil {
return nil, err
}
response, err := d.dasignersKeeper.QuorumCount(ctx, req) response, err := d.dasignersKeeper.QuorumCount(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -42,6 +47,31 @@ func (d *DASignersPrecompile) GetSigner(ctx sdk.Context, _ *vm.EVM, method *abi.
return method.Outputs.Pack(signers) 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) { func (d *DASignersPrecompile) GetQuorum(ctx sdk.Context, _ *vm.EVM, method *abi.Method, args []interface{}) ([]byte, error) {
req, err := NewQueryEpochQuorumRequest(args) req, err := NewQueryEpochQuorumRequest(args)
if err != nil { if err != nil {