From c6e8e684962e0e1b2fa266e0d32442265d911bf2 Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Fri, 9 May 2025 10:48:17 +0100 Subject: [PATCH 1/6] Issue 23 - reformat for Dart 3.7 --- analysis_options.yaml | 17 + lib/ethereum_browser_http_client.dart | 13 +- lib/ethereum_browser_ws_client.dart | 8 +- lib/ethereum_server_client.dart | 8 +- .../ethereum_browser_http_adapter.dart | 25 +- .../adapters/ethereum_browser_ws_adapter.dart | 10 +- .../adapters/ethereum_inetwork_adapter.dart | 4 +- .../ethereum_server_http_adapter.dart | 18 +- lib/src/api/ethereum_api_admin.dart | 61 +- lib/src/api/ethereum_api_eth.dart | 216 ++-- lib/src/datatypes/ethereum_address.dart | 10 +- lib/src/datatypes/ethereum_data.dart | 4 +- lib/src/ethereum.dart | 15 +- lib/src/ethereum_utilities.dart | 3 +- lib/src/messages/ethereum_block.dart | 69 +- lib/src/messages/ethereum_filter.dart | 2 +- lib/src/messages/ethereum_log.dart | 31 +- lib/src/messages/ethereum_sync_status.dart | 9 +- lib/src/messages/ethereum_transaction.dart | 38 +- .../ethereum_transaction_receipt.dart | 37 +- lib/src/messages/ethereum_work.dart | 3 +- pubspec.yaml | 2 +- test/ethereum_base_test.dart | 946 ++++++++++++------ test/manual/ethereum_browser_http.dart | 5 +- test/manual/ethereum_browser_ws.dart | 6 +- test/manual/ethereum_common.dart | 470 +++++---- test/manual/ethereum_test_utilities.dart | 8 +- 27 files changed, 1311 insertions(+), 727 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index aadd8cb..91b6bee 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,3 +8,20 @@ include: package:lints/recommended.yaml analyzer: exclude: - test/issues/** + +dart_code_metrics: + exclude: + metrics: + - test/** + - example/** + rules: + - test/** + - example/** + extends: + - package:dart_code_metrics_presets/dart_all.yaml + rules: + - avoid-dynamic : false + - avoid-non-null-assertion : false + - newline-before-return : false + - avoid-late-keyword : false + - prefer-match-file-name : false diff --git a/lib/ethereum_browser_http_client.dart b/lib/ethereum_browser_http_client.dart index ecb0828..c30b336 100644 --- a/lib/ethereum_browser_http_client.dart +++ b/lib/ethereum_browser_http_client.dart @@ -23,10 +23,15 @@ class EthereumBrowserHTTPClient extends Ethereum { EthereumBrowserHTTPClient() : super(browserHttpAdapter); /// With connection parameters - EthereumBrowserHTTPClient.withConnectionParameters(String hostname, - [int? port]) - : super.withConnectionParameters( - browserHttpAdapter, hostname, Ethereum.rpcHttpScheme, port); + EthereumBrowserHTTPClient.withConnectionParameters( + String hostname, [ + int? port, + ]) : super.withConnectionParameters( + browserHttpAdapter, + hostname, + Ethereum.rpcHttpScheme, + port, + ); /// The adapter static EthereumBrowserHTTPAdapter browserHttpAdapter = diff --git a/lib/ethereum_browser_ws_client.dart b/lib/ethereum_browser_ws_client.dart index 03dc167..e54b900 100644 --- a/lib/ethereum_browser_ws_client.dart +++ b/lib/ethereum_browser_ws_client.dart @@ -25,8 +25,12 @@ class EthereumBrowserWSClient extends Ethereum { /// With connection parameters EthereumBrowserWSClient.withConnectionParameters(String hostname, [int? port]) - : super.withConnectionParameters( - browserWSAdapter, hostname, Ethereum.rpcWsScheme, port); + : super.withConnectionParameters( + browserWSAdapter, + hostname, + Ethereum.rpcWsScheme, + port, + ); /// The adapter static EthereumBrowserWSAdapter browserWSAdapter = EthereumBrowserWSAdapter(); diff --git a/lib/ethereum_server_client.dart b/lib/ethereum_server_client.dart index b7aaf5d..26847f6 100644 --- a/lib/ethereum_server_client.dart +++ b/lib/ethereum_server_client.dart @@ -23,8 +23,12 @@ class EthereumServerClient extends Ethereum { /// With connection parameters EthereumServerClient.withConnectionParameters(String hostname, [int? port]) - : super.withConnectionParameters( - serverHttpAdapter, hostname, Ethereum.rpcHttpScheme, port); + : super.withConnectionParameters( + serverHttpAdapter, + hostname, + Ethereum.rpcHttpScheme, + port, + ); /// The adapter static EthereumServerHTTPAdapter serverHttpAdapter = diff --git a/lib/src/adapters/ethereum_browser_http_adapter.dart b/lib/src/adapters/ethereum_browser_http_adapter.dart index 465ddad..b45544b 100644 --- a/lib/src/adapters/ethereum_browser_http_adapter.dart +++ b/lib/src/adapters/ethereum_browser_http_adapter.dart @@ -25,18 +25,25 @@ class EthereumBrowserHTTPAdapter implements EthereumINetworkAdapter { /// a JSON Object @override Future> httpRequest( - Uri uri, Map request) { + Uri uri, + Map request, + ) { final completer = Completer>(); final reqText = json.encode(request); final headers = {contentType: jsonMimeType}; - BrowserClient().post(uri, headers: headers, body: reqText).then((req) { - final Map resp = json.decode(req.body); - completer.complete(resp); - return completer.future; - }, onError: (final error) { - completer.complete({}); - return completer.future; - }); + BrowserClient() + .post(uri, headers: headers, body: reqText) + .then( + (req) { + final Map resp = json.decode(req.body); + completer.complete(resp); + return completer.future; + }, + onError: (final error) { + completer.complete({}); + return completer.future; + }, + ); return completer.future; } } diff --git a/lib/src/adapters/ethereum_browser_ws_adapter.dart b/lib/src/adapters/ethereum_browser_ws_adapter.dart index c41e40c..47ee07b 100644 --- a/lib/src/adapters/ethereum_browser_ws_adapter.dart +++ b/lib/src/adapters/ethereum_browser_ws_adapter.dart @@ -14,7 +14,9 @@ part of '../../ethereum_browser_ws_client.dart'; class EthereumBrowserWSAdapter implements EthereumINetworkAdapter { @override Future> httpRequest( - Uri uri, Map request) { + Uri uri, + Map request, + ) { final completer = Completer>(); final webSocket = WebSocket(uri.toString()); final message = json.encode(request); @@ -22,8 +24,10 @@ class EthereumBrowserWSAdapter implements EthereumINetworkAdapter { webSocket.send(message.jsify()!); }); webSocket.onError.listen((Event e) { - print('EthereumBrowserWSAdapter::WebSocket error, message not sent, ' - 'state is ${webSocket.readyState.toString()}'); + print( + 'EthereumBrowserWSAdapter::WebSocket error, message not sent, ' + 'state is ${webSocket.readyState.toString()}', + ); webSocket.close(); completer.complete({}); }); diff --git a/lib/src/adapters/ethereum_inetwork_adapter.dart b/lib/src/adapters/ethereum_inetwork_adapter.dart index 2cb879f..f54b82f 100644 --- a/lib/src/adapters/ethereum_inetwork_adapter.dart +++ b/lib/src/adapters/ethereum_inetwork_adapter.dart @@ -18,5 +18,7 @@ abstract class EthereumINetworkAdapter { /// Processes the HTTP request returning the HTTP response as /// a map Future> httpRequest( - Uri uri, Map request); + Uri uri, + Map request, + ); } diff --git a/lib/src/adapters/ethereum_server_http_adapter.dart b/lib/src/adapters/ethereum_server_http_adapter.dart index cbfe88c..f7c3a37 100644 --- a/lib/src/adapters/ethereum_server_http_adapter.dart +++ b/lib/src/adapters/ethereum_server_http_adapter.dart @@ -19,7 +19,9 @@ class EthereumServerHTTPAdapter implements EthereumINetworkAdapter { /// a map @override Future> httpRequest( - Uri uri, Map request) { + Uri uri, + Map request, + ) { final client = HttpClient(); final completer = Completer>(); client.postUrl(uri).then((HttpClientRequest req) { @@ -28,14 +30,12 @@ class EthereumServerHTTPAdapter implements EthereumINetworkAdapter { req.contentLength = payload.length; req.write(payload); req.close().then((HttpClientResponse resp) { - resp.listen( - (dynamic data) { - final Map? payload = - json.decode(String.fromCharCodes(data)); - completer.complete(payload); - }, - onError: print, - ); + resp.listen((dynamic data) { + final Map? payload = json.decode( + String.fromCharCodes(data), + ); + completer.complete(payload); + }, onError: print); }); }, onError: print); return completer.future; diff --git a/lib/src/api/ethereum_api_admin.dart b/lib/src/api/ethereum_api_admin.dart index 79925f8..99e8b06 100644 --- a/lib/src/api/ethereum_api_admin.dart +++ b/lib/src/api/ethereum_api_admin.dart @@ -17,13 +17,16 @@ class EthereumApiAdmin extends EthereumApi { /// Imports the given unencrypted private key (byte string) /// into the key store, encrypting it with the passphrase. Future personalImportRawKey( - String? keydata, String? passphrase) async { + String? keydata, + String? passphrase, + ) async { if (keydata == null) { throw ArgumentError.notNull('Ethereum::personalImportRawKey - keydata'); } if (passphrase == null) { throw ArgumentError.notNull( - 'Ethereum::personalImportRawKey - passphrase'); + 'Ethereum::personalImportRawKey - passphrase', + ); } const method = EthereumRpcMethods.importRawKey; final params = [keydata, passphrase]; @@ -41,7 +44,8 @@ class EthereumApiAdmin extends EthereumApi { final dynamic res = await _client.rpcClient.request(method); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { return EthereumAddress.toList( - res[EthereumConstants.ethResultKey].cast()); + res[EthereumConstants.ethResultKey].cast(), + ); } _client.processError(method, res); return null; @@ -88,14 +92,17 @@ class EthereumApiAdmin extends EthereumApi { /// The account can be used with eth_sign and eth_sendTransaction /// while it is unlocked. Future personalUnlockAccount( - EthereumAddress? address, String? passphrase, - [int duration = 300]) async { + EthereumAddress? address, + String? passphrase, [ + int duration = 300, + ]) async { if (address == null) { throw ArgumentError.notNull('Ethereum::personalUnlockAccount - address'); } if (passphrase == null) { throw ArgumentError.notNull( - 'Ethereum::personalUnlockAccount - passphrase'); + 'Ethereum::personalUnlockAccount - passphrase', + ); } final paramDuration = duration; const method = EthereumRpcMethods.unlockAccount; @@ -122,22 +129,26 @@ class EthereumApiAdmin extends EthereumApi { /// The account is not unlocked globally in the node and cannot be /// used in other RPC calls. Future personalSendTransaction( - EthereumAddress? address, String? passphrase, - {EthereumAddress? to, - EthereumAddress? data, - int? gas, - int? gasPrice, - int? value, - int? nonce, - int? condition, - bool conditionIsTimestamp = false}) async { + EthereumAddress? address, + String? passphrase, { + EthereumAddress? to, + EthereumAddress? data, + int? gas, + int? gasPrice, + int? value, + int? nonce, + int? condition, + bool conditionIsTimestamp = false, + }) async { if (address == null) { throw ArgumentError.notNull( - 'Ethereum::personalSendTransaction - address'); + 'Ethereum::personalSendTransaction - address', + ); } if (passphrase == null) { throw ArgumentError.notNull( - 'Ethereum::personalSendTransaction - passphrase'); + 'Ethereum::personalSendTransaction - passphrase', + ); } Map? conditionObject = {}; if (condition == null) { @@ -145,11 +156,11 @@ class EthereumApiAdmin extends EthereumApi { } else { if (conditionIsTimestamp) { conditionObject = { - 'timestamp': EthereumUtilities.intToHex(condition) + 'timestamp': EthereumUtilities.intToHex(condition), }; } else { conditionObject = { - 'block': EthereumUtilities.intToHex(condition) + 'block': EthereumUtilities.intToHex(condition), }; } } @@ -162,7 +173,7 @@ class EthereumApiAdmin extends EthereumApi { 'value': value == null ? null : EthereumUtilities.intToHex(value), 'data': data?.asString, 'nonce': nonce == null ? null : EthereumUtilities.intToHex(nonce), - 'condition': conditionObject + 'condition': conditionObject, }; const method = EthereumRpcMethods.psendTransaction; final dynamic params = [paramBlock, passphrase]; @@ -182,8 +193,10 @@ class EthereumApiAdmin extends EthereumApi { /// (e.g. transaction) and use the signature to impersonate the victim. /// See personalEcRecover to verify the signature. Future personalSign( - EthereumData? message, EthereumAddress? address, - [String password = '']) async { + EthereumData? message, + EthereumAddress? address, [ + String password = '', + ]) async { if (message == null) { throw ArgumentError.notNull('Ethereum::personalSign - message'); } @@ -203,7 +216,9 @@ class EthereumApiAdmin extends EthereumApi { /// Returns the address associated with the private key that was used to /// calculate the signature in personal_sign. Future personalEcRecover( - EthereumData? message, EthereumData? signature) async { + EthereumData? message, + EthereumData? signature, + ) async { if (message == null) { throw ArgumentError.notNull('Ethereum::personalEcRecover - message'); } diff --git a/lib/src/api/ethereum_api_eth.dart b/lib/src/api/ethereum_api_eth.dart index cfdd98d..d4c9ff6 100644 --- a/lib/src/api/ethereum_api_eth.dart +++ b/lib/src/api/ethereum_api_eth.dart @@ -147,7 +147,8 @@ class EthereumApiEth extends EthereumApi { final dynamic res = await _client.rpcClient.request(method); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { return EthereumAddress.toList( - res[EthereumConstants.ethResultKey].cast()); + res[EthereumConstants.ethResultKey].cast(), + ); } _client.processError(method, res); return null; @@ -166,7 +167,9 @@ class EthereumApiEth extends EthereumApi { /// Get balance, the balance of the account of the given address. Future getBalance( - EthereumAddress? address, EthereumDefaultBlock? block) async { + EthereumAddress? address, + EthereumDefaultBlock? block, + ) async { if (address == null) { throw ArgumentError.notNull('Ethereum::getBalance - address'); } @@ -188,7 +191,10 @@ class EthereumApiEth extends EthereumApi { /// Parameters are the address of the storage, the integer position /// of the storage and the default block parameter. Future getStorageAt( - EthereumAddress? address, int? pos, EthereumDefaultBlock? block) async { + EthereumAddress? address, + int? pos, + EthereumDefaultBlock? block, + ) async { if (address == null) { throw ArgumentError.notNull('Ethereum::getStorageAt - address'); } @@ -203,7 +209,7 @@ class EthereumApiEth extends EthereumApi { final params = [ address.asString, EthereumUtilities.intToHex(pos), - blockString + blockString, ]; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { @@ -216,7 +222,9 @@ class EthereumApiEth extends EthereumApi { /// Transaction count, returns the number of transactions sent /// from an address. Future getTransactionCount( - EthereumAddress? address, EthereumDefaultBlock? block) async { + EthereumAddress? address, + EthereumDefaultBlock? block, + ) async { if (address == null) { throw ArgumentError.notNull('Ethereum::getTransactionCount - address'); } @@ -242,7 +250,8 @@ class EthereumApiEth extends EthereumApi { Future getBlockTransactionCountByHash(EthereumData? blockHash) async { if (blockHash == null) { throw ArgumentError.notNull( - 'Ethereum::getBlockTransactionCountByHash - blockHash'); + 'Ethereum::getBlockTransactionCountByHash - blockHash', + ); } const method = EthereumRpcMethods.blockTransactionCountByHash; final params = [blockHash.asString]; @@ -263,10 +272,12 @@ class EthereumApiEth extends EthereumApi { /// If the method returns null a count of 0 is returned, this is to /// distinguish between this and an error. Future getBlockTransactionCountByNumber( - EthereumDefaultBlock? blockNumber) async { + EthereumDefaultBlock? blockNumber, + ) async { if (blockNumber == null) { throw ArgumentError.notNull( - 'Ethereum::getBlockTransactionCountByNumber - blockNumber'); + 'Ethereum::getBlockTransactionCountByNumber - blockNumber', + ); } const method = EthereumRpcMethods.blockTransactionCountByNumber; final blockString = blockNumber.getSelection(); @@ -313,7 +324,8 @@ class EthereumApiEth extends EthereumApi { Future getUncleCountByNumber(EthereumDefaultBlock? blockNumber) async { if (blockNumber == null) { throw ArgumentError.notNull( - 'Ethereum::getUncleCountByNumber - blockNumber'); + 'Ethereum::getUncleCountByNumber - blockNumber', + ); } const method = EthereumRpcMethods.blockUncleCountByBlockNumber; final blockString = blockNumber.getSelection(); @@ -332,7 +344,9 @@ class EthereumApiEth extends EthereumApi { /// Get code, the code at the given address. Future getCode( - EthereumAddress? address, EthereumDefaultBlock? block) async { + EthereumAddress? address, + EthereumDefaultBlock? block, + ) async { if (address == null) { throw ArgumentError.notNull('Ethereum::getCode - address'); } @@ -355,7 +369,9 @@ class EthereumApiEth extends EthereumApi { /// sign(keccak256('\x19Ethereum Signed Message:\n' + len(message) + message))). /// Note the address to sign with must be unlocked. Future sign( - EthereumAddress? account, EthereumData? message) async { + EthereumAddress? account, + EthereumData? message, + ) async { if (account == null) { throw ArgumentError.notNull('Ethereum::sign - account'); } @@ -392,12 +408,14 @@ class EthereumApiEth extends EthereumApi { /// Returns the transaction hash, or the zero hash if the /// transaction is not yet available. Future sendTransaction( - EthereumAddress? address, EthereumData? data, - {EthereumAddress? to, - int gas = 9000, - int? gasPrice, - int? value, - int? nonce}) async { + EthereumAddress? address, + EthereumData? data, { + EthereumAddress? to, + int gas = 9000, + int? gasPrice, + int? value, + int? nonce, + }) async { if (address == null) { throw ArgumentError.notNull('Ethereum::sendTransaction - address'); } @@ -413,7 +431,7 @@ class EthereumApiEth extends EthereumApi { gasPrice == null ? null : EthereumUtilities.intToHex(gasPrice), 'value': value == null ? null : EthereumUtilities.intToHex(value), 'data': data.asString, - 'nonce': nonce == null ? null : EthereumUtilities.intToHex(nonce) + 'nonce': nonce == null ? null : EthereumUtilities.intToHex(nonce), }; paramBlock = EthereumUtilities.removeNull(paramBlock) as Map; @@ -433,10 +451,12 @@ class EthereumApiEth extends EthereumApi { /// Returns the transaction hash, or the zero hash if the transaction /// is not yet available. Future sendRawTransaction( - EthereumData? signedTransaction) async { + EthereumData? signedTransaction, + ) async { if (signedTransaction == null) { throw ArgumentError.notNull( - 'Ethereum::sendRawTransaction - signedTransaction'); + 'Ethereum::sendRawTransaction - signedTransaction', + ); } const method = EthereumRpcMethods.sendRawTransaction; final dynamic params = [signedTransaction.asString]; @@ -464,12 +484,14 @@ class EthereumApiEth extends EthereumApi { /// block: default block parameter /// Returns the return value of executed contract. Future call( - EthereumAddress? address, EthereumDefaultBlock? block, - {EthereumAddress? from, - int? gas, - int? gasPrice, - int? value, - EthereumData? data}) async { + EthereumAddress? address, + EthereumDefaultBlock? block, { + EthereumAddress? from, + int? gas, + int? gasPrice, + int? value, + EthereumData? data, + }) async { if (address == null) { throw ArgumentError.notNull('Ethereum::call - address'); } @@ -485,7 +507,7 @@ class EthereumApiEth extends EthereumApi { 'gasPrice': gasPrice == null ? null : EthereumUtilities.intToHex(gasPrice), 'value': value == null ? null : EthereumUtilities.intToHex(value), - 'data': data?.asString + 'data': data?.asString, }; paramBlock = EthereumUtilities.removeNull(paramBlock) as Map; @@ -508,13 +530,14 @@ class EthereumApiEth extends EthereumApi { /// might not be enough to executed the call/transaction when the /// amount of gas is higher than the pending block gas limit. /// Returns the amount of gas used. - Future estimateGas( - {EthereumAddress? address, - EthereumAddress? from, - int? gas, - int? gasPrice, - int? value, - EthereumData? data}) async { + Future estimateGas({ + EthereumAddress? address, + EthereumAddress? from, + int? gas, + int? gasPrice, + int? value, + EthereumData? data, + }) async { var paramBlock = { 'from': from?.asString, 'to': address?.asString, @@ -522,7 +545,7 @@ class EthereumApiEth extends EthereumApi { 'gasPrice': gasPrice == null ? null : EthereumUtilities.intToHex(gasPrice), 'value': value == null ? null : EthereumUtilities.intToHex(value), - 'data': data?.asString + 'data': data?.asString, }; paramBlock = EthereumUtilities.removeNull(paramBlock) as Map; @@ -542,8 +565,10 @@ class EthereumApiEth extends EthereumApi { /// full transaction objects, /// if false only the hashes of the transactions, defaults to true. /// Returns A block object, or null when no block was found : - Future getBlockByHash(EthereumData? blockHash, - {bool full = true}) async { + Future getBlockByHash( + EthereumData? blockHash, { + bool full = true, + }) async { if (blockHash == null) { throw ArgumentError.notNull('Ethereum::getBlockByHash - blockHash'); } @@ -564,8 +589,10 @@ class EthereumApiEth extends EthereumApi { /// A boolean, if true it returns the full transaction objects, /// if false only the hashes of the transactions, defaults to true. /// Returns See getBlockByHash - Future getBlockByNumber(EthereumDefaultBlock? blockNumber, - {bool full = true}) async { + Future getBlockByNumber( + EthereumDefaultBlock? blockNumber, { + bool full = true, + }) async { if (blockNumber == null) { throw ArgumentError.notNull('Ethereum::getBlockByNumber - blockNumber'); } @@ -604,18 +631,22 @@ class EthereumApiEth extends EthereumApi { /// Hash of a block and integer of the transaction index position. /// Returns see getTransactionByHash. Future getTransactionByBlockHashAndIndex( - EthereumData? blockHash, int? index) async { + EthereumData? blockHash, + int? index, + ) async { if (blockHash == null) { throw ArgumentError.notNull( - 'Ethereum::getTransactionByBlockHashAndIndex - blockHash'); + 'Ethereum::getTransactionByBlockHashAndIndex - blockHash', + ); } if (index == null) { throw ArgumentError.notNull( - 'Ethereum::getTransactionByBlockHashAndIndex - index'); + 'Ethereum::getTransactionByBlockHashAndIndex - index', + ); } final dynamic params = [ blockHash.asString, - EthereumUtilities.intToHex(index) + EthereumUtilities.intToHex(index), ]; const method = EthereumRpcMethods.getTransactionByBlockHashAndIndex; final dynamic res = await _client.rpcClient.request(method, params); @@ -632,19 +663,23 @@ class EthereumApiEth extends EthereumApi { /// A block number as in the default block parameter. /// Returns see getTransactionByHash. Future getTransactionByBlockNumberAndIndex( - EthereumDefaultBlock? blockNumber, int? index) async { + EthereumDefaultBlock? blockNumber, + int? index, + ) async { if (blockNumber == null) { throw ArgumentError.notNull( - 'Ethereum::getTransactionByBlockNumberAndIndex - blockNumber'); + 'Ethereum::getTransactionByBlockNumberAndIndex - blockNumber', + ); } if (index == null) { throw ArgumentError.notNull( - 'Ethereum::getTransactionByBlockNumberAndIndex - index'); + 'Ethereum::getTransactionByBlockNumberAndIndex - index', + ); } final blockNumberString = blockNumber.getSelection(); final dynamic params = [ blockNumberString, - EthereumUtilities.intToHex(index) + EthereumUtilities.intToHex(index), ]; const method = EthereumRpcMethods.getTransactionByBlockNumberAndIndex; final dynamic res = await _client.rpcClient.request(method, params); @@ -661,17 +696,20 @@ class EthereumApiEth extends EthereumApi { /// Hash of a transaction /// Returns a transaction receipt object, or null when no receipt was found: Future getTransactionReceipt( - EthereumData? transactionHash) async { + EthereumData? transactionHash, + ) async { if (transactionHash == null) { throw ArgumentError.notNull( - 'Ethereum::getTransactionReceipt - transactionHash'); + 'Ethereum::getTransactionReceipt - transactionHash', + ); } final dynamic params = [transactionHash.asString]; const method = EthereumRpcMethods.getTransactionReceipt; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { return EthereumTransactionReceipt.fromMap( - res[EthereumConstants.ethResultKey]); + res[EthereumConstants.ethResultKey], + ); } _client.processError(method, res); return null; @@ -683,18 +721,22 @@ class EthereumApiEth extends EthereumApi { /// Hash of a block and integer of the uncle index position. /// Returns see getBlockByHash. Future getUncleByBlockHashAndIndex( - EthereumData? blockHash, int? index) async { + EthereumData? blockHash, + int? index, + ) async { if (blockHash == null) { throw ArgumentError.notNull( - 'Ethereum::getUncleByBlockHashAndIndex - blockHash'); + 'Ethereum::getUncleByBlockHashAndIndex - blockHash', + ); } if (index == null) { throw ArgumentError.notNull( - 'Ethereum::getUncleByBlockHashAndIndex - index'); + 'Ethereum::getUncleByBlockHashAndIndex - index', + ); } final dynamic params = [ blockHash.asString, - EthereumUtilities.intToHex(index) + EthereumUtilities.intToHex(index), ]; const method = EthereumRpcMethods.getUncleByBlockHashAndIndex; final dynamic res = await _client.rpcClient.request(method, params); @@ -712,19 +754,23 @@ class EthereumApiEth extends EthereumApi { /// A block number as in the default block parameter. /// Returns see getBlockByHash. Future getUncleByBlockNumberAndIndex( - EthereumDefaultBlock? blockNumber, int? index) async { + EthereumDefaultBlock? blockNumber, + int? index, + ) async { if (blockNumber == null) { throw ArgumentError.notNull( - 'Ethereum::getUncleByBlockNumberAndIndex - blockNumber'); + 'Ethereum::getUncleByBlockNumberAndIndex - blockNumber', + ); } if (index == null) { throw ArgumentError.notNull( - 'Ethereum::getUncleByBlockNumberAndIndex - index'); + 'Ethereum::getUncleByBlockNumberAndIndex - index', + ); } final blockNumberString = blockNumber.getSelection(); final dynamic params = [ blockNumberString, - EthereumUtilities.intToHex(index) + EthereumUtilities.intToHex(index), ]; const method = EthereumRpcMethods.getUncleByBlockNumberAndIndex; final dynamic res = await _client.rpcClient.request(method, params); @@ -762,21 +808,23 @@ class EthereumApiEth extends EthereumApi { /// [EthereumUtilities] class. See the Ethereum /// Wiki RPC page for examples. /// Returns a filter id. - Future newFilter( - {required EthereumDefaultBlock fromBlock, - required EthereumDefaultBlock toBlock, - dynamic address, - List? topics}) async { + Future newFilter({ + required EthereumDefaultBlock fromBlock, + required EthereumDefaultBlock toBlock, + dynamic address, + List? topics, + }) async { final fromBlockString = fromBlock.getSelection(); final toBlockString = toBlock.getSelection(); final params = { 'toBlock': toBlockString, - 'fromBlock': fromBlockString + 'fromBlock': fromBlockString, }; if (address != null) { if (address is List) { - final addresses = - EthereumAddress.toStringList(address as List); + final addresses = EthereumAddress.toStringList( + address as List, + ); params['address'] = addresses; } else { params['address'] = [address.asString]; @@ -886,21 +934,23 @@ class EthereumApiEth extends EthereumApi { /// Get logs /// Returns an array of all logs matching a given filter object. /// The filter definition, see newFilter parameters. - Future?> getLogs( - {required EthereumDefaultBlock fromBlock, - required EthereumDefaultBlock toBlock, - dynamic address, - List? topics}) async { + Future?> getLogs({ + required EthereumDefaultBlock fromBlock, + required EthereumDefaultBlock toBlock, + dynamic address, + List? topics, + }) async { final fromBlockString = fromBlock.getSelection(); final toBlockString = toBlock.getSelection(); final params = { 'toBlock': toBlockString, - 'fromBlock': fromBlockString + 'fromBlock': fromBlockString, }; if (address != null) { if (address is List) { - final addresses = - EthereumData.toStringList(address as List); + final addresses = EthereumData.toStringList( + address as List, + ); params['address'] = addresses; } else { params['address'] = address.asString; @@ -941,7 +991,10 @@ class EthereumApiEth extends EthereumApi { /// The mix digest /// Returns true if the provided solution is valid, otherwise false. Future submitWork( - EthereumData? nonce, EthereumData? powHash, EthereumData? digest) async { + EthereumData? nonce, + EthereumData? powHash, + EthereumData? digest, + ) async { if (nonce == null) { throw ArgumentError.notNull('Ethereum::submitWork - nonce'); } @@ -1007,9 +1060,14 @@ class EthereumApiEth extends EthereumApi { /// priority: - The integer of the priority in a range from ... (?). /// ttl: - integer of the time to live in seconds. /// Returns true if the message was send, otherwise false. - Future shhPost(List? topics, EthereumData? payload, - int? priority, int? ttl, - {required EthereumAddress to, required EthereumAddress from}) async { + Future shhPost( + List? topics, + EthereumData? payload, + int? priority, + int? ttl, { + required EthereumAddress to, + required EthereumAddress from, + }) async { if (topics == null) { throw ArgumentError.notNull('Ethereum::shhPost - topics'); } @@ -1028,7 +1086,7 @@ class EthereumApiEth extends EthereumApi { 'priority': EthereumUtilities.intToHex(priority), 'ttl': ttl, 'to': to.asString, - 'from': from.asString + 'from': from.asString, }; params = EthereumUtilities.removeNull(params) as Map; final paramBlock = [params]; diff --git a/lib/src/datatypes/ethereum_address.dart b/lib/src/datatypes/ethereum_address.dart index 34fab71..b6d344f 100644 --- a/lib/src/datatypes/ethereum_address.dart +++ b/lib/src/datatypes/ethereum_address.dart @@ -67,7 +67,9 @@ class EthereumAddress { /// Address string list to EthereumAddress list static List toList(List val) => List.generate( - val.length, (int index) => EthereumAddress.fromString(val[index])); + val.length, + (int index) => EthereumAddress.fromString(val[index]), + ); /// EthereumAddress list to address string static List toStringList(List val) => @@ -86,7 +88,8 @@ class EthereumAddress { // to be padded with 00 if (hexString.length > addressCharacterLength) { throw const FormatException( - 'EthereumAddress - address has more than 40 characters'); + 'EthereumAddress - address has more than 40 characters', + ); } else { if (hexString.length < addressCharacterLength) { // Must be even @@ -106,7 +109,8 @@ class EthereumAddress { if (!val.startsWith(EthereumConstants.leadingHexString) || val.length != addressCharacterLength + 2) { throw const FormatException( - 'EthereumAddress - address string is badly formed'); + 'EthereumAddress - address string is badly formed', + ); } } } diff --git a/lib/src/datatypes/ethereum_data.dart b/lib/src/datatypes/ethereum_data.dart index b04bea3..48c0e09 100644 --- a/lib/src/datatypes/ethereum_data.dart +++ b/lib/src/datatypes/ethereum_data.dart @@ -52,7 +52,9 @@ class EthereumData { /// Data string list to EthereumAddress list static List toList(List val) => List.generate( - val.length, (int index) => EthereumData.fromString(val[index])); + val.length, + (int index) => EthereumData.fromString(val[index]), + ); /// EthereumData list to string list static List toStringList(List val) => diff --git a/lib/src/ethereum.dart b/lib/src/ethereum.dart index 1029cc1..0796bea 100644 --- a/lib/src/ethereum.dart +++ b/lib/src/ethereum.dart @@ -25,9 +25,11 @@ class Ethereum { /// With connection parameters Ethereum.withConnectionParameters( - EthereumINetworkAdapter adapter, String hostname, String scheme, - [int? port = defaultHttpPort]) - : _networkAdapter = adapter { + EthereumINetworkAdapter adapter, + String hostname, + String scheme, [ + int? port = defaultHttpPort, + ]) : _networkAdapter = adapter { rpcClient = EthereumRpcClient(_networkAdapter); /// Construct the API classes @@ -106,7 +108,8 @@ class Ethereum { } if ((scheme != rpcHttpScheme) && (scheme != rpcWsScheme)) { throw FormatException( - 'Ethereum::connectParameters - invalid scheme $scheme'); + 'Ethereum::connectParameters - invalid scheme $scheme', + ); } int? uriPort; if (port != null) { @@ -122,7 +125,9 @@ class Ethereum { host = puri.host; } else { throw ArgumentError.value( - puri.host, 'Ethereum::_validateUri - invalid host'); + puri.host, + 'Ethereum::_validateUri - invalid host', + ); } var newUri = puri; if (!puri.hasPort) { diff --git a/lib/src/ethereum_utilities.dart b/lib/src/ethereum_utilities.dart index 63792f1..82204ca 100644 --- a/lib/src/ethereum_utilities.dart +++ b/lib/src/ethereum_utilities.dart @@ -36,7 +36,8 @@ class EthereumUtilities { if (pad != 0) { if (pad.isNegative || pad.isOdd) { throw FormatException( - 'EthereumUtilities:: intToHex - invalid pad value, $pad'); + 'EthereumUtilities:: intToHex - invalid pad value, $pad', + ); } if (ret.length.isOdd) { ret = '0$ret'; diff --git a/lib/src/messages/ethereum_block.dart b/lib/src/messages/ethereum_block.dart index 3a6d097..b333316 100644 --- a/lib/src/messages/ethereum_block.dart +++ b/lib/src/messages/ethereum_block.dart @@ -130,76 +130,95 @@ class EthereumBlock { } if (data[EthereumConstants.ethResultKey].containsKey('number')) { _number = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['number']); + data[EthereumConstants.ethResultKey]['number'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('hash')) { - _hash = - EthereumData.fromString(data[EthereumConstants.ethResultKey]['hash']); + _hash = EthereumData.fromString( + data[EthereumConstants.ethResultKey]['hash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('parentHash')) { _parentHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['parentHash']); + data[EthereumConstants.ethResultKey]['parentHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('nonce')) { _nonce = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['nonce']); + data[EthereumConstants.ethResultKey]['nonce'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('sha3Uncles')) { _sha3Uncles = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['sha3Uncles']); + data[EthereumConstants.ethResultKey]['sha3Uncles'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('logsBloom')) { _logsBloom = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['logsBloom']); + data[EthereumConstants.ethResultKey]['logsBloom'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactionsRoot')) { _transactionsRoot = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['transactionsRoot']); + data[EthereumConstants.ethResultKey]['transactionsRoot'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('stateRoot')) { _stateRoot = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['stateRoot']); + data[EthereumConstants.ethResultKey]['stateRoot'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('receiptsRoot')) { _receiptsRoot = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['receiptsRoot']); + data[EthereumConstants.ethResultKey]['receiptsRoot'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('miner')) { _miner = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['miner']); + data[EthereumConstants.ethResultKey]['miner'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('difficulty')) { _difficulty = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['difficulty']); + data[EthereumConstants.ethResultKey]['difficulty'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('totalDifficulty')) { _totalDifficulty = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['totalDifficulty']); + data[EthereumConstants.ethResultKey]['totalDifficulty'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('extraData')) { _extraData = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['extraData']); + data[EthereumConstants.ethResultKey]['extraData'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('size')) { _size = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['size']); + data[EthereumConstants.ethResultKey]['size'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('gasLimit')) { _gasLimit = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['gasLimit']); + data[EthereumConstants.ethResultKey]['gasLimit'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('gasUsed')) { _gasUsed = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['gasUsed']); + data[EthereumConstants.ethResultKey]['gasUsed'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('timestamp')) { _timestamp = DateTime.fromMillisecondsSinceEpoch( - EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['timestamp'])!); + EthereumUtilities.hexToInt( + data[EthereumConstants.ethResultKey]['timestamp'], + )!, + ); } if (data[EthereumConstants.ethResultKey].containsKey('uncles')) { - _uncles = - EthereumData.toList(data[EthereumConstants.ethResultKey]['uncles']); + _uncles = EthereumData.toList( + data[EthereumConstants.ethResultKey]['uncles'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactions')) { if ((data[EthereumConstants.ethResultKey]['transactions'] != null) && @@ -208,14 +227,15 @@ class EthereumBlock { // Hashes _transactionsAreHashes = true; _transactions = EthereumData.toList( - data[EthereumConstants.ethResultKey]['transactions']); + data[EthereumConstants.ethResultKey]['transactions'], + ); } else { // Transaction objects _transactions = []; for (final Map transaction in data[EthereumConstants.ethResultKey]['transactions']) { final buildTrans = { - EthereumConstants.ethResultKey: transaction + EthereumConstants.ethResultKey: transaction, }; final entry = EthereumTransaction.fromMap(buildTrans); _transactions!.add(entry); @@ -227,7 +247,8 @@ class EthereumBlock { @override String toString() { - final ret = 'Ethereum Block :' + final ret = + 'Ethereum Block :' '\n' ' Number : $number' '\n' diff --git a/lib/src/messages/ethereum_filter.dart b/lib/src/messages/ethereum_filter.dart index 3e71725..ee32558 100644 --- a/lib/src/messages/ethereum_filter.dart +++ b/lib/src/messages/ethereum_filter.dart @@ -50,7 +50,7 @@ class EthereumFilter { for (final Map log in data[EthereumConstants.ethResultKey]) { final buildLog = { - EthereumConstants.ethResultKey: log + EthereumConstants.ethResultKey: log, }; final entry = EthereumLog.fromMap(buildLog); _logs!.add(entry); diff --git a/lib/src/messages/ethereum_log.dart b/lib/src/messages/ethereum_log.dart index 7484d20..252f6e2 100644 --- a/lib/src/messages/ethereum_log.dart +++ b/lib/src/messages/ethereum_log.dart @@ -93,44 +93,53 @@ class EthereumLog { } if (data[EthereumConstants.ethResultKey].containsKey('logIndex')) { _logIndex = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['logIndex']); + data[EthereumConstants.ethResultKey]['logIndex'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactionIndex')) { _transactionIndex = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['transactionIndex']); + data[EthereumConstants.ethResultKey]['transactionIndex'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactionHash')) { _transactionHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['transactionHash']); + data[EthereumConstants.ethResultKey]['transactionHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockHash')) { _blockHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['blockHash']); + data[EthereumConstants.ethResultKey]['blockHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockNumber')) { _blockNumber = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['blockNumber']); + data[EthereumConstants.ethResultKey]['blockNumber'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('address')) { _address = EthereumAddress.fromString( - data[EthereumConstants.ethResultKey]['address']); + data[EthereumConstants.ethResultKey]['address'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('data')) { - _data = - EthereumData.fromString(data[EthereumConstants.ethResultKey]['data']); + _data = EthereumData.fromString( + data[EthereumConstants.ethResultKey]['data'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('topics')) { if ((data[EthereumConstants.ethResultKey]['topics'] != null) && (data[EthereumConstants.ethResultKey]['topics'].isNotEmpty)) { - _topics = - EthereumData.toList(data[EthereumConstants.ethResultKey]['topics']); + _topics = EthereumData.toList( + data[EthereumConstants.ethResultKey]['topics'], + ); } } } @override String toString() { - final ret = 'Ethereum Log :' + final ret = + 'Ethereum Log :' '\n' ' Removed : $removed' '\n' diff --git a/lib/src/messages/ethereum_sync_status.dart b/lib/src/messages/ethereum_sync_status.dart index d2427c6..05ef071 100644 --- a/lib/src/messages/ethereum_sync_status.dart +++ b/lib/src/messages/ethereum_sync_status.dart @@ -57,9 +57,14 @@ class EthereumSyncStatus { @override String toString() { - var ret = 'Ethereum Sync Status :' '\n' ' Syncing : $syncing' '\n'; + var ret = + 'Ethereum Sync Status :' + '\n' + ' Syncing : $syncing' + '\n'; if (syncing) { - ret += ' Starting Block : $startingBlock' + ret += + ' Starting Block : $startingBlock' '\n' ' Current Block : $currentBlock' '\n' diff --git a/lib/src/messages/ethereum_transaction.dart b/lib/src/messages/ethereum_transaction.dart index bea2f03..a481783 100644 --- a/lib/src/messages/ethereum_transaction.dart +++ b/lib/src/messages/ethereum_transaction.dart @@ -83,54 +83,66 @@ class EthereumTransaction { return; } if (data[EthereumConstants.ethResultKey].containsKey('hash')) { - _hash = - EthereumData.fromString(data[EthereumConstants.ethResultKey]['hash']); + _hash = EthereumData.fromString( + data[EthereumConstants.ethResultKey]['hash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('nonce')) { _nonce = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['nonce']); + data[EthereumConstants.ethResultKey]['nonce'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockHash')) { _blockHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['blockHash']); + data[EthereumConstants.ethResultKey]['blockHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockNumber')) { _blockNumber = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['blockNumber']); + data[EthereumConstants.ethResultKey]['blockNumber'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactionIndex')) { _transactionIndex = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['transactionIndex']); + data[EthereumConstants.ethResultKey]['transactionIndex'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('from')) { _from = EthereumAddress.fromString( - data[EthereumConstants.ethResultKey]['from']); + data[EthereumConstants.ethResultKey]['from'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('to')) { _to = EthereumAddress.fromString( - data[EthereumConstants.ethResultKey]['to']); + data[EthereumConstants.ethResultKey]['to'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('value')) { _value = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['value']); + data[EthereumConstants.ethResultKey]['value'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('gasPrice')) { _gasPrice = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['gasPrice']); + data[EthereumConstants.ethResultKey]['gasPrice'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('gas')) { _gas = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['gas']); + data[EthereumConstants.ethResultKey]['gas'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('input')) { _input = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['input']); + data[EthereumConstants.ethResultKey]['input'], + ); } } @override String toString() { - final ret = 'Ethereum Transaction :' + final ret = + 'Ethereum Transaction :' '\n' ' Hash : $hash' '\n' diff --git a/lib/src/messages/ethereum_transaction_receipt.dart b/lib/src/messages/ethereum_transaction_receipt.dart index 463d3af..8413362 100644 --- a/lib/src/messages/ethereum_transaction_receipt.dart +++ b/lib/src/messages/ethereum_transaction_receipt.dart @@ -86,43 +86,53 @@ class EthereumTransactionReceipt { } if (data[EthereumConstants.ethResultKey].containsKey('transactionHash')) { _transactionHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['transactionHash']); + data[EthereumConstants.ethResultKey]['transactionHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('transactionIndex')) { _transactionIndex = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['transactionIndex']); + data[EthereumConstants.ethResultKey]['transactionIndex'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockHash')) { _blockHash = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['blockHash']); + data[EthereumConstants.ethResultKey]['blockHash'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('blockNumber')) { _blockNumber = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['blockNumber']); + data[EthereumConstants.ethResultKey]['blockNumber'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('cumulativeGasUsed')) { _cumulativeGasUsed = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['cumulativeGasUsed']); + data[EthereumConstants.ethResultKey]['cumulativeGasUsed'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('gasUsed')) { _gasUsed = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['gasUsed']); + data[EthereumConstants.ethResultKey]['gasUsed'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('contractAddress')) { _contractAddress = EthereumAddress.fromString( - data[EthereumConstants.ethResultKey]['contractAddress']); + data[EthereumConstants.ethResultKey]['contractAddress'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('logsBloom')) { _logsBloom = EthereumData.fromString( - data[EthereumConstants.ethResultKey]['logsBloom']); + data[EthereumConstants.ethResultKey]['logsBloom'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('root')) { - _root = - EthereumData.fromString(data[EthereumConstants.ethResultKey]['root']); + _root = EthereumData.fromString( + data[EthereumConstants.ethResultKey]['root'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('status')) { _status = EthereumUtilities.hexToInt( - data[EthereumConstants.ethResultKey]['status']); + data[EthereumConstants.ethResultKey]['status'], + ); } if (data[EthereumConstants.ethResultKey].containsKey('logs')) { if ((data[EthereumConstants.ethResultKey]['logs'] != null) && @@ -131,7 +141,7 @@ class EthereumTransactionReceipt { for (final Map log in data[EthereumConstants.ethResultKey]['logs']) { final buildLog = { - EthereumConstants.ethResultKey: log + EthereumConstants.ethResultKey: log, }; final entry = EthereumLog.fromMap(buildLog); _logs!.add(entry); @@ -142,7 +152,8 @@ class EthereumTransactionReceipt { @override String toString() { - final ret = 'Ethereum Transaction Receipt:' + final ret = + 'Ethereum Transaction Receipt:' '\n' ' Transaction Hash : $transactionHash' '\n' diff --git a/lib/src/messages/ethereum_work.dart b/lib/src/messages/ethereum_work.dart index 0c3b31e..ced6a0e 100644 --- a/lib/src/messages/ethereum_work.dart +++ b/lib/src/messages/ethereum_work.dart @@ -50,7 +50,8 @@ class EthereumWork { @override String toString() { - final ret = 'Ethereum Work :' + final ret = + 'Ethereum Work :' '\n' ' Pow Hash : $powHash' '\n' diff --git a/pubspec.yaml b/pubspec.yaml index 6d8db65..2fc26a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ funding: - https://www.darticulate.com/#funding environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: hex: '^0.2.0' diff --git a/test/ethereum_base_test.dart b/test/ethereum_base_test.dart index 559f6be..cd80dc5 100644 --- a/test/ethereum_base_test.dart +++ b/test/ethereum_base_test.dart @@ -34,8 +34,10 @@ void main() { EthereumUtilities.intToHex(1, -2); } on Exception catch (e) { expect(e is FormatException, isTrue); - expect(e.toString(), - 'FormatException: EthereumUtilities:: intToHex - invalid pad value, -2'); + expect( + e.toString(), + 'FormatException: EthereumUtilities:: intToHex - invalid pad value, -2', + ); thrown = true; } expect(thrown, isTrue); @@ -46,8 +48,10 @@ void main() { EthereumUtilities.intToHex(1, 3); } on Exception catch (e) { expect(e is FormatException, isTrue); - expect(e.toString(), - 'FormatException: EthereumUtilities:: intToHex - invalid pad value, 3'); + expect( + e.toString(), + 'FormatException: EthereumUtilities:: intToHex - invalid pad value, 3', + ); thrown = true; } expect(thrown, isTrue); @@ -82,8 +86,10 @@ void main() { client.connectString(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::connectString - hostname): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::connectString - hostname): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -107,8 +113,10 @@ void main() { client.connectUri(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::connectUri - uri): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::connectUri - uri): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -134,8 +142,10 @@ void main() { client.connectParameters(Ethereum.rpcHttpScheme, null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::connectParameters - hostname): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::connectParameters - hostname): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -147,8 +157,10 @@ void main() { client.connectParameters('Billy', 'localhost'); } on Exception catch (e) { expect(e is FormatException, isTrue); - expect(e.toString(), - 'FormatException: Ethereum::connectParameters - invalid scheme Billy'); + expect( + e.toString(), + 'FormatException: Ethereum::connectParameters - invalid scheme Billy', + ); thrown = true; } expect(thrown, isTrue); @@ -187,8 +199,10 @@ void main() { await client.eth!.sha3(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sha3 - data): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sha3 - data): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -199,8 +213,10 @@ void main() { await client.eth!.getBalance(null, null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBalance - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBalance - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -208,12 +224,16 @@ void main() { test('Balance - block', () async { var thrown = false; try { - await client.eth! - .getBalance(EthereumAddress.fromBigInt(BigInt.zero), null); + await client.eth!.getBalance( + EthereumAddress.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBalance - block): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBalance - block): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -221,12 +241,17 @@ void main() { test('Storage at - block', () async { var thrown = false; try { - await client.eth! - .getStorageAt(EthereumAddress.fromBigInt(BigInt.one), 2, null); + await client.eth!.getStorageAt( + EthereumAddress.fromBigInt(BigInt.one), + 2, + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getStorageAt - block): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getStorageAt - block): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -234,12 +259,17 @@ void main() { test('Storage at - pos', () async { var thrown = false; try { - await client.eth!.getStorageAt(EthereumAddress.fromBigInt(BigInt.one), - null, EthereumDefaultBlock()); + await client.eth!.getStorageAt( + EthereumAddress.fromBigInt(BigInt.one), + null, + EthereumDefaultBlock(), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getStorageAt - pos): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getStorageAt - pos): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -250,8 +280,10 @@ void main() { await client.eth!.getStorageAt(null, 1, EthereumDefaultBlock()); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getStorageAt - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getStorageAt - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -262,8 +294,10 @@ void main() { await client.eth!.getTransactionCount(null, EthereumDefaultBlock()); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionCount - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionCount - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -271,12 +305,16 @@ void main() { test('Block transaction count - block', () async { var thrown = false; try { - await client.eth! - .getTransactionCount(EthereumAddress.fromBigInt(BigInt.one), null); + await client.eth!.getTransactionCount( + EthereumAddress.fromBigInt(BigInt.one), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionCount - block): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionCount - block): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -287,8 +325,10 @@ void main() { await client.eth!.getBlockTransactionCountByHash(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBlockTransactionCountByHash - blockHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBlockTransactionCountByHash - blockHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -299,8 +339,10 @@ void main() { await client.eth!.getBlockTransactionCountByNumber(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBlockTransactionCountByNumber - blockNumber): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBlockTransactionCountByNumber - blockNumber): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -311,8 +353,10 @@ void main() { await client.eth!.getUncleCountByHash(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleCountByHash - blockHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleCountByHash - blockHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -323,8 +367,10 @@ void main() { await client.eth!.getUncleCountByNumber(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleCountByNumber - blockNumber): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleCountByNumber - blockNumber): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -335,8 +381,10 @@ void main() { await client.eth!.getCode(null, EthereumDefaultBlock()); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getCode - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getCode - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -347,8 +395,10 @@ void main() { await client.eth!.getCode(EthereumAddress.fromBigInt(BigInt.two), null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getCode - block): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getCode - block): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -359,8 +409,10 @@ void main() { await client.eth!.sign(null, EthereumData.fromBigInt(BigInt.zero)); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sign - account): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sign - account): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -371,8 +423,10 @@ void main() { await client.eth!.sign(EthereumAddress.fromBigInt(BigInt.zero), null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sign - message): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sign - message): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -380,12 +434,16 @@ void main() { test('Send transaction - address', () async { var thrown = false; try { - await client.eth! - .sendTransaction(null, EthereumData.fromBigInt(BigInt.zero)); + await client.eth!.sendTransaction( + null, + EthereumData.fromBigInt(BigInt.zero), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sendTransaction - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sendTransaction - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -393,12 +451,16 @@ void main() { test('Send transaction - data', () async { var thrown = false; try { - await client.eth! - .sendTransaction(EthereumAddress.fromBigInt(BigInt.zero), null); + await client.eth!.sendTransaction( + EthereumAddress.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sendTransaction - data): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sendTransaction - data): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -409,8 +471,10 @@ void main() { await client.eth!.sendRawTransaction(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::sendRawTransaction - signedTransaction): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::sendRawTransaction - signedTransaction): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -421,8 +485,10 @@ void main() { await client.eth!.call(null, null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::call - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::call - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -433,8 +499,10 @@ void main() { await client.eth!.call(EthereumAddress.fromBigInt(BigInt.zero), null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::call - block): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::call - block): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -445,8 +513,10 @@ void main() { await client.eth!.getBlockByHash(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBlockByHash - blockHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBlockByHash - blockHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -457,8 +527,10 @@ void main() { await client.eth!.getBlockByNumber(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getBlockByNumber - blockNumber): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getBlockByNumber - blockNumber): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -469,8 +541,10 @@ void main() { await client.eth!.getTransactionByHash(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionByHash - hash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionByHash - hash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -481,8 +555,10 @@ void main() { await client.eth!.getTransactionByBlockHashAndIndex(null, 0); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionByBlockHashAndIndex - blockHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionByBlockHashAndIndex - blockHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -491,11 +567,15 @@ void main() { var thrown = false; try { await client.eth!.getTransactionByBlockHashAndIndex( - EthereumData.fromBigInt(BigInt.zero), null); + EthereumData.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionByBlockHashAndIndex - index): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionByBlockHashAndIndex - index): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -506,8 +586,10 @@ void main() { await client.eth!.getTransactionByBlockNumberAndIndex(null, 0); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionByBlockNumberAndIndex - blockNumber): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionByBlockNumberAndIndex - blockNumber): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -515,12 +597,16 @@ void main() { test('Get transaction by block number and index - index', () async { var thrown = false; try { - await client.eth! - .getTransactionByBlockNumberAndIndex(EthereumDefaultBlock(), null); + await client.eth!.getTransactionByBlockNumberAndIndex( + EthereumDefaultBlock(), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionByBlockNumberAndIndex - index): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionByBlockNumberAndIndex - index): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -531,8 +617,10 @@ void main() { await client.eth!.getTransactionReceipt(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getTransactionReceipt - transactionHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getTransactionReceipt - transactionHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -543,8 +631,10 @@ void main() { await client.eth!.getUncleByBlockHashAndIndex(null, 0); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleByBlockHashAndIndex - blockHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleByBlockHashAndIndex - blockHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -553,11 +643,15 @@ void main() { var thrown = false; try { await client.eth!.getUncleByBlockHashAndIndex( - EthereumData.fromBigInt(BigInt.zero), null); + EthereumData.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleByBlockHashAndIndex - index): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleByBlockHashAndIndex - index): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -568,8 +662,10 @@ void main() { await client.eth!.getUncleByBlockNumberAndIndex(null, 0); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleByBlockNumberAndIndex - blockNumber): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleByBlockNumberAndIndex - blockNumber): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -577,12 +673,16 @@ void main() { test('Get uncle by block number and index - index', () async { var thrown = false; try { - await client.eth! - .getUncleByBlockNumberAndIndex(EthereumDefaultBlock(), null); + await client.eth!.getUncleByBlockNumberAndIndex( + EthereumDefaultBlock(), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getUncleByBlockNumberAndIndex - index): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getUncleByBlockNumberAndIndex - index): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -593,8 +693,10 @@ void main() { await client.eth!.uninstallFilter(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::uninstallFilter - filterId): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::uninstallFilter - filterId): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -605,8 +707,10 @@ void main() { await client.eth!.getFilterChanges(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getFilterChanges - filterId): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getFilterChanges - filterId): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -617,8 +721,10 @@ void main() { await client.eth!.getFilterLogs(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::getFilterLogs - filterId): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::getFilterLogs - filterId): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -626,12 +732,17 @@ void main() { test('Submit work - nonce', () async { var thrown = false; try { - await client.eth!.submitWork(null, EthereumData.fromBigInt(BigInt.one), - EthereumData.fromBigInt(BigInt.two)); + await client.eth!.submitWork( + null, + EthereumData.fromBigInt(BigInt.one), + EthereumData.fromBigInt(BigInt.two), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::submitWork - nonce): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::submitWork - nonce): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -639,12 +750,17 @@ void main() { test('Submit work - powHash', () async { var thrown = false; try { - await client.eth!.submitWork(EthereumData.fromBigInt(BigInt.one), null, - EthereumData.fromBigInt(BigInt.two)); + await client.eth!.submitWork( + EthereumData.fromBigInt(BigInt.one), + null, + EthereumData.fromBigInt(BigInt.two), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::submitWork - powHash): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::submitWork - powHash): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -652,12 +768,17 @@ void main() { test('Submit work - digest', () async { var thrown = false; try { - await client.eth!.submitWork(EthereumData.fromBigInt(BigInt.one), - EthereumData.fromBigInt(BigInt.two), null); + await client.eth!.submitWork( + EthereumData.fromBigInt(BigInt.one), + EthereumData.fromBigInt(BigInt.two), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::submitWork - digest): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::submitWork - digest): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -668,8 +789,10 @@ void main() { await client.eth!.submitHashrate(null, 'id'); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::submitHashRate - hashRate): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::submitHashRate - hashRate): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -677,12 +800,16 @@ void main() { test('Submit hash rate - id', () async { var thrown = false; try { - await client.eth! - .submitHashrate(EthereumData.fromBigInt(BigInt.one), null); + await client.eth!.submitHashrate( + EthereumData.fromBigInt(BigInt.one), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::submitHashRate - id): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::submitHashRate - id): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -691,15 +818,23 @@ void main() { var thrown = false; try { await client.eth!.shhPost( - null, EthereumData.fromBigInt(BigInt.one), 2, 3, - to: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168'), - from: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168')); + null, + EthereumData.fromBigInt(BigInt.one), + 2, + 3, + to: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + from: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::shhPost - topics): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::shhPost - topics): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -708,15 +843,23 @@ void main() { var thrown = false; try { await client.eth!.shhPost( - [EthereumData.fromBigInt(BigInt.one)], null, 2, 3, - to: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168'), - from: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168')); + [EthereumData.fromBigInt(BigInt.one)], + null, + 2, + 3, + to: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + from: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::shhPost - payload): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::shhPost - payload): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -725,18 +868,23 @@ void main() { var thrown = false; try { await client.eth!.shhPost( - [EthereumData.fromBigInt(BigInt.one)], - EthereumData.fromBigInt(BigInt.one), - null, - 3, - to: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168'), - from: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168')); + [EthereumData.fromBigInt(BigInt.one)], + EthereumData.fromBigInt(BigInt.one), + null, + 3, + to: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + from: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::shhPost - priority): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::shhPost - priority): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -745,18 +893,23 @@ void main() { var thrown = false; try { await client.eth!.shhPost( - [EthereumData.fromBigInt(BigInt.one)], - EthereumData.fromBigInt(BigInt.one), - 2, - null, - to: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168'), - from: EthereumAddress.fromString( - '0xad52b73690c35b9211a18c9293e805d792474168')); + [EthereumData.fromBigInt(BigInt.one)], + EthereumData.fromBigInt(BigInt.one), + 2, + null, + to: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + from: EthereumAddress.fromString( + '0xad52b73690c35b9211a18c9293e805d792474168', + ), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::shhPost - ttl): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::shhPost - ttl): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -794,7 +947,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress(fromList(data)); expect(address.toList(), data); @@ -829,7 +982,7 @@ void main() { 67, 98, 76, - 100 + 100, ]; const checkdata = [ 1, @@ -851,7 +1004,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress(fromList(data)); expect(address.toList(), checkdata); @@ -878,7 +1031,7 @@ void main() { 0, 0, 0, - 0 + 0, ]; final address = EthereumByteAddress(fromList(data)); expect(address.toList(), checkdata); @@ -904,7 +1057,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress.fromIntList(data); expect(address.toList(), data); @@ -930,7 +1083,7 @@ void main() { 17, 18, 19, - 400 + 400, ]; const checkdata = [ 1, @@ -952,7 +1105,7 @@ void main() { 17, 18, 19, - 0 + 0, ]; final address = EthereumByteAddress.fromIntList(data); expect(address.toList(), checkdata); @@ -978,11 +1131,13 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress(fromList(data)); - expect(address.toString(), - '[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]'); + expect( + address.toString(), + '[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]', + ); }); test('Equals', () { const data = [ @@ -1005,7 +1160,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address1 = EthereumByteAddress(fromList(data)); final address2 = EthereumByteAddress(fromList(data)); @@ -1032,7 +1187,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; const data2 = [ 1, @@ -1054,7 +1209,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address1 = EthereumByteAddress(fromList(data1)); final address2 = EthereumByteAddress(fromList(data2)); @@ -1081,7 +1236,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; const data2 = [ 1, @@ -1103,7 +1258,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address2 = EthereumByteAddress(fromList(data2)); expect(data1 == address2.toList(), isFalse); @@ -1129,7 +1284,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress(fromList(data)); expect(address.asString, '0x0102030405060708090a0b0c0d0e0f1011121314'); @@ -1200,7 +1355,7 @@ void main() { 17, 18, 19, - 20 + 20, ]; final address = EthereumByteAddress(fromList(data)); final eaddress = EthereumAddress.fromByteAddress(address); @@ -1326,7 +1481,7 @@ void main() { final sync = { 'startingBlock': '0x384', 'currentBlock': '0x386', - 'highestBlock': '0x454' + 'highestBlock': '0x454', }; final message = EthereumSyncStatus.fromMap(sync); expect(message.syncing, isTrue); @@ -1370,27 +1525,37 @@ void main() { 'gas': '0x7f111', // 520465 'gasPrice': '0x09184e72a000', 'input': - '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360' - } + '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360', + }, }; final message = EthereumTransaction.fromMap(transaction); - expect(message.hash!.asString, - '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b'); + expect( + message.hash!.asString, + '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b', + ); expect(message.nonce, 0); - expect(message.blockHash!.asString, - '0xbeab0aa2411b7ab17f30a99d3cb9c6ef2fc5426d6ad6fd9e2a26a6aed1d1055b'); + expect( + message.blockHash!.asString, + '0xbeab0aa2411b7ab17f30a99d3cb9c6ef2fc5426d6ad6fd9e2a26a6aed1d1055b', + ); expect(message.blockNumber, 5599); expect(message.transactionIndex, 1); expect( - message.from!.asString, '0x407d73d8a49eeb85d32cf465507dd71d507100c1'); + message.from!.asString, + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ); expect( - message.to!.asString, '0x85a43d8a49eeb85d32cf465507dd71d507100c10'); + message.to!.asString, + '0x85a43d8a49eeb85d32cf465507dd71d507100c10', + ); expect(message.value, 520464); expect(message.gas, 520465); expect(message.gasPrice, 0x09184e72a000); - expect(message.input!.asString, - '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360'); + expect( + message.input!.asString, + '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360', + ); print(message); }); test('Block - null', () { @@ -1450,34 +1615,52 @@ void main() { 'timestamp': '0x54e34e8e', // 1424182926 'transactions': [ '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527332', - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527333' + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527333', ], 'uncles': [ '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334', - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335' - ] - } + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335', + ], + }, }; final message = EthereumBlock.fromMap(block); expect(message.number, 436); - expect(message.hash!.asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'); - expect(message.parentHash!.asString, - '0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5'); - expect(message.nonce!.asString, - '0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2'); - expect(message.sha3Uncles!.asString, - '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'); - expect(message.logsBloom!.asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'); - expect(message.transactionsRoot!.asString, - '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'); - expect(message.stateRoot!.asString, - '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff'); - expect(message.receiptsRoot!.asString, - '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff'); - expect(message.miner!.asString, - '0x4e65fda2159562a496f9f3522f89122a3088497a'); + expect( + message.hash!.asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ); + expect( + message.parentHash!.asString, + '0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5', + ); + expect( + message.nonce!.asString, + '0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2', + ); + expect( + message.sha3Uncles!.asString, + '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + ); + expect( + message.logsBloom!.asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ); + expect( + message.transactionsRoot!.asString, + '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + ); + expect( + message.stateRoot!.asString, + '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff', + ); + expect( + message.receiptsRoot!.asString, + '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff', + ); + expect( + message.miner!.asString, + '0x4e65fda2159562a496f9f3522f89122a3088497a', + ); expect(message.difficulty, 163591); expect(message.totalDifficulty, 163591); expect(message.extraData, EthereumData.fromBigInt(BigInt.zero)); @@ -1485,14 +1668,22 @@ void main() { expect(message.gasLimit, 653145); expect(message.gasUsed, 653145); expect(message.timestamp!.millisecondsSinceEpoch, 1424182926); - expect(message.transactions![0].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527332'); - expect(message.transactions![1].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527333'); - expect(message.uncles![0].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334'); - expect(message.uncles![1].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335'); + expect( + message.transactions![0].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527332', + ); + expect( + message.transactions![1].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527333', + ); + expect( + message.uncles![0].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334', + ); + expect( + message.uncles![1].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335', + ); expect(message.transactionsAreHashes, isTrue); print(message); }); @@ -1538,7 +1729,7 @@ void main() { 'gas': '0x7f111', // 520465 'gasPrice': '0x09184e72a000', 'input': - '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360' + '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360', }, { 'hash': @@ -1554,33 +1745,49 @@ void main() { 'gas': '0x7f111', // 520465 'gasPrice': '0x09184e72a000', 'input': - '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360' - } + '0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360', + }, ], 'uncles': [ '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334', - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335' - ] - } + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335', + ], + }, }; final message = EthereumBlock.fromMap(block); expect(message.number, 436); - expect(message.hash!.asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'); - expect(message.parentHash!.asString, - '0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5'); - expect(message.nonce!.asString, - '0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2'); - expect(message.sha3Uncles!.asString, - '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'); - expect(message.logsBloom!.asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'); - expect(message.transactionsRoot!.asString, - '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'); - expect(message.stateRoot!.asString, - '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff'); - expect(message.miner!.asString, - '0x4e65fda2159562a496f9f3522f89122a3088497a'); + expect( + message.hash!.asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ); + expect( + message.parentHash!.asString, + '0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5', + ); + expect( + message.nonce!.asString, + '0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2', + ); + expect( + message.sha3Uncles!.asString, + '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + ); + expect( + message.logsBloom!.asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ); + expect( + message.transactionsRoot!.asString, + '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + ); + expect( + message.stateRoot!.asString, + '0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff', + ); + expect( + message.miner!.asString, + '0x4e65fda2159562a496f9f3522f89122a3088497a', + ); expect(message.difficulty, 163591); expect(message.totalDifficulty, 163591); expect(message.extraData!.asBigInt, BigInt.zero); @@ -1591,10 +1798,14 @@ void main() { expect(message.transactions!.length, 2); expect(message.transactions![0].nonce, 0); expect(message.transactions![1].nonce, 1); - expect(message.uncles![0].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334'); - expect(message.uncles![1].asString, - '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335'); + expect( + message.uncles![0].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527334', + ); + expect( + message.uncles![1].asString, + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527335', + ); expect(message.transactionsAreHashes, isFalse); }); test('Log - null', () { @@ -1626,26 +1837,34 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] - } + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], + }, }; final message = EthereumLog.fromMap(log); expect(message.removed, false); expect(message.logIndex, 1); expect(message.blockNumber, 436); - expect(message.blockHash!.asString, - '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d'); - expect(message.transactionHash!.asString, - '0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf'); + expect( + message.blockHash!.asString, + '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d', + ); + expect( + message.transactionHash!.asString, + '0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf', + ); expect(message.transactionIndex, 0); - expect(message.address!.asString, - '0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d'); + expect( + message.address!.asString, + '0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d', + ); expect(message.data!.asBigInt, BigInt.zero); expect(message.topics, isNotNull); expect(message.topics!.length, 1); - expect(message.topics![0].asString, - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5'); + expect( + message.topics![0].asString, + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ); print(message); }); test('Transaction receipt - null', () { @@ -1693,8 +1912,8 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], }, { 'logIndex': '0x2', // 1 @@ -1708,26 +1927,32 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] - } + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], + }, ], 'logsBloom': '0x0', // 256 byte bloom filter - 'status': '0x1' - } + 'status': '0x1', + }, }; final message = EthereumTransactionReceipt.fromMap(tr); - expect(message.transactionHash!.asString, - '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'); + expect( + message.transactionHash!.asString, + '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238', + ); expect(message.transactionIndex, 1); expect(message.blockNumber, 11); - expect(message.blockHash!.asString, - '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b'); + expect( + message.blockHash!.asString, + '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b', + ); expect(message.cumulativeGasUsed, 13244); expect(message.gasUsed, 1244); - expect(message.contractAddress!.asString, - '0xb60e8dd61c5d32be8058bb8eb970870f07233155'); + expect( + message.contractAddress!.asString, + '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + ); expect(message.logs, isNotNull); expect(message.logs!.length, 2); expect(message.logs![0].logIndex, 1); @@ -1769,8 +1994,8 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], }, { 'logIndex': '0x2', // 1 @@ -1784,34 +2009,42 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] - } + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], + }, ], 'logsBloom': '0x0', // 256 byte bloom filter 'root': - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - } + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + }, }; final message = EthereumTransactionReceipt.fromMap(tr); - expect(message.transactionHash!.asString, - '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'); + expect( + message.transactionHash!.asString, + '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238', + ); expect(message.transactionIndex, 1); expect(message.blockNumber, 11); - expect(message.blockHash!.asString, - '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b'); + expect( + message.blockHash!.asString, + '0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b', + ); expect(message.cumulativeGasUsed, 13244); expect(message.gasUsed, 1244); - expect(message.contractAddress!.asString, - '0xb60e8dd61c5d32be8058bb8eb970870f07233155'); + expect( + message.contractAddress!.asString, + '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + ); expect(message.logs, isNotNull); expect(message.logs!.length, 2); expect(message.logs![0].logIndex, 1); expect(message.logs![1].logIndex, 2); expect(message.logsBloom!.asBigInt, BigInt.zero); - expect(message.root!.asString, - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5'); + expect( + message.root!.asString, + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ); expect(message.status, isNull); }); }); @@ -1827,17 +2060,21 @@ void main() { final filter = { 'result': [ '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d', - '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7e' - ] + '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7e', + ], }; final message = EthereumFilter.fromMap(filter); expect(message.logs, isNull); expect(message.hashes, isNotNull); expect(message.hashes!.length, 2); - expect(message.hashes![0].asString, - '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d'); - expect(message.hashes![1].asString, - '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7e'); + expect( + message.hashes![0].asString, + '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d', + ); + expect( + message.hashes![1].asString, + '0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7e', + ); }); test('Filter - logs', () { final filter = { @@ -1854,8 +2091,8 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], }, { 'logIndex': '0x2', // 1 @@ -1869,10 +2106,10 @@ void main() { 'data': '0x0000000000000000000000000000000000000000000000000000000000000000', 'topics': [ - '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5' - ] - } - ] + '0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5', + ], + }, + ], }; final message = EthereumFilter.fromMap(filter); expect(message.hashes, isNull); @@ -1892,15 +2129,21 @@ void main() { final work = [ '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0x5EED00000000000000000000000000005EED0000000000000000000000000000', - '0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000' + '0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000', ]; final message = EthereumWork.fromList(work); - expect(message.powHash!.asString, - '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'); - expect(message.seedHash!.asString, - '0x5EED00000000000000000000000000005EED0000000000000000000000000000'); - expect(message.boundaryCondition!.asString, - '0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000'); + expect( + message.powHash!.asString, + '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', + ); + expect( + message.seedHash!.asString, + '0x5EED00000000000000000000000000005EED0000000000000000000000000000', + ); + expect( + message.boundaryCondition!.asString, + '0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000', + ); print(message); final message1 = EthereumWork(); print(message1); @@ -1908,7 +2151,7 @@ void main() { test('Work - insufficient elements', () { final work = [ '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', - '0x5EED00000000000000000000000000005EED0000000000000000000000000000' + '0x5EED00000000000000000000000000005EED0000000000000000000000000000', ]; final message = EthereumWork.fromList(work); expect(message.powHash, isNull); @@ -1979,9 +2222,10 @@ void main() { expect(error.message, 'An Error'); expect(error.id, 50); expect( - error.timestamp!.millisecondsSinceEpoch <= - DateTime.now().millisecondsSinceEpoch, - isTrue); + error.timestamp!.millisecondsSinceEpoch <= + DateTime.now().millisecondsSinceEpoch, + isTrue, + ); expect(error.toString(), 'Code : 10 <> Message : An Error <> Id : 50'); }); }); @@ -1994,8 +2238,10 @@ void main() { await client.admin!.personalImportRawKey(null, ''); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalImportRawKey - keydata): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalImportRawKey - keydata): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2006,8 +2252,10 @@ void main() { await client.admin!.personalImportRawKey('', null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalImportRawKey - passphrase): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalImportRawKey - passphrase): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2018,8 +2266,10 @@ void main() { await client.admin!.personalLockAccount(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalLockAccount - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalLockAccount - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2030,8 +2280,10 @@ void main() { await client.admin!.personalNewAccount(null); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalNewAccount - passphrase): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalNewAccount - passphrase): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2042,8 +2294,10 @@ void main() { await client.admin!.personalUnlockAccount(null, ''); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalUnlockAccount - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalUnlockAccount - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2052,11 +2306,15 @@ void main() { var thrown = false; try { await client.admin!.personalUnlockAccount( - EthereumAddress.fromBigInt(BigInt.zero), null); + EthereumAddress.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalUnlockAccount - passphrase): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalUnlockAccount - passphrase): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2067,8 +2325,10 @@ void main() { await client.admin!.personalSendTransaction(null, 'password'); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalSendTransaction - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalSendTransaction - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2077,11 +2337,15 @@ void main() { var thrown = false; try { await client.admin!.personalSendTransaction( - EthereumAddress.fromBigInt(BigInt.zero), null); + EthereumAddress.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalSendTransaction - passphrase): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalSendTransaction - passphrase): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2090,11 +2354,16 @@ void main() { var thrown = false; try { await client.admin!.personalSign( - null, EthereumAddress.fromBigInt(BigInt.zero), 'password'); + null, + EthereumAddress.fromBigInt(BigInt.zero), + 'password', + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalSign - message): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalSign - message): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2103,11 +2372,16 @@ void main() { var thrown = false; try { await client.admin!.personalSign( - EthereumData.fromBigInt(BigInt.zero), null, 'password'); + EthereumData.fromBigInt(BigInt.zero), + null, + 'password', + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalSign - address): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalSign - address): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2115,12 +2389,16 @@ void main() { test('personalEcRecover - message', () async { var thrown = false; try { - await client.admin! - .personalEcRecover(null, EthereumData.fromBigInt(BigInt.zero)); + await client.admin!.personalEcRecover( + null, + EthereumData.fromBigInt(BigInt.zero), + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalEcRecover - message): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalEcRecover - message): Must not be null', + ); thrown = true; } expect(thrown, isTrue); @@ -2128,12 +2406,16 @@ void main() { test('personalEcRecover - signature', () async { var thrown = false; try { - await client.admin! - .personalEcRecover(EthereumData.fromBigInt(BigInt.zero), null); + await client.admin!.personalEcRecover( + EthereumData.fromBigInt(BigInt.zero), + null, + ); } on Error catch (e) { expect(e is ArgumentError, isTrue); - expect(e.toString(), - 'Invalid argument(s) (Ethereum::personalEcRecover - signature): Must not be null'); + expect( + e.toString(), + 'Invalid argument(s) (Ethereum::personalEcRecover - signature): Must not be null', + ); thrown = true; } expect(thrown, isTrue); diff --git a/test/manual/ethereum_browser_http.dart b/test/manual/ethereum_browser_http.dart index 6f0fa5d..a300b00 100644 --- a/test/manual/ethereum_browser_http.dart +++ b/test/manual/ethereum_browser_http.dart @@ -17,8 +17,9 @@ import 'ethereum_test_utilities.dart'; void main() { if (EthereumTestConfiguration.runBrowserHttp) { // Run the common API tests - final client = - EthereumBrowserHTTPClient.withConnectionParameters('localhost'); + final client = EthereumBrowserHTTPClient.withConnectionParameters( + 'localhost', + ); // Print errors client.printError = true; EthereumTestUtilities.browserHttpTestsRunning = true; diff --git a/test/manual/ethereum_browser_ws.dart b/test/manual/ethereum_browser_ws.dart index 54a86bd..c7bcf0e 100644 --- a/test/manual/ethereum_browser_ws.dart +++ b/test/manual/ethereum_browser_ws.dart @@ -17,8 +17,10 @@ import 'ethereum_test_utilities.dart'; void main() { if (EthereumTestConfiguration.runBrowserWS) { // Run the common API tests - final client = - EthereumBrowserWSClient.withConnectionParameters('localhost', 8546); + final client = EthereumBrowserWSClient.withConnectionParameters( + 'localhost', + 8546, + ); // Print errors client.printError = true; EthereumTestUtilities.browserWsTestsRunning = true; diff --git a/test/manual/ethereum_common.dart b/test/manual/ethereum_common.dart index b154542..e0eca45 100644 --- a/test/manual/ethereum_common.dart +++ b/test/manual/ethereum_common.dart @@ -77,8 +77,10 @@ class EthereumCommon { print('Coinbase address is $address'); } else { expect(client.eth!.lastError.code, -32000); - expect(client.eth!.lastError.message, - 'etherbase must be explicitly specified'); + expect( + client.eth!.lastError.message, + 'etherbase must be explicitly specified', + ); } }); test('Mining', () async { @@ -107,7 +109,9 @@ class EthereumCommon { if (accounts.isNotEmpty) { print('Accounts are $accountsStr'); expect( - accounts[0].asString, EthereumTestConfiguration.defaultAccount); + accounts[0].asString, + EthereumTestConfiguration.defaultAccount, + ); } else { print('There are no accounts'); } @@ -122,9 +126,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.number = 0; final balance = await client.eth!.getBalance( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(balance, isNotNull); expect(client.eth!.id, ++id); print('Balance number is $balance'); @@ -133,9 +139,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.latest = true; final balance = await client.eth!.getBalance( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(balance, isNotNull); expect(client.eth!.id, ++id); print('Balance latest is $balance'); @@ -144,9 +152,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.earliest = true; final balance = await client.eth!.getBalance( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(balance, isNotNull); expect(client.eth!.id, ++id); print('Balance earliest is $balance'); @@ -155,9 +165,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.pending = true; final balance = await client.eth!.getBalance( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(balance, isNotNull); expect(client.eth!.id, ++id); print('Balance pending is $balance'); @@ -166,10 +178,12 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.latest = true; final storage = await client.eth!.getStorageAt( - EthereumAddress.fromString( - '0x295a70b2de5e3953354a6a8344e616ed314d7251'), - 0x0, - block); + EthereumAddress.fromString( + '0x295a70b2de5e3953354a6a8344e616ed314d7251', + ), + 0x0, + block, + ); expect(storage, isNotNull); expect(client.eth!.id, ++id); print('Storage at latest is $storage'); @@ -178,10 +192,12 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.earliest = true; final storage = await client.eth!.getStorageAt( - EthereumAddress.fromString( - '0x295a70b2de5e3953354a6a8344e616ed314d7251'), - 0x0, - block); + EthereumAddress.fromString( + '0x295a70b2de5e3953354a6a8344e616ed314d7251', + ), + 0x0, + block, + ); expect(storage, isNotNull); expect(client.eth!.id, ++id); print('Storage at earliest is $storage'); @@ -190,10 +206,12 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.pending = true; final storage = await client.eth!.getStorageAt( - EthereumAddress.fromString( - '0x295a70b2de5e3953354a6a8344e616ed314d7251'), - 0x0, - block); + EthereumAddress.fromString( + '0x295a70b2de5e3953354a6a8344e616ed314d7251', + ), + 0x0, + block, + ); expect(storage, isNotNull); expect(client.eth!.id, ++id); print('Storage at pending is $storage'); @@ -202,10 +220,12 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.number = 0x4b7; final storage = await client.eth!.getStorageAt( - EthereumAddress.fromString( - '0x295a70b2de5e3953354a6a8344e616ed314d7251'), - 0x0, - block); + EthereumAddress.fromString( + '0x295a70b2de5e3953354a6a8344e616ed314d7251', + ), + 0x0, + block, + ); if (storage != null) { expect(storage.asBigInt, BigInt.zero); } @@ -216,9 +236,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.number = 0; final count = await client.eth!.getTransactionCount( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(count, isNotNull); expect(client.eth!.id, ++id); print('Transaction count is $count'); @@ -227,9 +249,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.earliest = true; final count = await client.eth!.getTransactionCount( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(count, isNotNull); expect(client.eth!.id, ++id); print('Transaction count is $count'); @@ -238,9 +262,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.pending = true; final count = await client.eth!.getTransactionCount( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(count, isNotNull); expect(client.eth!.id, ++id); print('Transaction count is $count'); @@ -249,17 +275,21 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.latest = true; final count = await client.eth!.getTransactionCount( - EthereumAddress.fromString( - '0x407d73d8a49eeb85d32cf465507dd71d507100c1'), - block); + EthereumAddress.fromString( + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + ), + block, + ); expect(count, isNotNull); expect(client.eth!.id, ++id); print('Transaction count is $count'); }); test('Block transaction count by hash', () async { final count = await client.eth!.getBlockTransactionCountByHash( - EthereumData.fromString( - '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238')); + EthereumData.fromString( + '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238', + ), + ); expect(count, 0); expect(client.eth!.id, ++id); }); @@ -292,8 +322,11 @@ class EthereumCommon { expect(client.eth!.id, ++id); }); test('Block uncle count by hash', () async { - final count = await client.eth!.getUncleCountByHash(EthereumData.fromString( - '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238')); + final count = await client.eth!.getUncleCountByHash( + EthereumData.fromString( + '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238', + ), + ); expect(count, 0); expect(client.eth!.id, ++id); }); @@ -329,9 +362,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.number = 0; final code = await client.eth!.getCode( - EthereumAddress.fromString( - '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - block); + EthereumAddress.fromString( + '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + block, + ); expect(code, isNull); expect(client.eth!.id, ++id); print('Code is $code'); @@ -340,9 +375,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.latest = true; final code = await client.eth!.getCode( - EthereumAddress.fromString( - '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - block); + EthereumAddress.fromString( + '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + block, + ); expect(code, isNull); expect(client.eth!.id, ++id); print('Code is $code'); @@ -351,9 +388,11 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.pending = true; final code = await client.eth!.getCode( - EthereumAddress.fromString( - '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - block); + EthereumAddress.fromString( + '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + block, + ); expect(code, isNull); expect(client.eth!.id, ++id); print('Code is $code'); @@ -362,18 +401,20 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.earliest = true; final code = await client.eth!.getCode( - EthereumAddress.fromString( - '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - block); + EthereumAddress.fromString( + '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + block, + ); expect(code, isNull); expect(client.eth!.id, ++id); print('Code is $code'); }); test('Sign', () async { final signature = await client.eth!.sign( - EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - EthereumData.fromString('0xdeadbeaf')); + EthereumAddress.fromString(EthereumTestConfiguration.defaultAccount), + EthereumData.fromString('0xdeadbeaf'), + ); if (signature != null) { print(signature); } else { @@ -383,16 +424,18 @@ class EthereumCommon { }); test('Send transaction', () async { final hash = await client.eth!.sendTransaction( - EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'), - to: EthereumAddress.fromString( - '0xd46e8dd67c5d32be8058bb8eb970870f07244567'), - gas: 0x100, - gasPrice: 0x1000, - value: 0x2000, - nonce: 2); + EthereumAddress.fromString(EthereumTestConfiguration.defaultAccount), + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + to: EthereumAddress.fromString( + '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + ), + gas: 0x100, + gasPrice: 0x1000, + value: 0x2000, + nonce: 2, + ); if (hash != null) { print(hash); } @@ -401,13 +444,15 @@ class EthereumCommon { }); test('Send transaction - some null', () async { final hash = await client.eth!.sendTransaction( - EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675'), - to: EthereumAddress.fromString( - '0xd46e8dd67c5d32be8058bb8eb970870f07244567'), - nonce: 2); + EthereumAddress.fromString(EthereumTestConfiguration.defaultAccount), + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + to: EthereumAddress.fromString( + '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + ), + nonce: 2, + ); if (hash != null) { print(hash); } @@ -415,8 +460,11 @@ class EthereumCommon { expect(client.eth!.lastError.id, id); }); test('Send raw transaction', () async { - final hash = await client.eth!.sendRawTransaction(EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675')); + final hash = await client.eth!.sendRawTransaction( + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + ); if (hash != null) { print(hash); } @@ -427,16 +475,18 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.number = 0x10; final ret = await client.eth!.call( - EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - block, - from: EthereumAddress.fromString( - '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c'), - gas: 0x2000, - gasPrice: 0x1000, - value: 0x2000, - data: EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675')); + EthereumAddress.fromString(EthereumTestConfiguration.defaultAccount), + block, + from: EthereumAddress.fromString( + '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c', + ), + gas: 0x2000, + gasPrice: 0x1000, + value: 0x2000, + data: EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + ); if (ret != null) { print(ret); } @@ -446,14 +496,16 @@ class EthereumCommon { final block = EthereumDefaultBlock(); block.latest = true; final ret = await client.eth!.call( - EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - block, - from: EthereumAddress.fromString( - '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c'), - gasPrice: 0x1000, - data: EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675')); + EthereumAddress.fromString(EthereumTestConfiguration.defaultAccount), + block, + from: EthereumAddress.fromString( + '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c', + ), + gasPrice: 0x1000, + data: EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + ); if (ret != null) { print(ret); } @@ -461,15 +513,19 @@ class EthereumCommon { }); test('Estimate gas', () async { final ret = await client.eth!.estimateGas( - address: EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - from: EthereumAddress.fromString( - '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c'), - gas: 0x2000, - gasPrice: 0x1000, - value: 0x2000, - data: EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675')); + address: EthereumAddress.fromString( + EthereumTestConfiguration.defaultAccount, + ), + from: EthereumAddress.fromString( + '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c', + ), + gas: 0x2000, + gasPrice: 0x1000, + value: 0x2000, + data: EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', + ), + ); if (ret != null) { print(ret); } @@ -477,20 +533,26 @@ class EthereumCommon { }); test('Estimate gas - some null', () async { final ret = await client.eth!.estimateGas( - address: EthereumAddress.fromString( - EthereumTestConfiguration.defaultAccount), - from: EthereumAddress.fromString( - '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c'), - gas: 0x2000, - gasPrice: 0x1000); + address: EthereumAddress.fromString( + EthereumTestConfiguration.defaultAccount, + ), + from: EthereumAddress.fromString( + '0xd10de988e845d33859c3f96c7f1fc723b7b56f4c', + ), + gas: 0x2000, + gasPrice: 0x1000, + ); if (ret != null) { print(ret); } expect(client.eth!.id, ++id); }); test('Get block by hash', () async { - final ret = await client.eth!.getBlockByHash(EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8')); + final ret = await client.eth!.getBlockByHash( + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8', + ), + ); if (ret != null) { print(ret); } @@ -506,8 +568,11 @@ class EthereumCommon { expect(client.eth!.id, ++id); }); test('Get transaction by hash', () async { - final ret = await client.eth!.getTransactionByHash(EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8')); + final ret = await client.eth!.getTransactionByHash( + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8', + ), + ); if (ret != null) { print(ret); } @@ -515,9 +580,11 @@ class EthereumCommon { }); test('Get transaction by block hash and index', () async { final ret = await client.eth!.getTransactionByBlockHashAndIndex( - EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8'), - 0); + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8', + ), + 0, + ); if (ret != null) { print(ret); } @@ -526,16 +593,21 @@ class EthereumCommon { test('Get transaction by block number and index', () async { final block = EthereumDefaultBlock(); block.number = 0x100; - final ret = - await client.eth!.getTransactionByBlockNumberAndIndex(block, 0); + final ret = await client.eth!.getTransactionByBlockNumberAndIndex( + block, + 0, + ); if (ret != null) { print(ret); } expect(client.eth!.id, ++id); }); test('Get transaction receipt', () async { - var ret = await client.eth!.getTransactionReceipt(EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8')); + var ret = await client.eth!.getTransactionReceipt( + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8', + ), + ); if (ret != null) { print(ret); } @@ -543,9 +615,11 @@ class EthereumCommon { }); test('Get uncle by block hash and index', () async { final ret = await client.eth!.getUncleByBlockHashAndIndex( - EthereumData.fromString( - '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8'), - 0); + EthereumData.fromString( + '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8', + ), + 0, + ); if (ret != null) { print(ret); } @@ -567,16 +641,20 @@ class EthereumCommon { final to = EthereumDefaultBlock(); from.number = 2; filterId = await client.eth!.newFilter( - fromBlock: from, - toBlock: to, - address: EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db1'), - topics: [ - EthereumData.fromString( - '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - EthereumData.fromString( - '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b') - ]); + fromBlock: from, + toBlock: to, + address: EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db1', + ), + topics: [ + EthereumData.fromString( + '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + EthereumData.fromString( + '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + ], + ); if (filterId != null) { print(filterId); } @@ -587,18 +665,26 @@ class EthereumCommon { from.number = 1; final to = EthereumDefaultBlock(); from.number = 2; - filterId = await client.eth! - .newFilter(fromBlock: from, toBlock: to, address: [ - EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db1'), - EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db2') - ], topics: [ - EthereumData.fromString( - '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b'), - EthereumData.fromString( - '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b') - ]); + filterId = await client.eth!.newFilter( + fromBlock: from, + toBlock: to, + address: [ + EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db1', + ), + EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db2', + ), + ], + topics: [ + EthereumData.fromString( + '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + EthereumData.fromString( + '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + ], + ); if (filterId != null) { print(filterId); } @@ -646,14 +732,17 @@ class EthereumCommon { final to = EthereumDefaultBlock(); to.earliest = true; final ret = await client.eth!.getLogs( - fromBlock: from, - toBlock: to, - address: EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db2'), - topics: [ - EthereumData.fromString( - '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b') - ]); + fromBlock: from, + toBlock: to, + address: EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db2', + ), + topics: [ + EthereumData.fromString( + '0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b', + ), + ], + ); if (ret != null) { print(ret); } @@ -668,24 +757,30 @@ class EthereumCommon { }); test('Submit work', () async { final ret = await client.eth!.submitWork( - EthereumData.fromString('0x123456789abcdef0'), - EthereumData.fromString( - '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'), - EthereumData.fromString( - '0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000')); + EthereumData.fromString('0x123456789abcdef0'), + EthereumData.fromString( + '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', + ), + EthereumData.fromString( + '0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000', + ), + ); expect(ret, isFalse); expect(client.eth!.id, ++id); }); test('Submit hash rate', () async { final ret = await client.eth!.submitHashrate( - EthereumData.fromString('0x500000'), - '0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'); + EthereumData.fromString('0x500000'), + '0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c', + ); if (ret != null) { expect(ret, isTrue); } else { expect(client.eth!.lastError.code, -32601); - expect(client.eth!.lastError.message, - 'The method eth_submitHashrate does not exist/is not available'); + expect( + client.eth!.lastError.message, + 'The method eth_submitHashrate does not exist/is not available', + ); } expect(client.eth!.id, ++id); }, skip: true); @@ -699,21 +794,30 @@ class EthereumCommon { expect(ok, isTrue); } else { expect(client.eth!.lastError.code, -32601); - expect(client.eth!.lastError.message, - 'The method shh_version does not exist/is not available'); + expect( + client.eth!.lastError.message, + 'The method shh_version does not exist/is not available', + ); } print('SHH version is $version'); expect(client.eth!.id, ++id); }, skip: true); test('SHH post', () async { - final ret = await client.eth!.shhPost([ - EthereumData.fromString('0x776869737065722d636861742d636c69656e74'), - EthereumData.fromString('0x4d5a695276454c39425154466b61693532') - ], EthereumData.fromString('0x7b2274797065223a226d60'), 0x64, 0x64, - to: EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db2'), - from: EthereumAddress.fromString( - '0x8888f1f195afa192cfee860698584c030f4c9db2')); + final ret = await client.eth!.shhPost( + [ + EthereumData.fromString('0x776869737065722d636861742d636c69656e74'), + EthereumData.fromString('0x4d5a695276454c39425154466b61693532'), + ], + EthereumData.fromString('0x7b2274797065223a226d60'), + 0x64, + 0x64, + to: EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db2', + ), + from: EthereumAddress.fromString( + '0x8888f1f195afa192cfee860698584c030f4c9db2', + ), + ); expect(ret, isNull); expect(client.eth!.id, ++id); }, skip: true); @@ -724,8 +828,9 @@ class EthereumCommon { EthereumData? signature; test('Personal ImportRawKey', () async { final key = await client.admin!.personalImportRawKey( - 'b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7', - 'password'); + 'b5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7', + 'password', + ); if (key != null) { expect(key.asBigInt!.isValidInt, true); } else { @@ -761,8 +866,11 @@ class EthereumCommon { }); test('Personal Sign', () async { final message = EthereumData.fromBigInt(BigInt.from(0xdeadbeaf)); - final ret = await (client.admin! - .personalSign(message, lockAddress, 'password')); + final ret = await (client.admin!.personalSign( + message, + lockAddress, + 'password', + )); expect(ret, isNotNull); signature = ret; print(ret!.asString); diff --git a/test/manual/ethereum_test_utilities.dart b/test/manual/ethereum_test_utilities.dart index 10bc6e5..0cd6999 100644 --- a/test/manual/ethereum_test_utilities.dart +++ b/test/manual/ethereum_test_utilities.dart @@ -13,11 +13,15 @@ import 'package:ethereum/ethereum.dart'; class EthereumTestUtilities { /// Hex String list to Integer list static List hexToIntList(List val) => List.generate( - val.length, (int index) => EthereumUtilities.hexToInt(val[index])); + val.length, + (int index) => EthereumUtilities.hexToInt(val[index]), + ); /// Integer list to Hex String list static List intToHexList(List val) => List.generate( - val.length, (int index) => EthereumUtilities.intToHex(val[index])); + val.length, + (int index) => EthereumUtilities.intToHex(val[index]), + ); static bool browserWsTestsRunning = false; static bool browserHttpTestsRunning = false; From cda7f800a3b242a10d7008fe860cd26b8f4151f1 Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Fri, 9 May 2025 10:57:10 +0100 Subject: [PATCH 2/6] Issue 23 - DCM fixes --- lib/ethereum_browser_http_client.dart | 8 +++--- lib/ethereum_browser_ws_client.dart | 7 +++-- lib/ethereum_server_client.dart | 8 +++--- lib/src/api/ethereum_api.dart | 8 +++--- lib/src/api/ethereum_api_admin.dart | 29 +++++++++---------- lib/src/api/ethereum_api_eth.dart | 40 ++++++++++++--------------- pubspec.yaml | 1 + 7 files changed, 47 insertions(+), 54 deletions(-) diff --git a/lib/ethereum_browser_http_client.dart b/lib/ethereum_browser_http_client.dart index c30b336..801e437 100644 --- a/lib/ethereum_browser_http_client.dart +++ b/lib/ethereum_browser_http_client.dart @@ -19,6 +19,10 @@ part 'src/adapters/ethereum_browser_http_adapter.dart'; /// The browser HTTP client class EthereumBrowserHTTPClient extends Ethereum { + /// The adapter + static final EthereumBrowserHTTPAdapter browserHttpAdapter = + EthereumBrowserHTTPAdapter(); + /// Construction EthereumBrowserHTTPClient() : super(browserHttpAdapter); @@ -32,8 +36,4 @@ class EthereumBrowserHTTPClient extends Ethereum { Ethereum.rpcHttpScheme, port, ); - - /// The adapter - static EthereumBrowserHTTPAdapter browserHttpAdapter = - EthereumBrowserHTTPAdapter(); } diff --git a/lib/ethereum_browser_ws_client.dart b/lib/ethereum_browser_ws_client.dart index e54b900..3359024 100644 --- a/lib/ethereum_browser_ws_client.dart +++ b/lib/ethereum_browser_ws_client.dart @@ -20,6 +20,10 @@ part 'src/adapters/ethereum_browser_ws_adapter.dart'; /// The browser web socket client class EthereumBrowserWSClient extends Ethereum { + /// The adapter + static final EthereumBrowserWSAdapter browserWSAdapter = + EthereumBrowserWSAdapter(); + /// Default construction EthereumBrowserWSClient() : super(browserWSAdapter); @@ -31,7 +35,4 @@ class EthereumBrowserWSClient extends Ethereum { Ethereum.rpcWsScheme, port, ); - - /// The adapter - static EthereumBrowserWSAdapter browserWSAdapter = EthereumBrowserWSAdapter(); } diff --git a/lib/ethereum_server_client.dart b/lib/ethereum_server_client.dart index 26847f6..370746d 100644 --- a/lib/ethereum_server_client.dart +++ b/lib/ethereum_server_client.dart @@ -18,6 +18,10 @@ part 'src/adapters/ethereum_server_http_adapter.dart'; /// The server HTTP client class EthereumServerClient extends Ethereum { + /// The adapter + static final EthereumServerHTTPAdapter serverHttpAdapter = + EthereumServerHTTPAdapter(); + /// Default constructor EthereumServerClient() : super(serverHttpAdapter); @@ -29,8 +33,4 @@ class EthereumServerClient extends Ethereum { Ethereum.rpcHttpScheme, port, ); - - /// The adapter - static EthereumServerHTTPAdapter serverHttpAdapter = - EthereumServerHTTPAdapter(); } diff --git a/lib/src/api/ethereum_api.dart b/lib/src/api/ethereum_api.dart index 0a33114..1e3608b 100644 --- a/lib/src/api/ethereum_api.dart +++ b/lib/src/api/ethereum_api.dart @@ -11,10 +11,7 @@ part of '../../ethereum.dart'; /// The API base class class EthereumApi { - /// Construction - EthereumApi(this._client); - - /// Our client + // Our client final Ethereum _client; /// Message Id @@ -22,4 +19,7 @@ class EthereumApi { /// Last error EthereumError get lastError => _client.lastError; + + /// Construction + EthereumApi(this._client); } diff --git a/lib/src/api/ethereum_api_admin.dart b/lib/src/api/ethereum_api_admin.dart index 99e8b06..6dbf88d 100644 --- a/lib/src/api/ethereum_api_admin.dart +++ b/lib/src/api/ethereum_api_admin.dart @@ -9,8 +9,10 @@ part of '../../ethereum.dart'; -/// This class implements the Ethereuum Admin API +/// This class implements the Ethereum Admin API class EthereumApiAdmin extends EthereumApi { + static const unlockDuration = 300; //seconds + /// Construction EthereumApiAdmin(super.client); @@ -87,14 +89,14 @@ class EthereumApiAdmin extends EthereumApi { /// Decrypts the key with the given address from the key store. /// The unencrypted key will be held in memory until the unlock /// duration expires. - /// The unlock duration defaults to 300 seconds. + /// The unlock duration defaults to [unlockDuration] seconds. /// An explicit duration of zero seconds unlocks the key until geth exits. /// The account can be used with eth_sign and eth_sendTransaction /// while it is unlocked. Future personalUnlockAccount( EthereumAddress? address, String? passphrase, [ - int duration = 300, + int duration = unlockDuration, ]) async { if (address == null) { throw ArgumentError.notNull('Ethereum::personalUnlockAccount - address'); @@ -151,19 +153,14 @@ class EthereumApiAdmin extends EthereumApi { ); } Map? conditionObject = {}; - if (condition == null) { - conditionObject = null; - } else { - if (conditionIsTimestamp) { - conditionObject = { - 'timestamp': EthereumUtilities.intToHex(condition), - }; - } else { - conditionObject = { - 'block': EthereumUtilities.intToHex(condition), - }; - } - } + conditionObject = + condition == null + ? null + : conditionIsTimestamp + ? { + 'timestamp': EthereumUtilities.intToHex(condition), + } + : {'block': EthereumUtilities.intToHex(condition)}; final paramBlock = { 'from': address.asString, 'to': to?.asString, diff --git a/lib/src/api/ethereum_api_eth.dart b/lib/src/api/ethereum_api_eth.dart index d4c9ff6..3c55350 100644 --- a/lib/src/api/ethereum_api_eth.dart +++ b/lib/src/api/ethereum_api_eth.dart @@ -9,8 +9,10 @@ part of '../../ethereum.dart'; -/// This class implements the Ethereuum eth API, sometimes referred to as DApp +/// This class implements the Ethereum eth API, sometimes referred to as DApp class EthereumApiEth extends EthereumApi { + static const gasDefault = 7000; + /// Construction EthereumApiEth(super.client); @@ -257,11 +259,9 @@ class EthereumApiEth extends EthereumApi { final params = [blockHash.asString]; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { - if (res[EthereumConstants.ethResultKey] != null) { - return EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]); - } else { - return 0; - } + return res[EthereumConstants.ethResultKey] != null + ? EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]) + : 0; } _client.processError(method, res); return null; @@ -284,11 +284,9 @@ class EthereumApiEth extends EthereumApi { final params = [blockString]; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { - if (res[EthereumConstants.ethResultKey] != null) { - return EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]); - } else { - return 0; - } + return res[EthereumConstants.ethResultKey] != null + ? EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]) + : 0; } _client.processError(method, res); return null; @@ -307,11 +305,9 @@ class EthereumApiEth extends EthereumApi { final params = [blockHash.asString]; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { - if (res[EthereumConstants.ethResultKey] != null) { - return EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]); - } else { - return 0; - } + return res[EthereumConstants.ethResultKey] != null + ? EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]) + : 0; } _client.processError(method, res); return null; @@ -332,11 +328,9 @@ class EthereumApiEth extends EthereumApi { final params = [blockString]; final dynamic res = await _client.rpcClient.request(method, params); if (res != null && res.containsKey(EthereumConstants.ethResultKey)) { - if (res[EthereumConstants.ethResultKey] != null) { - return EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]); - } else { - return 0; - } + return res[EthereumConstants.ethResultKey] != null + ? EthereumUtilities.hexToInt(res[EthereumConstants.ethResultKey]) + : 0; } _client.processError(method, res); return null; @@ -394,7 +388,7 @@ class EthereumApiEth extends EthereumApi { /// address: The address the transaction is sent from. /// to: (optional when creating new contract) /// The address the transaction is directed to. - /// gas: (optional, default: 90000) + /// gas: (optional, default: [gasDefault]) /// Integer of the gas provided for the transaction execution. /// It will return unused gas. /// gasPrice: (optional, default: @@ -411,7 +405,7 @@ class EthereumApiEth extends EthereumApi { EthereumAddress? address, EthereumData? data, { EthereumAddress? to, - int gas = 9000, + int gas = gasDefault, int? gasPrice, int? value, int? nonce, diff --git a/pubspec.yaml b/pubspec.yaml index 2fc26a2..8121407 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,4 +21,5 @@ dev_dependencies: build_test: '^2.2.2' build_web_compilers: '^4.0.7' lints: '^5.0.0' + dart_code_metrics_presets: '^2.22.0' From 078ecad85afe5b1a6dafc92f9418179f8261d2e8 Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Fri, 9 May 2025 11:03:11 +0100 Subject: [PATCH 3/6] Issue 23 - DCM fixes --- lib/src/datatypes/ethereum_address.dart | 38 ++++++++++--------- lib/src/datatypes/ethereum_byte_address.dart | 40 ++++++++++---------- lib/src/datatypes/ethereum_data.dart | 38 +++++++++---------- 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/lib/src/datatypes/ethereum_address.dart b/lib/src/datatypes/ethereum_address.dart index b6d344f..49713a2 100644 --- a/lib/src/datatypes/ethereum_address.dart +++ b/lib/src/datatypes/ethereum_address.dart @@ -1,3 +1,5 @@ +// ignore_for_file: no-magic-number + /* * Package : Ethereum * Author : S. Hamblett @@ -12,6 +14,24 @@ part of '../../ethereum.dart'; /// The address data type. If any supplied value cannot be safely represented as /// an Ethereum address FormatException will be thrown. class EthereumAddress { + /// The address length in characters + static const int addressCharacterLength = 40; + + /// The BigInt + BigInt? _bigint; + + /// The string + String? _string; + + /// Get as a BigInt + BigInt? get asBigInt => _bigint; + + /// Get as a String, includes the 0x prefix + String? get asString => _string; + + @override + int get hashCode => _bigint.hashCode; + /// From a BigInt. The value must be convertible into the /// standard Ethereum address /// format of 20 bytes, however unlike the string constructor @@ -37,21 +57,6 @@ class EthereumAddress { _bigint = _safeParse(_string!); } - /// The address length in characters - static const int addressCharacterLength = 40; - - /// The BigInt - BigInt? _bigint; - - /// The string - String? _string; - - /// Get as a BigInt - BigInt? get asBigInt => _bigint; - - /// Get as a String, includes the 0x prefix - String? get asString => _string; - @override String toString() => asString!; @@ -61,9 +66,6 @@ class EthereumAddress { other.runtimeType == runtimeType && _bigint == (other as EthereumAddress)._bigint; - @override - int get hashCode => _bigint.hashCode; - /// Address string list to EthereumAddress list static List toList(List val) => List.generate( diff --git a/lib/src/datatypes/ethereum_byte_address.dart b/lib/src/datatypes/ethereum_byte_address.dart index 84188ba..29d9d6a 100644 --- a/lib/src/datatypes/ethereum_byte_address.dart +++ b/lib/src/datatypes/ethereum_byte_address.dart @@ -11,6 +11,26 @@ part of '../../ethereum.dart'; /// Ethereum address as a byte array, 20 bytes long class EthereumByteAddress { + static const maxIntValue = 255; + + /// The length of an Ethereum address in bytes + static const int addressByteLength = 20; + + ByteData? _data; + + /// The raw byte data + ByteData? get byteData => _data; + + @override + int get hashCode => _data.hashCode; + + /// As an address string, i.e 40 hex chars with a leading 0x + String get asString { + const encoder = HexEncoder(); + final hex = encoder.convert(toList() as List); + return '0x$hex'; + } + /// If the length is greater than addressByteLength then only /// addressByteLength are taken. /// If the length is less than addressByteLength the size is padded @@ -26,21 +46,13 @@ class EthereumByteAddress { EthereumByteAddress.fromIntList(List data) { final tmp = ByteData(data.length); for (var i = 0; i < tmp.lengthInBytes; i++) { - if (data[i] <= 255) { + if (data[i] <= maxIntValue) { tmp.setUint8(i, data[i]); } } _setData(tmp); } - /// The length of an Ethereum address in bytes - static const int addressByteLength = 20; - - ByteData? _data; - - /// The raw byte data - ByteData? get byteData => _data; - /// To integer list List toList() { final tmp = List.filled(addressByteLength, 0); @@ -50,13 +62,6 @@ class EthereumByteAddress { return tmp; } - /// As an address string, i.e 40 hex chars with a leading 0x - String get asString { - const encoder = HexEncoder(); - final hex = encoder.convert(toList() as List); - return '0x$hex'; - } - @override String toString() => toList().toString(); @@ -66,9 +71,6 @@ class EthereumByteAddress { other.runtimeType == runtimeType && _isEqual((other as EthereumByteAddress)._data); - @override - int get hashCode => _data.hashCode; - bool _isEqual(ByteData? data) { for (var i = 0; i <= _data!.lengthInBytes - 1; i++) { if (data!.getUint8(i) != _data!.getUint8(i)) { diff --git a/lib/src/datatypes/ethereum_data.dart b/lib/src/datatypes/ethereum_data.dart index 48c0e09..d77af4d 100644 --- a/lib/src/datatypes/ethereum_data.dart +++ b/lib/src/datatypes/ethereum_data.dart @@ -1,3 +1,5 @@ +// ignore_for_file: no-magic-number + /* * Package : Ethereum * Author : S. Hamblett @@ -11,6 +13,21 @@ part of '../../ethereum.dart'; /// The Ethereum data type. This is not as constrained as the address type. class EthereumData { + /// The BigInt + BigInt? _bigint; + + /// The string + String? _string; + + /// Get as a BigInt + BigInt? get asBigInt => _bigint; + + /// Get as a String, includes the 0x prefix + String? get asString => _string; + + @override + int get hashCode => _bigint.hashCode; + /// From a BigInt. EthereumData.fromBigInt(BigInt val) { _bigint = val; @@ -25,18 +42,6 @@ class EthereumData { _bigint = _safeParse(_string!); } - /// The BigInt - BigInt? _bigint; - - /// The string - String? _string; - - /// Get as a BigInt - BigInt? get asBigInt => _bigint; - - /// Get as a String, includes the 0x prefix - String? get asString => _string; - @override String toString() => asString!; @@ -46,9 +51,6 @@ class EthereumData { other.runtimeType == runtimeType && _bigint == (other as EthereumData)._bigint; - @override - int get hashCode => _bigint.hashCode; - /// Data string list to EthereumAddress list static List toList(List val) => List.generate( @@ -73,11 +75,7 @@ class EthereumData { BigInt _safeParse(String val) { // If the string is zero trap this - if (val.contains(RegExp(r'[1-9]'))) { - return BigInt.parse(val); - } else { - return BigInt.zero; - } + return val.contains(RegExp(r'[1-9]')) ? BigInt.parse(val) : BigInt.zero; } void _checkString(String val) { From 8601d5e1bc35d9ad6caf26bef8efb51298b54b9a Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Sat, 10 May 2025 11:05:48 +0100 Subject: [PATCH 4/6] Issue 23 - DCM fixes --- lib/src/ethereum.dart | 134 +++++++++++++-------------- lib/src/ethereum_error.dart | 16 ++-- lib/src/ethereum_rpc_client.dart | 16 ++-- lib/src/ethereum_utilities.dart | 2 + lib/src/messages/ethereum_block.dart | 96 ++++++++++--------- 5 files changed, 129 insertions(+), 135 deletions(-) diff --git a/lib/src/ethereum.dart b/lib/src/ethereum.dart index 0796bea..35fb78a 100644 --- a/lib/src/ethereum.dart +++ b/lib/src/ethereum.dart @@ -14,30 +14,6 @@ part of '../ethereum.dart'; /// can be found at https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion. /// The API calls return null if an ethereum error occurred. class Ethereum { - /// Default constructor - Ethereum(this._networkAdapter) { - rpcClient = EthereumRpcClient(_networkAdapter); - - /// Construct the API classes - _eth = EthereumApiEth(this); - _admin = EthereumApiAdmin(this); - } - - /// With connection parameters - Ethereum.withConnectionParameters( - EthereumINetworkAdapter adapter, - String hostname, - String scheme, [ - int? port = defaultHttpPort, - ]) : _networkAdapter = adapter { - rpcClient = EthereumRpcClient(_networkAdapter); - - /// Construct the API classes - _eth = EthereumApiEth(this); - _admin = EthereumApiAdmin(this); - connectParameters(scheme, hostname, port); - } - /// Constants /// HTTP scheme static const String rpcHttpScheme = 'http'; @@ -59,28 +35,66 @@ class Ethereum { /// Host String? host; + /// Json RPC client + late EthereumRpcClient rpcClient; + + /// Print errors, default is off + bool printError = false; + + /// Last error + EthereumError lastError = EthereumError(); + late Uri _uri; + // Network adaptor + EthereumINetworkAdapter _networkAdapter; + + // Admin API + EthereumApiAdmin? _admin; + + // Eth API + EthereumApiEth? _eth; + /// Uri Uri get uri => _uri; - EthereumINetworkAdapter _networkAdapter; + /// Transmission id + int get id => rpcClient.id; + + /// The ETH API + EthereumApiEth? get eth => _eth; + + /// The Admin API + EthereumApiAdmin? get admin => _admin; /// HTTP Adapter set httpAdapter(EthereumINetworkAdapter adapter) => _networkAdapter = adapter; - /// Json RPC client - late EthereumRpcClient rpcClient; + set id(int? value) => rpcClient.resetTransmissionId(value); - /// Last error - EthereumError lastError = EthereumError(); + /// Default constructor + Ethereum(this._networkAdapter) { + rpcClient = EthereumRpcClient(_networkAdapter); - set id(int? value) => rpcClient.resetTransmissionId(value); + /// Construct the API classes + _eth = EthereumApiEth(this); + _admin = EthereumApiAdmin(this); + } - /// Transmission id - int get id => rpcClient.id; + /// With connection parameters + Ethereum.withConnectionParameters( + EthereumINetworkAdapter adapter, + String hostname, + String scheme, [ + int? port = defaultHttpPort, + ]) : _networkAdapter = adapter { + rpcClient = EthereumRpcClient(_networkAdapter); - /// Connection methods + /// Construct the API classes + _eth = EthereumApiEth(this); + _admin = EthereumApiAdmin(this); + connectParameters(scheme, hostname, port); + } //// Connect using a host string of the form http://thehost.com:1234, /// port is optional. Scheme must be http or ws @@ -119,6 +133,21 @@ class Ethereum { _validateUri(uri); } + /// Error processing helper + void processError(String method, Map res) { + if (res.isEmpty) { + if (printError) { + print('ERROR::$method - No status returned - Protocol failure}'); + } + } else { + final error = res[EthereumConstants.ethErrorKey]; + lastError.updateError(error['code'], error['message'], rpcClient.id); + if (printError) { + print('ERROR::$method - ${lastError.toString()}'); + } + } + } + void _validateUri(Uri puri) { // Must have a valid scheme which must be http, host and port if (puri.hasAuthority && (puri.host.isNotEmpty)) { @@ -131,44 +160,13 @@ class Ethereum { } var newUri = puri; if (!puri.hasPort) { - if (puri.scheme == rpcHttpScheme) { - newUri = puri.replace(port: defaultHttpPort); - } else { - newUri = puri.replace(port: defaultWsPort); - } + newUri = + puri.scheme == rpcHttpScheme + ? puri.replace(port: defaultHttpPort) + : puri.replace(port: defaultWsPort); } port = newUri.port; _uri = newUri; rpcClient.uri = _uri; } - - /// Print errors, default is off - bool printError = false; - - /// Error processing helper - void processError(String method, Map res) { - if (res.isEmpty) { - if (printError) { - print('ERROR::$method - No status returned - Protocol failure}'); - } - } else { - final error = res[EthereumConstants.ethErrorKey]; - lastError.updateError(error['code'], error['message'], rpcClient.id); - if (printError) { - print('ERROR::$method - ${lastError.toString()}'); - } - } - } - - /// Eth API - EthereumApiEth? _eth; - - /// The ETH API - EthereumApiEth? get eth => _eth; - - /// Admin API - EthereumApiAdmin? _admin; - - /// The Admin API - EthereumApiAdmin? get admin => _admin; } diff --git a/lib/src/ethereum_error.dart b/lib/src/ethereum_error.dart index bbdb72e..df29922 100644 --- a/lib/src/ethereum_error.dart +++ b/lib/src/ethereum_error.dart @@ -11,9 +11,6 @@ part of '../ethereum.dart'; /// Manages Ethereum client errors class EthereumError { - /// Constructor - EthereumError(); - /// No error static const String noError = 'No Error'; @@ -22,24 +19,27 @@ class EthereumError { int? _code = 0; - /// Error code - int? get code => _code; + int _id = noId; + + DateTime? _timestamp; String? _message = noError; /// Error message String? get message => _message; - int _id = noId; + /// Error code + int? get code => _code; /// Error transaction id int get id => _id; - DateTime? _timestamp; - /// Error timestamp DateTime? get timestamp => _timestamp; + /// Constructor + EthereumError(); + /// Update the error details void updateError(int? errorCode, String? errorMessage, int errorId) { _code = errorCode; diff --git a/lib/src/ethereum_rpc_client.dart b/lib/src/ethereum_rpc_client.dart index 9720e65..627eca2 100644 --- a/lib/src/ethereum_rpc_client.dart +++ b/lib/src/ethereum_rpc_client.dart @@ -11,12 +11,12 @@ part of '../ethereum.dart'; /// The RPC client class EthereumRpcClient { - /// Constructor - EthereumRpcClient(this._adapter); - /// Version static const String jsonRPpcVersion = '2.0'; + /// The Uri + late Uri uri; + /// The HTTP adapter final EthereumINetworkAdapter _adapter; @@ -25,8 +25,8 @@ class EthereumRpcClient { /// The transmission id int get id => _id; - /// The Uri - late Uri uri; + /// Constructor + EthereumRpcClient(this._adapter); /// The request method Future> request(String method, [dynamic parameters]) { @@ -43,10 +43,6 @@ class EthereumRpcClient { /// Reset the transmission id void resetTransmissionId([int? value]) { - if (value == null) { - _id = 0; - } else { - _id = value; - } + _id = value ?? 0; } } diff --git a/lib/src/ethereum_utilities.dart b/lib/src/ethereum_utilities.dart index 82204ca..2d5c92f 100644 --- a/lib/src/ethereum_utilities.dart +++ b/lib/src/ethereum_utilities.dart @@ -1,3 +1,5 @@ +// ignore_for_file: no-magic-number + /* * Package : Ethereum * Author : S. Hamblett diff --git a/lib/src/messages/ethereum_block.dart b/lib/src/messages/ethereum_block.dart index b333316..a01227a 100644 --- a/lib/src/messages/ethereum_block.dart +++ b/lib/src/messages/ethereum_block.dart @@ -11,117 +11,117 @@ part of '../../ethereum.dart'; /// An ethereum block descriptor message class EthereumBlock { - /// Constructor - EthereumBlock(); + int? _number; - /// From map - EthereumBlock.fromMap(Map? result) { - construct(result); - } + EthereumData? _hash; - int? _number; + EthereumData? _parentHash; + + EthereumData? _nonce; + + EthereumData? _sha3Uncles; + + EthereumData? _logsBloom; + + EthereumData? _transactionsRoot; + + EthereumData? _stateRoot; + + EthereumData? _receiptsRoot; + + EthereumData? _miner; + + int? _difficulty; + + int? _totalDifficulty; + + EthereumData? _extraData; + + int? _size; + + int? _gasLimit; + + int? _gasUsed; + + DateTime? _timestamp; + + List? _transactions; + + bool _transactionsAreHashes = false; + + List? _uncles; + + /// Uncles. A list of uncle hashes. + List? get uncles => _uncles; /// The block number. Null when its a pending block. int? get number => _number; - EthereumData? _hash; - /// Hash of the block. Null when its a pending block. EthereumData? get hash => _hash; - EthereumData? _parentHash; - /// Parent hash. Hash of the parent block. EthereumData? get parentHash => _parentHash; - EthereumData? _nonce; - /// Nonce. Hash of the generated proof-of-work. Null when its pending block. EthereumData? get nonce => _nonce; - EthereumData? _sha3Uncles; - /// Sha3 Uncles. SHA3 of the uncles data in the block. EthereumData? get sha3Uncles => _sha3Uncles; - EthereumData? _logsBloom; - /// Logs bloom. The bloom filter for the logs of the block. /// Null when its pending block. EthereumData? get logsBloom => _logsBloom; - EthereumData? _transactionsRoot; - /// Transactions root. The root of the transaction tree of the block. EthereumData? get transactionsRoot => _transactionsRoot; - EthereumData? _stateRoot; - /// State root. The root of the final state tree of the block. EthereumData? get stateRoot => _stateRoot; - EthereumData? _receiptsRoot; - /// Receipts root. The root of the receipts tree of the block. EthereumData? get receiptsRoot => _receiptsRoot; - EthereumData? _miner; - /// Miner. The address of the beneficiary to whom the /// mining rewards were given. EthereumData? get miner => _miner; - int? _difficulty; - /// Difficulty. Integer of the difficulty for this block. int? get difficulty => _difficulty; - int? _totalDifficulty; - /// Total difficulty. Integer of the total difficulty /// of the chain until this block. int? get totalDifficulty => _totalDifficulty; - EthereumData? _extraData; - /// Extra data. The 'extra data' field of this block. EthereumData? get extraData => _extraData; - int? _size; - /// Size. Integer the size of this block in bytes. int? get size => _size; - int? _gasLimit; - /// Gas limit. The maximum gas allowed in this block. int? get gasLimit => _gasLimit; - int? _gasUsed; - /// Gas used. The total used gas by all transactions in this block. int? get gasUsed => _gasUsed; - DateTime? _timestamp; - /// Timestamp. The unix timestamp for when the block was collated. DateTime? get timestamp => _timestamp; - List? _transactions; - /// Transactions. A list of transaction objects, /// or 32 Bytes transaction hashes depending on the last given parameter. List? get transactions => _transactions; - bool _transactionsAreHashes = false; - /// Indicates if the transactions are hashes or transaction objects bool get transactionsAreHashes => _transactionsAreHashes; - List? _uncles; + /// Constructor + EthereumBlock(); - /// Uncles. A list of uncle hashes. - List? get uncles => _uncles; + /// From map + EthereumBlock.fromMap(Map? result) { + construct(result); + } /// Construct from the supplied Map, only check for the keys we need. void construct(Map? data) { @@ -247,8 +247,7 @@ class EthereumBlock { @override String toString() { - final ret = - 'Ethereum Block :' + return 'Ethereum Block :' '\n' ' Number : $number' '\n' @@ -264,6 +263,5 @@ class EthereumBlock { '\n' ' Time : $timestamp' '\n'; - return ret; } } From 751a2965bcfce4c4c36da0e32640ea788106f370 Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Sat, 10 May 2025 11:24:23 +0100 Subject: [PATCH 5/6] Issue 23 - DCM fixes --- lib/src/messages/ethereum_filter.dart | 20 ++--- lib/src/messages/ethereum_log.dart | 78 +++++++++---------- lib/src/messages/ethereum_sync_status.dart | 28 +++---- lib/src/messages/ethereum_transaction.dart | 61 +++++++-------- .../ethereum_transaction_receipt.dart | 65 ++++++++-------- lib/src/messages/ethereum_work.dart | 35 ++++----- .../parameters/ethereum_default_block.dart | 30 +++---- 7 files changed, 154 insertions(+), 163 deletions(-) diff --git a/lib/src/messages/ethereum_filter.dart b/lib/src/messages/ethereum_filter.dart index ee32558..8261eca 100644 --- a/lib/src/messages/ethereum_filter.dart +++ b/lib/src/messages/ethereum_filter.dart @@ -16,24 +16,24 @@ part of '../../ethereum.dart'; /// For filters created with newFilter or getFilterChanges the /// class contains logs which are are Ethereum Log objects. class EthereumFilter { - /// Construction - EthereumFilter(); - - /// From map - EthereumFilter.fromMap(Map result) { - construct(result); - } - List? _hashes; + List? _logs; + /// Hashes, block or transaction List? get hashes => _hashes; - List? _logs; - /// Logs List? get logs => _logs; + /// Construction + EthereumFilter(); + + /// From map + EthereumFilter.fromMap(Map result) { + construct(result); + } + /// Ethereum log objects, returned by /// Construct from the supplied Map, only check for the keys we need. void construct(Map data) { diff --git a/lib/src/messages/ethereum_log.dart b/lib/src/messages/ethereum_log.dart index 252f6e2..b30bdc2 100644 --- a/lib/src/messages/ethereum_log.dart +++ b/lib/src/messages/ethereum_log.dart @@ -11,77 +11,77 @@ part of '../../ethereum.dart'; /// Ethereum log message class EthereumLog { - /// Construction - EthereumLog(); + bool? _removed; - /// From map - EthereumLog.fromMap(Map result) { - construct(result); - } + int? _logIndex; - /// From list - static List fromList(dynamic res) { - final logs = []; - for (final dynamic log in res) { - final buildLog = {EthereumConstants.ethResultKey: log}; - final entry = EthereumLog.fromMap(buildLog); - logs.add(entry); - } - return logs; - } + int? _transactionIndex; - bool? _removed; + EthereumData? _transactionHash; + + EthereumData? _blockHash; + + int? _blockNumber; + + EthereumAddress? _address; + + EthereumData? _data; + + List? _topics; + + /// Topics. List of 0 to 4 32 of indexed log arguments. (In solidity: + /// The first topic is the hash of the signature of the event + /// (e.g. Deposit(address,bytes32,uint256)), + /// except you declared the event with the anonymous specifier.) + List? get topics => _topics; /// Removed. True when the log was removed, due to a chain /// reorganization. false if its a valid log. bool? get removed => _removed; - int? _logIndex; - /// Log index. The log index position in the block. /// Null when the log is pending. int? get logIndex => _logIndex; - int? _transactionIndex; - /// Transaction index. The transactions index position the log was /// created from. Null when the log is pending. int? get transactionIndex => _transactionIndex; - EthereumData? _transactionHash; - /// Transaction hash. Hash of the transactions this log was created /// from. Null when the log is pending. EthereumData? get transactionHash => _transactionHash; - EthereumData? _blockHash; - /// Block hash. Hash of the block where this log was in. /// Null when the log is pending. EthereumData? get blockHash => _blockHash; - int? _blockNumber; - /// Block number. The block number of this log. Null when the log is pending. int? get blockNumber => _blockNumber; - EthereumAddress? _address; - /// Address. Address from which this log originated. EthereumAddress? get address => _address; - EthereumData? _data; - /// Data. Contains one or more 32 Bytes non-indexed arguments of the log. EthereumData? get data => _data; - List? _topics; + /// Construction + EthereumLog(); - /// Topics. List of 0 to 4 32 of indexed log arguments. (In solidity: - /// The first topic is the hash of the signature of the event - /// (e.g. Deposit(address,bytes32,uint256)), - /// except you declared the event with the anonymous specifier.) - List? get topics => _topics; + /// From map + EthereumLog.fromMap(Map result) { + construct(result); + } + + /// From list + static List fromList(dynamic res) { + final logs = []; + for (final dynamic log in res) { + final buildLog = {EthereumConstants.ethResultKey: log}; + final entry = EthereumLog.fromMap(buildLog); + logs.add(entry); + } + return logs; + } /// Construct from the supplied Map, only check for the keys we need. void construct(Map data) { @@ -138,8 +138,7 @@ class EthereumLog { @override String toString() { - final ret = - 'Ethereum Log :' + return 'Ethereum Log :' '\n' ' Removed : $removed' '\n' @@ -155,6 +154,5 @@ class EthereumLog { '\n' ' Address : $address' '\n'; - return ret; } } diff --git a/lib/src/messages/ethereum_sync_status.dart b/lib/src/messages/ethereum_sync_status.dart index 05ef071..d3f0c53 100644 --- a/lib/src/messages/ethereum_sync_status.dart +++ b/lib/src/messages/ethereum_sync_status.dart @@ -11,33 +11,33 @@ part of '../../ethereum.dart'; /// Sync status message class EthereumSyncStatus { - /// Constructor - EthereumSyncStatus(); + bool _syncing = false; - /// From map - EthereumSyncStatus.fromMap(Map result) { - construct(result); - } + int? _startingBlock; - bool _syncing = false; + int? _currentBlock; + + int? _highestBlock; + + /// Highest block, only valid if syncing + int? get highestBlock => _highestBlock; /// Syncing indicator, true if syncing bool get syncing => _syncing; - int? _startingBlock; - /// Starting block, only valid if syncing int? get startingBlock => _startingBlock; - int? _currentBlock; - /// Current block, only valid if syncing int? get currentBlock => _currentBlock; - int? _highestBlock; + /// Constructor + EthereumSyncStatus(); - /// Highest block, only valid if syncing - int? get highestBlock => _highestBlock; + /// From map + EthereumSyncStatus.fromMap(Map result) { + construct(result); + } /// Construct from the supplied Map, only check for the keys we need. void construct(Map data) { diff --git a/lib/src/messages/ethereum_transaction.dart b/lib/src/messages/ethereum_transaction.dart index a481783..19fa61b 100644 --- a/lib/src/messages/ethereum_transaction.dart +++ b/lib/src/messages/ethereum_transaction.dart @@ -11,71 +11,71 @@ part of '../../ethereum.dart'; /// An ethereum transaction message class EthereumTransaction { - /// Constructor - EthereumTransaction(); + EthereumData? _hash; - /// From map - EthereumTransaction.fromMap(Map? result) { - construct(result); - } + int? _nonce; - EthereumData? _hash; + EthereumData? _blockHash; + + int? _blockNumber; + + int? _transactionIndex; + + EthereumAddress? _from; + + EthereumAddress? _to; + + int? _value; + + int? _gasPrice; + + int? _gas; + + EthereumData? _input; + + /// Input. Data sent with the transaction. + EthereumData? get input => _input; /// Hash. hash of the transaction. EthereumData? get hash => _hash; - int? _nonce; - /// Nonce. The number of transactions made by the sender prior to this one. int? get nonce => _nonce; - EthereumData? _blockHash; - /// Block hash. Hash of the block where this transaction was in. /// Null when the transaction is pending. EthereumData? get blockHash => _blockHash; - int? _blockNumber; - /// Block number. Block number of this transaction. /// Null when the transaction is pending. int? get blockNumber => _blockNumber; - int? _transactionIndex; - /// Transaction index. The transactions index position in the block. /// Null when the transaction is pending. int? get transactionIndex => _transactionIndex; - EthereumAddress? _from; - /// From. Address of the sender. EthereumAddress? get from => _from; - EthereumAddress? _to; - /// To. Address of the receiver. Null when a contract creation transaction. EthereumAddress? get to => _to; - int? _value; - /// Value. Value transferred in Wei. int? get value => _value; - int? _gasPrice; - /// Gas price. Gas price provided by the sender in Wei. int? get gasPrice => _gasPrice; - int? _gas; - /// Gas. Gas provided by the sender. int? get gas => _gas; - EthereumData? _input; + /// Constructor + EthereumTransaction(); - /// Input. Data sent with the transaction. - EthereumData? get input => _input; + /// From map + EthereumTransaction.fromMap(Map? result) { + construct(result); + } /// Construct from the supplied Map, only check for the keys we need. void construct(Map? data) { @@ -141,8 +141,7 @@ class EthereumTransaction { @override String toString() { - final ret = - 'Ethereum Transaction :' + return 'Ethereum Transaction :' '\n' ' Hash : $hash' '\n' @@ -160,7 +159,5 @@ class EthereumTransaction { '\n' ' Gas : $gas' '\n'; - - return ret; } } diff --git a/lib/src/messages/ethereum_transaction_receipt.dart b/lib/src/messages/ethereum_transaction_receipt.dart index 8413362..618625e 100644 --- a/lib/src/messages/ethereum_transaction_receipt.dart +++ b/lib/src/messages/ethereum_transaction_receipt.dart @@ -11,73 +11,73 @@ part of '../../ethereum.dart'; /// An ethereum transaction receipt message class EthereumTransactionReceipt { - /// Constructor - EthereumTransactionReceipt(); + EthereumData? _transactionHash; - /// From map - EthereumTransactionReceipt.fromMap(Map? result) { - construct(result); - } + int? _transactionIndex; - EthereumData? _transactionHash; + EthereumData? _blockHash; + + int? _blockNumber; + + int? _cumulativeGasUsed; + + int? _gasUsed; + + EthereumAddress? _contractAddress; + + List? _logs; + + EthereumData? _logsBloom; + + EthereumData? _root; + + int? _status; + + /// Status. Either 1 (success) or 0 (failure) + /// Null if root is present + int? get status => _status; /// Transaction hash. Hash of the transaction. EthereumData? get transactionHash => _transactionHash; - int? _transactionIndex; - /// Transaction index. Ihe transactions index position in the block. int? get transactionIndex => _transactionIndex; - EthereumData? _blockHash; - /// Block hash. Hash of the block this transaction was in. EthereumData? get blockHash => _blockHash; - int? _blockNumber; - /// Block number. Block number of this transaction. int? get blockNumber => _blockNumber; - int? _cumulativeGasUsed; - /// Cumulative gas used. The total amount of gas used when this /// transaction was executed in the block. int? get cumulativeGasUsed => _cumulativeGasUsed; - int? _gasUsed; - /// Gas used. The amount of gas used by this transaction. int? get gasUsed => _gasUsed; - EthereumAddress? _contractAddress; - /// Contract address. The contract address created, if the transaction was /// a contract creation, otherwise null. EthereumAddress? get contractAddress => _contractAddress; - List? _logs; - /// Logs. List of log objects, which this transaction generated. List? get logs => _logs; - EthereumData? _logsBloom; - /// Logs bloom. Bloom filter for light clients to quickly /// retrieve related logs. EthereumData? get logsBloom => _logsBloom; - EthereumData? _root; - - /// Root. Post-transaction stateroot (pre Byzantium) + /// Root. Post-transaction state root (pre Byzantium) /// Null if status is present. EthereumData? get root => _root; - int? _status; + /// Constructor + EthereumTransactionReceipt(); - /// Status. Either 1 (success) or 0 (failure) - /// Null if root is present - int? get status => _status; + /// From map + EthereumTransactionReceipt.fromMap(Map? result) { + construct(result); + } /// Construct from the supplied Map, only check for the keys we need. void construct(Map? data) { @@ -152,8 +152,7 @@ class EthereumTransactionReceipt { @override String toString() { - final ret = - 'Ethereum Transaction Receipt:' + return 'Ethereum Transaction Receipt:' '\n' ' Transaction Hash : $transactionHash' '\n' @@ -167,7 +166,5 @@ class EthereumTransactionReceipt { '\n' ' Gas used : $gasUsed' '\n'; - - return ret; } } diff --git a/lib/src/messages/ethereum_work.dart b/lib/src/messages/ethereum_work.dart index ced6a0e..b552143 100644 --- a/lib/src/messages/ethereum_work.dart +++ b/lib/src/messages/ethereum_work.dart @@ -12,46 +12,47 @@ part of '../../ethereum.dart'; /// An ethereum work message. /// All elements of the work message must be present. class EthereumWork { - /// Construction - EthereumWork(); - - /// From list - EthereumWork.fromList(List? result) { - construct(result); - } + static const workMessageLength = 3; EthereumData? _powHash; + EthereumData? _seedHash; + + EthereumData? _boundaryCondition; + + /// The boundary condition ('target'), 2^256 / difficulty. + EthereumData? get boundaryCondition => _boundaryCondition; + /// Current block header pow-hash EthereumData? get powHash => _powHash; - EthereumData? _seedHash; - /// Seed hash used for the DAG. EthereumData? get seedHash => _seedHash; - EthereumData? _boundaryCondition; + /// Construction + EthereumWork(); - /// The boundary condition ('target'), 2^256 / difficulty. - EthereumData? get boundaryCondition => _boundaryCondition; + /// From list + EthereumWork.fromList(List? result) { + construct(result); + } /// Construct from the supplied list. void construct(List? data) { if (data == null) { return; } - if (data.length != 3) { + if (data.length != workMessageLength) { return; } - _powHash = EthereumData.fromString(data[0]); + _powHash = EthereumData.fromString(data.first); _seedHash = EthereumData.fromString(data[1]); _boundaryCondition = EthereumData.fromString(data[2]); } @override String toString() { - final ret = - 'Ethereum Work :' + return 'Ethereum Work :' '\n' ' Pow Hash : $powHash' '\n' @@ -59,7 +60,5 @@ class EthereumWork { '\n' ' Boundary Condition : $boundaryCondition' '\n'; - - return ret; } } diff --git a/lib/src/parameters/ethereum_default_block.dart b/lib/src/parameters/ethereum_default_block.dart index 090800a..a82074d 100644 --- a/lib/src/parameters/ethereum_default_block.dart +++ b/lib/src/parameters/ethereum_default_block.dart @@ -24,11 +24,26 @@ class EthereumDefaultBlock { /// Pending static const String ethPending = 'pending'; + bool _pending = false; + bool _latest = true; + bool _earliest = false; + + int? _number; + /// Latest indicator. Default bool get latest => _latest; + /// Earliest indicator + bool get earliest => _earliest; + + /// Pending indicator + bool get pending => _pending; + + /// Block number + int? get number => _number; + set latest(bool state) { _latest = true; _earliest = false; @@ -36,11 +51,6 @@ class EthereumDefaultBlock { _number = null; } - bool _earliest = false; - - /// Earliest indicator - bool get earliest => _earliest; - set earliest(bool state) { _earliest = true; _latest = false; @@ -48,11 +58,6 @@ class EthereumDefaultBlock { _number = null; } - bool _pending = false; - - /// Pending indicator - bool get pending => _pending; - set pending(bool state) { _pending = true; _earliest = false; @@ -60,11 +65,6 @@ class EthereumDefaultBlock { _number = null; } - int? _number; - - /// Block number - int? get number => _number; - set number(int? value) { _number = value; _earliest = false; From 8ebd02d975e774fc678d42c849275fd6702b2a6b Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Sun, 11 May 2025 09:46:12 +0100 Subject: [PATCH 6/6] Issue 23 - change log --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98d4001..f61cfc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,25 @@ # 6.1.0 Issue 21 +- [Issue 21](https://github.com/shamblett/ethereum/issues21) # 6.0.1 Issue 19 +- [Issue 19](https://github.com/shamblett/ethereum/issues/19) # 6.0.0 Issue 18 - Dart 3 +- [Issue 18](https://github.com/shamblett/ethereum/issues/18) # 5.0.2 Issue 17 +- [Issue 17](https://github.com/shamblett/ethereum/issues/14) # 5.0.1 Issue 13 +- [Issue 13](https://github.com/shamblett/ethereum/issues/13) # 5.0.0 -Issue 9(NNBD) +- [Issue 9(NNBD)](https://github.com/shamblett/ethereum/issues/9) # 4.0.3 Linter + pana updates @@ -27,15 +32,19 @@ Update for use with Dart 2.1.1 # 4.0.0 Issue 5, new datatypes +- [Issue 5](https://github.com/shamblett/ethereum/issues/5) # 3.1.0 Issue 4 fixes, linter updates +- [Issue 4](https://github.com/shamblett/ethereum/issues/4) # 3.0.0 Issue 4, Interface updates - admin +- [Issue 4](https://github.com/shamblett/ethereum/issues/4) #2 .0.1 Issue 3, updates for Dart 2 +- [Issue 3](https://github.com/shamblett/ethereum/issues/3) # 1.1.0 Minor API(default block parameter) and coverage updates