@@ -13,7 +13,9 @@ pub use multisig::{MultisigSignature, MultisigSubsignature};
1313pub use transactions:: ApplicationCallTransactionFields ;
1414pub use transactions:: AssetConfigTransactionFields ;
1515pub use transactions:: AssetFreezeTransactionFields ;
16+ pub use transactions:: AssetTransferTransactionFields ;
1617pub use transactions:: KeyRegistrationTransactionFields ;
18+ pub use transactions:: PaymentTransactionFields ;
1719
1820// thiserror is used to easily create errors than can be propagated to the language bindings
1921// UniFFI will create classes for errors (i.e. `MsgPackError.EncodingError` in Python)
@@ -172,28 +174,6 @@ pub struct FeeParams {
172174 max_fee : Option < u64 > ,
173175}
174176
175- #[ ffi_record]
176- pub struct PaymentTransactionFields {
177- receiver : String ,
178-
179- amount : u64 ,
180-
181- close_remainder_to : Option < String > ,
182- }
183-
184- #[ ffi_record]
185- pub struct AssetTransferTransactionFields {
186- asset_id : u64 ,
187-
188- amount : u64 ,
189-
190- receiver : String ,
191-
192- asset_sender : Option < String > ,
193-
194- close_remainder_to : Option < String > ,
195- }
196-
197177#[ ffi_record]
198178pub struct Transaction {
199179 /// The type of transaction
@@ -310,80 +290,6 @@ impl TryFrom<Transaction> for algokit_transact::TransactionHeader {
310290 }
311291}
312292
313- impl From < algokit_transact:: PaymentTransactionFields > for PaymentTransactionFields {
314- fn from ( tx : algokit_transact:: PaymentTransactionFields ) -> Self {
315- Self {
316- receiver : tx. receiver . as_str ( ) ,
317- amount : tx. amount ,
318- close_remainder_to : tx. close_remainder_to . map ( |addr| addr. as_str ( ) ) ,
319- }
320- }
321- }
322-
323- impl TryFrom < Transaction > for algokit_transact:: PaymentTransactionFields {
324- type Error = AlgoKitTransactError ;
325-
326- fn try_from ( tx : Transaction ) -> Result < Self , Self :: Error > {
327- if tx. transaction_type != TransactionType :: Payment || tx. payment . is_none ( ) {
328- return Err ( Self :: Error :: DecodingError (
329- "Payment data missing" . to_string ( ) ,
330- ) ) ;
331- }
332-
333- let data = tx. clone ( ) . payment . unwrap ( ) ;
334- let header: algokit_transact:: TransactionHeader = tx. try_into ( ) ?;
335-
336- Ok ( Self {
337- header,
338- amount : data. amount ,
339- receiver : data. receiver . parse ( ) ?,
340- close_remainder_to : data
341- . close_remainder_to
342- . map ( |addr| addr. parse ( ) )
343- . transpose ( ) ?,
344- } )
345- }
346- }
347-
348- impl From < algokit_transact:: AssetTransferTransactionFields > for AssetTransferTransactionFields {
349- fn from ( tx : algokit_transact:: AssetTransferTransactionFields ) -> Self {
350- Self {
351- asset_id : tx. asset_id ,
352- amount : tx. amount ,
353- receiver : tx. receiver . as_str ( ) ,
354- asset_sender : tx. asset_sender . map ( |addr| addr. as_str ( ) ) ,
355- close_remainder_to : tx. close_remainder_to . map ( |addr| addr. as_str ( ) ) ,
356- }
357- }
358- }
359-
360- impl TryFrom < Transaction > for algokit_transact:: AssetTransferTransactionFields {
361- type Error = AlgoKitTransactError ;
362-
363- fn try_from ( tx : Transaction ) -> Result < Self , Self :: Error > {
364- if tx. transaction_type != TransactionType :: AssetTransfer || tx. asset_transfer . is_none ( ) {
365- return Err ( Self :: Error :: DecodingError (
366- "Asset Transfer data missing" . to_string ( ) ,
367- ) ) ;
368- }
369-
370- let data = tx. clone ( ) . asset_transfer . unwrap ( ) ;
371- let header: algokit_transact:: TransactionHeader = tx. try_into ( ) ?;
372-
373- Ok ( Self {
374- header,
375- asset_id : data. asset_id ,
376- amount : data. amount ,
377- receiver : data. receiver . parse ( ) ?,
378- asset_sender : data. asset_sender . map ( |addr| addr. parse ( ) ) . transpose ( ) ?,
379- close_remainder_to : data
380- . close_remainder_to
381- . map ( |addr| addr. parse ( ) )
382- . transpose ( ) ?,
383- } )
384- }
385- }
386-
387293impl TryFrom < algokit_transact:: Transaction > for Transaction {
388294 type Error = AlgoKitTransactError ;
389295
@@ -943,65 +849,9 @@ pub fn encode_signed_transactions(
943849#[ cfg( test) ]
944850mod tests {
945851 use super :: * ;
946- use algokit_transact:: test_utils:: { TestDataMother , TransactionMother } ;
852+ use algokit_transact:: test_utils:: TestDataMother ;
947853 use pretty_assertions:: assert_eq;
948854
949- #[ test]
950- fn test_get_encoded_payment_transaction_type ( ) {
951- let txn: Transaction = TransactionMother :: simple_payment ( )
952- . build ( )
953- . unwrap ( )
954- . try_into ( )
955- . unwrap ( ) ;
956-
957- // Encode the transaction
958- let encoded = encode_transaction ( txn) . unwrap ( ) ;
959-
960- // Test the get_encoded_transaction_type function
961- let tx_type = get_encoded_transaction_type ( & encoded) . unwrap ( ) ;
962- assert_eq ! ( tx_type, TransactionType :: Payment ) ;
963- }
964-
965- #[ test]
966- fn test_get_encoded_asset_transfer_transaction_type ( ) {
967- let txn: Transaction = TransactionMother :: simple_asset_transfer ( )
968- . build ( )
969- . unwrap ( )
970- . try_into ( )
971- . unwrap ( ) ;
972-
973- // Encode the transaction
974- let encoded = encode_transaction ( txn) . unwrap ( ) ;
975-
976- // Test the get_encoded_transaction_type function
977- let tx_type = get_encoded_transaction_type ( & encoded) . unwrap ( ) ;
978- assert_eq ! ( tx_type, TransactionType :: AssetTransfer ) ;
979- }
980-
981- #[ test]
982- fn test_payment_transaction_id_ffi ( ) {
983- let data = TestDataMother :: simple_payment ( ) ;
984- let tx_ffi: Transaction = data. transaction . try_into ( ) . unwrap ( ) ;
985-
986- let actual_id = get_transaction_id ( tx_ffi. clone ( ) ) . unwrap ( ) ;
987- let actual_id_raw = get_transaction_id_raw ( tx_ffi. clone ( ) ) . unwrap ( ) ;
988-
989- assert_eq ! ( actual_id, data. id) ;
990- assert_eq ! ( actual_id_raw, data. id_raw) ;
991- }
992-
993- #[ test]
994- fn test_asset_transfer_transaction_id_ffi ( ) {
995- let data = TestDataMother :: simple_asset_transfer ( ) ;
996- let tx_ffi: Transaction = data. transaction . try_into ( ) . unwrap ( ) ;
997-
998- let actual_id = get_transaction_id ( tx_ffi. clone ( ) ) . unwrap ( ) ;
999- let actual_id_raw = get_transaction_id_raw ( tx_ffi. clone ( ) ) . unwrap ( ) ;
1000-
1001- assert_eq ! ( actual_id, data. id) ;
1002- assert_eq ! ( actual_id_raw, data. id_raw) ;
1003- }
1004-
1005855 #[ test]
1006856 fn test_group_transactions_ffi ( ) {
1007857 let expected_group = [
0 commit comments