feat: evm precompile query func

This commit is contained in:
MiniFrenchBread 2024-08-12 18:39:13 +08:00
parent 550fdc331e
commit da02dc7eb7
2 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,7 @@ const (
RequiredGasMax uint64 = 1000_000_000
DASignersFunctionParams = "params"
DASignersFunctionEpochNumber = "epochNumber"
DASignersFunctionQuorumCount = "quorumCount"
DASignersFunctionGetSigner = "getSigner"
@ -32,6 +33,7 @@ const (
)
var RequiredGasBasic = map[string]uint64{
DASignersFunctionParams: 1000,
DASignersFunctionEpochNumber: 1000,
DASignersFunctionQuorumCount: 1000,
DASignersFunctionGetSigner: 100000,
@ -117,6 +119,8 @@ func (d *DASignersPrecompile) Run(evm *vm.EVM, contract *vm.Contract, readonly b
var bz []byte
switch method.Name {
// queries
case DASignersFunctionParams:
bz, err = d.Params(ctx, evm, method, args)
case DASignersFunctionEpochNumber:
bz, err = d.EpochNumber(ctx, evm, method, args)
case DASignersFunctionQuorumCount:

View File

@ -11,6 +11,17 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
)
func (d *DASignersPrecompile) Params(ctx sdk.Context, _ *vm.EVM, method *abi.Method, _ []interface{}) ([]byte, error) {
params := d.dasignersKeeper.GetParams(ctx)
return method.Outputs.Pack(IDASignersParams{
TokensPerVote: big.NewInt(int64(params.TokensPerVote)),
MaxVotesPerSigner: big.NewInt(int64(params.MaxVotesPerSigner)),
MaxQuorums: big.NewInt(int64(params.MaxQuorums)),
EpochBlocks: big.NewInt(int64(params.EpochBlocks)),
EncodedSlices: big.NewInt(int64(params.EncodedSlices)),
})
}
func (d *DASignersPrecompile) EpochNumber(ctx sdk.Context, _ *vm.EVM, method *abi.Method, _ []interface{}) ([]byte, error) {
epochNumber, err := d.dasignersKeeper.GetEpochNumber(ctx)
if err != nil {