-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac16921
commit 175eaa7
Showing
8 changed files
with
132 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:dart_coin_rpc/dart_coin_rpc.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:sidesail/rpc/rpc_config.dart'; | ||
|
||
/// RPC connection to the mainchain node. | ||
abstract class MainchainRPC { | ||
Future<double> estimateFee(); | ||
} | ||
|
||
class MainchainRPCLive implements MainchainRPC { | ||
late RPCClient _client; | ||
MainchainRPCLive(Config config) { | ||
_client = RPCClient( | ||
host: config.host, | ||
port: config.port, | ||
username: config.username, | ||
password: config.password, | ||
useSSL: false, | ||
); | ||
|
||
// Completely empty client, with no retry logic. | ||
_client.dioClient = Dio(); | ||
} | ||
|
||
@override | ||
Future<double> estimateFee() async { | ||
final estimate = await _client.call('estimatesmartfee', [6]) as Map<String, dynamic>; | ||
if (estimate.containsKey('errors')) { | ||
// 10 sats/byte | ||
return 0.001; | ||
} | ||
|
||
final btcPerKb = estimate['feerate'] as double; | ||
|
||
// who knows! | ||
const kbyteInTx = 5; | ||
return btcPerKb * kbyteInTx; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:sidesail/rpc/rpc_mainchain.dart'; | ||
|
||
class MockMainchainRPC extends MainchainRPC { | ||
@override | ||
Future<double> estimateFee() async { | ||
return 0.001; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters