Skip to content

Commit

Permalink
Client will only use current node as rpc node if it's persist finished
Browse files Browse the repository at this point in the history
  • Loading branch information
iheron authored and yilunzhang committed Mar 29, 2023
1 parent e058fbe commit fa95a95
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
12 changes: 9 additions & 3 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,17 @@ class Client {

this.ws = ws;
this.node = nodeInfo;
this.wallet.options.rpcServerAddr = '';

if (nodeInfo.rpcAddr) {
this.wallet.options.rpcServerAddr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
} else {
this.wallet.options.rpcServerAddr = '';
let addr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
common.rpc.getNodeState.call(this, {
rpcServerAddr: addr
}).then(nodeState => {
if (nodeState.syncState === 'PERSIST_FINISHED') {
this.wallet.options.rpcServerAddr = addr;
}
});
}

let challengeDone;
Expand Down
2 changes: 1 addition & 1 deletion dist/nkn.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>nkn-sdk 1.2.7 | Documentation</title>
<title>nkn-sdk 1.2.8 | Documentation</title>
<meta name='description' content='NKN client and wallet SDK'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>nkn-sdk</h3>
<div class='mb1'><code>1.2.7</code></div>
<div class='mb1'><code>1.2.8</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
12 changes: 9 additions & 3 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,17 @@ class Client {

this.ws = ws;
this.node = nodeInfo;
this.wallet.options.rpcServerAddr = '';

if (nodeInfo.rpcAddr) {
this.wallet.options.rpcServerAddr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
} else {
this.wallet.options.rpcServerAddr = '';
let addr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
common.rpc.getNodeState.call(this, {
rpcServerAddr: addr
}).then(nodeState => {
if (nodeState.syncState === 'PERSIST_FINISHED') {
this.wallet.options.rpcServerAddr = addr;
}
});
}

let challengeDone;
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": "nkn-sdk",
"version": "1.2.7",
"version": "1.2.8",
"description": "NKN client and wallet SDK",
"main": "lib/index.js",
"exports": {
Expand Down
10 changes: 7 additions & 3 deletions src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,14 @@ export default class Client {

this.ws = ws;
this.node = nodeInfo;
this.wallet.options.rpcServerAddr = '';
if (nodeInfo.rpcAddr) {
this.wallet.options.rpcServerAddr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
} else {
this.wallet.options.rpcServerAddr = '';
let addr = (tls ? 'https' : 'http') + '://' + nodeInfo.rpcAddr;
common.rpc.getNodeState.call(this, {rpcServerAddr:addr}).then(nodeState => {
if (nodeState.syncState === 'PERSIST_FINISHED') {
this.wallet.options.rpcServerAddr = addr;
}
})
}

let challengeDone: Function;
Expand Down

0 comments on commit fa95a95

Please sign in to comment.