Skip to content

Commit

Permalink
eth: enable personal API in Docker node, give proper error message
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad committed Nov 13, 2023
1 parent 943cc00 commit 7a86554
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions lib/rpc/rpc_ethereum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +18,16 @@ class EthereumRPCLive extends EthereumRPC {

@override
Future<dynamic> 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?
Expand Down Expand Up @@ -82,11 +92,11 @@ class EthereumRPCLive extends EthereumRPC {

@override
Future<void> 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);
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 7a86554

Please sign in to comment.