refactor fill and sign.
This commit is contained in:
parent
e363ed15cb
commit
9fd6229221
|
@ -317,6 +317,8 @@ function Block(data) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this._isBlock = Block._blockFlag;
|
||||
|
||||
Object.keys(data).forEach(function(key) {
|
||||
if (!self[key]) {
|
||||
self[key] = data[key];
|
||||
|
@ -326,6 +328,12 @@ function Block(data) {
|
|||
this.toHex();
|
||||
}
|
||||
|
||||
Block._blockFlag = {};
|
||||
|
||||
Block.isBlock = function(block) {
|
||||
return block._isBlock === Block._blockFlag;
|
||||
};
|
||||
|
||||
Block.prototype.verify = function() {
|
||||
return this.verified = this.verified || bitcoindjs.verifyBlock(this);
|
||||
};
|
||||
|
@ -418,6 +426,8 @@ function Transaction(data) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this._isTx = Transaction._txFlag;
|
||||
|
||||
this.nMinTxFee = data.nMinTxFee || data.minTxFee || 1000;
|
||||
this.nMinRelayTxFee = data.nMinRelayTxFee || data.minRelayTxFee || 1000;
|
||||
this.CURRENT_VERSION = 1;
|
||||
|
@ -444,25 +454,42 @@ function Transaction(data) {
|
|||
this.toHex();
|
||||
}
|
||||
|
||||
Transaction._txFlag = {};
|
||||
|
||||
Transaction.isTransaction =
|
||||
Transaction.isTx = function(tx) {
|
||||
return tx._isTx === Transaction._txFlag;
|
||||
};
|
||||
|
||||
Transaction.prototype.verify = function() {
|
||||
return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
|
||||
};
|
||||
|
||||
Transaction.prototype.sign =
|
||||
Transaction.prototype.fill = function() {
|
||||
var self = this;
|
||||
var tx = Transaction.fill(this);
|
||||
Object.keys(tx).forEach(function(key) {
|
||||
self[key] = tx[key];
|
||||
});
|
||||
self.toHex();
|
||||
return Transaction.fill(this);
|
||||
};
|
||||
|
||||
Transaction.sign =
|
||||
Transaction.fill = function(tx) {
|
||||
tx = bitcoin.tx(tx);
|
||||
tx = bitcoindjs.fillTransaction(tx);
|
||||
return bitcoin.tx(tx);
|
||||
var isTx = bitcoin.tx.isTx(tx)
|
||||
, newTx;
|
||||
|
||||
if (!isTx) {
|
||||
tx = bitcoin.tx(tx);
|
||||
}
|
||||
|
||||
try {
|
||||
newTx = bitcoindjs.fillTransaction(tx);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object.keys(newTx).forEach(function(key) {
|
||||
tx[key] = newTx[key];
|
||||
});
|
||||
|
||||
return isTx ? true : tx;
|
||||
};
|
||||
|
||||
Transaction.prototype.getSerializeSize = function() {
|
||||
|
|
Loading…
Reference in New Issue