From 649760d8ea3019691359f6082a888c3663f2bb99 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Fri, 19 Jan 2024 19:17:14 +0200 Subject: [PATCH] Add proper method interfaces for unsupported API methods --- api/api.go | 18 +++++++----------- api/api_test.go | 5 +---- api/fixtures/eth_json_rpc_requests.json | 5 ++++- api/fixtures/eth_json_rpc_responses.json | 5 ++++- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/api/api.go b/api/api.go index f3468eaa4..e99ee0639 100644 --- a/api/api.go +++ b/api/api.go @@ -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") } @@ -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") } diff --git a/api/api_test.go b/api/api_test.go index cd277c0d4..9bc2ee31d 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -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") @@ -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") diff --git a/api/fixtures/eth_json_rpc_requests.json b/api/fixtures/eth_json_rpc_requests.json index da9d4bcea..ee2e6b892 100644 --- a/api/fixtures/eth_json_rpc_requests.json +++ b/api/fixtures/eth_json_rpc_requests.json @@ -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"]} \ No newline at end of file +{"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"}]} \ No newline at end of file diff --git a/api/fixtures/eth_json_rpc_responses.json b/api/fixtures/eth_json_rpc_responses.json index caba6b898..97f91da31 100644 --- a/api/fixtures/eth_json_rpc_responses.json +++ b/api/fixtures/eth_json_rpc_responses.json @@ -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":{}} \ No newline at end of file +{"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"}} \ No newline at end of file