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

Merged
merged 28 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32432d9
chore: installing local python ffi package
CiottiGiorgio May 13, 2025
f15e32e
feat: using AlgoKit Core to build a payment transaction
CiottiGiorgio May 14, 2025
2700fbc
chore: addressed review comment on bridge core module visibility
CiottiGiorgio May 16, 2025
33a53ee
Merge branch 'main' into feat/algokit-core-payment
CiottiGiorgio May 16, 2025
064c069
chore: adding locally built algod client
CiottiGiorgio May 16, 2025
13e06d4
chore: rename payment_through_core -> build_payment_with_core
CiottiGiorgio May 19, 2025
5be8767
fix: keep the user min fee if set
CiottiGiorgio May 19, 2025
ae54d01
chore: update algod client
CiottiGiorgio May 19, 2025
0362cf9
chore: use algokit core from GH releases
CiottiGiorgio May 20, 2025
7dc168a
chore: use algod generated client from local filesystem because of a …
CiottiGiorgio May 20, 2025
40c674b
feat: using AlgodApi OpenAPI generated client to send transactions to…
CiottiGiorgio May 20, 2025
efac078
chore: adding the released version of python algokit algod client
CiottiGiorgio May 22, 2025
2ec3993
fix: introducing tagged releases for the integration with algokit-core
CiottiGiorgio May 27, 2025
89b9d89
chore: using the locally built version for now while we wait for CICD…
CiottiGiorgio May 28, 2025
b7b0f00
chore: using algolkit algod client from a package repo
CiottiGiorgio May 29, 2025
9c47442
wip: optional deps group as feature flag & adherence to new client's …
CiottiGiorgio May 29, 2025
67940f4
fix: correctly re-throw the exception
CiottiGiorgio May 29, 2025
b054765
chore: format
CiottiGiorgio May 29, 2025
73b97b0
chore: excluding experimental group form CI/CD
CiottiGiorgio May 29, 2025
481f712
chore: poetry update setuptools
CiottiGiorgio May 29, 2025
24c2a25
chore: ignore untyped stuff that replicates algosdk
CiottiGiorgio May 29, 2025
cb19b84
chore: removing redundant exception check
CiottiGiorgio May 29, 2025
eb82ba9
chore: poetry run format
CiottiGiorgio May 29, 2025
d64633d
chore: fix mypy and linting issues
CiottiGiorgio May 29, 2025
1f57a16
chore: remove redundant docstring
CiottiGiorgio May 29, 2025
add1bde
chore: allow the test to accept more than one log in case we are usin…
CiottiGiorgio May 30, 2025
c87d458
chore: updated to lates algokit core deps
lempira Jun 5, 2025
231395a
feat: calculated fee using assign_fee from core
lempira Jun 5, 2025
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 = {url = "https://github.com/algorandfoundation/algokit-core/releases/download/python%2Falgokit_transact%401.0.0-alpha.4/algokit_transact-1.0.0a4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}
algokit-algod-api = {url = "https://github.com/algorandfoundation/algokit-core/releases/download/python%2Falgod_api%401.0.0-alpha.6/algokit_algod_api-1.0.0a6-py3-none-any.whl"}

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

import algokit_algod_api
from algosdk.encoding import msgpack_encode
from algosdk.transaction import GenericSignedTransaction
from algosdk.v2client.algod import AlgodClient


class AlgodClientWithCore:
"""
A decorator for AlgodClient that extends its functionality with algokit_algod_api capabilities.
This class wraps an AlgodClient instance while maintaining the same interface.
"""

def __init__(self, algod_client: AlgodClient):
"""
Initialize the AlgodClientWithCore with an existing AlgodClient.

Args:
algod_client: The AlgodClient instance to wrap
"""
self._algod_client = algod_client

configuration = algokit_algod_api.Configuration(
host=algod_client.algod_address,
)
api_client = algokit_algod_api.ApiClient(configuration)
api_client.default_headers.update({"X-Algo-API-Token": self._algod_client.algod_token})
self._algod_core_client = algokit_algod_api.AlgodApi(api_client=api_client)

def send_raw_transaction(self, txn):
"""
Override the method to send a raw transaction using algokit_algod_api.
"""
return self._algod_core_client.raw_transaction(base64.b64decode(txn))

def send_transactions(self, txns: Iterable[GenericSignedTransaction]):
"""
Override the method to send multiple transactions using algokit_algod_api.
"""
return self.send_raw_transaction(
base64.b64encode(b"".join(base64.b64decode(msgpack_encode(txn)) for txn in txns))
)

def __getattr__(self, name):
"""
Delegate all other method calls to the wrapped AlgodClient instance.
"""
return getattr(self._algod_client, name)
3 changes: 2 additions & 1 deletion src/algokit_utils/clients/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from algokit_utils._legacy_v2.application_specification import ApplicationSpecification
from algokit_utils.applications.app_deployer import ApplicationLookup
from algokit_utils.applications.app_spec.arc56 import Arc56Contract
from algokit_utils.clients._algokit_core_bridge import AlgodClientWithCore
from algokit_utils.clients.dispenser_api_client import TestNetDispenserApiClient
from algokit_utils.models.network import AlgoClientConfigs, AlgoClientNetworkConfig
from algokit_utils.protocols.typed_clients import TypedAppClientProtocol, TypedAppFactoryProtocol
Expand Down Expand Up @@ -119,7 +120,7 @@ def __init__(self, clients_or_configs: AlgoClientConfigs | AlgoSdkClients, algor
if clients_or_configs.kmd_config
else None,
)
self._algod = _clients.algod
self._algod = AlgodClientWithCore(_clients.algod)
self._indexer = _clients.indexer
self._kmd = _clients.kmd
self._algorand = algorand_client
Expand Down
47 changes: 47 additions & 0 deletions src/algokit_utils/transactions/_algokit_core_bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import base64

import algokit_transact
import algosdk.transaction


def build_payment_with_core(
Copy link
Contributor

@neilcampbell neilcampbell May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic has been updated in utils-ts to also perform fee calculations via algokit-transact. See algorandfoundation/algokit-utils-ts#407

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use assign_fee from ak-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:
min_fee = sp.min_fee or algosdk.constants.MIN_TXN_FEE
final_fee = max(min_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 build_payment_with_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: build_payment_with_core(**x), params, txn_params)

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