algosdk/
lib.rs

1use serde::{Deserialize, Serialize};
2
3pub mod account;
4/// Algorand protocol daemon
5pub mod algod;
6pub mod auction;
7pub mod crypto;
8/// Key management daemon
9pub mod kmd;
10/// Support for turning 32 byte keys into human-readable mnemonics and back
11pub mod mnemonic;
12pub mod transaction;
13pub(crate) mod util;
14
15pub const MICRO_ALGO_CONVERSION_FACTOR: f64 = 1e6;
16
17pub use algod::AlgodClient;
18pub use crypto::Address;
19pub use kmd::KmdClient;
20/// MicroAlgos are the base unit of currency in Algorand
21#[derive(Copy, Clone, Default, Debug, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)]
22pub struct MicroAlgos(pub u64);
23/// Round of the Algorand consensus protocol
24#[derive(Copy, Clone, Default, Eq, PartialEq, Debug, Serialize, Deserialize)]
25pub struct Round(pub u64);
26/// A SHA512_256 hash
27#[derive(Copy, Clone, Eq, PartialEq, Debug)]
28pub struct HashDigest(pub [u8; 32]);
29/// Participation public key used in key registration transactions
30#[derive(Copy, Clone, Eq, PartialEq, Debug)]
31pub struct VotePK(pub [u8; 32]);
32/// VRF public key used in key registration transaction
33#[derive(Copy, Clone, Eq, PartialEq, Debug)]
34pub struct VRFPK(pub [u8; 32]);
35#[derive(Copy, Clone, Debug, Eq, PartialEq)]
36pub struct Ed25519PublicKey(pub [u8; 32]);
37#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
38pub struct MasterDerivationKey(pub [u8; 32]);
39
40impl MicroAlgos {
41    pub fn to_algos(self) -> f64 {
42        self.0 as f64 / MICRO_ALGO_CONVERSION_FACTOR
43    }
44
45    pub fn from_algos(algos: f64) -> MicroAlgos {
46        MicroAlgos((algos * MICRO_ALGO_CONVERSION_FACTOR) as u64)
47    }
48}
49
50#[derive(Debug)]
51pub enum Error {
52    Reqwest(reqwest::Error),
53    Encode(rmp_serde::encode::Error),
54    Json(serde_json::Error),
55    Api(String),
56}