From d36349e4105f0f8237732468093a6d8a6bc0bdc6 Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Sun, 26 Mar 2023 09:44:26 +0000 Subject: [PATCH] add invoke tx --- .../xrpl/src/models/transactions/index.ts | 1 + .../xrpl/src/models/transactions/invoke.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 packages/xrpl/src/models/transactions/invoke.ts diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 7c827d3b..27762509 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -14,6 +14,7 @@ export { DepositPreauth } from './depositPreauth' export { EscrowCancel } from './escrowCancel' export { EscrowCreate } from './escrowCreate' export { EscrowFinish } from './escrowFinish' +export { Invoke } from './invoke' export { NFTokenAcceptOffer } from './NFTokenAcceptOffer' export { NFTokenBurn } from './NFTokenBurn' export { NFTokenCancelOffer } from './NFTokenCancelOffer' diff --git a/packages/xrpl/src/models/transactions/invoke.ts b/packages/xrpl/src/models/transactions/invoke.ts new file mode 100644 index 00000000..a7824adc --- /dev/null +++ b/packages/xrpl/src/models/transactions/invoke.ts @@ -0,0 +1,32 @@ +import { ValidationError } from '../../errors' + +import { BaseTransaction, validateBaseTransaction } from './common' + +/** + * + * + * @category Transaction Models + */ +export interface Invoke extends BaseTransaction { + TransactionType: 'Invoke' + /** + * If present, invokes the Hook on the Destination account. + */ + Destination?: string +} + +/** + * Verify the form and type of an Invoke at runtime. + * + * @param tx - An Invoke Transaction. + * @throws When the Invoke is Malformed. + */ +export function validateInvoke(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.Account === tx.Destination) { + throw new ValidationError( + 'Invoke: Destination and Account must not be equal', + ) + } +}