XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

Stream of transactions #758

Closed tuloski closed 6 years ago

tuloski commented 7 years ago

Is there a way to subscribe to a server and get a stream of all transactions that are put in the open ledger before the ledger closes? I didn't see anything in the docs.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/44573129-stream-of-transactions?utm_campaign=plugin&utm_content=tracker%2F323756&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F323756&utm_medium=issues&utm_source=github).
sublimator commented 7 years ago

The raw rippled API definitely supports it, though I'm not sure about RippleAPI

tuloski commented 7 years ago

Thanks. But I'm almost sure it was supported in old versions.

sublimator commented 7 years ago

Define old version :) ?

tuloski commented 7 years ago

When it was called ripple-lib, before it became rippleAPI, probably up to release 0.13

sublimator commented 7 years ago

Yeah, with RippleAPI, they decided to wash over the raw rippled api, with different names/semantics etc. I'm sure there's probably some way you could make use of the connection though.

sublimator commented 7 years ago

https://github.com/ripple/ripple-lib/blob/develop/src/api.js#L96

sublimator commented 7 years ago

https://github.com/ripple/ripple-lib/blob/develop/src/common/connection.js#L389

sublimator commented 7 years ago

https://ripple.com/build/rippled-apis/#transaction-streams

You need to subscribe to the transactions_proposed stream

inmyth commented 7 years ago

I upvote this issue. The subscribe function disappeared on the newer version (right now it's 0.17.x). The ripple-lib library used in Ripple Websocket demo is version 0.11. Also compare it with this working snippet of subscription : http://code.runnable.com/VNyyD5TVKuVs7aZu/ripple-lib-subscribe-for-node-js With this library we can only listen to a ledger event. So it's not a stream, it basically just calls an API everytime a ledger closes.

api.connect().then(() => {
    api.getOrderbook(address, orderbook).then(orderbook => {
        console.log(JSON.stringify(orderbook, null, 2));
    });

});

api.on('ledger', ledger => {
    api.getOrderbook(address, orderbook).then(orderbook => {
        console.log(JSON.stringify(orderbook, null, 2));
    });
});

And unfortunately Ripple makes it clear there is no way to get unvalidated transactions (accounts_proposed) with this API.

RippleAPI only provides access to validated, immutable transaction data.

Julyyq commented 7 years ago

@sublimator Do you know "how to subscribe to the transactions_proposed stream"? using RippleAPI?

Julyyq commented 7 years ago

I found the version 0.7.34 has this method: remote.request_subscribe().accounts(data.account,false).request();. But with 0.17.x, how to do that?

wilsonianb commented 7 years ago

You can subscribe to websocket streams using a library like ws (no ripple-lib required). Here's an example of a validations subscription: https://github.com/wilsonianb/validation-count-reporter/blob/d03f74c20f80da420a291760693cbc5d5bcec9f7/index.js#L102-L156

Julyyq commented 7 years ago

@wilsonianb Thanks very much!

intelliot commented 6 years ago

This will also be available in an upcoming release of ripple-lib; see https://github.com/ripple/ripple-lib/blob/14704ee/docs/index.md#listening-to-streams