Skip to content

Commit

Permalink
Migrates to null safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelongqy committed Oct 28, 2021
1 parent 8e72095 commit 27fbe1b
Show file tree
Hide file tree
Showing 32 changed files with 1,402 additions and 1,259 deletions.
40 changes: 20 additions & 20 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ecc.EOSPrivateKey> keys = Map();

/// Converts abi files between binary and structured form (`abi.abi.json`) */
Map<String, Type> abiTypes;
Map<String, Type> transactionTypes;
late Map<String, Type> abiTypes;
late Map<String, Type> transactionTypes;

/// Construct the EOS client from eos node URL
EOSClient(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -115,7 +115,7 @@ class EOSClient {
}

/// Get table row (eosio get table ...)
Future<Map<String, dynamic>> getTableRow(
Future<Map<String, dynamic>?> getTableRow(
String code,
String scope,
String table, {
Expand Down Expand Up @@ -194,7 +194,7 @@ class EOSClient {

/// Get EOS account info form the given account name
Future<List<Holding>> 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();
Expand All @@ -221,7 +221,7 @@ class EOSClient {
}

/// Get EOS account actions
Future<Actions> getActions(String accountName, {int pos, int offset}) async {
Future<Actions> getActions(String accountName, {int pos = -1, int offset = -1}) async {
return this._post('/history/get_actions', {
'account_name': accountName,
'pot': pos,
Expand All @@ -232,7 +232,7 @@ class EOSClient {
}

/// Get EOS transaction
Future<TransactionBlock> getTransaction(String id, {int blockNumHint}) async {
Future<TransactionBlock> getTransaction(String id, {int? blockNumHint}) async {
return this._post('/history/get_transaction',
{'id': id, 'block_num_hint': blockNumHint}).then((transaction) {
return TransactionBlock.fromJson(transaction);
Expand All @@ -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', {
Expand All @@ -279,9 +279,9 @@ class EOSClient {
Future<Contract> _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<String, Type>();
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);
Expand All @@ -291,7 +291,7 @@ class EOSClient {
/// Fill the transaction withe reference block data
Future<Transaction> _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;

Expand All @@ -300,13 +300,13 @@ class EOSClient {

/// serialize actions in a transaction
Future<Transaction> _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;
}
Expand All @@ -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());
}

Expand Down Expand Up @@ -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());
}
}
Expand Down
50 changes: 29 additions & 21 deletions lib/src/eosdart_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,50 @@ 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 {
String name;

String aliasOfName;

Type arrayOf;
Type? arrayOf;

Type optionalOf;
Type? optionalOf;

Type extensionOf;
Type? extensionOf;

String baseName;

Type base;
Type? base;

List<Field> 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 {
Expand All @@ -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,
});
}
Loading

0 comments on commit 27fbe1b

Please sign in to comment.