diff --git a/bin/gobject-prepare.js b/bin/gobject-prepare.js index c9db3f7..7e58a65 100755 --- a/bin/gobject-prepare.js +++ b/bin/gobject-prepare.js @@ -20,12 +20,12 @@ async function main() { console.info(""); console.info("USAGE"); console.info( - " dashgov draft-proposal [start period] [num periods] <./collateral-key.wif>", + " dashgov draft-proposal [start period] [num periods] <./collateral-key.wif> [network]", ); console.info(""); console.info("EXAMPLE"); console.info( - " dashgov draft-proposal '1' '3' '100' 'https://example.com/example-proposal' example-proposal yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC ./private-key.wif", + " dashgov draft-proposal '1' '3' '100' 'https://example.com/example-proposal' example-proposal yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC ./private-key.wif testnet", ); console.info(""); @@ -41,6 +41,9 @@ async function main() { collateralWif = await Fs.readFile(collateralWifPath, "utf8"); collateralWif = collateralWif.trim(); } + /** @type {"mainnet"|"testnet"} */ + //@ts-ignore - TODO + let network = process.argv[9] || "mainnet"; let rpcConfig = { protocol: process.env.DASHD_RPC_PROTOCOL || "", @@ -268,7 +271,7 @@ async function main() { * @param {Number} i */ getPrivateKey: async function (txInput, i) { - return DashKeys.wifToPrivKey(collateralWif, { version: "testnet" }); + return DashKeys.wifToPrivKey(collateralWif, { version: network }); }, /** @@ -307,7 +310,7 @@ async function main() { // dash-cli -testnet getaddressutxos '{"addresses":["yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC"]}' let collateralAddr = await DashKeys.wifToAddr(collateralWif, { - version: "testnet", + version: network, }); console.log(""); @@ -317,7 +320,7 @@ async function main() { // we can set txid to short circuit for testing let txid = ""; // ./bin/gobject-prepare.js 1 3 100 https://example.com/proposal-00 proposal-00 yPPy7Z5RQj46SnFtuFXyT6DFAygxESPR7K ./yjZxu7SJAwgSm1JtWybuQRYQDx34z8P2Z7.wif - // txid = ""; + // txid = "10d9862feb6eac6cf6fa653589e39b60a0ed640bae4140c51c35401ffe019479"; if (!txid) { let utxosResult = await rpc.getaddressutxos({ addresses: [collateralAddr], @@ -406,31 +409,32 @@ async function main() { // } async function submit() { - let gobjResult = await rpc - .request("/", { - method: "gobject", - params: [ - "submit", - gobj.hashParent.toString(), // '0' must be a string for some reason - gobj.revision.toString(), - gobj.time.toString(), - gobj.dataHex, - txid, - ], - }) - .catch( - /** @param {Error} err */ function (err) { - const E_INVALID_COLLATERAL = -32603; - // @ts-ignore - code exists - let code = err.code; - if (code === E_INVALID_COLLATERAL) { - // wait for collateral to become valid - console.error(code, err.message); - return null; - } - throw err; - }, - ); + let req = { + method: "gobject", + params: [ + "submit", + gobj.hashParent.toString(), // '0' must be a string for some reason + gobj.revision.toString(), + gobj.time.toString(), + gobj.dataHex, + txid, + ], + }; + let args = req.params.join(" "); + console.log(`${req.method} ${args}`); + let gobjResult = await rpc.request("/", req).catch( + /** @param {Error} err */ function (err) { + const E_INVALID_COLLATERAL = -32603; + // @ts-ignore - code exists + let code = err.code; + if (code === E_INVALID_COLLATERAL) { + // wait for collateral to become valid + console.error(code, err.message); + return null; + } + throw err; + }, + ); return gobjResult; }