Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ node_modules/
.dmypy.json
.build
.bin/
.vscode/
.DS_Store
*.idea
wheelhouse/

# Android/Kotlin
.gradle/
build/
*.iml
local.properties
gradle-wrapper.jar
*.so

# Insta snapshot testing
*.snap.new
*.pending-snap
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ The exported interfaces should be purely functional without any state owned by R

## Contributing

## Build Scripts

`cargo pkg` will run the build script. For example: `cargo pkg transact kt` builds `algokit_transact` for `kotlin`.

The scripts are defined in [tools/build_pkgs] for each language.

### Learning Resources

If you are new to Rust or UniFFI, check out the [learning resources document](./docs/contributing/learning_resources.md)
Expand Down
10 changes: 5 additions & 5 deletions crates/algokit_transact/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl FromStr for Address {
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.len() != ALGORAND_ADDRESS_LENGTH {
return Err(AlgoKitTransactError::InvalidAddress {
message: "Algorand address must be exactly 58 characters".into(),
err_msg:"Algorand address must be exactly 58 characters".into(),
});
}
let decoded_address = base32::decode(base32::Alphabet::Rfc4648 { padding: false }, s)
.ok_or_else(|| AlgoKitTransactError::InvalidAddress {
message: "Invalid base32 encoding for Algorand address".into(),
err_msg:"Invalid base32 encoding for Algorand address".into(),
})?;

// Although this is called public key (and it actually is when the account is a `KeyPairAccount`),
Expand All @@ -80,18 +80,18 @@ impl FromStr for Address {
[..ALGORAND_PUBLIC_KEY_BYTE_LENGTH]
.try_into()
.map_err(|_| AlgoKitTransactError::InvalidAddress {
message: "Could not decode address into 32-byte public key".to_string(),
err_msg:"Could not decode address into 32-byte public key".to_string(),
})?;
let checksum: [u8; ALGORAND_CHECKSUM_BYTE_LENGTH] = decoded_address
[ALGORAND_PUBLIC_KEY_BYTE_LENGTH..]
.try_into()
.map_err(|_| AlgoKitTransactError::InvalidAddress {
message: "Could not get 4-byte checksum from decoded address".to_string(),
err_msg:"Could not get 4-byte checksum from decoded address".to_string(),
})?;

if pub_key_to_checksum(&pub_key) != checksum {
return Err(AlgoKitTransactError::InvalidAddress {
message: "Checksum is invalid".to_string(),
err_msg:"Checksum is invalid".to_string(),
});
}
Ok(Address(pub_key))
Expand Down
16 changes: 8 additions & 8 deletions crates/algokit_transact/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ pub enum AlgoKitTransactError {
#[snafu(display("Error ocurred during msgpack decoding: {source}"))]
MsgpackDecodingError { source: rmpv::decode::Error },

#[snafu(display("Unknown transaction type: {message}"))]
UnknownTransactionType { message: String },
#[snafu(display("Unknown transaction type: {err_msg}"))]
UnknownTransactionType { err_msg: String },

#[snafu(display("{message}"))]
InputError { message: String },
#[snafu(display("{err_msg}"))]
InputError { err_msg: String },

#[snafu(display("{message}"))]
InvalidAddress { message: String },
#[snafu(display("{err_msg}"))]
InvalidAddress { err_msg: String },

#[snafu(display("Invalid multisig signature: {message}"))]
InvalidMultisigSignature { message: String },
#[snafu(display("Invalid multisig signature: {err_msg}"))]
InvalidMultisigSignature { err_msg: String },
}

impl From<rmp_serde::encode::Error> for AlgoKitTransactError {
Expand Down
14 changes: 7 additions & 7 deletions crates/algokit_transact/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ impl MultisigSignature {
) -> Result<Self, AlgoKitTransactError> {
if version == 0 {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Version cannot be zero".to_string(),
err_msg:"Version cannot be zero".to_string(),
});
}
if subsignatures.is_empty() {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Subsignatures cannot be empty".to_string(),
err_msg:"Subsignatures cannot be empty".to_string(),
});
}
if threshold == 0 || threshold as usize > subsignatures.len() {
return Err(AlgoKitTransactError::InvalidMultisigSignature { message: "Threshold must be greater than zero and less than or equal to the number of sub-signers".to_string() });
return Err(AlgoKitTransactError::InvalidMultisigSignature { err_msg:"Threshold must be greater than zero and less than or equal to the number of sub-signers".to_string() });
}
Ok(Self {
version,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl MultisigSignature {
}
if !found {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Address not found in multisig signature".to_string(),
err_msg:"Address not found in multisig signature".to_string(),
});
}

Expand All @@ -161,17 +161,17 @@ impl MultisigSignature {
pub fn merge(&self, other: &Self) -> Result<Self, AlgoKitTransactError> {
if self.version != other.version {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Cannot merge multisig signatures with different versions".to_string(),
err_msg:"Cannot merge multisig signatures with different versions".to_string(),
});
}
if self.threshold != other.threshold {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Cannot merge multisig signatures with different thresholds".to_string(),
err_msg:"Cannot merge multisig signatures with different thresholds".to_string(),
});
}
if self.participants() != other.participants() {
return Err(AlgoKitTransactError::InvalidMultisigSignature {
message: "Cannot merge multisig signatures with different participants".to_string(),
err_msg:"Cannot merge multisig signatures with different participants".to_string(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/algokit_transact/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait AlgorandMsgpack: Serialize + for<'de> Deserialize<'de> {
fn decode(bytes: &[u8]) -> Result<Self, AlgoKitTransactError> {
if bytes.is_empty() {
return Err(AlgoKitTransactError::InputError {
message: "attempted to decode 0 bytes".to_string(),
err_msg:"attempted to decode 0 bytes".to_string(),
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/algokit_transact/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Transaction {
if let Some(max_fee) = request.max_fee {
if calculated_fee > max_fee {
return Err(AlgoKitTransactError::InputError {
message: format!(
err_msg:format!(
"Transaction fee {} µALGO is greater than max fee {} µALGO",
calculated_fee, max_fee
),
Expand Down Expand Up @@ -207,7 +207,7 @@ impl AlgorandMsgpack for SignedTransaction {
Ok(stxn)
}
_ => Err(AlgoKitTransactError::InputError {
message: format!(
err_msg:format!(
"expected signed transaction to be a map, but got a: {:#?}",
value.type_id()
),
Expand Down
2 changes: 1 addition & 1 deletion crates/algokit_transact/src/transactions/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod tests {
let msg = format!("{}", err);
assert!(
msg == "Transaction fee 2470 µALGO is greater than max fee 1000 µALGO",
"Unexpected error message: {}",
"Unexpected error err_msg:{}",
msg
);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/algokit_transact/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ pub fn hash(bytes: &Vec<u8>) -> Byte32 {
pub fn compute_group(txs: &[Transaction]) -> Result<Byte32, AlgoKitTransactError> {
if txs.is_empty() {
return Err(AlgoKitTransactError::InputError {
message: String::from("Transaction group size cannot be 0"),
err_msg:String::from("Transaction group size cannot be 0"),
});
}

if txs.len() > MAX_TX_GROUP_SIZE {
return Err(AlgoKitTransactError::InputError {
message: format!(
err_msg:format!(
"Transaction group size exceeds the max limit of {}",
MAX_TX_GROUP_SIZE
),
Expand All @@ -124,7 +124,7 @@ pub fn compute_group(txs: &[Transaction]) -> Result<Byte32, AlgoKitTransactError
.map(|tx| {
if tx.header().group.is_some() {
return Err(AlgoKitTransactError::InputError {
message: "Transactions must not already be grouped".to_string(),
err_msg:"Transactions must not already be grouped".to_string(),
});
}
tx.id_raw()
Expand Down
46 changes: 23 additions & 23 deletions crates/algokit_transact_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ use snafu::Snafu;
#[derive(Debug, Snafu)]
#[cfg_attr(feature = "ffi_uniffi", derive(uniffi::Error))]
pub enum AlgoKitTransactError {
#[snafu(display("EncodingError: {message}"))]
EncodingError { message: String },
#[snafu(display("DecodingError: {message}"))]
DecodingError { message: String },
#[snafu(display("{message}"))]
InputError { message: String },
#[snafu(display("MsgPackError: {message}"))]
MsgPackError { message: String },
#[snafu(display("EncodingError: {error_msg}"))]
EncodingError { error_msg: String },
#[snafu(display("DecodingError: {error_msg}"))]
DecodingError { error_msg: String },
#[snafu(display("{error_msg}"))]
InputError { error_msg: String },
#[snafu(display("MsgPackError: {error_msg}"))]
MsgPackError { error_msg: String },
}

// Convert errors from the Rust crate into the FFI-specific errors
Expand All @@ -39,40 +39,40 @@ impl From<algokit_transact::AlgoKitTransactError> for AlgoKitTransactError {
match e {
algokit_transact::AlgoKitTransactError::DecodingError { .. } => {
AlgoKitTransactError::DecodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::EncodingError { .. } => {
AlgoKitTransactError::EncodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::MsgpackDecodingError { .. } => {
AlgoKitTransactError::DecodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::MsgpackEncodingError { .. } => {
AlgoKitTransactError::EncodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::UnknownTransactionType { .. } => {
AlgoKitTransactError::DecodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::InputError { message } => {
AlgoKitTransactError::InputError { message }
algokit_transact::AlgoKitTransactError::InputError { err_msg: message } => {
AlgoKitTransactError::InputError { error_msg: message }
}
algokit_transact::AlgoKitTransactError::InvalidAddress { .. } => {
AlgoKitTransactError::DecodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
algokit_transact::AlgoKitTransactError::InvalidMultisigSignature { .. } => {
AlgoKitTransactError::DecodingError {
message: e.to_string(),
error_msg: e.to_string(),
}
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl TryFrom<KeyPairAccount> for algokit_transact::KeyPairAccount {
let pub_key: [u8; ALGORAND_PUBLIC_KEY_BYTE_LENGTH] =
vec_to_array(&value.pub_key, "public key").map_err(|e| {
AlgoKitTransactError::DecodingError {
message: format!("Error while decoding a public key: {}", e),
error_msg: format!("Error while decoding a public key: {}", e),
}
})?;

Expand Down Expand Up @@ -212,7 +212,7 @@ impl TryFrom<Transaction> for algokit_transact::Transaction {
> 1
{
return Err(Self::Error::DecodingError {
message: "Multiple transaction type specific fields set".to_string(),
error_msg: "Multiple transaction type specific fields set".to_string(),
});
}

Expand Down Expand Up @@ -393,7 +393,7 @@ impl TryFrom<SignedTransaction> for algokit_transact::SignedTransaction {
.map(|sig| vec_to_array(&sig, "signature"))
.transpose()
.map_err(|e| AlgoKitTransactError::DecodingError {
message: format!(
error_msg: format!(
"Error while decoding the signature in a signed transaction: {}",
e
),
Expand All @@ -417,7 +417,7 @@ fn vec_to_array<const N: usize>(
buf.to_vec()
.try_into()
.map_err(|_| AlgoKitTransactError::DecodingError {
message: format!(
error_msg: format!(
"Expected {} {} bytes but got {} bytes",
context,
N,
Expand Down Expand Up @@ -544,7 +544,7 @@ pub fn estimate_transaction_size(transaction: Transaction) -> Result<u64, AlgoKi
.estimate_size()?
.try_into()
.map_err(|_| AlgoKitTransactError::EncodingError {
message: "Failed to convert size to u64".to_string(),
error_msg: "Failed to convert size to u64".to_string(),
})
}

Expand All @@ -553,7 +553,7 @@ pub fn address_from_public_key(public_key: &[u8]) -> Result<String, AlgoKitTrans
Ok(
algokit_transact::KeyPairAccount::from_pubkey(public_key.try_into().map_err(|_| {
AlgoKitTransactError::EncodingError {
message: format!(
error_msg: format!(
"public key should be {} bytes",
ALGORAND_PUBLIC_KEY_BYTE_LENGTH
),
Expand Down
4 changes: 2 additions & 2 deletions crates/algokit_transact_ffi/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl TryFrom<MultisigSubsignature> for algokit_transact::MultisigSubsignature {
.map(|sig| vec_to_array(&sig, "signature"))
.transpose()
.map_err(|e| AlgoKitTransactError::DecodingError {
message: format!("Error while decoding a subsignature: {}", e),
error_msg:format!("Error while decoding a subsignature: {}", e),
})?,
})
}
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn apply_multisig_subsignature(
subsignature
.try_into()
.map_err(|_| AlgoKitTransactError::EncodingError {
message: format!(
error_msg:format!(
"signature should be {} bytes",
ALGORAND_SIGNATURE_BYTE_LENGTH
),
Expand Down
4 changes: 2 additions & 2 deletions crates/algokit_transact_ffi/src/transactions/app_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TryFrom<Transaction> for algokit_transact::AppCallTransactionFields {
fn try_from(tx: Transaction) -> Result<Self, Self::Error> {
if tx.transaction_type != TransactionType::AppCall || tx.app_call.is_none() {
return Err(Self::Error::DecodingError {
message: "AppCall call data missing".to_string(),
error_msg:"AppCall call data missing".to_string(),
});
}

Expand Down Expand Up @@ -135,7 +135,7 @@ impl TryFrom<Transaction> for algokit_transact::AppCallTransactionFields {
transaction_fields
.validate()
.map_err(|errors| AlgoKitTransactError::DecodingError {
message: format!("App call validation failed: {}", errors.join("\n")),
error_msg:format!("App call validation failed: {}", errors.join("\n")),
})?;

Ok(transaction_fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TryFrom<Transaction> for algokit_transact::AssetConfigTransactionFields {
fn try_from(tx: Transaction) -> Result<Self, Self::Error> {
if tx.transaction_type != TransactionType::AssetConfig || tx.asset_config.is_none() {
return Err(Self::Error::DecodingError {
message: "Asset configuration data missing".to_string(),
error_msg:"Asset configuration data missing".to_string(),
});
}

Expand Down Expand Up @@ -170,7 +170,7 @@ impl TryFrom<Transaction> for algokit_transact::AssetConfigTransactionFields {
transaction_fields
.validate()
.map_err(|errors| AlgoKitTransactError::DecodingError {
message: format!("Asset config validation failed: {}", errors.join("\n")),
error_msg:format!("Asset config validation failed: {}", errors.join("\n")),
})?;

Ok(transaction_fields)
Expand Down
Loading
Loading