Skip to content

Commit 8d895c5

Browse files
authored
Merge pull request #281 from xch-dev/quex
Slot Update
2 parents 57064d8 + 704a07f commit 8d895c5

File tree

6 files changed

+94
-90
lines changed

6 files changed

+94
-90
lines changed

crates/chia-sdk-driver/src/primitives/action_layer/catalog_registry.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
DelegatedStateAction, DriverError, Layer, Puzzle, SingletonAction, Spend, SpendContext,
1212
};
1313

14-
use super::{CatalogRegistryConstants, CatalogRegistryInfo, CatalogRegistryState, Slot, SlotProof};
14+
use super::{CatalogRegistryConstants, CatalogRegistryInfo, CatalogRegistryState, Slot};
1515

1616
#[derive(Debug, Clone)]
1717
pub struct CatalogPendingSpendInfo {
@@ -295,13 +295,12 @@ impl CatalogRegistry {
295295
&self,
296296
slot_value: CatalogSlotValue,
297297
) -> Slot<CatalogSlotValue> {
298-
let proof = SlotProof {
299-
parent_parent_info: self.coin.parent_coin_info,
300-
parent_inner_puzzle_hash: self.info.inner_puzzle_hash().into(),
301-
};
302-
303298
Slot::new(
304-
proof,
299+
LineageProof {
300+
parent_parent_coin_info: self.coin.parent_coin_info,
301+
parent_inner_puzzle_hash: self.info.inner_puzzle_hash().into(),
302+
parent_amount: self.coin.amount,
303+
},
305304
SlotInfo::from_value(self.info.constants.launcher_id, 0, slot_value),
306305
)
307306
}

crates/chia-sdk-driver/src/primitives/action_layer/launch_drivers.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use clvmr::{Allocator, NodePtr};
2626
use crate::{
2727
Cat, CatSpend, CatalogRegistry, CatalogRegistryConstants, CatalogRegistryInfo,
2828
CatalogRegistryState, DriverError, Launcher, Layer, Nft, Offer, Reserve, RewardDistributor,
29-
RewardDistributorConstants, RewardDistributorInfo, RewardDistributorState, Slot, SlotProof,
30-
Spend, SpendContext, StandardLayer, XchandlesConstants, XchandlesRegistry,
31-
XchandlesRegistryInfo, XchandlesRegistryState,
29+
RewardDistributorConstants, RewardDistributorInfo, RewardDistributorState, Slot, Spend,
30+
SpendContext, StandardLayer, XchandlesConstants, XchandlesRegistry, XchandlesRegistryInfo,
31+
XchandlesRegistryState,
3232
};
3333

3434
#[allow(clippy::needless_pass_by_value)]
@@ -207,9 +207,10 @@ where
207207
parent_amount: 1,
208208
});
209209

210-
let slot_proof = SlotProof {
211-
parent_parent_info: eve_coin.parent_coin_info,
210+
let slot_proof = LineageProof {
211+
parent_parent_coin_info: eve_coin.parent_coin_info,
212212
parent_inner_puzzle_hash: eve_singleton_inner_puzzle_hash.into(),
213+
parent_amount: 1,
213214
};
214215
let left_slot = Slot::new(
215216
slot_proof,
@@ -703,17 +704,12 @@ pub fn launch_dig_reward_distributor(
703704
SingletonArgs::curry_tree_hash(launcher_id, target_inner_puzzle_hash).into(),
704705
1,
705706
);
706-
let new_proof = Proof::Lineage(LineageProof {
707+
let new_proof = LineageProof {
707708
parent_parent_coin_info: eve_coin.parent_coin_info,
708709
parent_inner_puzzle_hash: eve_singleton_inner_puzzle_hash.into(),
709-
parent_amount: 1,
710-
});
711-
712-
let slot_proof = SlotProof {
713-
parent_parent_info: eve_coin.parent_coin_info,
714-
parent_inner_puzzle_hash: eve_singleton_inner_puzzle_hash.into(),
710+
parent_amount: eve_coin.amount,
715711
};
716-
let slot = Slot::new(slot_proof, slot_info);
712+
let slot = Slot::new(new_proof, slot_info);
717713

718714
// this creates the launcher & secures the spend
719715
let security_coin_conditions =
@@ -729,7 +725,12 @@ pub fn launch_dig_reward_distributor(
729725
0,
730726
reserve_cat.coin.amount,
731727
);
732-
let registry = RewardDistributor::new(new_registry_coin, new_proof, target_info, reserve);
728+
let registry = RewardDistributor::new(
729+
new_registry_coin,
730+
Proof::Lineage(new_proof),
731+
target_info,
732+
reserve,
733+
);
733734

734735
// Spend security coin
735736
let security_coin_sig = spend_security_coin(
@@ -1640,6 +1641,7 @@ mod tests {
16401641
payment_cat.info.asset_id,
16411642
),
16421643
)?;
1644+
println!("launched"); // todo: debug
16431645

16441646
// Check XCHandlesRegistry::from_launcher_solution
16451647
let spends = ctx.take();

crates/chia-sdk-driver/src/primitives/action_layer/reward_distributor.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::{
2121
RewardDistributorCommitIncentivesAction, RewardDistributorInitiatePayoutAction,
2222
RewardDistributorNewEpochAction, RewardDistributorRemoveEntryAction,
2323
RewardDistributorStakeAction, RewardDistributorSyncAction, RewardDistributorUnstakeAction,
24-
RewardDistributorWithdrawIncentivesAction, SingletonAction, SingletonLayer, Slot, SlotProof,
25-
Spend, SpendContext,
24+
RewardDistributorWithdrawIncentivesAction, SingletonAction, SingletonLayer, Slot, Spend,
25+
SpendContext,
2626
};
2727

2828
use super::{Reserve, RewardDistributorConstants, RewardDistributorInfo, RewardDistributorState};
@@ -487,18 +487,14 @@ impl RewardDistributor {
487487
));
488488
}
489489

490-
let slot_proof = SlotProof {
491-
parent_parent_info: lineage_proof.parent_parent_coin_info,
492-
parent_inner_puzzle_hash: lineage_proof.parent_inner_puzzle_hash,
493-
};
494490
let slot_value = RewardDistributorRewardSlotValue {
495491
epoch_start: initial_state.round_time_info.epoch_end,
496492
next_epoch_initialized: false,
497493
rewards: 0,
498494
};
499495

500496
let slot = Slot::new(
501-
slot_proof,
497+
lineage_proof,
502498
SlotInfo::from_value(
503499
constants.launcher_id,
504500
RewardDistributorSlotNonce::REWARD.to_u64(),
@@ -599,13 +595,12 @@ impl RewardDistributor {
599595
where
600596
SlotValue: Copy + ToTreeHash,
601597
{
602-
let proof = SlotProof {
603-
parent_parent_info: self.coin.parent_coin_info,
604-
parent_inner_puzzle_hash: self.info.inner_puzzle_hash().into(),
605-
};
606-
607598
Slot::new(
608-
proof,
599+
LineageProof {
600+
parent_parent_coin_info: self.coin.parent_coin_info,
601+
parent_inner_puzzle_hash: self.info.inner_puzzle_hash().into(),
602+
parent_amount: self.coin.amount,
603+
},
609604
SlotInfo::from_value(self.info.constants.launcher_id, nonce.to_u64(), slot_value),
610605
)
611606
}

crates/chia-sdk-driver/src/primitives/action_layer/slot.rs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chia_protocol::{Bytes32, Coin, CoinSpend};
2-
use chia_puzzle_types::singleton::{SingletonArgs, SingletonStruct};
2+
use chia_puzzle_types::{singleton::SingletonArgs, LineageProof};
33
use chia_sdk_types::{
44
puzzles::{Slot1stCurryArgs, Slot2ndCurryArgs, SlotInfo, SlotSolution},
55
Mod,
@@ -9,36 +9,24 @@ use clvmr::NodePtr;
99

1010
use crate::{DriverError, SpendContext};
1111

12-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13-
pub struct SlotProof {
14-
pub parent_parent_info: Bytes32,
15-
pub parent_inner_puzzle_hash: Bytes32,
16-
}
17-
18-
impl SlotProof {
19-
pub fn slot_parent_id(&self, launcher_id: Bytes32) -> Bytes32 {
20-
Coin::new(
21-
self.parent_parent_info,
22-
SingletonArgs::curry_tree_hash(launcher_id, self.parent_inner_puzzle_hash.into())
23-
.into(),
24-
1,
25-
)
26-
.coin_id()
27-
}
28-
}
29-
3012
#[derive(Debug, Clone, PartialEq, Eq)]
3113
#[must_use]
3214
pub struct Slot<V> {
3315
pub coin: Coin,
34-
pub proof: SlotProof,
16+
pub proof: LineageProof,
3517

3618
pub info: SlotInfo<V>,
3719
}
3820

3921
impl<V> Slot<V> {
40-
pub fn new(proof: SlotProof, info: SlotInfo<V>) -> Self {
41-
let parent_coin_id = proof.slot_parent_id(info.launcher_id);
22+
pub fn new(proof: LineageProof, info: SlotInfo<V>) -> Self {
23+
let parent_coin_id = Coin::new(
24+
proof.parent_parent_coin_info,
25+
SingletonArgs::curry_tree_hash(info.launcher_id, proof.parent_inner_puzzle_hash.into())
26+
.into(),
27+
proof.parent_amount,
28+
)
29+
.coin_id();
4230

4331
Self {
4432
coin: Coin::new(parent_coin_id, Slot::<V>::puzzle_hash(&info).into(), 0),
@@ -48,11 +36,7 @@ impl<V> Slot<V> {
4836
}
4937

5038
pub fn first_curry_hash(launcher_id: Bytes32, nonce: u64) -> TreeHash {
51-
Slot1stCurryArgs {
52-
singleton_struct: SingletonStruct::new(launcher_id),
53-
nonce,
54-
}
55-
.curry_tree_hash()
39+
Slot1stCurryArgs::new(launcher_id, nonce).curry_tree_hash()
5640
}
5741

5842
pub fn puzzle_hash(info: &SlotInfo<V>) -> TreeHash {
@@ -66,10 +50,10 @@ impl<V> Slot<V> {
6650
}
6751

6852
pub fn construct_puzzle(&self, ctx: &mut SpendContext) -> Result<NodePtr, DriverError> {
69-
let self_program = ctx.curry(Slot1stCurryArgs {
70-
singleton_struct: SingletonStruct::new(self.info.launcher_id),
71-
nonce: self.info.nonce,
72-
})?;
53+
let self_program = ctx.curry(Slot1stCurryArgs::new(
54+
self.info.launcher_id,
55+
self.info.nonce,
56+
))?;
7357

7458
ctx.alloc(&CurriedProgram {
7559
program: self_program,
@@ -88,8 +72,7 @@ impl<V> Slot<V> {
8872
let puzzle_reveal = ctx.serialize(&puzzle_reveal)?;
8973

9074
let solution = ctx.serialize(&SlotSolution {
91-
parent_parent_info: self.proof.parent_parent_info,
92-
parent_inner_puzzle_hash: self.proof.parent_inner_puzzle_hash,
75+
lineage_proof: self.proof,
9376
spender_inner_puzzle_hash,
9477
})?;
9578

crates/chia-sdk-driver/src/primitives/action_layer/xchandles_registry.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
XchandlesRegisterAction, XchandlesUpdateAction,
1515
};
1616

17-
use super::{Slot, SlotProof, XchandlesConstants, XchandlesRegistryInfo, XchandlesRegistryState};
17+
use super::{Slot, XchandlesConstants, XchandlesRegistryInfo, XchandlesRegistryState};
1818

1919
#[derive(Debug, Clone)]
2020
pub struct XchandlesPendingSpendInfo {
@@ -367,9 +367,10 @@ impl XchandlesRegistry {
367367
parent_amount: eve_coin.amount,
368368
});
369369

370-
let slot_proof = SlotProof {
371-
parent_parent_info: eve_coin.parent_coin_info,
370+
let slot_proof = LineageProof {
371+
parent_parent_coin_info: eve_coin.parent_coin_info,
372372
parent_inner_puzzle_hash: eve_singleton_inner_puzzle_hash.into(),
373+
parent_amount: 1,
373374
};
374375
let slots = [
375376
Slot::new(
@@ -448,9 +449,10 @@ impl XchandlesRegistry {
448449
&self,
449450
slot_value: XchandlesSlotValue,
450451
) -> Slot<XchandlesSlotValue> {
451-
let proof = SlotProof {
452-
parent_parent_info: self.coin.parent_coin_info,
452+
let proof = LineageProof {
453+
parent_parent_coin_info: self.coin.parent_coin_info,
453454
parent_inner_puzzle_hash: self.info.inner_puzzle_hash().into(),
455+
parent_amount: 1,
454456
};
455457

456458
Slot::new(

crates/chia-sdk-types/src/puzzles/action_layer/slot.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,69 @@
11
use std::borrow::Cow;
22

33
use chia_protocol::Bytes32;
4-
use chia_puzzle_types::singleton::SingletonStruct;
4+
use chia_puzzle_types::{singleton::SingletonStruct, LineageProof};
5+
use chia_puzzles::SINGLETON_TOP_LAYER_V1_1_HASH;
56
use clvm_traits::{FromClvm, ToClvm};
6-
use clvm_utils::TreeHash;
7+
use clvm_utils::{ToTreeHash, TreeHash};
78
use hex_literal::hex;
89

910
use crate::Mod;
1011

11-
pub const SLOT_PUZZLE: [u8; 456] = hex!(
12+
pub const SLOT_PUZZLE: [u8; 360] = hex!(
1213
"
13-
ff02ffff01ff04ffff04ff08ffff04ffff30ff2fffff02ff1effff04ff02ffff
14-
04ff05ffff04ff5fff8080808080ffff010180ff808080ffff04ffff04ff14ff
15-
ff04ffff0112ffff04ff80ffff04ffff02ff1effff04ff02ffff04ff05ffff04
16-
ff81bfff8080808080ff8080808080ff808080ffff04ffff01ffff47ff4302ff
14+
ff02ffff01ff04ffff04ff08ffff04ffff30ff4fffff02ff1effff04ff02ffff
15+
04ff05ffff04ff81afff8080808080ff82016f80ff808080ffff04ffff04ff0c
16+
ffff04ffff0112ffff04ff80ffff04ffff02ff1effff04ff02ffff04ff05ffff
17+
04ff3fff8080808080ff8080808080ff808080ffff04ffff01ffff4743ff02ff
1718
ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c77
1819
85459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596
1920
718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225
2021
f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a9
21-
1ce119a63400ade7c5ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff
22-
02ff16ffff04ff02ffff04ff09ff80808080ffff02ff16ffff04ff02ffff04ff
23-
0dff8080808080ffff01ff0bffff0101ff058080ff0180ff0bff2affff0bff1c
24-
ffff0bff1cff32ff0980ffff0bff1cffff0bff3affff0bff1cffff0bff1cff32
25-
ffff02ff16ffff04ff02ffff04ff05ff8080808080ffff0bff1cffff0bff3aff
26-
ff0bff1cffff0bff1cff32ff0b80ffff0bff1cff32ff22808080ff22808080ff
27-
22808080ff018080
22+
1ce119a63400ade7c5ff0bff56ffff0bff0affff0bff0aff66ff0980ffff0bff
23+
0affff0bff76ffff0bff0affff0bff0aff66ff0d80ffff0bff0affff0bff76ff
24+
ff0bff0affff0bff0aff66ff0b80ffff0bff0aff66ff46808080ff46808080ff
25+
46808080ff018080
2826
"
2927
);
3028

3129
pub const SLOT_PUZZLE_HASH: TreeHash = TreeHash::new(hex!(
3230
"
33-
66460af4bd504bc5e26f05698530a46fceb764b354727faf620e3a49065fa513
31+
2d55c0904da19dfb06ccdfb9b6ee3e4117e5856b573c9e5f495a5cdeab35ab51
3432
"
3533
));
3634

35+
#[derive(ToClvm, FromClvm, Debug, Clone, Copy, PartialEq, Eq)]
36+
#[clvm(list)]
37+
pub struct PackedSingletonStruct {
38+
pub singleton_mod_hash: Bytes32,
39+
#[clvm(rest)]
40+
pub singleton_struct_hash: Bytes32,
41+
}
42+
43+
impl PackedSingletonStruct {
44+
pub fn new(launcher_id: Bytes32) -> Self {
45+
Self {
46+
singleton_mod_hash: SINGLETON_TOP_LAYER_V1_1_HASH.into(),
47+
singleton_struct_hash: SingletonStruct::new(launcher_id).tree_hash().into(),
48+
}
49+
}
50+
}
3751
#[derive(ToClvm, FromClvm, Debug, Clone, Copy, PartialEq, Eq)]
3852
#[clvm(curry)]
3953
pub struct Slot1stCurryArgs {
40-
pub singleton_struct: SingletonStruct,
54+
pub controller_singleton_info: PackedSingletonStruct,
4155
pub nonce: u64,
4256
}
4357

58+
impl Slot1stCurryArgs {
59+
pub fn new(launcher_id: Bytes32, nonce: u64) -> Self {
60+
Self {
61+
controller_singleton_info: PackedSingletonStruct::new(launcher_id),
62+
nonce,
63+
}
64+
}
65+
}
66+
4467
#[derive(ToClvm, FromClvm, Debug, Clone, Copy, PartialEq, Eq)]
4568
#[clvm(curry)]
4669
pub struct Slot2ndCurryArgs {
@@ -50,8 +73,8 @@ pub struct Slot2ndCurryArgs {
5073
#[derive(ToClvm, FromClvm, Debug, Clone, Copy, PartialEq, Eq)]
5174
#[clvm(list)]
5275
pub struct SlotSolution {
53-
pub parent_parent_info: Bytes32,
54-
pub parent_inner_puzzle_hash: Bytes32,
76+
pub lineage_proof: LineageProof,
77+
#[clvm(rest)]
5578
pub spender_inner_puzzle_hash: Bytes32,
5679
}
5780

0 commit comments

Comments
 (0)