@multiplechain/bitcoin 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "namespace": "multiplechain",
3
3
  "name": "@multiplechain/bitcoin",
4
- "version": "0.1.8",
4
+ "version": "0.1.10",
5
5
  "description": "Bitcoin JS provider",
6
6
  "scripts": {
7
7
  "serve": "parcel test.html --no-cache --dist-dir test",
package/src/provider.js CHANGED
@@ -56,14 +56,14 @@ class Provider {
56
56
  this.testnet = options.testnet;
57
57
  this.network = options.testnet ? 'testnet' : 'livenet';
58
58
 
59
- if (!this.testnet) {
60
- this.api = "https://blockstream.info/api/";
61
- this.explorer = "https://blockstream.info/";
62
- this.wsUrl = "wss://mempool.space/api/v1/ws";
63
- } else {
59
+ if (this.testnet) {
64
60
  this.api = "https://blockstream.info/testnet/api/";
65
61
  this.explorer = "https://blockstream.info/testnet/";
66
- this.wsUrl = "wss://mempool.space/testnet/api/v1/ws";
62
+ this.wsUrl = "wss://socket.blockcypher.com/v1/btc/test3?token=6d9cba333f234b9498473955497c40d9";
63
+ } else {
64
+ this.api = "https://blockstream.info/api/";
65
+ this.explorer = "https://blockstream.info/";
66
+ this.wsUrl = "wss://ws.blockchain.info/inv";
67
67
  }
68
68
 
69
69
  this.detectWallets();
@@ -76,33 +76,75 @@ class Provider {
76
76
  listenTransactions(options, callback) {
77
77
  let receiver = options.receiver;
78
78
  let ws = new WebSocket(this.wsUrl);
79
- let subscription = {
80
- unsubscribe: () => {
81
- ws.close();
79
+
80
+ if (this.testnet) {
81
+ let subscription = {
82
+ unsubscribe: () => {
83
+ ws.close();
84
+ }
82
85
  }
83
- }
84
86
 
85
- ws.addEventListener('open', () => {
86
- ws.send(JSON.stringify({ 'track-address': receiver }));
87
- });
88
-
89
- let startCallback = async (data) => {
90
- try {
91
- let tx = this.Transaction(data['address-transactions'][0].txid);
92
- await tx.getData();
93
- callback(subscription, tx);
94
- } catch (error) {
87
+ ws.addEventListener('open', () => {
88
+ ws.send(JSON.stringify({
89
+ event: "unconfirmed-tx",
90
+ address: receiver,
91
+ token: "6d9cba333f234b9498473955497c40d9"
92
+ }));
93
+ });
94
+
95
+ let startCallback = async (data) => {
96
+ try {
97
+ let tx = this.Transaction(data.hash);
98
+ await tx.getData();
99
+ callback(subscription, tx);
100
+ } catch (error) {
101
+ setTimeout(() => {
102
+ startCallback(data);
103
+ }, 2500);
104
+ }
105
+ }
106
+
107
+ ws.addEventListener('message', (res) => {
95
108
  setTimeout(() => {
96
- startCallback(data);
97
- }, 2500);
109
+ startCallback(JSON.parse(res.data));
110
+ }, 6000);
111
+ });
112
+ } else {
113
+ let subscription = {
114
+ unsubscribe: () => {
115
+ ws.send(JSON.stringify({
116
+ "op": "addr_unsub",
117
+ "addr": receiver
118
+ }));
119
+ ws.close();
120
+ }
121
+ }
122
+
123
+ ws.addEventListener('open', () => {
124
+ ws.send(JSON.stringify({
125
+ "op": "addr_sub",
126
+ "addr": receiver
127
+ }));
128
+ });
129
+
130
+ let startCallback = async (data) => {
131
+ try {
132
+ let tx = this.Transaction(data.x.hash);
133
+ await tx.getData();
134
+ callback(subscription, tx);
135
+ } catch (error) {
136
+ setTimeout(() => {
137
+ startCallback(data);
138
+ }, 2500);
139
+ }
98
140
  }
141
+
142
+ ws.addEventListener('message', (res) => {
143
+ setTimeout(() => {
144
+ startCallback(JSON.parse(res.data));
145
+ }, 6000);
146
+ });
99
147
  }
100
-
101
- ws.addEventListener('message', (res) => {
102
- setTimeout(() => {
103
- startCallback(JSON.parse(res.data));
104
- }, 6000);
105
- });
106
148
  }
107
149
 
108
150
  /**