From 782d167e1602e824679e9a5a7500079e0187def4 Mon Sep 17 00:00:00 2001 From: fzxu Date: Sat, 27 Jun 2020 13:14:02 -0700 Subject: [PATCH] add http timeout --- CHANGELOG.md | 4 ++++ example/eosdart_example.dart | 2 +- lib/src/client.dart | 11 +++++++++-- pubspec.yaml | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23af2ef..0d755d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.5 + +- Support adding timeout on http request + ## 0.4.4 - Support abi float32 and float64 diff --git a/example/eosdart_example.dart b/example/eosdart_example.dart index 3ae052f..cb7e80d 100644 --- a/example/eosdart_example.dart +++ b/example/eosdart_example.dart @@ -2,7 +2,7 @@ import 'package:eosdart/eosdart.dart'; main() { EOSClient client = EOSClient('https://eos.greymass.com', 'v1'); -// EOSClient client = EOSClient('http://127.0.0.1:8888', 'v1'); +// EOSClient client = EOSClient('http://127.0.0.1:8888', 'v1', httpTimeout: 15); // Get EOS Node Info client.getInfo().then((NodeInfo nodeInfo) { diff --git a/lib/src/client.dart b/lib/src/client.dart index db92a23..1e88577 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -23,6 +23,7 @@ class EOSClient { final String _nodeURL; final String _version; int expirationInSec; + int httpTimeout; Map keys = Map(); /// Converts abi files between binary and structured form (`abi.abi.json`) */ @@ -30,8 +31,13 @@ class EOSClient { Map transactionTypes; /// Construct the EOS client from eos node URL - EOSClient(this._nodeURL, this._version, - {this.expirationInSec = 180, List privateKeys = const []}) { + EOSClient( + this._nodeURL, + this._version, { + this.expirationInSec = 180, + List privateKeys = const [], + this.httpTimeout = 10, + }) { _mapKeys(privateKeys); abiTypes = ser.getTypesFromAbi( @@ -56,6 +62,7 @@ class EOSClient { http .post('${this._nodeURL}/${this._version}${path}', body: json.encode(body)) + .timeout(Duration(seconds: this.httpTimeout)) .then((http.Response response) { if (response.statusCode >= 300) { completer.completeError(response.body); diff --git a/pubspec.yaml b/pubspec.yaml index 1a676bd..f9d0bcc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: eosdart description: EOSIO-based blockchain RPC API client in Dart language -version: 0.4.4 +version: 0.4.5 homepage: https://github.com/primes-network/eosdart author: primes-network