Skip to content

txnbuild: Add txnbuild helper for sending a payment to a smart contract #5642

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 15 commits into from
Apr 17, 2025

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Mar 25, 2025

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've reviewed the changes in this PR and if I consider them worthwhile for being mentioned on release notes then I have updated the relevant CHANGELOG.md within the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Close #5626

Update txnbuild to support constructing SAC payments to contracts with default fees so that simulateTransaction calls to rpc are not necessary.

Also fixes a bug in txnbuild where the max fee in the transaction envelope did not include the additional soroban resource fee.

Why

see #5626

Known limitations

[N/A]

@tamirms tamirms marked this pull request as ready for review March 26, 2025 20:02
@tamirms tamirms requested review from a team and marcelosalloum March 26, 2025 20:05
@leighmcculloch leighmcculloch requested a review from Copilot March 27, 2025 06:04
Copy link

@Copilot Copilot AI left a 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 adds txnbuild helpers for sending a payment to a smart contract and for restoring an asset balance via a new restore footprint operation. It also updates fee handling and adjusts integration tests to use the new helper signatures while removing legacy fee parameters.

  • Introduces NewAssetBalanceRestoration and NewPaymentToContract functions with configurable Soroban fee values.
  • Updates integration tests to use the new Preflight functions without separate minFee values.
  • Refactors code across txnbuild and integration tests to align with these helper changes.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

File Description
txnbuild/restore_footprint.go Adds a helper for constructing asset balance restoration operations.
txnbuild/invoke_host_function.go Adds a helper for constructing payment-to-contract operations with updated fee handling.
Integration tests (various files) Adjust test calls to use the new helper function signatures by removing extra fee parameters.
Horizon integration tests Update fee-bump and Preflight function calls to support the new txnbuild APIs.
Comments suppressed due to low confidence (2)

services/horizon/internal/integration/integration.go:816

  • Double-check that all callers of PreflightHostFunctions have been updated to handle the new signature returning a single value, as the removal of minFee could cause runtime issues if any outdated expectation remains.
return function

services/horizon/internal/integration/invokehostfunction_test.go:130

  • [nitpick] Consider defining a named constant for 'HostFunctionTypeHostFunctionTypeUploadContractWasm' to improve code clarity and reduce potential typos in repeated usage.
assert.Equal(t, invokeHostFunctionOpJson.Function, "HostFunctionTypeHostFunctionTypeUploadContractWasm")

@tamirms
Copy link
Contributor Author

tamirms commented Apr 16, 2025

@sreuland can you take another look at the PR?

Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

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

lgtm, nice work!

@tamirms tamirms enabled auto-merge (squash) April 17, 2025 08:43
@tamirms tamirms merged commit 2e64bc5 into stellar:master Apr 17, 2025
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

txnbuild: add helpers for constructing transactions to send payments to contracts
4 participants