fabric_gateway/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 fabric-gateway-rs contributors
3
4//! # fabric-gateway
5//!
6//! A Rust client for the Hyperledger Fabric Gateway, ported from the official
7//! [fabric-gateway-go](https://github.com/hyperledger/fabric-gateway) `client`
8//! package. It lets applications evaluate (query) and submit (update)
9//! transactions against chaincode deployed to a Fabric network, connecting
10//! through a peer's embedded Gateway service.
11//!
12//! ## Programming model
13//!
14//! The type hierarchy mirrors the Go library:
15//! [`Gateway`] → [`Network`] (a channel) → [`Contract`] (a chaincode) →
16//! [`Proposal`] → [`Transaction`] → [`Commit`].
17//!
18//! ```no_run
19//! use fabric_gateway::{Gateway, Identity, identity::EcdsaP256Signer};
20//! use std::sync::Arc;
21//!
22//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
23//! let channel = tonic::transport::Channel::from_static("https://peer:7051")
24//! .connect()
25//! .await?;
26//! let identity = Identity::new("Org1MSP", std::fs::read("cert.pem")?);
27//! let signer = Arc::new(EcdsaP256Signer::from_pem(&std::fs::read_to_string("key.pem")?)?);
28//!
29//! let gateway = Gateway::connect(identity, signer, channel)?;
30//! let contract = gateway.get_network("mychannel").get_contract("basic");
31//!
32//! let result = contract.evaluate_transaction("GetAllAssets", &[]).await?;
33//! println!("{}", String::from_utf8_lossy(&result));
34//! # Ok(())
35//! # }
36//! ```
37//!
38//! ## Wire-compatibility
39//!
40//! Proposals, transactions and commit-status requests are serialised with the
41//! same protobuf layout, transaction-ID derivation
42//! (`hex(sha256(nonce || creator))`), SHA-256 digesting and low-S ASN.1-DER
43//! ECDSA signing as fabric-gateway-go, so signatures verify on the peer.
44
45pub mod error;
46pub mod hash;
47pub mod identity;
48pub mod pb;
49
50mod client;
51mod commit;
52mod contract;
53mod events;
54mod gateway;
55mod network;
56mod proposal;
57mod signing;
58mod transaction;
59mod util;
60
61#[cfg(test)]
62mod conformance;
63#[cfg(test)]
64mod robustness;
65
66#[cfg(feature = "_fuzz")]
67#[doc(hidden)]
68pub mod fuzz_api;
69
70pub use commit::{Commit, Status};
71pub use contract::Contract;
72pub use error::{GatewayError, TransactionError};
73pub use events::{
74 BlockEventsBuilder, BlockEventsRequest, ChaincodeEvent, ChaincodeEventsBuilder,
75 ChaincodeEventsRequest, FilteredBlockEventsRequest,
76};
77pub use gateway::{Gateway, GatewayBuilder};
78pub use identity::{EcdsaP256Signer, Identity, Signer};
79pub use network::Network;
80pub use proposal::{Proposal, ProposalBuilder};
81pub use transaction::Transaction;