mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #37 from matiu/feature/wallet-integration2
Feature/wallet integration2
This commit is contained in:
commit
b42ab80128
8
copay.js
8
copay.js
|
@ -5,14 +5,14 @@ module.exports.TxProposals = require('./js/models/core/TxProposals');
|
|||
module.exports.PrivateKey = require('./js/models/core/PrivateKey');
|
||||
|
||||
// components
|
||||
var WebRTC = require('./js/models/network/WebRTC');
|
||||
var Plain = require('./js/models/storage/Plain');
|
||||
var Insight = require('./js/models/blockchain/Insight');
|
||||
var WebRTC = module.exports.WebRTC = require('./js/models/network/WebRTC');
|
||||
var Insight = module.exports.Insight = require('./js/models/blockchain/Insight');
|
||||
var StoragePlain = module.exports.StoragePlain = require('./js/models/storage/Plain');
|
||||
|
||||
module.exports.Wallet = require('soop').load('./js/models/core/Wallet',{
|
||||
Network: WebRTC,
|
||||
Storage: Plain,
|
||||
Blockchain: Insight,
|
||||
Storage: StoragePlain,
|
||||
});
|
||||
|
||||
|
||||
|
|
7840
js/copayBundle.js
7840
js/copayBundle.js
File diff suppressed because it is too large
Load Diff
|
@ -5,74 +5,89 @@ var imports = require('soop').imports();
|
|||
var bitcore = require('bitcore');
|
||||
var http = require('http');
|
||||
|
||||
var Storage = imports.Storage || require('FakeStorage');
|
||||
var Network = imports.Network || require('FakeNetwork');
|
||||
var Blockchain = imports.Blockchain || require('FakeBlockchain');
|
||||
var Storage = imports.Storage;
|
||||
var Network = imports.Network;
|
||||
var Blockchain = imports.Blockchain;
|
||||
|
||||
var copay = copay || require('../../../copay');
|
||||
|
||||
|
||||
function Wallet(opts, config) {
|
||||
opts = opts || {};
|
||||
function Wallet(config) {
|
||||
this._startInterface(config);
|
||||
}
|
||||
|
||||
console.log('### CREATING WALLET.'
|
||||
+ (opts.walletId ? ' USING ID: ' +opts.walletId : ' NEW ID') );
|
||||
|
||||
//
|
||||
Wallet.prototype._startInterface = function(config) {
|
||||
this.storage = new Storage(config.storage);
|
||||
this.network = new Network(config.network);
|
||||
this.blockchain = new Blockchain(config.blockchain);
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype._createNew = function(config, opts) {
|
||||
|
||||
console.log('### CREATING NEW WALLET.'
|
||||
+ (opts.walletId ? ' USING ID: ' +opts.walletId : ' NEW ID') );
|
||||
|
||||
this.privateKey = new copay.PrivateKey({networkName: config.networkName});
|
||||
console.log('\t### PrivateKey Initialized');
|
||||
|
||||
|
||||
|
||||
this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({
|
||||
id: opts.walletId,
|
||||
requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers,
|
||||
totalCopayers: opts.totalCopayers || config.wallet.totalCopayers,
|
||||
networkName: config.networkName,
|
||||
});
|
||||
|
||||
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
|
||||
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.id);
|
||||
|
||||
this.txProposals = new copay.TxProposals({
|
||||
this.txProposals = opts.txProposals || new copay.TxProposals({
|
||||
walletId: this.publicKeyRing.id,
|
||||
publicKeyRing: this.publicKeyRing,
|
||||
networkName: config.networkName,
|
||||
});
|
||||
console.log('\t### TxProposals Initialized');
|
||||
}
|
||||
//
|
||||
// var Read = function(walletId) {
|
||||
// this.storage.read(walletId);
|
||||
// $rootScope.w = new copay.PublicKeyRing.fromObj(pkr);
|
||||
// $rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
||||
// $rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
||||
//
|
||||
//
|
||||
};
|
||||
|
||||
// HERE or in Storage?
|
||||
// $rootScope.walletId = walletId;
|
||||
// $rootScope.w = new copay.PublicKeyRing.fromObj(pkr);
|
||||
// $rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
||||
// $rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
||||
|
||||
// // JIC: Add our key
|
||||
// try {
|
||||
// $rootScope.publicKeyRing.addCopayer(
|
||||
// $rootScope.PrivateKey.getBIP32().extendedPublicKeyString()
|
||||
// );
|
||||
// } catch (e) {
|
||||
// console.log('NOT NECCESARY AN ERROR:', e); //TODO
|
||||
// };
|
||||
// ret = true;
|
||||
// }
|
||||
// return ret;
|
||||
// };
|
||||
// };
|
||||
Wallet.prototype._load = function(config, walletId) {
|
||||
this.id = walletId;
|
||||
this.publicKeyRing = new copay.PublicKeyRing.fromObj(
|
||||
this.storage.get(this.id, 'publicKeyRing')
|
||||
);
|
||||
this.txProposals = new copay.TxProposals.fromObj(
|
||||
this.storage.get(this.id, 'txProposals')
|
||||
);
|
||||
this.privateKey = new copay.PrivateKey.fromObj(
|
||||
this.storage.get(this.id, 'privateKey')
|
||||
); //TODO secure
|
||||
|
||||
// JIC: Add our key
|
||||
try {
|
||||
this.publicKeyRing.addCopayer(
|
||||
this.privateKey.getBIP32().extendedPublicKeyString()
|
||||
);
|
||||
} catch (e) {
|
||||
console.log('NOT NECCESARY AN ERROR:', e); //TODO
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// CONSTRUCTORS
|
||||
Wallet.read = function(config, walletId) {
|
||||
var w = new Wallet(config);
|
||||
w.load(walletId);
|
||||
|
||||
return w;
|
||||
};
|
||||
|
||||
Wallet.create = function(config, opts) {
|
||||
var w = new Wallet(config);
|
||||
w._createNew(config, opts);
|
||||
|
||||
return w;
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = require('soop')(Wallet);
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
<script src="../js/copayBundle.js"></script>
|
||||
<script>
|
||||
|
||||
var copay = require('copay');
|
||||
var copay = require('copay');
|
||||
</script>
|
||||
<script src="test.Storage.js"></script>
|
||||
<script src="test.storage-plain.js"></script>
|
||||
<script src="test.Wallet.js"></script>
|
||||
<script src="test.PublicKeyRing.js"></script>
|
||||
<!--
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
if (!process.version) {
|
||||
if (typeof process === 'undefined' || !process.version) {
|
||||
// browser
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var copay = copay || require('../copay');
|
||||
var Plain = copay.Storage;
|
||||
var Plain = copay.StoragePlain;
|
||||
|
||||
describe('Storage model', function() {
|
||||
describe('Storage/Plain model', function() {
|
||||
|
||||
it('should create an instance', function () {
|
||||
var s = new Storage();
|
||||
var s = new Plain();
|
||||
should.exist(s);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ describe('Wallet model', function() {
|
|||
|
||||
it('should create an instance', function () {
|
||||
var opts = {};
|
||||
var w = new Wallet(opts, config);
|
||||
var w = new Wallet(config, opts);
|
||||
should.exist(w);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,6 +42,7 @@ var createBundle = function(opts) {
|
|||
b.require('./copay', {
|
||||
expose: 'copay'
|
||||
});
|
||||
b.require('./js/models/core/Wallet');
|
||||
|
||||
if (!opts.dontminify) {
|
||||
b.transform({
|
||||
|
|
Loading…
Reference in New Issue