From 36e4ece76fcb2a369e964e2575f21bacadabe287 Mon Sep 17 00:00:00 2001 From: Toshihiko Okubo Date: Wed, 1 Dec 2021 11:55:32 +0900 Subject: [PATCH] move keyStore to the keyring package --- web3-gateway/evm/native_contract.go | 6 +++--- web3-gateway/{acm => keyring}/key_store.go | 2 +- web3-gateway/rpc/eth.go | 17 ++++------------- web3-gateway/rpc/serve.go | 3 ++- 4 files changed, 10 insertions(+), 18 deletions(-) rename web3-gateway/{acm => keyring}/key_store.go (99%) diff --git a/web3-gateway/evm/native_contract.go b/web3-gateway/evm/native_contract.go index 5171e92..9775b06 100644 --- a/web3-gateway/evm/native_contract.go +++ b/web3-gateway/evm/native_contract.go @@ -13,8 +13,8 @@ import ( pb "github.com/datachainlab/iroha-ibc-modules/iroha-go/iroha.generated/protocol" "github.com/datachainlab/iroha-ibc-modules/iroha-go/query" - "github.com/datachainlab/iroha-ibc-modules/web3-gateway/acm" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha/db" + "github.com/datachainlab/iroha-ibc-modules/web3-gateway/keyring" ) var ( @@ -322,14 +322,14 @@ type callContext struct { queryClient query.QueryClient dbClient db.DBClient querierAccountID string - keyStore acm.KeyStore + keyStore keyring.KeyStore } func RegisterCallContext( queryClient query.QueryClient, dbClient db.DBClient, querierAccountID string, - keyStore acm.KeyStore, + keyStore keyring.KeyStore, ) *callContext { once.Do(func() { callCtx = &callContext{ diff --git a/web3-gateway/acm/key_store.go b/web3-gateway/keyring/key_store.go similarity index 99% rename from web3-gateway/acm/key_store.go rename to web3-gateway/keyring/key_store.go index 0509646..c7e39ce 100644 --- a/web3-gateway/acm/key_store.go +++ b/web3-gateway/keyring/key_store.go @@ -1,4 +1,4 @@ -package acm +package keyring import ( "errors" diff --git a/web3-gateway/rpc/eth.go b/web3-gateway/rpc/eth.go index 785385b..e9d5a6b 100644 --- a/web3-gateway/rpc/eth.go +++ b/web3-gateway/rpc/eth.go @@ -22,6 +22,7 @@ import ( "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha/db" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha/db/entity" + "github.com/datachainlab/iroha-ibc-modules/web3-gateway/keyring" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/util" ) @@ -36,7 +37,7 @@ var _ web3.Service = (*EthService)(nil) type EthService struct { accountState *acm.AccountState - keyStore acm.KeyStore + keyStore keyring.KeyStore irohaClient *iroha.Client logger *logging.Logger querier string @@ -44,7 +45,7 @@ type EthService struct { func NewEthService( accountState *acm.AccountState, - keyStore acm.KeyStore, + keyStore keyring.KeyStore, irohaClient *iroha.Client, logger *logging.Logger, querier string, @@ -163,24 +164,14 @@ func (e EthService) EthGetBlockByNumber(params *web3.EthGetBlockByNumberParams) var err error if params.BlockNumber == "latest" || params.BlockNumber == "pending" { height, err = e.irohaClient.GetLatestHeight() - if err != nil { - return nil, err - } } else { height, err = strconv.ParseUint(x.RemovePrefix(params.BlockNumber), 16, 64) - if err != nil { - return nil, err - } } - if err != nil { return nil, err } - q := query.GetBlock( - height, - query.CreatorAccountId(e.querier), - ) + q := query.GetBlock(height, query.CreatorAccountId(e.querier)) _, err = e.keyStore.SignQuery(q, e.querier) if err != nil { diff --git a/web3-gateway/rpc/serve.go b/web3-gateway/rpc/serve.go index 1ca819f..babc0c6 100644 --- a/web3-gateway/rpc/serve.go +++ b/web3-gateway/rpc/serve.go @@ -20,6 +20,7 @@ import ( "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha/api" "github.com/datachainlab/iroha-ibc-modules/web3-gateway/iroha/db/postgres" + "github.com/datachainlab/iroha-ibc-modules/web3-gateway/keyring" ) func Serve(cfg *config.Config) error { @@ -35,7 +36,7 @@ func Serve(cfg *config.Config) error { return err } - keyStore := acm.NewKeyStore() + keyStore := keyring.NewKeyStore() accountState := acm.NewAccountState(accountDB) for _, account := range cfg.Accounts { if err = accountState.Add(account.ID, account.PrivateKey); err != nil {