From 1596439444f61c8f13498dca517dbe9fd41e762b Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 28 Jun 2024 16:14:14 +0300 Subject: [PATCH] rename TxOptions to TxConfig --- api/docgen/examples.go | 4 +- api/rpc_test.go | 4 +- blob/service.go | 6 +- docs/adr/adr-009-public-api.md | 16 ++-- nodebuilder/blob/blob.go | 6 +- nodebuilder/blob/cmd/blob.go | 2 +- nodebuilder/blob/mocks/api.go | 2 +- nodebuilder/da/service.go | 2 +- nodebuilder/state/cmd/state.go | 20 ++--- nodebuilder/state/mocks/api.go | 16 ++-- nodebuilder/state/state.go | 48 +++++------ nodebuilder/state/stub.go | 16 ++-- nodebuilder/tests/api_test.go | 2 +- nodebuilder/tests/blob_test.go | 6 +- state/core_access.go | 86 +++++++++---------- state/core_access_test.go | 8 +- state/{tx_options.go => tx_config.go} | 86 +++++++++---------- .../{tx_options_test.go => tx_config_test.go} | 4 +- 18 files changed, 167 insertions(+), 167 deletions(-) rename state/{tx_options.go => tx_config.go} (71%) rename state/{tx_options_test.go => tx_config_test.go} (91%) diff --git a/api/docgen/examples.go b/api/docgen/examples.go index b241dfe0bc..f78d29543b 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -178,14 +178,14 @@ func init() { } addToExampleValues(libhead.Hash(hash)) - txOptions := state.NewTxOptions( + txConfig := state.NewTxConfig( state.WithGasPrice(0.002), state.WithGas(142225), state.WithKeyName("my_celes_key"), state.WithSignerAddress("celestia1pjcmwj8w6hyr2c4wehakc5g8cfs36aysgucx66"), state.WithFeeGranterAddress("celestia1hakc56ax66ypjcmwj8w6hyr2c4g8cfs3wesguc"), ) - addToExampleValues(txOptions) + addToExampleValues(txConfig) } func addToExampleValues(v interface{}) { diff --git a/api/rpc_test.go b/api/rpc_test.go index 5f8c9c1af7..e6d9ca0778 100644 --- a/api/rpc_test.go +++ b/api/rpc_test.go @@ -192,12 +192,12 @@ func TestAuthedRPC(t *testing.T) { server.State.EXPECT().Delegate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedResp, nil) txResp, err := rpcClient.State.Delegate(ctx, - state.ValAddress{}, state.Int{}, state.NewTxOptions()) + state.ValAddress{}, state.Int{}, state.NewTxConfig()) require.NoError(t, err) require.Equal(t, expectedResp, txResp) } else { _, err := rpcClient.State.Delegate(ctx, - state.ValAddress{}, state.Int{}, state.NewTxOptions()) + state.ValAddress{}, state.Int{}, state.NewTxConfig()) require.Error(t, err) require.ErrorContains(t, err, "missing permission") } diff --git a/blob/service.go b/blob/service.go index 86cb419961..48f15ec8ac 100644 --- a/blob/service.go +++ b/blob/service.go @@ -33,7 +33,7 @@ var ( // avoid a circular dependency between the blob and the state package, since the state package needs // the blob.Blob type for this signature. type Submitter interface { - SubmitPayForBlob(context.Context, []*state.Blob, *state.TxOptions) (*types.TxResponse, error) + SubmitPayForBlob(context.Context, []*state.Blob, *state.TxConfig) (*types.TxResponse, error) } type Service struct { @@ -61,7 +61,7 @@ func NewService( // Allows sending multiple Blobs atomically synchronously. // Uses default wallet registered on the Node. // Handles gas estimation and fee calculation. -func (s *Service) Submit(ctx context.Context, blobs []*Blob, txOptions *state.TxOptions) (uint64, error) { +func (s *Service) Submit(ctx context.Context, blobs []*Blob, txConfig *state.TxConfig) (uint64, error) { log.Debugw("submitting blobs", "amount", len(blobs)) appblobs := make([]*state.Blob, len(blobs)) @@ -72,7 +72,7 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob, txOptions *state.Tx appblobs[i] = &blobs[i].Blob } - resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, appblobs, txOptions) + resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, appblobs, txConfig) if err != nil { return 0, err } diff --git a/docs/adr/adr-009-public-api.md b/docs/adr/adr-009-public-api.md index f75fd8e2b6..1a534896dd 100644 --- a/docs/adr/adr-009-public-api.md +++ b/docs/adr/adr-009-public-api.md @@ -253,7 +253,7 @@ NetworkHead(ctx context.Context) (*header.ExtendedHeader, error) ctx context.Context, nID namespace.ID, data []byte, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // Transfer sends the given amount of coins from default wallet of the node // to the given account address. @@ -261,7 +261,7 @@ NetworkHead(ctx context.Context) (*header.ExtendedHeader, error) ctx context.Context, to types.Address, amount types.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // StateModule also provides StakingModule @@ -282,7 +282,7 @@ yet. ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // BeginRedelegate sends a user's delegated tokens to a new validator for redelegation. BeginRedelegate( @@ -290,7 +290,7 @@ yet. srcValAddr, dstValAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // Undelegate undelegates a user's delegated tokens, unbonding them from the // current validator. @@ -298,7 +298,7 @@ yet. ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a @@ -308,7 +308,7 @@ yet. valAddr state.ValAddress, amount types.Int, height types.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // QueryDelegation retrieves the delegation information between a delegator @@ -399,7 +399,7 @@ type BankModule interface { SubmitPayForBlob( ctx context.Context, blobs []*state.Blob, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // Transfer sends the given amount of coins from default wallet of the node // to the given account address. @@ -407,7 +407,7 @@ type BankModule interface { ctx context.Context, to state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) } ``` diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index 8414406810..8a770a9c0d 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -17,7 +17,7 @@ type Module interface { // Submit sends Blobs and reports the height in which they were included. // Allows sending multiple Blobs atomically synchronously. // Uses default wallet registered on the Node. - Submit(_ context.Context, _ []*blob.Blob, _ *state.TxOptions) (height uint64, _ error) + Submit(_ context.Context, _ []*blob.Blob, _ *state.TxConfig) (height uint64, _ error) // Get retrieves the blob by commitment under the given namespace and height. Get(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Blob, error) // GetAll returns all blobs at the given height under the given namespaces. @@ -31,7 +31,7 @@ type Module interface { type API struct { Internal struct { - Submit func(context.Context, []*blob.Blob, *state.TxOptions) (uint64, error) `perm:"write"` + Submit func(context.Context, []*blob.Blob, *state.TxConfig) (uint64, error) `perm:"write"` Get func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Blob, error) `perm:"read"` GetAll func(context.Context, uint64, []share.Namespace) ([]*blob.Blob, error) `perm:"read"` GetProof func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Proof, error) `perm:"read"` @@ -39,7 +39,7 @@ type API struct { } } -func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *state.TxOptions) (uint64, error) { +func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *state.TxConfig) (uint64, error) { return api.Internal.Submit(ctx, blobs, options) } diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index 6b68a6b8d2..d5f36c36c3 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -200,7 +200,7 @@ var submitCmd = &cobra.Command{ height, err := client.Blob.Submit( cmd.Context(), resultBlobs, - state.GetTxOptions(), + state.GetTxConfig(), ) response := struct { diff --git a/nodebuilder/blob/mocks/api.go b/nodebuilder/blob/mocks/api.go index af7cb16bfb..8b46c42d6c 100644 --- a/nodebuilder/blob/mocks/api.go +++ b/nodebuilder/blob/mocks/api.go @@ -98,7 +98,7 @@ func (mr *MockModuleMockRecorder) Included(arg0, arg1, arg2, arg3, arg4 interfac } // Submit mocks base method. -func (m *MockModule) Submit(arg0 context.Context, arg1 []*blob.Blob, arg2 *state.TxOptions) (uint64, error) { +func (m *MockModule) Submit(arg0 context.Context, arg1 []*blob.Blob, arg2 *state.TxConfig) (uint64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Submit", arg0, arg1, arg2) ret0, _ := ret[0].(uint64) diff --git a/nodebuilder/da/service.go b/nodebuilder/da/service.go index a3aecfbe80..ebb47b9e3f 100644 --- a/nodebuilder/da/service.go +++ b/nodebuilder/da/service.go @@ -111,7 +111,7 @@ func (s *Service) Submit( return nil, err } - opts := state.NewTxOptions(state.WithGasPrice(gasPrice)) + opts := state.NewTxConfig(state.WithGasPrice(gasPrice)) height, err := s.blobServ.Submit(ctx, blobs, opts) if err != nil { diff --git a/nodebuilder/state/cmd/state.go b/nodebuilder/state/cmd/state.go index da576f7378..2db6e3ebfc 100644 --- a/nodebuilder/state/cmd/state.go +++ b/nodebuilder/state/cmd/state.go @@ -46,7 +46,7 @@ func init() { "The default value is 0 which means the grantee does not have a spend limit.", ) - // apply option flags for all txs that require `TxOptions`. + // apply option flags for all txs that require `TxConfig`. ApplyFlags( transferCmd, cancelUnbondingDelegationCmd, @@ -144,7 +144,7 @@ var transferCmd = &cobra.Command{ cmd.Context(), addr.Address.(state.AccAddress), math.NewInt(amount), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -181,7 +181,7 @@ var cancelUnbondingDelegationCmd = &cobra.Command{ addr.Address.(state.ValAddress), math.NewInt(amount), math.NewInt(height), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -218,7 +218,7 @@ var beginRedelegateCmd = &cobra.Command{ srcAddr.Address.(state.ValAddress), dstAddr.Address.(state.ValAddress), math.NewInt(amount), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -249,7 +249,7 @@ var undelegateCmd = &cobra.Command{ cmd.Context(), addr.Address.(state.ValAddress), math.NewInt(amount), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -280,7 +280,7 @@ var delegateCmd = &cobra.Command{ cmd.Context(), addr.Address.(state.ValAddress), math.NewInt(amount), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -378,7 +378,7 @@ var grantFeeCmd = &cobra.Command{ txResponse, err := client.State.GrantFee( cmd.Context(), granteeAddr.Address.(state.AccAddress), - math.NewInt(int64(amount)), GetTxOptions(), + math.NewInt(int64(amount)), GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -403,7 +403,7 @@ var revokeGrantFeeCmd = &cobra.Command{ txResponse, err := client.State.RevokeGrantFee( cmd.Context(), granteeAddr.Address.(state.AccAddress), - GetTxOptions(), + GetTxConfig(), ) return cmdnode.PrintOutput(txResponse, err, nil) }, @@ -464,8 +464,8 @@ func ApplyFlags(cmds ...*cobra.Command) { } } -func GetTxOptions() *state.TxOptions { - return state.NewTxOptions( +func GetTxConfig() *state.TxConfig { + return state.NewTxConfig( state.WithGasPrice(gasPrice), state.WithGas(gas), state.WithKeyName(keyName), diff --git a/nodebuilder/state/mocks/api.go b/nodebuilder/state/mocks/api.go index b59d42f923..b82b4fddce 100644 --- a/nodebuilder/state/mocks/api.go +++ b/nodebuilder/state/mocks/api.go @@ -86,7 +86,7 @@ func (mr *MockModuleMockRecorder) BalanceForAddress(arg0, arg1 interface{}) *gom } // BeginRedelegate mocks base method. -func (m *MockModule) BeginRedelegate(arg0 context.Context, arg1, arg2 types.ValAddress, arg3 math.Int, arg4 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) BeginRedelegate(arg0 context.Context, arg1, arg2 types.ValAddress, arg3 math.Int, arg4 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BeginRedelegate", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*types.TxResponse) @@ -101,7 +101,7 @@ func (mr *MockModuleMockRecorder) BeginRedelegate(arg0, arg1, arg2, arg3, arg4 i } // CancelUnbondingDelegation mocks base method. -func (m *MockModule) CancelUnbondingDelegation(arg0 context.Context, arg1 types.ValAddress, arg2, arg3 math.Int, arg4 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) CancelUnbondingDelegation(arg0 context.Context, arg1 types.ValAddress, arg2, arg3 math.Int, arg4 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CancelUnbondingDelegation", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*types.TxResponse) @@ -116,7 +116,7 @@ func (mr *MockModuleMockRecorder) CancelUnbondingDelegation(arg0, arg1, arg2, ar } // Delegate mocks base method. -func (m *MockModule) Delegate(arg0 context.Context, arg1 types.ValAddress, arg2 math.Int, arg3 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) Delegate(arg0 context.Context, arg1 types.ValAddress, arg2 math.Int, arg3 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Delegate", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*types.TxResponse) @@ -131,7 +131,7 @@ func (mr *MockModuleMockRecorder) Delegate(arg0, arg1, arg2, arg3 interface{}) * } // GrantFee mocks base method. -func (m *MockModule) GrantFee(arg0 context.Context, arg1 types.AccAddress, arg2 math.Int, arg3 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) GrantFee(arg0 context.Context, arg1 types.AccAddress, arg2 math.Int, arg3 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GrantFee", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*types.TxResponse) @@ -191,7 +191,7 @@ func (mr *MockModuleMockRecorder) QueryUnbonding(arg0, arg1 interface{}) *gomock } // RevokeGrantFee mocks base method. -func (m *MockModule) RevokeGrantFee(arg0 context.Context, arg1 types.AccAddress, arg2 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) RevokeGrantFee(arg0 context.Context, arg1 types.AccAddress, arg2 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RevokeGrantFee", arg0, arg1, arg2) ret0, _ := ret[0].(*types.TxResponse) @@ -206,7 +206,7 @@ func (mr *MockModuleMockRecorder) RevokeGrantFee(arg0, arg1, arg2 interface{}) * } // SubmitPayForBlob mocks base method. -func (m *MockModule) SubmitPayForBlob(arg0 context.Context, arg1 []*types1.Blob, arg2 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) SubmitPayForBlob(arg0 context.Context, arg1 []*types1.Blob, arg2 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SubmitPayForBlob", arg0, arg1, arg2) ret0, _ := ret[0].(*types.TxResponse) @@ -236,7 +236,7 @@ func (mr *MockModuleMockRecorder) SubmitTx(arg0, arg1 interface{}) *gomock.Call } // Transfer mocks base method. -func (m *MockModule) Transfer(arg0 context.Context, arg1 types.AccAddress, arg2 math.Int, arg3 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) Transfer(arg0 context.Context, arg1 types.AccAddress, arg2 math.Int, arg3 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Transfer", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*types.TxResponse) @@ -251,7 +251,7 @@ func (mr *MockModuleMockRecorder) Transfer(arg0, arg1, arg2, arg3 interface{}) * } // Undelegate mocks base method. -func (m *MockModule) Undelegate(arg0 context.Context, arg1 types.ValAddress, arg2 math.Int, arg3 *state.TxOptions) (*types.TxResponse, error) { +func (m *MockModule) Undelegate(arg0 context.Context, arg1 types.ValAddress, arg2 math.Int, arg3 *state.TxConfig) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Undelegate", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*types.TxResponse) diff --git a/nodebuilder/state/state.go b/nodebuilder/state/state.go index 09a681f71f..fd5855143e 100644 --- a/nodebuilder/state/state.go +++ b/nodebuilder/state/state.go @@ -33,7 +33,7 @@ type Module interface { // Transfer sends the given amount of coins from default wallet of the node to the given account // address. Transfer( - ctx context.Context, to state.AccAddress, amount state.Int, options *state.TxOptions, + ctx context.Context, to state.AccAddress, amount state.Int, options *state.TxConfig, ) (*state.TxResponse, error) // SubmitTx submits the given transaction/message to the // Celestia network and blocks until the tx is included in @@ -43,7 +43,7 @@ type Module interface { SubmitPayForBlob( ctx context.Context, blobs []*state.Blob, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // CancelUnbondingDelegation cancels a user's pending undelegation from a validator. CancelUnbondingDelegation( @@ -51,7 +51,7 @@ type Module interface { valAddr state.ValAddress, amount, height state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // BeginRedelegate sends a user's delegated tokens to a new validator for redelegation. BeginRedelegate( @@ -59,21 +59,21 @@ type Module interface { srcValAddr, dstValAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // Undelegate undelegates a user's delegated tokens, unbonding them from the current validator. Undelegate( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // Delegate sends a user's liquid tokens to a validator for delegation. Delegate( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) // QueryDelegation retrieves the delegation information between a delegator and a validator. @@ -91,13 +91,13 @@ type Module interface { ctx context.Context, grantee state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) RevokeGrantFee( ctx context.Context, grantee state.AccAddress, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) } @@ -114,38 +114,38 @@ type API struct { ctx context.Context, to state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"read"` SubmitPayForBlob func( ctx context.Context, blobs []*state.Blob, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` CancelUnbondingDelegation func( ctx context.Context, valAddr state.ValAddress, amount, height state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` BeginRedelegate func( ctx context.Context, srcValAddr, dstValAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` Undelegate func( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` Delegate func( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` QueryDelegation func( ctx context.Context, @@ -164,12 +164,12 @@ type API struct { ctx context.Context, grantee state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` RevokeGrantFee func( ctx context.Context, grantee state.AccAddress, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) `perm:"write"` } } @@ -186,7 +186,7 @@ func (api *API) Transfer( ctx context.Context, to state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.Transfer(ctx, to, amount, options) } @@ -198,7 +198,7 @@ func (api *API) SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, e func (api *API) SubmitPayForBlob( ctx context.Context, blobs []*state.Blob, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.SubmitPayForBlob(ctx, blobs, options) } @@ -207,7 +207,7 @@ func (api *API) CancelUnbondingDelegation( ctx context.Context, valAddr state.ValAddress, amount, height state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.CancelUnbondingDelegation(ctx, valAddr, amount, height, options) } @@ -216,7 +216,7 @@ func (api *API) BeginRedelegate( ctx context.Context, srcValAddr, dstValAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.BeginRedelegate(ctx, srcValAddr, dstValAddr, amount, options) } @@ -225,7 +225,7 @@ func (api *API) Undelegate( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.Undelegate(ctx, delAddr, amount, options) } @@ -234,7 +234,7 @@ func (api *API) Delegate( ctx context.Context, delAddr state.ValAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.Delegate(ctx, delAddr, amount, options) } @@ -265,7 +265,7 @@ func (api *API) GrantFee( ctx context.Context, grantee state.AccAddress, amount state.Int, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.GrantFee(ctx, grantee, amount, options) } @@ -273,7 +273,7 @@ func (api *API) GrantFee( func (api *API) RevokeGrantFee( ctx context.Context, grantee state.AccAddress, - options *state.TxOptions, + options *state.TxConfig, ) (*state.TxResponse, error) { return api.Internal.RevokeGrantFee(ctx, grantee, options) } diff --git a/nodebuilder/state/stub.go b/nodebuilder/state/stub.go index d16467a608..c041ed3c1c 100644 --- a/nodebuilder/state/stub.go +++ b/nodebuilder/state/stub.go @@ -35,7 +35,7 @@ func (s stubbedStateModule) Transfer( _ context.Context, _ state.AccAddress, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -47,7 +47,7 @@ func (s stubbedStateModule) SubmitTx(context.Context, state.Tx) (*state.TxRespon func (s stubbedStateModule) SubmitPayForBlob( context.Context, []*state.Blob, - *state.TxOptions, + *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -56,7 +56,7 @@ func (s stubbedStateModule) CancelUnbondingDelegation( _ context.Context, _ state.ValAddress, _, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -65,7 +65,7 @@ func (s stubbedStateModule) BeginRedelegate( _ context.Context, _, _ state.ValAddress, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -74,7 +74,7 @@ func (s stubbedStateModule) Undelegate( _ context.Context, _ state.ValAddress, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -83,7 +83,7 @@ func (s stubbedStateModule) Delegate( _ context.Context, _ state.ValAddress, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -113,7 +113,7 @@ func (s stubbedStateModule) GrantFee( _ context.Context, _ state.AccAddress, _ state.Int, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } @@ -121,7 +121,7 @@ func (s stubbedStateModule) GrantFee( func (s stubbedStateModule) RevokeGrantFee( _ context.Context, _ state.AccAddress, - _ *state.TxOptions, + _ *state.TxConfig, ) (*state.TxResponse, error) { return nil, ErrNoStateAccess } diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 4f5649ae8d..f9e10c5ea6 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -117,7 +117,7 @@ func TestBlobRPC(t *testing.T) { ) require.NoError(t, err) - height, err := rpcClient.Blob.Submit(ctx, []*blob.Blob{newBlob}, state.NewTxOptions()) + height, err := rpcClient.Blob.Submit(ctx, []*blob.Blob{newBlob}, state.NewTxConfig()) require.NoError(t, err) require.True(t, height != 0) } diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index e673814b75..c068ad1066 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -59,7 +59,7 @@ func TestBlobModule(t *testing.T) { fullClient := getAdminClient(ctx, fullNode, t) lightClient := getAdminClient(ctx, lightNode, t) - height, err := fullClient.Blob.Submit(ctx, blobs, state.NewTxOptions()) + height, err := fullClient.Blob.Submit(ctx, blobs, state.NewTxConfig()) require.NoError(t, err) _, err = fullClient.Header.WaitForHeight(ctx, height) @@ -142,7 +142,7 @@ func TestBlobModule(t *testing.T) { ) require.NoError(t, err) - height, err := fullClient.Blob.Submit(ctx, []*blob.Blob{b, b}, state.NewTxOptions()) + height, err := fullClient.Blob.Submit(ctx, []*blob.Blob{b, b}, state.NewTxConfig()) require.NoError(t, err) _, err = fullClient.Header.WaitForHeight(ctx, height) @@ -171,7 +171,7 @@ func TestBlobModule(t *testing.T) { // different pfbs. name: "Submit the same blob in different pfb", doFn: func(t *testing.T) { - h, err := fullClient.Blob.Submit(ctx, []*blob.Blob{blobs[0]}, state.NewTxOptions()) + h, err := fullClient.Blob.Submit(ctx, []*blob.Blob{blobs[0]}, state.NewTxConfig()) require.NoError(t, err) _, err = fullClient.Header.WaitForHeight(ctx, h) diff --git a/state/core_access.go b/state/core_access.go index 55121ee8f9..c8f1b08f68 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -187,27 +187,27 @@ func (ca *CoreAccessor) cancelCtx() { } // SubmitPayForBlob builds, signs, and synchronously submits a MsgPayForBlob with additional options defined -// in `TxOptions`. It blocks until the transaction is committed and returns the TxResponse. +// in `TxConfig`. It blocks until the transaction is committed and returns the TxResponse. // The user can specify additional options that can bee applied to the Tx. func (ca *CoreAccessor) SubmitPayForBlob( ctx context.Context, appblobs []*Blob, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if len(appblobs) == 0 { return nil, errors.New("state: no blobs provided") } var feeGrant user.TxOption - if options.FeeGranterAddress() != "" { - granter, err := parseAccAddressFromString(options.FeeGranterAddress()) + if cfg.FeeGranterAddress() != "" { + granter, err := parseAccAddressFromString(cfg.FeeGranterAddress()) if err != nil { return nil, err } feeGrant = user.SetFeeGranter(granter) } - gas := options.GasLimit() + gas := cfg.GasLimit() if gas == 0 { blobSizes := make([]uint32, len(appblobs)) for i, blob := range appblobs { @@ -216,14 +216,14 @@ func (ca *CoreAccessor) SubmitPayForBlob( gas = estimateGasForBlobs(blobSizes) } - gasPrice := options.GasPrice() - if options.GasPrice() == DefaultPrice { + gasPrice := cfg.GasPrice() + if cfg.GasPrice() == DefaultPrice { gasPrice = ca.getMinGasPrice() } fee := calculateFee(gas, gasPrice) - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } @@ -389,20 +389,20 @@ func (ca *CoreAccessor) Transfer( ctx context.Context, addr AccAddress, amount Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if amount.IsNil() || amount.Int64() <= 0 { return nil, ErrInvalidAmount } - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } coins := sdktypes.NewCoins(sdktypes.NewCoin(app.BondDenom, amount)) msg := banktypes.NewMsgSend(signer, addr, coins) - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) CancelUnbondingDelegation( @@ -410,20 +410,20 @@ func (ca *CoreAccessor) CancelUnbondingDelegation( valAddr ValAddress, amount, height Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if amount.IsNil() || amount.Int64() <= 0 { return nil, ErrInvalidAmount } - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } coins := sdktypes.NewCoin(app.BondDenom, amount) msg := stakingtypes.NewMsgCancelUnbondingDelegation(signer, valAddr, height.Int64(), coins) - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) BeginRedelegate( @@ -431,60 +431,60 @@ func (ca *CoreAccessor) BeginRedelegate( srcValAddr, dstValAddr ValAddress, amount Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if amount.IsNil() || amount.Int64() <= 0 { return nil, ErrInvalidAmount } - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } coins := sdktypes.NewCoin(app.BondDenom, amount) msg := stakingtypes.NewMsgBeginRedelegate(signer, srcValAddr, dstValAddr, coins) - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) Undelegate( ctx context.Context, delAddr ValAddress, amount Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if amount.IsNil() || amount.Int64() <= 0 { return nil, ErrInvalidAmount } - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } coins := sdktypes.NewCoin(app.BondDenom, amount) msg := stakingtypes.NewMsgUndelegate(signer, delAddr, coins) - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) Delegate( ctx context.Context, delAddr ValAddress, amount Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { if amount.IsNil() || amount.Int64() <= 0 { return nil, ErrInvalidAmount } - signer, err := ca.getSigner(options) + signer, err := ca.getSigner(cfg) if err != nil { return nil, err } coins := sdktypes.NewCoin(app.BondDenom, amount) msg := stakingtypes.NewMsgDelegate(signer, delAddr, coins) - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) QueryDelegation( @@ -526,9 +526,9 @@ func (ca *CoreAccessor) GrantFee( ctx context.Context, grantee AccAddress, amount Int, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { - granter, err := ca.getSigner(options) + granter, err := ca.getSigner(cfg) if err != nil { return nil, err } @@ -543,21 +543,21 @@ func (ca *CoreAccessor) GrantFee( if err != nil { return nil, err } - return ca.submitMsg(ctx, msg, options) + return ca.submitMsg(ctx, msg, cfg) } func (ca *CoreAccessor) RevokeGrantFee( ctx context.Context, grantee AccAddress, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { - granter, err := ca.getSigner(options) + granter, err := ca.getSigner(cfg) if err != nil { return nil, err } msg := feegrant.NewMsgRevokeAllowance(granter, grantee) - return ca.submitMsg(ctx, &msg, options) + return ca.submitMsg(ctx, &msg, cfg) } func (ca *CoreAccessor) LastPayForBlob() int64 { @@ -627,11 +627,11 @@ func (ca *CoreAccessor) setupTxClient(ctx context.Context, keyName string) (*use func (ca *CoreAccessor) submitMsg( ctx context.Context, msg sdktypes.Msg, - options *TxOptions, + cfg *TxConfig, ) (*TxResponse, error) { - txOptions := make([]user.TxOption, 0) + txConfig := make([]user.TxOption, 0) var ( - gas = options.GasLimit() + gas = cfg.GasLimit() err error ) if gas == 0 { @@ -641,32 +641,32 @@ func (ca *CoreAccessor) submitMsg( } } - gasPrice := options.GasPrice() + gasPrice := cfg.GasPrice() if gasPrice == DefaultPrice { gasPrice = ca.minGasPrice } fee := calculateFee(gas, gasPrice) - txOptions = append(txOptions, user.SetGasLimitAndFee(gas, float64(fee))) + txConfig = append(txConfig, user.SetGasLimitAndFee(gas, float64(fee))) - if options.FeeGranterAddress() != "" { - granter, err := parseAccAddressFromString(options.FeeGranterAddress()) + if cfg.FeeGranterAddress() != "" { + granter, err := parseAccAddressFromString(cfg.FeeGranterAddress()) if err != nil { return nil, fmt.Errorf("getting granter: %w", err) } - txOptions = append(txOptions, user.SetFeeGranter(granter)) + txConfig = append(txConfig, user.SetFeeGranter(granter)) } - resp, err := ca.client.SubmitTx(ctx, []sdktypes.Msg{msg}, txOptions...) + resp, err := ca.client.SubmitTx(ctx, []sdktypes.Msg{msg}, txConfig...) return unsetTx(resp), err } -func (ca *CoreAccessor) getSigner(options *TxOptions) (AccAddress, error) { +func (ca *CoreAccessor) getSigner(cfg *TxConfig) (AccAddress, error) { switch { - case options.SignerAddress() != "": - return parseAccAddressFromString(options.SignerAddress()) - case options.KeyName() != "" && options.KeyName() != ca.defaultSignerAccount: - return parseAccountKey(ca.keyring, options.KeyName()) + case cfg.SignerAddress() != "": + return parseAccAddressFromString(cfg.SignerAddress()) + case cfg.KeyName() != "" && cfg.KeyName() != ca.defaultSignerAccount: + return parseAccountKey(ca.keyring, cfg.KeyName()) default: return ca.defaultSignerAddress, nil } diff --git a/state/core_access_test.go b/state/core_access_test.go index 2c4940d5bd..84cebe6002 100644 --- a/state/core_access_test.go +++ b/state/core_access_test.go @@ -68,7 +68,7 @@ func TestSubmitPayForBlob(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - resp, err := ca.SubmitPayForBlob(ctx, tc.blobs, NewTxOptions()) + resp, err := ca.SubmitPayForBlob(ctx, tc.blobs, NewTxConfig()) require.Equal(t, tc.expErr, err) if err == nil { require.EqualValues(t, 0, resp.Code) @@ -78,7 +78,7 @@ func TestSubmitPayForBlob(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - opts := NewTxOptions( + opts := NewTxConfig( WithGas(tc.gasLim), WithGasPrice(tc.gasPrice), WithKeyName(accounts[2]), @@ -131,7 +131,7 @@ func TestTransfer(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - opts := NewTxOptions( + opts := NewTxConfig( WithGas(tc.gasLim), WithGasPrice(tc.gasPrice), WithKeyName(accounts[2]), @@ -191,7 +191,7 @@ func TestDelegate(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - opts := NewTxOptions( + opts := NewTxConfig( WithGas(tc.gasLim), WithGasPrice(tc.gasPrice), WithKeyName(accounts[2]), diff --git a/state/tx_options.go b/state/tx_config.go similarity index 71% rename from state/tx_options.go rename to state/tx_config.go index 4dd57ced17..c4d1486061 100644 --- a/state/tx_options.go +++ b/state/tx_config.go @@ -15,24 +15,24 @@ import ( const ( DefaultPrice float64 = -1.0 - // gasMultiplier is used to increase gas limit in case if tx has additional options. + // gasMultiplier is used to increase gas limit in case if tx has additional cfg. gasMultiplier = 1.1 ) -func NewTxOptions(attributes ...Attribute) *TxOptions { - options := &TxOptions{gasPrice: DefaultPrice} +func NewTxConfig(attributes ...Attribute) *TxConfig { + options := &TxConfig{gasPrice: DefaultPrice} for _, attr := range attributes { attr(options) } return options } -// TxOptions specifies additional options that will be applied to the Tx. +// TxConfig specifies additional options that will be applied to the Tx. // Implements `Option` interface. -type TxOptions struct { +type TxConfig struct { // Specifies the address from the keystore that will sign transactions. // NOTE: Only `signerAddress` or `KeyName` should be passed. - // signerAddress is a primary options. This means If both the address and the key are specified, + // signerAddress is a primary cfg. This means If both the address and the key are specified, // the address field will take priority. signerAddress string // Specifies the key from the keystore associated with an account that @@ -52,22 +52,22 @@ type TxOptions struct { feeGranterAddress string } -func (options *TxOptions) GasPrice() float64 { - if !options.isGasPriceSet { +func (cfg *TxConfig) GasPrice() float64 { + if !cfg.isGasPriceSet { return DefaultPrice } - return options.gasPrice + return cfg.gasPrice } -func (options *TxOptions) GasLimit() uint64 { return options.gas } +func (cfg *TxConfig) GasLimit() uint64 { return cfg.gas } -func (options *TxOptions) KeyName() string { return options.keyName } +func (cfg *TxConfig) KeyName() string { return cfg.keyName } -func (options *TxOptions) SignerAddress() string { return options.signerAddress } +func (cfg *TxConfig) SignerAddress() string { return cfg.signerAddress } -func (options *TxOptions) FeeGranterAddress() string { return options.feeGranterAddress } +func (cfg *TxConfig) FeeGranterAddress() string { return cfg.feeGranterAddress } -type jsonTxOptions struct { +type jsonTxConfig struct { GasPrice float64 `json:"gas_price,omitempty"` IsGasPriceSet bool `json:"is_gas_price_set,omitempty"` Gas uint64 `json:"gas,omitempty"` @@ -76,31 +76,31 @@ type jsonTxOptions struct { FeeGranterAddress string `json:"fee_granter_address,omitempty"` } -func (options *TxOptions) MarshalJSON() ([]byte, error) { - jsonOpts := &jsonTxOptions{ - SignerAddress: options.signerAddress, - KeyName: options.keyName, - GasPrice: options.gasPrice, - IsGasPriceSet: options.isGasPriceSet, - Gas: options.gas, - FeeGranterAddress: options.feeGranterAddress, +func (cfg *TxConfig) MarshalJSON() ([]byte, error) { + jsonOpts := &jsonTxConfig{ + SignerAddress: cfg.signerAddress, + KeyName: cfg.keyName, + GasPrice: cfg.gasPrice, + IsGasPriceSet: cfg.isGasPriceSet, + Gas: cfg.gas, + FeeGranterAddress: cfg.feeGranterAddress, } return json.Marshal(jsonOpts) } -func (options *TxOptions) UnmarshalJSON(data []byte) error { - var jsonOpts jsonTxOptions +func (cfg *TxConfig) UnmarshalJSON(data []byte) error { + var jsonOpts jsonTxConfig err := json.Unmarshal(data, &jsonOpts) if err != nil { - return fmt.Errorf("unmarshalling TxOptions: %w", err) + return fmt.Errorf("unmarshalling TxConfig: %w", err) } - options.keyName = jsonOpts.KeyName - options.signerAddress = jsonOpts.SignerAddress - options.gasPrice = jsonOpts.GasPrice - options.isGasPriceSet = jsonOpts.IsGasPriceSet - options.gas = jsonOpts.Gas - options.feeGranterAddress = jsonOpts.FeeGranterAddress + cfg.keyName = jsonOpts.KeyName + cfg.signerAddress = jsonOpts.SignerAddress + cfg.gasPrice = jsonOpts.GasPrice + cfg.isGasPriceSet = jsonOpts.IsGasPriceSet + cfg.gas = jsonOpts.Gas + cfg.feeGranterAddress = jsonOpts.FeeGranterAddress return nil } @@ -143,16 +143,16 @@ func parseAccAddressFromString(addrStr string) (sdktypes.AccAddress, error) { // Attribute is the functional option that is applied to the TxOption instance // to configure parameters. -type Attribute func(options *TxOptions) +type Attribute func(cfg *TxConfig) // WithGasPrice is an attribute that allows to specify a GasPrice, which is needed // to calculate the fee. In case GasPrice is not specified, the global GasPrice fetched from // celestia-app will be used. func WithGasPrice(gasPrice float64) Attribute { - return func(options *TxOptions) { + return func(cfg *TxConfig) { if gasPrice >= 0 { - options.gasPrice = gasPrice - options.isGasPriceSet = true + cfg.gasPrice = gasPrice + cfg.isGasPriceSet = true } } } @@ -160,8 +160,8 @@ func WithGasPrice(gasPrice float64) Attribute { // WithGas is an attribute that allows to specify Gas. // Gas will be calculated in case it wasn't specified. func WithGas(gas uint64) Attribute { - return func(options *TxOptions) { - options.gas = gas + return func(cfg *TxConfig) { + cfg.gas = gas } } @@ -169,22 +169,22 @@ func WithGas(gas uint64) Attribute { // sign the transaction. This key should be associated with the address and stored // locally in the key store. Default Account will be used in case it wasn't specified. func WithKeyName(key string) Attribute { - return func(options *TxOptions) { - options.keyName = key + return func(cfg *TxConfig) { + cfg.keyName = key } } // WithSignerAddress is an attribute that allows you to specify an address, that will sign the transaction. // This address must be stored locally in the key store. Default signerAddress will be used in case it wasn't specified. func WithSignerAddress(address string) Attribute { - return func(options *TxOptions) { - options.signerAddress = address + return func(cfg *TxConfig) { + cfg.signerAddress = address } } // WithFeeGranterAddress is an attribute that allows you to specify a GranterAddress to pay the fees. func WithFeeGranterAddress(granter string) Attribute { - return func(options *TxOptions) { - options.feeGranterAddress = granter + return func(cfg *TxConfig) { + cfg.feeGranterAddress = granter } } diff --git a/state/tx_options_test.go b/state/tx_config_test.go similarity index 91% rename from state/tx_options_test.go rename to state/tx_config_test.go index 835db17de2..69ade8f24d 100644 --- a/state/tx_options_test.go +++ b/state/tx_config_test.go @@ -8,7 +8,7 @@ import ( ) func TestMarshallingOptions(t *testing.T) { - opts := NewTxOptions( + opts := NewTxConfig( WithGas(10_000), WithGasPrice(0.002), WithKeyName("test"), @@ -19,7 +19,7 @@ func TestMarshallingOptions(t *testing.T) { data, err := json.Marshal(opts) require.NoError(t, err) - newOpts := &TxOptions{} + newOpts := &TxConfig{} err = json.Unmarshal(data, newOpts) require.NoError(t, err) require.Equal(t, opts, newOpts)