From ad9498a7e7d3c78dc20a025bdb4c86ffd60f38e6 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Mon, 14 Jun 2021 11:33:44 +0200 Subject: [PATCH 1/6] Rename functions --- algonaut_client/tests/test_trasactions.rs | 10 ++++---- algonaut_transaction/src/account.rs | 31 +++++++++++++---------- algonaut_transaction/src/transaction.rs | 2 +- examples/sign_offline.rs | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/algonaut_client/tests/test_trasactions.rs b/algonaut_client/tests/test_trasactions.rs index dd5fd969..8dd73ad8 100644 --- a/algonaut_client/tests/test_trasactions.rs +++ b/algonaut_client/tests/test_trasactions.rs @@ -42,7 +42,7 @@ async fn test_transaction() -> Result<(), Box> { ) .build(); - let sign_response = from.sign_and_generate_signed_transaction(&t); + let sign_response = from.sign_transaction(&t); println!("{:#?}", sign_response); assert!(sign_response.is_ok()); let sign_response = sign_response.unwrap(); @@ -219,7 +219,7 @@ int 1 ) .build(); - let signature = from.sign_program(&program); + let signature = from.generate_program_sig(&program); let signed_transaction = SignedTransaction { transaction: t, @@ -341,7 +341,7 @@ async fn test_create_asset_transaction() -> Result<(), Box> { .build(), ) .build(); - let signed_t = from.sign_and_generate_signed_transaction(&t)?; + let signed_t = from.sign_transaction(&t)?; let send_response = algod .broadcast_raw_transaction(&signed_t.to_msg_pack()?) .await; @@ -462,8 +462,8 @@ async fn test_atomic_swap() -> Result<(), Box> { TxGroup::assign_group_id(vec![t1, t2])?; - let signed_t1 = account1.sign_and_generate_signed_transaction(&t1)?; - let signed_t2 = account2.sign_and_generate_signed_transaction(&t2)?; + let signed_t1 = account1.sign_transaction(&t1)?; + let signed_t2 = account2.sign_transaction(&t2)?; let send_response = algod .broadcast_raw_transaction(&[signed_t1.to_msg_pack()?, signed_t2.to_msg_pack()?].concat()) diff --git a/algonaut_transaction/src/account.rs b/algonaut_transaction/src/account.rs index 8f6e1ba1..42192948 100644 --- a/algonaut_transaction/src/account.rs +++ b/algonaut_transaction/src/account.rs @@ -56,7 +56,7 @@ impl Account { self.seed } - fn sign(&self, bytes: &[u8]) -> Signature { + fn generate_sig(&self, bytes: &[u8]) -> Signature { let signature = self.key_pair.sign(&bytes); // ring returns a signature with padding at the end to make it 105 bytes, only 64 bytes are actually used let mut stripped_signature = [0; 64]; @@ -64,20 +64,23 @@ impl Account { Signature(stripped_signature) } - pub fn sign_program(&self, program: &CompiledTeal) -> Signature { - self.sign(&["Program".as_bytes(), &program.bytes].concat()) + pub fn generate_program_sig(&self, program: &CompiledTeal) -> Signature { + self.generate_sig(&["Program".as_bytes(), &program.bytes].concat()) } - fn sign_transaction(&self, transaction: &Transaction) -> Result { - Ok(self.sign(&transaction.bytes_to_sign()?)) + fn generate_transaction_sig( + &self, + transaction: &Transaction, + ) -> Result { + Ok(self.generate_sig(&transaction.bytes_to_sign()?)) } /// Sign a bid with the account's private key - pub fn sign_and_generate_signed_bid(&self, bid: Bid) -> Result { + pub fn sign_bid(&self, bid: Bid) -> Result { let encoded_bid = bid.to_msg_pack()?; let mut prefix_encoded_bid = b"aB".to_vec(); prefix_encoded_bid.extend_from_slice(&encoded_bid); - let signature = self.sign(&prefix_encoded_bid); + let signature = self.generate_sig(&prefix_encoded_bid); Ok(SignedBid { bid, sig: signature, @@ -85,19 +88,19 @@ impl Account { } /// Sign transaction and generate a single signature SignedTransaction - pub fn sign_and_generate_signed_transaction( + pub fn sign_transaction( &self, transaction: &Transaction, ) -> Result { Ok(SignedTransaction { transaction: transaction.clone(), transaction_id: transaction.id()?, - sig: TransactionSignature::Single(self.sign_transaction(&transaction)?), + sig: TransactionSignature::Single(self.generate_transaction_sig(&transaction)?), }) } /// Sign transaction and generate a multi signature SignedTransaction - pub fn sign_and_generate_multisig_transaction( + pub fn sign_multisig_transaction( &self, from: MultisigAddress, transaction: &Transaction, @@ -122,7 +125,7 @@ impl Account { return Err(ApiError::InvalidSecretKeyInMultisig.into()); } - Ok(self.init_msig(from, self.sign_transaction(&transaction)?)) + Ok(self.init_msig(from, self.generate_transaction_sig(&transaction)?)) } /// Creates logic multi signature corresponding to multisign addresses, inserting own signature @@ -135,7 +138,7 @@ impl Account { return Err(ApiError::InvalidSecretKeyInMultisig.into()); } - Ok(self.init_msig(ma, self.sign_program(program))) + Ok(self.init_msig(ma, self.generate_program_sig(program))) } pub fn append_to_logic_msig( @@ -143,7 +146,7 @@ impl Account { program: &CompiledTeal, msig: MultisigSignature, ) -> Result { - self.append_sig_to_msig(self.sign_program(program), msig) + self.append_sig_to_msig(self.generate_program_sig(program), msig) } pub fn append_to_transaction_msig( @@ -151,7 +154,7 @@ impl Account { transaction: &Transaction, msig: MultisigSignature, ) -> Result { - self.append_sig_to_msig(self.sign_transaction(transaction)?, msig) + self.append_sig_to_msig(self.generate_transaction_sig(transaction)?, msig) } /// Creates multi signature corresponding to multisign addresses, inserting own signature diff --git a/algonaut_transaction/src/transaction.rs b/algonaut_transaction/src/transaction.rs index 11ad1f46..5c067e59 100644 --- a/algonaut_transaction/src/transaction.rs +++ b/algonaut_transaction/src/transaction.rs @@ -108,7 +108,7 @@ impl Transaction { // Estimates the size of the encoded transaction, used in calculating the fee fn estimate_size(&self) -> Result { let account = Account::generate(); - let signed_transaction = account.sign_and_generate_signed_transaction(self)?; + let signed_transaction = account.sign_transaction(self)?; Ok(signed_transaction.to_msg_pack()?.len() as u64) } } diff --git a/examples/sign_offline.rs b/examples/sign_offline.rs index b8491b94..74f9eeda 100644 --- a/examples/sign_offline.rs +++ b/examples/sign_offline.rs @@ -50,7 +50,7 @@ async fn main() -> Result<(), Box> { println!("Made unsigned transaction: {:?}", t); // sign the transaction - let signed_transaction = account.sign_and_generate_signed_transaction(&t)?; + let signed_transaction = account.sign_transaction(&t)?; let bytes = rmp_serde::to_vec_named(&ApiSignedTransaction::from(signed_transaction))?; let filename = "./signed.tx"; From e4852641cf8a6fd2d76754a56b1a8bf0edd7aeec Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Mon, 14 Jun 2021 12:33:44 +0200 Subject: [PATCH 2/6] Hide api models, remove nested exports --- algonaut_core/src/lib.rs | 40 ---------------- .../src/{api_transaction.rs => api_models.rs} | 46 +++++++++++++++++-- algonaut_transaction/src/lib.rs | 3 +- examples/algod_client.rs | 2 +- examples/kmd_client.rs | 2 +- examples/new_asa_sandnet.rs | 2 +- examples/quickstart.rs | 4 +- examples/sign_offline.rs | 7 ++- examples/sign_submit_transaction.rs | 2 +- examples/sign_submit_transaction_sandnet.rs | 2 +- examples/submit_file.rs | 3 +- examples/wallet_backup.rs | 3 +- examples/wallet_restore.rs | 2 +- src/lib.rs | 3 -- 14 files changed, 59 insertions(+), 62 deletions(-) rename algonaut_transaction/src/{api_transaction.rs => api_models.rs} (90%) diff --git a/algonaut_core/src/lib.rs b/algonaut_core/src/lib.rs index 00b35f5b..deaa9b9f 100644 --- a/algonaut_core/src/lib.rs +++ b/algonaut_core/src/lib.rs @@ -380,46 +380,6 @@ pub enum LogicSignature { DelegatedMultiSig(MultisigSignature), } -#[derive(Debug)] -pub struct ApiSignedLogic { - pub logic: Vec, - pub sig: Option, - pub msig: Option, - pub args: Vec>, -} - -impl From for ApiSignedLogic { - fn from(s: SignedLogic) -> Self { - let (sig, msig) = match s.sig { - LogicSignature::ContractAccount => (None, None), - LogicSignature::DelegatedSig(sig) => (Some(sig), None), - LogicSignature::DelegatedMultiSig(msig) => (None, Some(msig)), - }; - ApiSignedLogic { - logic: s.logic.bytes, - sig, - msig, - args: s.args, - } - } -} - -impl Serialize for ApiSignedLogic { - fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> - where - S: Serializer, - { - // For some reason SerializeStruct ends up serializing as an array, so this explicitly serializes as a map - use serde::ser::SerializeMap; - let mut state = serializer.serialize_map(Some(4))?; - state.serialize_entry("l", &self.logic)?; - state.serialize_entry("arg", &self.args)?; - state.serialize_entry("sig", &self.sig)?; - state.serialize_entry("msig", &self.msig)?; - state.end() - } -} - pub trait ToMsgPack: Serialize { fn to_msg_pack(&self) -> Result, rmp_serde::encode::Error> { rmp_serde::to_vec_named(&self) diff --git a/algonaut_transaction/src/api_transaction.rs b/algonaut_transaction/src/api_models.rs similarity index 90% rename from algonaut_transaction/src/api_transaction.rs rename to algonaut_transaction/src/api_models.rs index d50d84f8..0cddb5df 100644 --- a/algonaut_transaction/src/api_transaction.rs +++ b/algonaut_transaction/src/api_models.rs @@ -1,9 +1,9 @@ use algonaut_core::{ - Address, ApiSignedLogic, MicroAlgos, MultisigSignature, Round, Signature, ToMsgPack, VotePk, - VrfPk, + Address, LogicSignature, MicroAlgos, MultisigSignature, Round, Signature, SignedLogic, + ToMsgPack, VotePk, VrfPk, }; use algonaut_crypto::HashDigest; -use serde::Serialize; +use serde::{Serialize, Serializer}; use crate::{ transaction::{StateSchema, TransactionSignature}, @@ -389,3 +389,43 @@ impl Serialize for SignedTransaction { api_transaction.serialize(serializer) } } + +#[derive(Debug)] +pub struct ApiSignedLogic { + pub logic: Vec, + pub sig: Option, + pub msig: Option, + pub args: Vec>, +} + +impl From for ApiSignedLogic { + fn from(s: SignedLogic) -> Self { + let (sig, msig) = match s.sig { + LogicSignature::ContractAccount => (None, None), + LogicSignature::DelegatedSig(sig) => (Some(sig), None), + LogicSignature::DelegatedMultiSig(msig) => (None, Some(msig)), + }; + ApiSignedLogic { + logic: s.logic.bytes, + sig, + msig, + args: s.args, + } + } +} + +impl Serialize for ApiSignedLogic { + fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> + where + S: Serializer, + { + // For some reason SerializeStruct ends up serializing as an array, so this explicitly serializes as a map + use serde::ser::SerializeMap; + let mut state = serializer.serialize_map(Some(4))?; + state.serialize_entry("l", &self.logic)?; + state.serialize_entry("arg", &self.args)?; + state.serialize_entry("sig", &self.sig)?; + state.serialize_entry("msig", &self.msig)?; + state.end() + } +} diff --git a/algonaut_transaction/src/lib.rs b/algonaut_transaction/src/lib.rs index b96d47d2..d213662d 100644 --- a/algonaut_transaction/src/lib.rs +++ b/algonaut_transaction/src/lib.rs @@ -1,12 +1,11 @@ pub mod account; -pub mod api_transaction; +mod api_models; pub mod auction; pub mod builder; pub mod error; pub mod transaction; pub mod tx_group; -pub use api_transaction::ApiSignedTransaction; pub use builder::{ AcceptAsset, CallApplication, ClawbackAsset, ConfigureAsset, FreezeAsset, Pay, RegisterKey, TransferAsset, Txn, diff --git a/examples/algod_client.rs b/examples/algod_client.rs index 9a4d1343..e50793ad 100644 --- a/examples/algod_client.rs +++ b/examples/algod_client.rs @@ -1,5 +1,5 @@ use algonaut::core::Round; -use algonaut::Algod; +use algonaut_client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/kmd_client.rs b/examples/kmd_client.rs index f993555a..056ecebd 100644 --- a/examples/kmd_client.rs +++ b/examples/kmd_client.rs @@ -1,5 +1,5 @@ use algonaut::crypto::MasterDerivationKey; -use algonaut::Kmd; +use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/new_asa_sandnet.rs b/examples/new_asa_sandnet.rs index 7e957d4d..5cd8290a 100644 --- a/examples/new_asa_sandnet.rs +++ b/examples/new_asa_sandnet.rs @@ -1,6 +1,6 @@ use algonaut::core::MicroAlgos; use algonaut::transaction::{ConfigureAsset, Txn}; -use algonaut::{Algod, Kmd}; +use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/quickstart.rs b/examples/quickstart.rs index bc11e340..adb15237 100644 --- a/examples/quickstart.rs +++ b/examples/quickstart.rs @@ -1,4 +1,6 @@ -use algonaut::{Algod, Indexer, Kmd}; +use algonaut_client::Algod; +use algonaut_client::Indexer; +use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/sign_offline.rs b/examples/sign_offline.rs index 74f9eeda..d99f1f47 100644 --- a/examples/sign_offline.rs +++ b/examples/sign_offline.rs @@ -1,9 +1,8 @@ -use algonaut::core::MicroAlgos; +use algonaut::core::{MicroAlgos, ToMsgPack}; use algonaut::crypto::mnemonic; use algonaut::transaction::account::Account; use algonaut::transaction::{Pay, Txn}; -use algonaut::Algod; -use algonaut_transaction::ApiSignedTransaction; +use algonaut_client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; @@ -51,7 +50,7 @@ async fn main() -> Result<(), Box> { // sign the transaction let signed_transaction = account.sign_transaction(&t)?; - let bytes = rmp_serde::to_vec_named(&ApiSignedTransaction::from(signed_transaction))?; + let bytes = signed_transaction.to_msg_pack()?; let filename = "./signed.tx"; let mut f = File::create(filename)?; diff --git a/examples/sign_submit_transaction.rs b/examples/sign_submit_transaction.rs index 66325e8c..1e439e80 100644 --- a/examples/sign_submit_transaction.rs +++ b/examples/sign_submit_transaction.rs @@ -1,6 +1,6 @@ use algonaut::core::MicroAlgos; use algonaut::transaction::{Pay, Txn}; -use algonaut::{Algod, Kmd}; +use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/sign_submit_transaction_sandnet.rs b/examples/sign_submit_transaction_sandnet.rs index 774cb20d..dda88b77 100644 --- a/examples/sign_submit_transaction_sandnet.rs +++ b/examples/sign_submit_transaction_sandnet.rs @@ -1,6 +1,6 @@ use algonaut::core::MicroAlgos; use algonaut::transaction::{Pay, Txn}; -use algonaut::{Algod, Kmd}; +use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/submit_file.rs b/examples/submit_file.rs index 55a5c6ab..3f9054f3 100644 --- a/examples/submit_file.rs +++ b/examples/submit_file.rs @@ -1,11 +1,10 @@ +use algonaut_client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; use std::fs::File; use std::io::Read; -use algonaut::Algod; - #[tokio::main] async fn main() -> Result<(), Box> { // load variables in .env diff --git a/examples/wallet_backup.rs b/examples/wallet_backup.rs index c6a5e7ac..4d76f873 100644 --- a/examples/wallet_backup.rs +++ b/examples/wallet_backup.rs @@ -1,4 +1,5 @@ -use algonaut::{crypto::mnemonic, Kmd}; +use algonaut::crypto::mnemonic; +use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/wallet_restore.rs b/examples/wallet_restore.rs index b71c43a8..0919323e 100644 --- a/examples/wallet_restore.rs +++ b/examples/wallet_restore.rs @@ -1,6 +1,6 @@ use algonaut::crypto::mnemonic; use algonaut::crypto::MasterDerivationKey; -use algonaut::Kmd; +use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/src/lib.rs b/src/lib.rs index 5201b539..b1b0b6a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,9 +17,6 @@ // Re-exports pub use algonaut_client as client; -pub use algonaut_client::algod::Algod; -pub use algonaut_client::indexer::Indexer; -pub use algonaut_client::kmd::Kmd; pub use algonaut_core as core; pub use algonaut_crypto as crypto; pub use algonaut_transaction as transaction; From 03364024a8e220f1eef3b6e57383e2cc64a86e67 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Wed, 16 Jun 2021 14:33:28 +0200 Subject: [PATCH 3/6] Use root project path --- algonaut_client/src/algod/mod.rs | 2 +- algonaut_client/src/kmd/mod.rs | 2 +- examples/algod_client.rs | 2 +- examples/kmd_client.rs | 2 +- examples/new_asa_sandnet.rs | 2 +- examples/query_indexer.rs | 4 ++-- examples/quickstart.rs | 6 +++--- examples/sign_offline.rs | 2 +- examples/sign_submit_transaction.rs | 2 +- examples/sign_submit_transaction_sandnet.rs | 2 +- examples/submit_file.rs | 2 +- examples/wallet_backup.rs | 2 +- examples/wallet_restore.rs | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/algonaut_client/src/algod/mod.rs b/algonaut_client/src/algod/mod.rs index 20a418ae..aa088035 100644 --- a/algonaut_client/src/algod/mod.rs +++ b/algonaut_client/src/algod/mod.rs @@ -8,7 +8,7 @@ pub mod v2; /// Algod is the entry point to the creation of a client for the Algorand protocol daemon. /// ``` -/// use algonaut_client::Algod; +/// use algonaut::client::Algod; /// /// fn main() -> Result<(), Box> { /// let algod = Algod::new() diff --git a/algonaut_client/src/kmd/mod.rs b/algonaut_client/src/kmd/mod.rs index 804b22a3..65903ed1 100644 --- a/algonaut_client/src/kmd/mod.rs +++ b/algonaut_client/src/kmd/mod.rs @@ -6,7 +6,7 @@ pub mod v1; /// Kmd is the entry point to the creation of a client for the Algorand key management daemon. /// ``` -/// use algonaut_client::Kmd; +/// use algonaut::client::Kmd; /// /// fn main() -> Result<(), Box> { /// let algod = Kmd::new() diff --git a/examples/algod_client.rs b/examples/algod_client.rs index e50793ad..735b0c84 100644 --- a/examples/algod_client.rs +++ b/examples/algod_client.rs @@ -1,5 +1,5 @@ +use algonaut::client::Algod; use algonaut::core::Round; -use algonaut_client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/kmd_client.rs b/examples/kmd_client.rs index 056ecebd..fa7060f4 100644 --- a/examples/kmd_client.rs +++ b/examples/kmd_client.rs @@ -1,5 +1,5 @@ +use algonaut::client::Kmd; use algonaut::crypto::MasterDerivationKey; -use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/new_asa_sandnet.rs b/examples/new_asa_sandnet.rs index 5cd8290a..1a084d3e 100644 --- a/examples/new_asa_sandnet.rs +++ b/examples/new_asa_sandnet.rs @@ -1,6 +1,6 @@ +use algonaut::client::{Algod, Kmd}; use algonaut::core::MicroAlgos; use algonaut::transaction::{ConfigureAsset, Txn}; -use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/query_indexer.rs b/examples/query_indexer.rs index 3401288d..e1e1e13a 100644 --- a/examples/query_indexer.rs +++ b/examples/query_indexer.rs @@ -1,5 +1,5 @@ -use algonaut_client::indexer::v2::message::QueryAccount; -use algonaut_client::Indexer; +use algonaut::client::indexer::v2::message::QueryAccount; +use algonaut::client::Indexer; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/quickstart.rs b/examples/quickstart.rs index adb15237..eb71cf88 100644 --- a/examples/quickstart.rs +++ b/examples/quickstart.rs @@ -1,6 +1,6 @@ -use algonaut_client::Algod; -use algonaut_client::Indexer; -use algonaut_client::Kmd; +use algonaut::client::Algod; +use algonaut::client::Indexer; +use algonaut::client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/sign_offline.rs b/examples/sign_offline.rs index d99f1f47..71bbb601 100644 --- a/examples/sign_offline.rs +++ b/examples/sign_offline.rs @@ -1,8 +1,8 @@ +use algonaut::client::Algod; use algonaut::core::{MicroAlgos, ToMsgPack}; use algonaut::crypto::mnemonic; use algonaut::transaction::account::Account; use algonaut::transaction::{Pay, Txn}; -use algonaut_client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/sign_submit_transaction.rs b/examples/sign_submit_transaction.rs index 1e439e80..f8110ec4 100644 --- a/examples/sign_submit_transaction.rs +++ b/examples/sign_submit_transaction.rs @@ -1,6 +1,6 @@ +use algonaut::client::{Algod, Kmd}; use algonaut::core::MicroAlgos; use algonaut::transaction::{Pay, Txn}; -use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/sign_submit_transaction_sandnet.rs b/examples/sign_submit_transaction_sandnet.rs index dda88b77..79b4c847 100644 --- a/examples/sign_submit_transaction_sandnet.rs +++ b/examples/sign_submit_transaction_sandnet.rs @@ -1,6 +1,6 @@ +use algonaut::client::{Algod, Kmd}; use algonaut::core::MicroAlgos; use algonaut::transaction::{Pay, Txn}; -use algonaut_client::{Algod, Kmd}; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/submit_file.rs b/examples/submit_file.rs index 3f9054f3..50686a46 100644 --- a/examples/submit_file.rs +++ b/examples/submit_file.rs @@ -1,4 +1,4 @@ -use algonaut_client::Algod; +use algonaut::client::Algod; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/wallet_backup.rs b/examples/wallet_backup.rs index 4d76f873..1b9589c1 100644 --- a/examples/wallet_backup.rs +++ b/examples/wallet_backup.rs @@ -1,5 +1,5 @@ +use algonaut::client::Kmd; use algonaut::crypto::mnemonic; -use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; diff --git a/examples/wallet_restore.rs b/examples/wallet_restore.rs index 0919323e..8795f905 100644 --- a/examples/wallet_restore.rs +++ b/examples/wallet_restore.rs @@ -1,6 +1,6 @@ +use algonaut::client::Kmd; use algonaut::crypto::mnemonic; use algonaut::crypto::MasterDerivationKey; -use algonaut_client::Kmd; use dotenv::dotenv; use std::env; use std::error::Error; From 6e1e4a5d75d27dcea07dedac8aaf38a9c7a3d666 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Thu, 17 Jun 2021 15:51:05 +0200 Subject: [PATCH 4/6] Add transitionary domain layer to clients For now uses api objects, will decouple gradually / on demand --- Cargo.toml | 2 + algonaut_client/src/algod/mod.rs | 115 --------- algonaut_client/src/algod/v1/mod.rs | 42 ++-- algonaut_client/src/algod/v2/mod.rs | 79 ++---- algonaut_client/src/indexer/v2/mod.rs | 9 + algonaut_client/src/kmd/v1/mod.rs | 31 +-- algonaut_client/src/lib.rs | 5 - examples/algod_client.rs | 6 +- examples/kmd_client.rs | 6 +- examples/new_asa_sandnet.rs | 11 +- examples/query_indexer.rs | 8 +- examples/quickstart.rs | 18 +- examples/sign_offline.rs | 6 +- examples/sign_submit_transaction.rs | 11 +- examples/sign_submit_transaction_sandnet.rs | 11 +- examples/submit_file.rs | 6 +- examples/wallet_backup.rs | 6 +- examples/wallet_restore.rs | 6 +- src/algod/mod.rs | 109 ++++++++ src/algod/v1/mod.rs | 122 +++++++++ src/algod/v2/mod.rs | 196 +++++++++++++++ src/indexer/mod.rs | 56 +++++ src/indexer/v2/mod.rs | 120 +++++++++ src/kmd/mod.rs | 97 +++++++ src/kmd/v1/mod.rs | 238 ++++++++++++++++++ src/lib.rs | 5 +- .../tests => tests}/test_algod_v1.rs | 30 +-- .../tests => tests}/test_algod_v2.rs | 90 +++---- .../tests => tests}/test_indexer_v2.rs | 54 ++-- .../tests => tests}/test_kmd_v1.rs | 66 ++--- .../tests => tests}/test_trasactions.rs | 42 ++-- 31 files changed, 1174 insertions(+), 429 deletions(-) create mode 100644 src/algod/mod.rs create mode 100644 src/algod/v1/mod.rs create mode 100644 src/algod/v2/mod.rs create mode 100644 src/indexer/mod.rs create mode 100644 src/indexer/v2/mod.rs create mode 100644 src/kmd/mod.rs create mode 100644 src/kmd/v1/mod.rs rename {algonaut_client/tests => tests}/test_algod_v1.rs (84%) rename {algonaut_client/tests => tests}/test_algod_v2.rs (87%) rename {algonaut_client/tests => tests}/test_indexer_v2.rs (89%) rename {algonaut_client/tests => tests}/test_kmd_v1.rs (94%) rename {algonaut_client/tests => tests}/test_trasactions.rs (95%) diff --git a/Cargo.toml b/Cargo.toml index 2e1f89cf..0d4e4e15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,5 @@ dirs = "2.0" dotenv = "0.15.0" rmp-serde = "0.14.0" tokio = { version = "1.6.0", features = ["rt-multi-thread", "macros"] } +rand = "0.8.3" +getrandom = { version = "0.2.2", features = ["js"] } diff --git a/algonaut_client/src/algod/mod.rs b/algonaut_client/src/algod/mod.rs index aa088035..ae6adc7c 100644 --- a/algonaut_client/src/algod/mod.rs +++ b/algonaut_client/src/algod/mod.rs @@ -1,117 +1,2 @@ -use super::token::ApiToken; -use crate::error::{AlgorandError, BuilderError}; -use reqwest::header::HeaderMap; -use url::Url; - pub mod v1; pub mod v2; - -/// Algod is the entry point to the creation of a client for the Algorand protocol daemon. -/// ``` -/// use algonaut::client::Algod; -/// -/// fn main() -> Result<(), Box> { -/// let algod = Algod::new() -/// .bind("http://localhost:4001") -/// .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") -/// .client_v1()?; -/// -/// println!("Algod versions: {:?}", algod.versions()?.versions); -/// -/// Ok(()) -/// } -/// ``` -pub struct Algod<'a> { - url: Option<&'a str>, - token: Option<&'a str>, - headers: HeaderMap, -} - -impl<'a> Algod<'a> { - /// Start the creation of a client. - pub fn new() -> Self { - Self::default() - } - - /// Bind to a URL. - pub fn bind(mut self, url: &'a str) -> Self { - self.url = Some(url); - self - } - - /// Use a token to authenticate. - pub fn auth(mut self, token: &'a str) -> Self { - self.token = Some(token); - self - } - - /// Build a v1 client for Algorand protocol daemon. - pub fn client_v1(self) -> Result { - match (self.url, self.token) { - (Some(url), Some(token)) => Ok(v1::Client { - url: Url::parse(url)?.as_ref().into(), - token: ApiToken::parse(token)?.to_string(), - headers: self.headers, - http_client: reqwest::Client::new(), - }), - (None, Some(_)) => Err(BuilderError::UnitializedUrl.into()), - (Some(_), None) => Err(BuilderError::UnitializedToken.into()), - (None, None) => Err(BuilderError::UnitializedUrl.into()), - } - } - - /// Build a v2 client for Algorand protocol daemon. - pub fn client_v2(self) -> Result { - match (self.url, self.token) { - (Some(url), Some(token)) => Ok(v2::Client { - url: Url::parse(url)?.as_ref().into(), - token: token.to_string(), - headers: self.headers, - http_client: reqwest::Client::new(), - }), - (None, Some(_)) => Err(BuilderError::UnitializedUrl.into()), - (Some(_), None) => Err(BuilderError::UnitializedToken.into()), - (None, None) => Err(BuilderError::UnitializedUrl.into()), - } - } -} - -impl<'a> Default for Algod<'a> { - fn default() -> Self { - Algod { - url: None, - token: None, - headers: HeaderMap::new(), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_valid_client_builder() { - let algod = Algod::new() - .bind("http://example.com") - .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - .client_v1(); - - assert!(algod.ok().is_some()); - } - - #[test] - #[should_panic(expected = "")] - fn test_client_builder_with_no_token() { - let _ = Algod::new().bind("http://example.com").client_v1().unwrap(); - } - - #[test] - #[should_panic(expected = "")] - fn test_client_builder_with_no_url() { - let _ = Algod::new() - .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - .client_v1() - .unwrap(); - } -} diff --git a/algonaut_client/src/algod/v1/mod.rs b/algonaut_client/src/algod/v1/mod.rs index 72e744b8..a1283041 100644 --- a/algonaut_client/src/algod/v1/mod.rs +++ b/algonaut_client/src/algod/v1/mod.rs @@ -1,11 +1,13 @@ use crate::error::AlgorandError; use crate::extensions::reqwest::ResponseExt; +use crate::token::ApiToken; use algonaut_core::Round; use message::{ Account, Block, NodeStatus, PendingTransactions, QueryAccountTransactions, Supply, Transaction, TransactionFee, TransactionId, TransactionList, TransactionParams, Version, }; use reqwest::header::HeaderMap; +use reqwest::Url; /// API message structs for Algorand's daemon v1 pub mod message; @@ -14,14 +16,22 @@ const AUTH_HEADER: &str = "X-Algo-API-Token"; /// Client for interacting with the Algorand protocol daemon. pub struct Client { - pub(super) url: String, - pub(super) token: String, - pub(super) headers: HeaderMap, - pub(super) http_client: reqwest::Client, + url: String, + token: String, + headers: HeaderMap, + http_client: reqwest::Client, } impl Client { - /// Returns Ok if healthy + pub fn new(url: &str, token: &str) -> Result { + Ok(Client { + url: Url::parse(url)?.as_ref().into(), + token: ApiToken::parse(token)?.to_string(), + headers: HeaderMap::new(), + http_client: reqwest::Client::new(), + }) + } + pub async fn health(&self) -> Result<(), AlgorandError> { let _ = self .http_client @@ -34,7 +44,6 @@ impl Client { Ok(()) } - /// Retrieves the current version pub async fn versions(&self) -> Result { let response = self .http_client @@ -50,7 +59,6 @@ impl Client { Ok(response) } - /// Gets the current node status pub async fn status(&self) -> Result { let response = self .http_client @@ -66,7 +74,6 @@ impl Client { Ok(response) } - /// Waits for a block to appear after the specified round and returns the node status at the time pub async fn status_after_block(&self, round: Round) -> Result { let response = self .http_client @@ -85,7 +92,6 @@ impl Client { Ok(response) } - /// Get the block for the given round pub async fn block(&self, round: Round) -> Result { let response = self .http_client @@ -101,7 +107,6 @@ impl Client { Ok(response) } - /// Gets the current supply reported by the ledger pub async fn ledger_supply(&self) -> Result { let response = self .http_client @@ -132,9 +137,6 @@ impl Client { Ok(response) } - /// Gets a list of unconfirmed transactions currently in the transaction pool - /// - /// Sorted by priority in decreasing order and truncated at the specified limit, or returns all if specified limit is 0 pub async fn pending_transactions( &self, limit: u64, @@ -154,14 +156,6 @@ impl Client { Ok(response) } - /// Get a specified pending transaction - /// - /// Given a transaction id of a recently submitted transaction, it returns information - /// about it. There are several cases when this might succeed: - transaction committed - /// (committed round > 0) - transaction still in the pool (committed round = 0, pool - /// error = "") - transaction removed from pool due to error (committed round = 0, pool - /// error != "") Or the transaction may have happened sufficiently long ago that the - /// node no longer remembers it, and this will return an error. pub async fn pending_transaction_information( &self, transaction_id: &str, @@ -183,7 +177,6 @@ impl Client { Ok(response) } - /// Get a list of confirmed transactions, limited to filters if specified pub async fn transactions( &self, address: &str, @@ -204,7 +197,6 @@ impl Client { Ok(response) } - /// Broadcasts a raw transaction to the network pub async fn raw_transaction(&self, raw: &[u8]) -> Result { let response = self .http_client @@ -222,7 +214,6 @@ impl Client { Ok(response) } - /// Gets the information of a single transaction pub async fn transaction(&self, transaction_id: &str) -> Result { let response = self .http_client @@ -238,7 +229,6 @@ impl Client { Ok(response) } - /// Gets a specific confirmed transaction pub async fn transaction_information( &self, address: &str, @@ -261,7 +251,6 @@ impl Client { Ok(response) } - /// Gets suggested fee in units of micro-Algos per byte pub async fn suggested_fee(&self) -> Result { let response = self .http_client @@ -277,7 +266,6 @@ impl Client { Ok(response) } - /// Gets parameters for constructing a new transaction pub async fn transaction_params(&self) -> Result { let response = self .http_client diff --git a/algonaut_client/src/algod/v2/mod.rs b/algonaut_client/src/algod/v2/mod.rs index e2e4a138..effee91b 100644 --- a/algonaut_client/src/algod/v2/mod.rs +++ b/algonaut_client/src/algod/v2/mod.rs @@ -1,8 +1,10 @@ use crate::error::AlgorandError; use crate::extensions::reqwest::ResponseExt; +use crate::token::ApiToken; use algonaut_core::Round; use message::*; use reqwest::header::HeaderMap; +use reqwest::Url; /// API message structs for Algorand's daemon v2 pub mod message; @@ -11,14 +13,22 @@ const AUTH_HEADER: &str = "X-Algo-API-Token"; /// Client for interacting with the Algorand protocol daemon pub struct Client { - pub(super) url: String, - pub(super) token: String, - pub(super) headers: HeaderMap, - pub(super) http_client: reqwest::Client, + url: String, + token: String, + headers: HeaderMap, + http_client: reqwest::Client, } impl Client { - /// Returns the entire genesis file in json. + pub fn new(url: &str, token: &str) -> Result { + Ok(Client { + url: Url::parse(url)?.as_ref().into(), + token: ApiToken::parse(token)?.to_string(), + headers: HeaderMap::new(), + http_client: reqwest::Client::new(), + }) + } + pub async fn genesis(&self) -> Result { let response = self .http_client @@ -34,7 +44,6 @@ impl Client { Ok(response) } - /// Returns Ok if healthy pub async fn health(&self) -> Result<(), AlgorandError> { let _ = self .http_client @@ -48,7 +57,6 @@ impl Client { Ok(()) } - /// Return metrics about algod functioning. pub async fn metrics(&self) -> Result { let response = self .http_client @@ -65,9 +73,6 @@ impl Client { Ok(response) } - /// Get account information. - /// Description Given a specific account public key, this call returns the accounts status, - /// balance and spendable amounts pub async fn account_information(&self, address: &str) -> Result { let response = self .http_client @@ -84,9 +89,6 @@ impl Client { Ok(response) } - /// Get a list of unconfirmed transactions currently in the transaction pool by address. - /// Description: Get the list of pending transactions by address, sorted by priority, - /// in decreasing order, truncated at the end at MAX. If MAX = 0, returns all pending transactions. pub async fn pending_transactions_for( &self, address: &str, @@ -110,10 +112,6 @@ impl Client { Ok(response) } - /// Get application information. - /// - /// Given a application id, it returns application information including creator, - /// approval and clear programs, global and local schemas, and global state. pub async fn application_information(&self, id: usize) -> Result { let response = self .http_client @@ -130,10 +128,6 @@ impl Client { Ok(response) } - /// Get asset information. - /// - /// Given a asset id, it returns asset information including creator, name, - /// total supply and special addresses. pub async fn asset_information(&self, id: usize) -> Result { let response = self .http_client @@ -150,7 +144,6 @@ impl Client { Ok(response) } - /// Get the block for the given round. pub async fn block(&self, round: Round) -> Result { let response = self .http_client @@ -167,7 +160,6 @@ impl Client { Ok(response) } - /// Starts a catchpoint catchup. pub async fn start_catchup(&self, catchpoint: &str) -> Result { let response = self .http_client @@ -184,7 +176,6 @@ impl Client { Ok(response) } - /// Aborts a catchpoint catchup. pub async fn abort_catchup(&self, catchpoint: &str) -> Result { let response = self .http_client @@ -201,7 +192,6 @@ impl Client { Ok(response) } - /// Get the current supply reported by the ledger. pub async fn ledger_supply(&self) -> Result { let response = self .http_client @@ -218,14 +208,6 @@ impl Client { Ok(response) } - /// Generate (or renew) and register participation keys on the node for a given account address. - /// - /// address: The account-id to update, or all to update all accounts. - /// fee: The fee to use when submitting key registration transactions. Defaults to the suggested - /// fee. (default = 1000) - /// key-dilution: value to use for two-level participation key. - /// no-wait: Don't wait for transaction to commit before returning response. - /// round-last-valid: The last round for which the generated participation keys will be valid. pub async fn register_participation_keys( &self, address: &str, @@ -250,8 +232,6 @@ impl Client { Ok(response) } - /// Special management endpoint to shutdown the node. Optionally provide a timeout parameter - /// to indicate that the node should begin shutting down after a number of seconds. pub async fn shutdown(&self, timeout: usize) -> Result<(), AlgorandError> { self.http_client .post(&format!("{}v2/shutdown", self.url)) @@ -268,7 +248,6 @@ impl Client { Ok(()) } - /// Gets the current node status. pub async fn status(&self) -> Result { let response = self .http_client @@ -285,7 +264,6 @@ impl Client { Ok(response) } - /// Gets the node status after waiting for the given round. pub async fn status_after_round(&self, round: Round) -> Result { let response = self .http_client @@ -305,11 +283,6 @@ impl Client { Ok(response) } - /// Compile TEAL source code to binary, produce its hash. - /// - /// Given TEAL source code in plain text, return base64 encoded program bytes and base32 - /// SHA512_256 hash of program bytes (Address style). This endpoint is only enabled when - /// a node's configuration file sets EnableDeveloperAPI to true. pub async fn compile_teal(&self, teal: String) -> Result { let response = self .http_client @@ -328,11 +301,6 @@ impl Client { Ok(response) } - /// Provide debugging information for a transaction (or group). - /// - /// Executes TEAL program(s) in context and returns debugging information about the execution. - /// This endpoint is only enabled when a node's configureation file sets EnableDeveloperAPI - /// to true. pub async fn dryrun_teal(&self, req: &DryrunRequest) -> Result { let response = self .http_client @@ -351,7 +319,6 @@ impl Client { Ok(response) } - /// Broadcasts a raw transaction to the network. pub async fn broadcast_raw_transaction( &self, rawtxn: &[u8], @@ -373,7 +340,6 @@ impl Client { Ok(response) } - /// Get parameters for constructing a new transaction. pub async fn transaction_params(&self) -> Result { let response = self .http_client @@ -390,10 +356,6 @@ impl Client { Ok(response) } - /// Get a list of unconfirmed transactions currently in the transaction pool. - /// - /// Get the list of pending transactions, sorted by priority, in decreasing order, - /// truncated at the end at MAX. If MAX = 0, returns all pending transactions. pub async fn pending_transactions( &self, max: u64, @@ -414,16 +376,6 @@ impl Client { Ok(response) } - /// Get a specific pending transaction. - /// - /// Given a transaction id of a recently submitted transaction, it returns information about - /// it. There are several cases when this might succeed: - /// - transaction committed (committed round > 0) - /// - transaction still in the pool (committed round = 0, pool error = "") - /// - transaction removed from pool due to error (committed round = 0, pool error != "") - /// - /// Or the transaction may have happened sufficiently long ago that the node no longer remembers - /// it, and this will return an error. pub async fn pending_transaction_with_id( &self, txid: &str, @@ -443,7 +395,6 @@ impl Client { Ok(response) } - /// Retrieves the current version pub async fn versions(&self) -> Result { let response = self .http_client diff --git a/algonaut_client/src/indexer/v2/mod.rs b/algonaut_client/src/indexer/v2/mod.rs index b777c422..5e602f9c 100644 --- a/algonaut_client/src/indexer/v2/mod.rs +++ b/algonaut_client/src/indexer/v2/mod.rs @@ -3,6 +3,7 @@ use crate::error::AlgorandError; use crate::extensions::reqwest::ResponseExt; use algonaut_core::Round; use reqwest::header::HeaderMap; +use reqwest::Url; /// API message structs for Algorand's indexer v2 pub mod message; @@ -15,6 +16,14 @@ pub struct Client { } impl Client { + pub fn new(url: &str) -> Result { + Ok(Client { + url: Url::parse(url)?.as_ref().into(), + headers: HeaderMap::new(), + http_client: reqwest::Client::new(), + }) + } + /// Returns Ok if healthy pub async fn health(&self) -> Result<(), AlgorandError> { let _ = self diff --git a/algonaut_client/src/kmd/v1/mod.rs b/algonaut_client/src/kmd/v1/mod.rs index 23ce7b31..ae4b0f58 100644 --- a/algonaut_client/src/kmd/v1/mod.rs +++ b/algonaut_client/src/kmd/v1/mod.rs @@ -19,7 +19,7 @@ pub struct Client { } impl Client { - pub(super) fn new(address: &str, token: &str) -> Client { + pub fn new(address: &str, token: &str) -> Client { Client { address: address.to_string(), token: token.to_string(), @@ -27,7 +27,6 @@ impl Client { } } - /// Retrieves the current version pub async fn versions(&self) -> Result { let response = self .http_client @@ -43,7 +42,6 @@ impl Client { Ok(response) } - /// List all of the wallets that kmd is aware of pub async fn list_wallets(&self) -> Result { let response = self .http_client @@ -59,7 +57,6 @@ impl Client { Ok(response) } - /// Creates a wallet pub async fn create_wallet( &self, wallet_name: &str, @@ -89,12 +86,6 @@ impl Client { Ok(response) } - /// Unlock the wallet and return a wallet token that can be used for subsequent operations - /// - /// These tokens expire periodically and must be renewed. - /// You can see how much time remains until expiration with [get_wallet_info](Client::get_wallet_info) - /// and renew it with [renew_wallet_handle](Client::renew_wallet_handle). - /// When you're done, you can invalidate the token with [release_wallet_handle](Client::release_wallet_handle) pub async fn init_wallet_handle( &self, wallet_id: &str, @@ -119,7 +110,6 @@ impl Client { Ok(response) } - /// Release a wallet handle token pub async fn release_wallet_handle( &self, wallet_handle: &str, @@ -142,7 +132,6 @@ impl Client { Ok(response) } - /// Renew a wallet handle token pub async fn renew_wallet_handle( &self, wallet_handle: &str, @@ -165,7 +154,6 @@ impl Client { Ok(response) } - /// Rename a wallet pub async fn rename_wallet( &self, wallet_id: &str, @@ -192,7 +180,6 @@ impl Client { Ok(response) } - /// Get wallet info pub async fn get_wallet_info( &self, wallet_handle: &str, @@ -215,7 +202,6 @@ impl Client { Ok(response) } - /// Export the master derivation key from a wallet pub async fn export_master_derivation_key( &self, wallet_handle: &str, @@ -240,7 +226,6 @@ impl Client { Ok(response) } - /// Import an externally generated key into the wallet pub async fn import_key( &self, wallet_handle: &str, @@ -265,9 +250,6 @@ impl Client { Ok(response) } - /// Export the Ed25519 seed associated with the passed address - /// - /// Note the first 32 bytes of the returned value is the seed, the second 32 bytes is the public key pub async fn export_key( &self, wallet_handle: &str, @@ -294,7 +276,6 @@ impl Client { Ok(response) } - /// Generates a key and adds it to the wallet, returning the public key pub async fn generate_key( &self, wallet_handle: &str, @@ -318,7 +299,6 @@ impl Client { Ok(response) } - /// Deletes the key from the wallet pub async fn delete_key( &self, wallet_handle: &str, @@ -345,7 +325,6 @@ impl Client { Ok(response) } - /// List all of the public keys in the wallet pub async fn list_keys(&self, wallet_handle: &str) -> Result { let req = ListKeysRequest { wallet_handle_token: wallet_handle.to_string(), @@ -365,7 +344,6 @@ impl Client { Ok(response) } - /// Sign a transaction pub async fn sign_transaction( &self, wallet_handle: &str, @@ -392,7 +370,6 @@ impl Client { Ok(response) } - /// Lists all of the multisig accounts whose preimages this wallet stores pub async fn list_multisig( &self, wallet_handle: &str, @@ -415,7 +392,6 @@ impl Client { Ok(response) } - /// Import a multisig account pub async fn import_multisig( &self, wallet_handle: &str, @@ -444,7 +420,6 @@ impl Client { Ok(response) } - /// Export multisig address metadata pub async fn export_multisig( &self, wallet_handle: &str, @@ -469,7 +444,6 @@ impl Client { Ok(response) } - /// Delete a multisig from the wallet pub async fn delete_multisig( &self, wallet_handle: &str, @@ -496,9 +470,6 @@ impl Client { Ok(response) } - /// Sign a multisig transaction. - /// - /// Start a multisig signature or add a signature to a partially completed multisig signature. pub async fn sign_multisig_transaction( &self, wallet_handle: &str, diff --git a/algonaut_client/src/lib.rs b/algonaut_client/src/lib.rs index 23f0c49e..a33e483f 100644 --- a/algonaut_client/src/lib.rs +++ b/algonaut_client/src/lib.rs @@ -10,8 +10,3 @@ pub mod indexer; pub mod kmd; /// Api token management utils pub mod token; - -// Re-exports -pub use algod::Algod; -pub use indexer::Indexer; -pub use kmd::Kmd; diff --git a/examples/algod_client.rs b/examples/algod_client.rs index 735b0c84..909ebf8f 100644 --- a/examples/algod_client.rs +++ b/examples/algod_client.rs @@ -1,4 +1,4 @@ -use algonaut::client::Algod; +use algonaut::algod::AlgodBuilder; use algonaut::core::Round; use dotenv::dotenv; use std::env; @@ -9,10 +9,10 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; // print algod status let node_status = algod.status().await?; diff --git a/examples/kmd_client.rs b/examples/kmd_client.rs index fa7060f4..f6e25bb1 100644 --- a/examples/kmd_client.rs +++ b/examples/kmd_client.rs @@ -1,5 +1,5 @@ -use algonaut::client::Kmd; use algonaut::crypto::MasterDerivationKey; +use algonaut::kmd::KmdBuilder; use dotenv::dotenv; use std::env; use std::error::Error; @@ -9,10 +9,10 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let create_wallet_response = kmd .create_wallet( diff --git a/examples/new_asa_sandnet.rs b/examples/new_asa_sandnet.rs index 1a084d3e..bcf1087e 100644 --- a/examples/new_asa_sandnet.rs +++ b/examples/new_asa_sandnet.rs @@ -1,5 +1,6 @@ -use algonaut::client::{Algod, Kmd}; +use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; +use algonaut::kmd::KmdBuilder; use algonaut::transaction::{ConfigureAsset, Txn}; use dotenv::dotenv; use std::env; @@ -11,10 +12,10 @@ async fn main() -> Result<(), Box> { dotenv().ok(); // kmd manages wallets and accounts - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; // first we obtain a handle to our wallet let list_response = kmd.list_wallets().await?; @@ -35,10 +36,10 @@ async fn main() -> Result<(), Box> { println!("Creator: {:?}", creator); // algod has a convenient method that retrieves basic information for a transaction - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let params = algod.transaction_params().await?; println!("Last round: {}", params.last_round); diff --git a/examples/query_indexer.rs b/examples/query_indexer.rs index e1e1e13a..8f9641db 100644 --- a/examples/query_indexer.rs +++ b/examples/query_indexer.rs @@ -1,5 +1,5 @@ -use algonaut::client::indexer::v2::message::QueryAccount; -use algonaut::client::Indexer; +use algonaut::indexer::IndexerBuilder; +use algonaut_client::indexer::v2::message::QueryAccount; use dotenv::dotenv; use std::env; use std::error::Error; @@ -9,9 +9,9 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; // query accounts using default query parameters (all None). let accounts = indexer.accounts(&QueryAccount::default()).await?.accounts; diff --git a/examples/quickstart.rs b/examples/quickstart.rs index eb71cf88..7de1111d 100644 --- a/examples/quickstart.rs +++ b/examples/quickstart.rs @@ -1,6 +1,6 @@ -use algonaut::client::Algod; -use algonaut::client::Indexer; -use algonaut::client::Kmd; +use algonaut::algod::AlgodBuilder; +use algonaut::indexer::IndexerBuilder; +use algonaut::kmd::KmdBuilder; use dotenv::dotenv; use std::env; use std::error::Error; @@ -10,17 +10,17 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; - let kmd = Kmd::new() + .build_v2()?; + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; - let indexer = Indexer::new() + .build_v1()?; + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; println!("Algod versions: {:#?}", algod.versions().await?); println!("Kmd versions: {:#?}", kmd.versions().await?); diff --git a/examples/sign_offline.rs b/examples/sign_offline.rs index 71bbb601..df6c45a2 100644 --- a/examples/sign_offline.rs +++ b/examples/sign_offline.rs @@ -1,4 +1,4 @@ -use algonaut::client::Algod; +use algonaut::algod::AlgodBuilder; use algonaut::core::{MicroAlgos, ToMsgPack}; use algonaut::crypto::mnemonic; use algonaut::transaction::account::Account; @@ -14,10 +14,10 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; // print algod status let node_status = algod.status().await?; diff --git a/examples/sign_submit_transaction.rs b/examples/sign_submit_transaction.rs index f8110ec4..4048802f 100644 --- a/examples/sign_submit_transaction.rs +++ b/examples/sign_submit_transaction.rs @@ -1,5 +1,6 @@ -use algonaut::client::{Algod, Kmd}; +use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; +use algonaut::kmd::KmdBuilder; use algonaut::transaction::{Pay, Txn}; use dotenv::dotenv; use std::env; @@ -10,14 +11,14 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; - let kmd = Kmd::new() + .build_v2()?; + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let list_response = kmd.list_wallets().await?; diff --git a/examples/sign_submit_transaction_sandnet.rs b/examples/sign_submit_transaction_sandnet.rs index 79b4c847..f333f642 100644 --- a/examples/sign_submit_transaction_sandnet.rs +++ b/examples/sign_submit_transaction_sandnet.rs @@ -1,5 +1,6 @@ -use algonaut::client::{Algod, Kmd}; +use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; +use algonaut::kmd::KmdBuilder; use algonaut::transaction::{Pay, Txn}; use dotenv::dotenv; use std::env; @@ -11,10 +12,10 @@ async fn main() -> Result<(), Box> { dotenv().ok(); // kmd manages wallets and accounts - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; // first we obtain a handle to our wallet let list_response = kmd.list_wallets().await?; @@ -38,10 +39,10 @@ async fn main() -> Result<(), Box> { println!("Receiver: {:#?}", to_address); // algod has a convenient method that retrieves basic information for a transaction - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let params = algod.transaction_params().await?; diff --git a/examples/submit_file.rs b/examples/submit_file.rs index 50686a46..4e660125 100644 --- a/examples/submit_file.rs +++ b/examples/submit_file.rs @@ -1,4 +1,4 @@ -use algonaut::client::Algod; +use algonaut::algod::AlgodBuilder; use dotenv::dotenv; use std::env; use std::error::Error; @@ -14,10 +14,10 @@ async fn main() -> Result<(), Box> { let mut raw_transaction = Vec::new(); let _ = f.read_to_end(&mut raw_transaction)?; - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let send_response = algod.broadcast_raw_transaction(&raw_transaction).await?; println!("Transaction ID: {}", send_response.tx_id); diff --git a/examples/wallet_backup.rs b/examples/wallet_backup.rs index 1b9589c1..849a9b34 100644 --- a/examples/wallet_backup.rs +++ b/examples/wallet_backup.rs @@ -1,5 +1,5 @@ -use algonaut::client::Kmd; use algonaut::crypto::mnemonic; +use algonaut::kmd::KmdBuilder; use dotenv::dotenv; use std::env; use std::error::Error; @@ -9,10 +9,10 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let list_response = kmd.list_wallets().await?; diff --git a/examples/wallet_restore.rs b/examples/wallet_restore.rs index 8795f905..3cd60e88 100644 --- a/examples/wallet_restore.rs +++ b/examples/wallet_restore.rs @@ -1,6 +1,6 @@ -use algonaut::client::Kmd; use algonaut::crypto::mnemonic; use algonaut::crypto::MasterDerivationKey; +use algonaut::kmd::KmdBuilder; use dotenv::dotenv; use std::env; use std::error::Error; @@ -10,10 +10,10 @@ async fn main() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let backup_phrase = "fire enlist diesel stamp nuclear chunk student stumble call snow flock brush example slab guide choice option recall south kangaroo hundred matrix school above zero"; let key_bytes = mnemonic::to_key(backup_phrase)?; diff --git a/src/algod/mod.rs b/src/algod/mod.rs new file mode 100644 index 00000000..b0344739 --- /dev/null +++ b/src/algod/mod.rs @@ -0,0 +1,109 @@ +use algonaut_client::error::{AlgorandError, BuilderError}; + +pub mod v1; +pub mod v2; + +/// AlgodBuilder is the entry point to the creation of a client for the Algorand protocol daemon. +/// ``` +/// use algonaut::AlgodBuilder; +/// +/// fn main() -> Result<(), Box> { +/// let algod = AlgodBuilder::new() +/// .bind("http://localhost:4001") +/// .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") +/// .algod_v2()?; +/// +/// println!("Algod versions: {:?}", algod.versions()?.versions); +/// +/// Ok(()) +/// } +/// ``` +pub struct AlgodBuilder<'a> { + url: Option<&'a str>, + token: Option<&'a str>, +} + +impl<'a> AlgodBuilder<'a> { + /// Start the creation of a client. + pub fn new() -> Self { + Self::default() + } + + /// Bind to a URL. + pub fn bind(mut self, url: &'a str) -> Self { + self.url = Some(url); + self + } + + /// Use a token to authenticate. + pub fn auth(mut self, token: &'a str) -> Self { + self.token = Some(token); + self + } + + /// Build a v1 client for Algorand protocol daemon. + pub fn build_v1(self) -> Result { + match (self.url, self.token) { + (Some(url), Some(token)) => Ok(v1::Algod::new( + algonaut_client::algod::v1::Client::new(url, token)?, + )), + (None, Some(_)) => Err(BuilderError::UnitializedUrl.into()), + (Some(_), None) => Err(BuilderError::UnitializedToken.into()), + (None, None) => Err(BuilderError::UnitializedUrl.into()), + } + } + + /// Build a v2 client for Algorand protocol daemon. + pub fn build_v2(self) -> Result { + match (self.url, self.token) { + (Some(url), Some(token)) => Ok(v2::Algod::new( + algonaut_client::algod::v2::Client::new(url, token)?, + )), + (None, Some(_)) => Err(BuilderError::UnitializedUrl.into()), + (Some(_), None) => Err(BuilderError::UnitializedToken.into()), + (None, None) => Err(BuilderError::UnitializedUrl.into()), + } + } +} + +impl<'a> Default for AlgodBuilder<'a> { + fn default() -> Self { + AlgodBuilder { + url: None, + token: None, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_valid_client_builder() { + let algod = AlgodBuilder::new() + .bind("http://example.com") + .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .build_v1(); + + assert!(algod.ok().is_some()); + } + + #[test] + #[should_panic(expected = "")] + fn test_client_builder_with_no_token() { + let _ = AlgodBuilder::new() + .bind("http://example.com") + .build_v1() + .unwrap(); + } + + #[test] + #[should_panic(expected = "")] + fn test_client_builder_with_no_url() { + let _ = AlgodBuilder::new() + .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .build_v1() + .unwrap(); + } +} diff --git a/src/algod/v1/mod.rs b/src/algod/v1/mod.rs new file mode 100644 index 00000000..66708d14 --- /dev/null +++ b/src/algod/v1/mod.rs @@ -0,0 +1,122 @@ +use algonaut_client::{ + algod::v1::{ + message::{ + Account, Block, NodeStatus, PendingTransactions, QueryAccountTransactions, Supply, + Transaction, TransactionFee, TransactionId, TransactionList, TransactionParams, + Version, + }, + Client, + }, + error::AlgorandError, +}; +use algonaut_core::Round; + +pub struct Algod { + pub(crate) client: Client, +} + +impl Algod { + pub fn new(client: Client) -> Algod { + Algod { client } + } + + pub async fn health(&self) -> Result<(), AlgorandError> { + self.client.health().await + } + + /// Retrieves the current version + pub async fn versions(&self) -> Result { + self.client.versions().await + } + + /// Gets the current node status + pub async fn status(&self) -> Result { + self.client.status().await + } + + /// Waits for a block to appear after the specified round and returns the node status at the time + pub async fn status_after_block(&self, round: Round) -> Result { + self.client.status_after_block(round).await + } + + /// Get the block for the given round + pub async fn block(&self, round: Round) -> Result { + self.client.block(round).await + } + + /// Gets the current supply reported by the ledger + pub async fn ledger_supply(&self) -> Result { + self.client.ledger_supply().await + } + + pub async fn account_information(&self, address: &str) -> Result { + self.client.account_information(address).await + } + + /// Gets a list of unconfirmed transactions currently in the transaction pool + /// + /// Sorted by priority in decreasing order and truncated at the specified limit, or returns all if specified limit is 0 + pub async fn pending_transactions( + &self, + limit: u64, + ) -> Result { + self.client.pending_transactions(limit).await + } + + /// Get a specified pending transaction + /// + /// Given a transaction id of a recently submitted transaction, it returns information + /// about it. There are several cases when this might succeed: - transaction committed + /// (committed round > 0) - transaction still in the pool (committed round = 0, pool + /// error = "") - transaction removed from pool due to error (committed round = 0, pool + /// error != "") Or the transaction may have happened sufficiently long ago that the + /// node no longer remembers it, and this will return an error. + pub async fn pending_transaction_information( + &self, + transaction_id: &str, + ) -> Result { + self.client + .pending_transaction_information(transaction_id) + .await + } + + /// Get a list of confirmed transactions, limited to filters if specified + pub async fn transactions( + &self, + address: &str, + query: &QueryAccountTransactions, + ) -> Result { + self.client.transactions(address, query).await + } + + /// Broadcasts a raw transaction to the network + pub async fn raw_transaction(&self, raw: &[u8]) -> Result { + self.client.raw_transaction(raw).await + } + + /// Gets the information of a single transaction + pub async fn transaction(&self, transaction_id: &str) -> Result { + self.client.transaction(transaction_id).await + } + + /// Gets a specific confirmed transaction + pub async fn transaction_information( + &self, + address: &str, + transaction_id: &str, + ) -> Result { + self.client + .transaction_information(address, transaction_id) + .await + } + + /// Gets suggested fee in units of micro-Algos per byte + pub async fn suggested_fee(&self) -> Result { + self.client.suggested_fee().await + } + + /// Gets parameters for constructing a new transaction + pub async fn transaction_params(&self) -> Result { + self.client.transaction_params().await + } +} diff --git a/src/algod/v2/mod.rs b/src/algod/v2/mod.rs new file mode 100644 index 00000000..a7a7734f --- /dev/null +++ b/src/algod/v2/mod.rs @@ -0,0 +1,196 @@ +use algonaut_client::algod::v2::message::Account; +use algonaut_client::algod::v2::message::ApiCompiledTeal; +use algonaut_client::algod::v2::message::Application; +use algonaut_client::algod::v2::message::Block; +use algonaut_client::algod::v2::message::Catchup; +use algonaut_client::algod::v2::message::DryrunRequest; +use algonaut_client::algod::v2::message::DryrunResponse; +use algonaut_client::algod::v2::message::GenesisBlock; +use algonaut_client::algod::v2::message::KeyRegistration; +use algonaut_client::algod::v2::message::NodeStatus; +use algonaut_client::algod::v2::message::PendingTransaction; +use algonaut_client::algod::v2::message::PendingTransactions; +use algonaut_client::algod::v2::message::Supply; +use algonaut_client::algod::v2::message::TransactionParams; +use algonaut_client::algod::v2::message::TransactionResponse; +use algonaut_client::algod::v2::message::Version; +use algonaut_client::algod::v2::Client; +use algonaut_client::error::AlgorandError; +use algonaut_core::Round; + +pub struct Algod { + pub(crate) client: Client, +} + +impl Algod { + pub fn new(client: Client) -> Algod { + Algod { client } + } + + /// Returns the entire genesis file in json. + pub async fn genesis(&self) -> Result { + self.client.genesis().await + } + + /// Returns Ok if healthy + pub async fn health(&self) -> Result<(), AlgorandError> { + self.client.health().await + } + + /// Return metrics about algod functioning. + pub async fn metrics(&self) -> Result { + self.client.metrics().await + } + + /// Get account information. + /// Description Given a specific account public key, this call returns the accounts status, + /// balance and spendable amounts + pub async fn account_information(&self, address: &str) -> Result { + self.client.account_information(address).await + } + + /// Get a list of unconfirmed transactions currently in the transaction pool by address. + /// Description: Get the list of pending transactions by address, sorted by priority, + /// in decreasing order, truncated at the end at MAX. If MAX = 0, returns all pending transactions. + pub async fn pending_transactions_for( + &self, + address: &str, + max: u64, + ) -> Result { + self.client.pending_transactions_for(address, max).await + } + + /// Get application information. + /// + /// Given a application id, it returns application information including creator, + /// approval and clear programs, global and local schemas, and global state. + pub async fn application_information(&self, id: usize) -> Result { + self.client.application_information(id).await + } + + /// Get asset information. + /// + /// Given a asset id, it returns asset information including creator, name, + /// total supply and special addresses. + pub async fn asset_information(&self, id: usize) -> Result { + self.client.asset_information(id).await + } + + /// Get the block for the given round. + pub async fn block(&self, round: Round) -> Result { + self.client.block(round).await + } + + /// Starts a catchpoint catchup. + pub async fn start_catchup(&self, catchpoint: &str) -> Result { + self.client.start_catchup(catchpoint).await + } + + /// Aborts a catchpoint catchup. + pub async fn abort_catchup(&self, catchpoint: &str) -> Result { + self.client.abort_catchup(catchpoint).await + } + + /// Get the current supply reported by the ledger. + pub async fn ledger_supply(&self) -> Result { + self.client.ledger_supply().await + } + + /// Generate (or renew) and register participation keys on the node for a given account address. + /// + /// address: The account-id to update, or all to update all accounts. + /// fee: The fee to use when submitting key registration transactions. Defaults to the suggested + /// fee. (default = 1000) + /// key-dilution: value to use for two-level participation key. + /// no-wait: Don't wait for transaction to commit before returning response. + /// round-last-valid: The last round for which the generated participation keys will be valid. + pub async fn register_participation_keys( + &self, + address: &str, + params: &KeyRegistration, + ) -> Result { + self.client + .register_participation_keys(address, params) + .await + } + + /// Special management endpoint to shutdown the node. Optionally provide a timeout parameter + /// to indicate that the node should begin shutting down after a number of seconds. + pub async fn shutdown(&self, timeout: usize) -> Result<(), AlgorandError> { + self.client.shutdown(timeout).await + } + + /// Gets the current node status. + pub async fn status(&self) -> Result { + self.client.status().await + } + + /// Gets the node status after waiting for the given round. + pub async fn status_after_round(&self, round: Round) -> Result { + self.client.status_after_round(round).await + } + + /// Compile TEAL source code to binary, produce its hash. + /// + /// Given TEAL source code in plain text, return base64 encoded program bytes and base32 + /// SHA512_256 hash of program bytes (Address style). This endpoint is only enabled when + /// a node's configuration file sets EnableDeveloperAPI to true. + pub async fn compile_teal(&self, teal: String) -> Result { + self.client.compile_teal(teal).await + } + + /// Provide debugging information for a transaction (or group). + /// + /// Executes TEAL program(s) in context and returns debugging information about the execution. + /// This endpoint is only enabled when a node's configureation file sets EnableDeveloperAPI + /// to true. + pub async fn dryrun_teal(&self, req: &DryrunRequest) -> Result { + self.client.dryrun_teal(req).await + } + + /// Broadcasts a raw transaction to the network. + pub async fn broadcast_raw_transaction( + &self, + rawtxn: &[u8], + ) -> Result { + self.client.broadcast_raw_transaction(rawtxn).await + } + + /// Get parameters for constructing a new transaction. + pub async fn transaction_params(&self) -> Result { + self.client.transaction_params().await + } + + /// Get a list of unconfirmed transactions currently in the transaction pool. + /// + /// Get the list of pending transactions, sorted by priority, in decreasing order, + /// truncated at the end at MAX. If MAX = 0, returns all pending transactions. + pub async fn pending_transactions( + &self, + max: u64, + ) -> Result { + self.client.pending_transactions(max).await + } + + /// Get a specific pending transaction. + /// + /// Given a transaction id of a recently submitted transaction, it returns information about + /// it. There are several cases when this might succeed: + /// - transaction committed (committed round > 0) + /// - transaction still in the pool (committed round = 0, pool error = "") + /// - transaction removed from pool due to error (committed round = 0, pool error != "") + /// + /// Or the transaction may have happened sufficiently long ago that the node no longer remembers + /// it, and this will return an error. + pub async fn pending_transaction_with_id( + &self, + txid: &str, + ) -> Result { + self.client.pending_transaction_with_id(txid).await + } + + /// Retrieves the current version + pub async fn versions(&self) -> Result { + self.client.versions().await + } +} diff --git a/src/indexer/mod.rs b/src/indexer/mod.rs new file mode 100644 index 00000000..c6e50a88 --- /dev/null +++ b/src/indexer/mod.rs @@ -0,0 +1,56 @@ +use algonaut_client::{ + error::{AlgorandError, BuilderError}, + indexer::v2::Client, +}; + +pub mod v2; + +/// Indexer is the entry point to the creation of a client for the Algorand's indexer +pub struct IndexerBuilder<'a> { + url: Option<&'a str>, +} + +impl<'a> IndexerBuilder<'a> { + /// Start the creation of a client. + pub fn new() -> Self { + Self::default() + } + + /// Bind to a URL. + pub fn bind(mut self, url: &'a str) -> Self { + self.url = Some(url); + self + } + + /// Build a v2 client for Algorand's indexer. + pub fn build_v2(self) -> Result { + match self.url { + Some(url) => Ok(v2::Indexer::new(Client::new(url)?)), + None => Err(BuilderError::UnitializedUrl.into()), + } + } +} + +impl<'a> Default for IndexerBuilder<'a> { + fn default() -> Self { + IndexerBuilder { url: None } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_valid_client_builder() { + let indexer = IndexerBuilder::new().bind("http://example.com").build_v2(); + + assert!(indexer.ok().is_some()); + } + + #[test] + #[should_panic(expected = "")] + fn test_client_builder_with_no_url() { + let _ = IndexerBuilder::new().build_v2().unwrap(); + } +} diff --git a/src/indexer/v2/mod.rs b/src/indexer/v2/mod.rs new file mode 100644 index 00000000..8435d85d --- /dev/null +++ b/src/indexer/v2/mod.rs @@ -0,0 +1,120 @@ +use algonaut_client::{ + error::AlgorandError, + indexer::v2::{ + message::{ + AccountInfoResponse, AccountResponse, AccountTransactionResponse, + ApplicationInfoResponse, ApplicationResponse, AssetResponse, AssetTransactionResponse, + AssetsInfoResponse, BalancesResponse, Block, QueryAccount, QueryAccountInfo, + QueryAccountTransaction, QueryApplicationInfo, QueryApplications, + QueryAssetTransaction, QueryAssets, QueryAssetsInfo, QueryBalances, QueryTransaction, + TransactionResponse, + }, + Client, + }, +}; +use algonaut_core::Round; + +pub struct Indexer { + pub(super) client: Client, +} + +impl Indexer { + pub fn new(client: Client) -> Indexer { + Indexer { client } + } + + /// Returns Ok if healthy + pub async fn health(&self) -> Result<(), AlgorandError> { + self.client.health().await + } + + /// Search for accounts. + pub async fn accounts(&self, query: &QueryAccount) -> Result { + self.client.accounts(query).await + } + + /// Lookup account information. + pub async fn account_info( + &self, + id: &str, + query: &QueryAccountInfo, + ) -> Result { + self.client.account_info(id, query).await + } + + /// Lookup account transactions. + pub async fn account_transactions( + &self, + id: &str, + query: &QueryAccountTransaction, + ) -> Result { + self.client.account_transactions(id, query).await + } + + /// Search for applications + pub async fn applications( + &self, + query: &QueryApplications, + ) -> Result { + self.client.applications(query).await + } + + /// Lookup application. + pub async fn application_info( + &self, + id: &str, + query: &QueryApplicationInfo, + ) -> Result { + self.client.application_info(id, query).await + } + + /// Search for assets. + pub async fn assets(&self, query: &QueryAssets) -> Result { + self.client.assets(query).await + } + + /// Lookup asset information. + pub async fn assets_info( + &self, + id: &str, + query: &QueryAssetsInfo, + ) -> Result { + self.client.assets_info(id, query).await + } + + /// Lookup the list of accounts who hold this asset. + pub async fn asset_balances( + &self, + id: &str, + query: &QueryBalances, + ) -> Result { + self.client.asset_balances(id, query).await + } + + /// Lookup transactions for an asset. + pub async fn asset_transactions( + &self, + id: &str, + query: &QueryAssetTransaction, + ) -> Result { + self.client.asset_transactions(id, query).await + } + + /// Lookup block. + pub async fn block(&self, round: Round) -> Result { + self.client.block(round).await + } + + /// Search for transactions. + pub async fn transactions( + &self, + query: &QueryTransaction, + ) -> Result { + self.client.transactions(query).await + } + + /// Search for transactions. + pub async fn transaction_info(&self, id: &str) -> Result { + self.client.transaction_info(id).await + } +} diff --git a/src/kmd/mod.rs b/src/kmd/mod.rs new file mode 100644 index 00000000..a939d0ab --- /dev/null +++ b/src/kmd/mod.rs @@ -0,0 +1,97 @@ +use algonaut_client::{ + error::{AlgorandError, BuilderError}, + kmd::v1::Client, +}; + +pub mod v1; + +/// KmdBuilder is the entry point to the creation of a client for the Algorand key management daemon. +/// ``` +/// use algonaut::KmdBuilder; +/// +/// fn main() -> Result<(), Box> { +/// let algod = KmdBuilder::new() +/// .bind("http://localhost:4001") +/// .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") +/// .kmd_v1()?; +/// +/// println!("Algod versions: {:?}", algod.versions()?.versions); +/// +/// Ok(()) +/// } +/// ``` +pub struct KmdBuilder<'a> { + url: Option<&'a str>, + token: Option<&'a str>, +} + +impl<'a> KmdBuilder<'a> { + /// Start the creation of a client. + pub fn new() -> Self { + Self::default() + } + + /// Bind to a URL. + pub fn bind(mut self, url: &'a str) -> Self { + self.url = Some(url); + self + } + + /// Use a token to authenticate. + pub fn auth(mut self, token: &'a str) -> Self { + self.token = Some(token); + self + } + + /// Build a v1 client for Algorand protocol daemon. + pub fn build_v1(self) -> Result { + match (self.url, self.token) { + (Some(url), Some(token)) => Ok(v1::Kmd::new(Client::new(url, token))), + (None, Some(_)) => Err(BuilderError::UnitializedUrl.into()), + (Some(_), None) => Err(BuilderError::UnitializedToken.into()), + (None, None) => Err(BuilderError::UnitializedUrl.into()), + } + } +} + +impl<'a> Default for KmdBuilder<'a> { + fn default() -> Self { + KmdBuilder { + url: None, + token: None, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_valid_client_builder() { + let algod = KmdBuilder::new() + .bind("http://example.com") + .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .build_v1(); + + assert!(algod.ok().is_some()); + } + + #[test] + #[should_panic(expected = "")] + fn test_client_builder_with_no_token() { + let _ = KmdBuilder::new() + .bind("http://example.com") + .build_v1() + .unwrap(); + } + + #[test] + #[should_panic(expected = "")] + fn test_client_builder_with_no_url() { + let _ = KmdBuilder::new() + .auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .build_v1() + .unwrap(); + } +} diff --git a/src/kmd/v1/mod.rs b/src/kmd/v1/mod.rs new file mode 100644 index 00000000..e9d4e979 --- /dev/null +++ b/src/kmd/v1/mod.rs @@ -0,0 +1,238 @@ +use algonaut_client::error::AlgorandError; +use algonaut_client::kmd::v1::message::{ + CreateWalletResponse, DeleteKeyResponse, DeleteMultisigResponse, ExportKeyResponse, + ExportMasterDerivationKeyResponse, ExportMultisigResponse, GenerateKeyResponse, + GetWalletInfoResponse, ImportKeyResponse, ImportMultisigResponse, InitWalletHandleResponse, + ListKeysResponse, ListMultisigResponse, ListWalletsResponse, ReleaseWalletHandleResponse, + RenameWalletResponse, RenewWalletHandleResponse, SignMultisigTransactionResponse, + SignTransactionResponse, VersionsResponse, +}; +use algonaut_client::kmd::v1::Client; +use algonaut_core::MultisigSignature; +use algonaut_crypto::{Ed25519PublicKey, MasterDerivationKey}; +use algonaut_transaction::Transaction; + +pub struct Kmd { + pub(crate) client: Client, +} + +impl Kmd { + pub fn new(client: Client) -> Kmd { + Kmd { client } + } + + /// Retrieves the current version + pub async fn versions(&self) -> Result { + self.client.versions().await + } + + /// List all of the wallets that kmd is aware of + pub async fn list_wallets(&self) -> Result { + self.client.list_wallets().await + } + + /// Creates a wallet + pub async fn create_wallet( + &self, + wallet_name: &str, + wallet_password: &str, + wallet_driver_name: &str, + master_derivation_key: MasterDerivationKey, + ) -> Result { + self.client + .create_wallet( + wallet_name, + wallet_password, + wallet_driver_name, + master_derivation_key, + ) + .await + } + + /// Unlock the wallet and return a wallet token that can be used for subsequent operations + /// + /// These tokens expire periodically and must be renewed. + /// You can see how much time remains until expiration with [get_wallet_info](Client::get_wallet_info) + /// and renew it with [renew_wallet_handle](Client::renew_wallet_handle). + /// When you're done, you can invalidate the token with [release_wallet_handle](Client::release_wallet_handle) + pub async fn init_wallet_handle( + &self, + wallet_id: &str, + wallet_password: &str, + ) -> Result { + self.client + .init_wallet_handle(wallet_id, wallet_password) + .await + } + + /// Release a wallet handle token + pub async fn release_wallet_handle( + &self, + wallet_handle: &str, + ) -> Result { + self.client.release_wallet_handle(wallet_handle).await + } + + /// Renew a wallet handle token + pub async fn renew_wallet_handle( + &self, + wallet_handle: &str, + ) -> Result { + self.client.renew_wallet_handle(wallet_handle).await + } + + /// Rename a wallet + pub async fn rename_wallet( + &self, + wallet_id: &str, + wallet_password: &str, + new_name: &str, + ) -> Result { + self.client + .rename_wallet(wallet_id, wallet_password, new_name) + .await + } + + /// Get wallet info + pub async fn get_wallet_info( + &self, + wallet_handle: &str, + ) -> Result { + self.client.get_wallet_info(wallet_handle).await + } + + /// Export the master derivation key from a wallet + pub async fn export_master_derivation_key( + &self, + wallet_handle: &str, + wallet_password: &str, + ) -> Result { + self.client + .export_master_derivation_key(wallet_handle, wallet_password) + .await + } + + /// Import an externally generated key into the wallet + pub async fn import_key( + &self, + wallet_handle: &str, + private_key: [u8; 32], + ) -> Result { + self.client.import_key(wallet_handle, private_key).await + } + + /// Export the Ed25519 seed associated with the passed address + /// + /// Note the first 32 bytes of the returned value is the seed, the second 32 bytes is the public key + pub async fn export_key( + &self, + wallet_handle: &str, + wallet_password: &str, + address: &str, + ) -> Result { + self.client + .export_key(wallet_handle, wallet_password, address) + .await + } + + /// Generates a key and adds it to the wallet, returning the public key + pub async fn generate_key( + &self, + wallet_handle: &str, + ) -> Result { + self.client.generate_key(wallet_handle).await + } + + /// Deletes the key from the wallet + pub async fn delete_key( + &self, + wallet_handle: &str, + wallet_password: &str, + address: &str, + ) -> Result { + self.client + .delete_key(wallet_handle, wallet_password, address) + .await + } + + /// List all of the public keys in the wallet + pub async fn list_keys(&self, wallet_handle: &str) -> Result { + self.client.list_keys(wallet_handle).await + } + + /// Sign a transaction + pub async fn sign_transaction( + &self, + wallet_handle: &str, + wallet_password: &str, + transaction: &Transaction, + ) -> Result { + self.client + .sign_transaction(wallet_handle, wallet_password, transaction) + .await + } + + /// Lists all of the multisig accounts whose preimages this wallet stores + pub async fn list_multisig( + &self, + wallet_handle: &str, + ) -> Result { + self.client.list_multisig(wallet_handle).await + } + + /// Import a multisig account + pub async fn import_multisig( + &self, + wallet_handle: &str, + version: u8, + threshold: u8, + pks: &[Ed25519PublicKey], + ) -> Result { + self.client + .import_multisig(wallet_handle, version, threshold, pks) + .await + } + + /// Export multisig address metadata + pub async fn export_multisig( + &self, + wallet_handle: &str, + address: &str, + ) -> Result { + self.client.export_multisig(wallet_handle, address).await + } + + /// Delete a multisig from the wallet + pub async fn delete_multisig( + &self, + wallet_handle: &str, + wallet_password: &str, + address: &str, + ) -> Result { + self.client + .delete_multisig(wallet_handle, wallet_password, address) + .await + } + + /// Sign a multisig transaction. + /// + /// Start a multisig signature or add a signature to a partially completed multisig signature. + pub async fn sign_multisig_transaction( + &self, + wallet_handle: &str, + wallet_password: &str, + transaction: &Transaction, + public_key: Ed25519PublicKey, + partial_multisig: Option, + ) -> Result { + self.client + .sign_multisig_transaction( + wallet_handle, + wallet_password, + transaction, + public_key, + partial_multisig, + ) + .await + } +} diff --git a/src/lib.rs b/src/lib.rs index b1b0b6a1..fcbcf93d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,10 @@ // TODO #![deny(missing_docs)] // Re-exports -pub use algonaut_client as client; pub use algonaut_core as core; pub use algonaut_crypto as crypto; pub use algonaut_transaction as transaction; + +pub mod algod; +pub mod indexer; +pub mod kmd; diff --git a/algonaut_client/tests/test_algod_v1.rs b/tests/test_algod_v1.rs similarity index 84% rename from algonaut_client/tests/test_algod_v1.rs rename to tests/test_algod_v1.rs index 9e48186b..608e5e3d 100644 --- a/algonaut_client/tests/test_algod_v1.rs +++ b/tests/test_algod_v1.rs @@ -1,4 +1,4 @@ -use algonaut_client::Algod; +use algonaut::algod::AlgodBuilder; use algonaut_core::Round; use dotenv::dotenv; use std::env; @@ -10,10 +10,10 @@ async fn test_health_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod.health().await.is_ok()); @@ -25,10 +25,10 @@ async fn test_versions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod.versions().await.is_ok()); @@ -40,10 +40,10 @@ async fn test_status_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod.status().await.is_ok()); @@ -55,10 +55,10 @@ async fn test_status_after_block_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod.status_after_block(Round(0)).await.is_ok()); @@ -70,10 +70,10 @@ async fn test_block_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let node_status = algod.status().await; println!("{:#?}", node_status); @@ -91,10 +91,10 @@ async fn test_ledger_supply_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod.ledger_supply().await.is_ok()); @@ -106,10 +106,10 @@ async fn test_account_information_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; assert!(algod .account_information("4MYUHDWHWXAKA5KA7U5PEN646VYUANBFXVJNONBK3TIMHEMWMD4UBOJBI4") diff --git a/algonaut_client/tests/test_algod_v2.rs b/tests/test_algod_v2.rs similarity index 87% rename from algonaut_client/tests/test_algod_v2.rs rename to tests/test_algod_v2.rs index 7016ae44..100f0f00 100644 --- a/algonaut_client/tests/test_algod_v2.rs +++ b/tests/test_algod_v2.rs @@ -1,5 +1,5 @@ +use algonaut::algod::AlgodBuilder; use algonaut_client::algod::v2::message::KeyRegistration; -use algonaut_client::Algod; use algonaut_core::Round; use dotenv::dotenv; use std::env; @@ -11,10 +11,10 @@ async fn test_genesis_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.genesis().await; @@ -29,10 +29,10 @@ async fn test_health_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.health().await; @@ -47,10 +47,10 @@ async fn test_metrics_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.metrics().await; @@ -65,10 +65,10 @@ async fn test_account_information_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod .account_information("4MYUHDWHWXAKA5KA7U5PEN646VYUANBFXVJNONBK3TIMHEMWMD4UBOJBI4") @@ -85,10 +85,10 @@ async fn test_pending_transactions_for_endpoint() -> Result<(), Box> // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod .pending_transactions_for( @@ -109,10 +109,10 @@ async fn test_application_information_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.application_information(0).await; @@ -128,10 +128,10 @@ async fn test_asset_information_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.asset_information(0).await; @@ -147,10 +147,10 @@ async fn test_block_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let last_round = algod.status().await?.last_round; let res = algod.block(Round(last_round)).await; @@ -167,10 +167,10 @@ async fn test_start_catchup_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod .start_catchup("4420000#Q7T2RRTDIRTYESIXKAAFJYFQWG4A3WRA3JIUZVCJ3F4AQ2G2HZRA") @@ -188,10 +188,10 @@ async fn test_abort_catchup_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod .abort_catchup("4420000#Q7T2RRTDIRTYESIXKAAFJYFQWG4A3WRA3JIUZVCJ3F4AQ2G2HZRA") @@ -208,10 +208,10 @@ async fn test_ledger_supply_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.ledger_supply().await; @@ -227,10 +227,10 @@ async fn test_register_participation_keys_endpoint() -> Result<(), Box Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.shutdown(0).await; @@ -275,10 +275,10 @@ async fn test_status_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.status().await; @@ -293,10 +293,10 @@ async fn test_status_after_round_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let node_status = algod.status().await?; @@ -315,10 +315,10 @@ async fn test_compile_teal_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod .compile_teal( @@ -344,10 +344,10 @@ async fn test_failure_compiling_teal() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.compile_teal("not-a-teal-program".into()).await; @@ -372,10 +372,10 @@ async fn test_broadcast_raw_transaction_endpoint() -> Result<(), Box> // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.broadcast_raw_transaction(&[0; 32]).await; @@ -390,10 +390,10 @@ async fn test_transaction_params_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.transaction_params().await; @@ -408,10 +408,10 @@ async fn test_pending_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.pending_transactions(0).await; @@ -427,10 +427,10 @@ async fn test_pending_transaction_with_id_endpoint() -> Result<(), Box Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = algod.versions().await; diff --git a/algonaut_client/tests/test_indexer_v2.rs b/tests/test_indexer_v2.rs similarity index 89% rename from algonaut_client/tests/test_indexer_v2.rs rename to tests/test_indexer_v2.rs index ce9119b7..76cc4c95 100644 --- a/algonaut_client/tests/test_indexer_v2.rs +++ b/tests/test_indexer_v2.rs @@ -1,9 +1,9 @@ +use algonaut::indexer::IndexerBuilder; use algonaut_client::indexer::v2::message::{ QueryAccount, QueryAccountInfo, QueryAccountTransaction, QueryApplicationInfo, QueryApplications, QueryAssetTransaction, QueryAssets, QueryAssetsInfo, QueryBalances, QueryTransaction, Role, }; -use algonaut_client::Indexer; use algonaut_core::Round; use dotenv::dotenv; use std::env; @@ -15,9 +15,9 @@ async fn test_health_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = indexer.health().await; @@ -32,9 +32,9 @@ async fn test_accounts_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryAccount { application_id: None, @@ -60,9 +60,9 @@ async fn test_account_info_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let account: String = env::var("ACCOUNT")?.parse()?; @@ -84,9 +84,9 @@ async fn test_account_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryAccountTransaction { after_time: None, @@ -123,9 +123,9 @@ async fn test_applications_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryApplications { application_id: None, @@ -147,9 +147,9 @@ async fn test_applications_info_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryApplicationInfo { include_all: None }; @@ -166,9 +166,9 @@ async fn test_assets_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryAssets { asset_id: None, @@ -193,9 +193,9 @@ async fn test_assets_info_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryAssetsInfo { include_all: None }; @@ -212,9 +212,9 @@ async fn test_asset_balances_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryBalances { currency_greater_than: None, @@ -237,9 +237,9 @@ async fn test_asset_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryAssetTransaction { address: None, @@ -274,9 +274,9 @@ async fn test_block_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = indexer.block(Round(0)).await; @@ -292,9 +292,9 @@ async fn test_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let query = QueryTransaction { address: None, @@ -332,9 +332,9 @@ async fn test_transaction_info_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let indexer = Indexer::new() + let indexer = IndexerBuilder::new() .bind(env::var("INDEXER_URL")?.as_ref()) - .client_v2()?; + .build_v2()?; let res = indexer.transaction_info("123").await; diff --git a/algonaut_client/tests/test_kmd_v1.rs b/tests/test_kmd_v1.rs similarity index 94% rename from algonaut_client/tests/test_kmd_v1.rs rename to tests/test_kmd_v1.rs index d1604597..b39199d0 100644 --- a/algonaut_client/tests/test_kmd_v1.rs +++ b/tests/test_kmd_v1.rs @@ -1,4 +1,4 @@ -use algonaut_client::Kmd; +use algonaut::kmd::KmdBuilder; use algonaut_crypto::{Ed25519PublicKey, MasterDerivationKey}; use dotenv::dotenv; use rand::{distributions::Alphanumeric, Rng}; @@ -11,10 +11,10 @@ async fn test_versions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let versions = kmd.versions().await; println!("{:#?}", versions); @@ -28,10 +28,10 @@ async fn test_list_wallets_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallets = kmd.list_wallets().await; println!("{:#?}", wallets); @@ -45,10 +45,10 @@ async fn test_create_wallet_and_obtain_handle() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -84,10 +84,10 @@ async fn test_release_wallet_handle_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -129,10 +129,10 @@ async fn test_renew_wallet_handle_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -174,10 +174,10 @@ async fn test_rename_wallet_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -221,10 +221,10 @@ async fn test_get_wallet_info_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -266,10 +266,10 @@ async fn test_export_wallet_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -311,10 +311,10 @@ async fn test_import_export_key() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -371,10 +371,10 @@ async fn test_generate_key_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -416,10 +416,10 @@ async fn test_delete_key_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -474,10 +474,10 @@ async fn test_list_keys_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -524,10 +524,10 @@ async fn test_list_keys_of_empty_wallet() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -569,10 +569,10 @@ async fn test_list_multisig_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let wallet_name: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -614,10 +614,10 @@ async fn test_import_export_multisig() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let version = 1; let threshold = 1; @@ -680,10 +680,10 @@ async fn test_delete_multisig_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let kmd = Kmd::new() + let kmd = KmdBuilder::new() .bind(env::var("KMD_URL")?.as_ref()) .auth(env::var("KMD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let version = 1; let threshold = 1; diff --git a/algonaut_client/tests/test_trasactions.rs b/tests/test_trasactions.rs similarity index 95% rename from algonaut_client/tests/test_trasactions.rs rename to tests/test_trasactions.rs index 8dd73ad8..ad909858 100644 --- a/algonaut_client/tests/test_trasactions.rs +++ b/tests/test_trasactions.rs @@ -1,5 +1,5 @@ +use algonaut::algod::AlgodBuilder; use algonaut_client::algod::v1::message::QueryAccountTransactions; -use algonaut_client::Algod; use algonaut_core::CompiledTeal; use algonaut_core::SignedLogic; use algonaut_core::{LogicSignature, MicroAlgos, MultisigAddress, ToMsgPack}; @@ -17,10 +17,10 @@ async fn test_transaction() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let from = account1(); let to = account2(); @@ -63,10 +63,10 @@ async fn test_multisig_transaction() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let account1 = account1(); let account2 = account2(); @@ -117,10 +117,10 @@ async fn test_transaction_with_contract_account_logic_sig() -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let from = account1(); @@ -357,10 +357,10 @@ async fn test_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; let address: String = env::var("ACCOUNT")?.parse()?; @@ -387,10 +387,10 @@ async fn test_pending_transactions_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; println!("{:?}", algod.pending_transactions(0).await); assert!(algod.pending_transactions(0).await.is_ok()); @@ -403,10 +403,10 @@ async fn test_transaction_information_endpoint() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v1()?; + .build_v1()?; println!("{:?}", algod.transaction_params().await); assert!(algod.transaction_params().await.is_ok()); @@ -420,10 +420,10 @@ async fn test_atomic_swap() -> Result<(), Box> { // load variables in .env dotenv().ok(); - let algod = Algod::new() + let algod = AlgodBuilder::new() .bind(env::var("ALGOD_URL")?.as_ref()) .auth(env::var("ALGOD_TOKEN")?.as_ref()) - .client_v2()?; + .build_v2()?; let account1 = account1(); let account2 = account2(); From 596ee3a12442993f2723a57de45792df96574e24 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Thu, 17 Jun 2021 15:53:55 +0200 Subject: [PATCH 5/6] Rename Txn in TxnBuilder Consistency with other builders --- algonaut_transaction/src/builder.rs | 4 ++-- algonaut_transaction/src/lib.rs | 2 +- examples/new_asa_sandnet.rs | 4 ++-- examples/sign_offline.rs | 4 ++-- examples/sign_submit_transaction.rs | 4 ++-- examples/sign_submit_transaction_sandnet.rs | 4 ++-- tests/test_trasactions.rs | 18 +++++++++--------- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/algonaut_transaction/src/builder.rs b/algonaut_transaction/src/builder.rs index 10ec81ba..9ead113e 100644 --- a/algonaut_transaction/src/builder.rs +++ b/algonaut_transaction/src/builder.rs @@ -8,7 +8,7 @@ use algonaut_crypto::HashDigest; /// A builder for [Transaction]. #[derive(Default)] -pub struct Txn { +pub struct TxnBuilder { fee: MicroAlgos, first_valid: Round, genesis_hash: Option, @@ -22,7 +22,7 @@ pub struct Txn { rekey_to: Option
, } -impl Txn { +impl TxnBuilder { pub fn new() -> Self { Self::default() } diff --git a/algonaut_transaction/src/lib.rs b/algonaut_transaction/src/lib.rs index d213662d..54f0cef6 100644 --- a/algonaut_transaction/src/lib.rs +++ b/algonaut_transaction/src/lib.rs @@ -8,6 +8,6 @@ pub mod tx_group; pub use builder::{ AcceptAsset, CallApplication, ClawbackAsset, ConfigureAsset, FreezeAsset, Pay, RegisterKey, - TransferAsset, Txn, + TransferAsset, TxnBuilder, }; pub use transaction::{SignedTransaction, Transaction, TransactionType}; diff --git a/examples/new_asa_sandnet.rs b/examples/new_asa_sandnet.rs index bcf1087e..341b311a 100644 --- a/examples/new_asa_sandnet.rs +++ b/examples/new_asa_sandnet.rs @@ -1,7 +1,7 @@ use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; use algonaut::kmd::KmdBuilder; -use algonaut::transaction::{ConfigureAsset, Txn}; +use algonaut::transaction::{ConfigureAsset, TxnBuilder}; use dotenv::dotenv; use std::env; use std::error::Error; @@ -45,7 +45,7 @@ async fn main() -> Result<(), Box> { println!("Last round: {}", params.last_round); // we are ready to build the transaction - let t = Txn::new() + let t = TxnBuilder::new() .sender(creator) .first_valid(params.last_round) .last_valid(params.last_round + 1000) diff --git a/examples/sign_offline.rs b/examples/sign_offline.rs index df6c45a2..f4b2669e 100644 --- a/examples/sign_offline.rs +++ b/examples/sign_offline.rs @@ -2,7 +2,7 @@ use algonaut::algod::AlgodBuilder; use algonaut::core::{MicroAlgos, ToMsgPack}; use algonaut::crypto::mnemonic; use algonaut::transaction::account::Account; -use algonaut::transaction::{Pay, Txn}; +use algonaut::transaction::{Pay, TxnBuilder}; use dotenv::dotenv; use std::env; use std::error::Error; @@ -31,7 +31,7 @@ async fn main() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(account.address()) .first_valid(params.last_round) .last_valid(params.last_round + 1000) diff --git a/examples/sign_submit_transaction.rs b/examples/sign_submit_transaction.rs index 4048802f..77570bb4 100644 --- a/examples/sign_submit_transaction.rs +++ b/examples/sign_submit_transaction.rs @@ -1,7 +1,7 @@ use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; use algonaut::kmd::KmdBuilder; -use algonaut::transaction::{Pay, Txn}; +use algonaut::transaction::{Pay, TxnBuilder}; use dotenv::dotenv; use std::env; use std::error::Error; @@ -44,7 +44,7 @@ async fn main() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(from_address) .first_valid(params.last_round) .last_valid(params.last_round + 1000) diff --git a/examples/sign_submit_transaction_sandnet.rs b/examples/sign_submit_transaction_sandnet.rs index f333f642..e7826bb6 100644 --- a/examples/sign_submit_transaction_sandnet.rs +++ b/examples/sign_submit_transaction_sandnet.rs @@ -1,7 +1,7 @@ use algonaut::algod::AlgodBuilder; use algonaut::core::MicroAlgos; use algonaut::kmd::KmdBuilder; -use algonaut::transaction::{Pay, Txn}; +use algonaut::transaction::{Pay, TxnBuilder}; use dotenv::dotenv; use std::env; use std::error::Error; @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box> { let params = algod.transaction_params().await?; // we are ready to build the transaction - let t = Txn::new() + let t = TxnBuilder::new() .sender(from_address) .first_valid(params.last_round) .last_valid(params.last_round + 10) diff --git a/tests/test_trasactions.rs b/tests/test_trasactions.rs index ad909858..f18c4040 100644 --- a/tests/test_trasactions.rs +++ b/tests/test_trasactions.rs @@ -5,7 +5,7 @@ use algonaut_core::SignedLogic; use algonaut_core::{LogicSignature, MicroAlgos, MultisigAddress, ToMsgPack}; use algonaut_transaction::transaction::TransactionSignature; use algonaut_transaction::tx_group::TxGroup; -use algonaut_transaction::{account::Account, ConfigureAsset, Pay, SignedTransaction, Txn}; +use algonaut_transaction::{account::Account, ConfigureAsset, Pay, SignedTransaction, TxnBuilder}; use dotenv::dotenv; use std::convert::TryInto; use std::env; @@ -27,7 +27,7 @@ async fn test_transaction() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(from.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -75,7 +75,7 @@ async fn test_multisig_transaction() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(multisig_address.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -143,7 +143,7 @@ byte 0xFF let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(from_address) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -204,7 +204,7 @@ int 1 let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(from.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -270,7 +270,7 @@ int 1 let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(multisig_address.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -325,7 +325,7 @@ async fn test_create_asset_transaction() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t = Txn::new() + let t = TxnBuilder::new() .sender(from.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -430,7 +430,7 @@ async fn test_atomic_swap() -> Result<(), Box> { let params = algod.transaction_params().await?; - let t1 = &mut Txn::new() + let t1 = &mut TxnBuilder::new() .sender(account1.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) @@ -445,7 +445,7 @@ async fn test_atomic_swap() -> Result<(), Box> { ) .build(); - let t2 = &mut Txn::new() + let t2 = &mut TxnBuilder::new() .sender(account2.address()) .first_valid(params.last_round) .last_valid(params.last_round + 10) From 8c59fb77a3ac6838038cd31d5a8230f1143a5a13 Mon Sep 17 00:00:00 2001 From: Ivan Schuetz Date: Fri, 18 Jun 2021 06:50:27 +0200 Subject: [PATCH 6/6] Rename module --- algonaut_transaction/src/{api_models.rs => api_model.rs} | 0 algonaut_transaction/src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename algonaut_transaction/src/{api_models.rs => api_model.rs} (100%) diff --git a/algonaut_transaction/src/api_models.rs b/algonaut_transaction/src/api_model.rs similarity index 100% rename from algonaut_transaction/src/api_models.rs rename to algonaut_transaction/src/api_model.rs diff --git a/algonaut_transaction/src/lib.rs b/algonaut_transaction/src/lib.rs index 54f0cef6..bd404f28 100644 --- a/algonaut_transaction/src/lib.rs +++ b/algonaut_transaction/src/lib.rs @@ -1,5 +1,5 @@ pub mod account; -mod api_models; +mod api_model; pub mod auction; pub mod builder; pub mod error;