XRPL API changes 4.0.0
This commit is contained in:
Generated
+942
-678
File diff suppressed because it is too large
Load Diff
+5
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rjsvm",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.5",
|
||||
"description": "",
|
||||
"main": "lib/src/main.js",
|
||||
"scripts": {
|
||||
@@ -15,10 +15,11 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
"stream-http": "^3.2.0",
|
||||
"url": "^0.11.3",
|
||||
"xrpio": "^0.2.1",
|
||||
"xrpl": "^2.7.0",
|
||||
"xrpio": "^0.3.0",
|
||||
"xrpl": "^4.0.0",
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -46,6 +47,7 @@
|
||||
"lib/src/main.js",
|
||||
"lib/src/main.d.ts",
|
||||
"lib/src/util/*",
|
||||
"lib/browser/rjsvm.browser.js",
|
||||
"lib/src/RJSVM/*"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
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))
|
||||
)
|
||||
|
||||
//apply any state changes
|
||||
await Promise.all(raw_txs.map((tx: PaymentTx_T) => this.parseMemos(tx, tx.Memos)))
|
||||
//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,
|
||||
|
||||
+28
-16
@@ -27,9 +27,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,
|
||||
sendWallet: ownerWallet,
|
||||
@@ -129,7 +145,7 @@ const setup = async () => {
|
||||
describe('RJSVM basic functions', () => {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(10000)
|
||||
this.timeout(100000)
|
||||
await setup()
|
||||
})
|
||||
|
||||
@@ -138,9 +154,11 @@ describe('RJSVM basic functions', () => {
|
||||
})
|
||||
|
||||
it('Env contains the payload carrying transaction', function (done) {
|
||||
this.timeout(30000)
|
||||
this.timeout(45000)
|
||||
|
||||
console.log("Making wallet...")
|
||||
makeTestnetWallet().then(async testWallet => {
|
||||
console.log(testWallet)
|
||||
//create a mock RJSVM
|
||||
abstract class RJSVM_Base
|
||||
extends RJSVM<undefined, { testEndpoint: () => void }>
|
||||
@@ -153,17 +171,12 @@ describe('RJSVM basic functions', () => {
|
||||
const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
|
||||
testEndpoint: {
|
||||
implementation: function (env) {
|
||||
|
||||
expect(env.Account).to.be.equal(userWallet.address)
|
||||
expect(env.Amount).to.be.equal('1')
|
||||
expect(env.Destination).to.be.equal(testWallet.address)
|
||||
expect(Number(env.Fee)).to.be.greaterThanOrEqual(10)
|
||||
expect(env.LastLedgerSequence).to.be.a('number')
|
||||
|
||||
expect(env.Memos).to.be.an('Array')
|
||||
const memo = JSON.parse(DataParser.hex_to_ascii(env.Memos[0].Memo.MemoData))
|
||||
expect(memo.endpoint).to.be.equal('testEndpoint')
|
||||
|
||||
expect(env.Sequence).to.be.a('number')
|
||||
expect(env.SigningPubKey).to.be.a('string')
|
||||
expect(env.TransactionType).to.be.equal('Payment')
|
||||
@@ -172,7 +185,6 @@ describe('RJSVM basic functions', () => {
|
||||
expect(env.hash).to.be.a('string')
|
||||
expect(env.inLedger).to.be.a('number')
|
||||
expect(env.ledger_index).to.be.a('number')
|
||||
|
||||
runnable.disconnect()
|
||||
done()
|
||||
},
|
||||
@@ -182,7 +194,7 @@ describe('RJSVM basic functions', () => {
|
||||
}
|
||||
|
||||
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract)
|
||||
const runnable = new Rjsvm({listeningAddress: testWallet.address,rippleNode: xrpNode})
|
||||
const runnable = new Rjsvm({ listeningAddress: testWallet.address, rippleNode: xrpNode })
|
||||
await runnable.connect()
|
||||
|
||||
const dw = new Datawriter({
|
||||
@@ -197,7 +209,7 @@ describe('RJSVM basic functions', () => {
|
||||
})
|
||||
|
||||
it('Called endpoint triggers in RJSVM', function (done) {
|
||||
this.timeout(30000)
|
||||
this.timeout(45000)
|
||||
|
||||
const data = { title: "1", body: "2", from: "3" };
|
||||
rjsvm.once('submit', (payload) => {
|
||||
@@ -209,7 +221,7 @@ describe('RJSVM basic functions', () => {
|
||||
})
|
||||
|
||||
it('Calling an endpoint with insufficient fee fails', function (done) {
|
||||
this.timeout(30000)
|
||||
this.timeout(45000)
|
||||
|
||||
const data = { title: "f", body: "f", from: "f" };
|
||||
rjsvm.once('error', (err) => {
|
||||
@@ -220,7 +232,7 @@ describe('RJSVM basic functions', () => {
|
||||
})
|
||||
|
||||
it('Restricted endpoint can be called by owner', function (done) {
|
||||
this.timeout(30000)
|
||||
this.timeout(45000)
|
||||
|
||||
const data = { title: "11", body: "22", from: "33" };
|
||||
rjsvm.once('restricted', (payload) => {
|
||||
@@ -233,7 +245,7 @@ describe('RJSVM basic functions', () => {
|
||||
|
||||
|
||||
it('Restricted endpoint cannot be called by non-owner', function (done) {
|
||||
this.timeout(30000)
|
||||
this.timeout(45000)
|
||||
|
||||
const data = { title: "e", body: "e", from: "e" };
|
||||
rjsvm.once('error', (err) => {
|
||||
|
||||
+13
-13
@@ -1,16 +1,16 @@
|
||||
import axios from 'axios';
|
||||
|
||||
type Wallet = {secret: string, address:string }
|
||||
|
||||
export const makeTestnetWallet = () : Promise<Wallet> => fetch('https://faucet.altnet.rippletest.net/accounts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then((raw:any) => {
|
||||
return raw.json().then(content => {
|
||||
return({
|
||||
secret: content.account.secret,
|
||||
address: content.account.address
|
||||
});
|
||||
export const makeTestnetWallet = async () : Promise<Wallet> => {
|
||||
try{
|
||||
const response = await axios.post('https://faucet.altnet.rippletest.net/accounts', {})
|
||||
return ({
|
||||
secret: response.data.seed,
|
||||
address: response.data.account.address
|
||||
})
|
||||
});
|
||||
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user