mirror of https://github.com/BTCPrivate/copay.git
merge
This commit is contained in:
commit
3e0c1ad17c
|
@ -79,8 +79,8 @@ var defaultConfig = {
|
|||
}
|
||||
},
|
||||
limits: {
|
||||
totalCopayers: 10,
|
||||
mPlusN: 15
|
||||
totalCopayers: 12,
|
||||
mPlusN: 100
|
||||
},
|
||||
wallet: {
|
||||
requiredCopayers: 2,
|
||||
|
|
|
@ -52,8 +52,7 @@ angular.module('copay.send').controller('SendController',
|
|||
var amount = (form.amount.$modelValue * 100000000).toString(); // satoshi to string
|
||||
|
||||
var w = $rootScope.wallet;
|
||||
w.createTx( address, amount,function() {
|
||||
|
||||
w.createTx(address, amount,function() {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'The transaction proposal has been created', type: 'success'};
|
||||
$rootScope.$digest();
|
||||
|
@ -97,7 +96,7 @@ angular.module('copay.send').controller('SendController',
|
|||
//alert(JSON.stringify(qrcode.process(context)));
|
||||
qrcode.decode();
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
console.log('error decoding QR: '+e);
|
||||
}
|
||||
}, 1500);
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
var imports = require('soop').imports();
|
||||
|
||||
var bitcore = require('bitcore');
|
||||
var bignum = bitcore.Bignum;
|
||||
var coinUtil = bitcore.util;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var Builder = bitcore.TransactionBuilder;
|
||||
|
@ -20,7 +21,8 @@ function Wallet(opts) {
|
|||
'requiredCopayers', 'totalCopayers', 'spendUnconfirmed',
|
||||
'publicKeyRing', 'txProposals', 'privateKey', 'version'
|
||||
].forEach(function(k) {
|
||||
if (typeof opts[k] === 'undefined') throw new Error('missing key:' + k);
|
||||
if (typeof opts[k] === 'undefined')
|
||||
throw new Error('missing required option for Wallet: ' + k);
|
||||
self[k] = opts[k];
|
||||
});
|
||||
|
||||
|
@ -439,9 +441,8 @@ Wallet.prototype.sendTx = function(ntxid, cb) {
|
|||
this.log('[Wallet.js.261:txHex:]', txHex); //TODO
|
||||
|
||||
var self = this;
|
||||
|
||||
this.blockchain.sendRawTransaction(txHex, function(txid) {
|
||||
self.log('BITCOND txid:', txid); //TODO
|
||||
self.log('BITCOIND txid:', txid); //TODO
|
||||
if (txid) {
|
||||
self.txProposals.setSent(ntxid, txid);
|
||||
self.sendTxProposals(null, ntxid);
|
||||
|
@ -572,7 +573,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
|||
self.store();
|
||||
self.emit('txProposalsUpdated');
|
||||
}
|
||||
return cb();
|
||||
return cb(ntxid);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -581,7 +582,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
|||
var priv = this.privateKey;
|
||||
opts = opts || {};
|
||||
|
||||
var amountSat = bitcore.bignum(amountSatStr);
|
||||
var amountSat = bignum(amountSatStr);
|
||||
|
||||
if (!pkr.isComplete()) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
|
|
|
@ -17,6 +17,8 @@ var Wallet = require('./Wallet');
|
|||
|
||||
function WalletFactory(config, version) {
|
||||
var self = this;
|
||||
config = config || {};
|
||||
|
||||
this.storage = new Storage(config.storage);
|
||||
this.network = new Network(config.network);
|
||||
this.blockchain = new Blockchain(config.blockchain);
|
||||
|
@ -97,7 +99,6 @@ WalletFactory.prototype.create = function(opts) {
|
|||
|
||||
opts.privateKey = opts.privateKey || new PrivateKey({ networkName: this.networkName });
|
||||
|
||||
|
||||
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
|
||||
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
|
||||
|
||||
|
@ -124,7 +125,7 @@ WalletFactory.prototype.create = function(opts) {
|
|||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||
opts.requiredCopayers = requiredCopayers;
|
||||
opts.totalCopayers = totalCopayers;
|
||||
opts.version = this.version;
|
||||
opts.version = opts.version || this.version;
|
||||
var w = new Wallet(opts);
|
||||
w.store();
|
||||
return w;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
"bitcore": "git://github.com/bitpay/bitcore.git",
|
||||
"chai": "~1.9.1",
|
||||
"sinon": "~1.9.1",
|
||||
"node-cryptojs-aes": "=0.4.0"
|
||||
"node-cryptojs-aes": "=0.4.0",
|
||||
"async": "~0.9.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var bitcore = require('bitcore');
|
||||
var PublicKeyRing = require('../js/models/core/PublicKeyRing');
|
||||
var PrivateKey = require('../js/models/core/PrivateKey');
|
||||
|
||||
var FakeNetwork = require('./mocks/FakeNetwork');
|
||||
var Insight = require('../js/models/blockchain/Insight');
|
||||
var FakeStorage = require('./mocks/FakeStorage');
|
||||
|
||||
var WalletFactory = require('soop').load('../js/models/core/WalletFactory', {
|
||||
Network: FakeNetwork,
|
||||
Blockchain: Insight,
|
||||
Storage: FakeStorage,
|
||||
});
|
||||
var Key = bitcore.Key;
|
||||
|
||||
|
||||
var N_LIMIT = 20;
|
||||
var nn = 'livenet';
|
||||
|
||||
for (var n = 1; n <= N_LIMIT; n++) {
|
||||
var end = false;
|
||||
for (var m = 1; m <= n; m++) {
|
||||
// case m-of-n
|
||||
console.log('case ' + m + '-of-' + n);
|
||||
// create full pkr
|
||||
var publicKeyRing = new PublicKeyRing({
|
||||
networkName: nn,
|
||||
requiredCopayers: m,
|
||||
totalCopayers: n,
|
||||
});
|
||||
var privateKey = null;
|
||||
var pks = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
var pk = new PrivateKey({
|
||||
networkName: nn
|
||||
});
|
||||
if (i === 0) {
|
||||
privateKey = pk;
|
||||
} else {
|
||||
publicKeyRing.addCopayer(pk.getExtendedPublicKeyString(), 'dummy');
|
||||
}
|
||||
pks.push(pk);
|
||||
}
|
||||
|
||||
var opts = {};
|
||||
opts.publicKeyRing = publicKeyRing;
|
||||
opts.privateKey = privateKey;
|
||||
opts.requiredCopayers = m;
|
||||
opts.totalCopayers = n;
|
||||
opts.spendUnconfirmed = true;
|
||||
opts.version = 'script'
|
||||
|
||||
var w = new WalletFactory(opts).create(opts);
|
||||
var addr = w.generateAddress();
|
||||
console.log('\t receive addr=' + addr);
|
||||
|
||||
|
||||
var toAddress = 'msj42CCGruhRsFrGATiUuh25dtxYtnpbTx';
|
||||
var amount = '5000000';
|
||||
// create fake utxo
|
||||
var utxos = [{
|
||||
'address': addr,
|
||||
'txid': '82a974b72d3135152043989652e687e2966c651ba4822274926221017ea072d2',
|
||||
'vout': 1,
|
||||
'ts': 1400696213,
|
||||
'scriptPubKey': 'a914b2562c950498ff48ad3479ca1c2dfda2b0273e2287',
|
||||
'amount': 10.0,
|
||||
'confirmations': 2
|
||||
}];
|
||||
var ntxid = w.createTxSync(toAddress, amount, utxos);
|
||||
console.log('\t ntxid =' + ntxid);
|
||||
var txp = w.txProposals.txps[ntxid];
|
||||
var tx = txp.builder.build();
|
||||
var scriptSig = tx.ins[0].getScript();
|
||||
var size = scriptSig.serialize().length;
|
||||
console.log('\t scriptSig size: '+size);
|
||||
if (size > 500) {
|
||||
if (m === 1) {
|
||||
end = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end) break;
|
||||
}
|
Loading…
Reference in New Issue