sui_transaction_builder/intent/mod.rs
1//! High-level transaction intents.
2//!
3//! Intents describe *what* a transaction should accomplish without requiring the caller to
4//! manually manage coin selection or object resolution. When the transaction is built with
5//! [`TransactionBuilder::build`](crate::TransactionBuilder::build), registered resolvers
6//! communicate with the network to fill in the details.
7//!
8//! The built-in intents are [`Coin`] (requesting a `Coin<T>`) and [`Balance`] (requesting a
9//! `Balance<T>`). Both are handled by the same resolver so that mixed requests for the same
10//! coin type are accounted for together.
11
12use crate::Argument;
13use crate::TransactionBuilder;
14
15mod coin_with_balance;
16pub use coin_with_balance::Balance;
17pub use coin_with_balance::Coin;
18pub use coin_with_balance::CoinWithBalance;
19
20const MAX_GAS_OBJECTS: usize = 250; // 256
21#[allow(unused)]
22const MAX_COMMANDS: usize = 1000; // 1024
23#[allow(unused)]
24const MAX_INPUT_OBJECTS: usize = 2000; // 2048
25const MAX_ARGUMENTS: usize = 500; // 512
26
27pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
28
29pub(crate) trait Intent: std::any::Any + Send + Sync {
30 fn register(self, builder: &mut TransactionBuilder) -> Argument;
31}
32
33#[async_trait::async_trait]
34pub(crate) trait IntentResolver: std::any::Any + std::fmt::Debug + Send + Sync {
35 // Perform any required resolutions
36 async fn resolve(
37 &self,
38 builder: &mut TransactionBuilder,
39 client: &mut sui_rpc::Client,
40 ) -> Result<(), BoxError>;
41}