Skip to main content

Crate ootle_rs

Crate ootle_rs 

Source
Expand description

§ootle.rs

A Rust library for interacting with the Tari Ootle (Layer 2) network.

ootle-rs provides a high-level, type-safe API modelled after alloy-rs, using the familiar Provider, Wallet, and Signer architecture. It supports public and confidential (stealth) transfers, balance queries, template invocation, and real-time event streaming.

§Quick start

Connect to a local Ootle indexer, create a wallet, fund it from the faucet, and send a public transfer:

use ootle_rs::{
    address,
    builtin_templates::{account::IAccount, faucet::IFaucet},
    key_provider::PrivateKeyProvider,
    provider::ProviderBuilder,
    wallet::OotleWallet,
    Network, TransactionRequest,
};
use tari_template_lib_types::constants::TARI_TOKEN;

let network = Network::LocalNet;

// 1. Create a wallet backed by a random keypair
let signer = PrivateKeyProvider::random(network);
let wallet = OotleWallet::from(signer);

// 2. Connect to the indexer
let provider = ProviderBuilder::new()
    .wallet(wallet)
    .connect("http://127.0.0.1:12500")
    .await?;

// 3. Fund our account from the faucet
let faucet_tx = IFaucet::new(&provider)
    .pay_fee(1000u64)
    .take_free_coins(500_000_000u64)
    .prepare()
    .await?;

let faucet_tx = TransactionRequest::default()
    .with_transaction(faucet_tx)
    .build(provider.wallet())
    .await?;
provider.send_transaction(faucet_tx).await?.watch().await?;

// 4. Transfer tokens to a recipient
let recipient = address!("otl_loc_10mc0v2lyy43kldl0ft4c2x5pe7j0ckduv8zej6jgr2z2g9m07fz7gl96ar5wwgu0qu0atmr5tl53ye7n38xr5u7ytlmudq0ruxcau0gge7rxk");

let unsigned_tx = IAccount::new(&provider)
    .pay_fee(1000u64)
    .public_transfer(&recipient, TARI_TOKEN, 1_000_000u64)
    .prepare()
    .await?;

let tx = TransactionRequest::default()
    .with_transaction(unsigned_tx)
    .build(provider.wallet())
    .await?;

let outcome = provider.send_transaction(tx).await?.watch().await?;
println!("Transaction confirmed: {:?}", outcome);

§Architecture

The crate follows the layered design of alloy:

§Type-safe template invocation

The ootle_template! macro generates typed wrappers for custom templates:

use ootle_rs::ootle_template;
use tari_template_lib_types::Amount;

ootle_template! {
    template StableCoin {
        fn instantiate(initial_supply: Amount);
        fn mint(&mut self, amount: Amount);
        fn balance(&self) -> Amount;
    }
}

// Call a constructor
let tx = StableCoin::for_template(template_addr, &provider)
    .instantiate(Amount::new(1_000_000))
    .pay_fee(1000)
    .prepare()
    .await?;

// Call a component method
let tx = StableCoin::for_component(component_addr, &provider)
    .mint(Amount::new(500))
    .pay_fee(1000)
    .prepare()
    .await?;

§Features

  • mmap-value-lookup — enables memory-mapped pregenerated lookup tables for fast ElGamal UTXO value decryption. Without this feature, values are decrypted via on-the-fly brute-force which is significantly slower.

Re-exports§

pub use tari_ootle_wallet_crypto as crypto;
pub use tari_template_lib_types as template_types;

Modules§

builtin_templates
Ergonomic builders for interacting with Ootle’s built-in templates.
displayable
key_provider
Cryptographic key providers for output mask generation and key derivation.
keys
macros
provider
Network provider for interacting with the Ootle indexer.
signer
stealth
Confidential (stealth) transfer support.
transaction
Transaction signing traits and ephemeral signers.
wallet
Wallet for managing keys and signing transactions.

Macros§

address
const_nonzero_u64
A macro to create a NonZeroU64 constant from a literal expression. Panics at compile time if the value is zero.
ootle_template
Define a typed interface for invoking functions and methods on a Tari Ootle template.
resource_address

Structs§

Initial
Signed
TransactionRequest
A builder for constructing signed transactions ready for submission.
WithTx

Enums§

Network
Represents the available Tari networks. The variants and assigned byte needs to match the L1 network enum.
TransactionOutcome

Traits§

ToAccountAddress
Derives the on-chain component address for an account from its Address.

Functions§

default_indexer_url
Returns the default indexer URL for the given network.

Type Aliases§

Address
An Ootle network address, identifying an account by its public key and network.
Signature