Skip to content
Open
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
11 changes: 11 additions & 0 deletions packages/xrpl/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ class Client extends EventEmitter<EventTypes> {
* console.log(response)
* ```
*/
// public async request<

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.

nit: Should we remove these comments?

// R extends Request,
// V extends APIVersion = typeof DEFAULT_API_VERSION,
// >(req: R): Promise<RequestResponseMap<R, V>>

// public async request<
// R extends Request,
// V extends APIVersion = typeof DEFAULT_API_VERSION,
// T = RequestResponseMap<R, V>,
// >(req: R): Promise<T>

public async request<
R extends Request,
V extends APIVersion = typeof DEFAULT_API_VERSION,
Expand Down
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
129 changes: 129 additions & 0 deletions 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 @@ -115,6 +136,26 @@ import {
LedgerEntryBinaryResponse,
LedgerEntryJsonResponse,
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'
Expand Down Expand Up @@ -198,6 +239,12 @@ import {
UnsubscribeResponse,
} from './unsubscribe'
import { VaultInfoRequest, VaultInfoResponse } from './vaultInfo'

type LedgerEntryLookupResponse<T, EntryType> =
T extends LedgerEntryJsonRequest
? LedgerEntryJsonResponse<EntryType>
: LedgerEntryResponse<EntryType>

/**
* @category Requests
*/
Expand All @@ -218,6 +265,28 @@ type Request =
| LedgerClosedRequest
| LedgerCurrentRequest
| LedgerDataRequest
| LedgerEntryBinaryRequest
| LedgerEntryJsonRequest
| LedgerEntryAccountRootRequest
| LedgerEntryAMMRequest
| LedgerEntryBridgeAccountRequest
| LedgerEntryBridgeRequest
| LedgerEntryCheckRequest
| LedgerEntryCredentialRequest
| LedgerEntryDelegateRequest
| LedgerEntryDepositPreauthRequest
| LedgerEntryDIDRequest
| LedgerEntryDirectoryRequest
| LedgerEntryEscrowRequest
| LedgerEntryMPTokenIssuanceRequest
| LedgerEntryMPTokenRequest
| LedgerEntryNFTokenPageRequest
| LedgerEntryOfferRequest
| LedgerEntryPayChannelRequest
| LedgerEntryRippleStateRequest
| LedgerEntryTicketRequest
| LedgerEntryXChainOwnedClaimIDRequest
| LedgerEntryXChainOwnedCreateAccountClaimIDRequest
| LedgerEntryRequest
// transaction methods
| SimulateRequest
Expand Down Expand Up @@ -421,6 +490,46 @@ export type RequestResponseMap<
? LedgerDataResponse
: T extends LedgerEntryBinaryRequest
? LedgerEntryBinaryResponse
: T extends LedgerEntryAccountRootRequest
? LedgerEntryLookupResponse<T, AccountRoot>
: T extends LedgerEntryAMMRequest
? LedgerEntryLookupResponse<T, AMM>
: T extends LedgerEntryBridgeAccountRequest
? LedgerEntryLookupResponse<T, Bridge>
: T extends LedgerEntryBridgeRequest
? LedgerEntryLookupResponse<T, Bridge>
: T extends LedgerEntryCheckRequest
? LedgerEntryLookupResponse<T, Check>
: T extends LedgerEntryCredentialRequest
? LedgerEntryLookupResponse<T, Credential>
: T extends LedgerEntryDelegateRequest
? LedgerEntryLookupResponse<T, Delegate>
: T extends LedgerEntryDepositPreauthRequest
? LedgerEntryLookupResponse<T, DepositPreauth>
: T extends LedgerEntryDIDRequest
? LedgerEntryLookupResponse<T, DID>
: T extends LedgerEntryDirectoryRequest
? LedgerEntryLookupResponse<T, DirectoryNode>
: T extends LedgerEntryEscrowRequest
? LedgerEntryLookupResponse<T, Escrow>
: T extends LedgerEntryMPTokenIssuanceRequest
? LedgerEntryLookupResponse<T, MPTokenIssuance>
: T extends LedgerEntryMPTokenRequest
? LedgerEntryLookupResponse<T, MPToken>
: T extends LedgerEntryNFTokenPageRequest
? LedgerEntryLookupResponse<T, NFTokenPage>
: T extends LedgerEntryOfferRequest
? LedgerEntryLookupResponse<T, Offer>
: T extends LedgerEntryPayChannelRequest
? LedgerEntryLookupResponse<T, PayChannel>
: T extends LedgerEntryRippleStateRequest
? LedgerEntryLookupResponse<T, RippleState>
: T extends LedgerEntryTicketRequest
? LedgerEntryLookupResponse<T, Ticket>
: T extends LedgerEntryXChainOwnedClaimIDRequest
? LedgerEntryLookupResponse<T, XChainOwnedClaimID>
: T extends LedgerEntryXChainOwnedCreateAccountClaimIDRequest
? LedgerEntryLookupResponse<T, XChainOwnedCreateAccountClaimID>
: T extends LedgerEntryJsonRequest
? LedgerEntryJsonResponse
: T extends LedgerEntryRequest
Expand Down Expand Up @@ -582,6 +691,26 @@ export {
LedgerEntryBinaryResponse,
LedgerEntryJsonResponse,
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?

export type LedgerEntryBinaryRequest = LedgerEntryRequest & {
binary: true
}
Expand Down
6 changes: 6 additions & 0 deletions packages/xrpl/test/integration/requests/ledgerEntry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ describe('ledger_entry', function () {
})

assert.isDefined(ledgerEntryResponse.result.node)
assert.isDefined(ledgerEntryResponse.result.node.OwnerCount)
// @ts-expect-error - Owner is not present in the AccountRoot response
assert.isUndefined(ledgerEntryResponse.result.node.Owner)
// @ts-expect-error - node_binary is not present in the response
assert.isUndefined(ledgerEntryResponse.result.node_binary)
},
Expand All @@ -86,6 +89,9 @@ describe('ledger_entry', function () {
})

assert.isDefined(ledgerEntryResponse.result.node)
assert.isDefined(ledgerEntryResponse.result.node.OwnerCount)
// @ts-expect-error - Owner is not present in the AccountRoot response
assert.isUndefined(ledgerEntryResponse.result.node.Owner)
// @ts-expect-error - node_binary is not present in the response
assert.isUndefined(ledgerEntryResponse.result.node_binary)
},
Expand Down
18 changes: 7 additions & 11 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,17 +161,15 @@ 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,
'9223372036854775807',
)
Expand All @@ -198,7 +195,6 @@ describe('Clawback', function () {
})

assert.equal(
// @ts-expect-error: Known issue with unknown object type
ledgerEntryResponse.result.node.MPTAmount,
'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
Loading
Loading