New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

xrpl-txdata

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xrpl-txdata - npm Package Compare versions

Comparing version 1.1.2 to 1.2.1

6

dist/src/index.d.ts

@@ -32,2 +32,3 @@ import { FormattedBalanceChanges } from './ext-dependencies/balanceParser';

OverallTimeoutMs?: number;
AllowNoFullHistory?: boolean;
};

@@ -43,2 +44,3 @@ export declare class TxData {

private LookupTimeoutMs;
private AllowNoFullHistory;
constructor(endpoints?: Array<string>, options?: TxDataOptions);

@@ -54,4 +56,4 @@ /**

end(): void;
getOne(TxHash: string): Promise<ResolvedLookup>;
get(TxHash: string): Promise<ResolvedLookup>;
getOne(TxHash: string, WaitForSeconds?: number): Promise<ResolvedLookup>;
get(TxHash: string, WaitForSeconds?: number): Promise<ResolvedLookup>;
/**

@@ -58,0 +60,0 @@ * PRIVATE

@@ -59,2 +59,3 @@ "use strict";

this.LookupTimeoutMs = 10000;
this.AllowNoFullHistory = false;
this.EventBus = new events_1.EventEmitter();

@@ -95,2 +96,5 @@ log('Constructed');

}
if (typeof options.AllowNoFullHistory === 'boolean') {
this.AllowNoFullHistory = options.AllowNoFullHistory;
}
}

@@ -118,5 +122,5 @@ const minTimeoutMs = this.ConnectionAndQueryTimeoutMs * (this.Endpoints.length + 1);

}
getOne(TxHash) {
getOne(TxHash, WaitForSeconds = 0) {
return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.get(TxHash);
const tx = yield this.get(TxHash, WaitForSeconds);
this.end();

@@ -126,3 +130,3 @@ return tx;

}
get(TxHash) {
get(TxHash, WaitForSeconds = 0) {
return __awaiter(this, void 0, void 0, function* () {

@@ -139,5 +143,22 @@ if (this.Ended) {

var e_1, _a;
const Timer = setTimeout(() => {
reject(this.GenerateError('MAX_LOOKUP_TIME_REACHED'));
}, this.LookupTimeoutMs);
let Timer;
let WaitMode = false;
let WaitModeFinish;
const setTimer = (SecondsAdded = 0) => {
clearTimeout(Timer);
const timeoutMs = this.LookupTimeoutMs + SecondsAdded * 1000;
log('Set Timeout Timer at (sec)', timeoutMs / 1000);
const TimedOut = () => {
if (WaitMode) {
WaitModeFinish();
}
else {
reject(this.GenerateError('MAX_LOOKUP_TIME_REACHED'));
}
};
Timer = setTimeout(() => {
TimedOut();
}, timeoutMs);
};
setTimer();
const cleanup = () => {

@@ -147,10 +168,39 @@ clearTimeout(Timer);

this.EventBus.removeListener('result', onTx);
this.EventBus.listeners('tx.' + TxHash).forEach(l => this.EventBus.removeListener('tx.' + TxHash, l));
};
const ResolveFormatted = (eventResult, resolvedBy, host) => {
cleanup();
const result = this.FormatResult(eventResult);
const balanceChanges = typeof result.meta !== 'undefined'
? balanceParser_1.parseBalanceChanges(result.meta)
: {};
resolve({ result, resolvedBy, host, balanceChanges });
var _a;
const finish = (customEventResult, customHost) => {
var _a, _b, _c, _d, _e;
cleanup();
const result = this.FormatResult(customEventResult ? customEventResult : eventResult);
const balanceChanges = typeof result.meta !== 'undefined'
? balanceParser_1.parseBalanceChanges(result.meta)
: {};
resolve({
result: (customEventResult === null || customEventResult === void 0 ? void 0 : customEventResult.result) ? Object.assign(Object.assign({}, (_a = customEventResult.result) === null || _a === void 0 ? void 0 : _a.transaction), { meta: (_b = customEventResult.result) === null || _b === void 0 ? void 0 : _b.meta, validated: (_c = customEventResult.result) === null || _c === void 0 ? void 0 : _c.validated, ledger_index: (_d = customEventResult.result) === null || _d === void 0 ? void 0 : _d.ledger_index, inLedger: (_e = customEventResult.result) === null || _e === void 0 ? void 0 : _e.ledger_index }) : result,
resolvedBy: customHost ? 'asynchash' : resolvedBy,
host: customHost ? customHost : host,
balanceChanges
});
};
if (((_a = eventResult) === null || _a === void 0 ? void 0 : _a.error) === 'txnNotFound' && WaitForSeconds > 0) {
// Not found
if (!WaitMode) {
log('TX not found on ledger, could still arrive, wait for # sec.:', WaitForSeconds, TxHash);
setTimer(WaitForSeconds);
WaitMode = true;
WaitModeFinish = finish;
this.EventBus.once('tx.' + TxHash, event => {
finish({
status: event.response.status,
type: event.response.type,
result: event.response
}, event.url);
});
}
}
else {
finish();
}
};

@@ -263,2 +313,3 @@ const onTx = (r) => {

socket.send(JSON.stringify({ command: 'server_info' }));
socket.send(JSON.stringify({ command: 'subscribe', streams: ['transactions'] }));
}

@@ -280,3 +331,3 @@ };

socket.onmessage = (m) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e, _f, _g;
try {

@@ -286,9 +337,14 @@ const response = JSON.parse(m.data.toString());

this.EventBus.emit('xrpljson', response);
const txHash = (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.hash;
if (((_c = response) === null || _c === void 0 ? void 0 : _c.validated) && txHash) {
// log('Seen TX', txHash, 'emitted', 'tx.#')
this.EventBus.emit('tx.' + txHash, { response, url: socket.url });
}
}
else {
if (typeof ((_b = (_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.complete_ledgers) !== 'undefined') {
if (typeof ((_e = (_d = response === null || response === void 0 ? void 0 : response.result) === null || _d === void 0 ? void 0 : _d.info) === null || _e === void 0 ? void 0 : _e.complete_ledgers) !== 'undefined') {
socketMeta.ready = true;
const ledgerString = String(((_d = (_c = response === null || response === void 0 ? void 0 : response.result) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.complete_ledgers) || '');
const ledgerString = String(((_g = (_f = response === null || response === void 0 ? void 0 : response.result) === null || _f === void 0 ? void 0 : _f.info) === null || _g === void 0 ? void 0 : _g.complete_ledgers) || '');
const isFullHistory = ledgerString.split(',').length < 2 && ledgerString.split('-')[0] === '32570';
if (!isFullHistory) {
if (!isFullHistory && !this.AllowNoFullHistory) {
logInvalid('Closed connection to ', socket.url, 'incomplete history:', ledgerString);

@@ -362,3 +418,5 @@ this.Endpoints[index] = '';

if (r.id === id) {
this.EventBus.off('xrpljson', onTx);
process.nextTick(() => {
this.EventBus.removeListener('xrpljson', onTx);
});
return resolve(r);

@@ -365,0 +423,0 @@ }

{
"name": "xrpl-txdata",
"version": "1.1.2",
"version": "1.2.1",
"description": "Fetch XRPL transaction by hash (+ meta & balances), awaits if required",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -31,3 +31,3 @@ # XRPL Transaction Data fetcher [![npm version](https://badge.fury.io/js/xrpl-txdata.svg)](https://www.npmjs.com/xrpl-txdata) [![GitHub Actions NodeJS status](https://github.com/XRPL-Labs/XrplTxData/workflows/NodeJS/badge.svg?branch=main)](https://github.com/XRPL-Labs/XrplTxData/actions) [![CDNJS Browserified](https://img.shields.io/badge/cdnjs-browserified-blue)](https://cdn.jsdelivr.net/gh/XRPL-Labs/XrplTxData@main/dist/browser.js) [![CDNJS Browserified Minified](https://img.shields.io/badge/cdnjs-minified-orange)](https://cdn.jsdelivr.net/gh/XRPL-Labs/XrplTxData@main/dist/browser.min.js)

Fetching multiple transactionos and close the WebSocket connection(s) programmatically:
Fetching multiple transactions and close the WebSocket connection(s) programmatically:

@@ -52,2 +52,17 @@ ```javascript

### Fetching a transaction that may not have been applied to a ledger
When you are using this lib. to fetch a transaction, you may fetch a transaction before a transaction has been included in a validated ledger. This would result in a "Not Found" error, while if queried a couple of seconds later, the transaction would have been found.
If you are dealing with live / realtime transactions, you may want to instruct this lib. to wait a couple of more seconds while monitoring the live XRP Ledger transaction stream for the transaction(s) you're interested in.
You can do this by providing a second argument (Number, time in seconds) to the `.get()` or `.getOne()` methods. When a second argument (Number, time in seconds) is provided & the initial call will yield a "Not Found" error, this lib. will watch the live transaction stream for the provided amount of seconds and resolve when the transaction hits a validated ledger. If the transaction is not included in a ledger within the provided amount of seconds, the `.get()` or `.getOne()` method will resolve with the initial "Not Found" response.
```javascript
txd.get('85E19A60511544759C3F6EF814EDCDDE606640991CDDE5409354D21112F91EAA', 20)
.then(tx => {
log(`Got it anyway`, tx)
})
```
#### Advanced options

@@ -86,3 +101,6 @@

// Throw an error if none of the servers connected & replied in 5 seconds
OverallTimeoutMs: 5000
OverallTimeoutMs: 5000,
// Throw an error none of the provided nodes provides full history. If
// you want to allow non full history nodes, set to `true`.
AllowNoFullHistory: false
})

@@ -108,3 +126,3 @@ ```

- `host` (string): the endpoint (connetion url) of the first node replying to the request
- `resolvedBy` (string): `"generator"` if the host replied within the `EndpointTimeoutMs` timeout, `"emitter"` if the first reply came in after the `EndpointTimeoutMs` timeout, but before the next host replied
- `resolvedBy` (string): `"generator"` if the host replied within the `EndpointTimeoutMs` timeout, `"emitter"` if the first reply came in after the `EndpointTimeoutMs` timeout, but before the next host replied, or `"asynchash"` if resolved by waiting & monitoring the live ledger transaction stream
- **`result`** (object): containing the error or transaction response from the XRPL node

@@ -132,3 +150,3 @@ - **`balanceChanges`** (object): containing the parsed balance changes for all accounts affected by this transaction

"host": "wss://s2.ripple.com/",
"balanceChanges": {}
"balanceChanges": {, or `"asynchash"` if resolved by waiting & monitoring the live ledger transaction stream
}

@@ -196,3 +214,3 @@ ```

"host": "wss://s2.ripple.com/",
"balanceChanges": {
"balanceChanges": , or `"asynchash"` if resolved by waiting & monitoring the live ledger transaction stream
"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq": [

@@ -199,0 +217,0 @@ {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc