diff --git a/lib/src/client.dart b/lib/src/client.dart index 1e88577..61327ef 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -275,6 +275,21 @@ class EOSClient { return pushTransactionArgs; } + Future createTransaction(Transaction transaction, + { dynamic key, + int blocksBehind = 3, + int expireSecond = 180}) async { + NodeInfo info = await this.getInfo(); + Block refBlock = await getBlock((info.headBlockNum - blocksBehind).toString()); + final pKey = key ?? this.keys.values.toList()[0]; + + Transaction trx = await _fullFill(transaction, refBlock); + PushTransactionArgs pushTransactionArgs = await _createTransactionArgs( + info.chainId, transactionTypes['transaction'], trx, pKey); + + return pushTransactionArgs; + } + /// Get data needed to serialize actions in a contract */ Future _getContract(String accountName, {bool reload = false}) async { @@ -358,6 +373,21 @@ class EOSClient { return PushTransactionArgs(signatures, serializedTrx); } + + Future _createTransactionArgs(String chainId, + Type transactionType, Transaction transaction, ecc.EOSPrivateKey pKey) async { + List signatures = []; + transaction = await _serializeActions(transaction); + Uint8List serializedTrx = transaction.toBinary(transactionType); + + Uint8List signBuf = Uint8List.fromList(List.from(ser.stringToHex(chainId)) + ..addAll(serializedTrx) + ..addAll(Uint8List(32))); + + signatures.add(pKey.sign(signBuf).toString()); + + return PushTransactionArgs(signatures, serializedTrx); + } } class PushTransactionArgs { diff --git a/lib/src/serialize.dart b/lib/src/serialize.dart index 5c7beee..1b54cee 100644 --- a/lib/src/serialize.dart +++ b/lib/src/serialize.dart @@ -580,7 +580,7 @@ Symbol stringToSymbol(String s) { if (!exp.hasMatch(s)) { throw 'Invalid symbol'; } - return Symbol(name: m[2].toString(), precision: int.parse([1].toString())); + return Symbol(name: m[0].group(2), precision: int.parse(m[0].group(1).toString())); } /// Convert `Symbol` to `string`. format: `precision,NAME`. */ @@ -614,6 +614,8 @@ void serializeStruct(Type self, SerialBuffer buffer, Object data, } else { if (allowExtensions && field.type.extensionOf != null) { state.skippedBinaryExtension = true; + } else if(field.type.optionalOf != null ) { + field.type.serialize(field.type, buffer, dy[field.name],state: state); } else { throw 'missing ' + self.name +