create method Null safety
- Uint8List contents,
- KeyModel key,
- {String assetRef = 'AA=='}
Creates a TransactionModel with contents
.
Uses the KeyModel.privateKey from key
to sign the transaction. If the
assetRef
is not set, it defaults to AA==. The return is an uncommitted
TransactionModel. The TransactionModel should be added to a
BlockModel by setting the TransactionModel.block and
TransactionModel.merkelProof values and calling the commit method.
Implementation
TransactionModel create(Uint8List contents, KeyModel key,
{String assetRef = 'AA=='}) {
TransactionModel txn = TransactionModel(
address: key.address, contents: contents, assetRef: assetRef);
txn.signature =
Rsa.sign(key.privateKey, txn.serialize(includeSignature: false));
txn.id = Digest("SHA3-256").process(txn.serialize());
_repository.save(txn);
return txn;
}