-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (59 loc) · 2.12 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
const ElectrumClient = require("@codewarriorr/electrum-client-js");
//Electrum Ravencoin docs
//https://electrumx-ravencoin.readthedocs.io/en/latest/protocol.html
async function main() {
const client = new ElectrumClient("rvn4lyfe.com", 50002, "ssl");
try {
await client.connect(
"electrum-client-js", // optional client name
"1.9" // optional protocol version
);
const header = await client.blockchain_headers_subscribe();
console.log("Current header:", header);
const features = await client.server_features();
console.log("Features:", features);
//A burn address
const address = "RXissueAssetXXXXXXXXXXXXXXXXXhhZGt";
const balance = await client.blockchain_scripthash_getBalance(
getScriptHashFromRavencoinAddress(address)
);
console.log(
"RVN balance for address",
address,
(balance.confirmed / 100000000).toLocaleString()
);
const assetBalances = await client.request(
"blockchain.scripthash.get_asset_balance",
[getScriptHashFromRavencoinAddress(address)]
);
console.log("Assets balance for", address, assetBalances);
//TODO how to get the script hash?
const RAVENREBELS = await client.request("blockchain.asset.get_meta", [
"RAVENREBELS",
]);
console.log("RAVENREBELS", RAVENREBELS);
await client.close();
} catch (err) {
console.error(err);
}
}
main();
function getScriptHashFromRavencoinAddress(address) {
const bitcoin = require("bitcoinjs-lib");
const coininfo = require("coininfo"); //coininfo gives us meta data about a bunch of crypto currencies, including Ravencoin
const frmt = coininfo.ravencoin.main.toBitcoinJS();
const RAVENCOIN_NETWORK = {
messagePrefix: "\x16Raven Signed Message:\n",
bip32: {
public: frmt.bip32.public,
private: frmt.bip32.private,
},
pubKeyHash: frmt.pubKeyHash,
scriptHash: frmt.scriptHash,
wif: frmt.wif,
};
let script = bitcoin.address.toOutputScript(address, RAVENCOIN_NETWORK);
let hash = bitcoin.crypto.sha256(script);
let reversedHash = Buffer.from(hash.reverse());
return reversedHash.toString("hex");
}