fuel_core_client/client/types/
coins.rs1use crate::client::{
2 PaginatedResult,
3 schema,
4 types::primitives::{
5 Address,
6 AssetId,
7 Nonce,
8 UtxoId,
9 },
10};
11
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub enum CoinType {
14 Coin(Coin),
15 MessageCoin(MessageCoin),
16 Unknown,
17}
18
19impl CoinType {
20 pub fn amount(&self) -> u64 {
21 match self {
22 CoinType::Coin(c) => c.amount,
23 CoinType::MessageCoin(m) => m.amount,
24 CoinType::Unknown => 0,
25 }
26 }
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
30pub struct Coin {
31 pub amount: u64,
32 pub block_created: u32,
33 pub tx_created_idx: u16,
34 pub asset_id: AssetId,
35 pub utxo_id: UtxoId,
36 pub owner: Address,
37}
38
39#[derive(Clone, Copy, Debug, PartialEq, Eq)]
40pub struct MessageCoin {
41 pub amount: u64,
42 pub sender: Address,
43 pub recipient: Address,
44 pub nonce: Nonce,
45 pub da_height: u64,
46}
47
48impl From<schema::coins::CoinType> for CoinType {
51 fn from(value: schema::coins::CoinType) -> Self {
52 match value {
53 schema::coins::CoinType::Coin(coin) => Self::Coin(coin.into()),
54 schema::coins::CoinType::MessageCoin(message_coin) => {
55 Self::MessageCoin(message_coin.into())
56 }
57 schema::coins::CoinType::Unknown => Self::Unknown,
58 }
59 }
60}
61
62impl From<schema::coins::Coin> for Coin {
63 fn from(value: schema::coins::Coin) -> Self {
64 Self {
65 amount: value.amount.into(),
66 block_created: value.block_created.into(),
67 tx_created_idx: value.tx_created_idx.into(),
68 asset_id: value.asset_id.into(),
69 utxo_id: value.utxo_id.into(),
70 owner: value.owner.into(),
71 }
72 }
73}
74
75impl From<schema::coins::MessageCoin> for MessageCoin {
76 fn from(value: schema::coins::MessageCoin) -> Self {
77 Self {
78 amount: value.amount.into(),
79 sender: value.sender.into(),
80 recipient: value.recipient.into(),
81 nonce: value.nonce.into(),
82 da_height: value.da_height.into(),
83 }
84 }
85}
86
87impl From<schema::coins::CoinConnection> for PaginatedResult<Coin, String> {
88 fn from(conn: schema::coins::CoinConnection) -> Self {
89 PaginatedResult {
90 cursor: conn.page_info.end_cursor,
91 has_next_page: conn.page_info.has_next_page,
92 has_previous_page: conn.page_info.has_previous_page,
93 results: conn.edges.into_iter().map(|e| e.node.into()).collect(),
94 }
95 }
96}