Add cancelable handling
This commit is contained in:
parent
2b82121325
commit
11ea9e7c4b
|
@ -189,10 +189,9 @@ fn main() -> Result<(), Box<error::Error>> {
|
||||||
.use_delimiter(true)
|
.use_delimiter(true)
|
||||||
.help("Any third party signatures required to unlock the tokens"),
|
.help("Any third party signatures required to unlock the tokens"),
|
||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("cancellable")
|
Arg::with_name("cancelable")
|
||||||
.long("cancellable")
|
.long("cancelable")
|
||||||
.takes_value(false)
|
.takes_value(false),
|
||||||
.requires("witness"),
|
|
||||||
),
|
),
|
||||||
).subcommand(
|
).subcommand(
|
||||||
SubCommand::with_name("send-signature")
|
SubCommand::with_name("send-signature")
|
||||||
|
|
|
@ -333,6 +333,7 @@ mod test {
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
|
true,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
@ -407,6 +408,7 @@ mod test {
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
dt,
|
dt,
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
|
true,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
@ -471,6 +473,8 @@ mod test {
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
|
from.pubkey(),
|
||||||
|
true,
|
||||||
1,
|
1,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
@ -524,6 +528,7 @@ mod test {
|
||||||
contract,
|
contract,
|
||||||
date,
|
date,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
true,
|
||||||
192,
|
192,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -153,14 +153,19 @@ impl Transaction {
|
||||||
contract: Pubkey,
|
contract: Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
dt_pubkey: Pubkey,
|
dt_pubkey: Pubkey,
|
||||||
|
cancelable: bool,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let from = from_keypair.pubkey();
|
let from = from_keypair.pubkey();
|
||||||
let budget = Budget::Or(
|
let budget = if cancelable {
|
||||||
(Condition::Timestamp(dt, dt_pubkey), Payment { tokens, to }),
|
Budget::Or(
|
||||||
(Condition::Signature(from), Payment { tokens, to: from }),
|
(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 instruction = Instruction::NewContract(Contract { budget, tokens });
|
||||||
let userdata = serialize(&instruction).expect("serialize instruction");
|
let userdata = serialize(&instruction).expect("serialize instruction");
|
||||||
Self::new_with_userdata(
|
Self::new_with_userdata(
|
||||||
|
|
|
@ -374,6 +374,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<error::Error
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.map_err(|_| WalletError::RpcRequestError("Received bad last_id".to_string()))?;
|
.map_err(|_| WalletError::RpcRequestError("Received bad last_id".to_string()))?;
|
||||||
let last_id = Hash::new(&last_id_vec);
|
let last_id = Hash::new(&last_id_vec);
|
||||||
|
let cancelable_bool = cancelable.is_some();
|
||||||
|
|
||||||
if timestamp == None && *witnesses == None {
|
if timestamp == None && *witnesses == None {
|
||||||
let tx = Transaction::new(&config.id, to, tokens, last_id);
|
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 process_id = Keypair::new().pubkey();
|
||||||
let tx = Transaction::budget_new_on_date(
|
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 serialized = serialize(&tx).unwrap();
|
||||||
let params = json!(serialized);
|
let params = json!(serialized);
|
||||||
|
|
Loading…
Reference in New Issue