add version to networking

This commit is contained in:
Matias Alejo Garcia 2014-05-14 21:02:01 -03:00
commit 2e99d9a8ea
12 changed files with 46 additions and 25 deletions

View file

@ -18,7 +18,7 @@ function Wallet(opts) {
//required params
['storage', 'network', 'blockchain',
'requiredCopayers', 'totalCopayers', 'spendUnconfirmed',
'publicKeyRing', 'txProposals', 'privateKey'
'publicKeyRing', 'txProposals', 'privateKey', 'version'
].forEach(function(k) {
if (typeof opts[k] === 'undefined') throw new Error('missing key:' + k);
self[k] = opts[k];
@ -146,6 +146,7 @@ Wallet.prototype._optsToObj = function() {
totalCopayers: this.totalCopayers,
name: this.name,
netKey: this.netKey,
version: this.version,
};
return obj;

View file

@ -13,14 +13,9 @@ var Wallet = require('./Wallet');
/*
* WalletFactory
*
*
* var wallet = WF.read(config,walletId); -> always go to storage
* var wallet = WF.create(config,walletId); -> create wallets, with the given ID (or random is not given)
*
* var wallet = WF.open(config,walletId); -> try to read walletId, if fails, create a new wallet with that id
*/
function WalletFactory(config) {
function WalletFactory(config, version) {
var self = this;
this.storage = new Storage(config.storage);
this.network = new Network(config.network);
@ -29,6 +24,7 @@ function WalletFactory(config) {
this.networkName = config.networkName;
this.verbose = config.verbose;
this.walletDefaults = config.wallet;
this.version = version;
}
WalletFactory.prototype.log = function(){
@ -129,11 +125,28 @@ WalletFactory.prototype.create = function(opts) {
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers;
opts.version = this.version;
var w = new Wallet(opts);
w.store();
return w;
};
WalletFactory.prototype._checkVersion = function(inVersion) {
var thisV = this.version.split('.');
var thisV0 = parseInt(thisV[0]);
var inV = inVersion.split('.');
var inV0 = parseInt(inV[0]);
//We only check for major version differences
if( thisV0 < inV0 ) {
throw new Error('Major difference in software versions' +
'. Received:' + inVersion +
'. Current version:' + this.version +
'. Aborting.');
}
};
WalletFactory.prototype.open = function(walletId, opts) {
opts = opts || {};
opts.id = walletId;
@ -141,6 +154,8 @@ WalletFactory.prototype.open = function(walletId, opts) {
this.storage._setPassphrase(opts.passphrase);
var w = this.read(walletId);
this._checkVersion(w.version);
if (w) {
w.store();