Skip to content

Commit

Permalink
Merge pull request #18 from Someguy123/testnet
Browse files Browse the repository at this point in the history
Hive Testnet Network Support
  • Loading branch information
Someguy123 committed May 27, 2021
2 parents 8d979ce + 59b2c10 commit ee6ef33
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Hive Feed JS
This is a Hive Price Feed for witnesses on the [HIVE Network](https://hive.io). It's
written in Node.JS and uses Hive's [Hive-JS](https://www.npmjs.com/package/@hiveio/hive-js).

Recommended NodeJS version: v12.19.0
Recommended NodeJS version: v12.19.0.

Installation
========
Expand All @@ -18,7 +18,7 @@ cp config.example.json config.json
nano config.json
```

I recommend using Docker, however you can also use a locally installed copy of Node v8.11.4.
I recommend using Docker, however you can also use a locally installed copy of Node v8.11.4 or higher.

**Starting Via Docker**

Expand Down Expand Up @@ -103,7 +103,7 @@ Configuration

- **interval** (default: `60`) - The number of minutes between publishing the feed

- **network** (default: `hive`) - The network (chain) you're using this for. Options are: `hive`
- **network** (default: `hive`) - The network (chain) you're using this for. For using the hive long term testnet, set to `testnet`. Options are: `hive` `testnet`

- **peg** (default: `false`) - Set to true only if you want to adjust your price feed bias

Expand All @@ -129,6 +129,9 @@ Just set the correct `network`, and those settings will be automatically updated

`alternate_nodes` - Alternate nodes to use if the main provided one is down. Provided as an array of nodes. Default : `["https://api.hive.blog", "https://api.deathwing.me"]`

`chain_id` - Chain id of the chain that you are using. Default: `beeab0de00000000000000000000000000000000000000000000000000000000`

`address_prefix` - Address prefix of the chain that you are using. Default: `STM`

`disable_exchanges` - A list of exchange `code` 's to disable. Exchanges listed here will not be used
directly (i.e. get price for A/B), nor indirectly (i.e. get price for A/D by converting A/C then C/D).
Expand Down
10 changes: 5 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ log(`Loaded configuration:
Username: ${config.name}
Bias: ${config.peg ? config.peg_multi : 'Disabled'}
RPC Node: ${config.node}
Alternate Nodes: ${config.alternate_nodes.join(", ")}`);
Alternate Nodes: ${config.alternate_nodes.join(', ')}`);
console.log('-------------');

global.verbose = false;
Expand All @@ -32,7 +32,7 @@ for (var t_arg of process.argv) {
}
}

hive.api.setOptions({url: config.node});
hive.api.setOptions({url: config.node, address_prefix: config.address_prefix ,chain_id: config.chain_id})

// used for re-trying failed promises
function delay(t) {
Expand Down Expand Up @@ -226,8 +226,8 @@ class HiveAcc {
let signing = result.signing_key;
if (signing_keys.hasOwnProperty(signing)) {
let props = {
"key": signing,
"hbd_exchange_rate": exchangeRate
'key': signing,
'hbd_exchange_rate': exchangeRate
};
let op = hive.utils.buildWitnessUpdateOp(username, props);
hive.broadcast.witnessSetProperties(signing_keys[signing], username, op[1].props, [], async (err, result) => {
Expand Down Expand Up @@ -364,7 +364,7 @@ function startup(){
console.error(`An error occurred attempting to log into ${config.name}...`);
console.error(`Reason: ${e}`, e);
if (config.signing_keys === undefined || !Object.keys(config.signing_keys).length){
console.error("Exiting");
console.error('Exiting');
process.exit(1);
} else {
console.log(`Trying again in ${config.interval} minute(s)`);
Expand Down
2 changes: 2 additions & 0 deletions config.advanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"peg_multi": 1.0,
"node": "https://hivded.privex.io",
"alternate_nodes" : ["https://api.deathwing.me", "https://api.hive.blog"],
"chain_id" : "beeab0de00000000000000000000000000000000000000000000000000000000",
"address_prefix" : "STM",
"ex_symbol": "hive",
"ex_compare": "usd",
"base_symbol": "HBD",
Expand Down
14 changes: 13 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ var settings = {
var defaults = {
hive: {
node: 'https://hived.privex.io/',
alternate_nodes : ["https://api.deathwing.me", "https://api.hive.blog"],
alternate_nodes : ['https://api.deathwing.me', 'https://api.hive.blog'],
ex_symbol: 'hive', ex_compare: 'usd',
base_symbol: 'HBD', quote_symbol: 'HIVE',
chain_id: 'beeab0de00000000000000000000000000000000000000000000000000000000',
address_prefix : 'SMT',
},
testnet : {
node: 'https://testnet.openhive.network/',
alternate_nodes : [],
ex_symbol: 'hive', ex_compare: 'usd',
base_symbol: 'TBD', quote_symbol: 'TESTS',
chain_id : '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e',
address_prefix : 'TST',
}
};

Expand All @@ -31,6 +41,8 @@ var ndef = defaults[config.network];

if(!('node' in config)) { config.node = ndef.node; }
if(!('alternate_nodes' in config)) { config.alternate_nodes = ndef.alternate_nodes; }
if(!('chain_id' in config)) { config.chain_id = ndef.chain_id; }
if(!('address_prefix' in config)) { config.address_prefix = ndef.address_prefix; }
// disable peg by default. 0% peg (bias)
if(!('peg' in config)) { config.peg = false; }
if(!('peg_multi' in config)) { config.peg_multi = 1; }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hivefeed-js",
"version": "4.2.0",
"version": "4.3.0",
"description": "Hive Price Feed in JS with automatic retry for down nodes",
"repository": "https://github.com/someguy123/hivefeed-js",
"main": "app.js",
Expand Down

0 comments on commit ee6ef33

Please sign in to comment.