diff --git a/lib/src/client.dart b/lib/src/client.dart index 1e88577..6c50734 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -22,13 +22,13 @@ import 'serialize.dart' as ser; class EOSClient { final String _nodeURL; final String _version; - int expirationInSec; - int httpTimeout; + late int expirationInSec; + late int httpTimeout; Map keys = Map(); /// Converts abi files between binary and structured form (`abi.abi.json`) */ - Map abiTypes; - Map transactionTypes; + late Map abiTypes; + late Map transactionTypes; /// Construct the EOS client from eos node URL EOSClient( @@ -60,7 +60,7 @@ class EOSClient { Future _post(String path, Object body) async { Completer completer = Completer(); http - .post('${this._nodeURL}/${this._version}${path}', + .post(Uri.parse('${this._nodeURL}/${this._version}${path}'), body: json.encode(body)) .timeout(Duration(seconds: this.httpTimeout)) .then((http.Response response) { @@ -115,7 +115,7 @@ class EOSClient { } /// Get table row (eosio get table ...) - Future> getTableRow( + Future?> getTableRow( String code, String scope, String table, { @@ -194,7 +194,7 @@ class EOSClient { /// Get EOS account info form the given account name Future> getCurrencyBalance(String code, String account, - [String symbol]) async { + [String? symbol]) async { return this._post('/chain/get_currency_balance', {'code': code, 'account': account, 'symbol': symbol}).then((balance) { return (balance as List).map((e) => new Holding.fromJson(e)).toList(); @@ -221,7 +221,7 @@ class EOSClient { } /// Get EOS account actions - Future getActions(String accountName, {int pos, int offset}) async { + Future getActions(String accountName, {int pos = -1, int offset = -1}) async { return this._post('/history/get_actions', { 'account_name': accountName, 'pot': pos, @@ -232,7 +232,7 @@ class EOSClient { } /// Get EOS transaction - Future getTransaction(String id, {int blockNumHint}) async { + Future getTransaction(String id, {int? blockNumHint}) async { return this._post('/history/get_transaction', {'id': id, 'block_num_hint': blockNumHint}).then((transaction) { return TransactionBlock.fromJson(transaction); @@ -255,11 +255,11 @@ class EOSClient { int expireSecond = 180}) async { NodeInfo info = await this.getInfo(); Block refBlock = - await getBlock((info.headBlockNum - blocksBehind).toString()); + await getBlock((info.headBlockNum! - blocksBehind).toString()); Transaction trx = await _fullFill(transaction, refBlock); PushTransactionArgs pushTransactionArgs = await _pushTransactionArgs( - info.chainId, transactionTypes['transaction'], trx, sign); + info.chainId!, transactionTypes['transaction']!, trx, sign); if (broadcast) { return this._post('/chain/push_transaction', { @@ -279,9 +279,9 @@ class EOSClient { Future _getContract(String accountName, {bool reload = false}) async { var abi = await getRawAbi(accountName); - var types = ser.getTypesFromAbi(ser.createInitialTypes(), abi.abi); + var types = ser.getTypesFromAbi(ser.createInitialTypes(), abi.abi!); var actions = new Map(); - for (var act in abi.abi.actions) { + for (var act in abi.abi!.actions!) { actions[act.name] = ser.getType(types, act.type); } var result = Contract(types, actions); @@ -291,7 +291,7 @@ class EOSClient { /// Fill the transaction withe reference block data Future _fullFill(Transaction transaction, Block refBlock) async { transaction.expiration = - refBlock.timestamp.add(Duration(seconds: expirationInSec)); + refBlock.timestamp!.add(Duration(seconds: expirationInSec)); transaction.refBlockNum = refBlock.blockNum & 0xffff; transaction.refBlockPrefix = refBlock.refBlockPrefix; @@ -300,13 +300,13 @@ class EOSClient { /// serialize actions in a transaction Future _serializeActions(Transaction transaction) async { - for (Action action in transaction.actions) { - String account = action.account; + for (Action action in transaction.actions!) { + String account = action.account!; Contract contract = await _getContract(account); action.data = - _serializeActionData(contract, account, action.name, action.data); + _serializeActionData(contract, account, action.name!, action.data!); } return transaction; } @@ -319,7 +319,7 @@ class EOSClient { throw "Unknown action $name in contract $account"; } var buffer = new ser.SerialBuffer(Uint8List(0)); - action.serialize(action, buffer, data); + action.serialize?.call(action, buffer, data); return ser.arrayToHex(buffer.asUint8List()); } @@ -350,8 +350,8 @@ class EOSClient { ..addAll(serializedTrx) ..addAll(Uint8List(32))); - for (String publicKey in requiredKeys.requiredKeys) { - ecc.EOSPrivateKey pKey = this.keys[publicKey]; + for (String publicKey in requiredKeys.requiredKeys!) { + ecc.EOSPrivateKey pKey = this.keys[publicKey]!; signatures.add(pKey.sign(signBuf).toString()); } } diff --git a/lib/src/eosdart_base.dart b/lib/src/eosdart_base.dart index 71a201f..40c514d 100644 --- a/lib/src/eosdart_base.dart +++ b/lib/src/eosdart_base.dart @@ -7,9 +7,13 @@ class Field { String typeName; /// Type of the field */ - Type type; + Type? type; - Field({this.name, this.type, this.typeName}); + Field({ + required this.name, + this.type, + required this.typeName, + }); } class Type { @@ -17,35 +21,36 @@ class Type { String aliasOfName; - Type arrayOf; + Type? arrayOf; - Type optionalOf; + Type? optionalOf; - Type extensionOf; + Type? extensionOf; String baseName; - Type base; + Type? base; List fields; - Function serialize; + Function? serialize; // void Function(Type self,SerialBuffer buffer, Object data, {SerializerState state,bool allowExtensions}) serialize; - Function deserialize; - - Type( - {this.name, - this.aliasOfName, - this.arrayOf, - this.optionalOf, - this.extensionOf, - this.baseName, - this.base, - this.fields, - this.serialize, - this.deserialize}); + Function? deserialize; + + Type({ + required this.name, + required this.aliasOfName, + this.arrayOf, + this.optionalOf, + this.extensionOf, + required this.baseName, + this.base, + required this.fields, + this.serialize, + this.deserialize, + }); } class Contract { @@ -64,5 +69,8 @@ class Symbol { /// Number of digits after the decimal point */ final int precision; - Symbol({this.name, this.precision}); + Symbol({ + required this.name, + required this.precision, + }); } diff --git a/lib/src/models/abi.dart b/lib/src/models/abi.dart index a325f23..b119fa9 100644 --- a/lib/src/models/abi.dart +++ b/lib/src/models/abi.dart @@ -14,44 +14,42 @@ part 'abi.g.dart'; @JsonSerializable() class AbiResp with ConversionHelper { @JsonKey(name: 'account_name') - String accountName; + String? accountName; @JsonKey(name: 'code_hash') - String codeHash; + String? codeHash; @JsonKey(name: 'abi_hash') - String abiHash; + String? abiHash; @JsonKey(name: 'wasm') - String wasm; + String? wasm; @JsonKey(name: 'abi', fromJson: _decodeAbi) - Abi abi; + Abi? abi; AbiResp(); - factory AbiResp.fromJson(Map json) => - _$AbiRespFromJson(json); + factory AbiResp.fromJson(Map json) => _$AbiRespFromJson(json); Map toJson() => _$AbiRespToJson(this); - static Abi _decodeAbi(Object abi) { + static Abi? _decodeAbi(dynamic abi) { if (abi is String) { return _base64ToAbi(abi); } return Abi.fromJson(abi); } - static Abi _base64ToAbi(String base64String) { + static Abi? _base64ToAbi(String base64String) { Uint8List abiBuffer = base64ToBinary(base64String); return _rawAbiToJson(abiBuffer); } /// Decodes an abi as Uint8List into json. */ - static Abi _rawAbiToJson(Uint8List rawAbi) { - Map abiTypes = ser.getTypesFromAbi( - ser.createInitialTypes(), Abi.fromJson(json.decode(abiJson))); + static Abi? _rawAbiToJson(Uint8List rawAbi) { + Map abiTypes = ser.getTypesFromAbi(ser.createInitialTypes(), Abi.fromJson(json.decode(abiJson))); try { var buffer = ser.SerialBuffer(rawAbi); var str = buffer.getString(); @@ -60,10 +58,10 @@ class AbiResp with ConversionHelper { } buffer.restartRead(); var t = abiTypes['abi_def']; - var b = t.deserialize(t, buffer); + var b = t?.deserialize?.call(t, buffer); return Abi.fromJson(json.decode(json.encode(b))); } catch (e) { - print(e.message); + print(e.toString()); return null; } } @@ -82,8 +80,7 @@ class AbiType { AbiType(this.new_type_name, this.type); - factory AbiType.fromJson(Map json) => - _$AbiTypeFromJson(json); + factory AbiType.fromJson(Map json) => _$AbiTypeFromJson(json); Map toJson() => _$AbiTypeToJson(this); @@ -101,8 +98,7 @@ class AbiStructField { AbiStructField(this.name, this.type); - factory AbiStructField.fromJson(Map json) => - _$AbiStructFieldFromJson(json); + factory AbiStructField.fromJson(Map json) => _$AbiStructFieldFromJson(json); Map toJson() => _$AbiStructFieldToJson(this); @@ -113,18 +109,21 @@ class AbiStructField { @JsonSerializable() class AbiStruct { @JsonKey(name: 'name') - String name; + String? name; @JsonKey(name: 'base') - String base; + String? base; @JsonKey(name: 'fields') - List fields; + List? fields; - AbiStruct(this.name, this.base, this.fields); + AbiStruct( + this.name, + this.base, + this.fields, + ); - factory AbiStruct.fromJson(Map json) => - _$AbiStructFromJson(json); + factory AbiStruct.fromJson(Map json) => _$AbiStructFromJson(json); Map toJson() => _$AbiStructToJson(this); @@ -145,8 +144,7 @@ class AbiAction { AbiAction(this.name, this.type, this.ricardian_contract); - factory AbiAction.fromJson(Map json) => - _$AbiActionFromJson(json); + factory AbiAction.fromJson(Map json) => _$AbiActionFromJson(json); Map toJson() => _$AbiActionToJson(this); @@ -171,11 +169,9 @@ class AbiTable { @JsonKey(name: 'key_types') List key_types; //key_types - AbiTable( - this.name, this.type, this.index_type, this.key_names, this.key_types); + AbiTable(this.name, this.type, this.index_type, this.key_names, this.key_types); - factory AbiTable.fromJson(Map json) => - _$AbiTableFromJson(json); + factory AbiTable.fromJson(Map json) => _$AbiTableFromJson(json); Map toJson() => _$AbiTableToJson(this); @@ -193,8 +189,7 @@ class AbiRicardianClauses { AbiRicardianClauses(this.id, this.body); - factory AbiRicardianClauses.fromJson(Map json) => - _$AbiRicardianClausesFromJson(json); + factory AbiRicardianClauses.fromJson(Map json) => _$AbiRicardianClausesFromJson(json); Map toJson() => _$AbiRicardianClausesToJson(this); @@ -212,8 +207,7 @@ class AbiErrorMessages { AbiErrorMessages(this.error_code, this.error_msg); - factory AbiErrorMessages.fromJson(Map json) => - _$AbiErrorMessagesFromJson(json); + factory AbiErrorMessages.fromJson(Map json) => _$AbiErrorMessagesFromJson(json); Map toJson() => _$AbiErrorMessagesToJson(this); @@ -231,8 +225,7 @@ class AbiExtensions { AbiExtensions(this.tag, this.value); - factory AbiExtensions.fromJson(Map json) => - _$AbiExtensionsFromJson(json); + factory AbiExtensions.fromJson(Map json) => _$AbiExtensionsFromJson(json); Map toJson() => _$AbiExtensionsToJson(this); @@ -243,15 +236,17 @@ class AbiExtensions { @JsonSerializable() class AbiVariants { @JsonKey(name: 'name') - String name; + String? name; @JsonKey(name: 'types') - List types; + List? types; - AbiVariants(this.name, this.types); + AbiVariants( + this.name, + this.types, + ); - factory AbiVariants.fromJson(Map json) => - _$AbiVariantsFromJson(json); + factory AbiVariants.fromJson(Map json) => _$AbiVariantsFromJson(json); Map toJson() => _$AbiVariantsToJson(this); @@ -263,42 +258,43 @@ class AbiVariants { @JsonSerializable() class Abi { @JsonKey(name: 'version') - String version; + String? version; @JsonKey(name: 'types') - List types; + List? types; @JsonKey(name: 'structs') - List structs; + List? structs; @JsonKey(name: 'actions') - List actions; + List? actions; @JsonKey(name: 'tables') - List tables; + List? tables; @JsonKey(name: 'ricardian_clauses') - List ricardian_clauses; + List? ricardian_clauses; @JsonKey(name: 'error_messages') - List error_messages; + List? error_messages; @JsonKey(name: 'abi_extensions') - List abi_extensions; + List? abi_extensions; @JsonKey(name: 'variants') - List variants; - - Abi( - {this.abi_extensions, - this.actions, - this.error_messages, - this.ricardian_clauses, - this.structs, - this.tables, - this.types, - this.variants, - this.version}); + List? variants; + + Abi({ + this.abi_extensions, + this.actions, + this.error_messages, + this.ricardian_clauses, + this.structs, + this.tables, + this.types, + this.variants, + this.version, + }); factory Abi.fromJson(Map json) => _$AbiFromJson(json); diff --git a/lib/src/models/abi.g.dart b/lib/src/models/abi.g.dart index 3e83fd7..05d5d20 100644 --- a/lib/src/models/abi.g.dart +++ b/lib/src/models/abi.g.dart @@ -6,158 +6,160 @@ part of 'abi.dart'; // JsonSerializableGenerator // ************************************************************************** -AbiResp _$AbiRespFromJson(Map json) { - return AbiResp() - ..accountName = json['account_name'] as String - ..codeHash = json['code_hash'] as String - ..abiHash = json['abi_hash'] as String - ..wasm = json['wasm'] as String - ..abi = json['abi'] == null ? null : AbiResp._decodeAbi(json['abi']); -} +AbiResp _$AbiRespFromJson(Map json) => AbiResp() + ..accountName = json['account_name'] as String? + ..codeHash = json['code_hash'] as String? + ..abiHash = json['abi_hash'] as String? + ..wasm = json['wasm'] as String? + ..abi = AbiResp._decodeAbi(json['abi']); Map _$AbiRespToJson(AbiResp instance) => { 'account_name': instance.accountName, 'code_hash': instance.codeHash, 'abi_hash': instance.abiHash, 'wasm': instance.wasm, - 'abi': instance.abi + 'abi': instance.abi, }; -AbiType _$AbiTypeFromJson(Map json) { - return AbiType(json['new_type_name'] as String, json['type'] as String); -} +AbiType _$AbiTypeFromJson(Map json) => AbiType( + json['new_type_name'] as String, + json['type'] as String, + ); Map _$AbiTypeToJson(AbiType instance) => { 'new_type_name': instance.new_type_name, - 'type': instance.type + 'type': instance.type, }; -AbiStructField _$AbiStructFieldFromJson(Map json) { - return AbiStructField(json['name'] as String, json['type'] as String); -} +AbiStructField _$AbiStructFieldFromJson(Map json) => + AbiStructField( + json['name'] as String, + json['type'] as String, + ); Map _$AbiStructFieldToJson(AbiStructField instance) => - {'name': instance.name, 'type': instance.type}; + { + 'name': instance.name, + 'type': instance.type, + }; -AbiStruct _$AbiStructFromJson(Map json) { - return AbiStruct( - json['name'] as String, - json['base'] as String, - (json['fields'] as List) - ?.map((e) => e == null - ? null - : AbiStructField.fromJson(e as Map)) - ?.toList()); -} +AbiStruct _$AbiStructFromJson(Map json) => AbiStruct( + json['name'] as String?, + json['base'] as String?, + (json['fields'] as List?) + ?.map((e) => AbiStructField.fromJson(e as Map)) + .toList(), + ); Map _$AbiStructToJson(AbiStruct instance) => { 'name': instance.name, 'base': instance.base, - 'fields': instance.fields + 'fields': instance.fields, }; -AbiAction _$AbiActionFromJson(Map json) { - return AbiAction(json['name'] as String, json['type'] as String, - json['ricardian_contract'] as String); -} +AbiAction _$AbiActionFromJson(Map json) => AbiAction( + json['name'] as String, + json['type'] as String, + json['ricardian_contract'] as String, + ); Map _$AbiActionToJson(AbiAction instance) => { 'name': instance.name, 'type': instance.type, - 'ricardian_contract': instance.ricardian_contract + 'ricardian_contract': instance.ricardian_contract, }; -AbiTable _$AbiTableFromJson(Map json) { - return AbiTable( +AbiTable _$AbiTableFromJson(Map json) => AbiTable( json['name'] as String, json['type'] as String, json['index_type'] as String, - (json['key_names'] as List)?.map((e) => e as String)?.toList(), - (json['key_types'] as List)?.map((e) => e as String)?.toList()); -} + (json['key_names'] as List).map((e) => e as String).toList(), + (json['key_types'] as List).map((e) => e as String).toList(), + ); Map _$AbiTableToJson(AbiTable instance) => { 'name': instance.name, 'type': instance.type, 'index_type': instance.index_type, 'key_names': instance.key_names, - 'key_types': instance.key_types + 'key_types': instance.key_types, }; -AbiRicardianClauses _$AbiRicardianClausesFromJson(Map json) { - return AbiRicardianClauses(json['id'] as String, json['body'] as String); -} +AbiRicardianClauses _$AbiRicardianClausesFromJson(Map json) => + AbiRicardianClauses( + json['id'] as String, + json['body'] as String, + ); Map _$AbiRicardianClausesToJson( AbiRicardianClauses instance) => - {'id': instance.id, 'body': instance.body}; + { + 'id': instance.id, + 'body': instance.body, + }; -AbiErrorMessages _$AbiErrorMessagesFromJson(Map json) { - return AbiErrorMessages( - json['error_code'] as String, json['error_msg'] as String); -} +AbiErrorMessages _$AbiErrorMessagesFromJson(Map json) => + AbiErrorMessages( + json['error_code'] as String, + json['error_msg'] as String, + ); Map _$AbiErrorMessagesToJson(AbiErrorMessages instance) => { 'error_code': instance.error_code, - 'error_msg': instance.error_msg + 'error_msg': instance.error_msg, }; -AbiExtensions _$AbiExtensionsFromJson(Map json) { - return AbiExtensions(json['tag'] as int, json['value'] as String); -} +AbiExtensions _$AbiExtensionsFromJson(Map json) => + AbiExtensions( + json['tag'] as int, + json['value'] as String, + ); Map _$AbiExtensionsToJson(AbiExtensions instance) => - {'tag': instance.tag, 'value': instance.value}; + { + 'tag': instance.tag, + 'value': instance.value, + }; -AbiVariants _$AbiVariantsFromJson(Map json) { - return AbiVariants(json['name'] as String, - (json['types'] as List)?.map((e) => e as String)?.toList()); -} +AbiVariants _$AbiVariantsFromJson(Map json) => AbiVariants( + json['name'] as String?, + (json['types'] as List?)?.map((e) => e as String).toList(), + ); Map _$AbiVariantsToJson(AbiVariants instance) => - {'name': instance.name, 'types': instance.types}; - -Abi _$AbiFromJson(Map json) { - return Abi( - abi_extensions: (json['abi_extensions'] as List) - ?.map((e) => e == null - ? null - : AbiExtensions.fromJson(e as Map)) - ?.toList(), - actions: (json['actions'] as List) - ?.map((e) => - e == null ? null : AbiAction.fromJson(e as Map)) - ?.toList(), - error_messages: (json['error_messages'] as List) - ?.map((e) => e == null - ? null - : AbiErrorMessages.fromJson(e as Map)) - ?.toList(), - ricardian_clauses: (json['ricardian_clauses'] as List) - ?.map((e) => e == null - ? null - : AbiRicardianClauses.fromJson(e as Map)) - ?.toList(), - structs: (json['structs'] as List) - ?.map((e) => - e == null ? null : AbiStruct.fromJson(e as Map)) - ?.toList(), - tables: (json['tables'] as List) - ?.map((e) => - e == null ? null : AbiTable.fromJson(e as Map)) - ?.toList(), - types: (json['types'] as List) - ?.map((e) => - e == null ? null : AbiType.fromJson(e as Map)) - ?.toList(), - variants: (json['variants'] as List) - ?.map((e) => e == null - ? null - : AbiVariants.fromJson(e as Map)) - ?.toList(), - version: json['version'] as String); -} + { + 'name': instance.name, + 'types': instance.types, + }; + +Abi _$AbiFromJson(Map json) => Abi( + abi_extensions: (json['abi_extensions'] as List?) + ?.map((e) => AbiExtensions.fromJson(e as Map)) + .toList(), + actions: (json['actions'] as List?) + ?.map((e) => AbiAction.fromJson(e as Map)) + .toList(), + error_messages: (json['error_messages'] as List?) + ?.map((e) => AbiErrorMessages.fromJson(e as Map)) + .toList(), + ricardian_clauses: (json['ricardian_clauses'] as List?) + ?.map((e) => AbiRicardianClauses.fromJson(e as Map)) + .toList(), + structs: (json['structs'] as List?) + ?.map((e) => AbiStruct.fromJson(e as Map)) + .toList(), + tables: (json['tables'] as List?) + ?.map((e) => AbiTable.fromJson(e as Map)) + .toList(), + types: (json['types'] as List?) + ?.map((e) => AbiType.fromJson(e as Map)) + .toList(), + variants: (json['variants'] as List?) + ?.map((e) => AbiVariants.fromJson(e as Map)) + .toList(), + version: json['version'] as String?, + ); Map _$AbiToJson(Abi instance) => { 'version': instance.version, @@ -168,5 +170,5 @@ Map _$AbiToJson(Abi instance) => { 'ricardian_clauses': instance.ricardian_clauses, 'error_messages': instance.error_messages, 'abi_extensions': instance.abi_extensions, - 'variants': instance.variants + 'variants': instance.variants, }; diff --git a/lib/src/models/account.dart b/lib/src/models/account.dart index 69230c4..389a934 100644 --- a/lib/src/models/account.dart +++ b/lib/src/models/account.dart @@ -14,52 +14,52 @@ class Account with ConversionHelper { final int headBlockNum; @JsonKey(name: 'head_block_time') - DateTime headBlockTime; + DateTime? headBlockTime; @JsonKey(name: 'privileged') - bool privileged; + bool? privileged; @JsonKey(name: 'last_code_update') - DateTime lastCodeUpdate; + DateTime? lastCodeUpdate; @JsonKey(name: 'created') - DateTime created; + DateTime? created; @JsonKey(name: 'core_liquid_balance') - Holding coreLiquidBalance; + Holding? coreLiquidBalance; @JsonKey(name: 'ram_quota', fromJson: ConversionHelper.getIntFromJson) - int ramQuota; + int? ramQuota; @JsonKey(name: 'net_weight', fromJson: ConversionHelper.getIntFromJson) - int netWeight; + int? netWeight; @JsonKey(name: 'cpu_weight', fromJson: ConversionHelper.getIntFromJson) - int cpuWeight; + int? cpuWeight; @JsonKey(name: 'net_limit') - Limit netLimit; + Limit? netLimit; @JsonKey(name: 'cpu_limit') - Limit cpuLimit; + Limit? cpuLimit; @JsonKey(name: 'ram_usage', fromJson: ConversionHelper.getIntFromJson) - int ramUsage; + int? ramUsage; @JsonKey(name: 'total_resources') - TotalResources totalResources; + TotalResources? totalResources; @JsonKey(name: 'permissions') - List permissions; + List? permissions; @JsonKey(name: 'self_delegated_bandwidth') - SelfDelegatedBandwidth selfDelegatedBandwidth; + SelfDelegatedBandwidth? selfDelegatedBandwidth; @JsonKey(name: 'refund_request') - RefundRequest refundRequest; + RefundRequest? refundRequest; @JsonKey(name: 'voter_info') - VoterInfo voterInfo; + VoterInfo? voterInfo; Account(this.accountName, this.headBlockNum); @@ -75,13 +75,13 @@ class Account with ConversionHelper { @JsonSerializable() class Limit with ConversionHelper { @JsonKey(name: 'used', fromJson: ConversionHelper.getIntFromJson) - int used; + int? used; @JsonKey(name: 'available', fromJson: ConversionHelper.getIntFromJson) - int available; + int? available; @JsonKey(name: 'max', fromJson: ConversionHelper.getIntFromJson) - int max; + int? max; Limit(); @@ -98,8 +98,8 @@ class Limit with ConversionHelper { /// Structure for the JSON string format e.g. '1.0000 EOS', it splits that by /// 'amount' and 'currency' class Holding { - double amount; - String currency; + double? amount; + String? currency; Holding.fromJson(String json) { List segments = json.split(" "); @@ -119,13 +119,13 @@ class Holding { @JsonSerializable() class Permission { @JsonKey(name: 'perm_name') - String permName; + String? permName; @JsonKey(name: 'parent') - String parent; + String? parent; @JsonKey(name: 'required_auth') - RequiredAuth requiredAuth; + RequiredAuth? requiredAuth; Permission(); @@ -141,16 +141,16 @@ class Permission { @JsonSerializable() class RequiredAuth { @JsonKey(name: 'threshold') - int threshold; + int? threshold; @JsonKey(name: 'keys') - List keys; + List? keys; @JsonKey(name: 'accounts') - List accounts; + List? accounts; @JsonKey(name: 'waits') - List waits; + List? waits; RequiredAuth(); @@ -166,10 +166,10 @@ class RequiredAuth { @JsonSerializable() class AuthKey { @JsonKey(name: 'key') - String key; + String? key; @JsonKey(name: 'weight') - int weight; + int? weight; AuthKey(); @@ -185,16 +185,16 @@ class AuthKey { @JsonSerializable() class TotalResources with ConversionHelper { @JsonKey(name: 'owner') - String owner; + String? owner; @JsonKey(name: 'net_weight') - Holding netWeight; + Holding? netWeight; @JsonKey(name: 'cpu_weight') - Holding cpuWeight; + Holding? cpuWeight; @JsonKey(name: 'ram_bytes', fromJson: ConversionHelper.getIntFromJson) - int ramBytes; + int? ramBytes; TotalResources(); @@ -210,16 +210,16 @@ class TotalResources with ConversionHelper { @JsonSerializable() class SelfDelegatedBandwidth { @JsonKey(name: 'from') - String from; + String? from; @JsonKey(name: 'to') - String to; + String? to; @JsonKey(name: 'net_weight') - Holding netWeight; + Holding? netWeight; @JsonKey(name: 'cpu_weight') - Holding cpuWeight; + Holding? cpuWeight; SelfDelegatedBandwidth(); @@ -235,16 +235,16 @@ class SelfDelegatedBandwidth { @JsonSerializable() class RefundRequest { @JsonKey(name: 'owner') - String owner; + String? owner; @JsonKey(name: 'request_time') - DateTime requestTime; + DateTime? requestTime; @JsonKey(name: 'net_amount') - Holding netAmount; + Holding? netAmount; @JsonKey(name: 'cpu_amount') - Holding cpuAmount; + Holding? cpuAmount; RefundRequest(); @@ -260,25 +260,25 @@ class RefundRequest { @JsonSerializable() class VoterInfo with ConversionHelper { @JsonKey(name: 'owner') - String owner; + String? owner; @JsonKey(name: 'proxy') - String proxy; + String? proxy; @JsonKey(name: 'producers') - Object producers; + Object? producers; @JsonKey(name: 'staked', fromJson: ConversionHelper.getIntFromJson) - int staked; + int? staked; @JsonKey(name: 'last_vote_weight') - String lastVoteWeight; + String? lastVoteWeight; @JsonKey(name: 'proxied_vote_weight') - String proxiedVoteWeight; + String? proxiedVoteWeight; @JsonKey(name: 'is_proxy') - int isProxy; + int? isProxy; VoterInfo(); diff --git a/lib/src/models/account.g.dart b/lib/src/models/account.g.dart index 76eaca7..099cf2a 100644 --- a/lib/src/models/account.g.dart +++ b/lib/src/models/account.g.dart @@ -6,58 +6,51 @@ part of 'account.dart'; // JsonSerializableGenerator // ************************************************************************** -Account _$AccountFromJson(Map json) { - return Account(json['account_name'] as String, json['head_block_num'] as int) - ..headBlockTime = json['head_block_time'] == null - ? null - : DateTime.parse(json['head_block_time'] as String) - ..privileged = json['privileged'] as bool - ..lastCodeUpdate = json['last_code_update'] == null - ? null - : DateTime.parse(json['last_code_update'] as String) - ..created = json['created'] == null - ? null - : DateTime.parse(json['created'] as String) - ..coreLiquidBalance = json['core_liquid_balance'] == null - ? null - : Holding.fromJson(json['core_liquid_balance'] as String) - ..ramQuota = json['ram_quota'] == null - ? null - : ConversionHelper.getIntFromJson(json['ram_quota']) - ..netWeight = json['net_weight'] == null - ? null - : ConversionHelper.getIntFromJson(json['net_weight']) - ..cpuWeight = json['cpu_weight'] == null - ? null - : ConversionHelper.getIntFromJson(json['cpu_weight']) - ..netLimit = json['net_limit'] == null - ? null - : Limit.fromJson(json['net_limit'] as Map) - ..cpuLimit = json['cpu_limit'] == null - ? null - : Limit.fromJson(json['cpu_limit'] as Map) - ..ramUsage = json['ram_usage'] == null - ? null - : ConversionHelper.getIntFromJson(json['ram_usage']) - ..totalResources = json['total_resources'] == null - ? null - : TotalResources.fromJson( - json['total_resources'] as Map) - ..permissions = (json['permissions'] as List) - ?.map((e) => - e == null ? null : Permission.fromJson(e as Map)) - ?.toList() - ..selfDelegatedBandwidth = json['self_delegated_bandwidth'] == null - ? null - : SelfDelegatedBandwidth.fromJson( - json['self_delegated_bandwidth'] as Map) - ..refundRequest = json['refund_request'] == null - ? null - : RefundRequest.fromJson(json['refund_request'] as Map) - ..voterInfo = json['voter_info'] == null - ? null - : VoterInfo.fromJson(json['voter_info'] as Map); -} +Account _$AccountFromJson(Map json) => Account( + json['account_name'] as String, + json['head_block_num'] as int, + ) + ..headBlockTime = json['head_block_time'] == null + ? null + : DateTime.parse(json['head_block_time'] as String) + ..privileged = json['privileged'] as bool? + ..lastCodeUpdate = json['last_code_update'] == null + ? null + : DateTime.parse(json['last_code_update'] as String) + ..created = json['created'] == null + ? null + : DateTime.parse(json['created'] as String) + ..coreLiquidBalance = json['core_liquid_balance'] == null + ? null + : Holding.fromJson(json['core_liquid_balance'] as String) + ..ramQuota = ConversionHelper.getIntFromJson(json['ram_quota']) + ..netWeight = ConversionHelper.getIntFromJson(json['net_weight']) + ..cpuWeight = ConversionHelper.getIntFromJson(json['cpu_weight']) + ..netLimit = json['net_limit'] == null + ? null + : Limit.fromJson(json['net_limit'] as Map) + ..cpuLimit = json['cpu_limit'] == null + ? null + : Limit.fromJson(json['cpu_limit'] as Map) + ..ramUsage = ConversionHelper.getIntFromJson(json['ram_usage']) + ..totalResources = json['total_resources'] == null + ? null + : TotalResources.fromJson( + json['total_resources'] as Map) + ..permissions = (json['permissions'] as List?) + ?.map((e) => Permission.fromJson(e as Map)) + .toList() + ..selfDelegatedBandwidth = json['self_delegated_bandwidth'] == null + ? null + : SelfDelegatedBandwidth.fromJson( + json['self_delegated_bandwidth'] as Map) + ..refundRequest = json['refund_request'] == null + ? null + : RefundRequest.fromJson( + json['refund_request'] as Map) + ..voterInfo = json['voter_info'] == null + ? null + : VoterInfo.fromJson(json['voter_info'] as Map); Map _$AccountToJson(Account instance) => { 'account_name': instance.accountName, @@ -77,106 +70,90 @@ Map _$AccountToJson(Account instance) => { 'permissions': instance.permissions, 'self_delegated_bandwidth': instance.selfDelegatedBandwidth, 'refund_request': instance.refundRequest, - 'voter_info': instance.voterInfo + 'voter_info': instance.voterInfo, }; -Limit _$LimitFromJson(Map json) { - return Limit() - ..used = json['used'] == null - ? null - : ConversionHelper.getIntFromJson(json['used']) - ..available = json['available'] == null - ? null - : ConversionHelper.getIntFromJson(json['available']) - ..max = json['max'] == null - ? null - : ConversionHelper.getIntFromJson(json['max']); -} +Limit _$LimitFromJson(Map json) => Limit() + ..used = ConversionHelper.getIntFromJson(json['used']) + ..available = ConversionHelper.getIntFromJson(json['available']) + ..max = ConversionHelper.getIntFromJson(json['max']); Map _$LimitToJson(Limit instance) => { 'used': instance.used, 'available': instance.available, - 'max': instance.max + 'max': instance.max, }; -Permission _$PermissionFromJson(Map json) { - return Permission() - ..permName = json['perm_name'] as String - ..parent = json['parent'] as String - ..requiredAuth = json['required_auth'] == null - ? null - : RequiredAuth.fromJson(json['required_auth'] as Map); -} +Permission _$PermissionFromJson(Map json) => Permission() + ..permName = json['perm_name'] as String? + ..parent = json['parent'] as String? + ..requiredAuth = json['required_auth'] == null + ? null + : RequiredAuth.fromJson(json['required_auth'] as Map); Map _$PermissionToJson(Permission instance) => { 'perm_name': instance.permName, 'parent': instance.parent, - 'required_auth': instance.requiredAuth + 'required_auth': instance.requiredAuth, }; -RequiredAuth _$RequiredAuthFromJson(Map json) { - return RequiredAuth() - ..threshold = json['threshold'] as int - ..keys = (json['keys'] as List) - ?.map((e) => - e == null ? null : AuthKey.fromJson(e as Map)) - ?.toList() - ..accounts = json['accounts'] as List - ..waits = json['waits'] as List; -} +RequiredAuth _$RequiredAuthFromJson(Map json) => RequiredAuth() + ..threshold = json['threshold'] as int? + ..keys = (json['keys'] as List?) + ?.map((e) => AuthKey.fromJson(e as Map)) + .toList() + ..accounts = + (json['accounts'] as List?)?.map((e) => e as Object).toList() + ..waits = (json['waits'] as List?)?.map((e) => e as Object).toList(); Map _$RequiredAuthToJson(RequiredAuth instance) => { 'threshold': instance.threshold, 'keys': instance.keys, 'accounts': instance.accounts, - 'waits': instance.waits + 'waits': instance.waits, }; -AuthKey _$AuthKeyFromJson(Map json) { - return AuthKey() - ..key = json['key'] as String - ..weight = json['weight'] as int; -} - -Map _$AuthKeyToJson(AuthKey instance) => - {'key': instance.key, 'weight': instance.weight}; - -TotalResources _$TotalResourcesFromJson(Map json) { - return TotalResources() - ..owner = json['owner'] as String - ..netWeight = json['net_weight'] == null - ? null - : Holding.fromJson(json['net_weight'] as String) - ..cpuWeight = json['cpu_weight'] == null - ? null - : Holding.fromJson(json['cpu_weight'] as String) - ..ramBytes = json['ram_bytes'] == null - ? null - : ConversionHelper.getIntFromJson(json['ram_bytes']); -} +AuthKey _$AuthKeyFromJson(Map json) => AuthKey() + ..key = json['key'] as String? + ..weight = json['weight'] as int?; + +Map _$AuthKeyToJson(AuthKey instance) => { + 'key': instance.key, + 'weight': instance.weight, + }; + +TotalResources _$TotalResourcesFromJson(Map json) => + TotalResources() + ..owner = json['owner'] as String? + ..netWeight = json['net_weight'] == null + ? null + : Holding.fromJson(json['net_weight'] as String) + ..cpuWeight = json['cpu_weight'] == null + ? null + : Holding.fromJson(json['cpu_weight'] as String) + ..ramBytes = ConversionHelper.getIntFromJson(json['ram_bytes']); Map _$TotalResourcesToJson(TotalResources instance) => { 'owner': instance.owner, 'net_weight': instance.netWeight, 'cpu_weight': instance.cpuWeight, - 'ram_bytes': instance.ramBytes + 'ram_bytes': instance.ramBytes, }; SelfDelegatedBandwidth _$SelfDelegatedBandwidthFromJson( - Map json) { - return SelfDelegatedBandwidth() - ..from = json['from'] as String - ..to = json['to'] as String - ..netWeight = json['net_weight'] == null - ? null - : Holding.fromJson(json['net_weight'] as String) - ..cpuWeight = json['cpu_weight'] == null - ? null - : Holding.fromJson(json['cpu_weight'] as String); -} + Map json) => + SelfDelegatedBandwidth() + ..from = json['from'] as String? + ..to = json['to'] as String? + ..netWeight = json['net_weight'] == null + ? null + : Holding.fromJson(json['net_weight'] as String) + ..cpuWeight = json['cpu_weight'] == null + ? null + : Holding.fromJson(json['cpu_weight'] as String); Map _$SelfDelegatedBandwidthToJson( SelfDelegatedBandwidth instance) => @@ -184,43 +161,38 @@ Map _$SelfDelegatedBandwidthToJson( 'from': instance.from, 'to': instance.to, 'net_weight': instance.netWeight, - 'cpu_weight': instance.cpuWeight + 'cpu_weight': instance.cpuWeight, }; -RefundRequest _$RefundRequestFromJson(Map json) { - return RefundRequest() - ..owner = json['owner'] as String - ..requestTime = json['request_time'] == null - ? null - : DateTime.parse(json['request_time'] as String) - ..netAmount = json['net_amount'] == null - ? null - : Holding.fromJson(json['net_amount'] as String) - ..cpuAmount = json['cpu_amount'] == null - ? null - : Holding.fromJson(json['cpu_amount'] as String); -} +RefundRequest _$RefundRequestFromJson(Map json) => + RefundRequest() + ..owner = json['owner'] as String? + ..requestTime = json['request_time'] == null + ? null + : DateTime.parse(json['request_time'] as String) + ..netAmount = json['net_amount'] == null + ? null + : Holding.fromJson(json['net_amount'] as String) + ..cpuAmount = json['cpu_amount'] == null + ? null + : Holding.fromJson(json['cpu_amount'] as String); Map _$RefundRequestToJson(RefundRequest instance) => { 'owner': instance.owner, 'request_time': instance.requestTime?.toIso8601String(), 'net_amount': instance.netAmount, - 'cpu_amount': instance.cpuAmount + 'cpu_amount': instance.cpuAmount, }; -VoterInfo _$VoterInfoFromJson(Map json) { - return VoterInfo() - ..owner = json['owner'] as String - ..proxy = json['proxy'] as String - ..producers = json['producers'] - ..staked = json['staked'] == null - ? null - : ConversionHelper.getIntFromJson(json['staked']) - ..lastVoteWeight = json['last_vote_weight'] as String - ..proxiedVoteWeight = json['proxied_vote_weight'] as String - ..isProxy = json['is_proxy'] as int; -} +VoterInfo _$VoterInfoFromJson(Map json) => VoterInfo() + ..owner = json['owner'] as String? + ..proxy = json['proxy'] as String? + ..producers = json['producers'] + ..staked = ConversionHelper.getIntFromJson(json['staked']) + ..lastVoteWeight = json['last_vote_weight'] as String? + ..proxiedVoteWeight = json['proxied_vote_weight'] as String? + ..isProxy = json['is_proxy'] as int?; Map _$VoterInfoToJson(VoterInfo instance) => { 'owner': instance.owner, @@ -229,5 +201,5 @@ Map _$VoterInfoToJson(VoterInfo instance) => { 'staked': instance.staked, 'last_vote_weight': instance.lastVoteWeight, 'proxied_vote_weight': instance.proxiedVoteWeight, - 'is_proxy': instance.isProxy + 'is_proxy': instance.isProxy, }; diff --git a/lib/src/models/action.dart b/lib/src/models/action.dart index 321e350..c4f09a2 100644 --- a/lib/src/models/action.dart +++ b/lib/src/models/action.dart @@ -7,40 +7,40 @@ part 'action.g.dart'; @JsonSerializable() class ActionWithReceipt with ConversionHelper { @JsonKey(name: 'receipt') - ActionReceipt receipt; + ActionReceipt? receipt; @JsonKey(name: 'act') - Action action; + Action? action; @JsonKey(name: 'context_free') - bool contextFree; + bool? contextFree; @JsonKey(name: 'elapsed') - int elapsed; + int? elapsed; @JsonKey(name: 'console') - String console; + String? console; @JsonKey(name: 'trx_id') - String trxId; + String? trxId; @JsonKey(name: 'block_num', fromJson: ConversionHelper.getIntFromJson) - int blockNum; + int? blockNum; @JsonKey(name: 'block_time') - DateTime blockTime; + DateTime? blockTime; @JsonKey(name: 'producer_block_id') - String producerBlockId; + String? producerBlockId; @JsonKey(name: 'account_ram_deltas') - List accountRamDeltas; + List? accountRamDeltas; @JsonKey(name: 'except') - Object except; + Object? except; @JsonKey(name: 'inline_traces') - List inlineTraces; + List? inlineTraces; ActionWithReceipt(); @@ -56,16 +56,16 @@ class ActionWithReceipt with ConversionHelper { @JsonSerializable(explicitToJson: true) class Action { @JsonKey(name: 'account') - String account; + String? account; @JsonKey(name: 'name') - String name; + String? name; @JsonKey(name: 'authorization') - List authorization; + List? authorization; @JsonKey(name: 'data') - Object data; + Object? data; // @JsonKey(name: 'hex_data') // String hexData; @@ -83,16 +83,16 @@ class Action { @JsonSerializable(explicitToJson: true) class ActionArgs { @JsonKey(name: 'from') - String fromAccount; + String? fromAccount; @JsonKey(name: 'to') - String toAccount; + String? toAccount; @JsonKey(name: 'quantity') - String quantity; + String? quantity; @JsonKey(name: 'memo') - String memo; + String? memo; ActionArgs(); @@ -108,25 +108,25 @@ class ActionArgs { @JsonSerializable() class ActionReceipt with ConversionHelper { @JsonKey(name: 'receiver') - String receiver; + String? receiver; @JsonKey(name: 'act_digest') - String actDigest; + String? actDigest; @JsonKey(name: 'global_sequence', fromJson: ConversionHelper.getIntFromJson) - int globalSequence; + int? globalSequence; @JsonKey(name: 'recv_sequence', fromJson: ConversionHelper.getIntFromJson) - int receiveSequence; + int? receiveSequence; @JsonKey(name: 'auth_sequence') - List authSequence; + List? authSequence; @JsonKey(name: 'code_sequence', fromJson: ConversionHelper.getIntFromJson) - int codeSequence; + int? codeSequence; @JsonKey(name: 'abi_sequence', fromJson: ConversionHelper.getIntFromJson) - int abiSequence; + int? abiSequence; ActionReceipt(); @@ -142,10 +142,10 @@ class ActionReceipt with ConversionHelper { @JsonSerializable() class Authorization { @JsonKey(name: 'actor') - String actor; + String? actor; @JsonKey(name: 'permission') - String permission; + String? permission; Authorization(); diff --git a/lib/src/models/action.g.dart b/lib/src/models/action.g.dart index 7bebbb2..dc86105 100644 --- a/lib/src/models/action.g.dart +++ b/lib/src/models/action.g.dart @@ -6,33 +6,30 @@ part of 'action.dart'; // JsonSerializableGenerator // ************************************************************************** -ActionWithReceipt _$ActionWithReceiptFromJson(Map json) { - return ActionWithReceipt() - ..receipt = json['receipt'] == null - ? null - : ActionReceipt.fromJson(json['receipt'] as Map) - ..action = json['act'] == null - ? null - : Action.fromJson(json['act'] as Map) - ..contextFree = json['context_free'] as bool - ..elapsed = json['elapsed'] as int - ..console = json['console'] as String - ..trxId = json['trx_id'] as String - ..blockNum = json['block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_num']) - ..blockTime = json['block_time'] == null - ? null - : DateTime.parse(json['block_time'] as String) - ..producerBlockId = json['producer_block_id'] as String - ..accountRamDeltas = json['account_ram_deltas'] as List - ..except = json['except'] - ..inlineTraces = (json['inline_traces'] as List) - ?.map((e) => e == null - ? null - : ActionWithReceipt.fromJson(e as Map)) - ?.toList(); -} +ActionWithReceipt _$ActionWithReceiptFromJson(Map json) => + ActionWithReceipt() + ..receipt = json['receipt'] == null + ? null + : ActionReceipt.fromJson(json['receipt'] as Map) + ..action = json['act'] == null + ? null + : Action.fromJson(json['act'] as Map) + ..contextFree = json['context_free'] as bool? + ..elapsed = json['elapsed'] as int? + ..console = json['console'] as String? + ..trxId = json['trx_id'] as String? + ..blockNum = ConversionHelper.getIntFromJson(json['block_num']) + ..blockTime = json['block_time'] == null + ? null + : DateTime.parse(json['block_time'] as String) + ..producerBlockId = json['producer_block_id'] as String? + ..accountRamDeltas = (json['account_ram_deltas'] as List?) + ?.map((e) => e as Object) + .toList() + ..except = json['except'] + ..inlineTraces = (json['inline_traces'] as List?) + ?.map((e) => ActionWithReceipt.fromJson(e as Map)) + .toList(); Map _$ActionWithReceiptToJson(ActionWithReceipt instance) => { @@ -47,63 +44,50 @@ Map _$ActionWithReceiptToJson(ActionWithReceipt instance) => 'producer_block_id': instance.producerBlockId, 'account_ram_deltas': instance.accountRamDeltas, 'except': instance.except, - 'inline_traces': instance.inlineTraces + 'inline_traces': instance.inlineTraces, }; -Action _$ActionFromJson(Map json) { - return Action() - ..account = json['account'] as String - ..name = json['name'] as String - ..authorization = (json['authorization'] as List) - ?.map((e) => e == null - ? null - : Authorization.fromJson(e as Map)) - ?.toList() - ..data = json['data']; -} +Action _$ActionFromJson(Map json) => Action() + ..account = json['account'] as String? + ..name = json['name'] as String? + ..authorization = (json['authorization'] as List?) + ?.map((e) => Authorization.fromJson(e as Map)) + .toList() + ..data = json['data']; Map _$ActionToJson(Action instance) => { 'account': instance.account, 'name': instance.name, - 'authorization': - instance.authorization?.map((e) => e?.toJson())?.toList(), - 'data': instance.data + 'authorization': instance.authorization?.map((e) => e.toJson()).toList(), + 'data': instance.data, }; -ActionArgs _$ActionArgsFromJson(Map json) { - return ActionArgs() - ..fromAccount = json['from'] as String - ..toAccount = json['to'] as String - ..quantity = json['quantity'] as String - ..memo = json['memo'] as String; -} +ActionArgs _$ActionArgsFromJson(Map json) => ActionArgs() + ..fromAccount = json['from'] as String? + ..toAccount = json['to'] as String? + ..quantity = json['quantity'] as String? + ..memo = json['memo'] as String?; Map _$ActionArgsToJson(ActionArgs instance) => { 'from': instance.fromAccount, 'to': instance.toAccount, 'quantity': instance.quantity, - 'memo': instance.memo + 'memo': instance.memo, }; -ActionReceipt _$ActionReceiptFromJson(Map json) { - return ActionReceipt() - ..receiver = json['receiver'] as String - ..actDigest = json['act_digest'] as String - ..globalSequence = json['global_sequence'] == null - ? null - : ConversionHelper.getIntFromJson(json['global_sequence']) - ..receiveSequence = json['recv_sequence'] == null - ? null - : ConversionHelper.getIntFromJson(json['recv_sequence']) - ..authSequence = json['auth_sequence'] as List - ..codeSequence = json['code_sequence'] == null - ? null - : ConversionHelper.getIntFromJson(json['code_sequence']) - ..abiSequence = json['abi_sequence'] == null - ? null - : ConversionHelper.getIntFromJson(json['abi_sequence']); -} +ActionReceipt _$ActionReceiptFromJson(Map json) => + ActionReceipt() + ..receiver = json['receiver'] as String? + ..actDigest = json['act_digest'] as String? + ..globalSequence = + ConversionHelper.getIntFromJson(json['global_sequence']) + ..receiveSequence = ConversionHelper.getIntFromJson(json['recv_sequence']) + ..authSequence = (json['auth_sequence'] as List?) + ?.map((e) => e as Object) + .toList() + ..codeSequence = ConversionHelper.getIntFromJson(json['code_sequence']) + ..abiSequence = ConversionHelper.getIntFromJson(json['abi_sequence']); Map _$ActionReceiptToJson(ActionReceipt instance) => { @@ -113,17 +97,16 @@ Map _$ActionReceiptToJson(ActionReceipt instance) => 'recv_sequence': instance.receiveSequence, 'auth_sequence': instance.authSequence, 'code_sequence': instance.codeSequence, - 'abi_sequence': instance.abiSequence + 'abi_sequence': instance.abiSequence, }; -Authorization _$AuthorizationFromJson(Map json) { - return Authorization() - ..actor = json['actor'] as String - ..permission = json['permission'] as String; -} +Authorization _$AuthorizationFromJson(Map json) => + Authorization() + ..actor = json['actor'] as String? + ..permission = json['permission'] as String?; Map _$AuthorizationToJson(Authorization instance) => { 'actor': instance.actor, - 'permission': instance.permission + 'permission': instance.permission, }; diff --git a/lib/src/models/action_block.dart b/lib/src/models/action_block.dart index 61c17e4..ac378e5 100644 --- a/lib/src/models/action_block.dart +++ b/lib/src/models/action_block.dart @@ -8,7 +8,7 @@ part 'action_block.g.dart'; @JsonSerializable() class Actions { @JsonKey(name: 'actions') - List actions; + List? actions; Actions(); @@ -24,20 +24,20 @@ class Actions { @JsonSerializable() class ActionBlock with ConversionHelper { @JsonKey(name: 'global_action_seq', fromJson: ConversionHelper.getIntFromJson) - int globalActionSeq; + int? globalActionSeq; @JsonKey( name: 'account_action_seq', fromJson: ConversionHelper.getIntFromJson) - int accountActionSeq; + int? accountActionSeq; @JsonKey(name: 'block_num', fromJson: ConversionHelper.getIntFromJson) - int blockNum; + int? blockNum; @JsonKey(name: 'block_time') - DateTime blockTime; + DateTime? blockTime; @JsonKey(name: 'action_trace') - ActionWithReceipt actionTrace; + ActionWithReceipt? actionTrace; ActionBlock(); diff --git a/lib/src/models/action_block.g.dart b/lib/src/models/action_block.g.dart index f2afe6b..d99c777 100644 --- a/lib/src/models/action_block.g.dart +++ b/lib/src/models/action_block.g.dart @@ -6,36 +6,27 @@ part of 'action_block.dart'; // JsonSerializableGenerator // ************************************************************************** -Actions _$ActionsFromJson(Map json) { - return Actions() - ..actions = (json['actions'] as List) - ?.map((e) => - e == null ? null : ActionBlock.fromJson(e as Map)) - ?.toList(); -} +Actions _$ActionsFromJson(Map json) => Actions() + ..actions = (json['actions'] as List?) + ?.map((e) => ActionBlock.fromJson(e as Map)) + .toList(); -Map _$ActionsToJson(Actions instance) => - {'actions': instance.actions}; +Map _$ActionsToJson(Actions instance) => { + 'actions': instance.actions, + }; -ActionBlock _$ActionBlockFromJson(Map json) { - return ActionBlock() - ..globalActionSeq = json['global_action_seq'] == null - ? null - : ConversionHelper.getIntFromJson(json['global_action_seq']) - ..accountActionSeq = json['account_action_seq'] == null - ? null - : ConversionHelper.getIntFromJson(json['account_action_seq']) - ..blockNum = json['block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_num']) - ..blockTime = json['block_time'] == null - ? null - : DateTime.parse(json['block_time'] as String) - ..actionTrace = json['action_trace'] == null - ? null - : ActionWithReceipt.fromJson( - json['action_trace'] as Map); -} +ActionBlock _$ActionBlockFromJson(Map json) => ActionBlock() + ..globalActionSeq = ConversionHelper.getIntFromJson(json['global_action_seq']) + ..accountActionSeq = + ConversionHelper.getIntFromJson(json['account_action_seq']) + ..blockNum = ConversionHelper.getIntFromJson(json['block_num']) + ..blockTime = json['block_time'] == null + ? null + : DateTime.parse(json['block_time'] as String) + ..actionTrace = json['action_trace'] == null + ? null + : ActionWithReceipt.fromJson( + json['action_trace'] as Map); Map _$ActionBlockToJson(ActionBlock instance) => { @@ -43,5 +34,5 @@ Map _$ActionBlockToJson(ActionBlock instance) => 'account_action_seq': instance.accountActionSeq, 'block_num': instance.blockNum, 'block_time': instance.blockTime?.toIso8601String(), - 'action_trace': instance.actionTrace + 'action_trace': instance.actionTrace, }; diff --git a/lib/src/models/block.dart b/lib/src/models/block.dart index 7594fa5..fe33fda 100644 --- a/lib/src/models/block.dart +++ b/lib/src/models/block.dart @@ -14,43 +14,43 @@ class Block with ConversionHelper { final int blockNum; @JsonKey(name: 'timestamp') - DateTime timestamp; + DateTime? timestamp; @JsonKey(name: 'producer') - String producer; + String? producer; @JsonKey(name: 'confirmed') - int confirmed; + int? confirmed; @JsonKey(name: 'previous') - String previous; + String? previous; @JsonKey(name: 'transaction_mroot') - String transactionMRoot; + String? transactionMRoot; @JsonKey(name: 'action_mroot') - String actionMRoot; + String? actionMRoot; @JsonKey(name: 'schedule_version') - int scheduleVersion; + int? scheduleVersion; @JsonKey(name: 'new_producers') - Object newProducers; + Object? newProducers; @JsonKey(name: 'header_extensions') - List headerExtensions; + List? headerExtensions; @JsonKey(name: 'producer_signature') - String producerSignature; + String? producerSignature; @JsonKey(name: 'transactions') - List transactions; + List? transactions; @JsonKey(name: 'block_extensions') - List blockExtensions; + List? blockExtensions; @JsonKey(name: 'ref_block_prefix') - int refBlockPrefix; + int? refBlockPrefix; Block(this.id, this.blockNum); diff --git a/lib/src/models/block.g.dart b/lib/src/models/block.g.dart index 6726942..eea446f 100644 --- a/lib/src/models/block.g.dart +++ b/lib/src/models/block.g.dart @@ -6,32 +6,31 @@ part of 'block.dart'; // JsonSerializableGenerator // ************************************************************************** -Block _$BlockFromJson(Map json) { - return Block( +Block _$BlockFromJson(Map json) => Block( json['id'] as String, - json['block_num'] == null + ConversionHelper.getIntFromJson(json['block_num']), + ) + ..timestamp = json['timestamp'] == null ? null - : ConversionHelper.getIntFromJson(json['block_num'])) - ..timestamp = json['timestamp'] == null - ? null - : DateTime.parse(json['timestamp'] as String) - ..producer = json['producer'] as String - ..confirmed = json['confirmed'] as int - ..previous = json['previous'] as String - ..transactionMRoot = json['transaction_mroot'] as String - ..actionMRoot = json['action_mroot'] as String - ..scheduleVersion = json['schedule_version'] as int - ..newProducers = json['new_producers'] - ..headerExtensions = json['header_extensions'] as List - ..producerSignature = json['producer_signature'] as String - ..transactions = (json['transactions'] as List) - ?.map((e) => e == null - ? null - : TransactionReceipt.fromJson(e as Map)) - ?.toList() - ..blockExtensions = json['block_extensions'] as List - ..refBlockPrefix = json['ref_block_prefix'] as int; -} + : DateTime.parse(json['timestamp'] as String) + ..producer = json['producer'] as String? + ..confirmed = json['confirmed'] as int? + ..previous = json['previous'] as String? + ..transactionMRoot = json['transaction_mroot'] as String? + ..actionMRoot = json['action_mroot'] as String? + ..scheduleVersion = json['schedule_version'] as int? + ..newProducers = json['new_producers'] + ..headerExtensions = (json['header_extensions'] as List?) + ?.map((e) => e as Object) + .toList() + ..producerSignature = json['producer_signature'] as String? + ..transactions = (json['transactions'] as List?) + ?.map((e) => TransactionReceipt.fromJson(e as Map)) + .toList() + ..blockExtensions = (json['block_extensions'] as List?) + ?.map((e) => e as Object) + .toList() + ..refBlockPrefix = json['ref_block_prefix'] as int?; Map _$BlockToJson(Block instance) => { 'id': instance.id, @@ -48,5 +47,5 @@ Map _$BlockToJson(Block instance) => { 'producer_signature': instance.producerSignature, 'transactions': instance.transactions, 'block_extensions': instance.blockExtensions, - 'ref_block_prefix': instance.refBlockPrefix + 'ref_block_prefix': instance.refBlockPrefix, }; diff --git a/lib/src/models/block_header_state.dart b/lib/src/models/block_header_state.dart index 7d633ad..8e7813d 100644 --- a/lib/src/models/block_header_state.dart +++ b/lib/src/models/block_header_state.dart @@ -7,60 +7,60 @@ part 'block_header_state.g.dart'; @JsonSerializable() class BlockHeaderState with ConversionHelper { @JsonKey(name: 'id') - String id; + String? id; @JsonKey(name: 'block_num', fromJson: ConversionHelper.getIntFromJson) - int blockNum; + int? blockNum; @JsonKey(name: 'header') - Header header; + Header? header; @JsonKey( name: 'dpos_proposed_irreversible_blocknum', fromJson: ConversionHelper.getIntFromJson) - int dposProposedIrreversibleBlocknum; + int? dposProposedIrreversibleBlocknum; @JsonKey( name: 'dpos_irreversible_blocknum', fromJson: ConversionHelper.getIntFromJson) - int dposIrreversibleBlocknum; + int? dposIrreversibleBlocknum; @JsonKey( name: 'bft_irreversible_blocknum', fromJson: ConversionHelper.getIntFromJson) - int bftIrreversibleBlocknum; + int? bftIrreversibleBlocknum; @JsonKey( name: 'pending_schedule_lib_num', fromJson: ConversionHelper.getIntFromJson) - int pendingScheduleLibNum; + int? pendingScheduleLibNum; @JsonKey(name: 'pending_schedule_hash') - String pendingScheduleHash; + String? pendingScheduleHash; @JsonKey(name: 'pending_schedule') - Schedule pendingSchedule; + Schedule? pendingSchedule; @JsonKey(name: 'active_schedule') - Schedule activeSchedule; + Schedule? activeSchedule; @JsonKey(name: 'blockroot_merkle') - BlockRootMerkle blockrootMerkle; + BlockRootMerkle? blockrootMerkle; @JsonKey(name: 'producer_to_last_produced') - List> producerToLastProduced; + List>? producerToLastProduced; @JsonKey(name: 'producer_to_last_implied_irb') - List> producerToLastImpliedIrb; + List>? producerToLastImpliedIrb; @JsonKey(name: 'block_signing_key') - String blockSigningKey; + String? blockSigningKey; @JsonKey(name: 'confirm_count') - List confirmCount; + List? confirmCount; @JsonKey(name: 'confirmations') - List confirmations; + List? confirmations; BlockHeaderState(); @@ -76,31 +76,31 @@ class BlockHeaderState with ConversionHelper { @JsonSerializable() class Header { @JsonKey(name: 'timestamp') - DateTime timestamp; + DateTime? timestamp; @JsonKey(name: 'producer') - String producer; + String? producer; @JsonKey(name: 'confirmed') - int confirmed; + int? confirmed; @JsonKey(name: 'previous') - String previous; + String? previous; @JsonKey(name: 'transaction_mroot') - String transactionMRoot; + String? transactionMRoot; @JsonKey(name: 'action_mroot') - String actionMRoot; + String? actionMRoot; @JsonKey(name: 'schedule_version') - int scheduleVersion; + int? scheduleVersion; @JsonKey(name: 'header_extensions') - List headerExtensions; + List? headerExtensions; @JsonKey(name: 'producer_signature') - String producerSignature; + String? producerSignature; Header(); @@ -115,10 +115,10 @@ class Header { @JsonSerializable() class Schedule { @JsonKey(name: 'version') - int version; + int? version; @JsonKey(name: 'producers') - List producers; + List? producers; Schedule(); @@ -134,10 +134,10 @@ class Schedule { @JsonSerializable() class Producer { @JsonKey(name: 'producer_name') - String producerName; + String? producerName; @JsonKey(name: 'block_signing_key') - String blockSigningKey; + String? blockSigningKey; Producer(); @@ -153,10 +153,10 @@ class Producer { @JsonSerializable() class BlockRootMerkle { @JsonKey(name: '_active_nodes') - List activeNodes; + List? activeNodes; @JsonKey(name: '_node_count') - int nodeCount; + int? nodeCount; BlockRootMerkle(); diff --git a/lib/src/models/block_header_state.g.dart b/lib/src/models/block_header_state.g.dart index 6af660f..9337600 100644 --- a/lib/src/models/block_header_state.g.dart +++ b/lib/src/models/block_header_state.g.dart @@ -6,51 +6,47 @@ part of 'block_header_state.dart'; // JsonSerializableGenerator // ************************************************************************** -BlockHeaderState _$BlockHeaderStateFromJson(Map json) { - return BlockHeaderState() - ..id = json['id'] as String - ..blockNum = json['block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_num']) - ..header = json['header'] == null - ? null - : Header.fromJson(json['header'] as Map) - ..dposProposedIrreversibleBlocknum = - json['dpos_proposed_irreversible_blocknum'] == null - ? null - : ConversionHelper.getIntFromJson( - json['dpos_proposed_irreversible_blocknum']) - ..dposIrreversibleBlocknum = json['dpos_irreversible_blocknum'] == null - ? null - : ConversionHelper.getIntFromJson(json['dpos_irreversible_blocknum']) - ..bftIrreversibleBlocknum = json['bft_irreversible_blocknum'] == null - ? null - : ConversionHelper.getIntFromJson(json['bft_irreversible_blocknum']) - ..pendingScheduleLibNum = json['pending_schedule_lib_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['pending_schedule_lib_num']) - ..pendingScheduleHash = json['pending_schedule_hash'] as String - ..pendingSchedule = json['pending_schedule'] == null - ? null - : Schedule.fromJson(json['pending_schedule'] as Map) - ..activeSchedule = json['active_schedule'] == null - ? null - : Schedule.fromJson(json['active_schedule'] as Map) - ..blockrootMerkle = json['blockroot_merkle'] == null - ? null - : BlockRootMerkle.fromJson( - json['blockroot_merkle'] as Map) - ..producerToLastProduced = (json['producer_to_last_produced'] as List) - ?.map((e) => e as List) - ?.toList() - ..producerToLastImpliedIrb = (json['producer_to_last_implied_irb'] as List) - ?.map((e) => e as List) - ?.toList() - ..blockSigningKey = json['block_signing_key'] as String - ..confirmCount = - (json['confirm_count'] as List)?.map((e) => e as int)?.toList() - ..confirmations = json['confirmations'] as List; -} +BlockHeaderState _$BlockHeaderStateFromJson(Map json) => + BlockHeaderState() + ..id = json['id'] as String? + ..blockNum = ConversionHelper.getIntFromJson(json['block_num']) + ..header = json['header'] == null + ? null + : Header.fromJson(json['header'] as Map) + ..dposProposedIrreversibleBlocknum = ConversionHelper.getIntFromJson( + json['dpos_proposed_irreversible_blocknum']) + ..dposIrreversibleBlocknum = + ConversionHelper.getIntFromJson(json['dpos_irreversible_blocknum']) + ..bftIrreversibleBlocknum = + ConversionHelper.getIntFromJson(json['bft_irreversible_blocknum']) + ..pendingScheduleLibNum = + ConversionHelper.getIntFromJson(json['pending_schedule_lib_num']) + ..pendingScheduleHash = json['pending_schedule_hash'] as String? + ..pendingSchedule = json['pending_schedule'] == null + ? null + : Schedule.fromJson(json['pending_schedule'] as Map) + ..activeSchedule = json['active_schedule'] == null + ? null + : Schedule.fromJson(json['active_schedule'] as Map) + ..blockrootMerkle = json['blockroot_merkle'] == null + ? null + : BlockRootMerkle.fromJson( + json['blockroot_merkle'] as Map) + ..producerToLastProduced = (json['producer_to_last_produced'] + as List?) + ?.map((e) => (e as List).map((e) => e as Object).toList()) + .toList() + ..producerToLastImpliedIrb = (json['producer_to_last_implied_irb'] + as List?) + ?.map((e) => (e as List).map((e) => e as Object).toList()) + .toList() + ..blockSigningKey = json['block_signing_key'] as String? + ..confirmCount = (json['confirm_count'] as List?) + ?.map((e) => e as int) + .toList() + ..confirmations = (json['confirmations'] as List?) + ?.map((e) => e as Object) + .toList(); Map _$BlockHeaderStateToJson(BlockHeaderState instance) => { @@ -70,23 +66,23 @@ Map _$BlockHeaderStateToJson(BlockHeaderState instance) => 'producer_to_last_implied_irb': instance.producerToLastImpliedIrb, 'block_signing_key': instance.blockSigningKey, 'confirm_count': instance.confirmCount, - 'confirmations': instance.confirmations + 'confirmations': instance.confirmations, }; -Header _$HeaderFromJson(Map json) { - return Header() - ..timestamp = json['timestamp'] == null - ? null - : DateTime.parse(json['timestamp'] as String) - ..producer = json['producer'] as String - ..confirmed = json['confirmed'] as int - ..previous = json['previous'] as String - ..transactionMRoot = json['transaction_mroot'] as String - ..actionMRoot = json['action_mroot'] as String - ..scheduleVersion = json['schedule_version'] as int - ..headerExtensions = json['header_extensions'] as List - ..producerSignature = json['producer_signature'] as String; -} +Header _$HeaderFromJson(Map json) => Header() + ..timestamp = json['timestamp'] == null + ? null + : DateTime.parse(json['timestamp'] as String) + ..producer = json['producer'] as String? + ..confirmed = json['confirmed'] as int? + ..previous = json['previous'] as String? + ..transactionMRoot = json['transaction_mroot'] as String? + ..actionMRoot = json['action_mroot'] as String? + ..scheduleVersion = json['schedule_version'] as int? + ..headerExtensions = (json['header_extensions'] as List?) + ?.map((e) => e as Object) + .toList() + ..producerSignature = json['producer_signature'] as String?; Map _$HeaderToJson(Header instance) => { 'timestamp': instance.timestamp?.toIso8601String(), @@ -97,43 +93,38 @@ Map _$HeaderToJson(Header instance) => { 'action_mroot': instance.actionMRoot, 'schedule_version': instance.scheduleVersion, 'header_extensions': instance.headerExtensions, - 'producer_signature': instance.producerSignature + 'producer_signature': instance.producerSignature, }; -Schedule _$ScheduleFromJson(Map json) { - return Schedule() - ..version = json['version'] as int - ..producers = (json['producers'] as List) - ?.map((e) => - e == null ? null : Producer.fromJson(e as Map)) - ?.toList(); -} +Schedule _$ScheduleFromJson(Map json) => Schedule() + ..version = json['version'] as int? + ..producers = (json['producers'] as List?) + ?.map((e) => Producer.fromJson(e as Map)) + .toList(); Map _$ScheduleToJson(Schedule instance) => { 'version': instance.version, - 'producers': instance.producers + 'producers': instance.producers, }; -Producer _$ProducerFromJson(Map json) { - return Producer() - ..producerName = json['producer_name'] as String - ..blockSigningKey = json['block_signing_key'] as String; -} +Producer _$ProducerFromJson(Map json) => Producer() + ..producerName = json['producer_name'] as String? + ..blockSigningKey = json['block_signing_key'] as String?; Map _$ProducerToJson(Producer instance) => { 'producer_name': instance.producerName, - 'block_signing_key': instance.blockSigningKey + 'block_signing_key': instance.blockSigningKey, }; -BlockRootMerkle _$BlockRootMerkleFromJson(Map json) { - return BlockRootMerkle() - ..activeNodes = - (json['_active_nodes'] as List)?.map((e) => e as String)?.toList() - ..nodeCount = json['_node_count'] as int; -} +BlockRootMerkle _$BlockRootMerkleFromJson(Map json) => + BlockRootMerkle() + ..activeNodes = (json['_active_nodes'] as List?) + ?.map((e) => e as String) + .toList() + ..nodeCount = json['_node_count'] as int?; Map _$BlockRootMerkleToJson(BlockRootMerkle instance) => { '_active_nodes': instance.activeNodes, - '_node_count': instance.nodeCount + '_node_count': instance.nodeCount, }; diff --git a/lib/src/models/conversion_helper.dart b/lib/src/models/conversion_helper.dart index 15c675a..cb6bfad 100644 --- a/lib/src/models/conversion_helper.dart +++ b/lib/src/models/conversion_helper.dart @@ -15,7 +15,7 @@ mixin ConversionHelper { } static Uint8List base64ToBuffer(String base64String) { - return utf8.encode(base64String); + return Uint8List.fromList(utf8.encode(base64String)); } static String bufferToBase64(Uint8List buffer) { diff --git a/lib/src/models/node_info.dart b/lib/src/models/node_info.dart index 795055c..6737948 100644 --- a/lib/src/models/node_info.dart +++ b/lib/src/models/node_info.dart @@ -7,49 +7,49 @@ part 'node_info.g.dart'; @JsonSerializable() class NodeInfo with ConversionHelper { @JsonKey(name: 'server_version') - String serverVersion; + String? serverVersion; @JsonKey(name: 'chain_id') - String chainId; + String? chainId; @JsonKey(name: 'head_block_num', fromJson: ConversionHelper.getIntFromJson) - int headBlockNum; + int? headBlockNum; @JsonKey( name: 'last_irreversible_block_num', fromJson: ConversionHelper.getIntFromJson) - int lastIrreversibleBlockNum; + int? lastIrreversibleBlockNum; @JsonKey(name: 'last_irreversible_block_id') - String lastIrreversibleBlockId; + String? lastIrreversibleBlockId; @JsonKey(name: 'head_block_time') - DateTime headBlockTime; + DateTime? headBlockTime; @JsonKey(name: 'head_block_producer') - String headBlockProducer; + String? headBlockProducer; @JsonKey( name: 'virtual_block_cpu_limit', fromJson: ConversionHelper.getIntFromJson) - int virtualBlockCpuLimit; + int? virtualBlockCpuLimit; @JsonKey( name: 'virtual_block_net_limit', fromJson: ConversionHelper.getIntFromJson) - int virtualBlockNetLimit; + int? virtualBlockNetLimit; @JsonKey(name: 'block_cpu_limit', fromJson: ConversionHelper.getIntFromJson) - int blockCpuLimit; + int? blockCpuLimit; @JsonKey(name: 'block_net_limit', fromJson: ConversionHelper.getIntFromJson) - int blockNetLimit; + int? blockNetLimit; @JsonKey(name: 'server_version_string') - String serverVersionString; + String? serverVersionString; @JsonKey(name: 'website') - String website; + String? website; NodeInfo(); diff --git a/lib/src/models/node_info.g.dart b/lib/src/models/node_info.g.dart index 6f45130..3af7373 100644 --- a/lib/src/models/node_info.g.dart +++ b/lib/src/models/node_info.g.dart @@ -6,36 +6,25 @@ part of 'node_info.dart'; // JsonSerializableGenerator // ************************************************************************** -NodeInfo _$NodeInfoFromJson(Map json) { - return NodeInfo() - ..serverVersion = json['server_version'] as String - ..chainId = json['chain_id'] as String - ..headBlockNum = json['head_block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['head_block_num']) - ..lastIrreversibleBlockNum = json['last_irreversible_block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['last_irreversible_block_num']) - ..lastIrreversibleBlockId = json['last_irreversible_block_id'] as String - ..headBlockTime = json['head_block_time'] == null - ? null - : DateTime.parse(json['head_block_time'] as String) - ..headBlockProducer = json['head_block_producer'] as String - ..virtualBlockCpuLimit = json['virtual_block_cpu_limit'] == null - ? null - : ConversionHelper.getIntFromJson(json['virtual_block_cpu_limit']) - ..virtualBlockNetLimit = json['virtual_block_net_limit'] == null - ? null - : ConversionHelper.getIntFromJson(json['virtual_block_net_limit']) - ..blockCpuLimit = json['block_cpu_limit'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_cpu_limit']) - ..blockNetLimit = json['block_net_limit'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_net_limit']) - ..serverVersionString = json['server_version_string'] as String - ..website = json['website'] as String; -} +NodeInfo _$NodeInfoFromJson(Map json) => NodeInfo() + ..serverVersion = json['server_version'] as String? + ..chainId = json['chain_id'] as String? + ..headBlockNum = ConversionHelper.getIntFromJson(json['head_block_num']) + ..lastIrreversibleBlockNum = + ConversionHelper.getIntFromJson(json['last_irreversible_block_num']) + ..lastIrreversibleBlockId = json['last_irreversible_block_id'] as String? + ..headBlockTime = json['head_block_time'] == null + ? null + : DateTime.parse(json['head_block_time'] as String) + ..headBlockProducer = json['head_block_producer'] as String? + ..virtualBlockCpuLimit = + ConversionHelper.getIntFromJson(json['virtual_block_cpu_limit']) + ..virtualBlockNetLimit = + ConversionHelper.getIntFromJson(json['virtual_block_net_limit']) + ..blockCpuLimit = ConversionHelper.getIntFromJson(json['block_cpu_limit']) + ..blockNetLimit = ConversionHelper.getIntFromJson(json['block_net_limit']) + ..serverVersionString = json['server_version_string'] as String? + ..website = json['website'] as String?; Map _$NodeInfoToJson(NodeInfo instance) => { 'server_version': instance.serverVersion, @@ -50,5 +39,5 @@ Map _$NodeInfoToJson(NodeInfo instance) => { 'block_cpu_limit': instance.blockCpuLimit, 'block_net_limit': instance.blockNetLimit, 'server_version_string': instance.serverVersionString, - 'website': instance.website + 'website': instance.website, }; diff --git a/lib/src/models/primary_wrapper.dart b/lib/src/models/primary_wrapper.dart index 0c969ec..0c2ab18 100644 --- a/lib/src/models/primary_wrapper.dart +++ b/lib/src/models/primary_wrapper.dart @@ -5,7 +5,7 @@ part 'primary_wrapper.g.dart'; @JsonSerializable() class AccountNames { @JsonKey(name: 'account_names') - List accountNames; + List? accountNames; AccountNames(); @@ -21,7 +21,7 @@ class AccountNames { @JsonSerializable() class RequiredKeys { @JsonKey(name: 'required_keys') - List requiredKeys; + List? requiredKeys; RequiredKeys(); diff --git a/lib/src/models/primary_wrapper.g.dart b/lib/src/models/primary_wrapper.g.dart index 493dea9..73f5555 100644 --- a/lib/src/models/primary_wrapper.g.dart +++ b/lib/src/models/primary_wrapper.g.dart @@ -6,20 +6,22 @@ part of 'primary_wrapper.dart'; // JsonSerializableGenerator // ************************************************************************** -AccountNames _$AccountNamesFromJson(Map json) { - return AccountNames() - ..accountNames = - (json['account_names'] as List)?.map((e) => e as String)?.toList(); -} +AccountNames _$AccountNamesFromJson(Map json) => AccountNames() + ..accountNames = (json['account_names'] as List?) + ?.map((e) => e as String) + .toList(); Map _$AccountNamesToJson(AccountNames instance) => - {'account_names': instance.accountNames}; + { + 'account_names': instance.accountNames, + }; -RequiredKeys _$RequiredKeysFromJson(Map json) { - return RequiredKeys() - ..requiredKeys = - (json['required_keys'] as List)?.map((e) => e as String)?.toList(); -} +RequiredKeys _$RequiredKeysFromJson(Map json) => RequiredKeys() + ..requiredKeys = (json['required_keys'] as List?) + ?.map((e) => e as String) + .toList(); Map _$RequiredKeysToJson(RequiredKeys instance) => - {'required_keys': instance.requiredKeys}; + { + 'required_keys': instance.requiredKeys, + }; diff --git a/lib/src/models/transaction.dart b/lib/src/models/transaction.dart index 3623ec4..e23d6d5 100644 --- a/lib/src/models/transaction.dart +++ b/lib/src/models/transaction.dart @@ -11,24 +11,24 @@ part 'transaction.g.dart'; @JsonSerializable() class TransactionBlock with ConversionHelper { @JsonKey(name: 'id') - String id; + String? id; @JsonKey(name: 'trx') - TransactionWithReceipt trx; + TransactionWithReceipt? trx; @JsonKey(name: 'block_time') - DateTime blockTime; + DateTime? blockTime; @JsonKey(name: 'block_num', fromJson: ConversionHelper.getIntFromJson) - int blockNum; + int? blockNum; @JsonKey( name: 'last_irreversible_block', fromJson: ConversionHelper.getIntFromJson) - int lastIrreversibleBlock; + int? lastIrreversibleBlock; @JsonKey(name: 'traces') - List traces; + List? traces; TransactionBlock(); @@ -44,10 +44,10 @@ class TransactionBlock with ConversionHelper { @JsonSerializable() class TransactionWithReceipt { @JsonKey(name: 'receipt') - TransactionReceipt receipt; + TransactionReceipt? receipt; @JsonKey(name: 'trx') - Transaction transaction; + Transaction? transaction; TransactionWithReceipt(); @@ -63,16 +63,16 @@ class TransactionWithReceipt { @JsonSerializable() class TransactionReceipt with ConversionHelper { @JsonKey(name: 'status') - String status; + String? status; @JsonKey(name: 'cpu_usage_us', fromJson: ConversionHelper.getIntFromJson) - int cpuUsageUs; + int? cpuUsageUs; @JsonKey(name: 'net_usage_words', fromJson: ConversionHelper.getIntFromJson) - int netUsageWords; + int? netUsageWords; @JsonKey(name: 'trx') - Object trx; + Object? trx; TransactionReceipt(); @@ -88,37 +88,37 @@ class TransactionReceipt with ConversionHelper { @JsonSerializable(explicitToJson: true) class Transaction { @JsonKey(name: 'expiration') - DateTime expiration; + DateTime? expiration; @JsonKey(name: 'ref_block_num') - int refBlockNum; + int? refBlockNum; @JsonKey(name: 'ref_block_prefix') - int refBlockPrefix; + int? refBlockPrefix; @JsonKey(name: 'max_net_usage_words') - int maxNetUsageWords = 0; + int? maxNetUsageWords = 0; @JsonKey(name: 'max_cpu_usage_ms') - int maxCpuUsageMs = 0; + int? maxCpuUsageMs = 0; @JsonKey(name: 'delay_sec') - int delaySec = 0; + int? delaySec = 0; @JsonKey(name: 'context_free_actions') - List contextFreeActions = []; + List? contextFreeActions = []; @JsonKey(name: 'actions') - List actions = []; + List? actions = []; @JsonKey(name: 'transaction_extensions') - List transactionExtensions = []; + List? transactionExtensions = []; @JsonKey(name: 'signatures') - List signatures = []; + List? signatures = []; @JsonKey(name: 'context_free_data') - List contextFreeData = []; + List? contextFreeData = []; Transaction(); @@ -132,7 +132,7 @@ class Transaction { Uint8List toBinary(Type transactionType) { var buffer = ser.SerialBuffer(Uint8List(0)); - transactionType.serialize(transactionType, buffer, this.toJson()); + transactionType.serialize?.call(transactionType, buffer, this.toJson()); return buffer.asUint8List(); } } @@ -140,10 +140,10 @@ class Transaction { @JsonSerializable() class TransactionCommitted { @JsonKey(name: 'transaction_id') - String id; + String? id; @JsonKey(name: 'processed') - TransactionProcessed processed; + TransactionProcessed? processed; TransactionCommitted(); @@ -159,31 +159,31 @@ class TransactionCommitted { @JsonSerializable() class TransactionProcessed with ConversionHelper { @JsonKey(name: 'id') - String id; + String? id; @JsonKey(name: 'block_num', fromJson: ConversionHelper.getIntFromJson) - int blockNum; + int? blockNum; @JsonKey(name: 'block_time') - DateTime blockTime; + DateTime? blockTime; @JsonKey(name: 'producer_block_id', fromJson: ConversionHelper.getIntFromJson) - int producerBlockId; + int? producerBlockId; @JsonKey(name: 'receipt') - TransactionReceipt receipt; + TransactionReceipt? receipt; @JsonKey(name: 'elapsed', fromJson: ConversionHelper.getIntFromJson) - int elapsed; + int? elapsed; @JsonKey(name: 'net_usage', fromJson: ConversionHelper.getIntFromJson) - int netUsage; + int? netUsage; @JsonKey(name: 'scheduled') - bool scheduled; + bool? scheduled; @JsonKey(name: 'action_traces') - List actionTraces; + List? actionTraces; TransactionProcessed(); diff --git a/lib/src/models/transaction.g.dart b/lib/src/models/transaction.g.dart index d2f8176..4883b72 100644 --- a/lib/src/models/transaction.g.dart +++ b/lib/src/models/transaction.g.dart @@ -6,27 +6,21 @@ part of 'transaction.dart'; // JsonSerializableGenerator // ************************************************************************** -TransactionBlock _$TransactionBlockFromJson(Map json) { - return TransactionBlock() - ..id = json['id'] as String - ..trx = json['trx'] == null - ? null - : TransactionWithReceipt.fromJson(json['trx'] as Map) - ..blockTime = json['block_time'] == null - ? null - : DateTime.parse(json['block_time'] as String) - ..blockNum = json['block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_num']) - ..lastIrreversibleBlock = json['last_irreversible_block'] == null - ? null - : ConversionHelper.getIntFromJson(json['last_irreversible_block']) - ..traces = (json['traces'] as List) - ?.map((e) => e == null - ? null - : ActionWithReceipt.fromJson(e as Map)) - ?.toList(); -} +TransactionBlock _$TransactionBlockFromJson(Map json) => + TransactionBlock() + ..id = json['id'] as String? + ..trx = json['trx'] == null + ? null + : TransactionWithReceipt.fromJson(json['trx'] as Map) + ..blockTime = json['block_time'] == null + ? null + : DateTime.parse(json['block_time'] as String) + ..blockNum = ConversionHelper.getIntFromJson(json['block_num']) + ..lastIrreversibleBlock = + ConversionHelper.getIntFromJson(json['last_irreversible_block']) + ..traces = (json['traces'] as List?) + ?.map((e) => ActionWithReceipt.fromJson(e as Map)) + .toList(); Map _$TransactionBlockToJson(TransactionBlock instance) => { @@ -35,64 +29,64 @@ Map _$TransactionBlockToJson(TransactionBlock instance) => 'block_time': instance.blockTime?.toIso8601String(), 'block_num': instance.blockNum, 'last_irreversible_block': instance.lastIrreversibleBlock, - 'traces': instance.traces + 'traces': instance.traces, }; TransactionWithReceipt _$TransactionWithReceiptFromJson( - Map json) { - return TransactionWithReceipt() - ..receipt = json['receipt'] == null - ? null - : TransactionReceipt.fromJson(json['receipt'] as Map) - ..transaction = json['trx'] == null - ? null - : Transaction.fromJson(json['trx'] as Map); -} + Map json) => + TransactionWithReceipt() + ..receipt = json['receipt'] == null + ? null + : TransactionReceipt.fromJson(json['receipt'] as Map) + ..transaction = json['trx'] == null + ? null + : Transaction.fromJson(json['trx'] as Map); Map _$TransactionWithReceiptToJson( TransactionWithReceipt instance) => - {'receipt': instance.receipt, 'trx': instance.transaction}; + { + 'receipt': instance.receipt, + 'trx': instance.transaction, + }; -TransactionReceipt _$TransactionReceiptFromJson(Map json) { - return TransactionReceipt() - ..status = json['status'] as String - ..cpuUsageUs = json['cpu_usage_us'] == null - ? null - : ConversionHelper.getIntFromJson(json['cpu_usage_us']) - ..netUsageWords = json['net_usage_words'] == null - ? null - : ConversionHelper.getIntFromJson(json['net_usage_words']) - ..trx = json['trx']; -} +TransactionReceipt _$TransactionReceiptFromJson(Map json) => + TransactionReceipt() + ..status = json['status'] as String? + ..cpuUsageUs = ConversionHelper.getIntFromJson(json['cpu_usage_us']) + ..netUsageWords = ConversionHelper.getIntFromJson(json['net_usage_words']) + ..trx = json['trx']; Map _$TransactionReceiptToJson(TransactionReceipt instance) => { 'status': instance.status, 'cpu_usage_us': instance.cpuUsageUs, 'net_usage_words': instance.netUsageWords, - 'trx': instance.trx + 'trx': instance.trx, }; -Transaction _$TransactionFromJson(Map json) { - return Transaction() - ..expiration = json['expiration'] == null - ? null - : DateTime.parse(json['expiration'] as String) - ..refBlockNum = json['ref_block_num'] as int - ..refBlockPrefix = json['ref_block_prefix'] as int - ..maxNetUsageWords = json['max_net_usage_words'] as int - ..maxCpuUsageMs = json['max_cpu_usage_ms'] as int - ..delaySec = json['delay_sec'] as int - ..contextFreeActions = json['context_free_actions'] as List - ..actions = (json['actions'] as List) - ?.map((e) => - e == null ? null : Action.fromJson(e as Map)) - ?.toList() - ..transactionExtensions = json['transaction_extensions'] as List - ..signatures = - (json['signatures'] as List)?.map((e) => e as String)?.toList() - ..contextFreeData = json['context_free_data'] as List; -} +Transaction _$TransactionFromJson(Map json) => Transaction() + ..expiration = json['expiration'] == null + ? null + : DateTime.parse(json['expiration'] as String) + ..refBlockNum = json['ref_block_num'] as int? + ..refBlockPrefix = json['ref_block_prefix'] as int? + ..maxNetUsageWords = json['max_net_usage_words'] as int? + ..maxCpuUsageMs = json['max_cpu_usage_ms'] as int? + ..delaySec = json['delay_sec'] as int? + ..contextFreeActions = (json['context_free_actions'] as List?) + ?.map((e) => e as Object) + .toList() + ..actions = (json['actions'] as List?) + ?.map((e) => Action.fromJson(e as Map)) + .toList() + ..transactionExtensions = (json['transaction_extensions'] as List?) + ?.map((e) => e as Object) + .toList() + ..signatures = + (json['signatures'] as List?)?.map((e) => e as String).toList() + ..contextFreeData = (json['context_free_data'] as List?) + ?.map((e) => e as Object) + .toList(); Map _$TransactionToJson(Transaction instance) => { @@ -103,56 +97,47 @@ Map _$TransactionToJson(Transaction instance) => 'max_cpu_usage_ms': instance.maxCpuUsageMs, 'delay_sec': instance.delaySec, 'context_free_actions': instance.contextFreeActions, - 'actions': instance.actions?.map((e) => e?.toJson())?.toList(), + 'actions': instance.actions?.map((e) => e.toJson()).toList(), 'transaction_extensions': instance.transactionExtensions, 'signatures': instance.signatures, - 'context_free_data': instance.contextFreeData + 'context_free_data': instance.contextFreeData, }; -TransactionCommitted _$TransactionCommittedFromJson(Map json) { - return TransactionCommitted() - ..id = json['transaction_id'] as String - ..processed = json['processed'] == null - ? null - : TransactionProcessed.fromJson( - json['processed'] as Map); -} +TransactionCommitted _$TransactionCommittedFromJson( + Map json) => + TransactionCommitted() + ..id = json['transaction_id'] as String? + ..processed = json['processed'] == null + ? null + : TransactionProcessed.fromJson( + json['processed'] as Map); Map _$TransactionCommittedToJson( TransactionCommitted instance) => { 'transaction_id': instance.id, - 'processed': instance.processed + 'processed': instance.processed, }; -TransactionProcessed _$TransactionProcessedFromJson(Map json) { - return TransactionProcessed() - ..id = json['id'] as String - ..blockNum = json['block_num'] == null - ? null - : ConversionHelper.getIntFromJson(json['block_num']) - ..blockTime = json['block_time'] == null - ? null - : DateTime.parse(json['block_time'] as String) - ..producerBlockId = json['producer_block_id'] == null - ? null - : ConversionHelper.getIntFromJson(json['producer_block_id']) - ..receipt = json['receipt'] == null - ? null - : TransactionReceipt.fromJson(json['receipt'] as Map) - ..elapsed = json['elapsed'] == null - ? null - : ConversionHelper.getIntFromJson(json['elapsed']) - ..netUsage = json['net_usage'] == null - ? null - : ConversionHelper.getIntFromJson(json['net_usage']) - ..scheduled = json['scheduled'] as bool - ..actionTraces = (json['action_traces'] as List) - ?.map((e) => e == null - ? null - : ActionWithReceipt.fromJson(e as Map)) - ?.toList(); -} +TransactionProcessed _$TransactionProcessedFromJson( + Map json) => + TransactionProcessed() + ..id = json['id'] as String? + ..blockNum = ConversionHelper.getIntFromJson(json['block_num']) + ..blockTime = json['block_time'] == null + ? null + : DateTime.parse(json['block_time'] as String) + ..producerBlockId = + ConversionHelper.getIntFromJson(json['producer_block_id']) + ..receipt = json['receipt'] == null + ? null + : TransactionReceipt.fromJson(json['receipt'] as Map) + ..elapsed = ConversionHelper.getIntFromJson(json['elapsed']) + ..netUsage = ConversionHelper.getIntFromJson(json['net_usage']) + ..scheduled = json['scheduled'] as bool? + ..actionTraces = (json['action_traces'] as List?) + ?.map((e) => ActionWithReceipt.fromJson(e as Map)) + .toList(); Map _$TransactionProcessedToJson( TransactionProcessed instance) => @@ -165,5 +150,5 @@ Map _$TransactionProcessedToJson( 'elapsed': instance.elapsed, 'net_usage': instance.netUsage, 'scheduled': instance.scheduled, - 'action_traces': instance.actionTraces + 'action_traces': instance.actionTraces, }; diff --git a/lib/src/numeric.dart b/lib/src/numeric.dart index 22fff78..9e94152 100644 --- a/lib/src/numeric.dart +++ b/lib/src/numeric.dart @@ -138,7 +138,7 @@ Uint8List base58ToBinary(int size, String s) { /// Convert `bignum` to a base-58 number /// @param minDigits 0-pad result to this many digits String binaryToBase58(Uint8List bignum, {minDigits = 1}) { - var result = List(); + var result = [].cast(); for (var byte in bignum) { var carry = byte; for (var j = 0; j < result.length; ++j) { diff --git a/lib/src/serialize.dart b/lib/src/serialize.dart index 0f895ca..c8e9fd5 100644 --- a/lib/src/serialize.dart +++ b/lib/src/serialize.dart @@ -19,18 +19,16 @@ class SerializerState { /// Have any binary extensions been skipped? */ bool skippedBinaryExtension; - SerializerState( - {this.options = const SerializerOptions(false), - this.skippedBinaryExtension = false}); + SerializerState({this.options = const SerializerOptions(false), this.skippedBinaryExtension = false}); } /// Serialize and deserialize data */ class SerialBuffer { /// Amount of valid data in `array` */ - int length; + late int length; /// Data in serialized (binary) form */ - Uint8List array; + Uint8List? array; /// Current position while reading (deserializing) */ int readPos = 0; @@ -42,21 +40,21 @@ class SerialBuffer { SerialBuffer(this.array) { // array = array || new Uint8List(1024); - length = array != null ? array.length : 0; + length = array != null ? array!.length : 0; // textEncoder = textEncoder || new TextEncoder(); // textDecoder = textDecoder || new TextDecoder('utf-8', { fatal: true }); } /// Resize `array` if needed to have at least `size` bytes free */ void reserve(int size) { - if (length + size <= array.length) { + if (length + size <= array!.length) { return; } - var l = array.length; + var l = array!.length; while (length + size > l) { l = (l * 1.5).ceil(); } - var newArray = Uint8List.fromList(array); + var newArray = Uint8List.fromList(array!); array = newArray; } @@ -72,7 +70,7 @@ class SerialBuffer { /// Return data with excess storage trimmed away */ Uint8List asUint8List() { - return Uint8List.view(array.buffer, array.offsetInBytes, length); + return Uint8List.view(array!.buffer, array!.offsetInBytes, length); } /// Append bytes */ @@ -81,7 +79,7 @@ class SerialBuffer { // var t = Uint8List.view(array.buffer,0,array.length + v.length); // t.replaceRange(array.length, array.length + v.length - 1, v); // array = t; - var t = array.toList(); + var t = array!.toList(); t.addAll(v); array = Uint8List.fromList(t); length += v.length; @@ -95,7 +93,7 @@ class SerialBuffer { /// Get a single byte */ int get() { if (readPos < length) { - return array[readPos++]; + return array![readPos++]; } throw 'Read past end of buffer'; } @@ -113,8 +111,7 @@ class SerialBuffer { if (readPos + len > length) { throw 'Read past end of buffer'; } - var result = - Uint8List.view(array.buffer, array.offsetInBytes + readPos, len); + var result = Uint8List.view(array!.buffer, array!.offsetInBytes + readPos, len); readPos += len; return result; } @@ -134,12 +131,7 @@ class SerialBuffer { /// Append a `uint32` */ void pushUint32(int v) { - var t = [ - (v >> 0) & 0xff, - (v >> 8) & 0xff, - (v >> 16) & 0xff, - (v >> 24) & 0xff - ]; + var t = [(v >> 0) & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff, (v >> 24) & 0xff]; push(t); } @@ -364,9 +356,7 @@ class SerialBuffer { ++pos; } var foundDigit = false; - while (pos < s.length && - s.codeUnitAt(pos) >= '0'.codeUnitAt(0) && - s.codeUnitAt(pos) <= '9'.codeUnitAt(0)) { + while (pos < s.length && s.codeUnitAt(pos) >= '0'.codeUnitAt(0) && s.codeUnitAt(pos) <= '9'.codeUnitAt(0)) { foundDigit = true; amount += s[pos]; ++pos; @@ -376,9 +366,7 @@ class SerialBuffer { } if (s[pos] == '.') { ++pos; - while (pos < s.length && - s.codeUnitAt(pos) >= '0'.codeUnitAt(0) && - s.codeUnitAt(pos) <= '9'.codeUnitAt(0)) { + while (pos < s.length && s.codeUnitAt(pos) >= '0'.codeUnitAt(0) && s.codeUnitAt(pos) <= '9'.codeUnitAt(0)) { amount += s[pos]; ++precision; ++pos; @@ -395,9 +383,7 @@ class SerialBuffer { var sym = getSymbol(); var s = numeric.signedBinaryToDecimal(amount, minDigits: sym.precision + 1); if (sym.precision != 0) { - s = s.substring(0, s.length - sym.precision) + - '.' + - s.substring(s.length - sym.precision); + s = s.substring(0, s.length - sym.precision) + '.' + s.substring(s.length - sym.precision); } return s + ' ' + sym.name; } @@ -413,8 +399,7 @@ class SerialBuffer { String getPublicKey() { var type = get(); var data = getUint8List(numeric.publicKeyDataSize); - return numeric - .publicKeyToString(numeric.IKey(type as numeric.KeyType, data)); + return numeric.publicKeyToString(numeric.IKey(type as numeric.KeyType, data)); } /// Append a private key */ @@ -428,8 +413,7 @@ class SerialBuffer { String getPrivateKey() { var type = get(); var data = getUint8List(numeric.privateKeyDataSize); - return numeric - .privateKeyToString(numeric.IKey(type as numeric.KeyType, data)); + return numeric.privateKeyToString(numeric.IKey(type as numeric.KeyType, data)); } /// Append a signature */ @@ -443,25 +427,34 @@ class SerialBuffer { String getSignature() { var type = get(); var data = getUint8List(numeric.signatureDataSize); - return numeric - .signatureToString(numeric.IKey(type as numeric.KeyType, data)); + return numeric.signatureToString(numeric.IKey(type as numeric.KeyType, data)); } } // SerialBuffer -Type createType( - {String name = '', - String aliasOfName = "", - Type arrayOf, - Type optionalOf, - void Function(Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) - serialize, - Object Function(Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) - deserialize, - String baseName: "", - List fields: const [], - Type extensionOf}) { +Type createType({ + String name = '', + String aliasOfName = "", + Type? arrayOf, + Type? optionalOf, + void Function( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + })? + serialize, + dynamic Function( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + })? + deserialize, + String baseName: "", + List fields: const [], + Type? extensionOf, +}) { var t = Type( aliasOfName: aliasOfName, name: name, @@ -556,17 +549,12 @@ String timePointSecToDate(int sec) { /// Convert date in ISO format to `block_timestamp_type` (half-seconds since a different epoch) */ int dateToBlockTimestamp(String date) { - return ((checkDateParse(date + 'Z') - .subtract(Duration(milliseconds: 946684800000))) - .millisecondsSinceEpoch / - 500) - .round(); + return ((checkDateParse(date + 'Z').subtract(Duration(milliseconds: 946684800000))).millisecondsSinceEpoch / 500).round(); } /// Convert `block_timestamp_type` (half-seconds since a different epoch) to to date in ISO format */ String blockTimestampToDate(int slot) { - var s = (DateTime.fromMillisecondsSinceEpoch(slot * 500 + 946684800000)) - .toIso8601String(); + var s = (DateTime.fromMillisecondsSinceEpoch(slot * 500 + 946684800000)).toIso8601String(); return s.substring(0, s.length - 1); } @@ -590,13 +578,11 @@ bool supportedAbiVersion(String version) { return version.startsWith('eosio::abi/1.'); } -void serializeStruct(Type self, SerialBuffer buffer, Object data, - {SerializerState state, allowExtensions = true}) { +void serializeStruct(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); // try { if (self.base != null) { - self.base.serialize(self.base, buffer, data, - state: state, allowExtensions: allowExtensions); + self.base!.serialize?.call(self.base, buffer, data, state: state, allowExtensions: allowExtensions); } Map dy = data as dynamic; for (var field in self.fields) { @@ -604,21 +590,12 @@ void serializeStruct(Type self, SerialBuffer buffer, Object data, if (state.skippedBinaryExtension) { throw 'unexpected ' + self.name + '.' + field.name; } - field.type.serialize(field.type, buffer, dy[field.name], - state: state, - allowExtensions: - allowExtensions && field == self.fields[self.fields.length - 1]); + field.type!.serialize?.call(field.type, buffer, dy[field.name], state: state, allowExtensions: allowExtensions && field == self.fields[self.fields.length - 1]); } else { - if (allowExtensions && field.type.extensionOf != null) { + if (allowExtensions && field.type!.extensionOf != null) { state.skippedBinaryExtension = true; } else { - throw 'missing ' + - self.name + - '.' + - field.name + - ' (type=' + - field.type.name + - ')'; + throw 'missing ' + self.name + '.' + field.name + ' (type=' + field.type!.name + ')'; } } } @@ -627,25 +604,20 @@ void serializeStruct(Type self, SerialBuffer buffer, Object data, // } } -deserializeStruct(Type self, SerialBuffer buffer, - {SerializerState state, allowExtensions = true}) { +Object deserializeStruct(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); try { var result; if (self.base != null) { - result = self.base.deserialize(self.base, buffer, - state: state, allowExtensions: allowExtensions); + result = self.base!.deserialize?.call(self.base, buffer, state: state, allowExtensions: allowExtensions); } else { result = {}; } for (var field in self.fields) { - if (allowExtensions && - field.type.extensionOf != null && - !buffer.haveReadData()) { + if (allowExtensions && field.type!.extensionOf != null && !buffer.haveReadData()) { state.skippedBinaryExtension = true; } else { - result[field.name] = field.type.deserialize(field.type, buffer, - state: state, allowExtensions: allowExtensions); + result[field.name] = field.type!.deserialize?.call(field.type, buffer, state: state, allowExtensions: allowExtensions); } } return result; @@ -659,193 +631,347 @@ Map createInitialTypes() { var result = { "bool": createType( name: 'bool', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.push([data ? 1 : 0]); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.get(); }, ), "uint8": createType( name: 'uint8', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.push([checkRange(data, (data as int) & 0xff)]); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.get(); }, ), "int8": createType( name: 'int8', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { - buffer.push([checkRange((data as int), (data as int) << 24 >> 24)]); + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { + buffer.push([checkRange(data, (data as int) << 24 >> 24)]); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.get() << 24 >> 24; }, ), "uint16": createType( name: 'uint16', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint16(checkRange(data, (data as int) & 0xffff)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getUint16(); }, ), "int16": createType( name: 'int16', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint16(checkRange(data, (data as int) << 16 >> 16)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getUint16() << 16 >> 16; }, ), "uint32": createType( name: 'uint32', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint32(checkRange(data, (data as int) >> 0)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getUint32(); }, ), "uint64": createType( name: 'uint64', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { - buffer.pushArray(numeric.decimalToBinary(8, '' + data.toString())); + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { + buffer.pushArray(numeric.decimalToBinary(8, '' + data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return numeric.binaryToDecimal(buffer.getUint8List(8)); }, ), "int64": createType( name: 'int64', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { - buffer - .pushArray(numeric.signedDecimalToBinary(8, '' + data.toString())); + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { + buffer.pushArray(numeric.signedDecimalToBinary(8, '' + data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return numeric.signedBinaryToDecimal(buffer.getUint8List(8)); }, ), "int32": createType( name: 'int32', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { - buffer.pushUint32(checkRange(data, (data as int) | 0)); + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { + buffer.pushUint32(checkRange(data as int, data | 0)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getUint32() | 0; }, ), "varuint32": createType( name: 'varuint32', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushVaruint32(checkRange(data, (data as int) >> 0)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getVaruint32(); }, ), "varint32": createType( name: 'varint32', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushVarint32(checkRange(data, data == null ? 0 : data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getVarint32(); }, ), "uint128": createType( name: 'uint128', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushArray(numeric.decimalToBinary(16, '' + data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return numeric.binaryToDecimal(buffer.getUint8List(16)); }, ), "int128": createType( name: 'int128', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushArray(numeric.signedDecimalToBinary(16, '' + data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return numeric.signedBinaryToDecimal(buffer.getUint8List(16)); }, ), "float32": createType( name: 'float32', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushFloat32(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getFloat32(); }, ), "float64": createType( name: 'float64', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushFloat64(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getFloat64(); }, ), "float128": createType( name: 'float128', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint8ListChecked(hexToUint8List(data), 16); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return arrayToHex(buffer.getUint8List(16)); }, ), "bytes": createType( name: 'bytes', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { - if (data is Uint8List || data is List) { - buffer.pushBytes(data); + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { + if (data is Uint8List) { + buffer.pushBytes(data.toList()); + } else if (data is List) { + buffer.pushBytes(data.cast()); } else { buffer.pushBytes(hexToUint8List(data)); } }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { if (state != null && state.options.bytesAsUint8List) { return buffer.getBytes(); } else { @@ -855,156 +981,282 @@ Map createInitialTypes() { ), "string": createType( name: 'string', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushString(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getString(); }, ), "name": createType( name: 'name', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushName(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getName(); }, ), "time_point": createType( name: 'time_point', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushNumberAsUint64(dateToTimePoint(data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return timePointToDate(buffer.getUint64AsNumber()); }, ), "time_point_sec": createType( name: 'time_point_sec', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { var date = dateToTimePointSec(data); buffer.pushUint32(date); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return timePointSecToDate(buffer.getUint32()); }, ), "block_timestamp_type": createType( name: 'block_timestamp_type', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint32(dateToBlockTimestamp(data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return blockTimestampToDate(buffer.getUint32()); }, ), "symbol_code": createType( name: 'symbol_code', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushSymbolCode(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getSymbolCode(); }, ), "symbol": createType( name: 'symbol', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushSymbol(stringToSymbol(data)); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return symbolToString(buffer.getSymbol()); }, ), "asset": createType( name: 'asset', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushAsset(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getAsset(); }, ), "checksum160": createType( name: 'checksum160', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint8ListChecked(hexToUint8List(data), 20); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return arrayToHex(buffer.getUint8List(20)); }, ), "checksum256": createType( name: 'checksum256', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint8ListChecked(hexToUint8List(data), 32); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return arrayToHex(buffer.getUint8List(32)); }, ), "checksum512": createType( name: 'checksum512', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushUint8ListChecked(hexToUint8List(data), 64); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return arrayToHex(buffer.getUint8List(64)); }, ), "public_key": createType( name: 'public_key', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushPublicKey(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getPublicKey(); }, ), "private_key": createType( name: 'private_key', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushPrivateKey(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getPrivateKey(); }, ), "signature": createType( name: 'signature', - serialize: (Type self, SerialBuffer buffer, Object data, - {SerializerState state, bool allowExtensions}) { + serialize: ( + Type self, + SerialBuffer buffer, + dynamic data, { + SerializerState? state, + required bool allowExtensions, + }) { buffer.pushSignature(data); }, - deserialize: (Type self, SerialBuffer buffer, - {SerializerState state, bool allowExtensions}) { + deserialize: ( + Type self, + SerialBuffer buffer, { + SerializerState? state, + required bool allowExtensions, + }) { return buffer.getSignature(); }, ), @@ -1024,97 +1276,76 @@ Map createInitialTypes() { return result; } // createInitialTypes() -serializeVariant(Type self, SerialBuffer buffer, Object data, - {SerializerState state, allowExtensions = true}) { +serializeVariant(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); - if (!(data is List) || - (data as List).length != 2 || - !((data as List)[0] is String)) { + if (!(data is List) || data.length != 2 || !(data[0] is String)) { throw 'expected variant: ["type", value]'; } - var a = ((data as List)[0]) as String; - var b = ((data as List)[1]) as Object; + var a = (data[0]) as String; + var b = (data[1]) as Object; var i = self.fields.indexWhere((field) => field.name == a); if (i < 0) { throw 'type "$b" is not valid for variant'; } buffer.pushVaruint32(i); - self.fields[i].type.serialize(self.fields[i].type, buffer, b, - state: state, allowExtensions: allowExtensions); + self.fields[i].type!.serialize?.call(self.fields[i].type, buffer, b, state: state, allowExtensions: allowExtensions); } -deserializeVariant(Type self, SerialBuffer buffer, - {SerializerState state, allowExtensions = true}) { +deserializeVariant(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); var i = buffer.getVaruint32(); if (i >= self.fields.length) { throw 'type index $i is not valid for variant'; } var field = self.fields[i]; - return [ - field.name, - field.type.deserialize(field.type, buffer, - state: state, allowExtensions: allowExtensions) - ]; + return [field.name, field.type!.deserialize?.call(field.type, buffer, state: state, allowExtensions: allowExtensions)]; } -serializeArray(Type self, SerialBuffer buffer, Object data, - {SerializerState state, allowExtensions = true}) { +serializeArray(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); buffer.pushVaruint32((data as List).length); for (var item in data) { - self.arrayOf.serialize(self.arrayOf, buffer, item, - state: state, allowExtensions: false); + self.arrayOf!.serialize?.call(self.arrayOf, buffer, item, state: state, allowExtensions: false); } } -deserializeArray(Type self, SerialBuffer buffer, - {SerializerState state, allowExtensions = true}) { +deserializeArray(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); var len = buffer.getVaruint32(); var result = []; for (var i = 0; i < len; ++i) { - result.add(self.arrayOf.deserialize(self.arrayOf, buffer, - state: state, allowExtensions: false)); + result.add(self.arrayOf!.deserialize?.call(self.arrayOf, buffer, state: state, allowExtensions: false)); } return result; } -serializeOptional(Type self, SerialBuffer buffer, Object data, - {SerializerState state, allowExtensions = true}) { +serializeOptional(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); if (data == null) { buffer.push([0]); } else { buffer.push([1]); - self.optionalOf.serialize(self.optionalOf, buffer, data, - state: state, allowExtensions: allowExtensions); + self.optionalOf!.serialize?.call(self.optionalOf, buffer, data, state: state, allowExtensions: allowExtensions); } } -deserializeOptional(Type self, SerialBuffer buffer, - {SerializerState state, allowExtensions = true}) { +deserializeOptional(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); if (buffer.get() != 0) { - return self.optionalOf.deserialize(self.optionalOf, buffer, - state: state, allowExtensions: allowExtensions); + return self.optionalOf!.deserialize?.call(self.optionalOf, buffer, state: state, allowExtensions: allowExtensions); } else { return null; } } -serializeExtension(Type self, SerialBuffer buffer, Object data, - {SerializerState state, allowExtensions = true}) { +serializeExtension(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); - self.extensionOf.serialize(self.extensionOf, buffer, data, - state: state, allowExtensions: allowExtensions); + self.extensionOf!.serialize?.call(self.extensionOf, buffer, data, state: state, allowExtensions: allowExtensions); } -deserializeExtension(Type self, SerialBuffer buffer, - {SerializerState state, allowExtensions = true}) { +deserializeExtension(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) { if (state == null) state = SerializerState(); - return self.extensionOf.deserialize(self.extensionOf, buffer, - state: state, allowExtensions: allowExtensions); + return self.extensionOf!.deserialize?.call(self.extensionOf, buffer, state: state, allowExtensions: allowExtensions); } /// Get type from `types` */ @@ -1160,31 +1391,25 @@ Type getType(Map types, String name) { Map getTypesFromAbi(Map initialTypes, Abi abi) { var types = Map.from(initialTypes).cast(); if (abi.types != null) { - for (var item in abi.types) { - types[item.new_type_name] = - createType(name: item.new_type_name, aliasOfName: item.type); + for (var item in abi.types!) { + types[item.new_type_name] = createType(name: item.new_type_name, aliasOfName: item.type); } } if (abi.structs != null) { - for (var str in abi.structs) { - types[str.name] = createType( - name: str.name, - baseName: str.base, - fields: str.fields - ?.map((item) => - Field(name: item.name, typeName: item.type, type: null)) - ?.toList(), + for (var str in abi.structs!) { + types[str.name!] = createType( + name: str.name!, + baseName: str.base ?? '', + fields: str.fields?.map((item) => Field(name: item.name, typeName: item.type, type: null)).toList() ?? [], serialize: serializeStruct, deserialize: deserializeStruct); } } if (abi.variants != null) { - for (var v in abi.variants) { - types[v.name] = createType( - name: v.name, - fields: v.types - ?.map((s) => Field(name: s, typeName: s, type: null)) - ?.toList(), + for (var v in abi.variants!) { + types[v.name!] = createType( + name: v.name!, + fields: v.types?.map((s) => Field(name: s, typeName: s, type: null)).toList() ?? [], serialize: serializeVariant, deserialize: deserializeVariant, ); diff --git a/pubspec.yaml b/pubspec.yaml index 2ae0735..dd7d732 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,16 +4,16 @@ version: 0.4.7 homepage: https://github.com/primes-network/eosdart environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: - http: ^0.12.0+4 - json_annotation: ^3.0.1 - pointycastle: ^1.0.2 - eosdart_ecc: ^0.4.3 + http: ^0.13.4 + json_annotation: ^4.3.0 + pointycastle: ^3.3.5 + eosdart_ecc: ^0.4.4 # path: ^1.4.1 dev_dependencies: - test: ^1.0.0 - build_runner: ^1.7.4 - json_serializable: ^3.2.3 + test: ^1.19.2 + build_runner: ^2.1.4 + json_serializable: ^6.0.1 diff --git a/test/eosdart_test.dart b/test/eosdart_test.dart index 6487202..41c5b22 100644 --- a/test/eosdart_test.dart +++ b/test/eosdart_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { group('EOS Client', () { - EOSClient client; + late EOSClient client; setUp(() { client = EOSClient('https://eos.greymass.com', 'v1'); @@ -11,7 +11,7 @@ void main() { test('Get Info', () { client.getInfo().then((NodeInfo nodeInfo) { - expect(nodeInfo.headBlockNum > 0, isTrue); + expect(nodeInfo.headBlockNum! > 0, isTrue); }); }); @@ -35,7 +35,7 @@ void main() { test('Get Raw code and Abi', () { client.getRawCodeAndAbi('eosio.token').then((AbiResp abi) { expect(abi.accountName, equals('eosio.token')); - expect(abi.wasm.length > 0, isTrue); + expect(abi.wasm!.length > 0, isTrue); expect(abi.abi, isNotNull); }); }); @@ -47,14 +47,14 @@ void main() { expect(block.confirmed, 0); expect(block.transactionMRoot, '8fb685526d58dfabd05989b45b8576197acc1be59d753bb396386d5d718f9fa9'); - expect(block.transactions.length > 10, isTrue); + expect(block.transactions!.length > 10, isTrue); }); }); test('Get Account', () { client.getAccount('eosio.stake').then((Account account) { expect(account.accountName, equals('eosio.stake')); - expect(account.coreLiquidBalance.amount > 0, isTrue); + expect(account.coreLiquidBalance!.amount! > 0, isTrue); }); }); @@ -63,7 +63,7 @@ void main() { .getCurrencyBalance('parslseed123', 'newdexpocket', 'SEED') .then((List tokens) { expect(tokens.length > 0, isTrue); - expect(tokens[0].amount > 0, isTrue); + expect(tokens[0].amount! > 0, isTrue); expect(tokens[0].currency, 'SEED'); }); }); @@ -74,12 +74,12 @@ void main() { '8ca0fea82370a2dbbf2c4bd1026bf9fd98a57685bee3672c4ddbbc9be21de984') .then((TransactionBlock transaction) { expect(transaction.blockNum, 43743575); - expect(transaction.trx.receipt.cpuUsageUs, 132); - expect(transaction.trx.receipt.netUsageWords, 0); - expect(transaction.traces.length, 2); - expect(transaction.traces[0].receipt.receiver, 'trustdicelog'); - expect(transaction.traces[0].inlineTraces.length, 1); - expect(transaction.traces[0].inlineTraces[0].receipt.receiver, + expect(transaction.trx!.receipt!.cpuUsageUs, 132); + expect(transaction.trx!.receipt!.netUsageWords, 0); + expect(transaction.traces!.length, 2); + expect(transaction.traces![0].receipt!.receiver, 'trustdicelog'); + expect(transaction.traces![0].inlineTraces!.length, 1); + expect(transaction.traces![0].inlineTraces![0].receipt!.receiver, 'ge4tcnrxgyge'); }); }); diff --git a/test/models/abi_test.dart b/test/models/abi_test.dart index a988f24..130a7f3 100644 --- a/test/models/abi_test.dart +++ b/test/models/abi_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String abiStr; + late String abiStr; setUp(() { abiStr = File('./test/models/abi_test_data.json').readAsStringSync(); @@ -21,7 +21,7 @@ void main() { '01bd013c4f8be142b9cadf511f007c6ac201c068d529f01ed5661803c575befa'); expect(abi.abiHash, 'f8f677996a8ca68388bc41cf55e727949c161b624a47e497e3b2f71a0e635dad'); - print(abi.abi.actions); + print(abi.abi!.actions); // expect(abi.abi, // 'DmVvc2lvOjphYmkvMS4wAQxhY2NvdW50X25hbWUEbmFtZQcIdHJhbnNmZXIABARmcm9tDGFjY291bnRfbmFtZQJ0bwxhY2NvdW50X25hbWUIcXVhbnRpdHkFYXNzZXQEbWVtbwZzdHJpbmcGY3JlYXRlAAIGaXNzdWVyDGFjY291bnRfbmFtZQ5tYXhpbXVtX3N1cHBseQVhc3NldAVpc3N1ZQADAnRvDGFjY291bnRfbmFtZQhxdWFudGl0eQVhc3NldARtZW1vBnN0cmluZwZyZXRpcmUAAghxdWFudGl0eQVhc3NldARtZW1vBnN0cmluZwVjbG9zZQACBW93bmVyDGFjY291bnRfbmFtZQZzeW1ib2wGc3ltYm9sB2FjY291bnQAAQdiYWxhbmNlBWFzc2V0DmN1cnJlbmN5X3N0YXRzAAMGc3VwcGx5BWFzc2V0Cm1heF9zdXBwbHkFYXNzZXQGaXNzdWVyDGFjY291bnRfbmFtZQUAAABXLTzNzQh0cmFuc2ZlcucFIyMgVHJhbnNmZXIgVGVybXMgJiBDb25kaXRpb25zCgpJLCB7e2Zyb219fSwgY2VydGlmeSB0aGUgZm9sbG93aW5nIHRvIGJlIHRydWUgdG8gdGhlIGJlc3Qgb2YgbXkga25vd2xlZGdlOgoKMS4gSSBjZXJ0aWZ5IHRoYXQge3txdWFudGl0eX19IGlzIG5vdCB0aGUgcHJvY2VlZHMgb2YgZnJhdWR1bGVudCBvciB2aW9sZW50IGFjdGl2aXRpZXMuCjIuIEkgY2VydGlmeSB0aGF0LCB0byB0aGUgYmVzdCBvZiBteSBrbm93bGVkZ2UsIHt7dG99fSBpcyBub3Qgc3VwcG9ydGluZyBpbml0aWF0aW9uIG9mIHZpb2xlbmNlIGFnYWluc3Qgb3RoZXJzLgozLiBJIGhhdmUgZGlzY2xvc2VkIGFueSBjb250cmFjdHVhbCB0ZXJtcyAmIGNvbmRpdGlvbnMgd2l0aCByZXNwZWN0IHRvIHt7cXVhbnRpdHl9fSB0byB7e3RvfX0uCgpJIHVuZGVyc3RhbmQgdGhhdCBmdW5kcyB0cmFuc2ZlcnMgYXJlIG5vdCByZXZlcnNpYmxlIGFmdGVyIHRoZSB7e3RyYW5zYWN0aW9uLmRlbGF5fX0gc2Vjb25kcyBvciBvdGhlciBkZWxheSBhcyBjb25maWd1cmVkIGJ5IHt7ZnJvbX19J3MgcGVybWlzc2lvbnMuCgpJZiB0aGlzIGFjdGlvbiBmYWlscyB0byBiZSBpcnJldmVyc2libHkgY29uZmlybWVkIGFmdGVyIHJlY2VpdmluZyBnb29kcyBvciBzZXJ2aWNlcyBmcm9tICd7e3RvfX0nLCBJIGFncmVlIHRvIGVpdGhlciByZXR1cm4gdGhlIGdvb2RzIG9yIHNlcnZpY2VzIG9yIHJlc2VuZCB7e3F1YW50aXR5fX0gaW4gYSB0aW1lbHkgbWFubmVyLgoAAAAAAKUxdgVpc3N1ZQAAAAAAqGzURQZjcmVhdGUAAAAAAKjrsroGcmV0aXJlAAAAAAAAhWlEBWNsb3NlAAIAAAA4T00RMgNpNjQBCGN1cnJlbmN5AQZ1aW50NjQHYWNjb3VudAAAAAAAkE3GA2k2NAEIY3VycmVuY3kBBnVpbnQ2NA5jdXJyZW5jeV9zdGF0cwAAAA==='); expect(abi.wasm, isEmpty); diff --git a/test/models/account_test.dart b/test/models/account_test.dart index 6a1c51a..74a1d73 100644 --- a/test/models/account_test.dart +++ b/test/models/account_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String accountStr; + late String accountStr; setUp(() { accountStr = @@ -23,32 +23,32 @@ void main() { expect(account.privileged, false); expect(account.lastCodeUpdate, DateTime(1970, 1, 1)); expect(account.created, DateTime(2018, 11, 14, 6, 58)); - expect(account.coreLiquidBalance.amount, 49254569.1575); - expect(account.coreLiquidBalance.currency, 'EOS'); + expect(account.coreLiquidBalance!.amount, 49254569.1575); + expect(account.coreLiquidBalance!.currency, 'EOS'); expect(account.ramQuota, 20683); expect(account.netWeight, 1000500); expect(account.cpuWeight, 1001500); - expect(account.netLimit.used, 129); - expect(account.netLimit.available, 8344411498); - expect(account.netLimit.max, 8344545345); + expect(account.netLimit!.used, 129); + expect(account.netLimit!.available, 8344411498); + expect(account.netLimit!.max, 8344545345); expect(account.ramUsage, 3686); expect(account.permissions, isList); - expect(account.permissions.length, 2); - expect(account.permissions[0].permName, 'active'); - expect(account.permissions[0].requiredAuth.threshold, 1); - expect(account.permissions[0].requiredAuth.keys, isList); - expect(account.permissions[0].requiredAuth.keys.length, 1); - expect(account.permissions[0].requiredAuth.keys[0].key, + expect(account.permissions!.length, 2); + expect(account.permissions![0].permName, 'active'); + expect(account.permissions![0].requiredAuth!.threshold, 1); + expect(account.permissions![0].requiredAuth!.keys, isList); + expect(account.permissions![0].requiredAuth!.keys!.length, 1); + expect(account.permissions![0].requiredAuth!.keys![0].key, 'EOS5GZ7R4BsApfxKcSbHeBEeFavsu9b75ooXM6pf5fo5G4ZbSWBMX'); - expect(account.permissions[0].requiredAuth.keys[0].weight, 1); - expect(account.totalResources.owner, 'binancecold1'); - expect(account.totalResources.netWeight.amount, 100.05); - expect(account.totalResources.netWeight.currency, 'EOS'); - expect(account.selfDelegatedBandwidth.from, 'binancecold1'); - expect(account.selfDelegatedBandwidth.cpuWeight.amount, 100.0); - expect(account.refundRequest.owner, 'binancecold1'); - expect(account.refundRequest.netAmount.amount, 35.6); - expect(account.voterInfo.staked, 2000000); + expect(account.permissions![0].requiredAuth!.keys![0].weight, 1); + expect(account.totalResources!.owner, 'binancecold1'); + expect(account.totalResources!.netWeight!.amount, 100.05); + expect(account.totalResources!.netWeight!.currency, 'EOS'); + expect(account.selfDelegatedBandwidth!.from, 'binancecold1'); + expect(account.selfDelegatedBandwidth!.cpuWeight!.amount, 100.0); + expect(account.refundRequest!.owner, 'binancecold1'); + expect(account.refundRequest!.netAmount!.amount, 35.6); + expect(account.voterInfo!.staked, 2000000); }); }); } diff --git a/test/models/action_test.dart b/test/models/action_test.dart index a9581f1..abb0b42 100644 --- a/test/models/action_test.dart +++ b/test/models/action_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String actionStr; + late String actionStr; setUp(() { actionStr = @@ -19,11 +19,11 @@ void main() { expect(action.globalActionSeq, 4587073327); expect(action.accountActionSeq, 165); - expect(action.actionTrace.receipt.receiveSequence, 159); - expect(action.actionTrace.action.account, 'zosdiscounts'); - expect(action.actionTrace.action.authorization[0].actor, 'airdropsdac3'); - expect(action.actionTrace.contextFree, false); - expect(action.actionTrace.blockNum, 40066073); + expect(action.actionTrace!.receipt!.receiveSequence, 159); + expect(action.actionTrace!.action!.account, 'zosdiscounts'); + expect(action.actionTrace!.action!.authorization![0].actor, 'airdropsdac3'); + expect(action.actionTrace!.contextFree, false); + expect(action.actionTrace!.blockNum, 40066073); }); }); } diff --git a/test/models/block_header_state_test.dart b/test/models/block_header_state_test.dart index 751d97f..92300a8 100644 --- a/test/models/block_header_state_test.dart +++ b/test/models/block_header_state_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String stateStr; + late String stateStr; setUp(() { stateStr = File('./test/models/block_header_state_test_data.json') @@ -20,35 +20,35 @@ void main() { expect(headerState.id, '02a5e504b8d20cd2b3c08ba623dfbb3f98b34a7e8c6cbba81e7b4e25382def4d'); expect(headerState.blockNum, 44426500); - expect(headerState.header.timestamp, + expect(headerState.header!.timestamp, DateTime(2019, 02, 24, 07, 55, 01, 500)); - expect(headerState.header.producer, 'starteosiobp'); - expect(headerState.header.confirmed, 0); - expect(headerState.header.previous, + expect(headerState.header!.producer, 'starteosiobp'); + expect(headerState.header!.confirmed, 0); + expect(headerState.header!.previous, '02a5e503fa636e7a35d9fa04df9c2ab7860864acff3d835b6c1ec1259b7867e2'); - expect(headerState.header.transactionMRoot, + expect(headerState.header!.transactionMRoot, '1553f3e25495670bfd8879b0e972575051d012cb2b7793db9d3ebeec126909b6'); - expect(headerState.header.actionMRoot, + expect(headerState.header!.actionMRoot, '1351f42a98c3877fd406c8ab0e0c45c43b2b8cd2ea1bc1a325353cc8efc76aa4'); expect(headerState.dposProposedIrreversibleBlocknum, 44426340); expect(headerState.dposIrreversibleBlocknum, 44426172); expect(headerState.pendingScheduleLibNum, 44118384); - expect(headerState.pendingSchedule.version, 703); - expect(headerState.activeSchedule.version, 703); - expect(headerState.activeSchedule.producers.length > 10, isTrue); + expect(headerState.pendingSchedule!.version, 703); + expect(headerState.activeSchedule!.version, 703); + expect(headerState.activeSchedule!.producers!.length > 10, isTrue); expect( - headerState.activeSchedule.producers[0].producerName, 'atticlabeosb'); - expect(headerState.activeSchedule.producers[0].blockSigningKey, + headerState.activeSchedule!.producers![0].producerName, 'atticlabeosb'); + expect(headerState.activeSchedule!.producers![0].blockSigningKey, 'EOS7PfA3A4UdfMu2wKbuXdbHn8EWAxbMnFoFWui4X2zsr2oPwdQJP'); - expect(headerState.blockrootMerkle.activeNodes.length > 10, isTrue); - expect(headerState.blockrootMerkle.activeNodes[0], + expect(headerState.blockrootMerkle!.activeNodes!.length > 10, isTrue); + expect(headerState.blockrootMerkle!.activeNodes![0], '02a5e503fa636e7a35d9fa04df9c2ab7860864acff3d835b6c1ec1259b7867e2'); - expect(headerState.blockrootMerkle.nodeCount, 44426499); - expect(headerState.producerToLastProduced.length > 10, isTrue); - expect(headerState.producerToLastImpliedIrb.length > 10, isTrue); + expect(headerState.blockrootMerkle!.nodeCount, 44426499); + expect(headerState.producerToLastProduced!.length > 10, isTrue); + expect(headerState.producerToLastImpliedIrb!.length > 10, isTrue); expect(headerState.blockSigningKey, 'EOS4wZZXm994byKANLuwHD6tV3R3Mu3ktc41aSVXCBaGnXJZJ4pwF'); - expect(headerState.confirmCount.length > 10, isTrue); + expect(headerState.confirmCount!.length > 10, isTrue); }); }); } diff --git a/test/models/block_test.dart b/test/models/block_test.dart index 4d743a7..9d37a0d 100644 --- a/test/models/block_test.dart +++ b/test/models/block_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String blockStr; + late String blockStr; setUp(() { blockStr = File('./test/models/block_test_data.json').readAsStringSync(); @@ -21,10 +21,10 @@ void main() { expect(block.id, '02a07f3e8e112558b58e7027ae614336cf77b45980df9693219f77e7a2d0349e'); expect(block.refBlockPrefix, 661687989); - expect(block.transactions.length > 10, isTrue); - expect(block.transactions[0].status, 'executed'); - expect(block.transactions[0].cpuUsageUs, 444); - expect(block.transactions[0].netUsageWords, 0); + expect(block.transactions!.length > 10, isTrue); + expect(block.transactions![0].status, 'executed'); + expect(block.transactions![0].cpuUsageUs, 444); + expect(block.transactions![0].netUsageWords, 0); }); }); } diff --git a/test/models/node_info_test.dart b/test/models/node_info_test.dart index 4809c31..554ea0e 100644 --- a/test/models/node_info_test.dart +++ b/test/models/node_info_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('EOS Model', () { - String nodeInfoStr; + late String nodeInfoStr; setUp(() { nodeInfoStr = diff --git a/test/models/transaction_test.dart b/test/models/transaction_test.dart index 5840f3f..aa1dc95 100644 --- a/test/models/transaction_test.dart +++ b/test/models/transaction_test.dart @@ -14,17 +14,17 @@ void main() { expect(transaction.id, '58d0e48048a03cff57af924ab606726793c31607a501112b088896fc0a0f70ec'); - expect(transaction.trx.receipt.status, 'executed'); - expect(transaction.trx.receipt.cpuUsageUs, 303); - expect(transaction.trx.receipt.netUsageWords, 13); + expect(transaction.trx!.receipt!.status, 'executed'); + expect(transaction.trx!.receipt!.cpuUsageUs, 303); + expect(transaction.trx!.receipt!.netUsageWords, 13); expect(transaction.blockTime, DateTime(2019, 2, 22, 6, 45, 7)); expect(transaction.blockNum, 44072766); expect(transaction.lastIrreversibleBlock, 44075018); - expect(transaction.traces.length, 1); - expect(transaction.traces[0].receipt.receiver, 'pretonarts11'); - expect(transaction.traces[0].action.account, 'pretonarts11'); - expect(transaction.traces[0].action.name, 'chooseserver'); - expect(transaction.traces[0].producerBlockId, + expect(transaction.traces!.length, 1); + expect(transaction.traces![0].receipt!.receiver, 'pretonarts11'); + expect(transaction.traces![0].action!.account, 'pretonarts11'); + expect(transaction.traces![0].action!.name, 'chooseserver'); + expect(transaction.traces![0].producerBlockId, '02a07f3e8e112558b58e7027ae614336cf77b45980df9693219f77e7a2d0349e'); }); @@ -36,17 +36,17 @@ void main() { expect(transaction.id, '83875faeb054ba20b20f392418e3a0002c4bb1c36cc4e3fde15cbd0963da8a15'); - expect(transaction.trx.receipt.status, 'executed'); - expect(transaction.trx.receipt.cpuUsageUs, 444); - expect(transaction.trx.receipt.netUsageWords, 0); + expect(transaction.trx!.receipt!.status, 'executed'); + expect(transaction.trx!.receipt!.cpuUsageUs, 444); + expect(transaction.trx!.receipt!.netUsageWords, 0); expect(transaction.blockTime, DateTime(2019, 2, 22, 6, 45, 7)); expect(transaction.blockNum, 44072766); expect(transaction.lastIrreversibleBlock, 44075150); - expect(transaction.traces.length, 2); - expect(transaction.traces[0].receipt.receiver, 'xuxxxxxxxxxx'); - expect(transaction.traces[0].action.account, 'eosio.token'); - expect(transaction.traces[0].action.name, 'transfer'); - expect(transaction.traces[0].producerBlockId, + expect(transaction.traces!.length, 2); + expect(transaction.traces![0].receipt!.receiver, 'xuxxxxxxxxxx'); + expect(transaction.traces![0].action!.account, 'eosio.token'); + expect(transaction.traces![0].action!.name, 'transfer'); + expect(transaction.traces![0].producerBlockId, '02a07f3e8e112558b58e7027ae614336cf77b45980df9693219f77e7a2d0349e'); }); @@ -59,21 +59,21 @@ void main() { expect(transaction.id, '91b55122107079cb4eafb165511bac77b8a790c3d4008c5f7cd7cfa1236c0876'); - expect(transaction.processed.blockNum, 729864); - expect(transaction.processed.blockTime, + expect(transaction.processed!.blockNum, 729864); + expect(transaction.processed!.blockTime, DateTime(2019, 11, 14, 8, 10, 37, 500)); - expect(transaction.processed.producerBlockId, null); - expect(transaction.processed.receipt.status, 'executed'); - expect(transaction.processed.receipt.cpuUsageUs, 384); - expect(transaction.processed.receipt.netUsageWords, 16); - expect(transaction.processed.elapsed, 384); - expect(transaction.processed.netUsage, 128); - expect(transaction.processed.scheduled, false); - expect(transaction.processed.actionTraces.isNotEmpty, true); - expect(transaction.processed.actionTraces.first.action.name, 'transfer'); - expect(transaction.processed.actionTraces.first.action.data.toString(), + expect(transaction.processed!.producerBlockId, null); + expect(transaction.processed!.receipt!.status, 'executed'); + expect(transaction.processed!.receipt!.cpuUsageUs, 384); + expect(transaction.processed!.receipt!.netUsageWords, 16); + expect(transaction.processed!.elapsed, 384); + expect(transaction.processed!.netUsage, 128); + expect(transaction.processed!.scheduled, false); + expect(transaction.processed!.actionTraces!.isNotEmpty, true); + expect(transaction.processed!.actionTraces!.first.action!.name, 'transfer'); + expect(transaction.processed!.actionTraces!.first.action!.data.toString(), '{from: account1, to: account2, quantity: 1.00000000 EOS, memo: }'); - expect(transaction.processed.actionTraces.first.action.account, + expect(transaction.processed!.actionTraces!.first.action!.account, 'eosio.token'); }); });