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