Skip to content

Commit

Permalink
Fix error after merge
Browse files Browse the repository at this point in the history
replace missing constructor that was deleted during a merge
  • Loading branch information
parodyBit committed Oct 6, 2022
1 parent 4f3817b commit cfd90f5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions lib/src/network/node/node_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class NodeClient {
late Socket _socket;
Uint8List _buffer = Uint8List.fromList([]);

NodeClient({
required this.address,
required this.port,
this.keepAlive = false,
});

/// Get node status
Expand Down Expand Up @@ -60,7 +65,7 @@ class NodeClient {
Future<dynamic> inventory(Map<String, dynamic> inventoryItem) async {
try {
var response = await sendMessage(
formatRequest(method: 'inventory', params: inventoryItem))
formatRequest(method: 'inventory', params: inventoryItem))
.then((Map<String, dynamic> data) {
if (data.containsKey('error')) {
throw NodeException.fromJson(data['error']);
Expand All @@ -78,8 +83,8 @@ class NodeClient {
{required int epoch, required int limit}) async {
try {
var response = await sendMessage(formatRequest(
method: 'getBlockChain',
params: {'epoch': epoch, 'limit': limit}))
method: 'getBlockChain',
params: {'epoch': epoch, 'limit': limit}))
.then((Map<String, dynamic> data) {
if (data.containsKey('error')) {
throw NodeException.fromJson(data['error']);
Expand All @@ -99,7 +104,7 @@ class NodeClient {
Future<Block> getBlock({required String blockHash}) async {
try {
var response = await sendMessage(
formatRequest(method: 'getBlock', params: [blockHash]))
formatRequest(method: 'getBlock', params: [blockHash]))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
Expand Down Expand Up @@ -157,7 +162,7 @@ class NodeClient {
Future<Map<String, dynamic>> getBalance({required String address}) async {
try {
var response = await sendMessage(
formatRequest(method: 'getBalance', params: [address]))
formatRequest(method: 'getBalance', params: [address]))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
Expand All @@ -176,7 +181,7 @@ class NodeClient {
Future<Map<String, dynamic>> getReputation({required String address}) async {
try {
var response = await sendMessage(
formatRequest(method: 'getReputation', params: [address]))
formatRequest(method: 'getReputation', params: [address]))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
Expand All @@ -194,8 +199,8 @@ class NodeClient {
Future<Map<String, dynamic>> getReputationAll() async {
try {
var response =
await sendMessage(formatRequest(method: 'getReputationAll'))
.then((Map<String, dynamic> data) {
await sendMessage(formatRequest(method: 'getReputationAll'))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
} else if (data.containsKey('error')) {
Expand Down Expand Up @@ -266,8 +271,8 @@ class NodeClient {
Future<Map<String, dynamic>> getConsensusConstants() async {
try {
var response =
await sendMessage(formatRequest(method: 'getConsensusConstants'))
.then((Map<String, dynamic> data) {
await sendMessage(formatRequest(method: 'getConsensusConstants'))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
} else if (data.containsKey('error')) {
Expand Down Expand Up @@ -305,7 +310,7 @@ class NodeClient {
Future<UtxoInfo> getUtxoInfo({required String address}) async {
try {
var response = await sendMessage(
formatRequest(method: 'getUtxoInfo', params: [address]))
formatRequest(method: 'getUtxoInfo', params: [address]))
.then((Map<String, dynamic> data) {
if (data.containsKey('result')) {
return data['result'];
Expand Down Expand Up @@ -361,8 +366,7 @@ class NodeClient {
/// Handle the Socket connection for the Node
Future<Map<String, dynamic>> _handle(String _request) async {
Completer<Map<String, dynamic>> _completer =

new Completer<Map<String, dynamic>>();
new Completer<Map<String, dynamic>>();

String _secureResponse = '';

Expand All @@ -371,15 +375,14 @@ class NodeClient {
// =============================================================
_socket = await Socket.connect(address, port);
_socket.listen(
(Uint8List data) {
(Uint8List data) {
// add the current chunk to the end of the buffer
_buffer = concatBytes([_buffer, data]);
// try to decode the buffer
try {
// this will throw an error if the _buffer is not complete
Map<String, dynamic> response =
json.decode(new String.fromCharCodes(_buffer).trim());

json.decode(new String.fromCharCodes(_buffer).trim());

// clear the buffer
_buffer = Uint8List.fromList([]);
Expand All @@ -397,7 +400,6 @@ class NodeClient {
_socket.add(utf8.encode(_request));
}
} on SocketException catch (e) {

throw NodeException(code: e.osError!.errorCode, message: e.message);
} catch (e) {
throw NodeException(code: -1, message: e.toString());
Expand Down

0 comments on commit cfd90f5

Please sign in to comment.