add ID to cancel/create transactions

This commit is contained in:
Denis Angell
2024-02-29 15:43:33 +01:00
parent c7aafb2595
commit e27943aa3a
3 changed files with 41 additions and 10 deletions

View File

@@ -15,7 +15,12 @@ export interface EscrowCancel extends BaseTransaction {
* Transaction sequence (or Ticket number) of EscrowCreate transaction that. * Transaction sequence (or Ticket number) of EscrowCreate transaction that.
* created the escrow to cancel. * created the escrow to cancel.
*/ */
OfferSequence: number OfferSequence?: number
/**
* The ID of the Escrow ledger object to cancel as a 64-character hexadecimal
* string.
*/
EscrowID?: string
} }
/** /**
@@ -35,11 +40,17 @@ export function validateEscrowCancel(tx: Record<string, unknown>): void {
throw new ValidationError('EscrowCancel: Owner must be a string') throw new ValidationError('EscrowCancel: Owner must be a string')
} }
if (tx.OfferSequence === undefined) { if (tx.OfferSequence === undefined && tx.EscrowID === undefined) {
throw new ValidationError('EscrowCancel: missing OfferSequence') throw new ValidationError(
'EscrowCancel: must include OfferSequence or EscrowID',
)
} }
if (typeof tx.OfferSequence !== 'number') { if (tx.OfferSequence !== undefined && typeof tx.OfferSequence !== 'number') {
throw new ValidationError('EscrowCancel: OfferSequence must be a number') throw new ValidationError('EscrowCancel: invalid OfferSequence')
}
if (tx.EscrowID !== undefined && typeof tx.EscrowID !== 'string') {
throw new ValidationError('EscrowCancel: invalid EscrowID')
} }
} }

View File

@@ -15,7 +15,12 @@ export interface OfferCancel extends BaseTransaction {
* created by that transaction. It is not considered an error if the offer. * created by that transaction. It is not considered an error if the offer.
* specified does not exist. * specified does not exist.
*/ */
OfferSequence: number OfferSequence?: number
/**
* The ID of the Escrow ledger object to cancel as a 64-character hexadecimal
* string.
*/
OfferID?: string
} }
/** /**
@@ -27,11 +32,17 @@ export interface OfferCancel extends BaseTransaction {
export function validateOfferCancel(tx: Record<string, unknown>): void { export function validateOfferCancel(tx: Record<string, unknown>): void {
validateBaseTransaction(tx) validateBaseTransaction(tx)
if (tx.OfferSequence === undefined) { if (tx.OfferSequence === undefined && tx.OfferID === undefined) {
throw new ValidationError('OfferCancel: missing field OfferSequence') throw new ValidationError(
'OfferCancel: must include OfferSequence or OfferID',
)
} }
if (typeof tx.OfferSequence !== 'number') { if (tx.OfferSequence !== undefined && typeof tx.OfferSequence !== 'number') {
throw new ValidationError('OfferCancel: OfferSequence must be a number') throw new ValidationError('OfferCancel: invalid OfferSequence')
}
if (tx.OfferID !== undefined && typeof tx.OfferID !== 'string') {
throw new ValidationError('OfferCancel: invalid OfferID')
} }
} }

View File

@@ -103,6 +103,11 @@ export interface OfferCreate extends BaseTransaction {
Expiration?: number Expiration?: number
/** An offer to delete first, specified in the same way as OfferCancel. */ /** An offer to delete first, specified in the same way as OfferCancel. */
OfferSequence?: number OfferSequence?: number
/**
* The ID of the Offer ledger object to cancel as a 64-character hexadecimal
* string.
*/
OfferID?: string
/** The amount and type of currency being provided by the offer creator. */ /** The amount and type of currency being provided by the offer creator. */
TakerGets: Amount TakerGets: Amount
/** The amount and type of currency being requested by the offer creator. */ /** The amount and type of currency being requested by the offer creator. */
@@ -141,4 +146,8 @@ export function validateOfferCreate(tx: Record<string, unknown>): void {
if (tx.OfferSequence !== undefined && typeof tx.OfferSequence !== 'number') { if (tx.OfferSequence !== undefined && typeof tx.OfferSequence !== 'number') {
throw new ValidationError('OfferCreate: invalid OfferSequence') throw new ValidationError('OfferCreate: invalid OfferSequence')
} }
if (tx.OfferID !== undefined && typeof tx.OfferID !== 'string') {
throw new ValidationError('OfferCreate: invalid OfferID')
}
} }