Skip to content

Commit d121553

Browse files
committed
add view commands - and happy 1000th commit!
1 parent 89ddff5 commit d121553

File tree

5 files changed

+237
-5
lines changed

5 files changed

+237
-5
lines changed

src/cli/commands.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use super::{
88
reward_distributor_broadcast_entry_update, reward_distributor_clawback_rewards,
99
reward_distributor_commit_rewards, reward_distributor_initiate_payout,
1010
reward_distributor_launch, reward_distributor_new_epoch, reward_distributor_sign_entry_update,
11-
reward_distributor_sync, verifications_broadcast_launch, verifications_broadcast_revocation,
12-
verifications_sign_launch, verifications_sign_revocation, verifications_view,
13-
xchandles_continue_launch, xchandles_expire, xchandles_extend, xchandles_initiate_launch,
14-
xchandles_listen, xchandles_register, xchandles_unroll_state_scheduler, xchandles_update,
15-
xchandles_verify_deployment,
11+
reward_distributor_sync, reward_distributor_view, verifications_broadcast_launch,
12+
verifications_broadcast_revocation, verifications_sign_launch, verifications_sign_revocation,
13+
verifications_view, xchandles_continue_launch, xchandles_expire, xchandles_extend,
14+
xchandles_initiate_launch, xchandles_listen, xchandles_register,
15+
xchandles_unroll_state_scheduler, xchandles_update, xchandles_verify_deployment,
16+
xchandles_view,
1617
};
1718

1819
#[derive(Parser)]
@@ -618,6 +619,24 @@ enum XchandlesCliAction {
618619
#[arg(long, default_value_t = false)]
619620
testnet11: bool,
620621
},
622+
/// Shows up-to-date information about an XCHandles registry
623+
View {
624+
/// XCHandles (sub)registry launcher id
625+
#[arg(long)]
626+
launcher_id: String,
627+
628+
/// Use testnet11
629+
#[arg(long, default_value_t = false)]
630+
testnet11: bool,
631+
632+
/// Payment asset id hint
633+
#[arg(long)]
634+
payment_asset_id: Option<String>,
635+
636+
/// Payment CAT base price hint
637+
#[arg(long)]
638+
payment_cat_base_price: Option<String>,
639+
},
621640
}
622641

623642
#[derive(Subcommand)]
@@ -852,6 +871,16 @@ enum RewardDistributorCliAction {
852871
#[arg(long, default_value = "0.0025")]
853872
fee: String,
854873
},
874+
/// Views up-to-date information about a reward distributor
875+
View {
876+
/// Reward distributor singleton launcher id
877+
#[arg(long)]
878+
launcher_id: String,
879+
880+
/// Use testnet11
881+
#[arg(long, default_value_t = false)]
882+
testnet11: bool,
883+
},
855884
}
856885

857886
#[derive(Subcommand)]
@@ -1277,6 +1306,20 @@ pub async fn run_cli() {
12771306
testnet11,
12781307
launcher_ids,
12791308
} => xchandles_listen(launcher_ids, testnet11).await,
1309+
XchandlesCliAction::View {
1310+
launcher_id,
1311+
testnet11,
1312+
payment_asset_id,
1313+
payment_cat_base_price,
1314+
} => {
1315+
xchandles_view(
1316+
launcher_id,
1317+
testnet11,
1318+
payment_asset_id,
1319+
payment_cat_base_price,
1320+
)
1321+
.await
1322+
}
12801323
},
12811324
Commands::RewardDistributor { action } => match action {
12821325
RewardDistributorCliAction::Launch {
@@ -1411,6 +1454,10 @@ pub async fn run_cli() {
14111454
reward_distributor_initiate_payout(launcher_id, payout_puzzle_hash, testnet11, fee)
14121455
.await
14131456
}
1457+
RewardDistributorCliAction::View {
1458+
launcher_id,
1459+
testnet11,
1460+
} => reward_distributor_view(launcher_id, testnet11).await,
14141461
},
14151462
Commands::Verifications { action } => match action {
14161463
VerificationsCliAction::SignLaunch {

src/cli/reward_distributor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod new_epoch;
99
mod sign_entry_update;
1010
mod sync;
1111
mod sync_distributor;
12+
mod view;
1213

1314
pub use add_rewards::*;
1415
pub use broadcast_entry_update::*;
@@ -21,3 +22,4 @@ pub use new_epoch::*;
2122
pub use sign_entry_update::*;
2223
pub use sync::*;
2324
pub use sync_distributor::*;
25+
pub use view::*;

src/cli/reward_distributor/view.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use crate::{
2+
get_coinset_client, get_prefix, hex_string_to_bytes32, sync_distributor, CliError, Db,
3+
};
4+
use chia_wallet_sdk::{driver::SpendContext, utils::Address};
5+
6+
pub async fn reward_distributor_view(
7+
launcher_id_str: String,
8+
testnet11: bool,
9+
) -> Result<(), CliError> {
10+
let launcher_id = hex_string_to_bytes32(&launcher_id_str)?;
11+
12+
println!("Syncing reward distributor...");
13+
let client = get_coinset_client(testnet11);
14+
let db = Db::new(false).await?;
15+
let mut ctx = SpendContext::new();
16+
let distributor = sync_distributor(&client, &db, &mut ctx, launcher_id).await?;
17+
18+
println!(
19+
"Latest coin id: {}",
20+
hex::encode(distributor.coin.coin_id())
21+
);
22+
println!("State:");
23+
println!(" Active shares: {}", distributor.info.state.active_shares);
24+
println!(
25+
" Cumulative payout: {} mojos per share",
26+
distributor.info.state.round_reward_info.cumulative_payout
27+
);
28+
println!(
29+
" Remaining rewards: {} mojos",
30+
distributor.info.state.round_reward_info.remaining_rewards
31+
);
32+
println!(
33+
" Epoch end: {}",
34+
distributor.info.state.round_time_info.epoch_end
35+
);
36+
println!(
37+
" Last update: {}",
38+
distributor.info.state.round_time_info.last_update
39+
);
40+
println!(
41+
" Total reserves: {} CATs",
42+
distributor.info.state.total_reserves as f64 / 1000.0
43+
);
44+
45+
println!("Constants:");
46+
println!(
47+
" Launcher ID: {}",
48+
hex::encode(distributor.info.constants.launcher_id)
49+
);
50+
println!(
51+
" Manager launcher ID: {}",
52+
hex::encode(distributor.info.constants.manager_launcher_id)
53+
);
54+
println!(
55+
" Fee payout address: {}",
56+
Address::new(
57+
distributor.info.constants.fee_payout_puzzle_hash,
58+
get_prefix(testnet11)
59+
)
60+
.encode()?
61+
);
62+
println!(
63+
" Seconds per epoch: {}",
64+
distributor.info.constants.epoch_seconds
65+
);
66+
println!(
67+
" Max seconds offset: {}",
68+
distributor.info.constants.max_seconds_offset
69+
);
70+
println!(
71+
" Payout threshold: {} mojos",
72+
distributor.info.constants.payout_threshold
73+
);
74+
println!(" Fee bps: {}", distributor.info.constants.fee_bps);
75+
println!(
76+
" Withdrawal share bps: {}",
77+
distributor.info.constants.withdrawal_share_bps
78+
);
79+
80+
Ok(())
81+
}

src/cli/xchandles.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod sync;
99
mod unroll_state_scheduler;
1010
mod update;
1111
mod verify_deployment;
12+
mod view;
1213
mod xchandles_api_client;
1314

1415
pub use continue_launch::*;
@@ -22,4 +23,5 @@ pub use sync::*;
2223
pub use unroll_state_scheduler::*;
2324
pub use update::*;
2425
pub use verify_deployment::*;
26+
pub use view::*;
2527
pub use xchandles_api_client::*;

src/cli/xchandles/view.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
use chia::clvm_utils::ToTreeHash;
2+
use chia_wallet_sdk::{driver::SpendContext, utils::Address};
3+
4+
use crate::{
5+
get_coinset_client, get_prefix, hex_string_to_bytes32, parse_amount, quick_sync_xchandles,
6+
CliError, Db, DefaultCatMakerArgs, XchandlesExponentialPremiumRenewPuzzleArgs,
7+
XchandlesFactorPricingPuzzleArgs,
8+
};
9+
10+
#[allow(clippy::too_many_arguments)]
11+
pub async fn xchandles_view(
12+
launcher_id_str: String,
13+
testnet11: bool,
14+
payment_asset_id_str: Option<String>,
15+
payment_cat_base_price_str: Option<String>,
16+
) -> Result<(), CliError> {
17+
let launcher_id = hex_string_to_bytes32(&launcher_id_str)?;
18+
19+
let mut ctx = SpendContext::new();
20+
let cli = get_coinset_client(testnet11);
21+
22+
print!("Syncing registry... ");
23+
let mut db = Db::new(false).await?;
24+
let registry = quick_sync_xchandles(&cli, &mut db, &mut ctx, launcher_id).await?;
25+
println!("done.\n");
26+
27+
println!("State:");
28+
println!(
29+
" CAT maker puzzle hash: {}",
30+
registry.info.state.cat_maker_puzzle_hash
31+
);
32+
if let Some(payment_asset_id) = payment_asset_id_str {
33+
let payment_asset_id = hex_string_to_bytes32(&payment_asset_id)?;
34+
if registry.info.state.cat_maker_puzzle_hash
35+
== DefaultCatMakerArgs::curry_tree_hash(payment_asset_id.tree_hash().into()).into()
36+
{
37+
println!(
38+
" Payment asset id: {} (VERIFIED)",
39+
hex::encode(payment_asset_id)
40+
);
41+
} else {
42+
return Err(CliError::Custom(
43+
"Payment asset id hint is wrong".to_string(),
44+
));
45+
}
46+
}
47+
println!(
48+
" Pricing puzzle hash: {}",
49+
hex::encode(registry.info.state.pricing_puzzle_hash)
50+
);
51+
println!(
52+
" Expired handle pricing puzzle hash: {}",
53+
hex::encode(registry.info.state.expired_handle_pricing_puzzle_hash)
54+
);
55+
if let Some(payment_cat_base_price) = payment_cat_base_price_str {
56+
let payment_cat_base_price = parse_amount(&payment_cat_base_price, true)?;
57+
if registry.info.state.pricing_puzzle_hash
58+
== XchandlesFactorPricingPuzzleArgs::curry_tree_hash(payment_cat_base_price).into()
59+
&& registry.info.state.expired_handle_pricing_puzzle_hash
60+
== XchandlesExponentialPremiumRenewPuzzleArgs::curry_tree_hash(
61+
payment_cat_base_price,
62+
1000,
63+
)
64+
.into()
65+
{
66+
println!(
67+
" Payment CAT base price: {} mojos (VERIFIED)",
68+
payment_cat_base_price
69+
);
70+
} else {
71+
return Err(CliError::Custom(
72+
"Payment CAT base price hint is wrong".to_string(),
73+
));
74+
}
75+
}
76+
77+
println!("Constants:");
78+
println!(
79+
" Launcher ID: {}",
80+
hex::encode(registry.info.constants.launcher_id)
81+
);
82+
println!(
83+
" Precommit payout address: {}",
84+
Address::new(
85+
registry.info.constants.precommit_payout_puzzle_hash,
86+
get_prefix(testnet11)
87+
)
88+
.encode()?
89+
);
90+
println!(
91+
" Relative block height: {}",
92+
registry.info.constants.relative_block_height
93+
);
94+
println!(
95+
" Price singleton launcher ID: {}",
96+
hex::encode(registry.info.constants.price_singleton_launcher_id)
97+
);
98+
99+
Ok(())
100+
}

0 commit comments

Comments
 (0)