Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing JSON RPC functions #66

Closed
Prev Previous commit
Next Next commit
Add check for nil ecdsa private key in eth endpoint
  • Loading branch information
Stefan-Ethernal authored and goran-ethernal committed Feb 26, 2024
commit 41100a39c152b599ddc978876cd491b80af50cbe
7 changes: 5 additions & 2 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const (
NativeTokenMintableTestCfg = "Mintable Edge Coin:MEC:18" //nolint:gosec
)

var (
addressRegExp = regexp.MustCompile("\\(address\\) = 0x([a-fA-F0-9]+)")
)

type NodeType int

const (
Expand Down Expand Up @@ -977,8 +981,7 @@ func (c *TestCluster) InitSecrets(prefix string, count int) ([]types.Address, er
return nil, err
}

re := regexp.MustCompile("\\(address\\) = 0x([a-fA-F0-9]+)")
parsed := re.FindAllStringSubmatch(b.String(), -1)
parsed := addressRegExp.FindAllStringSubmatch(b.String(), -1)
result := make([]types.Address, len(parsed))

for i, v := range parsed {
Expand Down
25 changes: 22 additions & 3 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
ethgoWallet "github.com/umbracle/ethgo/wallet"
)

var (
errMissingPrivateKey = errors.New("local private key is undefined")
)

type ethTxPoolStore interface {
// AddTx adds a new transaction to the tx pool
AddTx(tx *types.Transaction) error
Expand Down Expand Up @@ -114,9 +118,16 @@ func NewEth(
chainID uint64,
priceLimit uint64,
txSigner crypto.TxSigner) (*Eth, error) {
ecdsaKey, err := polyWallet.GetEcdsaFromSecret(secretsManager)
if err != nil {
return nil, fmt.Errorf("failed to read account ECDSA key: %w", err)
var (
ecdsaKey *ethgoWallet.Key
err error
)

if secretsManager != nil {
ecdsaKey, err = polyWallet.GetEcdsaFromSecret(secretsManager)
if err != nil {
return nil, fmt.Errorf("failed to read account ECDSA key: %w", err)
}
}

return &Eth{
Expand All @@ -142,6 +153,10 @@ func (e *Eth) ChainId() (interface{}, error) {
}

func (e *Eth) Accounts() (interface{}, error) {
if e.ecdsaKey == nil {
return nil, errMissingPrivateKey
}

return []types.Address{types.Address(e.ecdsaKey.Address())}, nil
}

Expand Down Expand Up @@ -252,6 +267,10 @@ func (e *Eth) SendRawTransaction(buf argBytes) (interface{}, error) {

// SendTransaction rejects eth_sendTransaction json-rpc call as we don't support wallet management
func (e *Eth) SendTransaction(args *txnArgs) (interface{}, error) {
if e.ecdsaKey == nil {
return nil, errMissingPrivateKey
}

if err := args.setDefaults(e.priceLimit, e); err != nil {
return nil, err
}
Expand Down