chia_sdk_bindings/
coin.rs

1use bindy::Result;
2use chia_protocol::{Bytes, Bytes32, Coin, SpendBundle};
3use chia_traits::Streamable;
4
5pub trait CoinExt {
6    fn coin_id(&self) -> Result<Bytes32>;
7}
8
9impl CoinExt for Coin {
10    fn coin_id(&self) -> Result<Bytes32> {
11        Ok(self.coin_id())
12    }
13}
14
15pub trait SpendBundleExt: Sized {
16    fn to_bytes(&self) -> Result<Bytes>;
17    fn from_bytes(bytes: Bytes) -> Result<Self>;
18    fn hash(&self) -> Result<Bytes32>;
19}
20
21impl SpendBundleExt for SpendBundle {
22    fn to_bytes(&self) -> Result<Bytes> {
23        Ok(Streamable::to_bytes(self)?.into())
24    }
25
26    fn from_bytes(bytes: Bytes) -> Result<Self> {
27        Ok(Streamable::from_bytes(&bytes)?)
28    }
29
30    fn hash(&self) -> Result<Bytes32> {
31        Ok(Streamable::hash(self).into())
32    }
33}