Skip to content

Commit 25ea385

Browse files
authored
docs(api): add js example for subscribeToTransactionsWithProofs (#115)
* docs(api): add js example for subscribeToTransactionsWithProofs * docs(api): clarify how to stream continuously * docs(api): update status messages
1 parent 7366555 commit 25ea385

1 file changed

Lines changed: 77 additions & 5 deletions

File tree

docs/reference/dapi-endpoints-core-grpc-endpoints.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,79 @@ the update messages following a new block.
497497
| `from_block_hash` | Bytes | No | Return records beginning with the block hash provided |
498498
| `from_block_height` | Integer | No | Return records beginning with the block height provided |
499499
| ---------- | | | |
500-
| `count` | Integer | No | Number of blocks to sync. If set to 0 syncing is continuously sends new data as well (default: 0) |
500+
| `count` | Integer | No | Number of blocks to sync. If set to 0, syncing continuously sends new data as well (default: 0) |
501501
| `send_transaction_hashes` \* | Boolean | No | |
502502

503503
**Example Request and Response**
504504

505+
:::{note}
506+
Set `count` to 0 to continuously stream new data.
507+
:::
508+
505509
::::{tab-set}
510+
:::{tab-item} JavaScript (dapi-client)
511+
:sync: js-dapi-client
512+
```javascript
513+
const DAPIClient = require('@dashevo/dapi-client');
514+
515+
(async () => {
516+
const client = new DAPIClient({
517+
network: 'testnet',
518+
seeds: [{
519+
host: 'seed-1.testnet.networks.dash.org',
520+
port: 1443,
521+
}],
522+
});
523+
524+
const bloomFilter = {
525+
vData: [0xff],
526+
nHashFuncs: 1,
527+
nTweak: 0,
528+
nFlags: 0,
529+
};
530+
531+
const stream = await client.core.subscribeToTransactionsWithProofs(
532+
bloomFilter,
533+
{
534+
fromBlockHeight: 1232900,
535+
count: 0, // 0 = continuosly stream new data too
536+
},
537+
);
538+
539+
stream.on('data', (response) => {
540+
// If it's a protobufjs object, convert it
541+
if (typeof response.toObject === 'function') {
542+
response = response.toObject();
543+
}
544+
545+
if (response.rawTransactions) {
546+
const rawTxs = response.rawTransactions.transactionsList || [];
547+
console.log(`Received ${rawTxs.length} raw transaction(s)`);
548+
rawTxs.forEach((tx, i) => console.log(`\tTX #${i + 1}:`, Buffer.from(tx, 'base64').toString('hex')));
549+
} else if (response.rawMerkleBlock) {
550+
console.log(' Received Merkle block:', Buffer.from(response.rawMerkleBlock, 'base64').toString('hex'));
551+
} else if (response.instantSendLockMessages) {
552+
const locks = response.instantSendLockMessages.messagesList || [];
553+
console.log(`Received ${locks.length} InstantSend lock message(s)`);
554+
locks.forEach((msg, i) => console.log(`\tInstantSend Lock #${i + 1}:`, Buffer.from(msg, 'base64').toString('hex')));
555+
} else {
556+
console.log('Warning: unknown or empty response message:', response);
557+
}
558+
});
559+
560+
stream.on('error', (err) => console.error('Stream error:', err));
561+
stream.on('end', () => console.log('Stream ended'));
562+
stream.on('close', () => console.log('Stream closed'));
563+
})();
564+
```
565+
:::
506566
:::{tab-item} Request (gRPCurl)
567+
:sync: grpcurl
507568
```shell
508569
grpcurl -proto protos/core/v0/core.proto \
509570
-d '{
510-
"from_block_height": 1,
511-
"count": 1,
571+
"from_block_height": 1232900,
572+
"count": 0,
512573
"bloom_filter": {
513574
"n_hash_funcs": 11,
514575
"v_data": "",
@@ -523,6 +584,16 @@ grpcurl -proto protos/core/v0/core.proto \
523584
::::
524585

525586
::::{tab-set}
587+
:::{tab-item} Response (JavaScript)
588+
:sync: js-dapi-client
589+
```text
590+
Received Merkle block: 00000020384e6d494ba7ac426fe3f2bc990b1a1d46102ac0fc24e86a462653f32e0000002b848697ba771189baf8031fe52a4ef9b69d4259599104744271f53c4b3b3403895cfe67f4bb011ee0200f000200000002c0f0c91ad505b883996cc351e63976a7b0234d13547a8f7ace3c5776d051091f1a8e035c7f667bc21ad277ff50e25c11a99fc5e71a6f6ef5e96e720c4c9f47c40107
591+
Received 1 raw transaction(s)
592+
TX #1: 020000000202b72745ae5d7a8a2ef7b02f37e921d479cf3a27a899bc9fefbdc4a9558db344000000006a4730440220732d3a959630dc7b21bbf5c54d2968f0d72db922ad3556a004d63da064e68bf3022026423cabb47bb2a90cee7667f3d2bc53d2bbed56c8ac4001fc542ce4e77cee5a01210299b5e857403e74ef789dcfec66db750212f97d3282005df161a4f77370bc9a41feffffff345fbdad892f72f9a03d0bca6999d3dd9b310cf029816c19968d0ec59ae90caa000000006a47304402207bef35c51926e2a8f6c04ac3db701973f5188f1a9bfcacecac97d5a9c368804102206e9a30f4bb78581ec453ce9a3dbfe6dbd2286a9d80111873138d2391b764cbf001210315c295b58ade2af42ba53e17bfc0224e855f3f6d71c80b698d18a6084f74da25feffffff0240420f00000000001976a9146c503d4a6c85d349153f354a03bc77b50910ed6688ac710c2c00000000001976a914e7bd063a8420b439f4131dd90c305fbe20b5f80388ac52d01200
593+
Received 1 InstantSend lock message(s)
594+
InstantSend Lock #1: 010202b72745ae5d7a8a2ef7b02f37e921d479cf3a27a899bc9fefbdc4a9558db34400000000345fbdad892f72f9a03d0bca6999d3dd9b310cf029816c19968d0ec59ae90caa00000000ca0921f521075ca588738264440890ee3734246ee73c32990a6b9ca41c53ff9941e8984fdf68edb10a39140e045580bc19a871d6c62c624588fad31f1c0000008028345007268bcd091b39c6da8609e60817beb137b5a5a4335ace2b86661a570ee9cfb9a400c35c2ce5471a8edc33ae04d822dccb59d40135c975dbf0246261fcf2def2aa10d73d32592cb0f320edf06e66d012fe5b96335766bfb4e203fbbd
595+
```
596+
:::
526597
:::{tab-item} Response (gRPCurl)
527598
:sync: grpcurl
528599

@@ -532,12 +603,13 @@ Note: The gRPCurl response `transactions` and `rawMerkleBlock` data is Base64 en
532603
{
533604
"rawTransactions": {
534605
"transactions": [
535-
"AQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////8KUQEBBi9QMlNIL/////8BAHQ7pAsAAAAjIQIBMfOK4+sHFFMdv8P0VJG0Ex0SEeN3cXdjY4i7WnTD5KwAAAAA"
606+
"AwAFAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////8GAybQEgEB/////wN0aR0EAAAAABl2qRTGmgvafaquSBvo3vleXzR6HQCktIisiBWhBAAAAAABatMmtwcAAAAAGXapFMaaC9p9qq5IG+je+V5fNHodAKS0iKwAAAAArwMAJtASAI9++NlWNSgVfoN30b0i6+0MJU6HoUW8um8+Z4wnNN6ryzPggHZKesGiP7BSqWS2GJyNyoDKExUBb8JOo4SnWiwAiS4d6Qfq46Q5P7Ikc5FU1veS1BSOjANjy/TMxSW41lIimTJeC7uTelTgKUQRGuvGBpISS6JTaKe9EAyVssguGF6pkfGIrPXhSmnFYa6zVZOw+FImDqXAWuiA4fbrg++XnRFN+xAMAAA=",
607+
"AwAIAAGfo1ucb0QXQcszv3goPfj2HQ7hXy1H/UfV4sJxbRAelwEAAABqRzBEAiBHbuT42FzrisDUwTDWNZOwUzpeVqZD/4d63GqQtfazRAIgQ0D3R7zwdGggf6aV5+zn5Ny++EicUxy9JyTlfcmTWY4BIQL92QF9a831X8s6DQOxwj9gbvIRpKyXueTh+8F0mOo5p/////8CQEIPAAAAAAACagBHZZEHAAAAABl2qRTPU/9NqtGCTtqRtTv4GHut2FoTO4isAAAAACQBAUBCDwAAAAAAGXapFN4Kl0QKTPQeGVBUWowbrllp8NipiKw="
536608
]
537609
}
538610
}
539611
{
540-
"rawMerkleBlock": "AgAAACy8+DtikT1W9gXA5YGkiHKDlCjJLl63bNetlLyvCwAAfxHczhQHVSDo90zE3fCStOJuvSO42GZaGuW/xBtY/bTDqV5T//8PHvN6AAABAAAAAX8R3M4UB1Ug6PdMxN3wkrTibr0juNhmWhrlv8QbWP20AQE="
612+
"rawMerkleBlock": "AAAAIDhObUlLp6xCb+PyvJkLGh1GECrA/CToakYmU/MuAAAAK4SGl7p3EYm6+AMf5SpO+badQllZkQR0QnH1PEs7NAOJXP5n9LsBHuAgDwACAAAAAsDwyRrVBbiDmWzDUeY5dqewI00TVHqPes48V3bQUQkfGo4DXH9me8Ia0nf/UOJcEamfxecab2716W5yDEyfR8QBBw=="
541613
}
542614
```
543615
:::

0 commit comments

Comments
 (0)