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 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
153 changes: 153 additions & 0 deletions src/commands/neuron_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,91 @@ enum EnableState {
Disabled,
}

#[derive(CandidType, Default)]
pub struct Spawn {
pub new_controller: Option<Principal>,
}

#[derive(CandidType)]
pub struct Split {
pub amount_e8s: u64,
}

#[derive(CandidType)]
pub struct Merge {
pub source_neuron_id: NeuronId,
}

#[derive(CandidType)]
pub struct Follow {
pub topic: i32,
pub followees: Vec<NeuronId>,
}

#[derive(candid::CandidType)]
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),
RegisterVote(RegisterVote),
Disburse(Disburse),
Spawn(Spawn),
Split(Split),
Follow(Follow),
Merge(Merge),
MergeMaturity(MergeMaturity),
MakeProposal(Proposal),
}

#[derive(CandidType)]
struct ManageNeuron {
id: Option<NeuronId>,
command: Option<Command>,
neuron_id_or_subaccount: Option<NeuronIdOrSubaccount>,
}

/// Signs a neuron configuration change.
#[derive(Parser)]
pub struct ManageOpts {
Expand Down Expand Up @@ -124,6 +209,34 @@ pub struct ManageOpts {
/// Set whether new maturity should be automatically staked.
#[clap(long, arg_enum)]
auto_stake_maturity: Option<EnableState>,

/// 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 @@ -304,6 +417,46 @@ 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)
.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"),
description: opts.known_neuron_desc,
}),
}),
_ => 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: id.clone(),
Expand Down
1 change: 1 addition & 0 deletions tests/commands/neuron-manage-make-proposal.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
},
)