Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getnodestate rpc and expose rpcCall method #100

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9583,6 +9583,7 @@ Object.defineProperty(exports, "__esModule", {
exports.deleteName = deleteName;
exports.getBalance = getBalance;
exports.getLatestBlock = getLatestBlock;
exports.getNodeState = getNodeState;
exports.getNonce = getNonce;
exports.getRegistrant = getRegistrant;
exports.getSubscribers = getSubscribers;
Expand All @@ -9591,6 +9592,7 @@ exports.getSubscription = getSubscription;
exports.getWsAddr = getWsAddr;
exports.getWssAddr = getWssAddr;
exports.registerName = registerName;
exports.rpcCall = rpcCall;
exports.sendTransaction = sendTransaction;
exports.subscribe = subscribe;
exports.transferName = transferName;
Expand Down Expand Up @@ -9652,6 +9654,9 @@ const methods = {
},
sendRawTransaction: {
method: 'sendrawtransaction'
},
getNodeState: {
method: 'getnodestate'
}
};
var rpc = {};
Expand Down Expand Up @@ -9878,6 +9883,10 @@ async function unsubscribe(topic, identifier, options = {}) {
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function getNodeState(options = {}) {
return rpc.getNodeState(options.rpcServerAddr);
}
},{"../wallet/address":26,"../wallet/transaction":29,"./amount":6,"./errors":8,"./util":19,"axios":56}],18:[function(require,module,exports){
(function (Buffer){
'use strict';
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.5 | Documentation</title>
<title>nkn-sdk 1.2.6 | 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.5</code></div>
<div class='mb1'><code>1.2.6</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
9 changes: 9 additions & 0 deletions lib/common/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.deleteName = deleteName;
exports.getBalance = getBalance;
exports.getLatestBlock = getLatestBlock;
exports.getNodeState = getNodeState;
exports.getNonce = getNonce;
exports.getRegistrant = getRegistrant;
exports.getSubscribers = getSubscribers;
Expand All @@ -14,6 +15,7 @@ exports.getSubscription = getSubscription;
exports.getWsAddr = getWsAddr;
exports.getWssAddr = getWssAddr;
exports.registerName = registerName;
exports.rpcCall = rpcCall;
exports.sendTransaction = sendTransaction;
exports.subscribe = subscribe;
exports.transferName = transferName;
Expand Down Expand Up @@ -75,6 +77,9 @@ const methods = {
},
sendRawTransaction: {
method: 'sendrawtransaction'
},
getNodeState: {
method: 'getnodestate'
}
};
var rpc = {};
Expand Down Expand Up @@ -300,4 +305,8 @@ async function unsubscribe(topic, identifier, options = {}) {
let pld = transaction.newUnsubscribePayload(this.getPublicKey(), identifier, topic);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function getNodeState(options = {}) {
return rpc.getNodeState(options.rpcServerAddr);
}
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.5",
"version": "1.2.6",
"description": "NKN client and wallet SDK",
"main": "lib/index.js",
"exports": {
Expand Down
7 changes: 6 additions & 1 deletion src/common/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const methods = {
getRegistrant: { method: 'getregistrant' },
getLatestBlockHash: { method: 'getlatestblockhash' },
sendRawTransaction: { method: 'sendrawtransaction' },
getNodeState: { method: 'getnodestate' },
}

var rpc = {};
Expand All @@ -33,7 +34,7 @@ for (let method in methods) {
}
}

async function rpcCall(addr, method, params = {}) {
export async function rpcCall(addr, method, params = {}) {
const source = axios.CancelToken.source();
let response = null;

Expand Down Expand Up @@ -207,3 +208,7 @@ export async function unsubscribe(topic, identifier, options = {}) {
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

export async function getNodeState(options = {}) {
return rpc.getNodeState(options.rpcServerAddr);
}