Skip to content

Commit

Permalink
move keyStore to the keyring package
Browse files Browse the repository at this point in the history
  • Loading branch information
toshihiko-okubo committed Dec 1, 2021
1 parent fc41ece commit 36e4ece
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
6 changes: 3 additions & 3 deletions web3-gateway/evm/native_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package acm
package keyring

import (
"errors"
Expand Down
17 changes: 4 additions & 13 deletions web3-gateway/rpc/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -36,15 +37,15 @@ 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
}

func NewEthService(
accountState *acm.AccountState,
keyStore acm.KeyStore,
keyStore keyring.KeyStore,
irohaClient *iroha.Client,
logger *logging.Logger,
querier string,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion web3-gateway/rpc/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 36e4ece

Please sign in to comment.