Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pagination for checks, add check for ticket amount #48

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/dlc-handlers/keypair-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PaymentType, BIP32Interface> = {
funding: this.fundingDerivedKeyPair,
Expand Down
32 changes: 22 additions & 10 deletions src/functions/ripple/ripple.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
15 changes: 14 additions & 1 deletion src/network-handlers/ripple-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import xrpl, {
SubmittableTransaction,
TicketCreate,
TransactionMetadata,
decode,
} from 'xrpl';
import { NFTokenMintMetadata } from 'xrpl/dist/npm/models/transactions/NFTokenMint.js';

Expand Down Expand Up @@ -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<string, unknown> = 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}`);
}
Expand Down
Loading