-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactive-federation-utxos.js
More file actions
32 lines (23 loc) · 1.05 KB
/
active-federation-utxos.js
File metadata and controls
32 lines (23 loc) · 1.05 KB
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
const ethUtils = require('ethereumjs-util');
const RLP = ethUtils.rlp;
class Utxo {
constructor(btcTxHash, btcTxOutputIndex, valueInSatoshis) {
this.btcTxHash = btcTxHash;
this.btcTxOutputIndex = btcTxOutputIndex;
this.valueInSatoshis = valueInSatoshis;
}
}
const parseRLPToActiveFederationUtxos = rlp => {
const rlpActiveFederationUtxosList = RLP.decode(rlp);
const activeFederationUtxos = [];
rlpActiveFederationUtxosList.forEach(utxo => {
const valueBuffer = Buffer.from(utxo.toString('hex').substr(0, 15), 'hex');
valueBuffer.reverse();
const valueInSatoshis = parseInt(valueBuffer.toString('hex'), 16);
const btcTxHash = Buffer.from(utxo.toString('hex').substr(70, 64), 'hex').toString('hex');
const btcTxOutputIndex = parseInt(utxo.toString('hex').substr(134, 2), 16);
activeFederationUtxos.push(new Utxo(btcTxHash, btcTxOutputIndex, valueInSatoshis));
});
return activeFederationUtxos;
};
exports.parseRLPToActiveFederationUtxos = parseRLPToActiveFederationUtxos;