Skip to content

Commit f29f72d

Browse files
committed
feat: added asset freeze to ak-utils ffi
Added asset freeze test to the current compose tests
1 parent 3aa6d3b commit f29f72d

File tree

7 files changed

+157
-6
lines changed

7 files changed

+157
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::transactions::common::UtilsError;
2+
3+
use super::common::CommonParams;
4+
use algokit_utils::transactions::AssetFreezeParams as RustAssetFreezeParams;
5+
6+
#[derive(uniffi::Record)]
7+
pub struct AssetFreezeParams {
8+
/// Common transaction parameters.
9+
pub common_params: CommonParams,
10+
11+
/// The ID of the asset being frozen.
12+
pub asset_id: u64,
13+
14+
/// The target account whose asset holdings will be frozen.
15+
pub target_address: String,
16+
}
17+
18+
impl TryFrom<AssetFreezeParams> for RustAssetFreezeParams {
19+
type Error = UtilsError;
20+
21+
fn try_from(params: AssetFreezeParams) -> Result<Self, Self::Error> {
22+
let common_params = params.common_params.try_into()?;
23+
Ok(RustAssetFreezeParams {
24+
common_params,
25+
asset_id: params.asset_id,
26+
target_address: params
27+
.target_address
28+
.parse()
29+
.map_err(|_| UtilsError::UtilsError {
30+
message: "Invalid target address".to_string(),
31+
})?,
32+
})
33+
}
34+
}

crates/algokit_utils_ffi/src/transactions/composer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ impl Composer {
6161
})
6262
}
6363

64+
pub fn add_asset_freeze(&self, params: super::asset_freeze::AssetFreezeParams) -> Result<(), UtilsError> {
65+
let mut composer = self.inner_composer.blocking_lock();
66+
composer
67+
.add_asset_freeze(params.try_into()?)
68+
.map_err(|e| UtilsError::UtilsError {
69+
message: e.to_string(),
70+
})
71+
}
72+
6473
pub async fn send(&self) -> Result<Vec<String>, UtilsError> {
6574
let mut composer = self.inner_composer.blocking_lock();
6675
let result = composer
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod common;
22
pub mod composer;
33
pub mod payment;
4+
pub mod asset_freeze;

packages/python/algokit_utils/algokit_utils/algokit_utils_ffi.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ def _uniffi_check_contract_api_version(lib):
470470
raise InternalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
471471

472472
def _uniffi_check_api_checksums(lib):
473+
if lib.uniffi_algokit_utils_ffi_checksum_method_composer_add_asset_freeze() != 44087:
474+
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
473475
if lib.uniffi_algokit_utils_ffi_checksum_method_composer_add_payment() != 9188:
474476
raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
475477
if lib.uniffi_algokit_utils_ffi_checksum_method_composer_build() != 13184:
@@ -641,6 +643,12 @@ class _UniffiVTableCallbackInterfaceTransactionSignerGetter(ctypes.Structure):
641643
ctypes.POINTER(_UniffiRustCallStatus),
642644
)
643645
_UniffiLib.uniffi_algokit_utils_ffi_fn_constructor_composer_new.restype = ctypes.c_void_p
646+
_UniffiLib.uniffi_algokit_utils_ffi_fn_method_composer_add_asset_freeze.argtypes = (
647+
ctypes.c_void_p,
648+
_UniffiRustBuffer,
649+
ctypes.POINTER(_UniffiRustCallStatus),
650+
)
651+
_UniffiLib.uniffi_algokit_utils_ffi_fn_method_composer_add_asset_freeze.restype = None
644652
_UniffiLib.uniffi_algokit_utils_ffi_fn_method_composer_add_payment.argtypes = (
645653
ctypes.c_void_p,
646654
_UniffiRustBuffer,
@@ -968,6 +976,9 @@ class _UniffiVTableCallbackInterfaceTransactionSignerGetter(ctypes.Structure):
968976
ctypes.POINTER(_UniffiRustCallStatus),
969977
)
970978
_UniffiLib.ffi_algokit_utils_ffi_rust_future_complete_void.restype = None
979+
_UniffiLib.uniffi_algokit_utils_ffi_checksum_method_composer_add_asset_freeze.argtypes = (
980+
)
981+
_UniffiLib.uniffi_algokit_utils_ffi_checksum_method_composer_add_asset_freeze.restype = ctypes.c_uint16
971982
_UniffiLib.uniffi_algokit_utils_ffi_checksum_method_composer_add_payment.argtypes = (
972983
)
973984
_UniffiLib.uniffi_algokit_utils_ffi_checksum_method_composer_add_payment.restype = ctypes.c_uint16
@@ -1120,6 +1131,61 @@ def write(value, buf):
11201131

11211132

11221133

1134+
class AssetFreezeParams:
1135+
common_params: "CommonParams"
1136+
"""
1137+
Common transaction parameters.
1138+
"""
1139+
1140+
asset_id: "int"
1141+
"""
1142+
The ID of the asset being frozen.
1143+
"""
1144+
1145+
target_address: "str"
1146+
"""
1147+
The target account whose asset holdings will be frozen.
1148+
"""
1149+
1150+
def __init__(self, *, common_params: "CommonParams", asset_id: "int", target_address: "str"):
1151+
self.common_params = common_params
1152+
self.asset_id = asset_id
1153+
self.target_address = target_address
1154+
1155+
def __str__(self):
1156+
return "AssetFreezeParams(common_params={}, asset_id={}, target_address={})".format(self.common_params, self.asset_id, self.target_address)
1157+
1158+
def __eq__(self, other):
1159+
if self.common_params != other.common_params:
1160+
return False
1161+
if self.asset_id != other.asset_id:
1162+
return False
1163+
if self.target_address != other.target_address:
1164+
return False
1165+
return True
1166+
1167+
class _UniffiConverterTypeAssetFreezeParams(_UniffiConverterRustBuffer):
1168+
@staticmethod
1169+
def read(buf):
1170+
return AssetFreezeParams(
1171+
common_params=_UniffiConverterTypeCommonParams.read(buf),
1172+
asset_id=_UniffiConverterUInt64.read(buf),
1173+
target_address=_UniffiConverterString.read(buf),
1174+
)
1175+
1176+
@staticmethod
1177+
def check_lower(value):
1178+
_UniffiConverterTypeCommonParams.check_lower(value.common_params)
1179+
_UniffiConverterUInt64.check_lower(value.asset_id)
1180+
_UniffiConverterString.check_lower(value.target_address)
1181+
1182+
@staticmethod
1183+
def write(value, buf):
1184+
_UniffiConverterTypeCommonParams.write(value.common_params, buf)
1185+
_UniffiConverterUInt64.write(value.asset_id, buf)
1186+
_UniffiConverterString.write(value.target_address, buf)
1187+
1188+
11231189
class CommonParams:
11241190
sender: "str"
11251191
signer: "typing.Optional[TransactionSigner]"
@@ -1938,6 +2004,8 @@ def read(cls, buf: _UniffiRustBuffer):
19382004
def write(cls, value: AlgodClientProtocol, buf: _UniffiRustBuffer):
19392005
buf.write_u64(cls.lower(value))
19402006
class ComposerProtocol(typing.Protocol):
2007+
def add_asset_freeze(self, params: "AssetFreezeParams"):
2008+
raise NotImplementedError
19412009
def add_payment(self, params: "PaymentParams"):
19422010
raise NotImplementedError
19432011
def build(self, ):
@@ -1975,6 +2043,17 @@ def _make_instance_(cls, pointer):
19752043
return inst
19762044

19772045

2046+
def add_asset_freeze(self, params: "AssetFreezeParams") -> None:
2047+
_UniffiConverterTypeAssetFreezeParams.check_lower(params)
2048+
2049+
_uniffi_rust_call_with_error(_UniffiConverterTypeUtilsError,_UniffiLib.uniffi_algokit_utils_ffi_fn_method_composer_add_asset_freeze,self._uniffi_clone_pointer(),
2050+
_UniffiConverterTypeAssetFreezeParams.lower(params))
2051+
2052+
2053+
2054+
2055+
2056+
19782057
def add_payment(self, params: "PaymentParams") -> None:
19792058
_UniffiConverterTypePaymentParams.check_lower(params)
19802059

@@ -2174,6 +2253,7 @@ def _uniffi_foreign_future_do_free(task):
21742253
__all__ = [
21752254
"InternalError",
21762255
"UtilsError",
2256+
"AssetFreezeParams",
21772257
"CommonParams",
21782258
"PaymentParams",
21792259
"AlgodClient",
Binary file not shown.
Binary file not shown.

packages/python/algokit_utils/tests/test_utils.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from typing import override
22
import typing
33
from algokit_utils.algokit_http_client import HttpClient, HttpMethod, HttpResponse
4-
from algokit_utils.algokit_transact_ffi import SignedTransaction, Transaction, encode_transaction
4+
from algokit_utils.algokit_transact_ffi import (
5+
SignedTransaction,
6+
Transaction,
7+
encode_transaction,
8+
)
59
from algokit_utils import AlgodClient, TransactionSigner
610
from algokit_utils.algokit_utils_ffi import (
11+
AssetFreezeParams,
712
CommonParams,
813
Composer,
914
PaymentParams,
@@ -32,7 +37,9 @@ async def sign_transactions( # type: ignore
3237
for transaction in transactions:
3338
tx_for_signing = encode_transaction(transaction)
3439
sig = KEY.sign(tx_for_signing)
35-
stxns.append(SignedTransaction(transaction=transaction, signature=sig.signature))
40+
stxns.append(
41+
SignedTransaction(transaction=transaction, signature=sig.signature)
42+
)
3643

3744
return stxns
3845

@@ -65,11 +72,20 @@ async def request( # type: ignore
6572
headers["X-Algo-API-Token"] = "a" * 64
6673

6774
if method == HttpMethod.GET:
68-
res = requests.get(f"http://localhost:4001/{path}", params=query, headers=headers)
75+
res = requests.get(
76+
f"http://localhost:4001/{path}", params=query, headers=headers
77+
)
6978
elif method == HttpMethod.POST:
70-
res = requests.post(f"http://localhost:4001/{path}", params=query, data=body, headers=headers)
79+
res = requests.post(
80+
f"http://localhost:4001/{path}",
81+
params=query,
82+
data=body,
83+
headers=headers,
84+
)
7185
else:
72-
raise NotImplementedError(f"HTTP method {method} not implemented in test client")
86+
raise NotImplementedError(
87+
f"HTTP method {method} not implemented in test client"
88+
)
7389

7490
if res.status_code != 200:
7591
raise Exception(f"HTTP request failed: {res.status_code} {res.text}")
@@ -81,7 +97,7 @@ async def request( # type: ignore
8197

8298
return HttpResponse(
8399
body=res.content,
84-
headers=res.headers # type: ignore
100+
headers=res.headers, # type: ignore
85101
)
86102

87103

@@ -106,5 +122,16 @@ async def test_composer():
106122
)
107123
)
108124

125+
# Test asset freeze functionality
126+
composer.add_asset_freeze(
127+
params=AssetFreezeParams(
128+
common_params=CommonParams(
129+
sender=ADDR,
130+
),
131+
asset_id=12345,
132+
target_address=ADDR,
133+
)
134+
)
135+
109136
await composer.build()
110137
await composer.send()

0 commit comments

Comments
 (0)