#[macro_use]
mod logging;
pub mod error;
mod ops;
pub use error::AlgoError;
pub use ops::{
AlgoChainConfig, AlgoOps, AlgoSuggestedParams, AppArg, ConfirmedTxn, KeyProvider,
TransactionGroupBuilder, address_to_byte_key, byte_key_to_address,
};
use anyhow::Result;
use blockchain_ops::{AssetOps, BlockChainOps};
pub use blockchain_ops::TransactionQueryOps;
const MICRO_PER_ALGO: f64 = 1_000_000.0;
impl BlockChainOps for AlgoOps {
fn generate_keypair() -> (String, String) {
AlgoOps::generate_keypair()
}
fn create_address(&mut self) -> Result<String> {
AlgoOps::create_address(self)
}
fn address(&self) -> Result<String> {
AlgoOps::address_str(self)
}
fn public_key(&self) -> Result<[u8; 32]> {
AlgoOps::public_key_bytes(self)
}
fn private_key(&self) -> Result<Vec<u8>> {
AlgoOps::private_key_bytes(self)
}
fn sign(&self, text: &str) -> Result<String> {
AlgoOps::sign(self, text)
}
fn verify(&self, text: &str, sig_b64: &str) -> Result<bool> {
AlgoOps::verify(self, text, sig_b64)
}
fn send_payment(&self, to: &str, payment_amount: f64) -> Result<()> {
AlgoOps::send_algo(self, to, payment_amount)
}
fn account_balance(&self) -> Result<Option<f64>> {
AlgoOps::account_balance(self)
}
fn account_balance_at(&self, account: &str) -> Result<f64> {
Ok(AlgoOps::microalgos_at(self, account)? as f64 / MICRO_PER_ALGO)
}
fn wait_for_confirmation(&self, tx_id: &str, timeout: u64) -> Result<()> {
AlgoOps::wait_for_confirmation(self, tx_id, timeout)
}
}
impl AssetOps for AlgoOps {
fn send_asset(&self, asset_id: u64, amount: u64, to: &str) -> Result<()> {
AlgoOps::send_asset(self, asset_id, amount, to)
}
fn asset_holding(&self, account: &str, asset_id: u64) -> Result<u64> {
AlgoOps::asset_holding(self, account, asset_id)
}
}
impl TransactionQueryOps for AlgoOps {
fn confirmed_transaction(&self, tx_id: &str) -> Result<Option<ConfirmedTxn>> {
AlgoOps::confirmed_transaction(self, tx_id)
}
fn find_transaction_by_note(&self, note: &[u8]) -> Result<Option<ConfirmedTxn>> {
AlgoOps::find_transaction_by_note(self, note)
}
fn find_transaction_by_note_prefix(&self, prefix: &[u8]) -> Result<Option<ConfirmedTxn>> {
AlgoOps::find_transaction_by_note_prefix(self, prefix)
}
fn find_transactions_by_note_prefix(&self, prefix: &[u8]) -> Result<Vec<ConfirmedTxn>> {
AlgoOps::find_transactions_by_note_prefix(self, prefix)
}
fn find_transaction_by_note_and_sender(
&self,
note: &[u8],
sender: &str,
) -> Result<Option<ConfirmedTxn>> {
AlgoOps::find_transaction_by_note_and_sender(self, note, sender)
}
fn find_transaction_by_note_prefix_and_sender(
&self,
prefix: &[u8],
sender: &str,
) -> Result<Option<ConfirmedTxn>> {
AlgoOps::find_transaction_by_note_prefix_and_sender(self, prefix, sender)
}
fn find_transactions_by_note_prefix_and_sender(
&self,
prefix: &[u8],
sender: &str,
) -> Result<Vec<ConfirmedTxn>> {
AlgoOps::find_transactions_by_note_prefix_and_sender(self, prefix, sender)
}
}
impl AlgoOps {
pub fn new_for_algorand(
passphrase: Option<String>,
address: Option<String>,
config: Option<AlgoChainConfig>,
) -> Self {
AlgoOps::new(passphrase, address, config)
}
}