action_layer_driver/singleton/
spend_options.rs1use std::time::Duration;
4
5use chia::protocol::{Bytes32, Coin};
6
7#[derive(Clone)]
12pub struct SpendOptions {
13 pub fee: u64,
15
16 pub fee_coin: Option<Coin>,
18
19 pub change_puzzle_hash: Option<Bytes32>,
21
22 pub wait_for_confirmation: bool,
24
25 pub confirmation_timeout: Duration,
27}
28
29impl Default for SpendOptions {
30 fn default() -> Self {
31 Self {
32 fee: 0,
33 fee_coin: None,
34 change_puzzle_hash: None,
35 wait_for_confirmation: false,
36 confirmation_timeout: Duration::from_secs(300),
37 }
38 }
39}
40
41impl SpendOptions {
42 pub fn no_fee() -> Self {
44 Self::default()
45 }
46
47 pub fn with_fee(fee: u64, fee_coin: Coin, change_puzzle_hash: Bytes32) -> Self {
49 Self {
50 fee,
51 fee_coin: Some(fee_coin),
52 change_puzzle_hash: Some(change_puzzle_hash),
53 ..Default::default()
54 }
55 }
56
57 pub fn wait(mut self, wait: bool) -> Self {
59 self.wait_for_confirmation = wait;
60 self
61 }
62
63 pub fn timeout(mut self, timeout: Duration) -> Self {
65 self.confirmation_timeout = timeout;
66 self
67 }
68
69 pub fn has_fee(&self) -> bool {
71 self.fee > 0 && self.fee_coin.is_some()
72 }
73}
74
75#[derive(Debug, Clone)]
77pub struct FeeOptions {
78 pub fee_coin: Coin,
80
81 pub fee_amount: u64,
83
84 pub change_puzzle_hash: Bytes32,
86}
87
88impl FeeOptions {
89 pub fn new(fee_coin: Coin, fee_amount: u64, change_puzzle_hash: Bytes32) -> Self {
91 Self {
92 fee_coin,
93 fee_amount,
94 change_puzzle_hash,
95 }
96 }
97
98 pub fn change_amount(&self) -> u64 {
100 self.fee_coin.amount.saturating_sub(self.fee_amount)
101 }
102}