mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-04-29 15:37:50 +00:00
Merge branch 'main' into amm
This commit is contained in:
18001
package-lock.json
generated
18001
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -51,7 +51,7 @@
|
||||
"https-browserify": "^1.0.0",
|
||||
"jest": "^29.3.1",
|
||||
"jest-mock": "^29.3.1",
|
||||
"lerna": "^4.0.0",
|
||||
"lerna": "^6.6.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15",
|
||||
"path-browserify": "1.0.1",
|
||||
@@ -67,7 +67,7 @@
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.4.2",
|
||||
"url": "^0.11.0",
|
||||
"webpack": "^5.6.0",
|
||||
"webpack": "^5.81.0",
|
||||
"webpack-bundle-analyzer": "^4.1.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
},
|
||||
|
||||
@@ -93,6 +93,11 @@ import {
|
||||
NFTBuyOffersResponse,
|
||||
NFTSellOffersRequest,
|
||||
NFTSellOffersResponse,
|
||||
// clio only methods
|
||||
NFTInfoRequest,
|
||||
NFTInfoResponse,
|
||||
NFTHistoryRequest,
|
||||
NFTHistoryResponse,
|
||||
} from '../models/methods'
|
||||
import { BaseRequest, BaseResponse } from '../models/methods/baseMethod'
|
||||
import {
|
||||
@@ -320,6 +325,8 @@ class Client extends EventEmitter {
|
||||
public async request(r: ManifestRequest): Promise<ManifestResponse>
|
||||
public async request(r: NFTBuyOffersRequest): Promise<NFTBuyOffersResponse>
|
||||
public async request(r: NFTSellOffersRequest): Promise<NFTSellOffersResponse>
|
||||
public async request(r: NFTInfoRequest): Promise<NFTInfoResponse>
|
||||
public async request(r: NFTHistoryRequest): Promise<NFTHistoryResponse>
|
||||
public async request(r: NoRippleCheckRequest): Promise<NoRippleCheckResponse>
|
||||
public async request(r: PathFindRequest): Promise<PathFindResponse>
|
||||
public async request(r: PingRequest): Promise<PingResponse>
|
||||
|
||||
@@ -117,3 +117,21 @@ export interface NFTOffer {
|
||||
destination?: string
|
||||
expiration?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* One NFToken that might be returned from either an {@link NFTInfoResponse}
|
||||
*
|
||||
* @category Responses
|
||||
*/
|
||||
export interface NFToken {
|
||||
nft_id: string
|
||||
ledger_index: number
|
||||
owner: string
|
||||
is_burned: boolean
|
||||
flags: number
|
||||
transfer_fee: number
|
||||
issuer: string
|
||||
nft_taxon: number
|
||||
nft_serial: number
|
||||
uri: string
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ import { LedgerDataRequest, LedgerDataResponse } from './ledgerData'
|
||||
import { LedgerEntryRequest, LedgerEntryResponse } from './ledgerEntry'
|
||||
import { ManifestRequest, ManifestResponse } from './manifest'
|
||||
import { NFTBuyOffersRequest, NFTBuyOffersResponse } from './nftBuyOffers'
|
||||
import { NFTHistoryRequest, NFTHistoryResponse } from './nftHistory'
|
||||
import { NFTInfoRequest, NFTInfoResponse } from './nftInfo'
|
||||
import { NFTSellOffersRequest, NFTSellOffersResponse } from './nftSellOffers'
|
||||
import { NoRippleCheckRequest, NoRippleCheckResponse } from './norippleCheck'
|
||||
import {
|
||||
@@ -73,7 +75,6 @@ import {
|
||||
} from './transactionEntry'
|
||||
import { TxRequest, TxResponse } from './tx'
|
||||
import { UnsubscribeRequest, UnsubscribeResponse } from './unsubscribe'
|
||||
|
||||
/**
|
||||
* @category Requests
|
||||
*/
|
||||
@@ -122,6 +123,9 @@ type Request =
|
||||
// NFT methods
|
||||
| NFTBuyOffersRequest
|
||||
| NFTSellOffersRequest
|
||||
// clio only methods
|
||||
| NFTInfoRequest
|
||||
| NFTHistoryRequest
|
||||
|
||||
/**
|
||||
* @category Responses
|
||||
@@ -171,6 +175,9 @@ type Response =
|
||||
// NFT methods
|
||||
| NFTBuyOffersResponse
|
||||
| NFTSellOffersResponse
|
||||
// clio only methods
|
||||
| NFTInfoResponse
|
||||
| NFTHistoryResponse
|
||||
|
||||
export {
|
||||
Request,
|
||||
@@ -268,4 +275,9 @@ export {
|
||||
NFTBuyOffersResponse,
|
||||
NFTSellOffersRequest,
|
||||
NFTSellOffersResponse,
|
||||
// clio only methods
|
||||
NFTInfoRequest,
|
||||
NFTInfoResponse,
|
||||
NFTHistoryRequest,
|
||||
NFTHistoryResponse,
|
||||
}
|
||||
|
||||
117
packages/xrpl/src/models/methods/nftHistory.ts
Normal file
117
packages/xrpl/src/models/methods/nftHistory.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { LedgerIndex, ResponseOnlyTxInfo } from '../common'
|
||||
import { Transaction, TransactionMetadata } from '../transactions'
|
||||
|
||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||
|
||||
/**
|
||||
* The nft_history method retrieves a list of transactions that involved the
|
||||
* specified NFToken. Expects a response in the form of a {@link
|
||||
* NFTHistoryResponse}.
|
||||
*
|
||||
* @category Requests
|
||||
*/
|
||||
export interface NFTHistoryRequest extends BaseRequest {
|
||||
command: 'nft_history'
|
||||
/**
|
||||
* The unique identifier of an NFToken.
|
||||
*/
|
||||
nft_id: string
|
||||
/**
|
||||
* Use to specify the earliest ledger to include transactions from. A value
|
||||
* of -1 instructs the server to use the earliest validated ledger version
|
||||
* available.
|
||||
*/
|
||||
ledger_index_min?: number
|
||||
/**
|
||||
* Use to specify the most recent ledger to include transactions from. A
|
||||
* value of -1 instructs the server to use the most recent validated ledger
|
||||
* version available.
|
||||
*/
|
||||
ledger_index_max?: number
|
||||
/** Use to look for transactions from a single ledger only. */
|
||||
ledger_hash?: string
|
||||
/** Use to look for transactions from a single ledger only. */
|
||||
ledger_index?: LedgerIndex
|
||||
/**
|
||||
* If true, return transactions as hex strings instead of JSON. The default is
|
||||
* false.
|
||||
*/
|
||||
binary?: boolean
|
||||
/**
|
||||
* If true, returns values indexed with the oldest ledger first. Otherwise,
|
||||
* the results are indexed with the newest ledger first.
|
||||
*/
|
||||
forward?: boolean
|
||||
/**
|
||||
* Default varies. Limit the number of transactions to retrieve. The server
|
||||
* is not required to honor this value.
|
||||
*/
|
||||
limit?: number
|
||||
/**
|
||||
* Value from a previous paginated response. Resume retrieving data where
|
||||
* that response left off. This value is stable even if there is a change in
|
||||
* the server's range of available ledgers.
|
||||
*/
|
||||
marker?: unknown
|
||||
}
|
||||
|
||||
interface NFTokenTransaction {
|
||||
/** The ledger index of the ledger version that included this transaction. */
|
||||
ledger_index: number
|
||||
/**
|
||||
* If binary is True, then this is a hex string of the transaction metadata.
|
||||
* Otherwise, the transaction metadata is included in JSON format.
|
||||
*/
|
||||
meta: string | TransactionMetadata
|
||||
/** JSON object defining the transaction. */
|
||||
tx?: Transaction & ResponseOnlyTxInfo
|
||||
/** Unique hashed String representing the transaction. */
|
||||
tx_blob?: string
|
||||
/**
|
||||
* Whether or not the transaction is included in a validated ledger. Any
|
||||
* transaction not yet in a validated ledger is subject to change.
|
||||
*/
|
||||
validated: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Expected response from an {@link NFTHistoryRequest}.
|
||||
*
|
||||
* @category Responses
|
||||
*/
|
||||
export interface NFTHistoryResponse extends BaseResponse {
|
||||
result: {
|
||||
/**
|
||||
* The unique identifier of an NFToken.
|
||||
*/
|
||||
nft_id: string
|
||||
/**
|
||||
* The ledger index of the earliest ledger actually searched for
|
||||
* transactions.
|
||||
*/
|
||||
ledger_index_min: number
|
||||
/**
|
||||
* The ledger index of the most recent ledger actually searched for
|
||||
* transactions.
|
||||
*/
|
||||
ledger_index_max: number
|
||||
/** The limit value used in the request. */
|
||||
limit?: number
|
||||
/**
|
||||
* Server-defined value indicating the response is paginated. Pass this
|
||||
* to the next call to resume where this call left off.
|
||||
*/
|
||||
marker?: unknown
|
||||
/**
|
||||
* Array of transactions matching the request's criteria, as explained
|
||||
* below.
|
||||
*/
|
||||
transactions: NFTokenTransaction[]
|
||||
/**
|
||||
* If included and set to true, the information in this response comes from
|
||||
* a validated ledger version. Otherwise, the information is subject to
|
||||
* change.
|
||||
*/
|
||||
validated?: boolean
|
||||
}
|
||||
}
|
||||
33
packages/xrpl/src/models/methods/nftInfo.ts
Normal file
33
packages/xrpl/src/models/methods/nftInfo.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { LedgerIndex, NFToken } from '../common'
|
||||
|
||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||
|
||||
/**
|
||||
* The `nft_info` method retrieves information about NFToken
|
||||
* NFToken.
|
||||
*
|
||||
* @category Requests
|
||||
*/
|
||||
export interface NFTInfoRequest extends BaseRequest {
|
||||
command: 'nft_info'
|
||||
/**
|
||||
* The unique identifier of an NFToken.
|
||||
*/
|
||||
nft_id: string
|
||||
/** A 20-byte hex string for the ledger version to use. */
|
||||
ledger_hash?: string
|
||||
/**
|
||||
* The ledger index of the ledger to use, or a shortcut string to choose a
|
||||
* ledger automatically.
|
||||
*/
|
||||
ledger_index?: LedgerIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Response expected from an {@link NFTInfoResponse}.
|
||||
*
|
||||
* @category Responses
|
||||
*/
|
||||
export interface NFTInfoResponse extends BaseResponse {
|
||||
result: NFToken
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { decode, encode } from 'ripple-binary-codec'
|
||||
|
||||
import type { Client, SubmitRequest, SubmitResponse, Wallet } from '..'
|
||||
import { ValidationError, XrplError } from '../errors'
|
||||
import { Signer } from '../models/common'
|
||||
import { TxResponse } from '../models/methods'
|
||||
import { Transaction } from '../models/transactions'
|
||||
import { hashes } from '../utils'
|
||||
@@ -222,10 +223,26 @@ async function waitForFinalTransactionOutcome(
|
||||
// checks if the transaction has been signed
|
||||
function isSigned(transaction: Transaction | string): boolean {
|
||||
const tx = typeof transaction === 'string' ? decode(transaction) : transaction
|
||||
return (
|
||||
typeof tx !== 'string' &&
|
||||
(tx.SigningPubKey != null || tx.TxnSignature != null)
|
||||
)
|
||||
if (typeof tx === 'string') {
|
||||
return false
|
||||
}
|
||||
if (tx.Signers != null) {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know that tx.Signers is an array of Signers
|
||||
const signers = tx.Signers as Signer[]
|
||||
for (const signer of signers) {
|
||||
// eslint-disable-next-line max-depth -- necessary for checking if signer is signed
|
||||
if (
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- necessary check
|
||||
signer.Signer.SigningPubKey == null ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- necessary check
|
||||
signer.Signer.TxnSignature == null
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return tx.SigningPubKey != null && tx.TxnSignature != null
|
||||
}
|
||||
|
||||
// initializes a transaction for a submit request
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions -- error type thrown can be any */
|
||||
import { assert } from 'chai'
|
||||
import cloneDeep from 'lodash/cloneDeep'
|
||||
|
||||
import { ValidationError } from '../../src'
|
||||
import { multisign, ValidationError } from '../../src'
|
||||
import { Transaction } from '../../src/models/transactions'
|
||||
import Wallet from '../../src/Wallet'
|
||||
import rippled from '../fixtures/rippled'
|
||||
@@ -56,7 +57,6 @@ describe('client.submit', function () {
|
||||
const response = await testContext.client.submit(tx, { wallet })
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- error type thrown can be any
|
||||
assert(false, `Did not expect an error to be thrown: ${error}`)
|
||||
}
|
||||
})
|
||||
@@ -114,7 +114,31 @@ describe('client.submit', function () {
|
||||
const response = await testContext.client.submit(signedTxEncoded)
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- error type thrown can be any
|
||||
assert(false, `Did not expect an error to be thrown: ${error}`)
|
||||
}
|
||||
})
|
||||
|
||||
it('should submit a multisigned transaction', async function () {
|
||||
const signerWallet1 = Wallet.generate()
|
||||
const signerWallet2 = Wallet.generate()
|
||||
const accountSetTx: Transaction = {
|
||||
TransactionType: 'AccountSet',
|
||||
Account: 'rhvh5SrgBL5V8oeV9EpDuVszeJSSCEkbPc',
|
||||
Sequence: 1,
|
||||
Fee: '12',
|
||||
LastLedgerSequence: 12312,
|
||||
}
|
||||
|
||||
testContext.mockRippled!.addResponse('submit', rippled.submit.success)
|
||||
|
||||
const signed1 = signerWallet1.sign(accountSetTx, true)
|
||||
const signed2 = signerWallet2.sign(accountSetTx, true)
|
||||
const multisignedTxEncoded = multisign([signed1.tx_blob, signed2.tx_blob])
|
||||
|
||||
try {
|
||||
const response = await testContext.client.submit(multisignedTxEncoded)
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (error) {
|
||||
assert(false, `Did not expect an error to be thrown: ${error}`)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user