Skip to main content

Crate rgb_lib

Crate rgb_lib 

Source
Expand description

A library to manage wallets for RGB assets.

§Wallet

The main components of the library are the wallet::Wallet and wallet::MultisigWallet.

They allow to create and operate RGB wallets that can issue and operate on NIA, CFA, IFA and UDA assets. The library also manages UTXOs and asset allocations.

§Backend

The library uses BDK for walleting operations and several components from the RGB ecosystem for RGB asset operations.

§Database

A SQLite database is used to persist data to disk.

Database support is designed in order to support multiple database backends. At the moment only SQLite is supported but adding more should be relatively easy.

§External services

The library uses an external indexer to get information about the Bitcoin network. At the moment Electrum and Esplora are supported.

RGB asset operations may require the exchange of off-chain data in the form of consignment or media files with a counterparty. To do so the library is able to interact with a proxy server to support these data exchanges between the parties.

The library also supports the use of a multisig hub to support multisig wallets and the use of a reject list service.

§Errors

Errors are handled with the crate thiserror.

§FFI

Library functionality is exposed for other languages via FFI bindings.

§Examples

§Create an RGB singlesig wallet

use rgb_lib::keys::{WitnessVersion, generate_keys};
use rgb_lib::wallet::{DatabaseType, SinglesigKeys, Wallet, WalletData};
use rgb_lib::{AssetSchema, BitcoinNetwork};

fn main() -> Result<(), rgb_lib::Error> {
    let data_dir = tempfile::tempdir()?;
    let keys = generate_keys(BitcoinNetwork::Regtest, WitnessVersion::Taproot);
    let single_sig_keys = SinglesigKeys::from_keys(&keys, None);
    let wallet_data = WalletData {
        data_dir: data_dir.path().to_str().unwrap().to_string(),
        bitcoin_network: BitcoinNetwork::Regtest,
        database_type: DatabaseType::Sqlite,
        max_allocations_per_utxo: 5,
        supported_schemas: vec![AssetSchema::Nia],
    };
    let wallet = Wallet::new(wallet_data, single_sig_keys)?;

    Ok(())
}

§Load an existing RGB singlesig wallet

wallet::Wallet::new records the wallet settings in the wallet directory, so an existing wallet can be re-opened with just its location, its master fingerprint and its mnemonic. Passing no mnemonic loads the wallet in watch-only mode.

use rgb_lib::keys::{WitnessVersion, generate_keys};
use rgb_lib::wallet::{DatabaseType, SinglesigKeys, Wallet, WalletData};
use rgb_lib::{AssetSchema, BitcoinNetwork};

fn main() -> Result<(), rgb_lib::Error> {
    let data_dir = tempfile::tempdir()?;
    let data_dir = data_dir.path().to_str().unwrap();
    let keys = generate_keys(BitcoinNetwork::Regtest, WitnessVersion::Taproot);
    let wallet_data = WalletData {
        data_dir: data_dir.to_string(),
        bitcoin_network: BitcoinNetwork::Regtest,
        database_type: DatabaseType::Sqlite,
        max_allocations_per_utxo: 5,
        supported_schemas: vec![AssetSchema::Nia],
    };
    let wallet = Wallet::new(wallet_data, SinglesigKeys::from_keys(&keys, None))?;
    drop(wallet);

    let wallet = Wallet::load(
        data_dir,
        &keys.master_fingerprint,
        Some(keys.mnemonic.clone()),
    )?;

    Ok(())
}

Re-exports§

pub use crate::utils::BitcoinNetwork;
pub use crate::utils::block_on;
pub use bdk_wallet;
pub use bdk_wallet::bitcoin;

Modules§

keys
Wallet keys.
utils
Utilities.
wallet
Wallet functionality.

Structs§

ContractId
Unique contract identifier equivalent to the contract genesis commitment
Fascia
Structure exported from a PSBT for merging into the stash. It contains a set of finalized state transitions (under multiple contracts), packed into bundles, and anchored to a single layer 1 transaction.
RgbTxid
A bitcoin transaction hash/transaction ID.
SchemaId
Schema identifier.
UpdateRes
WitnessBundle

Enums§

AssetSchema
The schema of an asset.
Assignment
An RGB assignment.
Error
The error variants returned by functions.
PubWitness
TransferStatus
The status of a crate::wallet::Transfer.
TransportType
The type of an RGB transport.
WalletTransactionType
The type of a pending vanilla wallet transaction.
WitnessOrd
RGB consensus information about the status of a witness transaction. This information is used in ordering state transitions during the validation, as well as consensus ordering of the contract global state data, as they are presented to all contract users.

Traits§

ConsignmentExt
FileContent

Type Aliases§

CloseMethod
Method for closing single-use-seals.
RgbTransfer