another wallet rewrite.
This commit is contained in:
parent
6cc4c866dc
commit
501abbab45
@ -33,12 +33,12 @@ function Address(options) {
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
this.storage = options.storage;
|
this.storage = options.storage;
|
||||||
this.label = options.label || '';
|
this.label = options.label || '';
|
||||||
this.change = !!options.change;
|
|
||||||
this.derived = !!options.derived;
|
this.derived = !!options.derived;
|
||||||
|
|
||||||
this.key = bcoin.keypair(options);
|
this.key = bcoin.keypair(options);
|
||||||
this.index = options.index;
|
|
||||||
this.path = options.path;
|
this.path = options.path;
|
||||||
|
this.change = !!options.change;
|
||||||
|
this.index = options.index;
|
||||||
|
|
||||||
this.type = options.type || 'pubkeyhash';
|
this.type = options.type || 'pubkeyhash';
|
||||||
this.keys = [];
|
this.keys = [];
|
||||||
|
|||||||
@ -342,7 +342,7 @@ TXPool.prototype.getAll = function getAll(address) {
|
|||||||
return this._all[key];
|
return this._all[key];
|
||||||
}, this).filter(function(tx) {
|
}, this).filter(function(tx) {
|
||||||
if (address) {
|
if (address) {
|
||||||
if (!address.ownOutput(tx) && !address.ownInput(tx))
|
if (!tx.testInputs(address) && !tx.testOutputs(address))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -354,7 +354,7 @@ TXPool.prototype.getUnspent = function getUnspent(address) {
|
|||||||
return this._unspent[key];
|
return this._unspent[key];
|
||||||
}, this).filter(function(item) {
|
}, this).filter(function(item) {
|
||||||
if (address) {
|
if (address) {
|
||||||
if (!address.ownOutput(item))
|
if (!tx.testInputs(address) && !tx.testOutputs(address))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -366,7 +366,7 @@ TXPool.prototype.getPending = function getPending(address) {
|
|||||||
return this._all[key];
|
return this._all[key];
|
||||||
}, this).filter(function(tx) {
|
}, this).filter(function(tx) {
|
||||||
if (address) {
|
if (address) {
|
||||||
if (!address.ownInput(tx) && !address.ownOutput(tx))
|
if (!tx.testInputs(address) && !tx.testOutputs(address))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return tx.ts === 0;
|
return tx.ts === 0;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -35,15 +35,15 @@ describe('Wallet', function() {
|
|||||||
var w = bcoin.wallet();
|
var w = bcoin.wallet();
|
||||||
var addr = w.getAddress();
|
var addr = w.getAddress();
|
||||||
assert(addr);
|
assert(addr);
|
||||||
assert(bcoin.wallet.validateAddress(addr));
|
assert(bcoin.address.validate(addr));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should validate existing address', function() {
|
it('should validate existing address', function() {
|
||||||
assert(bcoin.wallet.validateAddress('1KQ1wMNwXHUYj1nV2xzsRcKUH8gVFpTFUc'));
|
assert(bcoin.address.validate('1KQ1wMNwXHUYj1nV2xzsRcKUH8gVFpTFUc'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to validate invalid address', function() {
|
it('should fail to validate invalid address', function() {
|
||||||
assert(!bcoin.wallet.validateAddress('1KQ1wMNwXHUYj1nv2xzsRcKUH8gVFpTFUc'));
|
assert(!bcoin.address.validate('1KQ1wMNwXHUYj1nv2xzsRcKUH8gVFpTFUc'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should sign/verify TX', function() {
|
it('should sign/verify TX', function() {
|
||||||
@ -74,21 +74,20 @@ describe('Wallet', function() {
|
|||||||
|
|
||||||
it('should multisign/verify TX', function() {
|
it('should multisign/verify TX', function() {
|
||||||
var w = bcoin.wallet({
|
var w = bcoin.wallet({
|
||||||
|
derivation: 'bip44',
|
||||||
type: 'multisig',
|
type: 'multisig',
|
||||||
m: 1,
|
m: 1,
|
||||||
n: 2
|
n: 2
|
||||||
});
|
});
|
||||||
// var k2 = w.getPublicKey().concat(1);
|
var k2 = bcoin.hd.priv().deriveAccount44(0).hdpub;
|
||||||
var k2 = bcoin.ecdsa.genKeyPair().getPublic(true, 'array');
|
|
||||||
w.addKey(k2);
|
w.addKey(k2);
|
||||||
// assert.equal(w.getKeyAddress(), w.getAddress());
|
|
||||||
|
|
||||||
// Input transcation
|
// Input transcation
|
||||||
var src = bcoin.tx({
|
var src = bcoin.tx({
|
||||||
outputs: [{
|
outputs: [{
|
||||||
value: 5460 * 2,
|
value: 5460 * 2,
|
||||||
m: 1,
|
m: 1,
|
||||||
keys: [ w.getPublicKey(), k2 ]
|
keys: [ w.getPublicKey(), k2.derive('m/0/0').publicKey ]
|
||||||
}, {
|
}, {
|
||||||
value: 5460 * 2,
|
value: 5460 * 2,
|
||||||
address: w.getAddress() + 'x'
|
address: w.getAddress() + 'x'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user