Browse Source

Hopefully fix browser websocket issue, npm 0.3.2

master
nitowa 1 month ago
parent
commit
d345e87bf0
8 changed files with 1902 additions and 1242 deletions
  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
File diff suppressed because it is too large
View File


+ 5
- 3
package.json View File

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

+ 3
- 3
src/util/types.ts View File

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

+ 3
- 6
src/webpack.js View File

1
 const path = require('path');
1
 const path = require('path');
2
 const webpack = require('webpack');
2
 const webpack = require('webpack');
3
+const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
4
+
3
 
5
 
4
 module.exports = {
6
 module.exports = {
5
   mode: "production",
7
   mode: "production",
13
   resolve: {
15
   resolve: {
14
     extensions: [".ts", ".tsx", ".js"],
16
     extensions: [".ts", ".tsx", ".js"],
15
     fallback: {
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
   module: {
20
   module: {
35
   externals: {
31
   externals: {
36
   },
32
   },
37
   plugins: [
33
   plugins: [
34
+    new NodePolyfillPlugin(),
38
     new webpack.ProvidePlugin({
35
     new webpack.ProvidePlugin({
39
       process: 'process/browser',
36
       process: 'process/browser',
40
       Buffer: ['buffer', 'Buffer']
37
       Buffer: ['buffer', 'Buffer']

+ 4
- 22
src/xrpIO/xrpl-binding.ts View File

16
 const XRP_PER_DROP = 0.000001
16
 const XRP_PER_DROP = 0.000001
17
 const DROP_PER_XRP = 1000000
17
 const DROP_PER_XRP = 1000000
18
 
18
 
19
-
20
 export class xrpIO {
19
 export class xrpIO {
21
   private api: Client
20
   private api: Client
22
 
21
 
85
       Memos: [{
84
       Memos: [{
86
         Memo: {
85
         Memo: {
87
           MemoData: hexEncode(data.data || ""),
86
           MemoData: hexEncode(data.data || ""),
88
-          MemoFormat: hexEncode(data.format || "0"),
87
+          MemoFormat: hexEncode(data.format || ""),
89
           MemoType: hexEncode(data.type || "")
88
           MemoType: hexEncode(data.type || "")
90
         }
89
         }
91
       }]
90
       }]
217
     return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
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
     const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
220
     const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
224
     if (bad_hash)
221
     if (bad_hash)
225
       throw new BadTxHashError(bad_hash)
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
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
225
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
244
 
226
 
245
     if (memos.some(memo => memo.format !== '0')) {
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
     return payload
231
     return payload

+ 15
- 1
test/index.html
File diff suppressed because it is too large
View File


+ 7
- 0
test/main.js View File

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 View File

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
     it('throws error if not enough funds', function(done){
48
     it('throws error if not enough funds', function(done){
42
         this.timeout(15000)
49
         this.timeout(15000)
43
         console.log(poorWallet)
50
         console.log(poorWallet)
121
 
128
 
122
     it('treeRead', async function(){
129
     it('treeRead', async function(){
123
         this.timeout(45000)
130
         this.timeout(45000)
124
-        const data = await api.treeRead([txHash])
131
+        const data = await api.treeRead([txHash], undefined)
125
         expect(data).to.exist
132
         expect(data).to.exist
126
         expect(data).to.be.equal(longText)
133
         expect(data).to.be.equal(longText)
127
     })
134
     })

Loading…
Cancel
Save