Skip to content

Commit

Permalink
Add proper method interfaces for unsupported API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Jan 19, 2024
1 parent 8ffa586 commit 649760d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
18 changes: 7 additions & 11 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,20 +565,18 @@ func (s *BlockChainAPI) Accounts() []common.Address {
}

// eth_sign
// Sign calculates an Ethereum ECDSA signature for:
// keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
// Sign calculates an ECDSA signature for:
// keccak256("\x19Ethereum Signed Message:\n" + len(message) + message).
//
// Note, the produced signature conforms to the secp256k1 curve R, S and V values,
// where the V value will be 27 or 28 for legacy reasons.
//
// The key used to calculate the signature is decrypted with the given password.
// The account associated with addr must be unlocked.
//
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
func (s *BlockChainAPI) Sign(
ctx context.Context,
addr common.Address,
data hexutil.Bytes,
address common.Address,
password string,
) (hexutil.Bytes, error) {
return hexutil.Bytes{}, fmt.Errorf("not implemented")
}
Expand All @@ -595,13 +593,11 @@ func (s *BlockChainAPI) SignTransaction(
}

// eth_sendTransaction
// SendTransaction will create a transaction from the given arguments and
// tries to sign it with the key associated with args.From. If the given
// passwd isn't able to decrypt the key it fails.
// SendTransaction creates a transaction for the given argument, sign it
// and submit it to the transaction pool.
func (s *BlockChainAPI) SendTransaction(
ctx context.Context,
args TransactionArgs,
password string,
) (common.Hash, error) {
return common.Hash{}, fmt.Errorf("not implemented")
}
Expand Down
5 changes: 1 addition & 4 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,8 @@ func TestBlockChainAPI(t *testing.T) {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
_, err := blockchainAPI.Sign(
context.Background(),
hexutil.Bytes{1, 2, 3, 4, 5},
addr,
"secret_password",
hexutil.Bytes{1, 2, 3, 4, 5},
)
require.Error(t, err)
assert.ErrorContains(t, err, "not implemented")
Expand Down Expand Up @@ -571,7 +569,6 @@ func TestBlockChainAPI(t *testing.T) {
To: &to.addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
},
"secret_password",
)
require.Error(t, err)
assert.ErrorContains(t, err, "not implemented")
Expand Down
5 changes: 4 additions & 1 deletion api/fixtures/eth_json_rpc_requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
{"jsonrpc":"2.0","id":29,"method":"eth_call","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]}
{"jsonrpc":"2.0","id":30,"method":"eth_estimateGas","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]}
{"jsonrpc":"2.0","id":31,"method":"eth_getUncleByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x45"]}
{"jsonrpc":"2.0","id":32,"method":"eth_getUncleByBlockNumberAndIndex","params":["0xe8", "0x45"]}
{"jsonrpc":"2.0","id":32,"method":"eth_getUncleByBlockNumberAndIndex","params":["0xe8", "0x45"]}
{"jsonrpc":"2.0","id":33,"method":"eth_sign","params":["0x9b2055d370f73ec7d8a03e965129118dc8f5bf83","0xdeadbeaf"]}
{"jsonrpc":"2.0","id":34,"method":"eth_signTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]}
{"jsonrpc":"2.0","id":35,"method":"eth_sendTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]}
5 changes: 4 additions & 1 deletion api/fixtures/eth_json_rpc_responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
{"jsonrpc":"2.0","id":29,"result":"0x00010203040506070809"}
{"jsonrpc":"2.0","id":30,"result":"0x69"}
{"jsonrpc":"2.0","id":31,"result":{}}
{"jsonrpc":"2.0","id":32,"result":{}}
{"jsonrpc":"2.0","id":32,"result":{}}
{"jsonrpc":"2.0","id":33,"error":{"code":-32000,"message":"not implemented"}}
{"jsonrpc":"2.0","id":34,"error":{"code":-32000,"message":"not implemented"}}
{"jsonrpc":"2.0","id":35,"error":{"code":-32000,"message":"not implemented"}}

0 comments on commit 649760d

Please sign in to comment.