From 7a86554c9428d51911733e2334a54e996d8c9ba1 Mon Sep 17 00:00:00 2001 From: Torkel Rogstad Date: Mon, 13 Nov 2023 08:57:39 +0100 Subject: [PATCH] eth: enable personal API in Docker node, give proper error message --- docker-compose.yml | 7 ++++++- lib/rpc/rpc_ethereum.dart | 32 +++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7aecd9cc..f2fc853a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,7 +56,12 @@ services: - 8551:8551 # Authenticated RPC command: - --http # enable HTTP RPC - - --http.addr=0.0.0.0 # TODO: add auth config? --authrpc.jwtsecret, --authrpc.addr=0.0.0.0, --authrpc.vhosts=* + # 'personal' API is needed for replicating the old ETH tutorial + # made by Paul. Think it's some sort of wallet functionality? Not sure, + # tbh. Went looking for a list of available APIs, without finding + # anything. + # - --http.api=net,eth,personal,web3 + - --http.addr=0.0.0.0 - --main.host=mainchain - --main.password=password - --main.user=user diff --git a/lib/rpc/rpc_ethereum.dart b/lib/rpc/rpc_ethereum.dart index 71bea766..d2840de4 100644 --- a/lib/rpc/rpc_ethereum.dart +++ b/lib/rpc/rpc_ethereum.dart @@ -4,6 +4,7 @@ import 'package:sidesail/pages/tabs/settings/node_settings_tab.dart'; import 'package:sidesail/rpc/models/core_transaction.dart'; import 'package:sidesail/rpc/rpc_sidechain.dart'; import 'package:web3dart/web3dart.dart'; +import 'package:web3dart/json_rpc.dart' as jsonrpc; abstract class EthereumRPC extends SidechainSubRPC { EthereumAddress? account; @@ -17,7 +18,16 @@ class EthereumRPCLive extends EthereumRPC { @override Future callRAW(String method, [params]) async { - return _client.makeRPCCall(method, params); + try { + final res = await _client.makeRPCCall(method, params); + return res; + } on jsonrpc.RPCError catch (err) { + const magicErrCode = -32601; // no clue what this is + if (err.errorCode == magicErrCode && method.startsWith('personal')) { + throw "The 'personal' API is not enabled on your Ethereum node. Add the \n`--http.api=personal` argument, and try again."; + } + rethrow; + } } // Apparently Ethereum doesn't have a conf file? @@ -82,11 +92,11 @@ class EthereumRPCLive extends EthereumRPC { @override Future newAccount() async { - final accountFut = await callRAW('personal_newAccount', ['passphrase', 'passphrase']); + final accountFut = await callRAW('personal_newAccount', ['passphrase']); final accountStr = await accountFut as String; if (accountStr.isEmpty) { - throw Exception('Could not create account. Try using cli with personal.newAccount'); + throw Exception('Could not create account. Try using CLI with personal.newAccount'); } account = EthereumAddress.fromHex(accountStr); @@ -156,6 +166,22 @@ final ethRpcMethods = [ 'eth_getFilterLogs', 'eth_getLogs', + // Wallet (?) stuff + 'personal_newAccount', + 'personal_importRawKey', + 'personal_unlockAccount', + 'personal_ecRecover', + 'personal_sign', + 'personal_sendTransaction', + 'personal_lockAccount', + 'personal_listAccounts', + 'personal_openWallet', + 'personal_deriveAccount', + 'personal_signTransaction', + 'personal_unpair', + 'personal_initializeWallet', + 'personal_listWallets', + // Sidechain specific RPC calls 'eth_deposit', 'eth_withdraw',