Skip to content

Commit

Permalink
Bugfix Websocket hostname. (#21)
Browse files Browse the repository at this point in the history
* Add yarn-error.log to gitignore.

* Add ts-node to devDependencies.
Add script to only build tsc.
Add websocket to keywords.

* Update yarn.lock libs.

* FIX websocket endpoint hostname.
FIX corrent import for all examples.
FIX websocket instrucions on readme.
  • Loading branch information
MiguelMedeiros authored May 20, 2021
1 parent 0aa3757 commit e3068c2
Show file tree
Hide file tree
Showing 28 changed files with 242 additions and 175 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/node_modules
/lib
/dist/*
!.gitkeep
!.gitkeep

yarn-error.log
103 changes: 56 additions & 47 deletions README-bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,60 +630,69 @@ Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you wa

Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions.

[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ]
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]

#### **Websocket Server**

```js
const {
bitcoin: { websocket },
} = mempoolJS();

const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
Only use on server side apps.

ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
```js
const { bitcoin: { websocket } } = mempoolJS();

const init = async () => {

const ws = websocket.initServer({
options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
});

ws.on("message", function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
}
init();
```

#### **Websocket Client**

```js
const {
bitcoin: { websocket },
} = mempoolJS();
Only use on browser apps.

const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
```js
const init = async () => {
const {
bitcoin: { websocket },
} = mempoolJS();

const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
};
init();
```
109 changes: 59 additions & 50 deletions README-liquid.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,60 +698,69 @@ Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you wa

Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions.

[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ]
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]

#### **Websocket Server**

```js
const {
liquid: { websocket },
} = mempoolJS();

const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
Only use on server side apps.

```js
const { liquid: { websocket } } = mempoolJS();

const init = async () => {

const ws = websocket.initServer({
options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
});

ws.on("message", function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
}
init();
```

#### **Websocket Client**

```js
const {
liquid: { websocket },
} = mempoolJS();

const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
```
Only use on browser apps.

```js
const init = async () => {
const {
liquid: { websocket },
} = mempoolJS();

const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
};
init();
```
4 changes: 2 additions & 2 deletions examples/html/bitcoin/websocket.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
const {
bitcoin: { websocket },
} = mempoolJS();
// console.log(mempoolJS());

const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.on('message', function incoming(data) {
ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
Expand Down
6 changes: 3 additions & 3 deletions examples/html/liquid/websocket.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
const {
liquid: { websocket },
} = mempoolJS();

const ws = websocket.initServer({
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});

ws.on('message', function incoming(data) {
ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bisq/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bisq/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bisq/statistics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bisq/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bitcoin/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bitcoin/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bitcoin/fees.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bitcoin/mempool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/bitcoin/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
17 changes: 8 additions & 9 deletions examples/nodejs/bitcoin/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
bitcoin: { websocket },
} = mempoolJS();
const { bitcoin: { websocket } } = mempoolJS();

const init = async () => {

const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
});

ws.on('message', function incoming(data) {
ws.on("message", function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
Expand All @@ -24,5 +23,5 @@ const init = async () => {
console.log(res.mempoolBlocks);
}
});
};
}
init();
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/fees.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/mempool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/liquid/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mempoolJS from '../../../src/index';
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
Expand Down
Loading

0 comments on commit e3068c2

Please sign in to comment.