Skip to content

Commit f8876aa

Browse files
authored
Tron Default Opts (#253)
Use pointers for options to support nil initialization, and raise the default deployment parameters for better reliability.
1 parent afca1be commit f8876aa

File tree

7 files changed

+49
-44
lines changed

7 files changed

+49
-44
lines changed

.changeset/soft-dingos-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": patch
3+
---
4+
5+
Refactor the Tron package options to be pointers in order to support optional configuration.

chain/tron/provider/ctf_provider.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,22 @@ func (p *CTFChainProvider) Initialize(_ context.Context) (chain.BlockChain, erro
140140
Address: deployerAddr, // Default "from" address for transactions
141141
URL: fullNodeURL,
142142
// Helper for sending and confirming transactions
143-
SendAndConfirm: func(ctx context.Context, tx *common.Transaction, opts ...tron.ConfirmRetryOptions) (*soliditynode.TransactionInfo, error) {
143+
SendAndConfirm: func(ctx context.Context, tx *common.Transaction, opts *tron.ConfirmRetryOptions) (*soliditynode.TransactionInfo, error) {
144144
options := tron.DefaultConfirmRetryOptions()
145-
if len(opts) > 0 {
146-
options = opts[0]
145+
if opts != nil {
146+
options = opts
147147
}
148148

149149
// Send transaction and wait for confirmation
150150
return client.SendAndConfirmTx(ctx, tx, options)
151151
},
152152
// Helper for deploying a contract and waiting for confirmation
153153
DeployContractAndConfirm: func(
154-
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts ...tron.DeployOptions,
154+
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts *tron.DeployOptions,
155155
) (address.Address, *soliditynode.TransactionInfo, error) {
156156
options := tron.DefaultDeployOptions()
157-
if len(opts) > 0 {
158-
options = opts[0]
157+
if opts != nil {
158+
options = opts
159159
}
160160

161161
// Create deploy contract transaction
@@ -187,11 +187,11 @@ func (p *CTFChainProvider) Initialize(_ context.Context) (chain.BlockChain, erro
187187
},
188188
// Helper for triggering a contract method and waiting for confirmation
189189
TriggerContractAndConfirm: func(
190-
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts ...tron.TriggerOptions,
190+
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts *tron.TriggerOptions,
191191
) (*soliditynode.TransactionInfo, error) {
192192
options := tron.DefaultTriggerOptions()
193-
if len(opts) > 0 {
194-
options = opts[0]
193+
if opts != nil {
194+
options = opts
195195
}
196196

197197
// Ensure contract is actually deployed on-chain

chain/tron/provider/rpc_provider.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ func (p *RPCChainProvider) Initialize(ctx context.Context) (chain.BlockChain, er
106106
Address: deployerAddr, // Default "from" address for transactions
107107
URL: p.config.FullNodeURL,
108108
// Helper for sending and confirming transactions
109-
SendAndConfirm: func(ctx context.Context, tx *common.Transaction, opts ...tron.ConfirmRetryOptions) (*soliditynode.TransactionInfo, error) {
109+
SendAndConfirm: func(ctx context.Context, tx *common.Transaction, opts *tron.ConfirmRetryOptions) (*soliditynode.TransactionInfo, error) {
110110
options := tron.DefaultConfirmRetryOptions()
111-
if len(opts) > 0 {
112-
options = opts[0]
111+
if opts != nil {
112+
options = opts
113113
}
114114

115115
// Send transaction and wait for confirmation
116116
return client.SendAndConfirmTx(ctx, tx, options)
117117
},
118118
// Helper for deploying a contract and waiting for confirmation
119119
DeployContractAndConfirm: func(
120-
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts ...tron.DeployOptions,
120+
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts *tron.DeployOptions,
121121
) (address.Address, *soliditynode.TransactionInfo, error) {
122122
options := tron.DefaultDeployOptions()
123-
if len(opts) > 0 {
124-
options = opts[0]
123+
if opts != nil {
124+
options = opts
125125
}
126126

127127
// Create deploy contract transaction
@@ -153,11 +153,11 @@ func (p *RPCChainProvider) Initialize(ctx context.Context) (chain.BlockChain, er
153153
},
154154
// Helper for triggering a contract method and waiting for confirmation
155155
TriggerContractAndConfirm: func(
156-
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts ...tron.TriggerOptions,
156+
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts *tron.TriggerOptions,
157157
) (*soliditynode.TransactionInfo, error) {
158158
options := tron.DefaultTriggerOptions()
159-
if len(opts) > 0 {
160-
options = opts[0]
159+
if opts != nil {
160+
options = opts
161161
}
162162

163163
// Ensure contract is actually deployed on-chain

chain/tron/provider/rpcclient/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
// confirmRetryOpts returns the retry options for confirming transactions.
2121
// It wraps a context and sets retry count and delay based on provided config.
22-
func confirmRetryOpts(ctx context.Context, c tron.ConfirmRetryOptions) []retry.Option {
22+
func confirmRetryOpts(ctx context.Context, c *tron.ConfirmRetryOptions) []retry.Option {
2323
return []retry.Option{
2424
retry.Context(ctx),
2525
retry.Attempts(c.RetryAttempts),
@@ -53,12 +53,12 @@ func New(client sdk.FullNodeClient, keystore *keystore.Keystore, account address
5353
func (c *Client) SendAndConfirmTx(
5454
ctx context.Context,
5555
tx *common.Transaction,
56-
opts ...tron.ConfirmRetryOptions,
56+
opts *tron.ConfirmRetryOptions,
5757
) (*soliditynode.TransactionInfo, error) {
5858
// Initialize the configuration with defaults or provided options.
5959
option := tron.DefaultConfirmRetryOptions()
60-
if len(opts) > 0 {
61-
option = opts[0]
60+
if opts != nil {
61+
option = opts
6262
}
6363

6464
// Decode the TxID from hex into bytes, required for signing

chain/tron/provider/rpcclient/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestConfirmRetryOpts_DefaultsAndOverrides(t *testing.T) {
3030
require.True(t, hasCtx)
3131

3232
// Test with custom options
33-
customOpts := confirmRetryOpts(ctx, tron.ConfirmRetryOptions{
33+
customOpts := confirmRetryOpts(ctx, &tron.ConfirmRetryOptions{
3434
RetryAttempts: 3,
3535
RetryDelay: 50 * time.Millisecond,
3636
})

chain/tron/tron_chain.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ type ConfirmRetryOptions struct {
2424

2525
// DeployOptions defines optional parameters for deploying a smart contract.
2626
type DeployOptions struct {
27-
OeLimit int // Max energy the creator is willing to provide during execution.
28-
CurPercent int // Percentage of resource consumption charged to the contract caller (0–100).
29-
FeeLimit int // Max TRX to be used for deploying the contract (gas limit in Tron terms).
30-
ConfirmRetryOptions ConfirmRetryOptions // Retry options for confirming the transaction.
27+
OeLimit int // Max energy the creator is willing to provide during execution.
28+
CurPercent int // Percentage of resource consumption charged to the contract caller (0–100).
29+
FeeLimit int // Max TRX to be used for deploying the contract (gas limit in Tron terms).
30+
ConfirmRetryOptions *ConfirmRetryOptions // Retry options for confirming the transaction.
3131
}
3232

3333
// TriggerOptions defines optional parameters for triggering (calling) a smart contract.
3434
type TriggerOptions struct {
35-
FeeLimit int32 // Max TRX to be used for this transaction call.
36-
TAmount int64 // Amount of TRX to transfer along with the contract call (like msg.value).
37-
ConfirmRetryOptions ConfirmRetryOptions // Retry options for confirming the transaction.
35+
FeeLimit int32 // Max TRX to be used for this transaction call.
36+
TAmount int64 // Amount of TRX to transfer along with the contract call (like msg.value).
37+
ConfirmRetryOptions *ConfirmRetryOptions // Retry options for confirming the transaction.
3838
}
3939

4040
// Chain represents a Tron chain
@@ -47,43 +47,43 @@ type Chain struct {
4747
DeployerSeed string // Optional: mnemonic or raw seed
4848

4949
// SendAndConfirm provides a utility function to send a transaction and waits for confirmation.
50-
SendAndConfirm func(ctx context.Context, tx *common.Transaction, opts ...ConfirmRetryOptions) (*soliditynode.TransactionInfo, error)
50+
SendAndConfirm func(ctx context.Context, tx *common.Transaction, opts *ConfirmRetryOptions) (*soliditynode.TransactionInfo, error)
5151

5252
// DeployContractAndConfirm provides a utility function to deploy a contract and waits for confirmation.
5353
DeployContractAndConfirm func(
54-
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts ...DeployOptions,
54+
ctx context.Context, contractName string, abi string, bytecode string, params []interface{}, opts *DeployOptions,
5555
) (address.Address, *soliditynode.TransactionInfo, error)
5656

5757
// TriggerContractAndConfim provides a utility function to send a contract transaction and waits for confirmation.
5858
TriggerContractAndConfirm func(
59-
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts ...TriggerOptions,
59+
ctx context.Context, contractAddr address.Address, functionName string, params []interface{}, opts *TriggerOptions,
6060
) (*soliditynode.TransactionInfo, error)
6161
}
6262

6363
// DefaultConfirmRetryOptions returns standard retry options used across contract deployment and invocation.
6464
// Defaults to 180 retries with a 500ms delay between each attempt.
65-
func DefaultConfirmRetryOptions() ConfirmRetryOptions {
66-
return ConfirmRetryOptions{
65+
func DefaultConfirmRetryOptions() *ConfirmRetryOptions {
66+
return &ConfirmRetryOptions{
6767
RetryAttempts: 180,
6868
RetryDelay: 500 * time.Millisecond,
6969
}
7070
}
7171

7272
// DefaultDeployOptions returns default options used when deploying a contract.
7373
// It includes a high fee and energy limit suitable for development/testing, and standard retry behavior.
74-
func DefaultDeployOptions() DeployOptions {
75-
return DeployOptions{
76-
FeeLimit: 10_000_000, // Default fee limit (in SUN).
77-
CurPercent: 100, // Caller pays full cost.
78-
OeLimit: 10_000_000, // Default energy limit.
74+
func DefaultDeployOptions() *DeployOptions {
75+
return &DeployOptions{
76+
FeeLimit: 100_000_000, // Default fee limit (in SUN).
77+
CurPercent: 100, // Caller pays full cost.
78+
OeLimit: 50_000_000, // Default energy limit.
7979
ConfirmRetryOptions: DefaultConfirmRetryOptions(),
8080
}
8181
}
8282

8383
// DefaultTriggerOptions returns default options for calling smart contract methods.
8484
// These defaults ensure calls succeed on local/dev environments without TRX transfer.
85-
func DefaultTriggerOptions() TriggerOptions {
86-
return TriggerOptions{
85+
func DefaultTriggerOptions() *TriggerOptions {
86+
return &TriggerOptions{
8787
FeeLimit: 10_000_000, // Default fee limit (in SUN).
8888
TAmount: 0, // No TRX transferred by default.
8989
ConfirmRetryOptions: DefaultConfirmRetryOptions(),

chain/tron/tron_chain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func Test_DefaultOptions(t *testing.T) {
5757
t.Run("DefaultDeployOptions", func(t *testing.T) {
5858
t.Parallel()
5959
opts := tron.DefaultDeployOptions()
60-
assert.Equal(t, 10_000_000, opts.FeeLimit)
60+
assert.Equal(t, 100_000_000, opts.FeeLimit)
6161
assert.Equal(t, 100, opts.CurPercent)
62-
assert.Equal(t, 10_000_000, opts.OeLimit)
62+
assert.Equal(t, 50_000_000, opts.OeLimit)
6363
assert.Equal(t, tron.DefaultConfirmRetryOptions(), opts.ConfirmRetryOptions)
6464
})
6565

0 commit comments

Comments
 (0)