Skip to content

Commit

Permalink
Will not get nonce from node if 0 nonce is passsed in
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Apr 1, 2022
1 parent 4bfec40 commit b58f918
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 22 deletions.
42 changes: 36 additions & 6 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9741,7 +9741,12 @@ async function transferTo(toAddress, amount, options = {}) {
throw new errors.InvalidAddressError('invalid recipient address');
}

let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let signatureRedeem = address.publicKeyToSignatureRedeem(this.getPublicKey());
let programHash = address.hexStringToProgramHash(signatureRedeem);
let pld = transaction.newTransferPayload(programHash, address.addressStringToProgramHash(toAddress), amount);
Expand All @@ -9750,35 +9755,60 @@ async function transferTo(toAddress, amount, options = {}) {
}

async function registerName(name, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newRegisterNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function transferName(name, recipient, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newTransferNamePayload(name, this.getPublicKey(), recipient);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function deleteName(name, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newDeleteNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function subscribe(topic, duration, identifier, meta, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newSubscribePayload(this.getPublicKey(), identifier, topic, duration, meta);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function unsubscribe(topic, identifier, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newUnsubscribePayload(this.getPublicKey(), identifier, topic);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
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.2 | Documentation</title>
<title>nkn-sdk 1.2.4 | 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.2</code></div>
<div class='mb1'><code>1.2.4</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
42 changes: 36 additions & 6 deletions lib/common/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ async function transferTo(toAddress, amount, options = {}) {
throw new errors.InvalidAddressError('invalid recipient address');
}

let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let signatureRedeem = address.publicKeyToSignatureRedeem(this.getPublicKey());
let programHash = address.hexStringToProgramHash(signatureRedeem);
let pld = transaction.newTransferPayload(programHash, address.addressStringToProgramHash(toAddress), amount);
Expand All @@ -238,35 +243,60 @@ async function transferTo(toAddress, amount, options = {}) {
}

async function registerName(name, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newRegisterNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function transferName(name, recipient, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newTransferNamePayload(name, this.getPublicKey(), recipient);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function deleteName(name, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newDeleteNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function subscribe(topic, duration, identifier, meta, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newSubscribePayload(this.getPublicKey(), identifier, topic, duration, meta);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

async function unsubscribe(topic, identifier, options = {}) {
let nonce = options.nonce || (await this.getNonce());
let nonce = options.nonce;

if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}

let pld = transaction.newUnsubscribePayload(this.getPublicKey(), identifier, topic);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
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.3",
"version": "1.2.4",
"description": "NKN client and wallet SDK",
"main": "lib/index.js",
"exports": {
Expand Down
30 changes: 24 additions & 6 deletions src/common/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export async function transferTo(toAddress, amount, options = {}) {
if(!address.verifyAddress(toAddress)) {
throw new errors.InvalidAddressError('invalid recipient address')
}
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let signatureRedeem = address.publicKeyToSignatureRedeem(this.getPublicKey());
let programHash = address.hexStringToProgramHash(signatureRedeem);
let pld = transaction.newTransferPayload(
Expand All @@ -156,35 +159,50 @@ export async function transferTo(toAddress, amount, options = {}) {
}

export async function registerName(name, options = {}) {
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let pld = transaction.newRegisterNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

export async function transferName(name, recipient, options = {}) {
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let pld = transaction.newTransferNamePayload(name, this.getPublicKey(), recipient);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

export async function deleteName(name, options = {}) {
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let pld = transaction.newDeleteNamePayload(this.getPublicKey(), name);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

export async function subscribe(topic, duration, identifier, meta, options = {}) {
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let pld = transaction.newSubscribePayload(this.getPublicKey(), identifier, topic, duration, meta);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
}

export async function unsubscribe(topic, identifier, options = {}) {
let nonce = options.nonce || await this.getNonce();
let nonce = options.nonce;
if (nonce === null || nonce === undefined) {
nonce = await this.getNonce();
}
let pld = transaction.newUnsubscribePayload(this.getPublicKey(), identifier, topic);
let txn = await this.createTransaction(pld, nonce, options);
return options.buildOnly ? txn : await this.sendTransaction(txn);
Expand Down

0 comments on commit b58f918

Please sign in to comment.