toOperationBody method
Generates OperationBody XDR object.
Implementation
@override
XdrOperationBody toOperationBody() {
XdrAccountID trustor =
new XdrAccountID(KeyPair.fromAccountId(this._trustor).xdrPublicKey);
// asset
XdrAssetType discriminant = XdrAssetType.ASSET_TYPE_CREDIT_ALPHANUM4;
Uint8List? assetCode4;
Uint8List? assetCode12;
if (_assetCode.length <= 4) {
assetCode4 =
Util.paddedByteArray(Uint8List.fromList(utf8.encode(_assetCode)), 4);
} else {
discriminant = XdrAssetType.ASSET_TYPE_CREDIT_ALPHANUM12;
assetCode12 =
Util.paddedByteArray(Uint8List.fromList(utf8.encode(_assetCode)), 12);
}
XdrAllowTrustOpAsset asset = new XdrAllowTrustOpAsset(discriminant);
asset.assetCode4 = assetCode4;
asset.assetCode12 = assetCode12;
int xdrAuthorize = 0;
// authorize
if (authorize) {
xdrAuthorize = XdrTrustLineFlags.AUTHORIZED_FLAG.value;
} else if (authorizeToMaintainLiabilities) {
xdrAuthorize =
XdrTrustLineFlags.AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG.value;
}
XdrAllowTrustOp op = new XdrAllowTrustOp(trustor, asset, xdrAuthorize);
XdrOperationBody body = new XdrOperationBody(XdrOperationType.ALLOW_TRUST);
body.allowTrustOp = op;
return body;
}