|
1 |
| -use algokit_transact::{constants, ALGORAND_PUBLIC_KEY_BYTE_LENGTH}; |
2 |
| -use algokit_transact::{ |
3 |
| - AlgorandMsgpack, Byte32, EstimateTransactionSize, TransactionId, ALGORAND_SIGNATURE_BYTE_LENGTH, |
4 |
| -}; |
5 |
| -use ffi_macros::{ffi_func, ffi_record}; |
| 1 | +use algokit_transact::constants::*; |
| 2 | +use algokit_transact::{AlgorandMsgpack, Byte32, EstimateTransactionSize, TransactionId}; |
| 3 | +use ffi_macros::{ffi_enum, ffi_func, ffi_record}; |
6 | 4 | use serde::{Deserialize, Serialize};
|
7 | 5 | use serde_bytes::ByteBuf;
|
8 | 6 |
|
@@ -477,47 +475,51 @@ pub fn get_transaction_id(tx: &Transaction) -> Result<String, AlgoKitTransactErr
|
477 | 475 | Ok(tx_internal.id()?)
|
478 | 476 | }
|
479 | 477 |
|
480 |
| -#[ffi_func] |
481 |
| -pub fn get_hash_bytes_length() -> u64 { |
482 |
| - constants::HASH_BYTES_LENGTH.try_into().unwrap() |
483 |
| -} |
| 478 | +/// Enum containing all constants used in this crate. |
| 479 | +#[ffi_enum] |
| 480 | +pub enum AlgorandConstant { |
| 481 | + /// Length of hash digests (32) |
| 482 | + HashLength, |
484 | 483 |
|
485 |
| -#[ffi_func] |
486 |
| -pub fn get_algorand_checksum_byte_length() -> u64 { |
487 |
| - constants::ALGORAND_CHECKSUM_BYTE_LENGTH.try_into().unwrap() |
488 |
| -} |
| 484 | + /// Length of the checksum used in Algorand addresses (4) |
| 485 | + ChecksumLength, |
489 | 486 |
|
490 |
| -#[ffi_func] |
491 |
| -pub fn get_algorand_address_length() -> u64 { |
492 |
| - constants::ALGORAND_ADDRESS_LENGTH.try_into().unwrap() |
493 |
| -} |
| 487 | + /// Length of a base32-encoded Algorand address (58) |
| 488 | + AddressLength, |
494 | 489 |
|
495 |
| -#[ffi_func] |
496 |
| -pub fn get_algorand_public_key_byte_length() -> u64 { |
497 |
| - constants::ALGORAND_PUBLIC_KEY_BYTE_LENGTH |
498 |
| - .try_into() |
499 |
| - .unwrap() |
500 |
| -} |
| 490 | + /// Length of an Algorand public key in bytes (32) |
| 491 | + PublicKeyLength, |
501 | 492 |
|
502 |
| -#[ffi_func] |
503 |
| -pub fn get_algorand_secret_key_byte_length() -> u64 { |
504 |
| - constants::ALGORAND_SECRET_KEY_BYTE_LENGTH |
505 |
| - .try_into() |
506 |
| - .unwrap() |
| 493 | + /// Length of an Algorand secret key in bytes (32) |
| 494 | + SecretKeyLength, |
| 495 | + |
| 496 | + /// Length of an Algorand signature in bytes (64) |
| 497 | + SignatureLength, |
| 498 | + |
| 499 | + /// Increment in the encoded byte size when a signature is attached to a transaction (75) |
| 500 | + SignatureEncodingIncrLength, |
507 | 501 | }
|
508 | 502 |
|
509 |
| -#[ffi_func] |
510 |
| -pub fn get_algorand_signature_byte_length() -> u64 { |
511 |
| - constants::ALGORAND_SIGNATURE_BYTE_LENGTH |
512 |
| - .try_into() |
513 |
| - .unwrap() |
| 503 | +impl AlgorandConstant { |
| 504 | + /// Get the numeric value of the constant |
| 505 | + pub fn value(&self) -> u64 { |
| 506 | + match self { |
| 507 | + AlgorandConstant::HashLength => HASH_BYTES_LENGTH as u64, |
| 508 | + AlgorandConstant::ChecksumLength => ALGORAND_CHECKSUM_BYTE_LENGTH as u64, |
| 509 | + AlgorandConstant::AddressLength => ALGORAND_ADDRESS_LENGTH as u64, |
| 510 | + AlgorandConstant::PublicKeyLength => ALGORAND_PUBLIC_KEY_BYTE_LENGTH as u64, |
| 511 | + AlgorandConstant::SecretKeyLength => ALGORAND_SECRET_KEY_BYTE_LENGTH as u64, |
| 512 | + AlgorandConstant::SignatureLength => ALGORAND_SIGNATURE_BYTE_LENGTH as u64, |
| 513 | + AlgorandConstant::SignatureEncodingIncrLength => { |
| 514 | + ALGORAND_SIGNATURE_ENCODING_INCR as u64 |
| 515 | + } |
| 516 | + } |
| 517 | + } |
514 | 518 | }
|
515 | 519 |
|
516 | 520 | #[ffi_func]
|
517 |
| -pub fn get_algorand_signature_encoding_incr() -> u64 { |
518 |
| - constants::ALGORAND_SIGNATURE_ENCODING_INCR |
519 |
| - .try_into() |
520 |
| - .unwrap() |
| 521 | +pub fn get_algorand_constant(constant: AlgorandConstant) -> u64 { |
| 522 | + constant.value() |
521 | 523 | }
|
522 | 524 |
|
523 | 525 | #[cfg(test)]
|
|
0 commit comments