fromTxRep method
Implementation
static AbstractTransaction fromTxRep(String txRep) {
if (txRep == null) {
return null;
}
List<String> lines = txRep.split('\n'); //TODO: handle newline within string
Map<String, String> map = Map<String, String>();
for (String line in lines) {
var parts = line.split(':');
if (parts.length > 1) {
String key = parts[0].trim();
String value = parts.sublist(1).join(':').trim();
map.addAll({key: value});
}
}
String sourceAccountId = _removeComment(map['tx.sourceAccount']);
int sequenceNumber = int.parse(_removeComment(map['tx.seqNum']));
KeyPair sourceKeyPair = KeyPair.fromAccountId(sourceAccountId);
Account sourceAccount = Account(sourceKeyPair, sequenceNumber - 1);
TransactionBuilder txBuilder = TransactionBuilder(sourceAccount);
// TimeBounds
if (_removeComment(map['tx.timeBounds._present']) == 'true' &&
map['tx.timeBounds.minTime'] != null &&
map['tx.timeBounds.maxTime'] != null) {
int minTime = int.parse(_removeComment(map['tx.timeBounds.minTime']));
int maxTime = int.parse(_removeComment(map['tx.timeBounds.maxTime']));
TimeBounds timeBounds = TimeBounds(minTime, maxTime);
txBuilder.addTimeBounds(timeBounds);
}
// Memo
String memoType = _removeComment(map['tx.memo.type']);
if (memoType == 'MEMO_TEXT' && map['tx.memo.text'] != null) {
txBuilder.addMemo(
MemoText(_removeComment(map['tx.memo.text']).replaceAll('"', '')));
} else if (memoType == 'MEMO_ID' && map['tx.memo.id'] != null) {
txBuilder.addMemo(MemoId(int.parse(_removeComment(map['tx.memo.id']))));
} else if (memoType == 'MEMO_HASH' && map['tx.memo.hash'] != null) {
txBuilder.addMemo(
MemoHash(Util.hexToBytes(_removeComment(map['tx.memo.hash']))));
} else if (memoType == 'MEMO_RETURN' && map['tx.memo.return'] != null) {
txBuilder.addMemo(
MemoReturnHash.string(_removeComment(map['tx.memo.return'])));
} else {
txBuilder.addMemo(MemoNone());
}
// Operations
int nrOfOperations = int.parse(_removeComment(map['tx.operations.len']));
for (int i = 0; i < nrOfOperations; i++) {
Operation operation = _getOperation(i, map);
if (operation != null) {
txBuilder.addOperation(operation);
}
}
AbstractTransaction transaction = txBuilder.build();
// Signatures
int nrOfSignatures = int.parse(_removeComment(map['tx.signatures.len']));
List<XdrDecoratedSignature> signatures = List<XdrDecoratedSignature>();
for (int i = 0; i < nrOfSignatures; i++) {
XdrDecoratedSignature signature = _getSignature(i, map);
if (signature != null) {
signatures.add(signature);
}
}
transaction.signatures = signatures;
return transaction;
}