Hopefully fix browser websocket issue, npm 0.3.2
This commit is contained in:
Generated
+1857
-1206
File diff suppressed because it is too large
Load Diff
+5
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xrpio",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.nitowa.xyz/npm-packages/xrpio.git"
|
||||
@@ -33,14 +33,14 @@
|
||||
"author": "nitowa",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
"ripple-lib": "^1.10.0",
|
||||
"xrpl": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.14.37",
|
||||
"assert": "^2.1.0",
|
||||
"axios": "^1.7.7",
|
||||
"base-64": "^1.0.0",
|
||||
"browserify-zlib": "^0.2.0",
|
||||
"buffer": "^6.0.3",
|
||||
@@ -50,6 +50,7 @@
|
||||
"mocha": "^9.2.0",
|
||||
"net": "^1.0.2",
|
||||
"node-fetch": "^2.6.2",
|
||||
"node-polyfill-webpack-plugin": "^4.0.0",
|
||||
"process": "^0.11.10",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"stream-http": "^3.2.0",
|
||||
@@ -60,6 +61,7 @@
|
||||
"typescript": "^4.5.0",
|
||||
"url": "^0.11.0",
|
||||
"utf8": "^3.0.0",
|
||||
"utils": "^0.3.1",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-cli": "^5.0.0",
|
||||
"wtfnode": "^0.9.1"
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ export type Options = {
|
||||
|
||||
export const defaultOptions: Options = {
|
||||
debug: false,
|
||||
connectionTimeout: 100000,
|
||||
readFreshApi: true,
|
||||
connectionTimeout: 5000,
|
||||
readFreshApi: false,
|
||||
readMaxRetry: 50,
|
||||
readRetryTimeout: 750,
|
||||
writeMaxRetry: 10,
|
||||
writeRetryTimeout: 10000
|
||||
writeRetryTimeout: 1000
|
||||
}
|
||||
+3
-6
@@ -1,5 +1,7 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
|
||||
|
||||
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
@@ -13,12 +15,6 @@ module.exports = {
|
||||
resolve: {
|
||||
extensions: [".ts", ".tsx", ".js"],
|
||||
fallback: {
|
||||
"https": require.resolve("https-browserify"),
|
||||
"zlib": require.resolve("browserify-zlib"),
|
||||
"stream": require.resolve("stream-browserify"),
|
||||
"crypto": require.resolve("crypto-browserify"),
|
||||
"http": require.resolve("stream-http"),
|
||||
"https": require.resolve("https-browserify")
|
||||
}
|
||||
},
|
||||
module: {
|
||||
@@ -35,6 +31,7 @@ module.exports = {
|
||||
externals: {
|
||||
},
|
||||
plugins: [
|
||||
new NodePolyfillPlugin(),
|
||||
new webpack.ProvidePlugin({
|
||||
process: 'process/browser',
|
||||
Buffer: ['buffer', 'Buffer']
|
||||
|
||||
@@ -16,7 +16,6 @@ const PAYLOAD_SIZE = 925
|
||||
const XRP_PER_DROP = 0.000001
|
||||
const DROP_PER_XRP = 1000000
|
||||
|
||||
|
||||
export class xrpIO {
|
||||
private api: Client
|
||||
|
||||
@@ -85,7 +84,7 @@ export class xrpIO {
|
||||
Memos: [{
|
||||
Memo: {
|
||||
MemoData: hexEncode(data.data || ""),
|
||||
MemoFormat: hexEncode(data.format || "0"),
|
||||
MemoFormat: hexEncode(data.format || ""),
|
||||
MemoType: hexEncode(data.type || "")
|
||||
}
|
||||
}]
|
||||
@@ -217,33 +216,16 @@ export class xrpIO {
|
||||
return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
|
||||
}
|
||||
|
||||
private maxMemos = 0
|
||||
|
||||
public async treeRead(hashes: string[], verifyOwner?:string, progressCallback:(max:number,finished:number)=>void = ()=>{}): Promise<string> {
|
||||
public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
|
||||
const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
|
||||
if (bad_hash)
|
||||
throw new BadTxHashError(bad_hash)
|
||||
|
||||
let count = 0;
|
||||
|
||||
const memos = await Promise.all(hashes.map(async hash => {
|
||||
const memo = await this.readRaw(hash, verifyOwner)
|
||||
if(String(memo.format) === '0'){
|
||||
count += 1;
|
||||
progressCallback(count, this.maxMemos)
|
||||
if(count === this.maxMemos){
|
||||
this.maxMemos = 0;
|
||||
}
|
||||
}else{
|
||||
this.maxMemos = Math.max(this.maxMemos, Number(memo.format))
|
||||
progressCallback(-1, this.maxMemos)
|
||||
}
|
||||
return memo
|
||||
}))
|
||||
const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
|
||||
const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
|
||||
|
||||
if (memos.some(memo => memo.format !== '0')) {
|
||||
return await this.treeRead(JSON.parse(payload), verifyOwner, progressCallback)
|
||||
return await this.treeRead(JSON.parse(payload), verifyOwner)
|
||||
}
|
||||
|
||||
return payload
|
||||
|
||||
+15
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
(() => {
|
||||
"use strict";
|
||||
const e = new xrpIO("wss://s.altnet.rippletest.net:51233", { debug: false });
|
||||
e.connect().then((async t => {
|
||||
const n = await e.treeRead(["1481F8DD37C2D3AE3CE60B25264B902BD9E0377AAA1AEDB924D05049F36DFB15"], void 0); document.write(n)
|
||||
}))
|
||||
})();
|
||||
+8
-1
@@ -38,6 +38,13 @@ describe('XRPIO', () => {
|
||||
})
|
||||
|
||||
|
||||
it('treeRead spc', async function(){
|
||||
this.timeout(450000)
|
||||
const data = await api.treeRead(["1481F8DD37C2D3AE3CE60B25264B902BD9E0377AAA1AEDB924D05049F36DFB15"], undefined)
|
||||
expect(data).to.exist
|
||||
})
|
||||
|
||||
|
||||
it('throws error if not enough funds', function(done){
|
||||
this.timeout(15000)
|
||||
console.log(poorWallet)
|
||||
@@ -121,7 +128,7 @@ describe('XRPIO', () => {
|
||||
|
||||
it('treeRead', async function(){
|
||||
this.timeout(45000)
|
||||
const data = await api.treeRead([txHash])
|
||||
const data = await api.treeRead([txHash], undefined)
|
||||
expect(data).to.exist
|
||||
expect(data).to.be.equal(longText)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user