Skip to content

Commit

Permalink
Merge pull request #70 from Bitcoin-com/ct-bulk-raw
Browse files Browse the repository at this point in the history
Updates to RawTransactions: sendRawTransaction and decodeScript
  • Loading branch information
cgcardona authored Feb 21, 2019
2 parents fa91205 + ede9b46 commit 8bb0b84
Show file tree
Hide file tree
Showing 12 changed files with 2,394 additions and 539 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const repl = require("repl")
const BITBOXSDK = require("./lib/bitbox-sdk").default
const clone = require("git-clone")

program.version("3.1.0 ", "-v, --version")
program.version("4.0.0 ", "-v, --version")

program
.command("new <name>")
Expand Down
34 changes: 24 additions & 10 deletions lib/RawTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,27 @@ var RawTransactions = function () {
}, {
key: "decodeScript",
value: async function decodeScript(script) {
if (typeof script !== "string") script = JSON.stringify(script);
//if (typeof script !== "string") script = JSON.stringify(script)

try {
var response = await _axios2.default.get(this.restURL + "rawtransactions/decodeScript/" + script);
return response.data;
if (typeof script === "string") {
var response = await _axios2.default.get(this.restURL + "rawtransactions/decodeScript/" + script);

return response.data;
} else if (Array.isArray(script)) {
var options = {
method: "POST",
url: this.restURL + "rawtransactions/decodeScript",
data: {
hexes: script
}
};
var _response2 = await (0, _axios2.default)(options);

return _response2.data;
}

throw new Error("Input must be a string or array of strings.");
} catch (error) {
if (error.response && error.response.data) throw error.response.data;else throw error;
}
Expand All @@ -81,9 +97,9 @@ var RawTransactions = function () {
verbose: verbose
}
};
var _response2 = await (0, _axios2.default)(options);
var _response3 = await (0, _axios2.default)(options);

return _response2.data;
return _response3.data;
}

throw new Error("Input must be a string or array of strings.");
Expand All @@ -99,9 +115,7 @@ var RawTransactions = function () {
try {
// Single tx hex.
if (typeof hex === "string") {
var response = await _axios2.default.post(this.restURL + "rawtransactions/sendRawTransaction", {
hexes: [hex]
});
var response = await _axios2.default.get(this.restURL + "rawtransactions/sendRawTransaction/" + hex);

if (response.data === "66: insufficient priority") {
console.warn("WARN: Insufficient Priority! This is likely due to a fee that is too low, or insufficient funds.\n Please ensure that there is BCH in the given wallet. If you are running on the testnet, get some\n BCH from the testnet faucet at https://developer.bitcoin.com/faucets/bch");
Expand All @@ -118,9 +132,9 @@ var RawTransactions = function () {
hexes: hex
}
};
var _response3 = await (0, _axios2.default)(options);
var _response4 = await (0, _axios2.default)(options);

return _response3.data;
return _response4.data;
}

throw new Error("Input hex must be a string or array of strings.");
Expand Down
Loading

0 comments on commit 8bb0b84

Please sign in to comment.