Skip to content

Commit f15e32e

Browse files
committed
feat: using AlgoKit Core to build a payment transaction
1 parent 32432d9 commit f15e32e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ python = "^3.10"
1111
py-algorand-sdk = "^2.4.0"
1212
httpx = ">=0.23.1,<=0.28.1"
1313
typing-extensions = ">=4.6.0"
14-
algokit-transact = {path = "../../RustroverProjects/algokit-core/packages/python/algokit_transact/dist/algokit_transact-0.1.0.tar.gz"}
14+
algokit-transact = {path = "../../RustroverProjects/algokit-core/target/wheels/algokit_transact-0.1.0-py3-none-manylinux_2_34_x86_64.whl"}
1515

1616
[tool.poetry.group.dev.dependencies]
1717
pytest = "^8"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import base64
2+
3+
import algokit_transact
4+
import algosdk.transaction
5+
6+
7+
def payment_through_core(
8+
sender,
9+
sp,
10+
receiver,
11+
amt,
12+
close_remainder_to=None,
13+
note=None,
14+
lease=None,
15+
rekey_to=None,
16+
) -> algosdk.transaction.PaymentTxn:
17+
txn = algokit_transact.Transaction(
18+
transaction_type=algokit_transact.TransactionType.PAYMENT,
19+
sender=algokit_transact.address_from_string(sender),
20+
# The correct fee will be calculated later based on suggested params and estimated size of the transaction.
21+
fee=sp.fee,
22+
first_valid=sp.first,
23+
last_valid=sp.last,
24+
genesis_hash=base64.b64decode(sp.gh),
25+
genesis_id=sp.gen,
26+
note=note,
27+
lease=lease,
28+
rekey_to=algokit_transact.address_from_string(rekey_to) if rekey_to else None,
29+
payment=algokit_transact.PaymentTransactionFields(
30+
receiver=algokit_transact.address_from_string(receiver),
31+
amount=amt,
32+
close_remainder_to=algokit_transact.address_from_string(close_remainder_to) if close_remainder_to else None,
33+
),
34+
)
35+
36+
size = algokit_transact.estimate_transaction_size(txn)
37+
final_fee: int
38+
if sp.flat_fee:
39+
final_fee = sp.fee
40+
else:
41+
final_fee = max(algosdk.constants.MIN_TXN_FEE, sp.flat_fee * size)
42+
txn.fee = final_fee
43+
44+
return algosdk.encoding.msgpack_decode(
45+
base64.b64encode(algokit_transact.encode_transaction_raw(txn)).decode("utf-8")
46+
)

src/algokit_utils/transactions/transaction_composer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from algokit_utils.models.state import BoxIdentifier, BoxReference
3030
from algokit_utils.models.transaction import SendParams, TransactionWrapper
3131
from algokit_utils.protocols.account import TransactionSignerAccountProtocol
32+
from algokit_utils.transactions.algokit_core_bridge import payment_through_core
3233

3334
if TYPE_CHECKING:
3435
from collections.abc import Callable
@@ -2251,7 +2252,7 @@ def _build_payment(
22512252
"close_remainder_to": params.close_remainder_to,
22522253
}
22532254

2254-
return self._common_txn_build_step(lambda x: algosdk.transaction.PaymentTxn(**x), params, txn_params)
2255+
return self._common_txn_build_step(lambda x: payment_through_core(**x), params, txn_params)
22552256

22562257
def _build_asset_create(
22572258
self, params: AssetCreateParams, suggested_params: algosdk.transaction.SuggestedParams

0 commit comments

Comments
 (0)