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

Feat web demo #6

Closed
wants to merge 2 commits into from
Closed
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
129 changes: 90 additions & 39 deletions bin/gobject-prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,40 @@ import * as Secp256k1 from "@dashincubator/secp256k1";

import Fs from "node:fs/promises";

async function main() {
/**
* @typedef ProposalData
* @prop {"mainnet"|"testnet"} network - The network type, either mainnet or testnet.
* @prop {String} rpcBasicAuth - Basic authentication credentials for RPC (e.g., `api:null`).
* @prop {String} rpcBaseUrl - Base URL for the RPC server, adjusted for the network.
* @prop {String} rpcExplorer - URL for the RPC explorer.
* @prop {Number} startPeriod - The start period for the proposal.
* @prop {Number} numPeriods - Number of periods for which the proposal applies.
* @prop {Number} dashAmount - The amount of Dash for the proposal.
* @prop {String} proposalUrl - URL of the proposal.
* @prop {String} proposalName - Name of the proposal.
* @prop {String} paymentAddr - Payment address for the proposal.
* @prop {String} burnWif - Wallet Import Format (WIF) key used for the burn address.
*/

/**
* @param {ProposalData} opts
*/
async function prepAndSubmit({
network,
rpcBasicAuth,
rpcBaseUrl,
rpcExplorer,
startPeriod,
numPeriods,
dashAmount,
proposalUrl,
proposalName,
paymentAddr,
burnWif,
}) {
/* jshint maxcomplexity: 100 */
/* jshint maxstatements: 1000 */

console.info("");
console.info("USAGE");
console.info(
" dashgov draft-proposal [start period] [num periods] <DASH-per-period> <proposal-url> <name> <payment-addr> <./burn-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 testnet",
);
console.info("");

/** @type {"mainnet"|"testnet"} */
let network = "mainnet";
let rpcBasicAuth = `api:null`;
let rpcBaseUrl = `https://${rpcBasicAuth}@rpc.digitalcash.dev/`;
let rpcExplorer = "https://rpc.digitalcash.dev/";

let isTestnet = takeFlag(process.argv, ["--testnet"]);
if (isTestnet) {
rpcBaseUrl = `https://${rpcBasicAuth}@trpc.digitalcash.dev/`;
rpcExplorer = "https://trpc.digitalcash.dev/";
network = "testnet";
}

let startPeriod = parseInt(process.argv[2] || "1", 10);
let numPeriods = parseInt(process.argv[3] || "1", 10);
let dashAmount = parseInt(process.argv[4] || "1", 10);
let proposalUrl = process.argv[5] || "";
let proposalName = process.argv[6] || "";
let paymentAddr = process.argv[7] || "";
let burnWifPath = process.argv[8] || "";
let burnWif = "";
if (burnWifPath) {
burnWif = await Fs.readFile(burnWifPath, "utf8");
burnWif = burnWif.trim();
}

/**
* @param {String} method
* @param {...any} params
Expand Down Expand Up @@ -428,6 +420,65 @@ async function main() {
}
}

async function main() {
/** @type {"mainnet"|"testnet"} */
let network = "mainnet";
let rpcBasicAuth = `api:null`;
let rpcBaseUrl = `https://${rpcBasicAuth}@rpc.digitalcash.dev/`;
let rpcExplorer = "https://rpc.digitalcash.dev/";

let isTestnet = takeFlag(process.argv, ["--testnet"]);
if (isTestnet) {
rpcBaseUrl = `https://${rpcBasicAuth}@trpc.digitalcash.dev/`;
rpcExplorer = "https://trpc.digitalcash.dev/";
network = "testnet";
}

let wantsHelp = takeFlag(process.argv, ["--help", "help"]);
let mustHelp = process.argv.length !== 5 && process.argv.length !== 9;
if (wantsHelp || mustHelp) {
console.info("");
console.info("USAGE");
console.info(
" dashgov draft-proposal [start period] [num periods] <DASH-per-period> <proposal-url> <name> <payment-addr> <./burn-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 testnet",
);
console.info("");
return;
}

let startPeriod = parseInt(process.argv[2] || "1", 10);
let numPeriods = parseInt(process.argv[3] || "1", 10);
let dashAmount = parseInt(process.argv[4] || "1", 10);
let proposalUrl = process.argv[5] || "";
let proposalName = process.argv[6] || "";
let paymentAddr = process.argv[7] || "";
let burnWifPath = process.argv[8] || "";
let burnWif = "";
if (burnWifPath) {
burnWif = await Fs.readFile(burnWifPath, "utf8");
burnWif = burnWif.trim();
}

await prepAndSubmit({
network,
rpcBasicAuth,
rpcBaseUrl,
rpcExplorer,
startPeriod,
numPeriods,
dashAmount,
proposalUrl,
proposalName,
paymentAddr,
burnWif,
});
}

/**
* Find, remove, and return the first matching flag from the arguments list
* @param {Array<String>} argv
Expand Down
8 changes: 7 additions & 1 deletion dashgov.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
* @prop {Uint53} ms - the time of that block in ms
*/

/**
* @typedef Selection
* @prop {Estimate} start
* @prop {Estimate} end
*/

/**
* @typedef Estimate
* @prop {String} startIso
Expand Down Expand Up @@ -337,7 +343,7 @@ DashGov.selectEstimates = function (estimates, startPeriod, endPeriod) {
}
if (!startEstimate) {
throw new Error(
`${startPeriod} is not valid ('startPeriod' might not be a number)`,
`${startPeriod} is not valid ('startPeriod' may be out of bounds or not a number)`,
);
}

Expand Down
Loading
Loading