pub struct Protocol { /* private fields */ }Expand description
A TX3 protocol loaded from a TII file.
This structure represents a loaded TX3 protocol definition and provides methods for inspecting transactions and creating invocations.
§Example
ⓘ
use tx3_sdk::tii::Protocol;
let protocol = Protocol::from_file("protocol.tii")?;
// List all available transactions
for (name, tx) in protocol.txs() {
println!("Transaction: {}", name);
}
// Invoke a specific transaction
let invocation = protocol.invoke("transfer", Some("mainnet"))?;Implementations§
Source§impl Protocol
impl Protocol
Sourcepub fn from_json(json: Value) -> Result<Protocol, Error>
pub fn from_json(json: Value) -> Result<Protocol, Error>
Creates a Protocol from a JSON value.
§Arguments
json- Aserde_json::Valuecontaining the TII file content
§Returns
Returns a Protocol on success, or an error if the JSON is invalid.
§Example
ⓘ
use tx3_sdk::tii::Protocol;
use serde_json::json;
let json = json!({
"tii": { "version": "1.0.0" },
"protocol": { "name": "MyProtocol", "version": "1.0.0" },
"transactions": {}
});
let protocol = Protocol::from_json(json)?;Sourcepub fn from_string(code: String) -> Result<Protocol, Error>
pub fn from_string(code: String) -> Result<Protocol, Error>
Creates a Protocol from a JSON string.
§Arguments
code- A string containing the TII JSON content
§Returns
Returns a Protocol on success, or an error if the JSON is invalid.
§Example
ⓘ
use tx3_sdk::tii::Protocol;
let tii_content = r#"{
"tii": { "version": "1.0.0" },
"protocol": { "name": "MyProtocol", "version": "1.0.0" },
"transactions": {}
}"#;
let protocol = Protocol::from_string(tii_content.to_string())?;Sourcepub fn invoke(
&self,
tx: &str,
profile: Option<&str>,
) -> Result<Invocation, Error>
pub fn invoke( &self, tx: &str, profile: Option<&str>, ) -> Result<Invocation, Error>
Creates an invocation for a transaction.
This method initializes an invocation for the specified transaction, optionally applying a profile to pre-populate arguments.
§Arguments
tx- The name of the transaction to invokeprofile- Optional profile name to apply (e.g., “mainnet”, “preview”)
§Returns
Returns an Invocation that can be configured with arguments and
converted to a TRP resolve request.
§Errors
Returns an error if:
- The transaction name is not found
- The profile name is not found (if specified)
§Example
ⓘ
use tx3_sdk::tii::Protocol;
let protocol = Protocol::from_file("protocol.tii")?;
// Invoke with a profile
let invocation = protocol.invoke("transfer", Some("mainnet"))?;
// Invoke without a profile
let invocation = protocol.invoke("transfer", None)?;Trait Implementations§
Source§impl<'de> Deserialize<'de> for Protocol
impl<'de> Deserialize<'de> for Protocol
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Protocol
impl RefUnwindSafe for Protocol
impl Send for Protocol
impl Sync for Protocol
impl Unpin for Protocol
impl UnsafeUnpin for Protocol
impl UnwindSafe for Protocol
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
Mutably borrows from an owned value. Read more