XRPL API changes 4.0.0

This commit is contained in:
nitowa
2024-10-11 18:37:37 +02:00
parent dc322788c7
commit d84684aa84
6 changed files with 1039 additions and 727 deletions
+942 -678
View File
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "rjsvm", "name": "rjsvm",
"version": "0.2.4", "version": "0.2.5",
"description": "", "description": "",
"main": "lib/src/main.js", "main": "lib/src/main.js",
"scripts": { "scripts": {
@@ -15,10 +15,11 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.7.7",
"stream-http": "^3.2.0", "stream-http": "^3.2.0",
"url": "^0.11.3", "url": "^0.11.3",
"xrpio": "^0.2.1", "xrpio": "^0.3.0",
"xrpl": "^2.7.0", "xrpl": "^4.0.0",
"zod": "^3.21.4" "zod": "^3.21.4"
}, },
"devDependencies": { "devDependencies": {
@@ -46,6 +47,7 @@
"lib/src/main.js", "lib/src/main.js",
"lib/src/main.d.ts", "lib/src/main.d.ts",
"lib/src/util/*", "lib/src/util/*",
"lib/browser/rjsvm.browser.js",
"lib/src/RJSVM/*" "lib/src/RJSVM/*"
] ]
} }
+23 -7
View File
@@ -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 { 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 { xrpIO } from 'xrpio';
import { DataParser } from "../../util/dataparser"; import { DataParser } from "../../util/dataparser";
import { XRP_ADDRESS } from "../../util/protocol.constants"; 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 memos
.map((memo: any) => { .map((memo: any) => {
if (!memo.Memo || !memo.Memo.MemoData) { if (!memo.Memo || !memo.Memo.MemoData) {
@@ -191,12 +192,27 @@ export abstract class RJSVM_Builder {
}) })
//results may not be ordered, so sort them //results may not be ordered, so sort them
const raw_txs = resp.result.transactions const raw_txs = await Promise.all(
.sort((a,b) => a.tx.ledger_index - b.tx.ledger_index) resp.result.transactions
.map((entry: any) => entry.tx) .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 //XRPL API update adaption
await Promise.all(raw_txs.map((tx: PaymentTx_T) => this.parseMemos(tx, tx.Memos))) 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. //if marker is present the result is paginated.
//re-run the same request with the marker included //re-run the same request with the marker included
+19 -1
View File
@@ -20,7 +20,25 @@ let owner_datawriter: Datawriter
const setup = async () => { 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({ owner_datawriter = new Datawriter({
receiveAddress: drainWallet.address, receiveAddress: drainWallet.address,
+27 -15
View File
@@ -27,9 +27,25 @@ let owner_datawriter: Datawriter
const setup = async () => { 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({ owner_datawriter = new Datawriter({
receiveAddress: drainWallet.address, receiveAddress: drainWallet.address,
sendWallet: ownerWallet, sendWallet: ownerWallet,
@@ -129,7 +145,7 @@ const setup = async () => {
describe('RJSVM basic functions', () => { describe('RJSVM basic functions', () => {
before(async function () { before(async function () {
this.timeout(10000) this.timeout(100000)
await setup() await setup()
}) })
@@ -138,9 +154,11 @@ describe('RJSVM basic functions', () => {
}) })
it('Env contains the payload carrying transaction', function (done) { it('Env contains the payload carrying transaction', function (done) {
this.timeout(30000) this.timeout(45000)
console.log("Making wallet...")
makeTestnetWallet().then(async testWallet => { makeTestnetWallet().then(async testWallet => {
console.log(testWallet)
//create a mock RJSVM //create a mock RJSVM
abstract class RJSVM_Base abstract class RJSVM_Base
extends RJSVM<undefined, { testEndpoint: () => void }> extends RJSVM<undefined, { testEndpoint: () => void }>
@@ -153,17 +171,12 @@ describe('RJSVM basic functions', () => {
const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = { const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
testEndpoint: { testEndpoint: {
implementation: function (env) { implementation: function (env) {
expect(env.Account).to.be.equal(userWallet.address) expect(env.Account).to.be.equal(userWallet.address)
expect(env.Amount).to.be.equal('1') expect(env.Amount).to.be.equal('1')
expect(env.Destination).to.be.equal(testWallet.address) expect(env.Destination).to.be.equal(testWallet.address)
expect(Number(env.Fee)).to.be.greaterThanOrEqual(10) expect(Number(env.Fee)).to.be.greaterThanOrEqual(10)
expect(env.LastLedgerSequence).to.be.a('number') expect(env.LastLedgerSequence).to.be.a('number')
expect(env.Memos).to.be.an('Array') 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.Sequence).to.be.a('number')
expect(env.SigningPubKey).to.be.a('string') expect(env.SigningPubKey).to.be.a('string')
expect(env.TransactionType).to.be.equal('Payment') expect(env.TransactionType).to.be.equal('Payment')
@@ -172,7 +185,6 @@ describe('RJSVM basic functions', () => {
expect(env.hash).to.be.a('string') expect(env.hash).to.be.a('string')
expect(env.inLedger).to.be.a('number') expect(env.inLedger).to.be.a('number')
expect(env.ledger_index).to.be.a('number') expect(env.ledger_index).to.be.a('number')
runnable.disconnect() runnable.disconnect()
done() done()
}, },
@@ -197,7 +209,7 @@ describe('RJSVM basic functions', () => {
}) })
it('Called endpoint triggers in RJSVM', function (done) { it('Called endpoint triggers in RJSVM', function (done) {
this.timeout(30000) this.timeout(45000)
const data = { title: "1", body: "2", from: "3" }; const data = { title: "1", body: "2", from: "3" };
rjsvm.once('submit', (payload) => { rjsvm.once('submit', (payload) => {
@@ -209,7 +221,7 @@ describe('RJSVM basic functions', () => {
}) })
it('Calling an endpoint with insufficient fee fails', function (done) { it('Calling an endpoint with insufficient fee fails', function (done) {
this.timeout(30000) this.timeout(45000)
const data = { title: "f", body: "f", from: "f" }; const data = { title: "f", body: "f", from: "f" };
rjsvm.once('error', (err) => { rjsvm.once('error', (err) => {
@@ -220,7 +232,7 @@ describe('RJSVM basic functions', () => {
}) })
it('Restricted endpoint can be called by owner', function (done) { it('Restricted endpoint can be called by owner', function (done) {
this.timeout(30000) this.timeout(45000)
const data = { title: "11", body: "22", from: "33" }; const data = { title: "11", body: "22", from: "33" };
rjsvm.once('restricted', (payload) => { rjsvm.once('restricted', (payload) => {
@@ -233,7 +245,7 @@ describe('RJSVM basic functions', () => {
it('Restricted endpoint cannot be called by non-owner', function (done) { 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" }; const data = { title: "e", body: "e", from: "e" };
rjsvm.once('error', (err) => { rjsvm.once('error', (err) => {
+12 -12
View File
@@ -1,16 +1,16 @@
import axios from 'axios';
type Wallet = {secret: string, address:string } type Wallet = {secret: string, address:string }
export const makeTestnetWallet = () : Promise<Wallet> => fetch('https://faucet.altnet.rippletest.net/accounts', { export const makeTestnetWallet = async () : Promise<Wallet> => {
method: 'POST', try{
headers: { const response = await axios.post('https://faucet.altnet.rippletest.net/accounts', {})
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).then((raw:any) => {
return raw.json().then(content => {
return ({ return ({
secret: content.account.secret, secret: response.data.seed,
address: content.account.address address: response.data.account.address
});
}) })
});
}catch(e){
console.log(e)
}
}