Skip to content

Commit

Permalink
docs: bring in latest dapi-client changes from platform repo
Browse files Browse the repository at this point in the history
  • Loading branch information
thephez committed Aug 28, 2024
1 parent c7d11fa commit 0b44f77
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 53 deletions.
4 changes: 2 additions & 2 deletions docs/dapi-client-js/usage/core/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
broadcasttransaction
generatetoaddress
getbestblockhash
getblockbyhash
getblockbyheight
getblockhash
getmnlistdiff
getstatus
gettransaction
subscribetoblockheaderswithchainlocks
subscribetomasternodelist
subscribetotransactionswithproofs
```
15 changes: 0 additions & 15 deletions docs/dapi-client-js/usage/core/generatetoaddress.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/dapi-client-js/usage/core/getmnlistdiff.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# subscribeToBlockHeadersWithChainLocks

**Usage**: `await client.core.subscribeToBlockHeadersWithChainLocks(options = { count: 0 })`\
**Description**: Returns a ClientReadableStream streaming of block headers and chainlocks.

Parameters:

| parameters | type | required | Description |
|----------------------------|------------------|----------------| ------------------------------------------------------------------------------------------------ |
| **options.fromBlockHash** | String | yes | Specifies block hash to start syncing from |
| **options.fromBlockHeight**| Number | yes | Specifies block height to start syncing from |
| **options.count** | Number | no (default: 0)| Number of blocks to sync, if set to 0 syncing is continuously sends new data as well |

Returns : Promise<EventEmitter>|!grpc.web.ClientReadableStream<!BlockHeadersWithChainLocksResponse>

Example :

```js
const { BlockHeader, ChainLock } = require('@dashevo/dashcore-lib');

const stream = await client.subscribeToBlockHeadersWithChainLocks({ fromBlockHeight: 0 });

stream
.on('data', (response) => {
const rawHeaders = response.getBlockHeaders();
const rawChainLock = response.getChainLock();

if (headers.length > 0) {
const headers = rawHeaders.map((rawHeader) => new BlockHeader(rawHeader));
console.dir(headers);
}

if (rawChainLock) {
const chainLock = new ChainLock(rawChainLock);
}
})
.on('error', (err) => {
// do something with err
});
```
26 changes: 26 additions & 0 deletions docs/dapi-client-js/usage/core/subscribetomasternodelist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# subscribeToMasternodeList

**Usage**: `await client.core.subscribeToMasternodeList(options = {})`\
**Description**: Returns a ClientReadableStream streaming of masternode list diffs ([DIP-4](https://github.com/dashpay/dips/blob/master/dip-0004.md)). As a first message it returns a diff from the first block to the current tip and a diff for each new chainlocked block.

Returns : Promise<EventEmitter>|!grpc.web.ClientReadableStream<!MasternodeListResponse>

Example :

```js
const { SimplifiedMNList, SimplifiedMNListDiff } = require('@dashevo/dashcore-lib');

const stream = await client.subscribeToMasternodeList();

const list = new SimplifiedMNList();

stream
.on('data', (response) => {
const diffBuffer = Buffer.from(response.getMasternodeListDiff_asU8());
const diff = new SimplifiedMNListDiff(diffBuffer);
list.applyDiff(diff);
})
.on('error', (err) => {
// do something with err
});
```
47 changes: 25 additions & 22 deletions docs/dapi-client-js/usage/core/subscribetotransactionswithproofs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,45 @@

Parameters:

| parameters | type | required | Description |
| --------------------------- | ---------------- | --------------- | --------------------------------------------------------------------------------------------------------- |
| **bloomFilter.vData** | Uint8Array/Array | yes | The filter itself is simply a bit field of arbitrary byte-aligned size. The maximum size is 36,000 bytes. |
| **bloomFilter.nHashFuncs** | Number | yes | The number of hash functions to use in this filter. The maximum value allowed in this field is 50. |
| **bloomFilter.nTweak** | Number | yes | A random value to add to the seed value in the hash function used by the bloom filter. |
| **bloomFilter.nFlags** | Number | yes | A set of flags that control how matched items are added to the filter. |
| **options.fromBlockHash** | String | yes | Specifies block hash to start syncing from |
| **options.fromBlockHeight** | Number | yes | Specifies block height to start syncing from |
| **options.count** | Number | no (default: 0) | Number of blocks to sync, if set to 0 syncing is continuously sends new data as well |

Returns : Promise<EventEmitter>|!grpc.web.ClientReadableStream\<!TransactionsWithProofsResponse>
| parameters | type | required | Description |
|----------------------------|------------------|----------------| ------------------------------------------------------------------------------------------------ |
| **bloomFilter.vData** | Uint8Array/Array | yes | The filter itself is simply a bit field of arbitrary byte-aligned size. The maximum size is 36,000 bytes. |
| **bloomFilter.nHashFuncs** | Number | yes | The number of hash functions to use in this filter. The maximum value allowed in this field is 50. |
| **bloomFilter.nTweak** | Number | yes | A random value to add to the seed value in the hash function used by the bloom filter. |
| **bloomFilter.nFlags** | Number | yes | A set of flags that control how matched items are added to the filter. |
| **options.fromBlockHash** | String | yes | Specifies block hash to start syncing from |
| **options.fromBlockHeight**| Number | yes | Specifies block height to start syncing from |
| **options.count** | Number | no (default: 0)| Number of blocks to sync, if set to 0 syncing is continuously sends new data as well |

Returns : Promise<EventEmitter>|!grpc.web.ClientReadableStream<!TransactionsWithProofsResponse>

Example :

```js
const filter; // A BloomFilter object
const { BloomFilter, Transaction, MerkleBlock } = require('@dashevo/dashcore-lib');

const filter = BloomFilter.create(1, 0.001); // A BloomFilter object
const stream = await client.subscribeToTransactionsWithProofs(filter, { fromBlockHeight: 0 });

stream
.on('data', (response) => {
const merkleBlock = response.getRawMerkleBlock();
const transactions = response.getRawTransactions();
const rawMerkleBlock = response.getRawMerkleBlock();
const rawTransactions = response.getRawTransactions();

if (merkleBlock) {
const merkleBlockHex = Buffer.from(merkleBlock).toString('hex');
const merkleBlock = new MerkleBlock(rawMerkleBlock);
console.dir(merkleBlock);
}

if (transactions) {
transactions.getTransactionsList()
.forEach((tx) => {
// tx are probabilistic, so you will have to verify it's yours
const tx = new Transaction(Buffer.from(tx));
});
if (transactions.length > 0) {
// tx are probabilistic, so you will have to verify it's yours
const transactions = transactions.getTransactionsList()
.map((tx) => new Transaction(Buffer.from(tx)));

console.dir(transactions);
}
})
.on('error', (err) => {
// do something with err
});
```
```

0 comments on commit 0b44f77

Please sign in to comment.