Add cancelable handling

This commit is contained in:
Tyera Eulberg 2018-09-21 19:51:42 -06:00 committed by Grimes
parent 2b82121325
commit 11ea9e7c4b
4 changed files with 26 additions and 9 deletions

View File

@ -189,10 +189,9 @@ fn main() -> Result<(), Box<error::Error>> {
.use_delimiter(true)
.help("Any third party signatures required to unlock the tokens"),
).arg(
Arg::with_name("cancellable")
.long("cancellable")
.takes_value(false)
.requires("witness"),
Arg::with_name("cancelable")
.long("cancelable")
.takes_value(false),
),
).subcommand(
SubCommand::with_name("send-signature")

View File

@ -333,6 +333,7 @@ mod test {
contract.pubkey(),
dt,
from.pubkey(),
true,
1,
Hash::default(),
);
@ -407,6 +408,7 @@ mod test {
contract.pubkey(),
dt,
from.pubkey(),
true,
1,
Hash::default(),
);
@ -471,6 +473,8 @@ mod test {
to.pubkey(),
contract.pubkey(),
Utc::now(),
from.pubkey(),
true,
1,
Hash::default(),
);
@ -524,6 +528,7 @@ mod test {
contract,
date,
keypair.pubkey(),
true,
192,
Hash::default(),
);

View File

@ -153,14 +153,19 @@ impl Transaction {
contract: Pubkey,
dt: DateTime<Utc>,
dt_pubkey: Pubkey,
cancelable: bool,
tokens: i64,
last_id: Hash,
) -> Self {
let from = from_keypair.pubkey();
let budget = Budget::Or(
(Condition::Timestamp(dt, dt_pubkey), Payment { tokens, to }),
(Condition::Signature(from), Payment { tokens, to: from }),
);
let budget = if cancelable {
Budget::Or(
(Condition::Timestamp(dt, dt_pubkey), Payment { tokens, to }),
(Condition::Signature(from), Payment { tokens, to: from }),
)
} else {
Budget::After(Condition::Timestamp(dt, dt_pubkey), Payment { tokens, to })
};
let instruction = Instruction::NewContract(Contract { budget, tokens });
let userdata = serialize(&instruction).expect("serialize instruction");
Self::new_with_userdata(

View File

@ -374,6 +374,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<error::Error
.into_vec()
.map_err(|_| WalletError::RpcRequestError("Received bad last_id".to_string()))?;
let last_id = Hash::new(&last_id_vec);
let cancelable_bool = cancelable.is_some();
if timestamp == None && *witnesses == None {
let tx = Transaction::new(&config.id, to, tokens, last_id);
@ -400,7 +401,14 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<error::Error
};
let process_id = Keypair::new().pubkey();
let tx = Transaction::budget_new_on_date(
&config.id, to, process_id, dt, dt_pubkey, tokens, last_id,
&config.id,
to,
process_id,
dt,
dt_pubkey,
cancelable_bool,
tokens,
last_id,
);
let serialized = serialize(&tx).unwrap();
let params = json!(serialized);