mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
fix: pseudo-transactions for ledger and tx (#2515)
* Add pseudo transactions as types returned by `tx` and `ledger` * Make` LedgerEntryResponse` generic to allow custom ledger entries * Update UNLModify to extend BaseTransaction * Create type `PseudoTransaction` Co-authored-by: Caleb Kniffen <ckniffen@ripple.com>
This commit is contained in:
@@ -6,6 +6,10 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Allow flag maps when submitting `NFTokenMint` and `NFTokenCreateOffer` transactions like others with flags
|
- 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<Escrow>`
|
||||||
|
|
||||||
## 2.12.0 (2023-09-27)
|
## 2.12.0 (2023-09-27)
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import type {
|
|||||||
TxResponse,
|
TxResponse,
|
||||||
} from '..'
|
} from '..'
|
||||||
import type { Amount } from '../models/common'
|
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 type { TransactionMetadata } from '../models/transactions/metadata'
|
||||||
import { isFlagEnabled } from '../models/utils'
|
import { isFlagEnabled } from '../models/utils'
|
||||||
|
|
||||||
@@ -36,7 +40,7 @@ function amountsEqual(amt1: Amount, amt2: Amount): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isPartialPayment(
|
function isPartialPayment(
|
||||||
tx?: Transaction,
|
tx?: Transaction | PseudoTransaction,
|
||||||
metadata?: TransactionMetadata | string,
|
metadata?: TransactionMetadata | string,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (tx == null || metadata == null || tx.TransactionType !== 'Payment') {
|
if (tx == null || metadata == null || tx.TransactionType !== 'Payment') {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Transaction, TransactionMetadata } from '../transactions'
|
import { Transaction, TransactionMetadata } from '../transactions'
|
||||||
|
import { PseudoTransaction } from '../transactions/transaction'
|
||||||
|
|
||||||
import LedgerEntry from './LedgerEntry'
|
import LedgerEntry from './LedgerEntry'
|
||||||
|
|
||||||
@@ -61,5 +62,7 @@ export default interface Ledger {
|
|||||||
* either JSON or binary depending on whether the request specified binary
|
* either JSON or binary depending on whether the request specified binary
|
||||||
* as true.
|
* as true.
|
||||||
*/
|
*/
|
||||||
transactions?: Array<Transaction & { metaData?: TransactionMetadata }>
|
transactions?: Array<
|
||||||
|
(Transaction | PseudoTransaction) & { metaData?: TransactionMetadata }
|
||||||
|
>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ export interface LedgerEntryRequest extends BaseRequest, LookupByLedgerRequest {
|
|||||||
*
|
*
|
||||||
* @category Responses
|
* @category Responses
|
||||||
*/
|
*/
|
||||||
export interface LedgerEntryResponse extends BaseResponse {
|
export interface LedgerEntryResponse<T = LedgerEntry> extends BaseResponse {
|
||||||
result: {
|
result: {
|
||||||
/** The unique ID of this ledger object. */
|
/** The unique ID of this ledger object. */
|
||||||
index: string
|
index: string
|
||||||
@@ -194,7 +194,7 @@ export interface LedgerEntryResponse extends BaseResponse {
|
|||||||
* Object containing the data of this ledger object, according to the
|
* Object containing the data of this ledger object, according to the
|
||||||
* ledger format.
|
* ledger format.
|
||||||
*/
|
*/
|
||||||
node?: LedgerEntry
|
node?: T
|
||||||
/** The binary representation of the ledger object, as hexadecimal. */
|
/** The binary representation of the ledger object, as hexadecimal. */
|
||||||
node_binary?: string
|
node_binary?: string
|
||||||
validated?: boolean
|
validated?: boolean
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Transaction, TransactionMetadata } from '../transactions'
|
import { Transaction, TransactionMetadata } from '../transactions'
|
||||||
import { BaseTransaction } from '../transactions/common'
|
import { BaseTransaction } from '../transactions/common'
|
||||||
|
import { PseudoTransaction } from '../transactions/transaction'
|
||||||
|
|
||||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||||
|
|
||||||
@@ -39,8 +40,9 @@ export interface TxRequest extends BaseRequest {
|
|||||||
*
|
*
|
||||||
* @category Responses
|
* @category Responses
|
||||||
*/
|
*/
|
||||||
export interface TxResponse<T extends BaseTransaction = Transaction>
|
export interface TxResponse<
|
||||||
extends BaseResponse {
|
T extends BaseTransaction = Transaction | PseudoTransaction,
|
||||||
|
> extends BaseResponse {
|
||||||
result: {
|
result: {
|
||||||
/** The SHA-512 hash of the transaction. */
|
/** The SHA-512 hash of the transaction. */
|
||||||
hash: string
|
hash: string
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { BaseTransaction } from './common'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a change to the Negative UNL.
|
* Mark a change to the Negative UNL.
|
||||||
*
|
*
|
||||||
* @category Pseudo Transaction Models
|
* @category Pseudo Transaction Models
|
||||||
*/
|
*/
|
||||||
export interface UNLModify {
|
export interface UNLModify extends BaseTransaction {
|
||||||
TransactionType: 'UNLModify'
|
TransactionType: 'UNLModify'
|
||||||
/**
|
/**
|
||||||
* The ledger index where this pseudo-transaction appears.
|
* The ledger index where this pseudo-transaction appears.
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
export { BaseTransaction } from './common'
|
export { BaseTransaction } from './common'
|
||||||
export { validate, TransactionAndMetadata, Transaction } from './transaction'
|
export {
|
||||||
|
validate,
|
||||||
|
PseudoTransaction,
|
||||||
|
TransactionAndMetadata,
|
||||||
|
Transaction,
|
||||||
|
} from './transaction'
|
||||||
export * from './metadata'
|
export * from './metadata'
|
||||||
export {
|
export {
|
||||||
AccountSetAsfFlags,
|
AccountSetAsfFlags,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { CheckCreate, validateCheckCreate } from './checkCreate'
|
|||||||
import { Clawback, validateClawback } from './clawback'
|
import { Clawback, validateClawback } from './clawback'
|
||||||
import { isIssuedCurrency } from './common'
|
import { isIssuedCurrency } from './common'
|
||||||
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
|
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
|
||||||
|
import { EnableAmendment } from './enableAmendment'
|
||||||
import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
|
import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
|
||||||
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
|
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
|
||||||
import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
|
import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
|
||||||
@@ -53,10 +54,12 @@ import {
|
|||||||
PaymentChannelFund,
|
PaymentChannelFund,
|
||||||
validatePaymentChannelFund,
|
validatePaymentChannelFund,
|
||||||
} from './paymentChannelFund'
|
} from './paymentChannelFund'
|
||||||
|
import { SetFee } from './setFee'
|
||||||
import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
|
import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
|
||||||
import { SignerListSet, validateSignerListSet } from './signerListSet'
|
import { SignerListSet, validateSignerListSet } from './signerListSet'
|
||||||
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
||||||
import { TrustSet, validateTrustSet } from './trustSet'
|
import { TrustSet, validateTrustSet } from './trustSet'
|
||||||
|
import { UNLModify } from './UNLModify'
|
||||||
import {
|
import {
|
||||||
XChainAccountCreateCommit,
|
XChainAccountCreateCommit,
|
||||||
validateXChainAccountCreateCommit,
|
validateXChainAccountCreateCommit,
|
||||||
@@ -128,6 +131,8 @@ export type Transaction =
|
|||||||
| XChainAccountCreateCommit
|
| XChainAccountCreateCommit
|
||||||
| XChainModifyBridge
|
| XChainModifyBridge
|
||||||
|
|
||||||
|
export type PseudoTransaction = EnableAmendment | SetFee | UNLModify
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category Transaction Models
|
* @category Transaction Models
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { ValidationError, XrplError } from '../../errors'
|
|||||||
import type { Ledger } from '../../models/ledger'
|
import type { Ledger } from '../../models/ledger'
|
||||||
import { LedgerEntry } from '../../models/ledger'
|
import { LedgerEntry } from '../../models/ledger'
|
||||||
import { Transaction, TransactionMetadata } from '../../models/transactions'
|
import { Transaction, TransactionMetadata } from '../../models/transactions'
|
||||||
|
import { PseudoTransaction } from '../../models/transactions/transaction'
|
||||||
|
|
||||||
import HashPrefix from './HashPrefix'
|
import HashPrefix from './HashPrefix'
|
||||||
import sha512Half from './sha512Half'
|
import sha512Half from './sha512Half'
|
||||||
@@ -124,7 +125,9 @@ export function hashLedgerHeader(ledgerHeader: Ledger): string {
|
|||||||
* @category Utilities
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashTxTree(
|
export function hashTxTree(
|
||||||
transactions: Array<Transaction & { metaData?: TransactionMetadata }>,
|
transactions: Array<
|
||||||
|
(Transaction | PseudoTransaction) & { metaData?: TransactionMetadata }
|
||||||
|
>,
|
||||||
): string {
|
): string {
|
||||||
const shamap = new SHAMap()
|
const shamap = new SHAMap()
|
||||||
for (const txJSON of transactions) {
|
for (const txJSON of transactions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user