-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathinsight-connect-test.js
64 lines (51 loc) · 1.13 KB
/
insight-connect-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const connect = require('./src/connect');
const networks = require('./src/bitcoinjs-networks');
const { parseBlockToJSON } = require('./src/block');
const keyPair = require('./src/keyPair');
const {
data,
transaction,
} = require('./src/transaction-builder');
const { toSats } = require('./src/utils');
const c = connect('insight', { server: 'rick' });
const address = new keyPair('test', 'kmd');
const normalizeUTXO = (utxo) => {
for (let i = 0; i < utxo.length; i++) {
utxo[i].value = utxo[i].satoshis;
}
return utxo;
};
async function send() {
let network = JSON.parse(JSON.stringify(networks.kmd));
delete network.kmdInterest;
let utxo = await c.getUTXO(address.pub)
.then((res) => {
return res;
});
utxo = normalizeUTXO(utxo);
console.log(utxo);
const d = data(
network,
toSats(0.0001),
toSats(0.0001),
address.pub,
address.pub,
utxo
);
console.log(d)
const t = transaction(
address.pub,
address.pub,
address.wif,
network,
d.inputs,
d.change,
d.value
);
console.log(t)
c.broadcast(t)
.then((res) => {
console.log(res);
});
};
send();