Skip to content
Snippets Groups Projects
Commit 0450d881 authored by Jason Salyers's avatar Jason Salyers
Browse files

[JES] Move some options to the config file

parent 2fe84706
No related branches found
No related tags found
2 merge requests!2Fail Over Capability,!1Automatic Fail Over
{ {
"transport": "http", "transport": "http",
"websocket": "wss://gtg.steem.house:8090", "websocket": "wss://api.hive.blog:8090",
"uri": "https://api.steemit.com", "uri": "https://anyx.io",
"url": "", "url": "https://anyx.io",
"dev_uri": "https://api.steemitdev.com", "dev_uri": "https://api.steemitdev.com",
"stage_uri": "https://api.steemitstage.com", "stage_uri": "https://api.steemitstage.com",
"address_prefix": "STM", "address_prefix": "STM",
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000" "chain_id": "0000000000000000000000000000000000000000000000000000000000000000",
"alternateAPIEndpoints": ["https://api.hive.blog", "https://anyx.io"],
"failoverThreshold": 3
} }
{ {
"name": "@steemit/steem-js", "name": "hive-js-dev",
"version": "0.7.11", "version": "0.0.3",
"description": "Steem.js the JavaScript API for Steem blockchain", "description": "Steem.js the JavaScript API for Steem blockchain",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
...@@ -76,5 +76,11 @@ ...@@ -76,5 +76,11 @@
"James Calfee (https://github.com/jcalfee)", "James Calfee (https://github.com/jcalfee)",
"Nilesh Suthar (https://github.com/nil1511)", "Nilesh Suthar (https://github.com/nil1511)",
"Pedro Tacla Yamada (https://github.com/yamadapc)" "Pedro Tacla Yamada (https://github.com/yamadapc)"
] ],
"directories": {
"doc": "doc",
"example": "examples",
"lib": "lib",
"test": "test"
}
} }
...@@ -20,8 +20,6 @@ import { ...@@ -20,8 +20,6 @@ import {
sign as signRequest sign as signRequest
} from '@steemit/rpc-auth'; } from '@steemit/rpc-auth';
const suggestedApiNodes = ['https://api.hive.blog', 'https://anyx.io'];
class Steem extends EventEmitter { class Steem extends EventEmitter {
constructor(options = {}) { constructor(options = {}) {
super(options); super(options);
...@@ -30,7 +28,6 @@ class Steem extends EventEmitter { ...@@ -30,7 +28,6 @@ class Steem extends EventEmitter {
this.options = options; this.options = options;
this.seqNo = 0; // used for rpc calls this.seqNo = 0; // used for rpc calls
this.errorCount = 0; this.errorCount = 0;
this.errorThreshold = 3;
this.apiIndex = 0; this.apiIndex = 0;
methods.forEach(method => { methods.forEach(method => {
const methodName = method.method_name || camelCase(method.method); const methodName = method.method_name || camelCase(method.method);
...@@ -57,6 +54,9 @@ class Steem extends EventEmitter { ...@@ -57,6 +54,9 @@ class Steem extends EventEmitter {
}); });
this.callAsync = Promise.promisify(this.call); this.callAsync = Promise.promisify(this.call);
this.signedCallAsync = Promise.promisify(this.signedCall); this.signedCallAsync = Promise.promisify(this.signedCall);
console.log("Alternate endpoitns: ", this.options.alternateAPIEndpoints);
console.log("Error Failover Threshold: ", this.options.failoverThreshold);
} }
_setTransport(options) { _setTransport(options) {
...@@ -368,17 +368,17 @@ class Steem extends EventEmitter { ...@@ -368,17 +368,17 @@ class Steem extends EventEmitter {
console.log("but we're being instructed to ignore this error. cherrio good chap, back to it"); console.log("but we're being instructed to ignore this error. cherrio good chap, back to it");
return; return;
} }
if (this.errorCount >= this.errorThreshold) if (this.errorCount >= this.options.failoverThreshold)
{ {
this.errorCount = 0; this.errorCount = 0;
this.apiIndex++; this.apiIndex++;
if (this.apiIndex >= suggestedApiNodes.length) if (this.apiIndex >= this.options.alternateAPIEndpoints.length)
{ {
this.apiIndex = 0; this.apiIndex = 0;
} }
let nextEndpoint = suggestedApiNodes[this.apiIndex]; let nextEndpoint = this.options.alternateAPIEndpoints[this.apiIndex];
this.setOptions({url: nextEndpoint}); this.setOptions({url: nextEndpoint});
console.log("switch to another api endpoint after too many failures. new endpoint is: " + nextEndpoint); console.log("switching to another api endpoint after too many failures. new endpoint is: " + nextEndpoint);
} }
} }
} }
......
import each from 'lodash/each'; import each from 'lodash/each';
const defaultConfig = require('../config.json'); const defaultConfig = require('./config.json');
class Config { class Config {
constructor(c) { constructor(c) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment