Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkWorkingNode() {
- const NODES = [
- "wss://golos.lexa.host/ws",
- "wss://api.golos.blckchnd.com/ws"
- ];
- let node = localStorage.getItem("node") || NODES[0];
- const idx = Math.max(NODES.indexOf(node), 0);
- let checked = 0;
- const find = (idx) => {
- if (idx >= NODES.length) {
- idx = 0;
- }
- if (checked >= NODES.length) {
- alert("no working nodes found");
- return;
- }
- node = NODES[idx];
- console.log("check", idx, node);
- golos.config.set("websocket", node);
- try {
- golos.api.stop();
- } catch(e) {
- }
- let timeout = false;
- let timer = setTimeout(() => {
- console.log("timeout", NODES[idx])
- timeout = true;
- find(idx + 1);
- }, 3000);
- golos.api.getDynamicGlobalPropertiesAsync()
- .then(props => {
- if(!timeout) {
- check = props.head_block_number;
- console.log("found working node", node);
- localStorage.setItem("node", node);
- clearTimeout(timer);
- }
- })
- .catch(e => {
- console.log("connection error", node, e);
- find(idx + 1);
- });
- }
- find(idx);
- }
- checkWorkingNode();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement