Skip to content

Commit

Permalink
decoderawtransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
cloneearth committed Feb 18, 2018
1 parent b4a1a22 commit 61c95d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function createWindow () {
'clearbanned',
'createmultisig',
'createrawtransaction',
'decoderawtransaction',
'decodescript',
'disconnectnode',
'encryptwallet',
Expand Down Expand Up @@ -192,6 +191,44 @@ function createWindow () {
});
});

server.get('/decoderawtransaction', function(req, res) {
res.setHeader('Content-Type', 'application/json');

let t = BitcoinCash.transaction();
let decodedTx = t.fromHex(req.query.rawHex);

let a = BitcoinCash.address();
let s = BitcoinCash.script();
let ins = [];
let ecpair = BitcoinCash.ECPair();
decodedTx.ins.forEach((input, index) => {
let chunksIn = s.decompile(input.script);
let inputPubKey = ecpair.fromPublicKeyBuffer(chunksIn[1]).getAddress();
ins.push({
inputPubKey: inputPubKey,
hex: input.script.toString('hex'),
script: s.toASM(chunksIn)
});
})
decodedTx.ins = ins;

let outs = [];
let value = 0;
decodedTx.outs.forEach((output, index) => {
value += output.value;
let chunksIn = s.decompile(output.script);
let outputPubKey = a.fromOutputScript(output.script);
outs.push({
outputPubKey: outputPubKey,
hex: output.script.toString('hex'),
script: s.toASM(chunksIn)
});
})
decodedTx.outs = outs;

res.send(decodedTx);
});

server.get('/dumpprivkey', function(req, res) {
res.setHeader('Content-Type', 'application/json');
store.get('addresses').forEach(function(address, index) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BITBOX",
"version": "0.0.13",
"version": "0.0.14",
"description": "A development framework for Bitcoin Cash",
"main": "main.js",
"productName": "BITBOX",
Expand Down

0 comments on commit 61c95d0

Please sign in to comment.