Add unix_timestap to stake lockups (#7569)

This commit is contained in:
Rob Walker
2019-12-19 14:37:47 -08:00
committed by GitHub
parent 0245847ea8
commit 3f405d8908
12 changed files with 1038 additions and 373 deletions

View File

@@ -287,7 +287,7 @@ pub struct CliConfig {
pub keypair: Keypair,
pub keypair_path: Option<String>,
pub rpc_client: Option<RpcClient>,
pub print_header: bool,
pub verbose: bool,
}
impl CliConfig {
@@ -313,7 +313,7 @@ impl Default for CliConfig {
keypair: Keypair::new(),
keypair_path: Some(Self::default_keypair_path()),
rpc_client: None,
print_header: true,
verbose: false,
}
}
}
@@ -1073,14 +1073,10 @@ fn process_witness(
}
pub fn process_command(config: &CliConfig) -> ProcessResult {
if config.print_header {
if config.verbose {
if let Some(keypair_path) = &config.keypair_path {
println_name_value("Keypair:", keypair_path);
}
if let CliCommand::Address = config.command {
// Get address of this client
return Ok(format!("{}", config.keypair.pubkey()));
}
println_name_value("RPC Endpoint:", &config.json_rpc_url);
}
@@ -1095,6 +1091,8 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
match &config.command {
// Cluster Query Commands
// Get address of this client
CliCommand::Address => Ok(format!("{}", config.keypair.pubkey())),
// Return software version of solana-cli and cluster entrypoint node
CliCommand::Catchup { node_pubkey } => process_catchup(&rpc_client, node_pubkey),
@@ -1383,8 +1381,6 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
// Wallet Commands
// Get address of this client
CliCommand::Address => unreachable!(),
// Request an airdrop from Solana Faucet;
CliCommand::Airdrop {
faucet_host,
@@ -2460,6 +2456,7 @@ mod tests {
withdrawer: None,
lockup: Lockup {
epoch: 0,
unix_timestamp: 0,
custodian,
},
lamports: 1234,

View File

@@ -133,15 +133,13 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<CliConfig, Box<dyn error::
(default.keypair, None)
};
let print_header = !matches.is_present("no_header");
Ok(CliConfig {
command,
json_rpc_url,
keypair,
keypair_path,
rpc_client: None,
print_header,
verbose: matches.is_present("verbose"),
})
}
@@ -186,10 +184,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.help("/path/to/id.json"),
)
.arg(
Arg::with_name("no_header")
.long("no-header")
Arg::with_name("verbose")
.long("verbose")
.short("v")
.global(true)
.help("Disable information header"),
.help("Show extra information header"),
)
.arg(
Arg::with_name(ASK_SEED_PHRASE_ARG.name)

View File

@@ -73,11 +73,18 @@ impl StakeSubCommands for App<'_, '_> {
.help("Identity of the custodian (can withdraw before lockup expires)")
)
.arg(
Arg::with_name("lockup")
.long("lockup")
.value_name("SLOT")
Arg::with_name("lockup_epoch")
.long("lockup-epoch")
.value_name("EPOCH")
.takes_value(true)
.help("The slot height at which this account will be available for withdrawal")
.help("The epoch height at which this account will be available for withdrawal")
)
.arg(
Arg::with_name("lockup_date")
.long("lockup-date")
.value_name("RFC3339 DATE TIME")
.takes_value(true)
.help("The date and time at which this account will be available for withdrawal")
)
.arg(
Arg::with_name("authorized_staker")
@@ -322,7 +329,8 @@ impl StakeSubCommands for App<'_, '_> {
pub fn parse_stake_create_account(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let stake_account = keypair_of(matches, "stake_account").unwrap();
let epoch = value_of(&matches, "lockup").unwrap_or(0);
let epoch = value_of(&matches, "lockup_epoch").unwrap_or(0);
let unix_timestamp = unix_timestamp_of(&matches, "lockup_date").unwrap_or(0);
let custodian = pubkey_of(matches, "custodian").unwrap_or_default();
let staker = pubkey_of(matches, "authorized_staker");
let withdrawer = pubkey_of(matches, "authorized_withdrawer");
@@ -333,7 +341,11 @@ pub fn parse_stake_create_account(matches: &ArgMatches<'_>) -> Result<CliCommand
stake_account: stake_account.into(),
staker,
withdrawer,
lockup: Lockup { custodian, epoch },
lockup: Lockup {
custodian,
epoch,
unix_timestamp,
},
lamports,
},
require_keypair: true,
@@ -906,7 +918,7 @@ mod tests {
&authorized_string,
"--custodian",
&custodian_string,
"--lockup",
"--lockup-epoch",
"43",
"lamports",
]);
@@ -919,6 +931,7 @@ mod tests {
withdrawer: Some(authorized),
lockup: Lockup {
epoch: 43,
unix_timestamp: 0,
custodian,
},
lamports: 50

View File

@@ -88,10 +88,7 @@ fn test_stake_delegation_and_deactivation() {
stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(),
staker: None,
withdrawer: None,
lockup: Lockup {
custodian: Pubkey::default(),
epoch: 0,
},
lockup: Lockup::default(),
lamports: 50_000,
};
process_command(&config_validator).unwrap();
@@ -175,10 +172,7 @@ fn test_stake_delegation_and_deactivation_offline() {
stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(),
staker: None,
withdrawer: None,
lockup: Lockup {
custodian: Pubkey::default(),
epoch: 0,
},
lockup: Lockup::default(),
lamports: 50_000,
};
process_command(&config_validator).unwrap();