Factom API Client
Asynchronous rust client for the Factom API.
Installation
Add to cargo.toml:
[]
= "1.0.1"
Quickstart
use *;
let api = new;
let response = fetch.expect;
dbg!;
/*
Response {
jsonrpc: "2.0",
id: 0,
result: result(
Object(
{
"factomdapiversion": String(
"2.0"
),
"factomdversion": String(
"6.1.0"
)
}
)
)
}
*/
Usage
use *;
Simple synchronous call from remote host
let api = from_host;
let height_query = api.heights;
let response = fetch.unwrap;
dbg!
Synchronous call using Tokio block_on
// Create Tokio runtime
let mut runtime = new.expect;
let api = new;
let entryhash = "6ecd7c6c40d0e9dbb52457343e083d4306c5b4cd2d6e623ba67cf9d18b39faa7";
let entry_query = api.entry;
// block_on waits for future to return result
let response = runtime.block_on.unwrap;
dbg!;
// Shutdown runtime once idle
shutdown;
Asynchronous requests using futures
let mut runtime = new.unwrap;
let api = new;
// Closure to parse heights response
let height_handler = ;
// Main heights request
let heights_query = api.heights
// Handle successful execution of future
.map
// Print FetchError info if it occurs
.map_err;
// Closure to print entry content
let entry_handler = ;
// Main entry request
let entryhash = "6ecd7c6c40d0e9dbb52457343e083d4306c5b4cd2d6e623ba67cf9d18b39faa7";
let entry_query = api.entry
.map
.map_err;
// Spawn queries into current runtime
runtime.spawn;
runtime.spawn;
shutdown;
Passing messages between async tasks
use oneshot;
let mut runtime = new.unwrap;
let api = from_host;
// Oneshot used for passing single values, use mpsc to pass streams.
let = ;
// Heights query transmits the response data
let heights = api.heights
.map
.map_err;
// Spawn into current runtime
runtime.spawn;
// Reciever prints out response
runtime.spawn;
shutdown;
Testing
Setup test environment first, if factomd/walletd are not run locally modify the HOST variable in tests/mod.rs, see the readme for more information.