Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 2e185aa

Browse files
committed
Proposals now have a 2 week deadline
1 parent eb7b4cb commit 2e185aa

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

feature-proposal/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license = "Apache-2.0"
88
edition = "2018"
99

1010
[dependencies]
11+
chrono = "0.4.19"
1112
clap = "2.33.3"
1213
solana-clap-utils = "1.4.8"
1314
solana-cli-config = "1.4.8"

feature-proposal/cli/src/main.rs

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use {
2+
chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc},
23
clap::{
34
crate_description, crate_name, crate_version, value_t_or_exit, App, AppSettings, Arg,
45
SubCommand,
@@ -9,14 +10,19 @@ use {
910
},
1011
solana_client::rpc_client::RpcClient,
1112
solana_sdk::{
13+
clock::UnixTimestamp,
1214
commitment_config::CommitmentConfig,
1315
program_pack::Pack,
1416
pubkey::Pubkey,
1517
signature::{read_keypair_file, Keypair, Signer},
1618
transaction::Transaction,
1719
},
1820
spl_feature_proposal::state::{AcceptanceCriteria, FeatureProposal},
19-
std::{fs::File, io::Write},
21+
std::{
22+
fs::File,
23+
io::Write,
24+
time::{Duration, SystemTime, UNIX_EPOCH},
25+
},
2026
};
2127

2228
struct Config {
@@ -183,12 +189,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
183189
let distribution_file = value_t_or_exit!(arg_matches, "distribution_file", String);
184190
let percent_stake_required =
185191
value_t_or_exit!(arg_matches, "percent_stake_required", u8);
192+
193+
// Hard code deadline for now...
194+
let fortnight = Duration::from_secs(60 * 60 * 24 * 14);
195+
let deadline = SystemTime::now()
196+
.duration_since(UNIX_EPOCH)
197+
.unwrap()
198+
.checked_add(fortnight)
199+
.unwrap()
200+
.as_secs() as UnixTimestamp;
201+
186202
process_propose(
187203
&rpc_client,
188204
&config,
189205
&feature_proposal_keypair,
190206
distribution_file,
191207
percent_stake_required,
208+
deadline,
192209
arg_matches.is_present("confirm"),
193210
)
194211
}
@@ -229,12 +246,25 @@ fn get_feature_proposal(
229246
}
230247
}
231248

249+
fn unix_timestamp_to_string(unix_timestamp: UnixTimestamp) -> String {
250+
format!(
251+
"{} (UnixTimestamp: {})",
252+
match NaiveDateTime::from_timestamp_opt(unix_timestamp, 0) {
253+
Some(ndt) =>
254+
DateTime::<Utc>::from_utc(ndt, Utc).to_rfc3339_opts(SecondsFormat::Secs, true),
255+
None => "unknown".to_string(),
256+
},
257+
unix_timestamp,
258+
)
259+
}
260+
232261
fn process_propose(
233262
rpc_client: &RpcClient,
234263
config: &Config,
235264
feature_proposal_keypair: &Keypair,
236265
distribution_file: String,
237266
percent_stake_required: u8,
267+
deadline: UnixTimestamp,
238268
confirm: bool,
239269
) -> Result<(), Box<dyn std::error::Error>> {
240270
let distributor_token_address =
@@ -295,7 +325,7 @@ fn process_propose(
295325
tokens_to_mint,
296326
AcceptanceCriteria {
297327
tokens_required,
298-
deadline: None,
328+
deadline,
299329
},
300330
)],
301331
Some(&config.keypair.pubkey()),
@@ -347,6 +377,11 @@ fn process_propose(
347377
println!("Tallying is permissionless and may be run by anybody.");
348378
println!("Once this feature proposal is accepted, the {} feature will be activated at the next epoch.", feature_id_address);
349379

380+
println!();
381+
println!(
382+
"Proposal will expire at {}",
383+
unix_timestamp_to_string(deadline)
384+
);
350385
println!();
351386
if !confirm {
352387
println!("Add --confirm flag to initiate the feature proposal");
@@ -396,19 +431,22 @@ fn process_tally(
396431
"{} tokens have been received",
397432
spl_feature_proposal::amount_to_ui_amount(acceptance_token_balance)
398433
);
434+
println!(
435+
"Proposal will expire at {}",
436+
unix_timestamp_to_string(acceptance_criteria.deadline)
437+
);
399438
println!();
400439

401-
match acceptance_criteria.deadline {
402-
None => {
403-
// Don't bother issuing a transaction if it's clear the Tally won't succeed
404-
if acceptance_token_balance < acceptance_criteria.tokens_required {
405-
println!("Feature proposal pending");
406-
return Ok(());
407-
}
408-
}
409-
Some(deadline) => {
410-
println!("Deadline: {}", deadline); // TODO: format deadline nicely
411-
}
440+
// Don't bother issuing a transaction if it's clear the Tally won't succeed
441+
if acceptance_token_balance < acceptance_criteria.tokens_required
442+
&& (SystemTime::now()
443+
.duration_since(UNIX_EPOCH)
444+
.unwrap()
445+
.as_secs() as UnixTimestamp)
446+
< acceptance_criteria.deadline
447+
{
448+
println!("Feature proposal pending");
449+
return Ok(());
412450
}
413451
}
414452
FeatureProposal::Accepted { .. } => {

0 commit comments

Comments
 (0)