Skip to content

feat: send payment transaction with algokit core #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ python = "^3.10"
py-algorand-sdk = "^2.4.0"
httpx = ">=0.23.1,<=0.28.1"
typing-extensions = ">=4.6.0"
algokit-transact = {path = "../../RustroverProjects/algokit-core/target/wheels/algokit_transact-0.1.0-py3-none-manylinux_2_34_x86_64.whl"}
algokit-algod-api = {path = "../../RustroverProjects/algokit-core/packages/python/algod_api/dist/algokit_algod_api-1.0.0a1-py3-none-any.whl"}

[tool.poetry.group.dev.dependencies]
pytest = "^8"
Expand Down
46 changes: 46 additions & 0 deletions src/algokit_utils/transactions/_algokit_core_bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import base64

import algokit_transact
import algosdk.transaction


def payment_through_core(
sender,
sp,
receiver,
amt,
close_remainder_to=None,
note=None,
lease=None,
rekey_to=None,
) -> algosdk.transaction.PaymentTxn:
txn = algokit_transact.Transaction(
transaction_type=algokit_transact.TransactionType.PAYMENT,
sender=algokit_transact.address_from_string(sender),
# The correct fee will be calculated later based on suggested params and estimated size of the transaction.
fee=sp.fee,
first_valid=sp.first,
last_valid=sp.last,
genesis_hash=base64.b64decode(sp.gh),
genesis_id=sp.gen,
note=note,
lease=lease,
rekey_to=algokit_transact.address_from_string(rekey_to) if rekey_to else None,
payment=algokit_transact.PaymentTransactionFields(
receiver=algokit_transact.address_from_string(receiver),
amount=amt,
close_remainder_to=algokit_transact.address_from_string(close_remainder_to) if close_remainder_to else None,
),
)

size = algokit_transact.estimate_transaction_size(txn)
final_fee: int
if sp.flat_fee:
final_fee = sp.fee
else:
final_fee = max(algosdk.constants.MIN_TXN_FEE, sp.flat_fee * size)
txn.fee = final_fee

return algosdk.encoding.msgpack_decode(
base64.b64encode(algokit_transact.encode_transaction_raw(txn)).decode("utf-8")
)
3 changes: 2 additions & 1 deletion src/algokit_utils/transactions/transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from algokit_utils.models.state import BoxIdentifier, BoxReference
from algokit_utils.models.transaction import SendParams, TransactionWrapper
from algokit_utils.protocols.account import TransactionSignerAccountProtocol
from algokit_utils.transactions._algokit_core_bridge import payment_through_core

if TYPE_CHECKING:
from collections.abc import Callable
Expand Down Expand Up @@ -2250,7 +2251,7 @@ def _build_payment(
"close_remainder_to": params.close_remainder_to,
}

return self._common_txn_build_step(lambda x: algosdk.transaction.PaymentTxn(**x), params, txn_params)
return self._common_txn_build_step(lambda x: payment_through_core(**x), params, txn_params)

def _build_asset_create(
self, params: AssetCreateParams, suggested_params: algosdk.transaction.SuggestedParams
Expand Down
Loading