Merge branch 'add_transaction_is_valid' into 'development'

Add function Transaction.isValid

See merge request GeneralProtocols/xo/stack!16
This commit is contained in:
Jim Hamill
2025-01-13 03:18:08 +00:00
+16
View File
@@ -100,6 +100,22 @@ export class Transaction {
return new this(transaction);
}
/**
* Validates the structure of a transaction.
*
* @param transaction The transaction (as hex or bytes).
* @returns boolean indicating whether the transaction structure is valid.
*/
public static isValid(transaction: Uint8Array | string): boolean {
try {
Transaction.from(transaction);
} catch (_error) {
return false;
}
return true;
}
public toBytes(): Uint8Array {
const bytes = encodeTransaction(this.transaction);