more input and output data work.

This commit is contained in:
Christopher Jeffrey 2015-12-23 21:55:25 -08:00
parent cf9e11e356
commit 0ccf67aef6

View File

@ -115,7 +115,7 @@ Input.getData = function getData(input) {
var s = input.script; var s = input.script;
var sub = bcoin.script.subscript(input.script); var sub = bcoin.script.subscript(input.script);
var schema, sig, pub, hash, addr, redeem, data, output; var schema, sig, pub, hash, addr, redeem, data, output, val;
schema = { schema = {
type: null, type: null,
@ -160,7 +160,7 @@ Input.getData = function getData(input) {
height: data.height || -1, height: data.height || -1,
addr: input._id('coinbase'), addr: input._id('coinbase'),
flags: data.flags, flags: data.flags,
text: data.text.join(''), text: data.text.join('').replace(/[\r\n\t\v]/g, ''),
none: true none: true
}); });
} }
@ -168,14 +168,26 @@ Input.getData = function getData(input) {
if (input.out.tx) { if (input.out.tx) {
output = input.out.tx.outputs[input.out.index]; output = input.out.tx.outputs[input.out.index];
data = bcoin.output.getData(output); data = bcoin.output.getData(output);
if (data.type === 'pubkey' || data.type === 'pubkeyhash') { if (data.type === 'pubkey' ) {
data.sig = sub[0]; data.sig = sub[0];
} else if (data.type === 'pubkeyhash') {
data.sig = sub[0];
data.pub = sub[1];
} else if (data.type === 'scripthash') {
// We work backwards here: scripthash is one of the few cases
// where we get more data from the input than the output.
val = Input.getData({
out: { hash: input.out.hash, index: input.out.index },
script: input.script,
seq: input.seq
});
val.lock = data.lock;
val.value = data.value;
val.script = data.script;
data = val;
} else if (data.type === 'multisig') { } else if (data.type === 'multisig') {
data.multisig.sigs = sub.slice(1); data.multisig.sigs = sub.slice(1);
data.sig = data.multisig.sigs[0]; data.sig = sub[1];
} else if (data.type === 'scripthash') {
data.multisig.sigs = sub.slice(1, -1);
data.sig = data.multisig.sigs[0];
} }
return utils.merge(data, { return utils.merge(data, {
seq: input.seq, seq: input.seq,