re-add progressCallback
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xrpio",
|
"name": "xrpio",
|
||||||
"version": "0.3.2",
|
"version": "0.4.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
|
"url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ module.exports = {
|
|||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".tsx", ".js"],
|
extensions: [".ts", ".tsx", ".js"],
|
||||||
fallback: {
|
fallback: {
|
||||||
|
buffer: require.resolve('buffer/'),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
|
|||||||
@@ -202,12 +202,19 @@ export class xrpIO {
|
|||||||
return memoParsed
|
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)
|
const wallet = Wallet.fromSecret(secret)
|
||||||
data = await compressB64(data)
|
data = await compressB64(data)
|
||||||
const chunks = chunkString(data, PAYLOAD_SIZE)
|
const chunks = chunkString(data, PAYLOAD_SIZE)
|
||||||
const latestSequence = await this.getAccountSequence(wallet.address)
|
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) {
|
if (hashes.length === 1) {
|
||||||
return hashes[0]
|
return hashes[0]
|
||||||
@@ -216,12 +223,18 @@ export class xrpIO {
|
|||||||
return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
|
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))
|
const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
|
||||||
if (bad_hash)
|
if (bad_hash)
|
||||||
throw new BadTxHashError(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(''))
|
const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
|
||||||
|
|
||||||
if (memos.some(memo => memo.format !== '0')) {
|
if (memos.some(memo => memo.format !== '0')) {
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ export const makeTestnetWallet = async () : Promise<Wallet> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
export const longText = `Software testing
|
||||||
From Wikipedia, the free encyclopedia
|
From Wikipedia, the free encyclopedia
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script src="../lib/browser/xrpio.browser.js"></script>
|
<script src="../lib/browser/xrpio.browser.js"></script>
|
||||||
<script src="./main.js"></script>
|
|
||||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"/>
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -81,8 +81,6 @@ describe('XRPIO', () => {
|
|||||||
expect(cost).to.be.greaterThan(30)
|
expect(cost).to.be.greaterThan(30)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let txHash
|
let txHash
|
||||||
it('writeRaw', async function(){
|
it('writeRaw', async function(){
|
||||||
this.timeout(15000)
|
this.timeout(15000)
|
||||||
@@ -161,24 +159,6 @@ describe('XRPIO', () => {
|
|||||||
expect(data).to.be.equal(htmlTxt)
|
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(){
|
it('print open handles', function(){
|
||||||
api.disconnect().then(_ => {
|
api.disconnect().then(_ => {
|
||||||
wtf.dump()
|
wtf.dump()
|
||||||
|
|||||||
Reference in New Issue
Block a user