diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 502a7cbe..bb55ae0b 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -6,6 +6,10 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ### Fixed - Allow flag maps when submitting `NFTokenMint` and `NFTokenCreateOffer` transactions like others with flags +- Add pseudo transaction types to `tx` and `ledger` methods responses. + +### Updated +- Make `LedgerEntryResponse` a generic so it can be used like `LedgerEntryResponse` ## 2.12.0 (2023-09-27) ### Added diff --git a/packages/xrpl/src/client/partialPayment.ts b/packages/xrpl/src/client/partialPayment.ts index 9c13ad0e..f765a0fc 100644 --- a/packages/xrpl/src/client/partialPayment.ts +++ b/packages/xrpl/src/client/partialPayment.ts @@ -10,7 +10,11 @@ import type { TxResponse, } from '..' import type { Amount } from '../models/common' -import { PaymentFlags, Transaction } from '../models/transactions' +import { + PaymentFlags, + PseudoTransaction, + Transaction, +} from '../models/transactions' import type { TransactionMetadata } from '../models/transactions/metadata' import { isFlagEnabled } from '../models/utils' @@ -36,7 +40,7 @@ function amountsEqual(amt1: Amount, amt2: Amount): boolean { } function isPartialPayment( - tx?: Transaction, + tx?: Transaction | PseudoTransaction, metadata?: TransactionMetadata | string, ): boolean { if (tx == null || metadata == null || tx.TransactionType !== 'Payment') { diff --git a/packages/xrpl/src/models/ledger/Ledger.ts b/packages/xrpl/src/models/ledger/Ledger.ts index 20c2b3b0..0e117cef 100644 --- a/packages/xrpl/src/models/ledger/Ledger.ts +++ b/packages/xrpl/src/models/ledger/Ledger.ts @@ -1,4 +1,5 @@ import { Transaction, TransactionMetadata } from '../transactions' +import { PseudoTransaction } from '../transactions/transaction' import LedgerEntry from './LedgerEntry' @@ -61,5 +62,7 @@ export default interface Ledger { * either JSON or binary depending on whether the request specified binary * as true. */ - transactions?: Array + transactions?: Array< + (Transaction | PseudoTransaction) & { metaData?: TransactionMetadata } + > } diff --git a/packages/xrpl/src/models/methods/ledgerEntry.ts b/packages/xrpl/src/models/methods/ledgerEntry.ts index 5068b6ca..688a3c40 100644 --- a/packages/xrpl/src/models/methods/ledgerEntry.ts +++ b/packages/xrpl/src/models/methods/ledgerEntry.ts @@ -184,7 +184,7 @@ export interface LedgerEntryRequest extends BaseRequest, LookupByLedgerRequest { * * @category Responses */ -export interface LedgerEntryResponse extends BaseResponse { +export interface LedgerEntryResponse extends BaseResponse { result: { /** The unique ID of this ledger object. */ index: string @@ -194,7 +194,7 @@ export interface LedgerEntryResponse extends BaseResponse { * Object containing the data of this ledger object, according to the * ledger format. */ - node?: LedgerEntry + node?: T /** The binary representation of the ledger object, as hexadecimal. */ node_binary?: string validated?: boolean diff --git a/packages/xrpl/src/models/methods/tx.ts b/packages/xrpl/src/models/methods/tx.ts index 48516eca..d1e15e34 100644 --- a/packages/xrpl/src/models/methods/tx.ts +++ b/packages/xrpl/src/models/methods/tx.ts @@ -1,5 +1,6 @@ import { Transaction, TransactionMetadata } from '../transactions' import { BaseTransaction } from '../transactions/common' +import { PseudoTransaction } from '../transactions/transaction' import { BaseRequest, BaseResponse } from './baseMethod' @@ -39,8 +40,9 @@ export interface TxRequest extends BaseRequest { * * @category Responses */ -export interface TxResponse - extends BaseResponse { +export interface TxResponse< + T extends BaseTransaction = Transaction | PseudoTransaction, +> extends BaseResponse { result: { /** The SHA-512 hash of the transaction. */ hash: string diff --git a/packages/xrpl/src/models/transactions/UNLModify.ts b/packages/xrpl/src/models/transactions/UNLModify.ts index bc197914..41570f56 100644 --- a/packages/xrpl/src/models/transactions/UNLModify.ts +++ b/packages/xrpl/src/models/transactions/UNLModify.ts @@ -1,9 +1,11 @@ +import { BaseTransaction } from './common' + /** * Mark a change to the Negative UNL. * * @category Pseudo Transaction Models */ -export interface UNLModify { +export interface UNLModify extends BaseTransaction { TransactionType: 'UNLModify' /** * The ledger index where this pseudo-transaction appears. diff --git a/packages/xrpl/src/models/transactions/index.ts b/packages/xrpl/src/models/transactions/index.ts index 577d8a38..59e3ae87 100644 --- a/packages/xrpl/src/models/transactions/index.ts +++ b/packages/xrpl/src/models/transactions/index.ts @@ -1,5 +1,10 @@ export { BaseTransaction } from './common' -export { validate, TransactionAndMetadata, Transaction } from './transaction' +export { + validate, + PseudoTransaction, + TransactionAndMetadata, + Transaction, +} from './transaction' export * from './metadata' export { AccountSetAsfFlags, diff --git a/packages/xrpl/src/models/transactions/transaction.ts b/packages/xrpl/src/models/transactions/transaction.ts index ef473347..575d58c0 100644 --- a/packages/xrpl/src/models/transactions/transaction.ts +++ b/packages/xrpl/src/models/transactions/transaction.ts @@ -20,6 +20,7 @@ import { CheckCreate, validateCheckCreate } from './checkCreate' import { Clawback, validateClawback } from './clawback' import { isIssuedCurrency } from './common' import { DepositPreauth, validateDepositPreauth } from './depositPreauth' +import { EnableAmendment } from './enableAmendment' import { EscrowCancel, validateEscrowCancel } from './escrowCancel' import { EscrowCreate, validateEscrowCreate } from './escrowCreate' import { EscrowFinish, validateEscrowFinish } from './escrowFinish' @@ -53,10 +54,12 @@ import { PaymentChannelFund, validatePaymentChannelFund, } from './paymentChannelFund' +import { SetFee } from './setFee' import { SetRegularKey, validateSetRegularKey } from './setRegularKey' import { SignerListSet, validateSignerListSet } from './signerListSet' import { TicketCreate, validateTicketCreate } from './ticketCreate' import { TrustSet, validateTrustSet } from './trustSet' +import { UNLModify } from './UNLModify' import { XChainAccountCreateCommit, validateXChainAccountCreateCommit, @@ -128,6 +131,8 @@ export type Transaction = | XChainAccountCreateCommit | XChainModifyBridge +export type PseudoTransaction = EnableAmendment | SetFee | UNLModify + /** * @category Transaction Models */ diff --git a/packages/xrpl/src/utils/hashes/hashLedger.ts b/packages/xrpl/src/utils/hashes/hashLedger.ts index f9fa2676..853cbd60 100644 --- a/packages/xrpl/src/utils/hashes/hashLedger.ts +++ b/packages/xrpl/src/utils/hashes/hashLedger.ts @@ -10,6 +10,7 @@ import { ValidationError, XrplError } from '../../errors' import type { Ledger } from '../../models/ledger' import { LedgerEntry } from '../../models/ledger' import { Transaction, TransactionMetadata } from '../../models/transactions' +import { PseudoTransaction } from '../../models/transactions/transaction' import HashPrefix from './HashPrefix' import sha512Half from './sha512Half' @@ -124,7 +125,9 @@ export function hashLedgerHeader(ledgerHeader: Ledger): string { * @category Utilities */ export function hashTxTree( - transactions: Array, + transactions: Array< + (Transaction | PseudoTransaction) & { metaData?: TransactionMetadata } + >, ): string { const shamap = new SHAMap() for (const txJSON of transactions) {