diff --git a/lib/config/dependencies.dart b/lib/config/dependencies.dart index 8b766e75..6beaefe7 100644 --- a/lib/config/dependencies.dart +++ b/lib/config/dependencies.dart @@ -4,7 +4,7 @@ import 'package:sidesail/config/sidechains.dart'; import 'package:sidesail/providers/balance_provider.dart'; import 'package:sidesail/providers/transactions_provider.dart'; import 'package:sidesail/routing/router.dart'; -import 'package:sidesail/rpc/rpc_eth.dart'; +import 'package:sidesail/rpc/rpc_ethereum.dart'; import 'package:sidesail/rpc/rpc_mainchain.dart'; import 'package:sidesail/rpc/rpc_sidechain.dart'; import 'package:sidesail/rpc/rpc_testchain.dart'; @@ -63,14 +63,15 @@ Future setSidechainRPC(Sidechain chain) async { break; case SidechainType.ethereum: - final testchainRPC = await EthereumRPCLive.create(); + final ethRPC = await EthereumRPCLive.create(); if (GetIt.I.isRegistered()) { GetIt.I.unregister(); } GetIt.I.registerLazySingleton( - () => testchainRPC, + () => ethRPC, ); - sidechainRPC = testchainRPC; + + sidechainRPC = ethRPC; break; } diff --git a/lib/rpc/rpc_sidechain.dart b/lib/rpc/rpc_sidechain.dart index c100df68..c36cde3f 100644 --- a/lib/rpc/rpc_sidechain.dart +++ b/lib/rpc/rpc_sidechain.dart @@ -1,39 +1,21 @@ import 'dart:async'; +import 'package:sidesail/config/dependencies.dart'; import 'package:sidesail/config/sidechains.dart'; import 'package:sidesail/rpc/models/core_transaction.dart'; import 'package:sidesail/rpc/rpc.dart'; /// RPC connection for all sidechain nodes abstract class SidechainRPC extends RPCConnection { - Future<(double, double)> getBalance(); - - Future mainSend( - String address, - double amount, - double sidechainFee, - double mainchainFee, - ); - Future mainGenerateAddress(); - Future mainBlockCount(); - - Future sideSend( - String address, - double amount, - bool subtractFeeFromAmount, - ); - Future sideGenerateAddress(); - Future sideBlockCount(); - Future sideEstimateFee(); + Future callRAW(String method, [List? params]); - // TODO: Don't do a CoreTransaction here + Future<(double, double)> getBalance(); Future> listTransactions(); - Future callRAW(String method, [dynamic params]); - late Sidechain chain; void setChain(Sidechain newChain) { chain = newChain; + setSidechainRPC(newChain); notifyListeners(); } } diff --git a/lib/rpc/rpc_testchain.dart b/lib/rpc/rpc_testchain.dart index b8a1f300..0afc11af 100644 --- a/lib/rpc/rpc_testchain.dart +++ b/lib/rpc/rpc_testchain.dart @@ -16,6 +16,24 @@ import 'package:sidesail/rpc/rpc_withdrawal_bundle.dart'; /// RPC connection the sidechain node. abstract class TestchainRPC extends SidechainRPC { + Future mainSend( + String address, + double amount, + double sidechainFee, + double mainchainFee, + ); + Future mainGenerateAddress(); + Future mainBlockCount(); + + Future sideSend( + String address, + double amount, + bool subtractFeeFromAmount, + ); + Future sideGenerateAddress(); + Future sideBlockCount(); + Future sideEstimateFee(); + Future refreshBMM(int bidSatoshis); /// Returns null if there's no current bundle diff --git a/lib/widgets/containers/tabs/dashboard_tab_widgets.dart b/lib/widgets/containers/tabs/dashboard_tab_widgets.dart index 4582d380..4ac8a892 100644 --- a/lib/widgets/containers/tabs/dashboard_tab_widgets.dart +++ b/lib/widgets/containers/tabs/dashboard_tab_widgets.dart @@ -9,7 +9,7 @@ import 'package:sail_ui/widgets/core/sail_text.dart'; import 'package:sidesail/providers/balance_provider.dart'; import 'package:sidesail/providers/transactions_provider.dart'; import 'package:sidesail/routing/router.dart'; -import 'package:sidesail/rpc/rpc_sidechain.dart'; +import 'package:sidesail/rpc/rpc_testchain.dart'; import 'package:sidesail/widgets/containers/dashboard_action_modal.dart'; import 'package:stacked/stacked.dart'; @@ -115,7 +115,7 @@ class SendOnSidechainViewModel extends BaseViewModel { BalanceProvider get _balanceProvider => GetIt.I.get(); TransactionsProvider get _transactionsProvider => GetIt.I.get(); AppRouter get _router => GetIt.I.get(); - SidechainRPC get _rpc => GetIt.I.get(); + TestchainRPC get _rpc => GetIt.I.get(); final bitcoinAddressController = TextEditingController(); final bitcoinAmountController = TextEditingController(); @@ -312,7 +312,7 @@ class ReceiveOnSidechainAction extends StatelessWidget { } class ReceiveOnSidechainViewModel extends BaseViewModel { - SidechainRPC get _rpc => GetIt.I.get(); + TestchainRPC get _rpc => GetIt.I.get(); final log = Logger(level: Level.debug); String? sidechainAddress; diff --git a/lib/widgets/containers/tabs/transfer_mainchain_tab_widgets.dart b/lib/widgets/containers/tabs/transfer_mainchain_tab_widgets.dart index 64773ed1..5bc63543 100644 --- a/lib/widgets/containers/tabs/transfer_mainchain_tab_widgets.dart +++ b/lib/widgets/containers/tabs/transfer_mainchain_tab_widgets.dart @@ -10,7 +10,7 @@ import 'package:sidesail/providers/balance_provider.dart'; import 'package:sidesail/providers/transactions_provider.dart'; import 'package:sidesail/routing/router.dart'; import 'package:sidesail/rpc/rpc_mainchain.dart'; -import 'package:sidesail/rpc/rpc_sidechain.dart'; +import 'package:sidesail/rpc/rpc_testchain.dart'; import 'package:sidesail/widgets/containers/dashboard_action_modal.dart'; import 'package:stacked/stacked.dart'; @@ -68,7 +68,7 @@ class PegOutViewModel extends BaseViewModel { BalanceProvider get _balanceProvider => GetIt.I.get(); TransactionsProvider get _transactionsProvider => GetIt.I.get(); AppRouter get _router => GetIt.I.get(); - SidechainRPC get _testchain => GetIt.I.get(); + TestchainRPC get _testchain => GetIt.I.get(); MainchainRPC get _mainchain => GetIt.I.get(); final bitcoinAddressController = TextEditingController(); @@ -282,7 +282,7 @@ class PegInAction extends StatelessWidget { } class PegInViewModel extends BaseViewModel { - SidechainRPC get _rpc => GetIt.I.get(); + TestchainRPC get _rpc => GetIt.I.get(); final log = Logger(level: Level.debug); String? pegInAddress; diff --git a/test/mocks/rpc_mock_sidechain.dart b/test/mocks/rpc_mock_sidechain.dart index f9df25d0..98828556 100644 --- a/test/mocks/rpc_mock_sidechain.dart +++ b/test/mocks/rpc_mock_sidechain.dart @@ -7,11 +7,6 @@ class MockSidechainRPC extends SidechainRPC { chain = TestSidechain(); } - @override - Future mainGenerateAddress() async { - return 'bc1...?'; - } - @override Future<(double, double)> getBalance() async { return (1.12345678, 2.24680); @@ -22,41 +17,6 @@ class MockSidechainRPC extends SidechainRPC { return; } - @override - Future sideEstimateFee() async { - return 0.001; - } - - @override - Future sideGenerateAddress() async { - return 's1deadbeef'; - } - - @override - Future mainSend(String address, double amount, double sidechainFee, double mainchainFee) async { - return 'txidmainbeef'; - } - - @override - Future sideSend(String address, double amount, bool subtractFeeFromAmount) async { - return 'txidsidebeef'; - } - - @override - Future> listTransactions() async { - return List.empty(); - } - - @override - Future sideBlockCount() async { - return 1; - } - - @override - Future mainBlockCount() async { - return 1; - } - @override Future<(bool, String?)> testConnection() async { return (true, null); @@ -71,4 +31,9 @@ class MockSidechainRPC extends SidechainRPC { Future ping() async { return; } + + @override + Future> listTransactions() async { + return List.empty(); + } }