Skip to content

Commit

Permalink
refactor: use submitAndWait instead of wait for some time
Browse files Browse the repository at this point in the history
  • Loading branch information
mukulljangid committed Oct 15, 2021
1 parent 3236614 commit da6150e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
15 changes: 3 additions & 12 deletions snippets/src/claimPayChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import {

const client = new Client('wss://s.altnet.rippletest.net:51233')

async function sleep(ms): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

void claimPayChannel()

async function claimPayChannel(): Promise<void> {
Expand All @@ -35,10 +29,11 @@ async function claimPayChannel(): Promise<void> {
PublicKey: wallet1.publicKey,
}

const paymentChannelResponse = await client.submit(
const paymentChannelResponse = await client.submitReliable(
wallet1,
paymentChannelCreate,
)
console.log(paymentChannelResponse)

// check that the object was actually created
const accountObjectsRequest: AccountObjectsRequest = {
Expand All @@ -51,17 +46,13 @@ async function claimPayChannel(): Promise<void> {

console.log(accountObjects)

// wait for one ledger close time.
const WAIT_TIME = 4000
await sleep(WAIT_TIME)

const paymentChannelClaim: PaymentChannelClaim = {
Account: wallet1.getClassicAddress(),
TransactionType: 'PaymentChannelClaim',
Channel: hashes.hashPaymentChannel(
wallet1.getClassicAddress(),
wallet2.getClassicAddress(),
paymentChannelResponse.result.tx_json.Sequence ?? 0,
paymentChannelResponse.result.Sequence ?? 0,
),
Amount: '100',
}
Expand Down
14 changes: 2 additions & 12 deletions snippets/src/sendEscrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ async function getXRPBalance(account: string): Promise<string> {
return (await client.request(request)).result.account_data.Balance
}

async function sleep(ms): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

void sendEscrow()

async function sendEscrow(): Promise<void> {
Expand All @@ -48,7 +42,7 @@ async function sendEscrow(): Promise<void> {
FinishAfter: finishAfter,
}

const createEscrowResponse = await client.submit(wallet1, createTx)
const createEscrowResponse = await client.submitReliable(wallet1, createTx)

console.log(createEscrowResponse)

Expand All @@ -66,15 +60,11 @@ async function sendEscrow(): Promise<void> {
)
console.log(accountObjects)

// wait for `finishAfter` to pass.
const WAIT_TIME = 4000
await sleep(WAIT_TIME)

const finishTx: EscrowFinish = {
TransactionType: 'EscrowFinish',
Account: wallet1.getClassicAddress(),
Owner: wallet1.getClassicAddress(),
OfferSequence: Number(createEscrowResponse.result.tx_json.Sequence),
OfferSequence: Number(createEscrowResponse.result.Sequence),
}

await client.submit(wallet1, finishTx)
Expand Down

0 comments on commit da6150e

Please sign in to comment.