-
Notifications
You must be signed in to change notification settings - Fork 12
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
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
32432d9
chore: installing local python ffi package
CiottiGiorgio f15e32e
feat: using AlgoKit Core to build a payment transaction
CiottiGiorgio 2700fbc
chore: addressed review comment on bridge core module visibility
CiottiGiorgio 33a53ee
Merge branch 'main' into feat/algokit-core-payment
CiottiGiorgio 064c069
chore: adding locally built algod client
CiottiGiorgio 13e06d4
chore: rename payment_through_core -> build_payment_with_core
CiottiGiorgio 5be8767
fix: keep the user min fee if set
CiottiGiorgio ae54d01
chore: update algod client
CiottiGiorgio 0362cf9
chore: use algokit core from GH releases
CiottiGiorgio 7dc168a
chore: use algod generated client from local filesystem because of a …
CiottiGiorgio 40c674b
feat: using AlgodApi OpenAPI generated client to send transactions to…
CiottiGiorgio efac078
chore: adding the released version of python algokit algod client
CiottiGiorgio 2ec3993
fix: introducing tagged releases for the integration with algokit-core
CiottiGiorgio 89b9d89
chore: using the locally built version for now while we wait for CICD…
CiottiGiorgio b7b0f00
chore: using algolkit algod client from a package repo
CiottiGiorgio 9c47442
wip: optional deps group as feature flag & adherence to new client's …
CiottiGiorgio 67940f4
fix: correctly re-throw the exception
CiottiGiorgio b054765
chore: format
CiottiGiorgio 73b97b0
chore: excluding experimental group form CI/CD
CiottiGiorgio 481f712
chore: poetry update setuptools
CiottiGiorgio 24c2a25
chore: ignore untyped stuff that replicates algosdk
CiottiGiorgio cb19b84
chore: removing redundant exception check
CiottiGiorgio eb82ba9
chore: poetry run format
CiottiGiorgio d64633d
chore: fix mypy and linting issues
CiottiGiorgio 1f57a16
chore: remove redundant docstring
CiottiGiorgio add1bde
chore: allow the test to accept more than one log in case we are usin…
CiottiGiorgio c87d458
chore: updated to lates algokit core deps
lempira 231395a
feat: calculated fee using assign_fee from core
lempira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import base64 | ||
from collections.abc import Iterable | ||
|
||
from algosdk.encoding import msgpack_encode | ||
from algosdk.transaction import GenericSignedTransaction | ||
from algosdk.v2client.algod import AlgodClient | ||
|
||
from algokit_utils import _EXPERIMENTAL_DEPENDENCIES_INSTALLED | ||
|
||
if not _EXPERIMENTAL_DEPENDENCIES_INSTALLED: | ||
raise ImportError( | ||
"Installing experimental dependencies is necessary to use AlgodClientWithCore. " | ||
"Install this package with --group=experimental" | ||
) | ||
|
||
import algokit_algod_api | ||
|
||
|
||
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): | ||
self._algod_client = algod_client | ||
|
||
configuration = algokit_algod_api.Configuration( | ||
host=algod_client.algod_address, api_key={"api_key": self._algod_client.algod_token} | ||
) | ||
api_client = algokit_algod_api.ApiClient(configuration) | ||
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import base64 | ||
from typing import cast | ||
|
||
import algosdk.transaction | ||
from algokit_transact import ( | ||
FeeParams, | ||
PaymentTransactionFields, | ||
Transaction, | ||
TransactionType, | ||
address_from_string, | ||
assign_fee, | ||
encode_transaction_raw, | ||
) | ||
|
||
|
||
def build_payment_with_core( # noqa: PLR0913 | ||
sender, | ||
sp, | ||
receiver, | ||
amt, | ||
close_remainder_to=None, | ||
note=None, | ||
lease=None, | ||
rekey_to=None, | ||
static_fee=None, | ||
max_fee=None, | ||
extra_fee=None, | ||
) -> algosdk.transaction.PaymentTxn: | ||
# Determine static fee based on parameters or suggested params | ||
static_fee_value = None | ||
if static_fee is not None: | ||
static_fee_value = static_fee | ||
elif sp.flat_fee: | ||
static_fee_value = sp.fee | ||
|
||
txn = Transaction( | ||
transaction_type=TransactionType.PAYMENT, | ||
sender=address_from_string(sender), | ||
fee=static_fee_value, | ||
first_valid=sp.first, | ||
last_valid=sp.last, | ||
genesis_hash=base64.b64decode(sp.gh), | ||
genesis_id=sp.gen, | ||
note=note, | ||
lease=lease, | ||
rekey_to=address_from_string(rekey_to) if rekey_to else None, | ||
payment=PaymentTransactionFields( | ||
receiver=address_from_string(receiver), | ||
amount=amt, | ||
close_remainder_to=address_from_string(close_remainder_to) if close_remainder_to else None, | ||
), | ||
) | ||
|
||
if txn.fee is not None: | ||
# Static fee is already set, encode and return directly | ||
return cast( | ||
algosdk.transaction.PaymentTxn, | ||
algosdk.encoding.msgpack_decode(base64.b64encode(encode_transaction_raw(txn)).decode("utf-8")), | ||
) | ||
else: | ||
# Use assign_fee with fee parameters | ||
min_fee = sp.min_fee or algosdk.constants.MIN_TXN_FEE | ||
txn_with_fee = assign_fee( | ||
txn, | ||
FeeParams( | ||
fee_per_byte=sp.fee, | ||
min_fee=min_fee, | ||
max_fee=max_fee, | ||
extra_fee=extra_fee, | ||
), | ||
) | ||
|
||
return cast( | ||
algosdk.transaction.PaymentTxn, | ||
algosdk.encoding.msgpack_decode(base64.b64encode(encode_transaction_raw(txn_with_fee)).decode("utf-8")), | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.