mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Rename RippleAPI client to Client (#1520)
* rename RippleAPI -> XrplClient * more renames * move API stuff to client folder * rename all api -> client * fix tests * make tests run * fix integ tests * fix urls * fix merge issues * XrplClient -> Client * fix merge issues * rename xrpl-client npm symlink to xrpl-local
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import {RippleAPI} from '../../dist/npm'
|
||||
import {Client} from '../../dist/npm'
|
||||
|
||||
const api = new RippleAPI({
|
||||
const client = new Client({
|
||||
server: 'wss://s.altnet.rippletest.net:51233'
|
||||
})
|
||||
|
||||
getTransaction()
|
||||
|
||||
async function getTransaction() {
|
||||
await api.connect()
|
||||
const ledger = await api.getLedger({includeTransactions: true})
|
||||
await client.connect()
|
||||
const ledger = await client.getLedger({includeTransactions: true})
|
||||
console.log(ledger)
|
||||
const tx = await api.getTransaction(ledger.transactionHashes[0])
|
||||
const tx = await client.getTransaction(ledger.transactionHashes[0])
|
||||
console.log(tx)
|
||||
console.log('deliveredAmount:', tx.outcome.deliveredAmount)
|
||||
process.exit(0)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {RippleAPI} from '../../dist/npm'
|
||||
import {Client} from '../../dist/npm'
|
||||
|
||||
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
const client = new Client({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
|
||||
parseAccountFlags()
|
||||
|
||||
async function parseAccountFlags() {
|
||||
await api.connect()
|
||||
const account_info = await api.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'})
|
||||
const flags = api.parseAccountFlags(account_info.account_data.Flags)
|
||||
await client.connect()
|
||||
const account_info = await client.request('account_info', {account: 'rKsdkGhyZH6b2Zzd5hNnEqSv2wpznn4n6N'})
|
||||
const flags = client.parseAccountFlags(account_info.account_data.Flags)
|
||||
console.log(JSON.stringify(flags, null, 2))
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {RippleAPI} from '../../dist/npm'
|
||||
import {Client} from '../../dist/npm'
|
||||
|
||||
const api = new RippleAPI({
|
||||
const client = new Client({
|
||||
// server: 'wss://s.altnet.rippletest.net:51233'
|
||||
// server: 'ws://35.158.96.209:51233'
|
||||
server: 'ws://34.210.87.206:51233'
|
||||
@@ -9,7 +9,7 @@ const api = new RippleAPI({
|
||||
sign()
|
||||
|
||||
async function sign() {
|
||||
await api.connect()
|
||||
await client.connect()
|
||||
const pathfind: any = {
|
||||
source: {
|
||||
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
@@ -27,14 +27,14 @@ async function sign() {
|
||||
}
|
||||
}
|
||||
|
||||
await api.getPaths(pathfind).then(async (data) => {
|
||||
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 api.preparePayment('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', pathfind).then(ret => {
|
||||
const signed = api.sign(ret.txJSON, fakeSecret)
|
||||
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))
|
||||
@@ -43,5 +43,5 @@ async function sign() {
|
||||
console.log('ERR 2:', err)
|
||||
})
|
||||
|
||||
api.disconnect()
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
RippleAPI,
|
||||
Client,
|
||||
AccountInfoResponse,
|
||||
LedgerClosedEvent
|
||||
} from '../../dist/npm'
|
||||
@@ -68,16 +68,16 @@ async function reliableTransactionSubmissionExample() {
|
||||
async function performPayments(payments) {
|
||||
const finalResults = []
|
||||
const txFinalizedPromises = []
|
||||
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
await api.connect()
|
||||
const client = new Client({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
await client.connect()
|
||||
|
||||
for (let i = 0; i < payments.length; i++) {
|
||||
const payment = payments[i]
|
||||
const account_info: AccountInfoResponse = await api.request('account_info', {
|
||||
const account_info: AccountInfoResponse = await client.request('account_info', {
|
||||
account: payment.source.classicAddress,
|
||||
ledger_index: 'current'})
|
||||
const sequence = account_info.account_data.Sequence
|
||||
const preparedPayment = await api.preparePayment(payment.source.classicAddress, {
|
||||
const preparedPayment = await client.preparePayment(payment.source.classicAddress, {
|
||||
source: {
|
||||
address: payment.source.classicAddress,
|
||||
amount: {
|
||||
@@ -95,11 +95,11 @@ async function performPayments(payments) {
|
||||
}, {
|
||||
sequence
|
||||
})
|
||||
const signed = api.sign(preparedPayment.txJSON, payment.source.secret)
|
||||
const signed = client.sign(preparedPayment.txJSON, payment.source.secret)
|
||||
finalResults.push({
|
||||
id: signed.id
|
||||
})
|
||||
const result = await api.submit(signed.signedTransaction)
|
||||
const result = await client.submit(signed.signedTransaction)
|
||||
|
||||
// Most of the time we'll get 'tesSUCCESS' or (after many submissions) 'terQUEUED'
|
||||
console.log(`tx ${i} - tentative: ${result.resultCode}`)
|
||||
@@ -108,7 +108,7 @@ async function performPayments(payments) {
|
||||
const ledgerClosedCallback = async (event: LedgerClosedEvent) => {
|
||||
let status
|
||||
try {
|
||||
status = await api.getTransaction(signed.id)
|
||||
status = await client.getTransaction(signed.id)
|
||||
} catch (e) {
|
||||
// Typical error when the tx hasn't been validated yet:
|
||||
if (e.name !== 'MissingLedgerHistoryError') {
|
||||
@@ -125,7 +125,7 @@ async function performPayments(payments) {
|
||||
}
|
||||
} else {
|
||||
// Check again later:
|
||||
api.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ async function performPayments(payments) {
|
||||
}
|
||||
}
|
||||
}
|
||||
api.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
client.connection.once('ledgerClosed', ledgerClosedCallback)
|
||||
})
|
||||
txFinalizedPromises.push(txFinalizedPromise)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user