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)?;Sourcepub fn txs(&self) -> &HashMap<String, Transaction>
pub fn txs(&self) -> &HashMap<String, Transaction>
Returns all transactions defined in the protocol.
§Returns
Returns a reference to the map of transaction names to their definitions.
Sourcepub fn parties(&self) -> &HashMap<String, Party>
pub fn parties(&self) -> &HashMap<String, Party>
Returns all parties defined in the protocol.
§Returns
Returns a reference to the map of party names to their definitions.
Sourcepub fn profiles(&self) -> &HashMap<String, Profile>
pub fn profiles(&self) -> &HashMap<String, Profile>
Returns all profiles defined in the protocol.
Sourcepub fn client(self) -> Tx3ClientBuilder
pub fn client(self) -> Tx3ClientBuilder
Starts a [Tx3ClientBuilder] for this protocol. Configure TRP options,
optional profile selection, party bindings, and env overrides, then
call build() to obtain a crate::Tx3Client.