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

Ability to submit proposals using only quill #134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 109 additions & 0 deletions src/commands/neuron_manage.rs
Expand Up @@ -115,6 +115,45 @@ pub struct MergeMaturity {
pub percentage_to_merge: u32,
}

#[derive(candid::CandidType)]
pub struct Motion {
pub motion_text: String,
}

#[derive(candid::CandidType)]
pub struct KnownNeuron {
id: Option<NeuronId>,
known_neuron_data: Option<KnownNeuronData>,
}

#[derive(candid::CandidType)]
pub struct KnownNeuronData {
name: String,
description: Option<String>,
}

#[derive(candid::CandidType)]
pub enum Action {
RegisterKnownNeuron(KnownNeuron),
// ManageNeuron(ManageNeuron),
// ExecuteNnsFunction(ExecuteNnsFunction),
// RewardNodeProvider(RewardNodeProvider),
// SetDefaultFollowees(SetDefaultFollowees),
// RewardNodeProviders(RewardNodeProviders),
// ManageNetworkEconomics(NetworkEconomics),
// ApproveGenesisKyc(ApproveGenesisKyc),
// AddOrRemoveNodeProvider(AddOrRemoveNodeProvider),
Motion(Motion),
}

#[derive(candid::CandidType)]
pub struct Proposal {
pub title: Option<String>,
pub summary: String,
pub url: String,
pub action: Option<Action>,
}

#[derive(CandidType)]
pub enum Command {
Configure(Configure),
Expand All @@ -125,6 +164,7 @@ pub enum Command {
Follow(Follow),
Merge(Merge),
MergeMaturity(MergeMaturity),
MakeProposal(Proposal),
}

#[derive(CandidType)]
Expand Down Expand Up @@ -207,6 +247,34 @@ pub struct ManageOpts {
/// Reject proposal(s).
#[clap(long)]
reject: bool,

/// Submit a proposal with this title; must be used with --proposal-summary-file
#[clap(long)]
proposal_title: Option<String>,

/// URL to be associated with a submitted proposal
#[clap(long)]
proposal_url: Option<String>,

/// Submit a proposal, taking its summary from this file and title from --proposal-title
#[clap(long)]
proposal_summary_file: Option<std::path::PathBuf>,

/// The kind of proposal to be submitted: "motion", or "register-known-neuron"
#[clap(long)]
proposal_kind: Option<String>,

/// For a register-known-neuron proposal, the neuron id being proposed
#[clap(long)]
known_neuron_id: Option<String>,

/// For a register-known-neuron proposal, the name being proposed
#[clap(long)]
known_neuron_name: Option<String>,

/// For a register-known-neuron proposal, a brief description of the neuron
#[clap(long)]
known_neuron_desc: Option<String>,
}

pub fn exec(auth: &AuthInfo, opts: ManageOpts) -> AnyhowResult<Vec<IngressWithRequestId>> {
Expand Down Expand Up @@ -383,6 +451,47 @@ pub fn exec(auth: &AuthInfo, opts: ManageOpts) -> AnyhowResult<Vec<IngressWithRe
msgs.push(args);
};

if let Some(summary_file) = opts.proposal_summary_file {
if let Some(title) = opts.proposal_title {
let args = Encode!(&ManageNeuron {
id,
command: Some(Command::MakeProposal(Proposal {
title: Some(title.clone()),
url: opts.proposal_url.unwrap_or_default(),
action: Some(match opts.proposal_kind.as_deref() {
Some("register-known-neuron") => Action::RegisterKnownNeuron(KnownNeuron {
id: opts.known_neuron_id.map(|x| NeuronId {
id: parse_neuron_id(x.to_string())
.expect("Could not parse known neuron id to propose")
}),
known_neuron_data: Some(KnownNeuronData {
name: opts
.known_neuron_name
.expect("Expected a known neuron name to propose")
.to_string(),
description: opts.known_neuron_desc.map(|x| x.to_string()),
}),
}),
_ => Action::Motion(Motion { motion_text: title }),
}),
summary: std::fs::read_to_string(summary_file.clone()).unwrap_or_else(
|_| panic!("Could not read summary file {}", summary_file.display())
),
})),
neuron_id_or_subaccount: None,
})?;
msgs.push(args);
} else {
return Err(anyhow!(
"--proposal-summary-file must be used with --proposal-title"
));
}
} else if opts.proposal_title.is_some() {
return Err(anyhow!(
"--proposal-summary-file must be used with --proposal-title"
));
};

if opts.join_community_fund {
let args = Encode!(&ManageNeuron {
id,
Expand Down
1 change: 1 addition & 0 deletions tests/commands/neuron-manage-make-proposal.sh
@@ -0,0 +1 @@
${CARGO_TARGET_DIR:-../target}/debug/quill neuron-manage 65 --proposal-title "Hello" --proposal-summary-file commands/neuron-manage-make-proposal.sh --pem-file - | ${CARGO_TARGET_DIR:-../target}/debug/quill send --dry-run -
20 changes: 20 additions & 0 deletions tests/outputs/neuron-manage-make-proposal.txt
@@ -0,0 +1,20 @@
Sending message with

Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: manage_neuron
Arguments: (
record {
id = opt record { id = 65 : nat64 };
command = opt variant {
MakeProposal = record {
url = "";
title = opt "Hello";
action = opt variant { Motion = record { motion_text = "Hello" } };
summary = "${CARGO_TARGET_DIR:-../target}/debug/quill neuron-manage 65 --proposal-title \"Hello\" --proposal-summary-file commands/neuron-manage-make-proposal.sh --pem-file - | ${CARGO_TARGET_DIR:-../target}/debug/quill send --dry-run -\n";
}
};
neuron_id_or_subaccount = null;
},
)