Skip to content

Commit 10262d4

Browse files
chore: allow creation of spending policy when creating profile
1 parent ad439e2 commit 10262d4

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

src/cli/api_client.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,26 @@ impl ApiClient {
6565
Ok(request)
6666
}
6767

68-
pub async fn create_profile(&self, name: String) -> anyhow::Result<()> {
68+
pub async fn create_profile(
69+
&self,
70+
name: String,
71+
addresses: Option<Vec<String>>,
72+
max_payout: Option<u64>,
73+
) -> anyhow::Result<()> {
74+
let policy = proto::SpendingPolicy {
75+
allowed_payout_addresses: addresses.unwrap_or_default(),
76+
max_payout_sats: max_payout,
77+
};
78+
let spending_policy =
79+
if policy.allowed_payout_addresses.is_empty() && policy.max_payout_sats.is_none() {
80+
None
81+
} else {
82+
Some(policy)
83+
};
84+
6985
let request = tonic::Request::new(proto::CreateProfileRequest {
7086
name,
71-
spending_policy: None,
87+
spending_policy,
7288
});
7389
let response = self
7490
.connect()
@@ -84,23 +100,16 @@ impl ApiClient {
84100
addresses: Option<Vec<String>>,
85101
max_payout: Option<u64>,
86102
) -> anyhow::Result<()> {
87-
let spending_policy = match (addresses, max_payout) {
88-
(Some(allowed_payout_addresses), Some(max_payout_sats)) => {
89-
Some(proto::SpendingPolicy {
90-
allowed_payout_addresses,
91-
max_payout_sats: Some(max_payout_sats),
92-
})
93-
}
94-
(Some(allowed_payout_addresses), None) => Some(proto::SpendingPolicy {
95-
allowed_payout_addresses,
96-
max_payout_sats: None,
97-
}),
98-
(None, Some(max_payout_sats)) => Some(proto::SpendingPolicy {
99-
allowed_payout_addresses: Vec::new(),
100-
max_payout_sats: Some(max_payout_sats),
101-
}),
102-
(None, None) => None,
103+
let policy = proto::SpendingPolicy {
104+
allowed_payout_addresses: addresses.unwrap_or_default(),
105+
max_payout_sats: max_payout,
103106
};
107+
let spending_policy =
108+
if policy.allowed_payout_addresses.is_empty() && policy.max_payout_sats.is_none() {
109+
None
110+
} else {
111+
Some(policy)
112+
};
104113

105114
let request = tonic::Request::new(proto::UpdateProfileRequest {
106115
id,

src/cli/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ enum Command {
8484
api_key: String,
8585
#[clap(short, long)]
8686
name: String,
87+
/// Allowed payout addresses for the spending policy
88+
#[clap(short, long)]
89+
addresses: Option<Vec<String>>,
90+
/// The max payout amount in Satoshi
91+
#[clap(short, long)]
92+
max_payout: Option<u64>,
8793
},
8894
/// Update a profile
8995
UpdateProfile {
@@ -751,9 +757,15 @@ pub async fn run() -> anyhow::Result<()> {
751757
}
752758
}
753759
}
754-
Command::CreateProfile { url, api_key, name } => {
760+
Command::CreateProfile {
761+
url,
762+
api_key,
763+
name,
764+
addresses,
765+
max_payout,
766+
} => {
755767
let client = api_client(cli.bria_home, url, api_key);
756-
client.create_profile(name).await?;
768+
client.create_profile(name, addresses, max_payout).await?;
757769
}
758770
Command::UpdateProfile {
759771
url,

0 commit comments

Comments
 (0)