3 Commits

Autor SHA1 Nachricht Datum
  nitowa d345e87bf0 Hopefully fix browser websocket issue, npm 0.3.2 vor 2 Monaten
  nitowa b5c71753cc npm 0.3.1 vor 2 Monaten
  nitowa 5277fbd703 progress callback for treeWrite vor 2 Monaten
8 geänderte Dateien mit 1905 neuen und 1229 gelöschten Zeilen
  1. 1859
    1208
      package-lock.json
  2. 5
    3
      package.json
  3. 3
    3
      src/util/types.ts
  4. 3
    6
      src/webpack.js
  5. 5
    7
      src/xrpIO/xrpl-binding.ts
  6. 15
    1
      test/index.html
  7. 7
    0
      test/main.js
  8. 8
    1
      test/primitives.ts

+ 1859
- 1208
package-lock.json
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 5
- 3
package.json Datei anzeigen

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "xrpio",
3
-  "version": "0.3.0",
3
+  "version": "0.3.2",
4 4
   "repository": {
5 5
     "type": "git",
6 6
     "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
@@ -33,14 +33,14 @@
33 33
   "author": "nitowa",
34 34
   "license": "MIT",
35 35
   "dependencies": {
36
-    "axios": "^1.7.7",
37
-    "ripple-lib": "^1.10.0",
38 36
     "xrpl": "^4.0.0"
39 37
   },
40 38
   "devDependencies": {
41 39
     "@types/chai": "^4.2.21",
42 40
     "@types/mocha": "^8.2.2",
43 41
     "@types/node": "^14.14.37",
42
+    "assert": "^2.1.0",
43
+    "axios": "^1.7.7",
44 44
     "base-64": "^1.0.0",
45 45
     "browserify-zlib": "^0.2.0",
46 46
     "buffer": "^6.0.3",
@@ -50,6 +50,7 @@
50 50
     "mocha": "^9.2.0",
51 51
     "net": "^1.0.2",
52 52
     "node-fetch": "^2.6.2",
53
+    "node-polyfill-webpack-plugin": "^4.0.0",
53 54
     "process": "^0.11.10",
54 55
     "stream-browserify": "^3.0.0",
55 56
     "stream-http": "^3.2.0",
@@ -60,6 +61,7 @@
60 61
     "typescript": "^4.5.0",
61 62
     "url": "^0.11.0",
62 63
     "utf8": "^3.0.0",
64
+    "utils": "^0.3.1",
63 65
     "webpack": "^5.75.0",
64 66
     "webpack-cli": "^5.0.0",
65 67
     "wtfnode": "^0.9.1"

+ 3
- 3
src/util/types.ts Datei anzeigen

@@ -25,10 +25,10 @@ export type Options = {
25 25
 
26 26
 export const defaultOptions: Options = {
27 27
     debug: false,
28
-    connectionTimeout: 100000,
29
-    readFreshApi: true,
28
+    connectionTimeout: 5000,
29
+    readFreshApi: false,
30 30
     readMaxRetry: 50,
31 31
     readRetryTimeout: 750,
32 32
     writeMaxRetry: 10,
33
-    writeRetryTimeout: 10000
33
+    writeRetryTimeout: 1000
34 34
   }

+ 3
- 6
src/webpack.js Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 const path = require('path');
2 2
 const webpack = require('webpack');
3
+const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
4
+
3 5
 
4 6
 module.exports = {
5 7
   mode: "production",
@@ -13,12 +15,6 @@ module.exports = {
13 15
   resolve: {
14 16
     extensions: [".ts", ".tsx", ".js"],
15 17
     fallback: {
16
-      "https": require.resolve("https-browserify"),
17
-      "zlib": require.resolve("browserify-zlib"),
18
-      "stream": require.resolve("stream-browserify"),
19
-      "crypto": require.resolve("crypto-browserify"),
20
-      "http": require.resolve("stream-http"),
21
-      "https": require.resolve("https-browserify")
22 18
     }
23 19
   },
24 20
   module: {
@@ -35,6 +31,7 @@ module.exports = {
35 31
   externals: {
36 32
   },
37 33
   plugins: [
34
+    new NodePolyfillPlugin(),
38 35
     new webpack.ProvidePlugin({
39 36
       process: 'process/browser',
40 37
       Buffer: ['buffer', 'Buffer']

+ 5
- 7
src/xrpIO/xrpl-binding.ts Datei anzeigen

@@ -16,7 +16,6 @@ const PAYLOAD_SIZE = 925
16 16
 const XRP_PER_DROP = 0.000001
17 17
 const DROP_PER_XRP = 1000000
18 18
 
19
-
20 19
 export class xrpIO {
21 20
   private api: Client
22 21
 
@@ -75,6 +74,7 @@ export class xrpIO {
75 74
     this.dbg("Sending payment", wallet.address, '->', to)
76 75
 
77 76
     const _api = await this.cloneApi()
77
+    
78 78
     const payment: Payment = await _api.autofill({
79 79
       TransactionType: 'Payment',
80 80
       Account: wallet.address,
@@ -188,8 +188,6 @@ export class xrpIO {
188 188
     }
189 189
     const tx = await this.getTransaction(hash)
190 190
 
191
-    
192
-
193 191
     if(verifyOwner && tx.result.tx_json.Account != verifyOwner){
194 192
       throw new CannotVerifyOwnerError(hash, tx.result.tx_json.Account, verifyOwner)
195 193
     }
@@ -204,7 +202,7 @@ export class xrpIO {
204 202
     return memoParsed
205 203
   }
206 204
 
207
-  public async treeWrite(data: string, to: string, secret: string, format: 'L' | 'N' = 'L'): Promise<string> {
205
+  public async treeWrite(data: string, to: string, secret: string, format: string = "0"): Promise<string> {
208 206
     const wallet = Wallet.fromSecret(secret)
209 207
     data = await compressB64(data)
210 208
     const chunks = chunkString(data, PAYLOAD_SIZE)
@@ -215,7 +213,7 @@ export class xrpIO {
215 213
       return hashes[0]
216 214
     }
217 215
 
218
-    return await this.treeWrite(JSON.stringify(hashes), to, secret, 'N')
216
+    return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
219 217
   }
220 218
 
221 219
   public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
@@ -223,10 +221,10 @@ export class xrpIO {
223 221
     if (bad_hash)
224 222
       throw new BadTxHashError(bad_hash)
225 223
 
226
-    const memos = await Promise.all(hashes.map(hash => this.readRaw(hash, verifyOwner)))
224
+    const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
227 225
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
228 226
 
229
-    if (memos.some(memo => memo.format === 'N')) {
227
+    if (memos.some(memo => memo.format !== '0')) {
230 228
       return await this.treeRead(JSON.parse(payload), verifyOwner)
231 229
     }
232 230
 

+ 15
- 1
test/index.html
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 7
- 0
test/main.js Datei anzeigen

@@ -0,0 +1,7 @@
1
+(() => {
2
+    "use strict";
3
+    const e = new xrpIO("wss://s.altnet.rippletest.net:51233", { debug: false });
4
+    e.connect().then((async t => {
5
+        const n = await e.treeRead(["1481F8DD37C2D3AE3CE60B25264B902BD9E0377AAA1AEDB924D05049F36DFB15"], void 0); document.write(n)
6
+    }))
7
+})();

+ 8
- 1
test/primitives.ts Datei anzeigen

@@ -38,6 +38,13 @@ describe('XRPIO', () => {
38 38
     })
39 39
 
40 40
 
41
+    it('treeRead spc', async function(){
42
+        this.timeout(450000)
43
+        const data = await api.treeRead(["1481F8DD37C2D3AE3CE60B25264B902BD9E0377AAA1AEDB924D05049F36DFB15"], undefined)
44
+        expect(data).to.exist
45
+    })
46
+
47
+
41 48
     it('throws error if not enough funds', function(done){
42 49
         this.timeout(15000)
43 50
         console.log(poorWallet)
@@ -121,7 +128,7 @@ describe('XRPIO', () => {
121 128
 
122 129
     it('treeRead', async function(){
123 130
         this.timeout(45000)
124
-        const data = await api.treeRead([txHash])
131
+        const data = await api.treeRead([txHash], undefined)
125 132
         expect(data).to.exist
126 133
         expect(data).to.be.equal(longText)
127 134
     })

Laden…
Abbrechen
Speichern