@multiplechain/bitcoin 0.1.8 → 0.1.9
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/dist/bitcoin-provider.js +1 -1
- package/package.json +1 -1
- package/src/provider.js +72 -28
package/package.json
CHANGED
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 (
|
|
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://
|
|
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,77 @@ class Provider {
|
|
|
76
76
|
listenTransactions(options, callback) {
|
|
77
77
|
let receiver = options.receiver;
|
|
78
78
|
let ws = new WebSocket(this.wsUrl);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
|
|
80
|
+
if (this.testnet) {
|
|
81
|
+
let subscription = {
|
|
82
|
+
unsubscribe: () => {
|
|
83
|
+
ws.close();
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
|
-
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
console.log(data);
|
|
98
|
+
let tx = this.Transaction(data.hash);
|
|
99
|
+
await tx.getData();
|
|
100
|
+
callback(subscription, tx);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
startCallback(data);
|
|
104
|
+
}, 2500);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ws.addEventListener('message', (res) => {
|
|
109
|
+
console.log(res);
|
|
95
110
|
setTimeout(() => {
|
|
96
|
-
startCallback(data);
|
|
97
|
-
},
|
|
111
|
+
startCallback(JSON.parse(res.data));
|
|
112
|
+
}, 6000);
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
let subscription = {
|
|
116
|
+
unsubscribe: () => {
|
|
117
|
+
ws.send(JSON.stringify({
|
|
118
|
+
"op": "addr_unsub",
|
|
119
|
+
"addr": receiver
|
|
120
|
+
}));
|
|
121
|
+
ws.close();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
ws.addEventListener('open', () => {
|
|
126
|
+
ws.send(JSON.stringify({
|
|
127
|
+
"op": "addr_sub",
|
|
128
|
+
"addr": receiver
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
let startCallback = async (data) => {
|
|
133
|
+
try {
|
|
134
|
+
let tx = this.Transaction(data.x.hash);
|
|
135
|
+
await tx.getData();
|
|
136
|
+
callback(subscription, tx);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
startCallback(data);
|
|
140
|
+
}, 2500);
|
|
141
|
+
}
|
|
98
142
|
}
|
|
143
|
+
|
|
144
|
+
ws.addEventListener('message', (res) => {
|
|
145
|
+
setTimeout(() => {
|
|
146
|
+
startCallback(JSON.parse(res.data));
|
|
147
|
+
}, 6000);
|
|
148
|
+
});
|
|
99
149
|
}
|
|
100
|
-
|
|
101
|
-
ws.addEventListener('message', (res) => {
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
startCallback(JSON.parse(res.data));
|
|
104
|
-
}, 6000);
|
|
105
|
-
});
|
|
106
150
|
}
|
|
107
151
|
|
|
108
152
|
/**
|