File tree Expand file tree Collapse file tree 15 files changed +1789
-82
lines changed
crates/algokit_utils_ffi/src/abi
packages/python/algokit_utils Expand file tree Collapse file tree 15 files changed +1789
-82
lines changed Original file line number Diff line number Diff line change 11use algokit_abi:: ABIType as RustABIType ;
22
3+ use crate :: abi:: abi_value:: ABIValue ;
4+
35use super :: { ABIType , FfiToRustABIType } ;
46
57#[ derive( uniffi:: Object , Clone ) ]
@@ -23,8 +25,19 @@ impl From<RustABIType> for ABIAddress {
2325
2426impl FfiToRustABIType for ABIAddress {
2527 fn to_rust_abi_type ( & self ) -> RustABIType {
26- ( * self ) . clone ( ) . into ( )
28+ self . clone ( ) . into ( )
2729 }
2830}
2931
30- impl ABIType for ABIAddress { }
32+ #[ uniffi:: export]
33+ impl ABIType for ABIAddress {
34+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
35+ let rust_abi_type = self . to_rust_abi_type ( ) ;
36+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
37+ }
38+
39+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
40+ let rust_abi_type = self . to_rust_abi_type ( ) ;
41+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
42+ }
43+ }
Original file line number Diff line number Diff line change 11use algokit_abi:: ABIType as RustABIType ;
22
3+ use crate :: abi:: abi_value:: ABIValue ;
4+
35use super :: { ABIType , FfiToRustABIType } ;
46
57#[ derive( uniffi:: Object , Clone ) ]
@@ -23,8 +25,28 @@ impl From<RustABIType> for ABIBool {
2325
2426impl FfiToRustABIType for ABIBool {
2527 fn to_rust_abi_type ( & self ) -> RustABIType {
26- ( * self ) . clone ( ) . into ( )
28+ self . clone ( ) . into ( )
29+ }
30+ }
31+
32+ #[ uniffi:: export]
33+ impl ABIBool {
34+ #[ allow( clippy:: new_without_default) ]
35+ #[ uniffi:: constructor]
36+ pub fn new ( ) -> Self {
37+ ABIBool { }
2738 }
2839}
2940
30- impl ABIType for ABIBool { }
41+ #[ uniffi:: export]
42+ impl ABIType for ABIBool {
43+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
44+ let rust_abi_type = self . to_rust_abi_type ( ) ;
45+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
46+ }
47+
48+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
49+ let rust_abi_type = self . to_rust_abi_type ( ) ;
50+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ use crate :: abi:: abi_value:: ABIValue ;
2+
13use super :: { ABIType , FfiToRustABIType } ;
24use algokit_abi:: ABIType as RustABIType ;
35
@@ -22,8 +24,19 @@ impl From<RustABIType> for ABIByte {
2224
2325impl FfiToRustABIType for ABIByte {
2426 fn to_rust_abi_type ( & self ) -> RustABIType {
25- ( * self ) . clone ( ) . into ( )
27+ self . clone ( ) . into ( )
2628 }
2729}
2830
29- impl ABIType for ABIByte { }
31+ #[ uniffi:: export]
32+ impl ABIType for ABIByte {
33+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
34+ let rust_abi_type = self . to_rust_abi_type ( ) ;
35+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
36+ }
37+
38+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
39+ let rust_abi_type = self . to_rust_abi_type ( ) ;
40+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ use std::sync::Arc;
22
33use algokit_abi:: ABIType as RustABIType ;
44
5+ use crate :: abi:: abi_value:: ABIValue ;
6+
57use super :: { ABIType , FfiToRustABIType , RustToFfiABIType } ;
68
79#[ derive( uniffi:: Object , Clone ) ]
@@ -29,8 +31,31 @@ impl From<RustABIType> for ABIDynamicArray {
2931
3032impl FfiToRustABIType for ABIDynamicArray {
3133 fn to_rust_abi_type ( & self ) -> RustABIType {
32- ( * self ) . clone ( ) . into ( )
34+ eprintln ! ( "DEBUGPRINT[43]: dynamic_array.rs:34 (before let cloned = self.clone();)" ) ;
35+ let cloned = self . clone ( ) ;
36+ eprintln ! ( "DEBUGPRINT[44]: dynamic_array.rs:35 (after let cloned = self.clone();)" ) ;
37+
38+ cloned. into ( )
3339 }
3440}
3541
36- impl ABIType for ABIDynamicArray { }
42+ #[ uniffi:: export]
43+ impl ABIType for ABIDynamicArray {
44+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
45+ let rust_abi_type = self . to_rust_abi_type ( ) ;
46+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
47+ }
48+
49+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
50+ let rust_abi_type = self . to_rust_abi_type ( ) ;
51+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
52+ }
53+ }
54+
55+ #[ uniffi:: export]
56+ impl ABIDynamicArray {
57+ #[ uniffi:: constructor]
58+ pub fn new ( element_type : Arc < dyn ABIType > ) -> Self {
59+ ABIDynamicArray { element_type }
60+ }
61+ }
Original file line number Diff line number Diff line change @@ -49,15 +49,11 @@ impl RustToFfiABIType for RustABIType {
4949 }
5050}
5151
52+ // NOTE: Exported traits cannot have default implementations, so we must implement in each ABIType
53+ // See https://github.com/mozilla/uniffi-rs/pull/2598
5254#[ uniffi:: export]
5355pub trait ABIType : Send + Sync + FfiToRustABIType {
54- fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
55- let rust_abi_type = self . to_rust_abi_type ( ) ;
56- ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
57- }
56+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue ;
5857
59- fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
60- let rust_abi_type = self . to_rust_abi_type ( ) ;
61- rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
62- }
58+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > ;
6359}
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ use std::sync::Arc;
22
33use algokit_abi:: ABIType as RustABIType ;
44
5+ use crate :: abi:: abi_value:: ABIValue ;
6+
57use super :: { ABIType , FfiToRustABIType , RustToFfiABIType } ;
68
79#[ derive( uniffi:: Object , Clone ) ]
@@ -34,8 +36,19 @@ impl From<RustABIType> for ABIStaticArray {
3436
3537impl FfiToRustABIType for ABIStaticArray {
3638 fn to_rust_abi_type ( & self ) -> RustABIType {
37- ( * self ) . clone ( ) . into ( )
39+ self . clone ( ) . into ( )
3840 }
3941}
4042
41- impl ABIType for ABIStaticArray { }
43+ #[ uniffi:: export]
44+ impl ABIType for ABIStaticArray {
45+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
46+ let rust_abi_type = self . to_rust_abi_type ( ) ;
47+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
48+ }
49+
50+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
51+ let rust_abi_type = self . to_rust_abi_type ( ) ;
52+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
53+ }
54+ }
Original file line number Diff line number Diff line change 11use algokit_abi:: ABIType as RustABIType ;
22
3+ use crate :: abi:: abi_value:: ABIValue ;
4+
35use super :: { ABIType , FfiToRustABIType } ;
46
57#[ derive( uniffi:: Object , Clone ) ]
@@ -23,8 +25,19 @@ impl From<RustABIType> for ABIString {
2325
2426impl FfiToRustABIType for ABIString {
2527 fn to_rust_abi_type ( & self ) -> RustABIType {
26- ( * self ) . clone ( ) . into ( )
28+ self . clone ( ) . into ( )
2729 }
2830}
2931
30- impl ABIType for ABIString { }
32+ #[ uniffi:: export]
33+ impl ABIType for ABIString {
34+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
35+ let rust_abi_type = self . to_rust_abi_type ( ) ;
36+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
37+ }
38+
39+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
40+ let rust_abi_type = self . to_rust_abi_type ( ) ;
41+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ use std::sync::Arc;
22
33use algokit_abi:: ABIType as RustABIType ;
44
5+ use crate :: abi:: abi_value:: ABIValue ;
6+
57use super :: RustToFfiABIType ;
68use super :: { ABIType , FfiToRustABIType } ;
79
@@ -12,12 +14,10 @@ pub struct ABITuple {
1214
1315impl FfiToRustABIType for ABITuple {
1416 fn to_rust_abi_type ( & self ) -> RustABIType {
15- ( * self ) . clone ( ) . into ( )
17+ self . clone ( ) . into ( )
1618 }
1719}
1820
19- impl ABIType for ABITuple { }
20-
2121impl From < ABITuple > for RustABIType {
2222 fn from ( value : ABITuple ) -> Self {
2323 let rust_components = value
@@ -42,3 +42,16 @@ impl From<RustABIType> for ABITuple {
4242 }
4343 }
4444}
45+
46+ #[ uniffi:: export]
47+ impl ABIType for ABITuple {
48+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
49+ let rust_abi_type = self . to_rust_abi_type ( ) ;
50+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
51+ }
52+
53+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
54+ let rust_abi_type = self . to_rust_abi_type ( ) ;
55+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
56+ }
57+ }
Original file line number Diff line number Diff line change 11use algokit_abi:: abi_type:: BitSize ;
22use algokit_abi:: { ABIType as RustABIType , abi_type:: Precision } ;
33
4+ use crate :: abi:: abi_value:: ABIValue ;
5+
46use super :: { ABIType , FfiToRustABIType } ;
57
68#[ derive( uniffi:: Object , Clone ) ]
@@ -33,8 +35,19 @@ impl From<RustABIType> for ABIUfixed {
3335
3436impl FfiToRustABIType for ABIUfixed {
3537 fn to_rust_abi_type ( & self ) -> RustABIType {
36- ( * self ) . clone ( ) . into ( )
38+ self . clone ( ) . into ( )
3739 }
3840}
3941
40- impl ABIType for ABIUfixed { }
42+ #[ uniffi:: export]
43+ impl ABIType for ABIUfixed {
44+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
45+ let rust_abi_type = self . to_rust_abi_type ( ) ;
46+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
47+ }
48+
49+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
50+ let rust_abi_type = self . to_rust_abi_type ( ) ;
51+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
52+ }
53+ }
Original file line number Diff line number Diff line change 11use algokit_abi:: ABIType as RustABIType ;
22use algokit_abi:: abi_type:: BitSize ;
33
4+ use crate :: abi:: abi_value:: ABIValue ;
5+
46use super :: { ABIType , FfiToRustABIType } ;
57
68#[ derive( uniffi:: Object , Clone ) ]
@@ -28,8 +30,19 @@ impl From<RustABIType> for ABIUint {
2830
2931impl FfiToRustABIType for ABIUint {
3032 fn to_rust_abi_type ( & self ) -> RustABIType {
31- ( * self ) . clone ( ) . into ( )
33+ self . clone ( ) . into ( )
3234 }
3335}
3436
35- impl ABIType for ABIUint { }
37+ #[ uniffi:: export]
38+ impl ABIType for ABIUint {
39+ fn decoode ( & self , data : & [ u8 ] ) -> ABIValue {
40+ let rust_abi_type = self . to_rust_abi_type ( ) ;
41+ ABIValue :: from ( rust_abi_type. decode ( data) . unwrap ( ) )
42+ }
43+
44+ fn encode ( & self , value : ABIValue ) -> Vec < u8 > {
45+ let rust_abi_type = self . to_rust_abi_type ( ) ;
46+ rust_abi_type. encode ( & value. into ( ) ) . unwrap ( )
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments