@kava-labs/javascript-sdk
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
{ | ||
"name": "@kava-labs/javascript-sdk", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"description": "Supports interaction with the Kava blockchain via a REST api", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,2 +11,3 @@ const sig = require("@kava-labs/sig"); | ||
nodeInfo: "/node_info", | ||
txs: "/txs", | ||
getParamsPricefeed: "/pricefeed/parameters", | ||
@@ -39,2 +40,3 @@ getParamsAuction: "/auction/parameters", | ||
this.baseURI = server; | ||
this.broadcastMode = "sync"; // default broadcast mode | ||
} | ||
@@ -79,2 +81,17 @@ | ||
/** | ||
* Set broadcast mode | ||
* @param {String} mode transaction broadcast mode | ||
*/ | ||
setBroadcastMode(mode) { | ||
if (!mode) { | ||
throw new Error("broadcast mode cannot be undefined"); | ||
} | ||
if(mode != "async" && mode != "sync" && mode != "block") { | ||
throw new Error("invalid broadcast mode ", mode, " - must be async, sync, or block"); | ||
} | ||
this.broadcastMode = String(mode); | ||
return this; | ||
} | ||
/** | ||
* Set the client's wallet which is used for signature generation | ||
@@ -289,2 +306,15 @@ * @param {String} mnemonic Kava address mnemonic | ||
/** | ||
* Checks a transaction hash for on-chain results | ||
* @param {String} txHash the transaction's hash | ||
* @return {Promise} | ||
*/ | ||
async checkTxHash(txHash) { | ||
const path = api.txs + "/" + txHash; | ||
const res = await tx.getTx(path, this.baseURI); | ||
if (res) { | ||
return res.data | ||
} | ||
} | ||
/*************************************************** | ||
@@ -306,3 +336,3 @@ * POST tx methods | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -328,3 +358,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -349,3 +379,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -369,3 +399,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -389,3 +419,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -409,3 +439,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -429,3 +459,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -449,3 +479,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -488,3 +518,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -507,3 +537,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -524,3 +554,3 @@ | ||
const signedTx = tx.signTx(rawTx, signInfo, this.wallet); | ||
return await tx.broadcastTx(signedTx, this.baseURI); | ||
return await tx.broadcastTx(signedTx, this.baseURI, this.broadcastMode); | ||
} | ||
@@ -527,0 +557,0 @@ } |
@@ -69,9 +69,10 @@ const sig = require("@kava-labs/sig"); | ||
* @param {String} base the request's base url | ||
* @param {String} mode transaction broadcast mode | ||
* @return {Promise} | ||
*/ | ||
async function broadcastTx(tx, base) { | ||
async function broadcastTx(tx, base, mode) { | ||
let txRes; | ||
try { | ||
const url = new URL(api.postTx, base).toString(); | ||
txRes = await axios.post(url, sig.createBroadcastTx(tx.value, "async")); | ||
txRes = await axios.post(url, sig.createBroadcastTx(tx.value, mode)); | ||
} catch (err) { | ||
@@ -78,0 +79,0 @@ logErr(err) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53783
15
1136