Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hive-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hive-js
Commits
10d605e1
Commit
10d605e1
authored
5 years ago
by
Jason Salyers
Browse files
Options
Downloads
Patches
Plain Diff
[JES] Add automatic failover capability
parent
36e75cd3
No related branches found
No related tags found
2 merge requests
!2
Fail Over Capability
,
!1
Automatic Fail Over
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
config.json
+4
-4
4 additions, 4 deletions
config.json
package.json
+3
-3
3 additions, 3 deletions
package.json
src/api/index.js
+33
-33
33 additions, 33 deletions
src/api/index.js
src/api/transports/http.js
+0
-1
0 additions, 1 deletion
src/api/transports/http.js
src/config.js
+0
-24
0 additions, 24 deletions
src/config.js
with
40 additions
and
65 deletions
config.json
+
4
−
4
View file @
10d605e1
{
{
"transport"
:
"http"
,
"transport"
:
"http"
,
"websocket"
:
"wss://api.hive.blog:8090"
,
"websocket"
:
"wss://api.hive.blog:8090"
,
"uri"
:
"https://a
nyx.io
"
,
"uri"
:
"https://a
pi.hive.blog
"
,
"url"
:
"https://a
nyx.io
"
,
"url"
:
"https://a
pi.hive.blog
"
,
"dev_uri"
:
"
https://api.steemitdev.com
"
,
"dev_uri"
:
""
,
"stage_uri"
:
"
https://api.steemitstage.com
"
,
"stage_uri"
:
""
,
"address_prefix"
:
"STM"
,
"address_prefix"
:
"STM"
,
"chain_id"
:
"0000000000000000000000000000000000000000000000000000000000000000"
,
"chain_id"
:
"0000000000000000000000000000000000000000000000000000000000000000"
,
"alternative_api_endpoints"
:
[
"https://api.hive.blog"
,
"https://anyx.io"
],
"alternative_api_endpoints"
:
[
"https://api.hive.blog"
,
"https://anyx.io"
],
...
...
This diff is collapsed.
Click to expand it.
package.json
+
3
−
3
View file @
10d605e1
{
{
"name"
:
"hive-js
-dev
"
,
"name"
:
"
@hiveio/
hive-js"
,
"version"
:
"0.0.
9
"
,
"version"
:
"0.0.
2
"
,
"description"
:
"
Steem
.js the JavaScript API for
Steem
blockchain"
,
"description"
:
"
Hive
.js the JavaScript API for
Hive
blockchain"
,
"main"
:
"lib/index.js"
,
"main"
:
"lib/index.js"
,
"scripts"
:
{
"scripts"
:
{
"test"
:
"eslint --quiet src test; mocha -t 40000 --require babel-polyfill --require babel-register"
,
"test"
:
"eslint --quiet src test; mocha -t 40000 --require babel-polyfill --require babel-register"
,
...
...
This diff is collapsed.
Click to expand it.
src/api/index.js
+
33
−
33
View file @
10d605e1
...
@@ -27,8 +27,10 @@ class Steem extends EventEmitter {
...
@@ -27,8 +27,10 @@ class Steem extends EventEmitter {
this
.
_setLogger
(
options
);
this
.
_setLogger
(
options
);
this
.
options
=
options
;
this
.
options
=
options
;
this
.
seqNo
=
0
;
// used for rpc calls
this
.
seqNo
=
0
;
// used for rpc calls
this
.
errorCount
=
0
;
this
.
error_count
=
0
;
this
.
apiIndex
=
0
;
this
.
api_index
=
0
;
this
.
error_threshold
=
3
;
this
.
alternative_api_endpoints
=
[
'
https://api.hive.blog
'
,
'
https://anyx.io
'
];
methods
.
forEach
(
method
=>
{
methods
.
forEach
(
method
=>
{
const
methodName
=
method
.
method_name
||
camelCase
(
method
.
method
);
const
methodName
=
method
.
method_name
||
camelCase
(
method
.
method
);
const
methodParams
=
method
.
params
||
[];
const
methodParams
=
method
.
params
||
[];
...
@@ -184,6 +186,12 @@ class Steem extends EventEmitter {
...
@@ -184,6 +186,12 @@ class Steem extends EventEmitter {
setOptions
(
options
)
{
setOptions
(
options
)
{
Object
.
assign
(
this
.
options
,
options
);
Object
.
assign
(
this
.
options
,
options
);
if
(
options
.
hasOwnProperty
(
'
failover_threshold
'
))
this
.
failover_threshold
=
options
.
failover_threshold
;
if
(
options
.
hasOwnProperty
(
'
alternative_api_endpoints
'
))
this
.
alternative_api_endpoints
=
options
.
alternative_api_endpoints
;
this
.
_setLogger
(
options
);
this
.
_setLogger
(
options
);
this
.
_setTransport
(
options
);
this
.
_setTransport
(
options
);
this
.
transport
.
setOptions
(
options
);
this
.
transport
.
setOptions
(
options
);
...
@@ -191,35 +199,22 @@ class Steem extends EventEmitter {
...
@@ -191,35 +199,22 @@ class Steem extends EventEmitter {
{
{
config
.
set
(
'
address_prefix
'
,
options
.
useTestNet
?
'
TST
'
:
'
STM
'
)
config
.
set
(
'
address_prefix
'
,
options
.
useTestNet
?
'
TST
'
:
'
STM
'
)
}
}
if
(
options
.
hasOwnProperty
(
'
failover_threshold
'
))
{
config
.
set
(
'
failover_threshold
'
,
options
.
failover_threshold
);
}
if
(
options
.
hasOwnProperty
(
'
alternative_api_endpoints
'
))
{
config
.
set
(
'
alternative_api_endpoints
'
,
options
.
alternative_api_endpoints
);
}
if
(
options
.
hasOwnProperty
(
'
url
'
))
if
(
options
.
hasOwnProperty
(
'
url
'
))
{
{
if
(
this
.
options
.
alternative_api_endpoints
===
undefined
||
this
.
options
.
alternative_api_endpoints
===
null
)
let
new_index
=
0
;
{
for
(
var
i
=
0
;
i
<
this
.
alternative_api_endpoints
.
length
;
i
++
)
console
.
log
(
"
no alternative api endpoints found, can't update the index
"
);
}
let
index
=
0
;
for
(
var
i
=
0
;
i
<
this
.
options
.
alternative_api_endpoints
.
length
;
i
++
)
{
{
if
(
this
.
options
.
url
===
this
.
options
.
alternative_api_endpoints
[
i
])
let
temp_endpoint
=
this
.
alternative_api_endpoints
[
i
];
if
(
temp_endpoint
===
options
.
url
)
{
{
index
=
i
;
new_
index
=
i
;
break
;
break
;
}
}
}
}
this
.
api
I
ndex
=
index
;
this
.
api
_i
ndex
=
new_
index
;
console
.
log
(
"
updated apiIndex to be
"
,
this
.
api
I
ndex
)
;
let
new_endpoint
=
this
.
alternative_api_endpoints
[
this
.
api
_i
ndex
]
;
}
}
console
.
log
(
"
done setting options. new options are:
"
,
this
.
options
);
console
.
log
(
"
does failover_threshold still exist?
"
,
this
.
options
.
failover_threshold
===
'
undefined
'
?
"
no
"
:
"
yes
"
);
}
}
setWebSocket
(
url
)
{
setWebSocket
(
url
)
{
...
@@ -382,26 +377,31 @@ class Steem extends EventEmitter {
...
@@ -382,26 +377,31 @@ class Steem extends EventEmitter {
notifyError
(
err
,
ignore
=
false
)
notifyError
(
err
,
ignore
=
false
)
{
{
this
.
errorCount
++
;
if
(
ignore
)
if
(
ignore
)
{
{
return
;
return
;
}
}
if
(
this
.
options
.
failover_threshold
===
'
undefined
'
)
if
(
this
.
failover_threshold
===
undefined
||
this
.
alternative_api_endpoints
===
undefined
)
{
return
;
}
if
(
err
&&
err
.
toString
().
includes
(
"
overseer
"
))
{
{
console
.
log
(
"
no failover options are listed, can't
failover
"
);
//overseer was a steem thing, it doesn't exist in hive so don't count this error towards
failover
return
;
return
;
}
}
if
(
this
.
errorCount
>=
this
.
options
.
failover_threshold
)
this
.
error_count
++
;
if
(
this
.
error_count
>=
this
.
failover_threshold
)
{
{
console
.
log
(
"
failing over
"
)
;
let
current_url
=
this
.
options
.
url
;
this
.
error
C
ount
=
0
;
this
.
error
_c
ount
=
0
;
this
.
api
I
ndex
++
;
this
.
api
_i
ndex
++
;
if
(
this
.
api
I
ndex
>=
this
.
options
.
alternative_api_endpoints
.
length
)
if
(
this
.
api
_i
ndex
>=
this
.
alternative_api_endpoints
.
length
)
{
{
this
.
api
I
ndex
=
0
;
this
.
api
_i
ndex
=
0
;
}
}
let
nextEndpoint
=
this
.
options
.
alternative_api_endpoints
[
this
.
apiIndex
];
let
nextEndpoint
=
this
.
alternative_api_endpoints
[
this
.
api_index
];
console
.
log
(
"
failing over. old endpoint was:
"
,
current_url
,
"
new one is:
"
,
nextEndpoint
);
this
.
setOptions
({
url
:
nextEndpoint
});
this
.
setOptions
({
url
:
nextEndpoint
});
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/api/transports/http.js
+
0
−
1
View file @
10d605e1
...
@@ -45,7 +45,6 @@ export function jsonRpc(uri, {method, id, params, fetchMethod=fetch}) {
...
@@ -45,7 +45,6 @@ export function jsonRpc(uri, {method, id, params, fetchMethod=fetch}) {
throw
new
Error
(
`Invalid response id:
${
rpcRes
.
id
}
`
);
throw
new
Error
(
`Invalid response id:
${
rpcRes
.
id
}
`
);
}
}
if
(
rpcRes
.
error
)
{
if
(
rpcRes
.
error
)
{
console
.
log
(
"
rcpRes error means rpc threw an error. uri, payload are:
"
,
uri
,
payload
);
throw
new
RPCError
(
rpcRes
.
error
);
throw
new
RPCError
(
rpcRes
.
error
);
}
}
return
rpcRes
.
result
return
rpcRes
.
result
...
...
This diff is collapsed.
Click to expand it.
src/config.js
deleted
100644 → 0
+
0
−
24
View file @
36e75cd3
import
each
from
'
lodash/each
'
;
const
defaultConfig
=
require
(
'
../config.json
'
);
class
Config
{
constructor
(
c
)
{
each
(
c
,
(
value
,
key
)
=>
{
this
[
key
]
=
value
;
});
}
get
(
k
)
{
return
this
[
k
];
}
set
(
k
,
v
)
{
this
[
k
]
=
v
;
}
}
module
.
exports
=
new
Config
(
defaultConfig
);
if
(
typeof
module
.
exports
.
Config
!==
'
undefined
'
)
{
throw
new
Error
(
"
default config.json file may not contain a property 'Config'
"
);
}
module
.
exports
.
Config
=
Config
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment