|
| 1 | +#!/usr/bin/env node |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +let DashGov = require("../"); |
| 5 | + |
| 6 | +function help() { |
| 7 | + console.info(""); |
| 8 | + console.info("USAGE"); |
| 9 | + console.info( |
| 10 | + " pre-proposal <start period> <num periods> <DASH-per-period> <proposal-url> <name> <payment-addr>", |
| 11 | + ); |
| 12 | + console.info(""); |
| 13 | + console.info("EXAMPLE"); |
| 14 | + console.info( |
| 15 | + " pre-proposal '1' '3' '100.0' 'https://example.com/example-proposal' example-proposal yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC", |
| 16 | + ); |
| 17 | + console.info(""); |
| 18 | +} |
| 19 | + |
| 20 | +async function main() { |
| 21 | + let startPeriod = parseInt(process.argv[2] || "1", 10); |
| 22 | + let numPeriods = parseInt(process.argv[3] || "1", 10); |
| 23 | + let payment_amount = parseFloat(process.argv[4] || "1"); |
| 24 | + let url = process.argv[5] || ""; |
| 25 | + let name = process.argv[6] || ""; |
| 26 | + let payment_address = process.argv[7] || ""; |
| 27 | + if (!url) { |
| 28 | + help(); |
| 29 | + } |
| 30 | + |
| 31 | + let totalCycleCount = numPeriods - 1; |
| 32 | + let endPeriod = startPeriod + totalCycleCount; |
| 33 | + let cycleCount = Math.max(3, endPeriod); |
| 34 | + |
| 35 | + let estimates = DashGov.estimateProposalCycles( |
| 36 | + cycleCount, |
| 37 | + // snapshot, |
| 38 | + // secondsPerBlock, |
| 39 | + ); |
| 40 | + |
| 41 | + let selected = DashGov.selectEstimates(estimates, startPeriod, endPeriod); |
| 42 | + let gobjData = DashGov.proposal.draftJson(selected, { |
| 43 | + name, |
| 44 | + url, |
| 45 | + payment_address, |
| 46 | + payment_amount, |
| 47 | + }); |
| 48 | + |
| 49 | + let now = Date.now(); |
| 50 | + let gobj = DashGov.proposal.draft(now, selected.start.startMs, gobjData, {}); |
| 51 | + console.log(selected); |
| 52 | + |
| 53 | + let gobjCollateralBytes = DashGov.serializeForCollateralTx(gobj); |
| 54 | + let gobjCollateralHex = DashGov.utils.bytesToHex(gobjCollateralBytes); |
| 55 | + |
| 56 | + let crypto = globalThis.crypto; |
| 57 | + let hash1 = await crypto.subtle.digest("SHA-256", gobjCollateralBytes); |
| 58 | + let gobjCollateralHashBuf = await crypto.subtle.digest("SHA-256", hash1); |
| 59 | + let gobjCollateralHashBytes = new Uint8Array(gobjCollateralHashBuf); |
| 60 | + let gobjCollateralHashHex = DashGov.utils.bytesToHex(gobjCollateralHashBytes); |
| 61 | + |
| 62 | + console.log( |
| 63 | + "gobject prepare", |
| 64 | + gobj.hashParent, |
| 65 | + gobj.revision, |
| 66 | + gobj.time, |
| 67 | + gobj.dataHex, |
| 68 | + ); |
| 69 | + console.log("# blackbox gobject serialization"); |
| 70 | + console.log(`# ${gobjCollateralHex}`); |
| 71 | + console.log(); |
| 72 | + console.log(`# GObject Hash ID (will be found in collateral tx memo)`); |
| 73 | + console.log(`# ${gobjCollateralHashHex}`); |
| 74 | +} |
| 75 | + |
| 76 | +main() |
| 77 | + .then(function () { |
| 78 | + process.exit(0); |
| 79 | + }) |
| 80 | + .catch(function (err) { |
| 81 | + console.error("Fail:"); |
| 82 | + console.error(err.stack || err); |
| 83 | + process.exit(1); |
| 84 | + }); |
0 commit comments