Merge pull request #37 from matiu/feature/wallet-integration2

Feature/wallet integration2
This commit is contained in:
Manuel Aráoz 2014-04-14 18:11:19 -03:00
commit b42ab80128
7 changed files with 67 additions and 7890 deletions

View File

@ -5,14 +5,14 @@ module.exports.TxProposals = require('./js/models/core/TxProposals');
module.exports.PrivateKey = require('./js/models/core/PrivateKey'); module.exports.PrivateKey = require('./js/models/core/PrivateKey');
// components // components
var WebRTC = require('./js/models/network/WebRTC'); var WebRTC = module.exports.WebRTC = require('./js/models/network/WebRTC');
var Plain = require('./js/models/storage/Plain'); var Insight = module.exports.Insight = require('./js/models/blockchain/Insight');
var 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',{ module.exports.Wallet = require('soop').load('./js/models/core/Wallet',{
Network: WebRTC, Network: WebRTC,
Storage: Plain,
Blockchain: Insight, Blockchain: Insight,
Storage: StoragePlain,
}); });

File diff suppressed because it is too large Load Diff

View File

@ -5,74 +5,89 @@ var imports = require('soop').imports();
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var http = require('http'); var http = require('http');
var Storage = imports.Storage || require('FakeStorage'); var Storage = imports.Storage;
var Network = imports.Network || require('FakeNetwork'); var Network = imports.Network;
var Blockchain = imports.Blockchain || require('FakeBlockchain'); var Blockchain = imports.Blockchain;
var copay = copay || require('../../../copay'); var copay = copay || require('../../../copay');
function Wallet(opts, config) { function Wallet(config) {
opts = opts || {}; 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.storage = new Storage(config.storage);
this.network = new Network(config.network); this.network = new Network(config.network);
this.blockchain = new Blockchain(config.blockchain); 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}); this.privateKey = new copay.PrivateKey({networkName: config.networkName});
console.log('\t### PrivateKey Initialized'); console.log('\t### PrivateKey Initialized');
this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({ this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({
id: opts.walletId, id: opts.walletId,
requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers, requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers,
totalCopayers: opts.totalCopayers || config.wallet.totalCopayers, totalCopayers: opts.totalCopayers || config.wallet.totalCopayers,
networkName: config.networkName, networkName: config.networkName,
}); });
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString()); this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.id); 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, walletId: this.publicKeyRing.id,
publicKeyRing: this.publicKeyRing, publicKeyRing: this.publicKeyRing,
networkName: config.networkName, networkName: config.networkName,
}); });
console.log('\t### TxProposals Initialized'); 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 Wallet.prototype._load = function(config, walletId) {
// try { this.id = walletId;
// $rootScope.publicKeyRing.addCopayer( this.publicKeyRing = new copay.PublicKeyRing.fromObj(
// $rootScope.PrivateKey.getBIP32().extendedPublicKeyString() this.storage.get(this.id, 'publicKeyRing')
// ); );
// } catch (e) { this.txProposals = new copay.TxProposals.fromObj(
// console.log('NOT NECCESARY AN ERROR:', e); //TODO this.storage.get(this.id, 'txProposals')
// }; );
// ret = true; this.privateKey = new copay.PrivateKey.fromObj(
// } this.storage.get(this.id, 'privateKey')
// return ret; ); //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); module.exports = require('soop')(Wallet);

View File

@ -17,7 +17,7 @@
var copay = require('copay'); var copay = require('copay');
</script> </script>
<script src="test.Storage.js"></script> <script src="test.storage-plain.js"></script>
<script src="test.Wallet.js"></script> <script src="test.Wallet.js"></script>
<script src="test.PublicKeyRing.js"></script> <script src="test.PublicKeyRing.js"></script>
<!-- <!--

View File

@ -1,15 +1,16 @@
'use strict'; 'use strict';
if (!process.version) { if (typeof process === 'undefined' || !process.version) {
// browser
var chai = chai || require('chai'); var chai = chai || require('chai');
var should = chai.should(); var should = chai.should();
var copay = copay || require('../copay'); 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 () { it('should create an instance', function () {
var s = new Storage(); var s = new Plain();
should.exist(s); should.exist(s);
}); });
}); });

View File

@ -18,7 +18,7 @@ describe('Wallet model', function() {
it('should create an instance', function () { it('should create an instance', function () {
var opts = {}; var opts = {};
var w = new Wallet(opts, config); var w = new Wallet(config, opts);
should.exist(w); should.exist(w);
}); });
}); });

View File

@ -42,6 +42,7 @@ var createBundle = function(opts) {
b.require('./copay', { b.require('./copay', {
expose: 'copay' expose: 'copay'
}); });
b.require('./js/models/core/Wallet');
if (!opts.dontminify) { if (!opts.dontminify) {
b.transform({ b.transform({