Docs: Snippets (#1729)

* refactor: adds snippets for sendEscrow, claimPayChannel, reliableSubmission, getTransaction, partialPayment, getPaths
This commit is contained in:
Mukul Jangid
2021-10-20 12:29:48 -04:00
committed by GitHub
parent d1b34bb458
commit 910a5999c9
17 changed files with 461 additions and 358 deletions

View File

@@ -1,63 +1,49 @@
// import {Client} from '../../dist/npm'
import { Client, Payment, RipplePathFindResponse } from '../../dist/npm'
/*
* const client = new Client(
* // 'wss://s.altnet.rippletest.net:51233'
* // 'ws://35.158.96.209:51233'
* 'ws://34.210.87.206:51233'
* )
*/
const client = new Client('wss://s.altnet.rippletest.net:51233')
// sign()
async function createTxWithPaths(): Promise<void> {
await client.connect()
/*
* async function sign() {
* await client.connect()
* const pathfind: any = {
* source: {
* address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
* amount: {
* currency: 'drops',
* value: '100'
* }
* },
* destination: {
* address: 'rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj',
* amount: {
* currency: 'USD',
* counterparty: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc'
* }
* }
* }
*/
const { wallet } = await client.fundWallet()
const destination_account = 'rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj'
const destination_amount = {
value: '0.001',
currency: 'USD',
issuer: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc',
}
/*
* await client
* .getPaths(pathfind)
* .then(async (data) => {
* console.log('paths:', JSON.stringify(data))
* const fakeSecret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
*/
const request = {
command: 'ripple_path_find',
source_account: wallet.classicAddress,
source_currencies: [
{
currency: 'XRP',
},
],
destination_account,
destination_amount,
}
/*
* pathfind.paths = data[0].paths
* pathfind.destination = data[0].destination
* await client
* .preparePayment('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', pathfind)
* .then((ret) => {
* const signed = client.sign(ret.txJSON, fakeSecret)
* console.log('signed:', signed)
* })
* .catch((err) => {
* console.log('ERR 1:', JSON.stringify(err))
* })
* })
* .catch((err) => {
* console.log('ERR 2:', err)
* })
*/
const resp: RipplePathFindResponse = await client.request(request)
console.log(resp)
/*
* client.disconnect()
* }
*/
const paths = resp.result.alternatives[0].paths_computed
console.log(paths)
const tx: Payment = {
TransactionType: 'Payment',
Account: wallet.classicAddress,
Amount: destination_amount,
Destination: destination_account,
Paths: paths,
}
await client.autofill(tx)
const signed = wallet.sign(tx)
console.log('signed:', signed)
await client.disconnect()
}
void createTxWithPaths()