Browse Source

XRPL API changes 4.0.0

master
nitowa 1 month ago
parent
commit
d84684aa84
6 changed files with 1037 additions and 725 deletions
  1. 939
    675
      package-lock.json
  2. 5
    3
      package.json
  3. 24
    8
      src/RJSVM/framework/rjsvm.ts
  4. 25
    7
      src/user-defined-contract.ts
  5. 30
    18
      test/Test.ts
  6. 14
    14
      test/tools.ts

+ 939
- 675
package-lock.json
File diff suppressed because it is too large
View File


+ 5
- 3
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "rjsvm",
3
-  "version": "0.2.4",
3
+  "version": "0.2.5",
4 4
   "description": "",
5 5
   "main": "lib/src/main.js",
6 6
   "scripts": {
@@ -15,10 +15,11 @@
15 15
   "author": "",
16 16
   "license": "ISC",
17 17
   "dependencies": {
18
+    "axios": "^1.7.7",
18 19
     "stream-http": "^3.2.0",
19 20
     "url": "^0.11.3",
20
-    "xrpio": "^0.2.1",
21
-    "xrpl": "^2.7.0",
21
+    "xrpio": "^0.3.0",
22
+    "xrpl": "^4.0.0",
22 23
     "zod": "^3.21.4"
23 24
   },
24 25
   "devDependencies": {
@@ -46,6 +47,7 @@
46 47
     "lib/src/main.js",
47 48
     "lib/src/main.d.ts",
48 49
     "lib/src/util/*",
50
+    "lib/browser/rjsvm.browser.js",
49 51
     "lib/src/RJSVM/*"
50 52
   ]
51 53
 }

+ 24
- 8
src/RJSVM/framework/rjsvm.ts View File

@@ -1,5 +1,5 @@
1 1
 import { PaymentTx_T, ParameterizedFunction, Payload, RJSVM, RJSVM_Config, RJSVM_Implementations, Function_Map, Endpoints_Of, State_Of, Generic_Ctor_ReturnType, RJSVM_Endpoint } from "./types"
2
-import { Client as Xrpl } from 'xrpl';
2
+import { AccountTxTransaction, Client as Xrpl } from 'xrpl';
3 3
 import { xrpIO } from 'xrpio';
4 4
 import { DataParser } from "../../util/dataparser";
5 5
 import { XRP_ADDRESS } from "../../util/protocol.constants";
@@ -151,7 +151,8 @@ export abstract class RJSVM_Builder {
151 151
                 }
152 152
             }
153 153
 
154
-            private parseMemos = async (tx:PaymentTx_T, memos: any[]) => {
154
+            private parseMemos = async (tx:PaymentTx_T) => {
155
+                const memos = tx.Memos
155 156
                 memos
156 157
                     .map((memo: any) => {
157 158
                         if (!memo.Memo || !memo.Memo.MemoData) {
@@ -191,12 +192,27 @@ export abstract class RJSVM_Builder {
191 192
                 })
192 193
 
193 194
                 //results may not be ordered, so sort them
194
-                const raw_txs = resp.result.transactions
195
-                    .sort((a,b) => a.tx.ledger_index - b.tx.ledger_index)
196
-                    .map((entry: any) => entry.tx)
197
-                
198
-                //apply any state changes
199
-                await Promise.all(raw_txs.map((tx: PaymentTx_T) => this.parseMemos(tx, tx.Memos)))
195
+                const raw_txs = await Promise.all(
196
+                    resp.result.transactions
197
+                        .filter(tx => tx.tx_json.TransactionType === "Payment")
198
+                        .sort((a,b) => a.tx_json.ledger_index - b.tx_json.ledger_index)
199
+                        .map((tx) => this.xrpIO.getTransaction(tx.hash))
200
+                )
201
+
202
+                //XRPL API update adaption
203
+                await Promise.all(
204
+                    raw_txs
205
+                        .filter(tx => !!tx.result.tx_json.Memos)
206
+                        .map(tx => {
207
+                            return({
208
+                                ...tx.result.tx_json,
209
+                                hash: tx.result.hash,
210
+                                Amount: tx.result.tx_json["DeliverMax"],
211
+                                inLedger: tx.result.tx_json['ledger_index']
212
+                            } as PaymentTx_T)
213
+                        })
214
+                        .map(tx => this.parseMemos(tx))
215
+                    )
200 216
                 
201 217
                 //if marker is present the result is paginated.
202 218
                 //re-run the same request with the marker included

+ 25
- 7
src/user-defined-contract.ts View File

@@ -20,7 +20,25 @@ let owner_datawriter: Datawriter
20 20
 
21 21
 const setup = async () => {
22 22
 
23
-    [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
23
+    //    [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
24
+    [ownerWallet, listeningWallet, userWallet, drainWallet] = [
25
+        {
26
+            secret: 'sEd7tPDHFk3w7ABSaCPYi12iwucMQLt',
27
+            address: 'rDML7QhJeVxZTwsjPtm4iyLUJTCzzuppMo'
28
+        },
29
+        {
30
+            secret: 'sEdSgbyouvLM26vq2F2XthfKGWndP72',
31
+            address: 'rPvwbb4JHncG9rKVrYATJw6HRixR69wgjg'
32
+        },
33
+        {
34
+            secret: 'sEd7c1Y8JwWyA2owbchMWnuzAhB3ypY',
35
+            address: 'rwuuWdyxwf3o78Ce2DAZrYCQ12SSawTp6M'
36
+        },
37
+        {
38
+            secret: 'sEdScantwGA5gYe4atKPbG5bsriURpf',
39
+            address: 'rDiwSioTRyV29rNk2FskxqFtMaRsmWvS7C'
40
+        }
41
+    ]
24 42
 
25 43
     owner_datawriter = new Datawriter({
26 44
         receiveAddress: drainWallet.address,
@@ -44,7 +62,7 @@ const setup = async () => {
44 62
     // #########################
45 63
     // Define parameter types
46 64
     // #########################
47
-    
65
+
48 66
     const shoutSchema = z.object({
49 67
         title: z.string(),
50 68
         body: z.string(),
@@ -78,8 +96,8 @@ const setup = async () => {
78 96
     // #########################
79 97
 
80 98
     abstract class RJSVM_Base
81
-    extends RJSVM<State, RJSVM_Endpoints>
82
-    implements RJSVM_Interface<RJSVM_Base> {
99
+        extends RJSVM<State, RJSVM_Endpoints>
100
+        implements RJSVM_Interface<RJSVM_Base> {
83 101
         owner = ownerWallet.address
84 102
 
85 103
         state: State = {
@@ -122,7 +140,7 @@ const setup = async () => {
122 140
     // #########################
123 141
     // Build and connect
124 142
     // #########################
125
-    
143
+
126 144
     const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
127 145
 
128 146
     const conf: RJSVM_Config = {
@@ -135,6 +153,6 @@ const setup = async () => {
135 153
 }
136 154
 
137 155
 (async () => {
138
-        await setup()
139
-        await owner_datawriter.callEndpoint('submit', { title: "1", body: "2", from: "3" }, 100)
156
+    await setup()
157
+    await owner_datawriter.callEndpoint('submit', { title: "1", body: "2", from: "3" }, 100)
140 158
 })()

+ 30
- 18
test/Test.ts View File

@@ -27,9 +27,25 @@ let owner_datawriter: Datawriter
27 27
 
28 28
 
29 29
 const setup = async () => {
30
-
31
-    [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(), makeTestnetWallet(), makeTestnetWallet(), makeTestnetWallet()])
32
-
30
+    //    [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
31
+    [ownerWallet, listeningWallet, userWallet, drainWallet] = [
32
+        {
33
+            secret: 'sEd7tPDHFk3w7ABSaCPYi12iwucMQLt',
34
+            address: 'rDML7QhJeVxZTwsjPtm4iyLUJTCzzuppMo'
35
+        },
36
+        {
37
+            secret: 'sEdSgbyouvLM26vq2F2XthfKGWndP72',
38
+            address: 'rPvwbb4JHncG9rKVrYATJw6HRixR69wgjg'
39
+        },
40
+        {
41
+            secret: 'sEd7c1Y8JwWyA2owbchMWnuzAhB3ypY',
42
+            address: 'rwuuWdyxwf3o78Ce2DAZrYCQ12SSawTp6M'
43
+        },
44
+        {
45
+            secret: 'sEdScantwGA5gYe4atKPbG5bsriURpf',
46
+            address: 'rDiwSioTRyV29rNk2FskxqFtMaRsmWvS7C'
47
+        }
48
+    ]
33 49
     owner_datawriter = new Datawriter({
34 50
         receiveAddress: drainWallet.address,
35 51
         sendWallet: ownerWallet,
@@ -129,7 +145,7 @@ const setup = async () => {
129 145
 describe('RJSVM basic functions', () => {
130 146
 
131 147
     before(async function () {
132
-        this.timeout(10000)
148
+        this.timeout(100000)
133 149
         await setup()
134 150
     })
135 151
 
@@ -138,13 +154,15 @@ describe('RJSVM basic functions', () => {
138 154
     })
139 155
 
140 156
     it('Env contains the payload carrying transaction', function (done) {
141
-        this.timeout(30000)
157
+        this.timeout(45000)
142 158
 
159
+        console.log("Making wallet...")
143 160
         makeTestnetWallet().then(async testWallet => {
161
+            console.log(testWallet)
144 162
             //create a mock RJSVM
145 163
             abstract class RJSVM_Base
146
-            extends RJSVM<undefined, { testEndpoint: () => void }>
147
-            implements RJSVM_Interface<RJSVM_Base> {
164
+                extends RJSVM<undefined, { testEndpoint: () => void }>
165
+                implements RJSVM_Interface<RJSVM_Base> {
148 166
                 owner = ownerWallet.address
149 167
                 state = undefined
150 168
             }
@@ -153,17 +171,12 @@ describe('RJSVM basic functions', () => {
153 171
             const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
154 172
                 testEndpoint: {
155 173
                     implementation: function (env) {
156
-
157 174
                         expect(env.Account).to.be.equal(userWallet.address)
158 175
                         expect(env.Amount).to.be.equal('1')
159 176
                         expect(env.Destination).to.be.equal(testWallet.address)
160 177
                         expect(Number(env.Fee)).to.be.greaterThanOrEqual(10)
161 178
                         expect(env.LastLedgerSequence).to.be.a('number')
162
-
163 179
                         expect(env.Memos).to.be.an('Array')
164
-                        const memo = JSON.parse(DataParser.hex_to_ascii(env.Memos[0].Memo.MemoData))
165
-                        expect(memo.endpoint).to.be.equal('testEndpoint')
166
-
167 180
                         expect(env.Sequence).to.be.a('number')
168 181
                         expect(env.SigningPubKey).to.be.a('string')
169 182
                         expect(env.TransactionType).to.be.equal('Payment')
@@ -172,7 +185,6 @@ describe('RJSVM basic functions', () => {
172 185
                         expect(env.hash).to.be.a('string')
173 186
                         expect(env.inLedger).to.be.a('number')
174 187
                         expect(env.ledger_index).to.be.a('number')
175
-
176 188
                         runnable.disconnect()
177 189
                         done()
178 190
                     },
@@ -182,7 +194,7 @@ describe('RJSVM basic functions', () => {
182 194
             }
183 195
 
184 196
             const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract)
185
-            const runnable = new Rjsvm({listeningAddress: testWallet.address,rippleNode: xrpNode})
197
+            const runnable = new Rjsvm({ listeningAddress: testWallet.address, rippleNode: xrpNode })
186 198
             await runnable.connect()
187 199
 
188 200
             const dw = new Datawriter({
@@ -197,7 +209,7 @@ describe('RJSVM basic functions', () => {
197 209
     })
198 210
 
199 211
     it('Called endpoint triggers in RJSVM', function (done) {
200
-        this.timeout(30000)
212
+        this.timeout(45000)
201 213
 
202 214
         const data = { title: "1", body: "2", from: "3" };
203 215
         rjsvm.once('submit', (payload) => {
@@ -209,7 +221,7 @@ describe('RJSVM basic functions', () => {
209 221
     })
210 222
 
211 223
     it('Calling an endpoint with insufficient fee fails', function (done) {
212
-        this.timeout(30000)
224
+        this.timeout(45000)
213 225
 
214 226
         const data = { title: "f", body: "f", from: "f" };
215 227
         rjsvm.once('error', (err) => {
@@ -220,7 +232,7 @@ describe('RJSVM basic functions', () => {
220 232
     })
221 233
 
222 234
     it('Restricted endpoint can be called by owner', function (done) {
223
-        this.timeout(30000)
235
+        this.timeout(45000)
224 236
 
225 237
         const data = { title: "11", body: "22", from: "33" };
226 238
         rjsvm.once('restricted', (payload) => {
@@ -233,7 +245,7 @@ describe('RJSVM basic functions', () => {
233 245
 
234 246
 
235 247
     it('Restricted endpoint cannot be called by non-owner', function (done) {
236
-        this.timeout(30000)
248
+        this.timeout(45000)
237 249
 
238 250
         const data = { title: "e", body: "e", from: "e" };
239 251
         rjsvm.once('error', (err) => {

+ 14
- 14
test/tools.ts View File

@@ -1,16 +1,16 @@
1
+import axios from 'axios';
2
+
1 3
 type Wallet = {secret: string, address:string }
2 4
 
3
-export const makeTestnetWallet = () : Promise<Wallet> => fetch('https://faucet.altnet.rippletest.net/accounts', {
4
-    method: 'POST',
5
-    headers: {
6
-        'Accept': 'application/json',
7
-        'Content-Type': 'application/json'
8
-    },
9
-}).then((raw:any) => {
10
-    return raw.json().then(content => {
11
-        return({
12
-            secret: content.account.secret,
13
-            address: content.account.address
14
-        });
15
-    })
16
-});
5
+export const makeTestnetWallet = async () : Promise<Wallet> => {
6
+    try{
7
+        const response = await axios.post('https://faucet.altnet.rippletest.net/accounts', {})
8
+        return ({
9
+            secret: response.data.seed,
10
+            address: response.data.account.address
11
+        })
12
+    
13
+    }catch(e){
14
+        console.log(e)
15
+    }
16
+}

Loading…
Cancel
Save