XRPL API changes 4.0.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PaymentTx_T, ParameterizedFunction, Payload, RJSVM, RJSVM_Config, RJSVM_Implementations, Function_Map, Endpoints_Of, State_Of, Generic_Ctor_ReturnType, RJSVM_Endpoint } from "./types"
|
||||
import { Client as Xrpl } from 'xrpl';
|
||||
import { AccountTxTransaction, Client as Xrpl } from 'xrpl';
|
||||
import { xrpIO } from 'xrpio';
|
||||
import { DataParser } from "../../util/dataparser";
|
||||
import { XRP_ADDRESS } from "../../util/protocol.constants";
|
||||
@@ -151,7 +151,8 @@ export abstract class RJSVM_Builder {
|
||||
}
|
||||
}
|
||||
|
||||
private parseMemos = async (tx:PaymentTx_T, memos: any[]) => {
|
||||
private parseMemos = async (tx:PaymentTx_T) => {
|
||||
const memos = tx.Memos
|
||||
memos
|
||||
.map((memo: any) => {
|
||||
if (!memo.Memo || !memo.Memo.MemoData) {
|
||||
@@ -191,12 +192,27 @@ export abstract class RJSVM_Builder {
|
||||
})
|
||||
|
||||
//results may not be ordered, so sort them
|
||||
const raw_txs = resp.result.transactions
|
||||
.sort((a,b) => a.tx.ledger_index - b.tx.ledger_index)
|
||||
.map((entry: any) => entry.tx)
|
||||
|
||||
//apply any state changes
|
||||
await Promise.all(raw_txs.map((tx: PaymentTx_T) => this.parseMemos(tx, tx.Memos)))
|
||||
const raw_txs = await Promise.all(
|
||||
resp.result.transactions
|
||||
.filter(tx => tx.tx_json.TransactionType === "Payment")
|
||||
.sort((a,b) => a.tx_json.ledger_index - b.tx_json.ledger_index)
|
||||
.map((tx) => this.xrpIO.getTransaction(tx.hash))
|
||||
)
|
||||
|
||||
//XRPL API update adaption
|
||||
await Promise.all(
|
||||
raw_txs
|
||||
.filter(tx => !!tx.result.tx_json.Memos)
|
||||
.map(tx => {
|
||||
return({
|
||||
...tx.result.tx_json,
|
||||
hash: tx.result.hash,
|
||||
Amount: tx.result.tx_json["DeliverMax"],
|
||||
inLedger: tx.result.tx_json['ledger_index']
|
||||
} as PaymentTx_T)
|
||||
})
|
||||
.map(tx => this.parseMemos(tx))
|
||||
)
|
||||
|
||||
//if marker is present the result is paginated.
|
||||
//re-run the same request with the marker included
|
||||
|
||||
@@ -20,7 +20,25 @@ let owner_datawriter: Datawriter
|
||||
|
||||
const setup = async () => {
|
||||
|
||||
[ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
|
||||
// [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
|
||||
[ownerWallet, listeningWallet, userWallet, drainWallet] = [
|
||||
{
|
||||
secret: 'sEd7tPDHFk3w7ABSaCPYi12iwucMQLt',
|
||||
address: 'rDML7QhJeVxZTwsjPtm4iyLUJTCzzuppMo'
|
||||
},
|
||||
{
|
||||
secret: 'sEdSgbyouvLM26vq2F2XthfKGWndP72',
|
||||
address: 'rPvwbb4JHncG9rKVrYATJw6HRixR69wgjg'
|
||||
},
|
||||
{
|
||||
secret: 'sEd7c1Y8JwWyA2owbchMWnuzAhB3ypY',
|
||||
address: 'rwuuWdyxwf3o78Ce2DAZrYCQ12SSawTp6M'
|
||||
},
|
||||
{
|
||||
secret: 'sEdScantwGA5gYe4atKPbG5bsriURpf',
|
||||
address: 'rDiwSioTRyV29rNk2FskxqFtMaRsmWvS7C'
|
||||
}
|
||||
]
|
||||
|
||||
owner_datawriter = new Datawriter({
|
||||
receiveAddress: drainWallet.address,
|
||||
@@ -44,7 +62,7 @@ const setup = async () => {
|
||||
// #########################
|
||||
// Define parameter types
|
||||
// #########################
|
||||
|
||||
|
||||
const shoutSchema = z.object({
|
||||
title: z.string(),
|
||||
body: z.string(),
|
||||
@@ -78,8 +96,8 @@ const setup = async () => {
|
||||
// #########################
|
||||
|
||||
abstract class RJSVM_Base
|
||||
extends RJSVM<State, RJSVM_Endpoints>
|
||||
implements RJSVM_Interface<RJSVM_Base> {
|
||||
extends RJSVM<State, RJSVM_Endpoints>
|
||||
implements RJSVM_Interface<RJSVM_Base> {
|
||||
owner = ownerWallet.address
|
||||
|
||||
state: State = {
|
||||
@@ -122,7 +140,7 @@ const setup = async () => {
|
||||
// #########################
|
||||
// Build and connect
|
||||
// #########################
|
||||
|
||||
|
||||
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
|
||||
|
||||
const conf: RJSVM_Config = {
|
||||
@@ -135,6 +153,6 @@ const setup = async () => {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await setup()
|
||||
await owner_datawriter.callEndpoint('submit', { title: "1", body: "2", from: "3" }, 100)
|
||||
await setup()
|
||||
await owner_datawriter.callEndpoint('submit', { title: "1", body: "2", from: "3" }, 100)
|
||||
})()
|
||||
Reference in New Issue
Block a user