Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 0 deletions packages/xrpl/src/models/ledger/LedgerEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Check from './Check'
import Credential from './Credential'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the scope of this PR? Does it aim to cover all the ledger entries listed on https://xrpl.org/docs/references/protocol/ledger-data/ledger-entry-types?

import Delegate from './Delegate'
import DepositPreauth from './DepositPreauth'
import DID from './DID'
import DirectoryNode from './DirectoryNode'
import Escrow from './Escrow'
import FeeSettings from './FeeSettings'
Expand Down Expand Up @@ -33,6 +34,7 @@ type LedgerEntry =
| Credential
| Delegate
| DepositPreauth
| DID

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add MPToken, MPTokenIssuance and NFTokenPage as well?

| DirectoryNode
| Escrow
| FeeSettings
Expand Down
106 changes: 105 additions & 1 deletion packages/xrpl/src/models/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
/* eslint-disable max-lines -- There is a lot to export */
/* eslint-disable prettier/prettier -- Required here to keep formatting in line */
import type { APIVersion, DEFAULT_API_VERSION } from '../common'
import type {
AccountRoot,
AMM,
Bridge,
Check,
Credential,
Delegate,
DepositPreauth,
DID,
DirectoryNode,
Escrow,
MPToken,
MPTokenIssuance,
NFTokenPage,
Offer,
PayChannel,
RippleState,
Ticket,
XChainOwnedClaimID,
XChainOwnedCreateAccountClaimID,
} from '../ledger'

import {
AccountChannelsRequest,
Expand Down Expand Up @@ -108,7 +129,30 @@ import {
LedgerDataRequest,
LedgerDataResponse,
} from './ledgerData'
import { LedgerEntryRequest, LedgerEntryResponse } from './ledgerEntry'
import {
LedgerEntryRequest,
LedgerEntryResponse,
LedgerEntryAccountRootRequest,
LedgerEntryAMMRequest,
LedgerEntryBridgeAccountRequest,
LedgerEntryBridgeRequest,
LedgerEntryCheckRequest,
LedgerEntryCredentialRequest,
LedgerEntryDelegateRequest,
LedgerEntryDepositPreauthRequest,
LedgerEntryDIDRequest,
LedgerEntryDirectoryRequest,
LedgerEntryEscrowRequest,
LedgerEntryMPTokenIssuanceRequest,
LedgerEntryMPTokenRequest,
LedgerEntryNFTokenPageRequest,
LedgerEntryOfferRequest,
LedgerEntryPayChannelRequest,
LedgerEntryRippleStateRequest,
LedgerEntryTicketRequest,
LedgerEntryXChainOwnedClaimIDRequest,
LedgerEntryXChainOwnedCreateAccountClaimIDRequest,
} from './ledgerEntry'
import { ManifestRequest, ManifestResponse } from './manifest'
import { NFTBuyOffersRequest, NFTBuyOffersResponse } from './nftBuyOffers'
import {
Expand Down Expand Up @@ -412,6 +456,46 @@ export type RequestResponseMap<
? LedgerCurrentResponse
: T extends LedgerDataRequest
? LedgerDataResponse
: T extends LedgerEntryAccountRootRequest
? LedgerEntryResponse<AccountRoot>
: T extends LedgerEntryAMMRequest
? LedgerEntryResponse<AMM>
: T extends LedgerEntryBridgeAccountRequest
? LedgerEntryResponse<Bridge>
: T extends LedgerEntryBridgeRequest
? LedgerEntryResponse<Bridge>
: T extends LedgerEntryCheckRequest
? LedgerEntryResponse<Check>
: T extends LedgerEntryCredentialRequest
? LedgerEntryResponse<Credential>
: T extends LedgerEntryDelegateRequest
? LedgerEntryResponse<Delegate>
: T extends LedgerEntryDepositPreauthRequest
? LedgerEntryResponse<DepositPreauth>
: T extends LedgerEntryDIDRequest
? LedgerEntryResponse<DID>
: T extends LedgerEntryDirectoryRequest
? LedgerEntryResponse<DirectoryNode>
: T extends LedgerEntryEscrowRequest
? LedgerEntryResponse<Escrow>
: T extends LedgerEntryMPTokenIssuanceRequest
? LedgerEntryResponse<MPTokenIssuance>
: T extends LedgerEntryMPTokenRequest
? LedgerEntryResponse<MPToken>
: T extends LedgerEntryNFTokenPageRequest
? LedgerEntryResponse<NFTokenPage>
: T extends LedgerEntryOfferRequest
? LedgerEntryResponse<Offer>
: T extends LedgerEntryPayChannelRequest
? LedgerEntryResponse<PayChannel>
: T extends LedgerEntryRippleStateRequest
? LedgerEntryResponse<RippleState>
: T extends LedgerEntryTicketRequest
? LedgerEntryResponse<Ticket>
: T extends LedgerEntryXChainOwnedClaimIDRequest
? LedgerEntryResponse<XChainOwnedClaimID>
: T extends LedgerEntryXChainOwnedCreateAccountClaimIDRequest
? LedgerEntryResponse<XChainOwnedCreateAccountClaimID>
: T extends LedgerEntryRequest
? LedgerEntryResponse
: T extends SimulateBinaryRequest
Expand Down Expand Up @@ -567,6 +651,26 @@ export {
LedgerDataLedgerState,
LedgerEntryRequest,
LedgerEntryResponse,
LedgerEntryAccountRootRequest,
LedgerEntryAMMRequest,
LedgerEntryBridgeRequest,
LedgerEntryBridgeAccountRequest,
LedgerEntryCheckRequest,
LedgerEntryCredentialRequest,
LedgerEntryDelegateRequest,
LedgerEntryDepositPreauthRequest,
LedgerEntryDIDRequest,
LedgerEntryDirectoryRequest,
LedgerEntryEscrowRequest,
LedgerEntryMPTokenIssuanceRequest,
LedgerEntryMPTokenRequest,
LedgerEntryNFTokenPageRequest,
LedgerEntryOfferRequest,
LedgerEntryPayChannelRequest,
LedgerEntryRippleStateRequest,
LedgerEntryTicketRequest,
LedgerEntryXChainOwnedClaimIDRequest,
LedgerEntryXChainOwnedCreateAccountClaimIDRequest,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// transaction methods with types
SimulateRequest,
SimulateResponse,
Expand Down
82 changes: 82 additions & 0 deletions packages/xrpl/src/models/methods/ledgerEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,88 @@ export interface LedgerEntryRequest extends BaseRequest, LookupByLedgerRequest {
}
}

export interface LedgerEntryAccountRootRequest extends LedgerEntryRequest {
account_root: Required<LedgerEntryRequest>['account_root']
}

export interface LedgerEntryAMMRequest extends LedgerEntryRequest {
amm: Required<LedgerEntryRequest>['amm']
}

export interface LedgerEntryBridgeAccountRequest extends LedgerEntryRequest {
bridge_account: Required<LedgerEntryRequest>['bridge_account']
}

export interface LedgerEntryBridgeRequest extends LedgerEntryRequest {
bridge: Required<LedgerEntryRequest>['bridge']
}

export interface LedgerEntryCheckRequest extends LedgerEntryRequest {
check: Required<LedgerEntryRequest>['check']
}

export interface LedgerEntryCredentialRequest extends LedgerEntryRequest {
credential: Required<LedgerEntryRequest>['credential']
}

export interface LedgerEntryDelegateRequest extends LedgerEntryRequest {
delegate: Required<LedgerEntryRequest>['delegate']
}

export interface LedgerEntryDepositPreauthRequest extends LedgerEntryRequest {
deposit_preauth: Required<LedgerEntryRequest>['deposit_preauth']
}

export interface LedgerEntryDIDRequest extends LedgerEntryRequest {
did: Required<LedgerEntryRequest>['did']
}

export interface LedgerEntryDirectoryRequest extends LedgerEntryRequest {
directory: Required<LedgerEntryRequest>['directory']
}

export interface LedgerEntryEscrowRequest extends LedgerEntryRequest {
escrow: Required<LedgerEntryRequest>['escrow']
}

export interface LedgerEntryMPTokenIssuanceRequest extends LedgerEntryRequest {
mpt_issuance: Required<LedgerEntryRequest>['mpt_issuance']
}

export interface LedgerEntryMPTokenRequest extends LedgerEntryRequest {
mptoken: Required<LedgerEntryRequest>['mptoken']
}

export interface LedgerEntryNFTokenPageRequest extends LedgerEntryRequest {
nft_page: Required<LedgerEntryRequest>['nft_page']
}

export interface LedgerEntryOfferRequest extends LedgerEntryRequest {
offer: Required<LedgerEntryRequest>['offer']
}

export interface LedgerEntryPayChannelRequest extends LedgerEntryRequest {
payment_channel: Required<LedgerEntryRequest>['payment_channel']
}

export interface LedgerEntryRippleStateRequest extends LedgerEntryRequest {
ripple_state: Required<LedgerEntryRequest>['ripple_state']
}

export interface LedgerEntryTicketRequest extends LedgerEntryRequest {
ticket: Required<LedgerEntryRequest>['ticket']
}

// eslint-disable-next-line max-len -- Disable for interface declaration.
export interface LedgerEntryXChainOwnedClaimIDRequest extends LedgerEntryRequest {
xchain_owned_claim_id: Required<LedgerEntryRequest>['xchain_owned_claim_id']
}

// eslint-disable-next-line max-len -- Disable for interface declaration.
export interface LedgerEntryXChainOwnedCreateAccountClaimIDRequest extends LedgerEntryRequest {
xchain_owned_create_account_claim_id: Required<LedgerEntryRequest>['xchain_owned_create_account_claim_id']
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the scope, but do we need requests for Oracle, Vault, PermissionedDomain, Loan and LoanBroker?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I should add those in this PR, since they didn't exist before.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tequdev Can you log a Github issue detailing missing ledger entires, so that we can close on this refactor PR?

/**
* Response expected from a {@link LedgerEntryRequest}.
*
Expand Down
24 changes: 11 additions & 13 deletions packages/xrpl/test/integration/transactions/clawback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
MPTokenIssuanceCreateFlags,
MPTokenAuthorize,
TransactionMetadata,
LedgerEntryResponse,
} from '../../../src'
import serverUrl from '../serverUrl'
import {
Expand Down Expand Up @@ -162,18 +161,17 @@ describe('Clawback', function () {

await testTransaction(testContext.client, paymentTx, testContext.wallet)

let ledgerEntryResponse: LedgerEntryResponse =
await testContext.client.request({
command: 'ledger_entry',
mptoken: {
mpt_issuance_id: mptID!,
account: wallet2.classicAddress,
},
})
let ledgerEntryResponse = await testContext.client.request({
command: 'ledger_entry',
mptoken: {
mpt_issuance_id: mptID!,
account: wallet2.classicAddress,
},
})

assert.equal(
// @ts-expect-error: Known issue with unknown object type
ledgerEntryResponse.result.node.MPTAmount,
// @ts-expect-error: string type assertion to MPTAmount field
Comment thread
tequdev marked this conversation as resolved.
Outdated
ledgerEntryResponse.result.node.MPTAmount as string,
'9223372036854775807',
)

Expand All @@ -198,8 +196,8 @@ describe('Clawback', function () {
})

assert.equal(
// @ts-expect-error: Known issue with unknown object type
ledgerEntryResponse.result.node.MPTAmount,
// @ts-expect-error: string type assertion to MPTAmount field
ledgerEntryResponse.result.node.MPTAmount as string,
'9223372036854775307',
)
},
Expand Down
19 changes: 8 additions & 11 deletions packages/xrpl/test/integration/transactions/delegateSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { assert } from 'chai'
import {
AccountSet,
DelegateSet,
LedgerEntryResponse,
Payment,
Wallet,
xrpToDrops,
} from '../../../src'
import { Delegate } from '../../../src/models/ledger'
import serverUrl from '../serverUrl'
import {
setupClient,
Expand Down Expand Up @@ -51,15 +49,14 @@ describe('DelegateSet', function () {
await testTransaction(testContext.client, delegateTx, alice)

// Verify Delegate ledger entry
const ledgerEntryRes: LedgerEntryResponse =
await testContext.client.request({
command: 'ledger_entry',
delegate: {
account: alice.address,
authorize: bob.address,
},
})
const delegateLedgerEntry = ledgerEntryRes.result.node as Delegate
const ledgerEntryRes = await testContext.client.request({
command: 'ledger_entry',
delegate: {
account: alice.address,
authorize: bob.address,
},
})
const delegateLedgerEntry = ledgerEntryRes.result.node!
assert.equal(delegateLedgerEntry.LedgerEntryType, 'Delegate')
assert.equal(delegateLedgerEntry.Account, alice.address)
assert.equal(delegateLedgerEntry.Authorize, bob.address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('PermissionedDEX', function () {
seq: offerCreateTxResponse.result.tx_json.Sequence as number,
},
})
).result.node as Offer
).result.node!

assert.equal(offerLedgerObject.LedgerEntryType, 'Offer')
assert.equal(offerLedgerObject.DomainID, permDomainLedgerObject.index)
Expand All @@ -259,7 +259,7 @@ describe('PermissionedDEX', function () {
})

assert.equal(
(ledgerEntryResponse.result.node as DirectoryNode).index,
ledgerEntryResponse.result.node?.index,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional chaining silently passes if node is undefined — add a guard before asserting:

Add assert.ok(ledgerEntryResponse.result.node, 'node should be present') before line 261, then restore the non-optional access:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

offerLedgerObject.BookDirectory,
)
assert.equal(
Expand Down
Loading