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 510 forks source link

How to get all created accounts of my rippled without DATA api? #874

Closed JJNET closed 6 years ago

JJNET commented 6 years ago

I can't find RippleAPI to get all accounts created by my rippled of server.

How can I get all accounts created by function "generateAddress" of RippleAPI?

If impossible, Can I dynamically add account for subscribing & unsubscribing?

It is very important to manage huge accounts of crypto exchange in order to operate without suspension or shutdown websocket subscribing server.

cf) I wrote this code to subscribe multi account's transaction, and it is well doing now. (All accounts is testnet addresses.)

const RippleAPI = require('ripple-lib').RippleAPI const api = new RippleAPI({ server: 'ws://localhost:6006' // Private rippled server });

api.on('error', (errorCode, errorMessage, data) => { console.log(errorCode + ': ' + errorMessage); });

api.on('connected', () => { console.log('Connection is open now.'); });

//const account = 'rEsxttdiVe9Ps8taKqMBUcMsq7QcUfMhtq' api.connect().then( () => { api.connection.on('transaction', (ev) => { var txhash = JSON.stringify(ev["transaction"]["hash"], null, 2) var valida = JSON.stringify(ev["validated"], null, 2) txhash = txhash.replace(/\"/gi, '') if(valida == "true" ) { console.log(txhash) } }) return api.connection.request({ command: 'subscribe', accounts: [ 'rEsxttdiVe9Ps8taKqMBUcMsq7QcUfMhtq', 'rJRRYqUGdtCxPBnio6zzHY4BRok9kqSoVD', 'rpSZeSoudR3qGTKEezvZxEqrsjEYcxEy3T', 'rMcHxejVWj6nRWMxuBCWGXzeafsvEAYsGT' ] }) })

intelliot commented 6 years ago

@JJNET rippled and RippleAPI do not store the accounts that they create.

To subscribe/unsubscribe from accounts, you'll need to issue the subscribe (or unsubscribe) command each time. See https://ripple.com/build/rippled-apis/#subscriptions

Most apps do not need to monitor large numbers of accounts. Exchanges typically use 1-2 hot/cold accounts. Use destination tags to distinguish deposits from different customers.

If you operate your own rippled server, you should be able to perform as many subscribe and unsubscribe calls as you need.

Does this help?

JJNET commented 6 years ago

Hi @intelliot

I know that. And I know DATA api can do it. by https://ripple.com/build/data-api-v2/#get-accounts (But, It doesn't support RippleAPI maybe.)

So I have a plan to solve this problem.

If Node.js server receive "generateAddress" command via client, then I call 'subscribe' command at the same time.

But, I don't know it is possible or not. Because one side of forked daemon(websocket subscribing server) have to subscribe transaction from rippled and the other side have to wait client command to register address for subscription.

JJNET commented 6 years ago

@intelliot

And I surprised that Exchanges typically use 1 or 2 hot/cold accounts. Really? Bitcoin or Ethereum use as much as members' counts.

And I am knowing that destination tag is a "address" by returned JSON of subscribing as follows: (rEsxttdiVe9Ps8taKqMBUcMsq7QcUfMhtq is account's address)

"transaction": { "Account": "rsNUZ9DgJKqs76qV5japkeSVVnu1eXgwJQ", "Amount": "20000000", "Destination": "rEsxttdiVe9Ps8taKqMBUcMsq7QcUfMhtq", "Fee": "12", "Flags": 2147483648, "LastLedgerSequence": 7739964, "Sequence": 13, "SigningPubKey": "02A5D08C079E138669FBBE85437EBFB6B365215523DA4C47B6197B8584FAB0E81C", "TransactionType": "Payment", "TxnSignature": "3045022100DE2D4FE738677487EE012F0C86E27945117DD23D2CFE5AAFD2D1BEC0895222850220168D0902AF1AAAB876BB1A24772C56178DAA23BAA479D9E7AB666E630250E503", "date": 575194073, "hash": "D20720D4E6A672A07E8A6052D6C53E4A3DAD0211A7CC6D1DFAD81207662D6522" },

JJNET commented 6 years ago

Hi @intelliot

I just put the program into the concept as I said above and just tested it. It works well. But there's a fatal problem. If I stop Node.js daemon, All addressed accounts was lost.

It looks like registered subscribe accounts are managed by Node.js other than rippled itself.

intelliot commented 6 years ago

@JJNET Correct - the XRP Ledger uses an account-based ledger, different from Bitcoin/Ethereum. Each account has reserve requirements (currently 20 XRP), making it cost-prohibitive to create an account for each member. Instead, a few accounts will suffice.

No, the destination tag is not the address. You can read more about destination tags here:

The subscribed accounts are specific to your websocket connection with rippled. These are not persisted, so you should store them yourself, in your own database or other persistent storage.

intelliot commented 6 years ago

Since subscriptions are specific to one websocket connection instance, they are not persisted after the websocket is closed or disconnected. You'll need to have your own persistent storage to keep track of the accounts you care about. I'm closing this issue, but feel free to open a new one if you have additional questions. Thanks!