Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix optionalOf serialize bug #31 #33

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ class EOSClient {
return pushTransactionArgs;
}

Future<dynamic> 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<Contract> _getContract(String accountName,
{bool reload = false}) async {
Expand Down Expand Up @@ -358,6 +373,21 @@ class EOSClient {

return PushTransactionArgs(signatures, serializedTrx);
}

Future<PushTransactionArgs> _createTransactionArgs(String chainId,
Type transactionType, Transaction transaction, ecc.EOSPrivateKey pKey) async {
List<String> 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 {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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`. */
Expand Down Expand Up @@ -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 +
Expand Down