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