Expand description
TAPLE is a DLT focused on traceability characterized by its level of scalability, its flexibility to be employed in different devices and use cases and its reduced resource consumption, including power consumption.
The TAPLE crate provides the library that allows instantiating nodes of this DLT in order to create a functional network through a single structure containing all the required logic. Applications can interact with these nodes through the API they expose, thus enabling read and write operations against the network. The API also allows the design and creation of customized clients for the technology according to the user’s needs.
In addition to the node itself, the library also exposes a series of data structures specific to the protocol that can be obtained when interacting with the API or, in some cases, may be necessary to interact with it.
§Basic usage
use std::str::FromStr;
use taple_core::crypto::*;
use taple_core::request::*;
use taple_core::signature::*;
use taple_core::*;
/**
* Basic usage of TAPLE Core. It includes:
* - Node inicialization with on-memory DB (only for testing purpouse)
* - Minimal governance creation example
*/
#[tokio::main]
async fn main() {
// Generate ramdom node ID key pair
let node_key_pair = crypto::KeyPair::Ed25519(Ed25519KeyPair::from_seed(&[]));
// Configure minimal settings
let settings = {
let mut settings = Settings::default();
settings.node.secret_key = hex::encode(node_key_pair.secret_key_bytes());
settings
};
// Build node
let (mut node, api) = Node::build(settings, MemoryManager::new()).expect("TAPLE node built");
// Create a minimal governance
// Compose and sign the subject creation request
let governance_key = api
.add_keys(KeyDerivator::Ed25519)
.await
.expect("Error getting server response");
let create_subject_request = EventRequest::Create(StartRequest {
governance_id: DigestIdentifier::default(),
name: "".to_string(),
namespace: "".to_string(),
schema_id: "governance".to_string(),
public_key: governance_key,
});
let signed_request = Signed::<EventRequest> {
content: create_subject_request.clone(),
signature: Signature::new(&create_subject_request, &node_key_pair).unwrap(),
};
// Send the signed request to the node
let _request_id = api.external_request(signed_request).await.unwrap();
// Wait until event notification
let subject_id = if let Notification::NewEvent { sn: _, subject_id } = node
.recv_notification()
.await
.expect("NewEvent notification received")
{
subject_id
} else {
panic!("Unexpected notification");
};
// Get the new subject data
let subject = api
.get_subject(DigestIdentifier::from_str(&subject_id).unwrap())
.await
.unwrap_or_else(|_| panic!("Error getting subject"));
println!("Subject ID: {}", subject.subject_id.to_str());
node.shutdown_gracefully().await;
}
Re-exports§
pub use error::Error;
Modules§
- crypto
- This module provides the structs and traits for the generation of key pairs for cryptographic operations.
- error
- Possible errors of a TAPLE Node
- identifier
- Identifiers module
- message
- request
- Contains all valid event requests
- signature
- Define the data structures related to signatures
Macros§
- test_
database_ manager_ trait - Allows a TAPLE database implementation to be subjected to a battery of tests. The use must specify both a valid implementation of DatabaseManager and DatabaseCollection
Structs§
- Api
- Object that allows interaction with a TAPLE node.
- Approval
Entity - A struct representing an approval entity.
- Approval
Request - A struct representing an approval request.
- Approval
Response - A struct representing an approval response.
- Digest
Identifier - Digest based identifier
- Evaluation
Request - A struct representing an evaluation request.
- Evaluation
Response - A struct representing an evaluation response.
- Event
- A struct representing an event.
- KeyIdentifier
- Key based identifier
- Memory
Collection - Collection for in-memory database implementation. It must be created through MemoryManager.
- Memory
Manager - In-memory database implementation for TAPLE.
- Metadata
- A struct representing the metadata of a TAPLE event.
- Network
Settings - P2P network configuration parameters of a TAPLE node.
- Node
- Structure representing a TAPLE node
- Node
Settings - General settings of a TAPLE node.
- Settings
- Configuration parameters of a TAPLE node divided into categories.
- Signature
Identifier - Signature based identifier
- Subject
Data - A struct representing the data associated with a TAPLE subject.
- Time
Stamp - A struct representing a timestamp.
- Validation
Proof - A struct representing a validation proof.
- Value
Wrapper - Wrapper of serde_json::Value implementing serialization and deserialization with Borsh.
Enums§
- ApiError
- Errors that may occur when using the TAPLE API
- Approval
State - An enum representing the state of an approval entity.
- DbError
- Errors that can be generated by Taple database implementations
- Digest
Derivator - Enumeration with digest derivator types
- Event
Request - An enum representing a TAPLE event request.
- KeyDerivator
- An enumeration of key derivator types.
- Listen
Addr - Represents a valid listening address for TAPLE. Internally, they are constituted as a MultiAddr.
- Listen
Addr Errors - Errors that can occur during the generation of a [ListenAddr].
- Notification
- Notifications generated by [NotificationHandler]. These notifications identify the type of message and its content. In addition, the message is accompanied by the data used to construct the message, so that it can be used to construct customized messages.
Traits§
- Database
Collection - A trait representing a collection of key-value pairs in a database.
- Database
Manager - Trait to define a database compatible with Taple
- Derivable
- Derivable Identifiers