mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
build: Initial linting setup (#1560)
* sets up linting config and runs `yarn lint --fix` once, so that all changes will show up correctly in future PRs. * Note that there are still a lot of linter errors.
This commit is contained in:
committed by
Mayukha Vadari
parent
cfa014c44b
commit
6742e2048a
@@ -1,9 +1,13 @@
|
||||
import * as codec from 'ripple-binary-codec'
|
||||
// import * as codec from 'ripple-binary-codec'
|
||||
|
||||
const original = codec.decode('12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900')
|
||||
// const original = codec.decode(
|
||||
// '12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900'
|
||||
// )
|
||||
|
||||
const test = codec.decode('12000022800200002400000017201B008694F261EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100D8B57E8E06EAE27B1343AF8CAD3F501E18260CCF8BCED08066074106F0F191A3022058FEA6CE9E7FA69D1244C3A70F18983CC2DAF0B10CBB86A6677CF2A5D2B8A68081145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900')
|
||||
// const test = codec.decode(
|
||||
// '12000022800200002400000017201B008694F261EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100D8B57E8E06EAE27B1343AF8CAD3F501E18260CCF8BCED08066074106F0F191A3022058FEA6CE9E7FA69D1244C3A70F18983CC2DAF0B10CBB86A6677CF2A5D2B8A68081145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900'
|
||||
// )
|
||||
|
||||
console.log('original:', JSON.stringify(original))
|
||||
// console.log('original:', JSON.stringify(original))
|
||||
|
||||
console.log('test:', JSON.stringify(test))
|
||||
// console.log('test:', JSON.stringify(test))
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import {Client} from '../../dist/npm'
|
||||
import { TransactionMetadata } from '../../src/models/common/transaction'
|
||||
// import {Client} from '../../dist/npm'
|
||||
// import {TransactionMetadata} from '../../src/models/common/transaction'
|
||||
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
// const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
|
||||
getTransaction()
|
||||
// getTransaction()
|
||||
|
||||
async function getTransaction() {
|
||||
await client.connect()
|
||||
const ledger = await client.request({command: 'ledger', transactions: true})
|
||||
console.log(ledger)
|
||||
const tx = await client.request({
|
||||
command: 'tx',
|
||||
transaction: ledger.result.ledger.transactions[0] as string
|
||||
})
|
||||
console.log(tx)
|
||||
console.log('deliveredAmount:', (tx.result.meta as TransactionMetadata).DeliveredAmount)
|
||||
process.exit(0)
|
||||
}
|
||||
// async function getTransaction() {
|
||||
// await client.connect()
|
||||
// const ledger = await client.request({command: 'ledger', transactions: true})
|
||||
// console.log(ledger)
|
||||
// const tx = await client.request({
|
||||
// command: 'tx',
|
||||
// transaction: ledger.result.ledger.transactions[0] as string
|
||||
// })
|
||||
// console.log(tx)
|
||||
// console.log(
|
||||
// 'deliveredAmount:',
|
||||
// (tx.result.meta as TransactionMetadata).DeliveredAmount
|
||||
// )
|
||||
// process.exit(0)
|
||||
// }
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import {Client} from '../../dist/npm'
|
||||
import { AccountFlags } from '../../dist/npm/common/constants'
|
||||
// import {Client} from '../../dist/npm'
|
||||
// import {AccountFlags} from '../../dist/npm/common/constants'
|
||||
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
// const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
|
||||
parseAccountFlags()
|
||||
// parseAccountFlags()
|
||||
|
||||
async function parseAccountFlags() {
|
||||
await client.connect()
|
||||
const account_info = await client.request({command: 'account_info', account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'})
|
||||
const flags = account_info.result.account_data.Flags
|
||||
for (const flagName in AccountFlags) {
|
||||
if (flags & AccountFlags[flagName]) {
|
||||
console.log(`${flagName} enabled`)
|
||||
}
|
||||
}
|
||||
process.exit(0)
|
||||
}
|
||||
// async function parseAccountFlags() {
|
||||
// await client.connect()
|
||||
// const account_info = await client.request({
|
||||
// command: 'account_info',
|
||||
// account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'
|
||||
// })
|
||||
// const flags = account_info.result.account_data.Flags
|
||||
// for (const flagName in AccountFlags) {
|
||||
// if (flags & AccountFlags[flagName]) {
|
||||
// console.log(`${flagName} enabled`)
|
||||
// }
|
||||
// }
|
||||
// process.exit(0)
|
||||
// }
|
||||
|
||||
@@ -1,47 +1,53 @@
|
||||
import {Client} from '../../dist/npm'
|
||||
// import {Client} 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'
|
||||
// // 'ws://35.158.96.209:51233'
|
||||
// 'ws://34.210.87.206:51233'
|
||||
// )
|
||||
|
||||
sign()
|
||||
// sign()
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
await client.getPaths(pathfind).then(async (data) => {
|
||||
console.log('paths:', JSON.stringify(data))
|
||||
const fakeSecret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
// await client
|
||||
// .getPaths(pathfind)
|
||||
// .then(async (data) => {
|
||||
// console.log('paths:', JSON.stringify(data))
|
||||
// const fakeSecret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
|
||||
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)
|
||||
})
|
||||
// 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)
|
||||
// })
|
||||
|
||||
client.disconnect()
|
||||
}
|
||||
// client.disconnect()
|
||||
// }
|
||||
|
||||
@@ -1,201 +1,215 @@
|
||||
import {
|
||||
Client,
|
||||
AccountInfoResponse,
|
||||
LedgerClosedEvent
|
||||
} from '../../dist/npm'
|
||||
import https = require('https')
|
||||
// import https = require('https')
|
||||
|
||||
/**
|
||||
* When implementing Reliable Transaction Submission, there are many potential solutions, each with different trade-offs. The main decision points are:
|
||||
* 1) Transaction preparation:
|
||||
* - How do we decide which account sequence and LastLedgerSequence numbers to use?
|
||||
* (To prevent unintentional duplicate transactions, an {account, account_sequence} pair can be used as a transaction's idempotency key)
|
||||
* - How do we decide how much to pay for the transaction fee? (If our transactions have been failing due to low fee, we should consider increasing this value)
|
||||
* 2) Transaction status retrieval. Options include:
|
||||
* - Poll for transaction status:
|
||||
* - On a regular interval (e.g. every 3-5 seconds), or
|
||||
* - When a new validated ledger is detected
|
||||
* + (To accommodate an edge case in transaction retrieval, check the sending account's Sequence number to confirm that it has the expected value;
|
||||
* alternatively, wait until a few additional ledgers have been validated before deciding that a transaction has definitively not been included in a validated ledger)
|
||||
* - Listen for transaction status: scan all validated transactions to see if our transactions are among them
|
||||
* 3) What do we do when a transaction fails? It is possible to implement retry logic, but caution is advised. Note that there are a few ways for a transaction to fail:
|
||||
* A) `tec`: The transaction was included in a ledger but only claimed the transaction fee
|
||||
* B) `tesSUCCESS` but unexpected result: The transaction was successful but did not have the expected result. This generally does not occur for XRP-to-XRP payments
|
||||
* C) The transaction was not, and never will be, included in a validated ledger [3C]
|
||||
*
|
||||
* References:
|
||||
* - https://xrpl.org/reliable-transaction-submission.html
|
||||
* - https://xrpl.org/send-xrp.html
|
||||
* - https://xrpl.org/look-up-transaction-results.html
|
||||
* - https://xrpl.org/get-started-with-rippleapi-for-javascript.html
|
||||
* - https://xrpl.org/monitor-incoming-payments-with-websocket.html
|
||||
*
|
||||
* For the implementation in this example, we have made the following decisions:
|
||||
* 1) The script will choose the account sequence and LastLedgerSequence numbers automatically. We allow ripple-lib to choose the fee.
|
||||
* Payments are defined upfront, and idempotency is not needed. If the script is run a second time, duplicate payments will result.
|
||||
* 2) We will listen for notification that a new validated ledger has been found, and poll for transaction status at that time.
|
||||
* Futhermore, as a precaution, we will wait until the server is 3 ledgers past the transaction's LastLedgerSequence
|
||||
* (with the transaction nowhere to be seen) before deciding that it has definitively failed per [3C]
|
||||
* 3) Transactions will not be automatically retried. Transactions are limited to XRP-to-XRP payments and cannot "succeed" in an unexpected way.
|
||||
*/
|
||||
reliableTransactionSubmissionExample()
|
||||
// import {Client, AccountInfoResponse, LedgerClosedEvent} from '../../dist/npm'
|
||||
|
||||
async function reliableTransactionSubmissionExample() {
|
||||
/**
|
||||
* Array of payments to execute.
|
||||
*
|
||||
* For brevity, these are XRP-to-XRP payments, taking a source, destination, and an amount in drops.
|
||||
*
|
||||
* The script will attempt to make all of these payments as quickly as possible, and report the final status of each. Transactions that fail are NOT retried.
|
||||
*/
|
||||
const payments = []
|
||||
// /**
|
||||
// * When implementing Reliable Transaction Submission, there are many potential solutions, each with different trade-offs. The main decision points are:
|
||||
// * 1) Transaction preparation:
|
||||
// * - How do we decide which account sequence and LastLedgerSequence numbers to use?
|
||||
// * (To prevent unintentional duplicate transactions, an {account, account_sequence} pair can be used as a transaction's idempotency key)
|
||||
// * - How do we decide how much to pay for the transaction fee? (If our transactions have been failing due to low fee, we should consider increasing this value)
|
||||
// * 2) Transaction status retrieval. Options include:
|
||||
// * - Poll for transaction status:
|
||||
// * - On a regular interval (e.g. Every 3-5 seconds), or
|
||||
// * - When a new validated ledger is detected
|
||||
// * + (To accommodate an edge case in transaction retrieval, check the sending account's Sequence number to confirm that it has the expected value;
|
||||
// * alternatively, wait until a few additional ledgers have been validated before deciding that a transaction has definitively not been included in a validated ledger)
|
||||
// * - Listen for transaction status: scan all validated transactions to see if our transactions are among them
|
||||
// * 3) What do we do when a transaction fails? It is possible to implement retry logic, but caution is advised. Note that there are a few ways for a transaction to fail:
|
||||
// * A) `tec`: The transaction was included in a ledger but only claimed the transaction fee
|
||||
// * B) `tesSUCCESS` but unexpected result: The transaction was successful but did not have the expected result. This generally does not occur for XRP-to-XRP payments
|
||||
// * C) The transaction was not, and never will be, included in a validated ledger [3C].
|
||||
// *
|
||||
// * References:
|
||||
// * - https://xrpl.org/reliable-transaction-submission.html
|
||||
// * - https://xrpl.org/send-xrp.html
|
||||
// * - https://xrpl.org/look-up-transaction-results.html
|
||||
// * - https://xrpl.org/get-started-with-rippleapi-for-javascript.html
|
||||
// * - https://xrpl.org/monitor-incoming-payments-with-websocket.html.
|
||||
// *
|
||||
// * For the implementation in this example, we have made the following decisions:
|
||||
// * 1) The script will choose the account sequence and LastLedgerSequence numbers automatically. We allow ripple-lib to choose the fee.
|
||||
// * Payments are defined upfront, and idempotency is not needed. If the script is run a second time, duplicate payments will result.
|
||||
// * 2) We will listen for notification that a new validated ledger has been found, and poll for transaction status at that time.
|
||||
// * Futhermore, as a precaution, we will wait until the server is 3 ledgers past the transaction's LastLedgerSequence
|
||||
// * (with the transaction nowhere to be seen) before deciding that it has definitively failed per [3C]
|
||||
// * 3) Transactions will not be automatically retried. Transactions are limited to XRP-to-XRP payments and cannot "succeed" in an unexpected way.
|
||||
// */
|
||||
// reliableTransactionSubmissionExample()
|
||||
|
||||
const sourceAccount = (await generateTestnetAccount()).account
|
||||
console.log(`Generated new Testnet account: ${sourceAccount.classicAddress}/${sourceAccount.secret}`)
|
||||
// Send amounts from 1 drop to 10 drops
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
payments.push({
|
||||
source: sourceAccount,
|
||||
destination: 'rhsoCozhUxwcyQgzFi1FVRoMVQgk7cZd4L', // Random Testnet destination
|
||||
amount_drops: i.toString(),
|
||||
})
|
||||
}
|
||||
const results = await performPayments(payments)
|
||||
console.log(JSON.stringify(results, null, 2))
|
||||
process.exit(0)
|
||||
}
|
||||
// async function reliableTransactionSubmissionExample() {
|
||||
// /**
|
||||
// * Array of payments to execute.
|
||||
// *
|
||||
// * For brevity, these are XRP-to-XRP payments, taking a source, destination, and an amount in drops.
|
||||
// *
|
||||
// * The script will attempt to make all of these payments as quickly as possible, and report the final status of each. Transactions that fail are NOT retried.
|
||||
// */
|
||||
// const payments = []
|
||||
|
||||
async function performPayments(payments) {
|
||||
const finalResults = []
|
||||
const txFinalizedPromises = []
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
await client.connect()
|
||||
// const sourceAccount = (await generateTestnetAccount()).account
|
||||
// console.log(
|
||||
// `Generated new Testnet account: ${sourceAccount.classicAddress}/${sourceAccount.secret}`
|
||||
// )
|
||||
// // Send amounts from 1 drop to 10 drops
|
||||
// for (let i = 1; i <= 10; i++) {
|
||||
// payments.push({
|
||||
// source: sourceAccount,
|
||||
// destination: 'rhsoCozhUxwcyQgzFi1FVRoMVQgk7cZd4L', // Random Testnet destination
|
||||
// amount_drops: i.toString()
|
||||
// })
|
||||
// }
|
||||
// const results = await performPayments(payments)
|
||||
// console.log(JSON.stringify(results, null, 2))
|
||||
// process.exit(0)
|
||||
// }
|
||||
|
||||
for (let i = 0; i < payments.length; i++) {
|
||||
const payment = payments[i]
|
||||
const account_info: AccountInfoResponse = await client.request({
|
||||
command: 'account_info',
|
||||
account: payment.source.classicAddress,
|
||||
ledger_index: 'current'})
|
||||
const sequence = account_info.result.account_data.Sequence
|
||||
const preparedPayment = await client.preparePayment(payment.source.classicAddress, {
|
||||
source: {
|
||||
address: payment.source.classicAddress,
|
||||
amount: {
|
||||
value: payment.amount_drops,
|
||||
currency: 'drops'
|
||||
}
|
||||
},
|
||||
destination: {
|
||||
address: payment.destination,
|
||||
minAmount: {
|
||||
value: payment.amount_drops,
|
||||
currency: 'drops'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
sequence
|
||||
})
|
||||
const signed = client.sign(preparedPayment.txJSON, payment.source.secret)
|
||||
finalResults.push({
|
||||
id: signed.id
|
||||
})
|
||||
const response = await client.request({command: 'submit', tx_blob: signed.signedTransaction})
|
||||
// async function performPayments(payments) {
|
||||
// const finalResults = []
|
||||
// const txFinalizedPromises = []
|
||||
// const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
// await client.connect()
|
||||
|
||||
// Most of the time we'll get 'tesSUCCESS' or (after many submissions) 'terQUEUED'
|
||||
console.log(`tx ${i} - tentative: ${response.result.engine_result}`)
|
||||
// for (let i = 0; i < payments.length; i++) {
|
||||
// const payment = payments[i]
|
||||
// const account_info: AccountInfoResponse = await client.request({
|
||||
// command: 'account_info',
|
||||
// account: payment.source.classicAddress,
|
||||
// ledger_index: 'current'
|
||||
// })
|
||||
// const sequence = account_info.result.account_data.Sequence
|
||||
// const preparedPayment = await client.preparePayment(
|
||||
// payment.source.classicAddress,
|
||||
// {
|
||||
// source: {
|
||||
// address: payment.source.classicAddress,
|
||||
// amount: {
|
||||
// value: payment.amount_drops,
|
||||
// currency: 'drops'
|
||||
// }
|
||||
// },
|
||||
// destination: {
|
||||
// address: payment.destination,
|
||||
// minAmount: {
|
||||
// value: payment.amount_drops,
|
||||
// currency: 'drops'
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// sequence
|
||||
// }
|
||||
// )
|
||||
// const signed = client.sign(preparedPayment.txJSON, payment.source.secret)
|
||||
// finalResults.push({
|
||||
// id: signed.id
|
||||
// })
|
||||
// const response = await client.request({
|
||||
// command: 'submit',
|
||||
// tx_blob: signed.signedTransaction
|
||||
// })
|
||||
|
||||
const txFinalizedPromise = new Promise<void>((resolve) => {
|
||||
const ledgerClosedCallback = async (event: LedgerClosedEvent) => {
|
||||
let status
|
||||
try {
|
||||
status = await client.request({command: 'tx', transaction: signed.id})
|
||||
} catch (e) {
|
||||
// Typical error when the tx hasn't been validated yet:
|
||||
if (e.name !== 'MissingLedgerHistoryError') {
|
||||
console.log(e)
|
||||
}
|
||||
// // Most of the time we'll get 'tesSUCCESS' or (after many submissions) 'terQUEUED'
|
||||
// console.log(`tx ${i} - tentative: ${response.result.engine_result}`)
|
||||
|
||||
if (event.ledger_index > preparedPayment.instructions.maxLedgerVersion + 3) {
|
||||
// Assumptions:
|
||||
// - We are still connected to the same rippled server
|
||||
// - No ledger gaps occurred
|
||||
// - All ledgers between the time we submitted the tx and now have been checked for the tx
|
||||
status = {
|
||||
finalResult: 'Transaction was not, and never will be, included in a validated ledger'
|
||||
}
|
||||
} else {
|
||||
// Check again later:
|
||||
client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
return
|
||||
}
|
||||
}
|
||||
// const txFinalizedPromise = new Promise<void>((resolve) => {
|
||||
// const ledgerClosedCallback = async (event: LedgerClosedEvent) => {
|
||||
// let status
|
||||
// try {
|
||||
// status = await client.request({command: 'tx', transaction: signed.id})
|
||||
// } catch (e) {
|
||||
// // Typical error when the tx hasn't been validated yet:
|
||||
// if (e.name !== 'MissingLedgerHistoryError') {
|
||||
// console.log(e)
|
||||
// }
|
||||
|
||||
for (let j = 0; j < finalResults.length; j++) {
|
||||
if (finalResults[j].id === signed.id) {
|
||||
finalResults[j].result = status.address ? {
|
||||
source: status.address,
|
||||
destination: status.specification.destination.address,
|
||||
deliveredAmount: status.outcome.deliveredAmount,
|
||||
result: status.outcome.result,
|
||||
timestamp: status.outcome.timestamp,
|
||||
ledgerVersion: status.outcome.ledgerVersion
|
||||
} : status
|
||||
process.stdout.write('.')
|
||||
return resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
})
|
||||
txFinalizedPromises.push(txFinalizedPromise)
|
||||
}
|
||||
await Promise.all(txFinalizedPromises)
|
||||
return finalResults
|
||||
}
|
||||
// if (
|
||||
// event.ledger_index >
|
||||
// preparedPayment.instructions.maxLedgerVersion + 3
|
||||
// ) {
|
||||
// // Assumptions:
|
||||
// // - We are still connected to the same rippled server
|
||||
// // - No ledger gaps occurred
|
||||
// // - All ledgers between the time we submitted the tx and now have been checked for the tx
|
||||
// status = {
|
||||
// finalResult:
|
||||
// 'Transaction was not, and never will be, included in a validated ledger'
|
||||
// }
|
||||
// } else {
|
||||
// // Check again later:
|
||||
// client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Generate a new Testnet account by requesting one from the faucet
|
||||
*/
|
||||
async function generateTestnetAccount(): Promise<{
|
||||
account: {
|
||||
xAddress: string,
|
||||
classicAddress, string,
|
||||
secret: string
|
||||
},
|
||||
balance: number
|
||||
}> {
|
||||
const options = {
|
||||
hostname: 'faucet.altnet.rippletest.net',
|
||||
port: 443,
|
||||
path: '/accounts',
|
||||
method: 'POST'
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = https.request(options, response => {
|
||||
const chunks = []
|
||||
response.on('data', d => {
|
||||
chunks.push(d)
|
||||
})
|
||||
response.on('end', () => {
|
||||
const body = Buffer.concat(chunks).toString()
|
||||
// for (let j = 0; j < finalResults.length; j++) {
|
||||
// if (finalResults[j].id === signed.id) {
|
||||
// finalResults[j].result = status.address
|
||||
// ? {
|
||||
// source: status.address,
|
||||
// destination: status.specification.destination.address,
|
||||
// deliveredAmount: status.outcome.deliveredAmount,
|
||||
// result: status.outcome.result,
|
||||
// timestamp: status.outcome.timestamp,
|
||||
// ledgerVersion: status.outcome.ledgerVersion
|
||||
// }
|
||||
// : status
|
||||
// process.stdout.write('.')
|
||||
// return resolve()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
// })
|
||||
// txFinalizedPromises.push(txFinalizedPromise)
|
||||
// }
|
||||
// await Promise.all(txFinalizedPromises)
|
||||
// return finalResults
|
||||
// }
|
||||
|
||||
// "application/json; charset=utf-8"
|
||||
if (response.headers['content-type'].startsWith('application/json')) {
|
||||
resolve(JSON.parse(body))
|
||||
} else {
|
||||
reject({
|
||||
statusCode: response.statusCode,
|
||||
contentType: response.headers['content-type'],
|
||||
body
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
request.on('error', error => {
|
||||
console.error(error)
|
||||
reject(error)
|
||||
})
|
||||
request.end()
|
||||
})
|
||||
}
|
||||
// /**
|
||||
// * Generate a new Testnet account by requesting one from the faucet.
|
||||
// */
|
||||
// async function generateTestnetAccount(): Promise<{
|
||||
// account: {
|
||||
// xAddress: string
|
||||
// classicAddress
|
||||
// string
|
||||
// secret: string
|
||||
// }
|
||||
// balance: number
|
||||
// }> {
|
||||
// const options = {
|
||||
// hostname: 'faucet.altnet.rippletest.net',
|
||||
// port: 443,
|
||||
// path: '/accounts',
|
||||
// method: 'POST'
|
||||
// }
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const request = https.request(options, (response) => {
|
||||
// const chunks = []
|
||||
// response.on('data', (d) => {
|
||||
// chunks.push(d)
|
||||
// })
|
||||
// response.on('end', () => {
|
||||
// const body = Buffer.concat(chunks).toString()
|
||||
|
||||
// // "application/json; charset=utf-8"
|
||||
// if (response.headers['content-type'].startsWith('application/json')) {
|
||||
// resolve(JSON.parse(body))
|
||||
// } else {
|
||||
// reject({
|
||||
// statusCode: response.statusCode,
|
||||
// contentType: response.headers['content-type'],
|
||||
// body
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// request.on('error', (error) => {
|
||||
// console.error(error)
|
||||
// reject(error)
|
||||
// })
|
||||
// request.end()
|
||||
// })
|
||||
// }
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../src" }
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user