1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use crate::*;
use vipers::{assert_keys_eq, invariant, unwrap_int, validate::Validate};
impl<'info> Validate<'info> for CreateSmartWallet<'info> {
fn validate(&self) -> ProgramResult {
Ok(())
}
}
impl<'info> Validate<'info> for Auth<'info> {
fn validate(&self) -> ProgramResult {
invariant!(
self.smart_wallet.to_account_info().is_signer,
"smart_wallet.is_signer"
);
Ok(())
}
}
impl<'info> Validate<'info> for CreateTransaction<'info> {
fn validate(&self) -> ProgramResult {
Ok(())
}
}
impl<'info> Validate<'info> for Approve<'info> {
fn validate(&self) -> ProgramResult {
assert_keys_eq!(
self.smart_wallet,
self.transaction.smart_wallet,
"smart_wallet"
);
require!(
self.smart_wallet.owner_set_seqno == self.transaction.owner_set_seqno,
OwnerSetChanged
);
Ok(())
}
}
impl<'info> Validate<'info> for ExecuteTransaction<'info> {
fn validate(&self) -> ProgramResult {
assert_keys_eq!(
self.smart_wallet,
self.transaction.smart_wallet,
"smart_wallet"
);
require!(
self.smart_wallet.owner_set_seqno == self.transaction.owner_set_seqno,
OwnerSetChanged
);
require!(self.transaction.executed_at == -1, AlreadyExecuted);
let eta = self.transaction.eta;
let clock = Clock::get()?;
let current_ts = clock.unix_timestamp;
msg!("current_ts: {}; eta: {}", current_ts, eta);
require!(current_ts >= eta, TransactionNotReady);
if eta != NO_ETA {
require!(
current_ts <= unwrap_int!(eta.checked_add(self.smart_wallet.grace_period)),
TransactionIsStale
);
}
let sig_count = self.transaction.num_signers();
require!(
(sig_count as u64) >= self.smart_wallet.threshold,
NotEnoughSigners
);
self.smart_wallet.owner_index(self.owner.key())?;
Ok(())
}
}