re-add progressCallback
This commit is contained in:
@@ -15,6 +15,7 @@ module.exports = {
|
||||
resolve: {
|
||||
extensions: [".ts", ".tsx", ".js"],
|
||||
fallback: {
|
||||
buffer: require.resolve('buffer/'),
|
||||
}
|
||||
},
|
||||
module: {
|
||||
|
||||
@@ -202,12 +202,19 @@ export class xrpIO {
|
||||
return memoParsed
|
||||
}
|
||||
|
||||
public async treeWrite(data: string, to: string, secret: string, format: string = "0"): Promise<string> {
|
||||
public async treeWrite(data: string, to: string, secret: string, format: string = "0", progressCallback: Function = (done:number,max:number)=>{}): Promise<string> {
|
||||
const wallet = Wallet.fromSecret(secret)
|
||||
data = await compressB64(data)
|
||||
const chunks = chunkString(data, PAYLOAD_SIZE)
|
||||
const latestSequence = await this.getAccountSequence(wallet.address)
|
||||
const hashes = await Promise.all(Object.entries(chunks).map(([i, chunk]) => this.writeRaw({ data: chunk, format: format }, to, secret, latestSequence + Number(i))))
|
||||
|
||||
let count = 0
|
||||
const hashes = await Promise.all(Object.entries(chunks).map(([i, chunk]) => {
|
||||
const res = this.writeRaw({ data: chunk, format: format }, to, secret, latestSequence + Number(i))
|
||||
count += 1
|
||||
progressCallback(count, chunks.length)
|
||||
return res
|
||||
}))
|
||||
|
||||
if (hashes.length === 1) {
|
||||
return hashes[0]
|
||||
@@ -216,12 +223,18 @@ export class xrpIO {
|
||||
return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
|
||||
}
|
||||
|
||||
public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
|
||||
public async treeRead(hashes: string[], verifyOwner?:string, progressCallback: Function = (done:number,max:number)=>{}): Promise<string> {
|
||||
const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
|
||||
if (bad_hash)
|
||||
throw new BadTxHashError(bad_hash)
|
||||
|
||||
const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
|
||||
let count = 0;
|
||||
const memos = await Promise.all(hashes.map(async hash => {
|
||||
const res = this.readRaw(hash, verifyOwner)
|
||||
count += 1
|
||||
progressCallback(count, hashes.length)
|
||||
return res
|
||||
}))
|
||||
const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
|
||||
|
||||
if (memos.some(memo => memo.format !== '0')) {
|
||||
|
||||
Reference in New Issue
Block a user