Merge pull request #334 from clark800/remove-config

Remove config singleton (global state)
This commit is contained in:
Chris Clark
2015-05-01 13:30:36 -07:00
7 changed files with 245 additions and 308 deletions

View File

@@ -1,10 +0,0 @@
// This object serves as a singleton to store config options
var extend = require('extend');
var config = module.exports = {
load: function (newOpts) {
extend(config, newOpts);
return config;
}
};

View File

@@ -33,25 +33,23 @@ exports.convertBase = require('./baseconverter');
exports.sjcl = require('./utils').sjcl;
exports.types = require('./serializedtypes');
exports.config = require('./config');
// camelCase to under_scored API conversion
function attachUnderscored(name) {
var o = exports[name];
var o = exports[name];
Object.keys(o.prototype).forEach(function(key) {
var UPPERCASE = /([A-Z]{1})[a-z]+/g;
Object.keys(o.prototype).forEach(function(key) {
var UPPERCASE = /([A-Z]{1})[a-z]+/g;
if (!UPPERCASE.test(key)) {
return;
}
if (!UPPERCASE.test(key)) {
return;
}
var underscored = key.replace(UPPERCASE, function(c) {
return '_' + c.toLowerCase();
});
var underscored = key.replace(UPPERCASE, function(c) {
return '_' + c.toLowerCase();
});
o.prototype[underscored] = o.prototype[key];
});
o.prototype[underscored] = o.prototype[key];
});
}
['Remote',

View File

@@ -34,7 +34,6 @@ var SerializedObject = require('./serializedobject').SerializedObject;
var RippleError = require('./rippleerror').RippleError;
var utils = require('./utils');
var hashprefixes = require('./hashprefixes');
var config = require('./config');
var log = require('./log').internal.sub('remote');
/**
@@ -238,29 +237,6 @@ Remote.flags = {
}
};
Remote.from_config = function(obj, trace) {
var serverConfig = (typeof obj === 'string') ? config.servers[obj] : obj;
var remote = new Remote(serverConfig, trace);
function initializeAccount(account) {
var accountInfo = config.accounts[account];
if (typeof accountInfo === 'object') {
if (accountInfo.secret) {
// Index by nickname
remote.setSecret(account, accountInfo.secret);
// Index by account ID
remote.setSecret(accountInfo.account, accountInfo.secret);
}
}
}
if (config.accounts) {
Object.keys(config.accounts).forEach(initializeAccount);
}
return remote;
};
/**
* Check that server message is valid
*

View File

@@ -11,7 +11,6 @@ var Seed = require('./seed').Seed;
var SerializedObject = require('./serializedobject').SerializedObject;
var RippleError = require('./rippleerror').RippleError;
var hashprefixes = require('./hashprefixes');
var config = require('./config');
var log = require('./log').internal.sub('transaction');
/**
@@ -433,8 +432,8 @@ Transaction.prototype.serialize = function() {
return SerializedObject.from_json(this.tx_json);
};
Transaction.prototype.signingHash = function() {
return this.hash(config.testnet ? 'HASH_TX_SIGN_TESTNET' : 'HASH_TX_SIGN');
Transaction.prototype.signingHash = function(testnet) {
return this.hash(testnet ? 'HASH_TX_SIGN_TESTNET' : 'HASH_TX_SIGN');
};
Transaction.prototype.hash = function(prefix, asUINT256, serialized) {
@@ -452,13 +451,13 @@ Transaction.prototype.hash = function(prefix, asUINT256, serialized) {
return asUINT256 ? hash : hash.to_hex();
};
Transaction.prototype.sign = function() {
Transaction.prototype.sign = function(testnet) {
var seed = Seed.from_json(this._secret);
var prev_sig = this.tx_json.TxnSignature;
delete this.tx_json.TxnSignature;
var hash = this.signingHash();
var hash = this.signingHash(testnet);
// If the hash is the same, we can re-use the previous signature
if (prev_sig && hash === this.previousSigningHash) {

View File

@@ -4,7 +4,6 @@
var utils = require('./utils');
var sjcl = utils.sjcl;
var config = require('./config');
//
// Abstract UInt class
@@ -131,12 +130,6 @@ UInt.prototype._update = function() {
// value = NaN on error.
UInt.prototype.parse_generic = function(j) {
// Canonicalize and validate
if (config.accounts && (j in config.accounts)) {
j = config.accounts[j].account;
}
switch (j) {
case undefined:
case '0':

View File

@@ -1,7 +1,6 @@
'use strict';
var utils = require('./utils');
var config = require('./config');
var extend = require('extend');
var UInt = require('./uint').UInt;
@@ -40,11 +39,6 @@ UInt160.prototype.get_version = function() {
// value = NaN on error.
UInt160.prototype.parse_json = function(j) {
// Canonicalize and validate
if (config.accounts && (j in config.accounts)) {
j = config.accounts[j].account;
}
if (typeof j === 'number' && !isNaN(j)) {
// Allow raw numbers - DEPRECATED
// This is used mostly by the test suite and is supported

File diff suppressed because it is too large Load Diff