mirror of https://github.com/BTCPrivate/copay.git
commit
cf4140ab2b
|
@ -3,7 +3,7 @@
|
||||||
var config = {
|
var config = {
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
network: {
|
network: {
|
||||||
key: 'lwjd5qra8257b9',
|
key: 'lwjd5qra8257b9',
|
||||||
// This is for running local peerJs with params: ./peerjs -p 10009 -k 'sdfjhwefh'
|
// This is for running local peerJs with params: ./peerjs -p 10009 -k 'sdfjhwefh'
|
||||||
// key: 'sdfjhwefh',
|
// key: 'sdfjhwefh',
|
||||||
// host: 'localhost',
|
// host: 'localhost',
|
||||||
|
|
|
@ -7,11 +7,13 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
|
|
||||||
var _updateTxs = function() {
|
var _updateTxs = function() {
|
||||||
var inT = $rootScope.wallet.getTxProposals();
|
var w =$rootScope.wallet;
|
||||||
var ts = [];
|
var inT = w.getTxProposals();
|
||||||
|
var ts = [];
|
||||||
|
|
||||||
inT.forEach(function(i){
|
inT.forEach(function(i){
|
||||||
var b =i.txp.builder;
|
var b = i.txp.builder;
|
||||||
var tx = b.build();
|
var tx = b.build();
|
||||||
var one = {
|
var one = {
|
||||||
valueOutSat: b.valueOutSat,
|
valueOutSat: b.valueOutSat,
|
||||||
feeSat: b.feeSat,
|
feeSat: b.feeSat,
|
||||||
|
@ -21,7 +23,8 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
tx.outs.forEach(function(o) {
|
tx.outs.forEach(function(o) {
|
||||||
var s = o.getScript();
|
var s = o.getScript();
|
||||||
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
|
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
|
||||||
outs.push({address: aStr, value: bitcore.util.valueToBigInt(o.getValue())});
|
if (!w.addressIsOwn(aStr))
|
||||||
|
outs.push({address: aStr, value: bitcore.util.valueToBigInt(o.getValue())});
|
||||||
});
|
});
|
||||||
one.outs = outs;
|
one.outs = outs;
|
||||||
ts.push(one);
|
ts.push(one);
|
||||||
|
@ -42,7 +45,6 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
$scope.sign = function (ntxid) {
|
$scope.sign = function (ntxid) {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
var ret = w.sign(ntxid);
|
var ret = w.sign(ntxid);
|
||||||
console.log('[transactions.js.28:ret:]',ret); //TODO
|
|
||||||
$rootScope.flashMessage = {type:'success', message: 'Transactions SEND! : ' + ret};
|
$rootScope.flashMessage = {type:'success', message: 'Transactions SEND! : ' + ret};
|
||||||
_updateTxs();
|
_updateTxs();
|
||||||
};
|
};
|
||||||
|
|
|
@ -311,6 +311,22 @@ Wallet.prototype.getAddressesStr = function(onlyMain) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Wallet.prototype.addressIsOwn = function(addrStr) {
|
||||||
|
var addrList = this.getAddressesStr();
|
||||||
|
var l = addrList.length;
|
||||||
|
var ret = false;
|
||||||
|
|
||||||
|
for(var i=0; i<l; i++) {
|
||||||
|
if (addrList[i] === addrStr) {
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.getTotalBalance = function(cb) {
|
Wallet.prototype.getTotalBalance = function(cb) {
|
||||||
this.getBalance(this.getAddressesStr(), function(balance) {
|
this.getBalance(this.getAddressesStr(), function(balance) {
|
||||||
return cb(balance);
|
return cb(balance);
|
||||||
|
|
|
@ -44,12 +44,12 @@ WalletFactory.prototype._checkRead = function(walletId) {
|
||||||
s.get(walletId, 'opts') &&
|
s.get(walletId, 'opts') &&
|
||||||
s.get(walletId, 'privateKey')
|
s.get(walletId, 'privateKey')
|
||||||
;
|
;
|
||||||
return ret;
|
return ret?true:false;
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.read = function(walletId) {
|
WalletFactory.prototype.read = function(walletId) {
|
||||||
if (! this._checkRead(walletId))
|
if (! this._checkRead(walletId))
|
||||||
throw Error('Check read failed');
|
return false;
|
||||||
|
|
||||||
var s = this.storage;
|
var s = this.storage;
|
||||||
var opts = s.get(walletId, 'opts');
|
var opts = s.get(walletId, 'opts');
|
||||||
|
@ -175,7 +175,7 @@ WalletFactory.prototype.connectTo = function(peerId, cb) {
|
||||||
self.network.start(function() {
|
self.network.start(function() {
|
||||||
self.network.connectTo(peerId)
|
self.network.connectTo(peerId)
|
||||||
self.network.on('walletId', function(walletId) {
|
self.network.on('walletId', function(walletId) {
|
||||||
console.log('[WalletFactory.js.187]'); //TODO
|
self.log('Opening walletId:' + walletId);
|
||||||
return cb(self.open(walletId));
|
return cb(self.open(walletId));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -133,7 +133,14 @@ describe('Wallet model', function() {
|
||||||
Object.keys(t.txps[0].seenBy).length.should.equal(1);
|
Object.keys(t.txps[0].seenBy).length.should.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#addressIsOwn', function () {
|
||||||
|
var w = createW2();
|
||||||
|
var l = w.getAddressesStr();
|
||||||
|
for (var i=0; i<l.length; i++)
|
||||||
|
w.addressIsOwn(l[i]).should.equal(true);
|
||||||
|
w.addressIsOwn('mmHqhvTVbxgJTnePa7cfweSRjBCy9bQQXJ').should.equal(false);
|
||||||
|
w.addressIsOwn('mgtUfP9sTJ6vPLoBxZLPEccGpcjNVryaCX').should.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('#create. Signing with derivate keys', function () {
|
it('#create. Signing with derivate keys', function () {
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,12 @@ describe('WalletFactory model', function() {
|
||||||
var wf = new WalletFactory(config);
|
var wf = new WalletFactory(config);
|
||||||
should.exist(wf);
|
should.exist(wf);
|
||||||
});
|
});
|
||||||
|
it('#_checkRead should return false', function() {
|
||||||
|
var wf = new WalletFactory(config);
|
||||||
|
wf._checkRead('dummy').should.equal(false);
|
||||||
|
wf.read('dummy').should.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should be able to create wallets', function() {
|
it('should be able to create wallets', function() {
|
||||||
var wf = new WalletFactory(config);
|
var wf = new WalletFactory(config);
|
||||||
var w = wf.create();
|
var w = wf.create();
|
||||||
|
|
Loading…
Reference in New Issue