pub struct Cat {
pub coin: Coin,
pub lineage_proof: Option<LineageProof>,
pub info: CatInfo,
}Expand description
Contains all information needed to spend the outer puzzles of CAT coins.
The CatInfo is used to construct the puzzle, but the LineageProof is needed for the solution.
The only thing missing to create a valid coin spend is the inner puzzle and solution. However, this is handled separately to provide as much flexibility as possible.
This type should contain all of the information you need to store in a database for later. As long as you can figure out what puzzle the p2 puzzle hash corresponds to and spend it, you have enough information to spend the CAT coin.
Fields§
§coin: CoinThe coin that this Cat represents. Its puzzle hash should match the CatInfo::puzzle_hash.
lineage_proof: Option<LineageProof>The lineage proof is needed by the CAT puzzle to prove that this coin is a legitimate CAT. It’s typically obtained by looking up and parsing the parent coin.
This can get a bit tedious, so a helper method Cat::parse_children is provided to parse
the child Cat objects from the parent (once you have looked up its information on-chain).
Note that while the lineage proof is needed for most coins, it is optional if you are issuing more of the CAT by running its TAIL program.
info: CatInfoThe information needed to construct the outer puzzle of a CAT. See CatInfo for more details.
Implementations§
Source§impl Cat
impl Cat
pub fn new( coin: Coin, lineage_proof: Option<LineageProof>, info: CatInfo, ) -> Self
pub fn issue_with_coin( ctx: &mut SpendContext, parent_coin_id: Bytes32, amount: u64, extra_conditions: Conditions, ) -> Result<(Conditions, Vec<Cat>), DriverError>
pub fn issue_with_key( ctx: &mut SpendContext, parent_coin_id: Bytes32, public_key: PublicKey, amount: u64, extra_conditions: Conditions, ) -> Result<(Conditions, Vec<Cat>), DriverError>
pub fn issue( ctx: &mut SpendContext, parent_coin_id: Bytes32, asset_id: Bytes32, amount: u64, run_tail: RunCatTail<NodePtr, NodePtr>, conditions: Conditions, ) -> Result<(Conditions, Vec<Cat>), DriverError>
Sourcepub fn spend_all(
ctx: &mut SpendContext,
cat_spends: &[CatSpend],
) -> Result<Vec<Cat>, DriverError>
pub fn spend_all( ctx: &mut SpendContext, cat_spends: &[CatSpend], ) -> Result<Vec<Cat>, DriverError>
Constructs a CoinSpend for each CatSpend in the list.
The spends are added to the SpendContext (in order) for convenience.
All of the ring announcements and proofs required by the CAT puzzle are calculated automatically. This requires running the inner spends to get the conditions, so any errors will be propagated.
It’s important not to spend CATs with different asset IDs at the same time, since they are not compatible.
Additionally, you should group all CAT spends done in the same transaction together so that the value of one coin can be freely used in the output of another. If you spend them separately, there will be multiple announcement rings and a non-zero delta will be calculated.
Sourcepub fn spend(
&self,
ctx: &mut SpendContext,
info: SingleCatSpend,
) -> Result<(), DriverError>
pub fn spend( &self, ctx: &mut SpendContext, info: SingleCatSpend, ) -> Result<(), DriverError>
Spends this CAT coin with the provided solution parameters. Other parameters are inferred from
the Cat instance.
This is useful if you have already calculated the conditions and want to spend the coin directly.
However, it’s more common to use Cat::spend_all which handles the details of calculating the
solution (including ring announcements) for multiple CATs and spending them all at once.
Sourcepub fn child_lineage_proof(&self) -> LineageProof
pub fn child_lineage_proof(&self) -> LineageProof
Creates a LineageProof for which would be valid for any children created by this Cat.
Sourcepub fn child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Self
pub fn child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Self
Creates a new Cat that represents a child of this one.
The child will have the same revocation layer (or lack thereof) as the current Cat.
If you need to construct a child without the revocation layer, use Cat::unrevocable_child.
Sourcepub fn unrevocable_child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Self
pub fn unrevocable_child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Self
Creates a new Cat that represents a child of this one.
The child will not have a revocation layer.
If you need to construct a child with the same revocation layer, use Cat::child.
Sourcepub fn child_with(&self, info: CatInfo, amount: u64) -> Self
pub fn child_with(&self, info: CatInfo, amount: u64) -> Self
Creates a new Cat that represents a child of this one.
You can specify the CatInfo to use for the child manually.
In most cases, you will want to use Cat::child or Cat::unrevocable_child instead.
Source§impl Cat
impl Cat
Sourcepub fn parse_children(
allocator: &mut Allocator,
parent_coin: Coin,
parent_puzzle: Puzzle,
parent_solution: NodePtr,
) -> Result<Option<Vec<Self>>, DriverError>where
Self: Sized,
pub fn parse_children(
allocator: &mut Allocator,
parent_coin: Coin,
parent_puzzle: Puzzle,
parent_solution: NodePtr,
) -> Result<Option<Vec<Self>>, DriverError>where
Self: Sized,
Parses the children of a Cat from the parent coin spend.
This can be used to construct a valid spendable Cat for a hinted coin.
You simply need to look up the parent coin’s spend, parse the children, and
find the one that matches the hinted coin.
There is special handling for the revocation layer.
See Cat::child_from_p2_create_coin for more details.
Sourcepub fn child_from_p2_create_coin(
&self,
allocator: &Allocator,
create_coin: CreateCoin<NodePtr>,
revoke: bool,
) -> Self
pub fn child_from_p2_create_coin( &self, allocator: &Allocator, create_coin: CreateCoin<NodePtr>, revoke: bool, ) -> Self
Creates a new Cat that reflects the create coin condition in the p2 spend’s conditions.
There is special handling for the revocation layer:
- If there is no revocation layer for the parent, the child will not have one either.
- If the parent was not revoked, the child will have the same revocation layer.
- If the parent was revoked, the child will not have a revocation layer.
- If the parent was revoked, and the child was hinted (and wrapped with the revocation layer), it will detect it.
Trait Implementations§
Source§impl Asset for Cat
impl Asset for Cat
fn coin_id(&self) -> Bytes32
fn full_puzzle_hash(&self) -> Bytes32
fn p2_puzzle_hash(&self) -> Bytes32
fn amount(&self) -> u64
fn constraints(&self) -> OutputConstraints
Source§impl FungibleAsset for Cat
impl FungibleAsset for Cat
fn make_child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Self
fn child_memos( &self, ctx: &mut SpendContext, p2_puzzle_hash: Bytes32, ) -> Result<Memos, DriverError>
impl Copy for Cat
impl Eq for Cat
impl StructuralPartialEq for Cat
Auto Trait Implementations§
impl Freeze for Cat
impl RefUnwindSafe for Cat
impl Send for Cat
impl Sync for Cat
impl Unpin for Cat
impl UnwindSafe for Cat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.