-
Notifications
You must be signed in to change notification settings - Fork 515
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
txnbuild: Add txnbuild helper for sending a payment to a smart contract #5642
base: master
Are you sure you want to change the base?
Conversation
return InvokeHostFunction{}, err | ||
} | ||
|
||
transferArgs := xdr.ScVec{ |
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.
Seems like the Go SDK could certainly use a nativeToScVal
equivalent, but that'd be a separate PR+refactor of course.
@@ -915,8 +914,16 @@ func NewTransaction(params TransactionParams) (*Transaction, error) { | |||
if err != nil { | |||
return nil, errors.Wrap(err, fmt.Sprintf("failed to build operation %T", sorobanOp)) | |||
} | |||
if envelope.V1.Tx.Ext.SorobanData != nil { |
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.
I think either this should be done higher up or the uint32 check should be done after this, otherwise we miss the "proper" validation on L853 in this case.
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.
@Shaptic I just pushed a fix for this issue. can you take a look?
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 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")
@@ -214,6 +214,10 @@ func NewTest(t *testing.T, config Config) *Test { | |||
} | |||
|
|||
i.WaitForHorizonIngest() | |||
|
|||
if !config.SkipCoreContainerCreation && !i.config.QuickExpiration { |
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.
minor, could consolidate all condition checks to single point inside upgradeLimits()
after existing check on protocolversion.
Amount string | ||
// Asset is the asset being transferred | ||
Asset Asset | ||
// SourceAccount is the source account of the payment |
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.
// SourceAccount is the source account of the payment | |
// SourceAccount is the source account of the payment, it must be a Stellar account in strkey encoded`VersionByteAccountID` format, i.e. a 'G' account. |
// Destination is the contract recipient of the payment | ||
Destination string | ||
// Amount is the amount being transferred | ||
Amount string |
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.
could Amount
be strongly typed to a float64 instead, more intuitive for callers?
} | ||
|
||
resources := params.Fees | ||
if resources.ResourceFee == 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.
could there ever be legit use case for setting fee to 0? If remotely plausible, it may be worthwhile to define PaymentToContractParams.Fees
as a pointer *SorobanFees
so can check for explicit absence before applying defaults.
Auth: []xdr.SorobanAuthorizationEntry{ | ||
{ | ||
Credentials: xdr.SorobanCredentials{ | ||
Type: xdr.SorobanCredentialsTypeSorobanCredentialsSourceAccount, |
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.
Based on this hardcode, should source account authentication be stated as limitation in docs forNewPaymentToContract
usage?
Can auth aspect be configurable via something like PaymentToContractParams.Auth SorobanAuth
with SorobanAuth
as a new struct for defining auth type and sub-fields such as when type is SOROBAN_CREDENTIALS_ADDRESS
? Maybe this latter address type auth requires client to assemble tx and invoke preflight manually, meaning they should not use NewPaymentToContract
in that case?
hi, lo := bits.Mul64(uint64(params.BaseFee), uint64(len(inner.operations)+1)) | ||
if hi > 0 || lo > math.MaxInt64 { | ||
return nil, errors.Errorf("base fee %d results in an overflow of max fee", params.BaseFee) | ||
} | ||
totalFee := lo + sorobanFee | ||
if totalFee < lo || totalFee > math.MaxInt64 { | ||
return nil, fmt.Errorf("soroban fee %v results in an overflow of max fee", sorobanFee) | ||
} | ||
tx.maxFee = int64(totalFee) |
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.
minor, lines 1006-1014 looks like duplication of same code on lines 916-925, might be worth refactor to internal, reusable fn?
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
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.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]