From 07cbd30822ffe4afa8fe1141b5c13fa7e6b4104c Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Fri, 20 Dec 2024 13:34:27 +0100 Subject: [PATCH] feat: add pagination for checks, add check for ticket amount --- package.json | 2 +- src/dlc-handlers/keypair-dlc-handler.ts | 9 +++++++ src/functions/ripple/ripple.functions.ts | 32 ++++++++++++++++-------- src/network-handlers/ripple-handler.ts | 15 ++++++++++- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index dc65cf4..0de15d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "dlc-btc-lib", - "version": "2.5.1", + "version": "2.5.2", "description": "This library provides a comprehensive set of interfaces and functions for minting dlcBTC tokens on supported blockchains.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/dlc-handlers/keypair-dlc-handler.ts b/src/dlc-handlers/keypair-dlc-handler.ts index fe7372f..d993720 100644 --- a/src/dlc-handlers/keypair-dlc-handler.ts +++ b/src/dlc-handlers/keypair-dlc-handler.ts @@ -8,6 +8,7 @@ import { deriveUnhardenedKeyPairFromRootPrivateKey, getInputIndicesByScript, } from '../functions/bitcoin/bitcoin-functions.js'; +import { PaymentInformation } from '../models/bitcoin-models.js'; import { FundingPaymentType, PaymentType, TransactionType } from '../models/dlc-handler.models.js'; import { InvalidTransactionTypeError, @@ -67,6 +68,14 @@ export class KeyPairDLCHandler extends AbstractDLCHandler { return bytesToHex(this.fundingDerivedKeyPair.publicKey); } + getPayment(): PaymentInformation { + if (!this._payment) { + throw new PaymentNotSetError(); + } + + return this._payment; + } + private getPrivateKey(paymentType: PaymentType): Signer { const keyPairMap: Record = { funding: this.fundingDerivedKeyPair, diff --git a/src/functions/ripple/ripple.functions.ts b/src/functions/ripple/ripple.functions.ts index ccd5d6a..3c241cd 100644 --- a/src/functions/ripple/ripple.functions.ts +++ b/src/functions/ripple/ripple.functions.ts @@ -384,18 +384,30 @@ export async function getCheckByTXHash( try { await connectRippleClient(rippleClient); - const getAccountObjectsRequest: AccountObjectsRequest = { - command: 'account_objects', - account: issuerAddress, - ledger_index: 'validated', - type: 'check', - }; + let marker: any = undefined; + const limit = 100; + let allChecks: any[] = []; - const { - result: { account_objects }, - } = await rippleClient.request(getAccountObjectsRequest); + do { + const getAccountObjectsRequest: AccountObjectsRequest = { + command: 'account_objects', + account: issuerAddress, + ledger_index: 'validated', + marker, + limit, + type: 'check', + }; + + const { + result: { account_objects, marker: newMarker }, + } = await rippleClient.request(getAccountObjectsRequest); + + allChecks = allChecks.concat(account_objects); + + marker = newMarker; + } while (marker); - const check = account_objects.find(accountObject => accountObject.PreviousTxnID === txHash); + const check = allChecks.find(accountObject => accountObject.PreviousTxnID === txHash); if (!check) { throw new RippleError(`Check with TX Hash: ${txHash} not found`); diff --git a/src/network-handlers/ripple-handler.ts b/src/network-handlers/ripple-handler.ts index 4a05186..eae9c63 100644 --- a/src/network-handlers/ripple-handler.ts +++ b/src/network-handlers/ripple-handler.ts @@ -12,6 +12,7 @@ import xrpl, { SubmittableTransaction, TicketCreate, TransactionMetadata, + decode, } from 'xrpl'; import { NFTokenMintMetadata } from 'xrpl/dist/npm/models/transactions/NFTokenMint.js'; @@ -182,7 +183,19 @@ export class RippleHandler { (node): node is CreatedNode => 'CreatedNode' in node ).map(node => node.CreatedNode); - return createdNodes.map(node => node.NewFields.TicketSequence) as string[]; + const tickets = createdNodes.map(node => node.NewFields.TicketSequence).filter(Boolean); + + const decodedSignature: Record = decode(multisignedTransaction); + + const ticketCount = (decodedSignature as unknown as TicketCreate).TicketCount; + + if (tickets.length !== ticketCount) { + throw new RippleError( + `Number of created tickets does not match the number of requested tickets. Requested: ${ticketCount}, Created: ${tickets.length}` + ); + } + + return tickets as string[]; } catch (error) { throw new RippleError(`Could not submit Ticket Transaction: ${error}`); }