diff --git a/package.json b/package.json index 9605202..d352dca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xrpio", - "version": "0.3.2", + "version": "0.4.1", "repository": { "type": "git", "url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git" diff --git a/src/webpack.js b/src/webpack.js index 17a7777..c1e5ea5 100644 --- a/src/webpack.js +++ b/src/webpack.js @@ -15,6 +15,7 @@ module.exports = { resolve: { extensions: [".ts", ".tsx", ".js"], fallback: { + buffer: require.resolve('buffer/'), } }, module: { diff --git a/src/xrpIO/xrpl-binding.ts b/src/xrpIO/xrpl-binding.ts index 82a820d..7cb3688 100644 --- a/src/xrpIO/xrpl-binding.ts +++ b/src/xrpIO/xrpl-binding.ts @@ -202,12 +202,19 @@ export class xrpIO { return memoParsed } - public async treeWrite(data: string, to: string, secret: string, format: string = "0"): Promise { + public async treeWrite(data: string, to: string, secret: string, format: string = "0", progressCallback: Function = (done:number,max:number)=>{}): Promise { 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 { + public async treeRead(hashes: string[], verifyOwner?:string, progressCallback: Function = (done:number,max:number)=>{}): Promise { 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')) { diff --git a/test/CONSTANTS.ts b/test/CONSTANTS.ts index 31359c2..ff57211 100644 --- a/test/CONSTANTS.ts +++ b/test/CONSTANTS.ts @@ -21,7 +21,7 @@ export const makeTestnetWallet = async () : Promise => { } } -export const htmlTxt = readFileSync(Path.resolve(__dirname, '..', '..', 'test', 'index.html')).toString('ascii') +export const htmlTxt = readFileSync(Path.resolve(__dirname, '..', '..', 'test', 'longhtml.html')).toString('ascii') export const longText = `Software testing From Wikipedia, the free encyclopedia diff --git a/test/index.html b/test/index.html index b61bb32..ef75077 100644 --- a/test/index.html +++ b/test/index.html @@ -3,7 +3,6 @@ - diff --git a/test/longhtml.html b/test/longhtml.html new file mode 100644 index 0000000..50f1f30 --- /dev/null +++ b/test/longhtml.html @@ -0,0 +1,6 @@ +AngularClr \ No newline at end of file diff --git a/test/primitives.ts b/test/primitives.ts index 789e476..642be7d 100644 --- a/test/primitives.ts +++ b/test/primitives.ts @@ -81,8 +81,6 @@ describe('XRPIO', () => { expect(cost).to.be.greaterThan(30) }) - - let txHash it('writeRaw', async function(){ this.timeout(15000) @@ -161,24 +159,6 @@ describe('XRPIO', () => { expect(data).to.be.equal(htmlTxt) }) - it('sends even if rate limit exceeded', async function(){ - this.timeout(100 * 60 * 1000) //100m - console.log("Testing if sending past rate limits correctly recovers and finishes. This may take a while.") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("1/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("2/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("3/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("4/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("5/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - console.log("6/7") - await api.treeWrite(htmlTxt, receiveWallet.address, sendWallet.secret) - }) - it('print open handles', function(){ api.disconnect().then(_ => { wtf.dump()