require coinbaseAddress to build coinbase transaction
This commit is contained in:
parent
fa572237a6
commit
69f51c749b
@ -20,6 +20,7 @@ function DB(options) {
|
|||||||
|
|
||||||
BaseDB.call(this, options);
|
BaseDB.call(this, options);
|
||||||
|
|
||||||
|
this.coinbaseAddress = options.coinbaseAddress;
|
||||||
this.coinbaseAmount = options.coinbaseAmount || 50 * 1e8;
|
this.coinbaseAmount = options.coinbaseAmount || 50 * 1e8;
|
||||||
this.Transaction = Transaction;
|
this.Transaction = Transaction;
|
||||||
|
|
||||||
@ -81,8 +82,8 @@ DB.prototype.buildGenesisData = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.buildCoinbaseTransaction = function(transactions, data) {
|
DB.prototype.buildCoinbaseTransaction = function(transactions, data) {
|
||||||
if(!this.wallet) {
|
if(!this.coinbaseAddress) {
|
||||||
throw new Error('Wallet required to build coinbase');
|
throw new Error('coinbaseAddress required to build coinbase');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!data) {
|
if(!data) {
|
||||||
@ -96,7 +97,7 @@ DB.prototype.buildCoinbaseTransaction = function(transactions, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var coinbaseTx = new this.Transaction();
|
var coinbaseTx = new this.Transaction();
|
||||||
coinbaseTx.to('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T', this.coinbaseAmount + fees);
|
coinbaseTx.to(this.coinbaseAddress, this.coinbaseAmount + fees);
|
||||||
|
|
||||||
var script = bitcore.Script.buildDataOut(data);
|
var script = bitcore.Script.buildDataOut(data);
|
||||||
|
|
||||||
|
|||||||
@ -69,9 +69,7 @@ describe('Bitcoin DB', function() {
|
|||||||
describe('#buildCoinbaseTransaction', function() {
|
describe('#buildCoinbaseTransaction', function() {
|
||||||
it('should correctly build a coinbase transaction with no fees', function() {
|
it('should correctly build a coinbase transaction with no fees', function() {
|
||||||
var db = new DB({path: 'path', store: memdown});
|
var db = new DB({path: 'path', store: memdown});
|
||||||
db.wallet = {
|
db.coinbaseAddress = 'mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L';
|
||||||
getAddress: sinon.stub().returns('mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L')
|
|
||||||
};
|
|
||||||
db.coinbaseAmount = coinbaseAmount;
|
db.coinbaseAmount = coinbaseAmount;
|
||||||
var coinbaseTx = db.buildCoinbaseTransaction();
|
var coinbaseTx = db.buildCoinbaseTransaction();
|
||||||
coinbaseTx.inputs.length.should.equal(1);
|
coinbaseTx.inputs.length.should.equal(1);
|
||||||
@ -88,9 +86,7 @@ describe('Bitcoin DB', function() {
|
|||||||
|
|
||||||
it('should correctly build a coinbase transaction with fees', function() {
|
it('should correctly build a coinbase transaction with fees', function() {
|
||||||
var db = new DB({path: 'path', store: memdown});
|
var db = new DB({path: 'path', store: memdown});
|
||||||
db.wallet = {
|
db.coinbaseAddress = 'mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L';
|
||||||
getAddress: sinon.stub().returns('mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L')
|
|
||||||
};
|
|
||||||
db.coinbaseAmount = coinbaseAmount;
|
db.coinbaseAmount = coinbaseAmount;
|
||||||
var transactions = [
|
var transactions = [
|
||||||
{
|
{
|
||||||
@ -117,18 +113,16 @@ describe('Bitcoin DB', function() {
|
|||||||
output.satoshis.should.equal(coinbaseAmount + 2000);
|
output.satoshis.should.equal(coinbaseAmount + 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if wallet not included', function() {
|
it('should throw an error if coinbaseAddress not included', function() {
|
||||||
var db = new DB({path: 'path', store: memdown});
|
var db = new DB({path: 'path', store: memdown});
|
||||||
(function() {
|
(function() {
|
||||||
db.buildCoinbaseTransaction();
|
db.buildCoinbaseTransaction();
|
||||||
}).should.throw('Wallet required to build coinbase');
|
}).should.throw('coinbaseAddress required to build coinbase');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will build a coinbase database with different data', function() {
|
it('will build a coinbase database with different data', function() {
|
||||||
var db = new DB({path: 'path', store: memdown});
|
var db = new DB({path: 'path', store: memdown});
|
||||||
db.wallet = {
|
db.coinbaseAddress = 'mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L';
|
||||||
getAddress: sinon.stub().returns('mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L')
|
|
||||||
};
|
|
||||||
var tx1 = db.buildCoinbaseTransaction().uncheckedSerialize();
|
var tx1 = db.buildCoinbaseTransaction().uncheckedSerialize();
|
||||||
var tx2 = db.buildCoinbaseTransaction().uncheckedSerialize();
|
var tx2 = db.buildCoinbaseTransaction().uncheckedSerialize();
|
||||||
tx1.should.not.equal(tx2);
|
tx1.should.not.equal(tx2);
|
||||||
@ -136,9 +130,7 @@ describe('Bitcoin DB', function() {
|
|||||||
|
|
||||||
it('can pass in custom data', function() {
|
it('can pass in custom data', function() {
|
||||||
var db = new DB({path: 'path', store: memdown});
|
var db = new DB({path: 'path', store: memdown});
|
||||||
db.wallet = {
|
db.coinbaseAddress = 'mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L';
|
||||||
getAddress: sinon.stub().returns('mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L')
|
|
||||||
};
|
|
||||||
var tx1 = db.buildCoinbaseTransaction(null, new Buffer('abcdef', 'hex'));
|
var tx1 = db.buildCoinbaseTransaction(null, new Buffer('abcdef', 'hex'));
|
||||||
var data = tx1.inputs[0]._script.getData();
|
var data = tx1.inputs[0]._script.getData();
|
||||||
data.should.deep.equal(new Buffer('abcdef', 'hex'));
|
data.should.deep.equal(new Buffer('abcdef', 'hex'));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user