|
@@ -202,12 +202,19 @@ export class xrpIO {
|
202
|
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
|
206
|
const wallet = Wallet.fromSecret(secret)
|
207
|
207
|
data = await compressB64(data)
|
208
|
208
|
const chunks = chunkString(data, PAYLOAD_SIZE)
|
209
|
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
|
219
|
if (hashes.length === 1) {
|
213
|
220
|
return hashes[0]
|
|
@@ -216,12 +223,18 @@ export class xrpIO {
|
216
|
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
|
227
|
const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
|
221
|
228
|
if (bad_hash)
|
222
|
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
|
238
|
const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
|
226
|
239
|
|
227
|
240
|
if (memos.some(memo => memo.format !== '0')) {
|