Skip to content

Commit

Permalink
dart update and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Aug 22, 2022
1 parent b903669 commit 6d85759
Show file tree
Hide file tree
Showing 68 changed files with 649 additions and 525 deletions.
37 changes: 20 additions & 17 deletions lib/explorer.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
export 'src/network/explorer/explorer_client.dart' show ExplorerClient, ExplorerMode;
export 'src/network/explorer/explorer_client.dart' show
ExplorerClient,
ExplorerMode;

export 'src/network/explorer/explorer_api.dart' show
ExplorerException,
Home,
Network,
NetworkStats,
NodePool,
Status,
SupplyInfo,
Tapi,
TapiInfo,
Blockchain,
AddressDetails,
InputUtxo,
AddressValueTransfers,
MintInfo,
TallyTxn,
ValueTransferInfo;
ExplorerException,
Home,
Network,
NetworkStats,
NodePool,
Status,
SupplyInfo,
Tapi,
TapiInfo,
Blockchain,
AddressDetails,
InputUtxo,
AddressValueTransfers,
MintInfo,
TallyTxn,
ValueTransferInfo;

9 changes: 7 additions & 2 deletions lib/node.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export 'src/network/node/node_api.dart' show NodeStats, SyncStatus, UtxoInfo;
export 'src/network/node/node_client.dart' show NodeClient;
export 'src/network/node/node_api.dart' show
NodeStats,
SyncStatus,
UtxoInfo;

export 'src/network/node/node_client.dart' show
NodeClient;
5 changes: 4 additions & 1 deletion lib/protobuf.dart
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export 'src/utils/protobuf/wire_type.dart' show pbField, VARINT, LENGTH_DELIMITED;
export 'src/utils/protobuf/wire_type.dart' show
pbField,
VARINT,
LENGTH_DELIMITED;
44 changes: 24 additions & 20 deletions lib/radon.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
export 'src/rad/types/types.dart' show
RadArray,
RadBoolean,
RadBytes,
RadFloat,
RadInteger,
RadMap,
RadString,
RadTypes,
REDUCERS,
FILTERS;

export 'src/rad/types/array.dart' show RadArray;
export 'src/rad/types/boolean.dart' show RadBoolean;
export 'src/rad/types/bytes.dart' show RadBytes;
export 'src/rad/types/float.dart' show RadFloat;
export 'src/rad/types/integer.dart' show RadInteger;
export 'src/rad/types/map.dart' show RadMap;
export 'src/rad/types/string.dart' show RadString;
export 'src/rad/types/types.dart' show RadTypes;
export 'src/rad/vm/virtual_machine.dart' show
RetrieveReport,
RadonWebClient,
Stats,
Stage;

export 'src/rad/vm/rad_result.dart' ;
export 'src/rad/vm/retrieve_report.dart' show RetrieveReport;
export 'src/rad/vm/stage.dart' show Stage;
export 'src/rad/vm/statistics.dart' show Stats;
export 'src/rad/vm/web_client.dart' show RadonWebClient;

export 'src/rad/script.dart' show
export 'src/rad/radon.dart' show
RadError,
OP,
Filter,
Reducer,
RadonArray,
RadonBoolean,
RadonBytes,
Expand All @@ -23,8 +29,6 @@ export 'src/rad/script.dart' show
RadonMap,
RadonString;

export 'src/rad/exceptions.dart' show RadError;
export 'src/rad/filters.dart' show Filter;
export 'src/rad/op_codes.dart' show OP;
export 'src/rad/reducers.dart' show Reducer;
export 'src/rad/util.dart' show cborToRad, radToCbor;
export 'src/rad/util.dart' show
cborToRad,
radToCbor;
6 changes: 4 additions & 2 deletions lib/src/data_structures/utxo_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class UtxoPool {
});

List<Utxo> selectedUtxos = [];
print('selecting Utxos to cover ${nanoWitToWit(amountNanoWit)}');

if (amountNanoWit > utxoValue) {
print('Insufficient funds.');
return [];
Expand All @@ -100,7 +100,6 @@ class UtxoPool {
selectedUtxos.add(utxo);
amountNanoWit -= utxo.value;
}

return selectedUtxos;
}

Expand All @@ -126,10 +125,12 @@ class UtxoPool {
});
List<Utxo> selectedUtxos = [];
print('selecting Utxos to cover ${nanoWitToWit(outputValue)}');

if (outputValue > utxoValue) {
print('Insufficient funds.');
return [];
}

while (outputValue > 0) {
// since the list is sorted - take the first item
Utxo utxo = utxos.first;
Expand All @@ -140,4 +141,5 @@ class UtxoPool {

return selectedUtxos;
}

}
5 changes: 2 additions & 3 deletions lib/src/network/node/node_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ChainBeacon {
"hashPrevBlock": hashPrevBlock,
};
}

class TransactionResponse {
TransactionResponse({
required this.blockHash,
Expand Down Expand Up @@ -88,6 +89,7 @@ class TransactionResponse {
"weight": weight,
};
}

class UtxoInfo {
UtxoInfo({
required this.collateralMin,
Expand Down Expand Up @@ -157,9 +159,6 @@ class NodeStats {
};
}




class SyncStatus {
SyncStatus({
required this.chainBeacon,
Expand Down
13 changes: 7 additions & 6 deletions lib/src/network/node/node_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class NodeClient {
late int _id;
List<String> messages = [];
bool keepAlive;

String _secureResponse = '';
Socket? _socket;
NodeClient(
{required this.address, required this.port, this.keepAlive = false});


Future<SyncStatus> syncStatus() async {
try{
var response = await sendMessage(formatRequest(method: 'syncStatus'))
Expand Down Expand Up @@ -88,6 +90,7 @@ class NodeClient {
var response = await sendMessage(
formatRequest(method: 'getBlock', params: [blockHash]))
.then((Map<String, dynamic> data) {

if (data.containsKey('result')) {
return data['result'];
} else if (data.containsKey('error')) {
Expand Down Expand Up @@ -243,7 +246,6 @@ class NodeClient {
if (data.containsKey('result')) {
return data['result'];
} else if (data.containsKey('error')) {
print(json.encode(data));
throw NodeException.fromJson(data['error']);
}
});
Expand All @@ -260,7 +262,6 @@ class NodeClient {
if (data.containsKey('result')) {
return data['result'];
} else if (data.containsKey('error')) {
print(json.encode(data));
throw NodeException.fromJson(data['error']);
}
});
Expand Down Expand Up @@ -318,11 +319,10 @@ class NodeClient {

Future<Map<String, dynamic>> _handle(String _request) async {

String _secureResponse = '';
Socket? _socket;

try {
// =============================================================
await Socket.connect(address, port).then((Socket sock) {
_socket = await Socket.connect(address, port).then((Socket sock) {
_socket = sock;
}).then((_) {
// SENT TO NODE
Expand All @@ -332,6 +332,7 @@ class NodeClient {
// GET FROM NODE
_secureResponse = new String.fromCharCodes(data).trim();
_socket!.close();
return _socket;
});
} on SocketException catch(e){
throw NodeException(code: e.osError!.errorCode, message: e.message);
Expand Down
1 change: 1 addition & 0 deletions lib/src/rad/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
part of 'radon.dart';

class RadError implements Exception{
String error;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/rad/filters.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
part of 'radon.dart';

class Filter {
static greaterThan(num value, List<num> values){return values.where((element) => (value > element)).toList();}
static lessThan(num value, List<num> values){return values.where((element) => (value < element)).toList();}
Expand Down
12 changes: 11 additions & 1 deletion lib/src/rad/op_codes.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
part of 'radon.dart';

class ANY {
static final FAIL = 0xFF;
static final IDENTITY = 0x00;
}

class ARRAY{
static final COUNT = 0x10;
static final FILTER = 0x11;
Expand All @@ -16,14 +19,17 @@ class ARRAY{
static final REDUCE = 0x1B;
static final SORT = 0x1D;
}

class BOOLEAN{
static final AS_STRING = 0x20;
static final NEGATE = 0x22;
}

class BYTES{
static final AS_STRING = 0x30;
static final HASH = 0x31;
}

class FLOAT{
static final ABSOLUTE = 0x50;
static final AS_STRING = 0x51;
Expand All @@ -38,6 +44,7 @@ class FLOAT{
static final ROUND = 0x5B;
static final TRUNCATE = 0x5d;
}

class INTEGER{
static final ABSOLUTE = 0x40;
static final AS_FLOAT = 0x41;
Expand All @@ -49,6 +56,7 @@ class INTEGER{
static final NEGATE = 0x48;
static final POWER = 0x49;
}

class MAP{
static final GET_ARRAY = 0x61;
static final GET_BOOLEAN = 0x62;
Expand All @@ -60,6 +68,7 @@ class MAP{
static final KEYS = 0x68;
static final VALUES_AS_ARRAY = 0x69;
}

class STRING{
static final AS_BOOLEAN = 0x70;
static final AS_FLOAT = 0x72;
Expand All @@ -68,10 +77,11 @@ class STRING{
static final MATCH = 0x75;
static final PARSE_JSON_ARRAY = 0x76;
static final PARSE_JSON_MAP = 0x77;
static final PARSE_XML = 0x78;
static final TO_LOWER_CASE = 0x79;
static final TO_UPPER_CASE = 0x7A;

}

class OP {
static final ANY_FAIL = ANY.FAIL;
static final ANY_IDENTITY = ANY.IDENTITY;
Expand Down
9 changes: 9 additions & 0 deletions lib/src/rad/radon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'types/types.dart';
import 'types/types.dart' show REDUCERS;
import 'vm/virtual_machine.dart' show Stats;

part 'exceptions.dart';
part 'filters.dart';
part 'op_codes.dart';
part 'reducers.dart';
part 'script.dart';
4 changes: 1 addition & 3 deletions lib/src/rad/reducers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import 'types/types.dart' show REDUCERS;
import 'vm/statistics.dart' show Stats;
part of 'radon.dart';

class Reducer{

Expand Down
5 changes: 2 additions & 3 deletions lib/src/rad/script.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

import 'op_codes.dart' show OP;
part of 'radon.dart';

class Source {

}


List<dynamic> concat(List<dynamic> script, dynamic op){
List<dynamic> _script = [];
_script.addAll(script);
Expand Down Expand Up @@ -98,6 +96,7 @@ class RadonString extends RadType{
RadonBoolean match(String key) {return RadonBoolean(concat(script, [OP.STRING_MATCH, key]));}
RadonArray parseJSONArray() {return RadonArray(concat(script, OP.STRING_PARSE_JSON_ARRAY));}
RadonMap parseJSONMap() {return RadonMap(concat([], OP.STRING_PARSE_JSON_MAP));}

RadonString toLowerCase() {return RadonString(concat(script, OP.STRING_TO_LOWER_CASE));}
RadonString toUpperCase() {return RadonString(concat(script, OP.STRING_TO_UPPER_CASE));}
}
Expand Down
12 changes: 1 addition & 11 deletions lib/src/rad/types/array.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import 'dart:collection' show ListBase;

import 'boolean.dart' show RadBoolean;
import 'bytes.dart' show RadBytes;
import 'integer.dart' show RadInteger;
import 'map.dart' show RadMap;
import 'string.dart' show RadString;
import 'types.dart' show RadTypes, TYPES, typesList, typesMap;

import '../op_codes.dart';
import '../exceptions.dart';
part of 'types.dart';

class RadArray<E> extends ListBase<E>{
final List<E> _value;
Expand Down
5 changes: 1 addition & 4 deletions lib/src/rad/types/boolean.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'string.dart' show RadString;
import 'types.dart' show TYPES;

import '../op_codes.dart' show OP;
part of 'types.dart';

class RadBoolean{
bool _value;
Expand Down
9 changes: 1 addition & 8 deletions lib/src/rad/types/bytes.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import 'dart:typed_data' show Uint8List;

import 'string.dart' show RadString;
import 'types.dart' show TYPES;
import '../op_codes.dart' show OP;

import 'package:witnet/crypto.dart' show sha256;
import 'package:witnet/utils.dart' show bytesToHex;
part of 'types.dart';

class RadBytes{
Uint8List _value;
Expand Down
8 changes: 1 addition & 7 deletions lib/src/rad/types/float.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
part of 'types.dart';

import 'dart:math' show pow;

import 'boolean.dart' show RadBoolean;
import 'integer.dart' show RadInteger;
import 'string.dart' show RadString;
import 'types.dart' show TYPES;
import '../op_codes.dart' show OP;

class RadFloat{
double _value;
Expand Down
Loading

0 comments on commit 6d85759

Please sign in to comment.