From 456eac0628ad1ef2bd53104449809c7ca62f50df Mon Sep 17 00:00:00 2001 From: tequ <69445828+develoQ@users.noreply.github.com> Date: Thu, 8 Jun 2023 22:21:37 +0900 Subject: [PATCH 1/2] feat: Add generics of TransactionType for TxResponse (#2332) * add generics of TransactionType for TxResponse * add generics to submitAndWait * add xrpl.js history --- packages/xrpl/HISTORY.md | 1 + packages/xrpl/src/models/methods/tx.ts | 6 ++++-- packages/xrpl/src/sugar/submit.ts | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 3e0bee83..d30044a5 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -13,6 +13,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Fixed the location of `signer_lists` in the `account_info` response so that it matches rippled * Guard check for signing algorithm used in `Wallet.generate()` * Null and undefined values in transactions are now treated as though the field was not passed in. +* Improved the type definition of the return value of `submitAndWait()`. ### Removed * RPCs and utils related to the old sidechain design diff --git a/packages/xrpl/src/models/methods/tx.ts b/packages/xrpl/src/models/methods/tx.ts index 3ef586a6..6109255e 100644 --- a/packages/xrpl/src/models/methods/tx.ts +++ b/packages/xrpl/src/models/methods/tx.ts @@ -1,4 +1,5 @@ import { Transaction, TransactionMetadata } from '../transactions' +import { BaseTransaction } from '../transactions/common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -38,7 +39,8 @@ export interface TxRequest extends BaseRequest { * * @category Responses */ -export interface TxResponse extends BaseResponse { +export interface TxResponse + extends BaseResponse { result: { /** The SHA-512 hash of the transaction. */ hash: string @@ -55,7 +57,7 @@ export interface TxResponse extends BaseResponse { * This number measures the number of seconds since the "Ripple Epoch" of January 1, 2000 (00:00 UTC) */ date?: number - } & Transaction + } & T /** * If true, the server was able to search all of the specified ledger * versions, and the transaction was in none of them. If false, the server did diff --git a/packages/xrpl/src/sugar/submit.ts b/packages/xrpl/src/sugar/submit.ts index 2fac20b3..e1e44bc3 100644 --- a/packages/xrpl/src/sugar/submit.ts +++ b/packages/xrpl/src/sugar/submit.ts @@ -3,8 +3,9 @@ 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 { TxRequest, TxResponse } from '../models/methods' import { Transaction } from '../models/transactions' +import { BaseTransaction } from '../models/transactions/common' import { hashes } from '../utils' /** Approximate time for a ledger to close, in milliseconds */ @@ -104,9 +105,9 @@ async function submit( * ledger, the promise returned by `submitAndWait()` will be rejected with an error. * @returns A promise that contains TxResponse, that will return when the transaction has been validated. */ -async function submitAndWait( +async function submitAndWait( this: Client, - transaction: Transaction | string, + transaction: T | string, opts?: { // If true, autofill a transaction. autofill?: boolean @@ -115,7 +116,7 @@ async function submitAndWait( // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction. wallet?: Wallet }, -): Promise { +): Promise> { const signedTx = await getSignedTx(this, transaction, opts) const lastLedger = getLastLedgerSequence(signedTx) @@ -167,12 +168,14 @@ async function submitRequest( * latest ledger sequence (meaning it will never be included in a validated ledger). */ // eslint-disable-next-line max-params, max-lines-per-function -- this function needs to display and do with more information. -async function waitForFinalTransactionOutcome( +async function waitForFinalTransactionOutcome< + T extends BaseTransaction = Transaction, +>( client: Client, txHash: string, lastLedger: number, submissionResult: string, -): Promise { +): Promise> { await sleep(LEDGER_CLOSE_TIME) const latestLedger = await client.getLedgerIndex() @@ -185,7 +188,7 @@ async function waitForFinalTransactionOutcome( } const txResponse = await client - .request({ + .request>({ command: 'tx', transaction: txHash, }) @@ -194,7 +197,7 @@ async function waitForFinalTransactionOutcome( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions,@typescript-eslint/no-unsafe-member-access -- ^ const message = error?.data?.error as string if (message === 'txnNotFound') { - return waitForFinalTransactionOutcome( + return waitForFinalTransactionOutcome( client, txHash, lastLedger, @@ -212,7 +215,7 @@ async function waitForFinalTransactionOutcome( return txResponse } - return waitForFinalTransactionOutcome( + return waitForFinalTransactionOutcome( client, txHash, lastLedger, From 44995a7e49d2af473a0eaf55b236fe0bb775fac3 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 9 Jun 2023 17:07:18 -0400 Subject: [PATCH 2/2] feat: add support for sidechain devnet faucet (#2336) * add sidechain faucet info * add test * update changelog * fix changelog --- packages/xrpl/HISTORY.md | 5 ++++- packages/xrpl/src/Wallet/defaultFaucets.ts | 12 ++++++++++++ packages/xrpl/test/integration/fundWallet.test.ts | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index d30044a5..a85f5232 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -13,7 +13,10 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Fixed the location of `signer_lists` in the `account_info` response so that it matches rippled * Guard check for signing algorithm used in `Wallet.generate()` * Null and undefined values in transactions are now treated as though the field was not passed in. -* Improved the type definition of the return value of `submitAndWait()`. +* Improved the type definition of the return value of `submitAndWait()` + +### Changed +* Added sidechain devnet support to faucet generation ### Removed * RPCs and utils related to the old sidechain design diff --git a/packages/xrpl/src/Wallet/defaultFaucets.ts b/packages/xrpl/src/Wallet/defaultFaucets.ts index 56b6c158..78197089 100644 --- a/packages/xrpl/src/Wallet/defaultFaucets.ts +++ b/packages/xrpl/src/Wallet/defaultFaucets.ts @@ -16,6 +16,7 @@ export enum FaucetNetwork { Devnet = 'faucet.devnet.rippletest.net', AMMDevnet = 'ammfaucet.devnet.rippletest.net', HooksV3Testnet = 'hooks-testnet-v3.xrpl-labs.com', + SidechainDevnet = 'sidechain-faucet.devnet.rippletest.net', } export const FaucetNetworkPaths: Record = { @@ -23,6 +24,7 @@ export const FaucetNetworkPaths: Record = { [FaucetNetwork.Devnet]: '/accounts', [FaucetNetwork.AMMDevnet]: '/accounts', [FaucetNetwork.HooksV3Testnet]: '/accounts', + [FaucetNetwork.SidechainDevnet]: '/accounts', } /** @@ -48,6 +50,16 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined { return FaucetNetwork.AMMDevnet } + if (connectionUrl.includes('sidechain-net1')) { + return FaucetNetwork.SidechainDevnet + } + + if (connectionUrl.includes('sidechain-net2')) { + throw new XRPLFaucetError( + 'Cannot fund an account on an issuing chain. Accounts must be created via the bridge.', + ) + } + if (connectionUrl.includes('devnet')) { return FaucetNetwork.Devnet } diff --git a/packages/xrpl/test/integration/fundWallet.test.ts b/packages/xrpl/test/integration/fundWallet.test.ts index 1a0d357b..4cf3309a 100644 --- a/packages/xrpl/test/integration/fundWallet.test.ts +++ b/packages/xrpl/test/integration/fundWallet.test.ts @@ -122,6 +122,16 @@ describe('fundWallet', function () { TIMEOUT, ) + it( + 'can generate and fund wallets on sidechain devnet', + async function () { + await generate_faucet_wallet_and_fund_again( + 'wss://sidechain-net1.devnet.rippletest.net:51233', + ) + }, + TIMEOUT, + ) + it( 'submit funds wallet with custom amount', async function () {