add types to data. aliases for utils.
This commit is contained in:
parent
eb6a9fc20d
commit
a91f245e86
@ -111,15 +111,12 @@ TX.prototype._input = function _input(i, index) {
|
|||||||
out: {
|
out: {
|
||||||
tx: (i.out ? i.out.tx : i.tx) || null,
|
tx: (i.out ? i.out.tx : i.tx) || null,
|
||||||
hash: utils.toHex(hash),
|
hash: utils.toHex(hash),
|
||||||
index: i.out ? i.out.index : i.index,
|
index: i.out ? i.out.index : i.index
|
||||||
get rhash() {
|
|
||||||
return utils.revHex(input.out.hash);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
script: i.script ? i.script.slice() : [],
|
script: i.script ? i.script.slice() : [],
|
||||||
seq: i.seq === undefined ? 0xffffffff : i.seq,
|
seq: i.seq === undefined ? 0xffffffff : i.seq,
|
||||||
get data() {
|
get data() {
|
||||||
return TX.getInputData(input);
|
return TX.getInputData(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -441,7 +438,7 @@ TX.prototype.output = function output(options, value) {
|
|||||||
value: new bn(options.value),
|
value: new bn(options.value),
|
||||||
script: options.script ? options.script.slice() : [],
|
script: options.script ? options.script.slice() : [],
|
||||||
get data() {
|
get data() {
|
||||||
return TX.getOutputData(output);
|
return TX.getOutputData(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -908,8 +905,9 @@ TX.getInputData = function getInputData(input) {
|
|||||||
|
|
||||||
if (!input.out) {
|
if (!input.out) {
|
||||||
return {
|
return {
|
||||||
addr: 'Unknown',
|
type: 'unknown',
|
||||||
hash: 'Unknown',
|
addr: '[unknown]',
|
||||||
|
hash: '[unknown]',
|
||||||
value: new bn(0),
|
value: new bn(0),
|
||||||
script: s,
|
script: s,
|
||||||
seq: input.seq,
|
seq: input.seq,
|
||||||
@ -919,8 +917,9 @@ TX.getInputData = function getInputData(input) {
|
|||||||
|
|
||||||
if (+input.out.hash === 0) {
|
if (+input.out.hash === 0) {
|
||||||
return {
|
return {
|
||||||
addr: 'Coinbase',
|
type: 'coinbase',
|
||||||
hash: 'Coinbase',
|
addr: '[coinbase]',
|
||||||
|
hash: '[coinbase]',
|
||||||
value: new bn(0),
|
value: new bn(0),
|
||||||
script: s,
|
script: s,
|
||||||
seq: input.seq,
|
seq: input.seq,
|
||||||
@ -939,6 +938,7 @@ TX.getInputData = function getInputData(input) {
|
|||||||
hash = utils.ripesha(pub);
|
hash = utils.ripesha(pub);
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
addr = bcoin.wallet.hash2addr(hash);
|
||||||
return {
|
return {
|
||||||
|
type: 'pubkeyhash',
|
||||||
sig: sig,
|
sig: sig,
|
||||||
pub: pub,
|
pub: pub,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -958,6 +958,7 @@ TX.getInputData = function getInputData(input) {
|
|||||||
script: redeem,
|
script: redeem,
|
||||||
value: new bn(0)
|
value: new bn(0)
|
||||||
});
|
});
|
||||||
|
data.type = 'scripthash';
|
||||||
data.pub = pub;
|
data.pub = pub;
|
||||||
data.hash = hash;
|
data.hash = hash;
|
||||||
data.addr = addr;
|
data.addr = addr;
|
||||||
@ -979,8 +980,9 @@ TX.getInputData = function getInputData(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addr: 'Unknown',
|
type: 'unknown',
|
||||||
hash: 'Unknown',
|
addr: '[unknown]',
|
||||||
|
hash: '[unknown]',
|
||||||
value: new bn(0),
|
value: new bn(0),
|
||||||
script: s,
|
script: s,
|
||||||
seq: input.seq,
|
seq: input.seq,
|
||||||
@ -1000,6 +1002,7 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
hash = utils.ripesha(pub);
|
hash = utils.ripesha(pub);
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
addr = bcoin.wallet.hash2addr(hash);
|
||||||
return {
|
return {
|
||||||
|
type: 'pubkey',
|
||||||
sig: null,
|
sig: null,
|
||||||
pub: pub,
|
pub: pub,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -1014,6 +1017,7 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
hash = s[2];
|
hash = s[2];
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
addr = bcoin.wallet.hash2addr(hash);
|
||||||
return {
|
return {
|
||||||
|
type: 'pubkeyhash',
|
||||||
sig: null,
|
sig: null,
|
||||||
pub: null,
|
pub: null,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -1029,6 +1033,7 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
hash = utils.ripesha(pubs[0]);
|
hash = utils.ripesha(pubs[0]);
|
||||||
addr = bcoin.wallet.hash2addr(hash);
|
addr = bcoin.wallet.hash2addr(hash);
|
||||||
return {
|
return {
|
||||||
|
type: 'multisig',
|
||||||
sig: null,
|
sig: null,
|
||||||
pub: pubs[0],
|
pub: pubs[0],
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -1056,6 +1061,7 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
hash = utils.toHex(s[1]);
|
hash = utils.toHex(s[1]);
|
||||||
addr = bcoin.wallet.hash2addr(hash, 'scripthash');
|
addr = bcoin.wallet.hash2addr(hash, 'scripthash');
|
||||||
return {
|
return {
|
||||||
|
type: 'scripthash',
|
||||||
sig: null,
|
sig: null,
|
||||||
pub: null,
|
pub: null,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -1075,8 +1081,9 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
if (bcoin.script.isColored(s)) {
|
if (bcoin.script.isColored(s)) {
|
||||||
ret = bcoin.script.colored(s);
|
ret = bcoin.script.colored(s);
|
||||||
return {
|
return {
|
||||||
addr: 'OP_RETURN',
|
type: 'colored',
|
||||||
hash: 'OP_RETURN',
|
addr: '[colored]',
|
||||||
|
hash: '[colored]',
|
||||||
data: ret,
|
data: ret,
|
||||||
text: utils.array2ascii(ret),
|
text: utils.array2ascii(ret),
|
||||||
value: output.value,
|
value: output.value,
|
||||||
@ -1087,8 +1094,9 @@ TX.getOutputData = function getOutputData(output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addr: '[Unknown]',
|
type: 'unknown',
|
||||||
hash: '[Unknown]',
|
addr: '[unknown]',
|
||||||
|
hash: '[unknown]',
|
||||||
value: new bn(0),
|
value: new bn(0),
|
||||||
script: s,
|
script: s,
|
||||||
lock: lock,
|
lock: lock,
|
||||||
|
|||||||
@ -548,6 +548,7 @@ utils.assert.equal = function assertEqual(l, r, msg) {
|
|||||||
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.btc =
|
||||||
utils.toBTC = function toBTC(satoshi, strict) {
|
utils.toBTC = function toBTC(satoshi, strict) {
|
||||||
var m = new bn(10000000).mul(new bn(10));
|
var m = new bn(10000000).mul(new bn(10));
|
||||||
var lo;
|
var lo;
|
||||||
@ -581,6 +582,7 @@ utils.toBTC = function toBTC(satoshi, strict) {
|
|||||||
return satoshi.div(m).toString(10) + lo;
|
return satoshi.div(m).toString(10) + lo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.satoshi =
|
||||||
utils.fromBTC = function fromBTC(btc, strict) {
|
utils.fromBTC = function fromBTC(btc, strict) {
|
||||||
var satoshi, parts, hi, lo;
|
var satoshi, parts, hi, lo;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user