fabric_contract::contract

Struct Ledger

Source
pub struct Ledger {}
Expand description

Ledger representing high level concept of the Fabric Blockchain network

Provides the access points for

  • getting access to data in both world state and peer’s private collections
  • invoking chaincode on this and other networks

When a transaction is invoked, it takes place under a ‘transactional context’ This context can be queried to provide the current transaction id, and information about the identity requesting the transaction.

All operations need to be done under this transactional context, therefore the context needs to be passed to obtain the Ledger instance

§Example

use fabric_contract::contract::*;


pub fn asset_exists(my_assset_id: String) -> Result<bool,String> {
   let ledger = Ledger::access_ledger();
    
   let world = ledger.get_collection(CollectionName::World);

   Ok(world.state_exists(&my_assset_id))

}

Implementations§

Source§

impl Ledger

Source

pub fn access_ledger() -> Ledger

Get the Ledger based on the current transactional context

The Tranasctional Context is available via the Transaction API

Source

pub fn get_collection(&self, name: CollectionName) -> Collection

Return the collection based on the name

The collection provides access to the put & get Fabric semantics of the underlying world state, or private data that is specified by the Collection name.

§Example
use fabric_contract::contract::*;
let ledger = Ledger::access_ledger();

// get the collectin that is backed by the World State
let world = ledger.get_collection(CollectionName::World);  

// get the collection that is backed by the Organization's Implicity Private Data Collection
let orgs_collection = ledger.get_collection(CollectionName::Organization(String::from("org1")));
    
// get the collection that is backed by the named Private Data Collection
let private_collection = ledger.get_collection(CollectionName::Private(String::from("my_private_details")));

Auto Trait Implementations§

§

impl Freeze for Ledger

§

impl RefUnwindSafe for Ledger

§

impl Send for Ledger

§

impl Sync for Ledger

§

impl Unpin for Ledger

§

impl UnwindSafe for Ledger

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.