Skip to content

Commit

Permalink
Add non critical ext options to client
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Dec 19, 2024
1 parent 4ee5843 commit 0f21853
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
52 changes: 31 additions & 21 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@ import (
// Factory defines a client transaction factory that facilitates generating and
// signing an application-specific transaction.
type Factory struct {
keybase keyring.Keyring
txConfig client.TxConfig
accountRetriever client.AccountRetriever
accountNumber uint64
sequence uint64
gas uint64
timeoutHeight uint64
gasAdjustment float64
chainID string
fromName string
offline bool
generateOnly bool
memo string
fees sdk.Coins
feeGranter sdk.AccAddress
feePayer sdk.AccAddress
gasPrices sdk.DecCoins
extOptions []*codectypes.Any
signMode signing.SignMode
simulateAndExecute bool
preprocessTxHook client.PreprocessTxFn
keybase keyring.Keyring
txConfig client.TxConfig
accountRetriever client.AccountRetriever
accountNumber uint64
sequence uint64
gas uint64
timeoutHeight uint64
gasAdjustment float64
chainID string
fromName string
offline bool
generateOnly bool
memo string
fees sdk.Coins
feeGranter sdk.AccAddress
feePayer sdk.AccAddress
gasPrices sdk.DecCoins
extOptions []*codectypes.Any
nonCriticalExtOptions []*codectypes.Any
signMode signing.SignMode
simulateAndExecute bool
preprocessTxHook client.PreprocessTxFn
}

// NewFactoryCLI creates a new Factory.
Expand Down Expand Up @@ -293,6 +294,11 @@ func (f Factory) WithExtensionOptions(extOpts ...*codectypes.Any) Factory {
return f
}

func (f Factory) WithNonCriticalExtensionOptions(extOpts ...*codectypes.Any) Factory {
f.nonCriticalExtOptions = extOpts
return f
}

// BuildUnsignedTx builds a transaction to be signed given a set of messages.
// Once created, the fee, memo, and messages are set.
func (f Factory) BuildUnsignedTx(msgs ...sdk.Msg) (client.TxBuilder, error) {
Expand Down Expand Up @@ -345,6 +351,10 @@ func (f Factory) BuildUnsignedTx(msgs ...sdk.Msg) (client.TxBuilder, error) {
etx.SetExtensionOptions(f.extOptions...)
}

if etx, ok := tx.(client.NonCriticalExtOptionsTxBuilder); ok {
etx.SetNonCriticalExtensionOptions(f.nonCriticalExtOptions...)
}

return tx, nil
}

Expand Down
6 changes: 6 additions & 0 deletions client/tx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ type (
ExtendedTxBuilder interface {
SetExtensionOptions(extOpts ...*codectypes.Any)
}

// NonCriticalExtOptionsTxBuilder extends the TxBuilder interface,
// which is used to set non-critical extension options to be included in a transaction.
NonCriticalExtOptionsTxBuilder interface {
SetNonCriticalExtensionOptions(extOpts ...*codectypes.Any)
}
)

0 comments on commit 0f21853

Please sign in to comment.