Skip to content

Commit

Permalink
feat: add listener callback to socket-io client subscription functions (
Browse files Browse the repository at this point in the history
#1799)

* feat: add listener callback to socket-io client subscription functions

* chore: fix test

* test: add unit tests for socket-io-client

* docs: update socket-io client docs

* chore: lint fix in client lib src

* test: fix flaky pox test
  • Loading branch information
zone117x authored Jan 5, 2024
1 parent 5050763 commit 5634522
Show file tree
Hide file tree
Showing 11 changed files with 2,785 additions and 2,191 deletions.
1 change: 1 addition & 0 deletions client/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/generated/*
29 changes: 16 additions & 13 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ import * as stacks from '@stacks/blockchain-api-client';
// for testnet, replace with https://api.testnet.hiro.so/
const socketUrl = "https://api.mainnet.hiro.so/";

const socket = io(socketUrl, {
transports: [ "websocket" ]
});
const socket = io(socketUrl);
const sc = new stacks.StacksApiSocketClient(socket);

sc.subscribeAddressTransactions('ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA');
sc.subscribeAddressTransactions('ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', (address, tx) => {
console.log('address:', address);
console.log('tx:', tx);
});
```

## Available Updates
Expand Down Expand Up @@ -108,7 +109,7 @@ client.subscribeBlocks(event => {});
```
Subscribe via Socket.io:
```js
sc.subscribeBlocks();
sc.subscribeBlocks(block => {});
```

### Microblock Updates
Expand Down Expand Up @@ -149,7 +150,7 @@ client.subscribeMicroblocks(event => {});
```
Subscribe via Socket.io:
```js
sc.subscribeMicroblocks();
sc.subscribeMicroblocks(microblock => {});
```

### Mempool Updates
Expand Down Expand Up @@ -210,7 +211,7 @@ client.subscribeMempool(event => {});
```
Subscribe via Socket.io:
```js
sc.subscribeMempool();
sc.subscribeMempool(mempoolTx => {});
```

### Transaction Updates
Expand Down Expand Up @@ -277,7 +278,7 @@ client.subscribeTxUpdates('0xd78988664aaa9a1b751cd58c55b253914f790e95ca6f3d402a8
```
Subscribe via Socket.io:
```js
sc.subscribeTransaction('0xd78988664aaa9a1b751cd58c55b253914f790e95ca6f3d402a866559e1cbe0b3');
sc.subscribeTransaction('0xd78988664aaa9a1b751cd58c55b253914f790e95ca6f3d402a866559e1cbe0b3', tx => {});
```

### Address Transaction Updates
Expand Down Expand Up @@ -366,7 +367,7 @@ client.subscribeAddressTransactions('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q',
```
Subscribe via Socket.io:
```js
sc.subscribeAddressTransactions('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q');
sc.subscribeAddressTransactions('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q', (address, tx) => {});
```

### Address Balance Updates
Expand Down Expand Up @@ -412,7 +413,7 @@ client.subscribeAddressBalanceUpdates('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q
```
Subscribe via Socket.io:
```js
sc.subscribeAddressStxBalance('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q');
sc.subscribeAddressStxBalance('SP3C5SSYVKPAWTR8Y63CVYBR65GD3MG7K80526D1Q', (addr, balance) => {});
```

### NFT event updates
Expand Down Expand Up @@ -451,13 +452,15 @@ client.subscribeNftCollectionEventUpdates(
```
Subscribe via Socket.io:
```js
sc.subscribeNftEventUpdates();
sc.subscribeNftAssetEventUpdates(
sc.subscribeNftEvent(nftEvent => {});
sc.subscribeNftAssetEvent(
'SP176ZMV706NZGDDX8VSQRGMB7QN33BBDVZ6BMNHD.project-indigo-act1::Project-Indigo-Act1',
'0x0100000000000000000000000000000095',
(assetId, value, nftEvent) => {}
);
sc.subscribeNftCollectionEventUpdates(
sc.subscribeNftCollectionEvent(
'SP176ZMV706NZGDDX8VSQRGMB7QN33BBDVZ6BMNHD.project-indigo-act1::Project-Indigo-Act1',
(assetId, nftEvent) => {}
);
```

Expand Down
Loading

0 comments on commit 5634522

Please sign in to comment.