another wallet rewrite.

This commit is contained in:
Christopher Jeffrey 2016-02-10 20:07:21 -08:00
parent 6cc4c866dc
commit 501abbab45
4 changed files with 377 additions and 645 deletions

View File

@ -33,12 +33,12 @@ function Address(options) {
this.options = options;
this.storage = options.storage;
this.label = options.label || '';
this.change = !!options.change;
this.derived = !!options.derived;
this.key = bcoin.keypair(options);
this.index = options.index;
this.path = options.path;
this.change = !!options.change;
this.index = options.index;
this.type = options.type || 'pubkeyhash';
this.keys = [];

View File

@ -342,7 +342,7 @@ TXPool.prototype.getAll = function getAll(address) {
return this._all[key];
}, this).filter(function(tx) {
if (address) {
if (!address.ownOutput(tx) && !address.ownInput(tx))
if (!tx.testInputs(address) && !tx.testOutputs(address))
return false;
}
return true;
@ -354,7 +354,7 @@ TXPool.prototype.getUnspent = function getUnspent(address) {
return this._unspent[key];
}, this).filter(function(item) {
if (address) {
if (!address.ownOutput(item))
if (!tx.testInputs(address) && !tx.testOutputs(address))
return false;
}
return true;
@ -366,7 +366,7 @@ TXPool.prototype.getPending = function getPending(address) {
return this._all[key];
}, this).filter(function(tx) {
if (address) {
if (!address.ownInput(tx) && !address.ownOutput(tx))
if (!tx.testInputs(address) && !tx.testOutputs(address))
return false;
}
return tx.ts === 0;

File diff suppressed because it is too large Load Diff

View File

@ -35,15 +35,15 @@ describe('Wallet', function() {
var w = bcoin.wallet();
var addr = w.getAddress();
assert(addr);
assert(bcoin.wallet.validateAddress(addr));
assert(bcoin.address.validate(addr));
});
it('should validate existing address', function() {
assert(bcoin.wallet.validateAddress('1KQ1wMNwXHUYj1nV2xzsRcKUH8gVFpTFUc'));
assert(bcoin.address.validate('1KQ1wMNwXHUYj1nV2xzsRcKUH8gVFpTFUc'));
});
it('should fail to validate invalid address', function() {
assert(!bcoin.wallet.validateAddress('1KQ1wMNwXHUYj1nv2xzsRcKUH8gVFpTFUc'));
assert(!bcoin.address.validate('1KQ1wMNwXHUYj1nv2xzsRcKUH8gVFpTFUc'));
});
it('should sign/verify TX', function() {
@ -74,21 +74,20 @@ describe('Wallet', function() {
it('should multisign/verify TX', function() {
var w = bcoin.wallet({
derivation: 'bip44',
type: 'multisig',
m: 1,
n: 2
});
// var k2 = w.getPublicKey().concat(1);
var k2 = bcoin.ecdsa.genKeyPair().getPublic(true, 'array');
var k2 = bcoin.hd.priv().deriveAccount44(0).hdpub;
w.addKey(k2);
// assert.equal(w.getKeyAddress(), w.getAddress());
// Input transcation
var src = bcoin.tx({
outputs: [{
value: 5460 * 2,
m: 1,
keys: [ w.getPublicKey(), k2 ]
keys: [ w.getPublicKey(), k2.derive('m/0/0').publicKey ]
}, {
value: 5460 * 2,
address: w.getAddress() + 'x'