-
Notifications
You must be signed in to change notification settings - Fork 6
Sending ABI methods with composer #221
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
base: main
Are you sure you want to change the base?
Conversation
- revert some naming (still not completed) - review function logic
@@ -152,3 +152,60 @@ pub struct AssetDestroyParams { | |||
/// ID of the existing asset to be destroyed. | |||
pub asset_id: u64, | |||
} | |||
|
|||
pub fn build_asset_create(params: &AssetCreateParams, header: TransactionHeader) -> Transaction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these methods were refactored out of composer.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the ability to send ABI methods using the composer, introducing comprehensive support for application method calls alongside existing raw transaction functionality.
- Adds new
ApplicationMethodCallParams
and related parameter structures for ABI method calls - Implements ABI method argument handling including payments, application calls, transactions, and references
- Extends the composer with
add_application_method_call
functionality to complement existing raw transaction methods
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
inner_fee_coverage.rs | Refactors test file to use new ApplicationRawCallParams instead of deprecated ApplicationCallParams |
asset_transfer.rs | Minor import reorganization moving asset-related imports to main utils module |
application_call.rs | Major addition of comprehensive ABI method call tests and new parameter structures |
contract.py | Adds new sandbox contract with various ABI methods for testing complex scenarios |
Sandbox.arc56.json | Contract specification file defining the sandbox contract's ABI interface |
payment.rs | Adds utility functions build_payment and build_account_close for transaction construction |
mod.rs | Updates module exports to include new transaction parameter types and removes deprecated ones |
key_registration.rs | Adds builder functions for different types of key registration transactions |
@@ -26,3 +26,22 @@ pub struct AccountCloseParams { | |||
/// The address to receive the remaining funds. | |||
pub close_remainder_to: Address, | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build_payment
function lacks documentation. Add a doc comment explaining its purpose, parameters, and return value.
/// Builds a payment transaction that sends ALGO from the sender to the specified receiver. | |
/// | |
/// # Parameters | |
/// - `params`: The parameters specifying the receiver and amount to send. | |
/// - `header`: The transaction header, including sender and other common fields. | |
/// | |
/// # Returns | |
/// A `Transaction` representing the payment transaction. |
Copilot uses AI. Check for mistakes.
close_remainder_to: None, | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build_account_close
function lacks documentation. Add a doc comment explaining its purpose, parameters, and return value.
/// Builds a payment transaction that closes an account by transferring all remaining funds | |
/// to the specified `close_remainder_to` address. | |
/// | |
/// # Parameters | |
/// - `params`: The parameters specifying the recipient of the remaining funds. | |
/// - `header`: The transaction header, including the sender's address. | |
/// | |
/// # Returns | |
/// A `Transaction` representing the account close operation. |
Copilot uses AI. Check for mistakes.
@@ -21,3 +23,51 @@ pub struct OfflineKeyRegistrationParams { | |||
pub struct NonParticipationKeyRegistrationParams { | |||
pub common_params: CommonParams, | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build_online_key_registration
function lacks documentation. Add a doc comment explaining its purpose, parameters, and return value.
/// Builds an online key registration transaction. | |
/// | |
/// # Parameters | |
/// - `params`: Reference to [`OnlineKeyRegistrationParams`] containing the key registration details, | |
/// such as vote key, selection key, voting period, key dilution, and optional state proof key. | |
/// - `header`: The [`TransactionHeader`] to use for the transaction. | |
/// | |
/// # Returns | |
/// A [`Transaction`] representing an online key registration with the provided parameters. |
Copilot uses AI. Check for mistakes.
non_participation: None, | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build_offline_key_registration
function lacks documentation. Add a doc comment explaining its purpose, parameters, and return value.
/// Builds an offline key registration transaction. | |
/// | |
/// # Parameters | |
/// - `params`: The parameters for the offline key registration, including common transaction fields and optional non-participation flag. | |
/// - `header`: The transaction header containing metadata such as sender, fee, and validity period. | |
/// | |
/// # Returns | |
/// A `Transaction` representing the offline key registration. |
Copilot uses AI. Check for mistakes.
non_participation: params.non_participation, | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new build_non_participation_key_registration
function lacks documentation. Add a doc comment explaining its purpose, parameters, and return value.
/// Builds a key registration transaction that marks the account as non-participating. | |
/// | |
/// # Parameters | |
/// - `_params`: Reference to `NonParticipationKeyRegistrationParams` containing common transaction parameters. | |
/// - `header`: The transaction header to use for the transaction. | |
/// | |
/// # Returns | |
/// A `Transaction` representing a non-participation key registration. |
Copilot uses AI. Check for mistakes.
}) | ||
} | ||
|
||
pub fn build_asset_reconfigure( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there a reason we initially defined this as reconfigure instead of configure? We don't have term reconfigure on utils py or ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the utils layer, we wanted to add some abstraction on top of asset configure, therefore, we have build_asset_create
, build_asset_reconfigure
, and build_asset_destroy
. The different is small, for example, the create method doesn't need asset ID because it's always 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In utils-ts/py we call it asset_config
. Based on the previous decision to align to utils-ts/py naming wherever possible, we should rename this as part of the stabilisation.
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum ProcessedApplicationMethodCallArg { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: When we add default value support, I wonder if we'd be able to process the resolution of the default value at add time? Probably the main thing to the consider is that you can use a readonly ABI method call as a default value, so it'd mean a simulate call when performing a transaction add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's something need to keep in mind. We might need to think it through a bit because that means the add will become an async method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep we'd need to colour those functions. Good reason not to do it there.
Another optimisation we can apply when processing at build, is sending a single simulate for all default method args in the group.
abi_values: &[ABIValue], | ||
) -> Result<Vec<Vec<u8>>, ComposerError> { | ||
// Encode first 13 arguments individually | ||
let the_first_abi_types = &abi_types[..ARGS_TUPLE_PACKING_THRESHOLD]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let the_first_abi_types = &abi_types[..ARGS_TUPLE_PACKING_THRESHOLD]; | |
let the_first_13_abi_types = &abi_types[..ARGS_TUPLE_PACKING_THRESHOLD]; |
To match name of values.
method: &ABIMethod, | ||
) -> Option<Result<ABIReturn, ComposerError>> { | ||
// Check if method has return type | ||
method.returns.as_ref()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method.returns.as_ref()?; | |
let return_type = method.returns.as_ref()?; |
Then you can remove the let return_type = method.returns.as_ref().unwrap(); // Safe unwrap since we checked above
later on. Without the assignment, the code threw me a little.
|
||
// Extract the return value bytes (skip the prefix) | ||
let return_bytes = &last_log[ABI_RETURN_PREFIX.len()..]; | ||
let return_type = method.returns.as_ref().unwrap(); // Safe unwrap since we checked above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let return_type = method.returns.as_ref().unwrap(); // Safe unwrap since we checked above |
Fixes #
Proposed Changes