SolanaTransaction constructor
SolanaTransaction({
- required SolAddress payerKey,
- required List<
TransactionInstruction> instructions, - required SolAddress recentBlockhash,
- List<
List< signatures = const [],int> > - TransactionType? type,
- List<
AddressLookupTableAccount> addressLookupTableAccounts = const [],
Constructs a Solana transaction with provided parameters.
Implementation
factory SolanaTransaction({
required SolAddress payerKey,
required List<TransactionInstruction> instructions,
required SolAddress recentBlockhash,
List<List<int>> signatures = const [],
TransactionType? type,
List<AddressLookupTableAccount> addressLookupTableAccounts = const [],
}) {
if (type == null) {
if (addressLookupTableAccounts.isNotEmpty) {
type = TransactionType.v0;
} else {
type = TransactionType.legacy;
}
} else {
if (type == TransactionType.legacy &&
addressLookupTableAccounts.isNotEmpty) {
throw const SolanaPluginException(
"Do not use addressLookupTableAccounts in legacy transactions.");
}
}
VersionedMessage message;
if (type == TransactionType.legacy) {
message = VersionedMessage.toLegacy(
payerKey: payerKey,
recentBlockhash: recentBlockhash,
instructions: instructions,
);
} else {
message = VersionedMessage.toV0(
payerKey: payerKey,
recentBlockhash: recentBlockhash,
instructions: instructions,
addressLookupTableAccounts: addressLookupTableAccounts,
);
}
if (signatures.isNotEmpty) {
if (signatures.length != message.header.numRequiredSignatures) {
throw const SolanaPluginException(
"The expected length of signatures should match the number of required signatures.");
}
} else {
signatures = List.generate(
message.header.numRequiredSignatures,
(index) => List<int>.unmodifiable(List<int>.filled(
SolanaTransactionConstant.signatureLengthInBytes, 0)),
);
}
return SolanaTransaction._(
List<List<int>>.unmodifiable(signatures),
message: message,
);
}