Переглянути джерело

Hopefully fix browser websocket issue, npm 0.3.2

master
nitowa 4 дні тому
джерело
коміт
d345e87bf0
8 змінених файлів з 1902 додано та 1242 видалено
  1. 1857
    1206
      package-lock.json
  2. 5
    3
      package.json
  3. 3
    3
      src/util/types.ts
  4. 3
    6
      src/webpack.js
  5. 4
    22
      src/xrpIO/xrpl-binding.ts
  6. 15
    1
      test/index.html
  7. 7
    0
      test/main.js
  8. 8
    1
      test/primitives.ts

+ 1857
- 1206
package-lock.json
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 5
- 3
package.json Переглянути файл

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "xrpio",
3
-  "version": "0.3.1",
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 Переглянути файл

@@ -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 Переглянути файл

@@ -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']

+ 4
- 22
src/xrpIO/xrpl-binding.ts Переглянути файл

@@ -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
 
@@ -85,7 +84,7 @@ export class xrpIO {
85 84
       Memos: [{
86 85
         Memo: {
87 86
           MemoData: hexEncode(data.data || ""),
88
-          MemoFormat: hexEncode(data.format || "0"),
87
+          MemoFormat: hexEncode(data.format || ""),
89 88
           MemoType: hexEncode(data.type || "")
90 89
         }
91 90
       }]
@@ -217,33 +216,16 @@ export class xrpIO {
217 216
     return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
218 217
   }
219 218
 
220
-  private maxMemos = 0
221
-
222
-  public async treeRead(hashes: string[], verifyOwner?:string, progressCallback:(max:number,finished:number)=>void = ()=>{}): Promise<string> {
219
+  public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
223 220
     const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
224 221
     if (bad_hash)
225 222
       throw new BadTxHashError(bad_hash)
226 223
 
227
-    let count = 0;
228
-
229
-    const memos = await Promise.all(hashes.map(async hash => {
230
-      const memo = await this.readRaw(hash, verifyOwner)
231
-      if(String(memo.format) === '0'){
232
-        count += 1;
233
-        progressCallback(count, this.maxMemos)
234
-        if(count === this.maxMemos){
235
-          this.maxMemos = 0;
236
-        }
237
-      }else{
238
-        this.maxMemos = Math.max(this.maxMemos, Number(memo.format))
239
-        progressCallback(-1, this.maxMemos)
240
-      }
241
-      return memo
242
-    }))
224
+    const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
243 225
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
244 226
 
245 227
     if (memos.some(memo => memo.format !== '0')) {
246
-      return await this.treeRead(JSON.parse(payload), verifyOwner, progressCallback)
228
+      return await this.treeRead(JSON.parse(payload), verifyOwner)
247 229
     }
248 230
 
249 231
     return payload

+ 15
- 1
test/index.html
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 7
- 0
test/main.js Переглянути файл

@@ -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 Переглянути файл

@@ -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
     })

Завантаження…
Відмінити
Зберегти