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