Browse Source

re-add progressCallback

master
nitowa 1 month ago
parent
commit
18afeffcad
7 changed files with 26 additions and 27 deletions
  1. 1
    1
      package.json
  2. 1
    0
      src/webpack.js
  3. 17
    4
      src/xrpIO/xrpl-binding.ts
  4. 1
    1
      test/CONSTANTS.ts
  5. 0
    1
      test/index.html
  6. 6
    0
      test/longhtml.html
  7. 0
    20
      test/primitives.ts

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "xrpio",
2
   "name": "xrpio",
3
-  "version": "0.3.2",
3
+  "version": "0.4.1",
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"

+ 1
- 0
src/webpack.js View File

15
   resolve: {
15
   resolve: {
16
     extensions: [".ts", ".tsx", ".js"],
16
     extensions: [".ts", ".tsx", ".js"],
17
     fallback: {
17
     fallback: {
18
+      buffer: require.resolve('buffer/'),
18
     }
19
     }
19
   },
20
   },
20
   module: {
21
   module: {

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

202
     return memoParsed
202
     return memoParsed
203
   }
203
   }
204
 
204
 
205
-  public async treeWrite(data: string, to: string, secret: string, format: string = "0"): Promise<string> {
205
+  public async treeWrite(data: string, to: string, secret: string, format: string = "0", progressCallback: Function = (done:number,max:number)=>{}): Promise<string> {
206
     const wallet = Wallet.fromSecret(secret)
206
     const wallet = Wallet.fromSecret(secret)
207
     data = await compressB64(data)
207
     data = await compressB64(data)
208
     const chunks = chunkString(data, PAYLOAD_SIZE)
208
     const chunks = chunkString(data, PAYLOAD_SIZE)
209
     const latestSequence = await this.getAccountSequence(wallet.address)
209
     const latestSequence = await this.getAccountSequence(wallet.address)
210
-    const hashes = await Promise.all(Object.entries(chunks).map(([i, chunk]) => this.writeRaw({ data: chunk, format: format }, to, secret, latestSequence + Number(i))))
210
+
211
+    let count = 0
212
+    const hashes = await Promise.all(Object.entries(chunks).map(([i, chunk]) => {
213
+      const res = this.writeRaw({ data: chunk, format: format }, to, secret, latestSequence + Number(i))
214
+      count += 1
215
+      progressCallback(count, chunks.length)
216
+      return res
217
+    }))
211
 
218
 
212
     if (hashes.length === 1) {
219
     if (hashes.length === 1) {
213
       return hashes[0]
220
       return hashes[0]
216
     return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
223
     return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
217
   }
224
   }
218
 
225
 
219
-  public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
226
+  public async treeRead(hashes: string[], verifyOwner?:string, progressCallback: Function = (done:number,max:number)=>{}): Promise<string> {
220
     const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
227
     const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
221
     if (bad_hash)
228
     if (bad_hash)
222
       throw new BadTxHashError(bad_hash)
229
       throw new BadTxHashError(bad_hash)
223
 
230
 
224
-    const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
231
+    let count = 0;
232
+    const memos = await Promise.all(hashes.map(async hash => {
233
+      const res = this.readRaw(hash, verifyOwner)
234
+      count += 1
235
+      progressCallback(count, hashes.length)
236
+      return res
237
+    }))
225
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
238
     const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
226
 
239
 
227
     if (memos.some(memo => memo.format !== '0')) {
240
     if (memos.some(memo => memo.format !== '0')) {

+ 1
- 1
test/CONSTANTS.ts View File

21
     }
21
     }
22
 }
22
 }
23
 
23
 
24
-export const htmlTxt = readFileSync(Path.resolve(__dirname, '..', '..', 'test', 'index.html')).toString('ascii')
24
+export const htmlTxt = readFileSync(Path.resolve(__dirname, '..', '..', 'test', 'longhtml.html')).toString('ascii')
25
 
25
 
26
 export const longText = `Software testing
26
 export const longText = `Software testing
27
 From Wikipedia, the free encyclopedia
27
 From Wikipedia, the free encyclopedia

+ 0
- 1
test/index.html View File

3
 
3
 
4
 <head>
4
 <head>
5
   <script src="../lib/browser/xrpio.browser.js"></script>
5
   <script src="../lib/browser/xrpio.browser.js"></script>
6
-  <script src="./main.js"></script>
7
   <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"/>
6
   <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"/>
8
 </head>
7
 </head>
9
 
8
 

+ 6
- 0
test/longhtml.html
File diff suppressed because it is too large
View File


+ 0
- 20
test/primitives.ts View File

81
         expect(cost).to.be.greaterThan(30)
81
         expect(cost).to.be.greaterThan(30)
82
     })
82
     })
83
 
83
 
84
-    
85
-
86
     let txHash
84
     let txHash
87
     it('writeRaw', async function(){
85
     it('writeRaw', async function(){
88
         this.timeout(15000)
86
         this.timeout(15000)
161
         expect(data).to.be.equal(htmlTxt)
159
         expect(data).to.be.equal(htmlTxt)
162
     })
160
     })
163
 
161
 
164
-    it('sends even if rate limit exceeded', async function(){
165
-        this.timeout(100 * 60 * 1000) //100m
166
-        console.log("Testing if sending past rate limits correctly recovers and finishes. This may take a while.")
167
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
168
-        console.log("1/7")
169
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
170
-        console.log("2/7")
171
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
172
-        console.log("3/7")
173
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
174
-        console.log("4/7")
175
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
176
-        console.log("5/7")
177
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
178
-        console.log("6/7")
179
-        await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret)
180
-    })
181
-
182
     it('print open handles', function(){
162
     it('print open handles', function(){
183
         api.disconnect().then(_ => {
163
         api.disconnect().then(_ => {
184
             wtf.dump()
164
             wtf.dump()

Loading…
Cancel
Save