Skip to content

Commit

Permalink
refactoring!(state): extend SubmitPayForBlob method (#1963)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed May 29, 2023
1 parent 9359b65 commit fecaebf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
12 changes: 11 additions & 1 deletion api/gateway/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/cosmos/cosmos-sdk/types"
"github.com/gorilla/mux"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/celestiaorg/celestia-node/state"
)

Expand Down Expand Up @@ -137,8 +140,15 @@ func (h *Handler) handleSubmitPFB(w http.ResponseWriter, r *http.Request) {
return
}
fee := types.NewInt(req.Fee)

blob := &apptypes.Blob{
NamespaceId: nID,
Data: data,
ShareVersion: uint32(appconsts.DefaultShareVersion),
}

// perform request
txResp, err := h.state.SubmitPayForBlob(r.Context(), nID, data, fee, req.GasLimit)
txResp, err := h.state.SubmitPayForBlob(r.Context(), fee, req.GasLimit, blob)
if err != nil {
writeError(w, http.StatusInternalServerError, submitPFBEndpoint, err)
return
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
logging "github.com/ipfs/go-log/v2"
)

const APIVersion = "v0.1.0"
const APIVersion = "v0.1.1"

type module struct {
tp Type
Expand Down
24 changes: 14 additions & 10 deletions nodebuilder/state/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions nodebuilder/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/celestiaorg/nmt/namespace"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/celestiaorg/celestia-node/state"
)
Expand Down Expand Up @@ -44,10 +44,9 @@ type Module interface {
// SubmitPayForBlob builds, signs and submits a PayForBlob transaction.
SubmitPayForBlob(
ctx context.Context,
nID namespace.ID,
data []byte,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
) (*state.TxResponse, error)

// CancelUnbondingDelegation cancels a user's pending undelegation from a validator.
Expand Down Expand Up @@ -113,10 +112,9 @@ type API struct {
SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"write"`
SubmitPayForBlob func(
ctx context.Context,
nID namespace.ID,
data []byte,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
) (*state.TxResponse, error) `perm:"write"`
CancelUnbondingDelegation func(
ctx context.Context,
Expand Down Expand Up @@ -192,12 +190,11 @@ func (api *API) SubmitTx(ctx context.Context, tx state.Tx) (*state.TxResponse, e

func (api *API) SubmitPayForBlob(
ctx context.Context,
nID namespace.ID,
data []byte,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
) (*state.TxResponse, error) {
return api.Internal.SubmitPayForBlob(ctx, nID, data, fee, gasLim)
return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs...)
}

func (api *API) CancelUnbondingDelegation(
Expand Down
12 changes: 6 additions & 6 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/x/blob"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/nmt/namespace"

"github.com/celestiaorg/celestia-node/header"
)
Expand Down Expand Up @@ -158,17 +156,19 @@ func (ca *CoreAccessor) constructSignedTx(

func (ca *CoreAccessor) SubmitPayForBlob(
ctx context.Context,
nID namespace.ID,
data []byte,
fee Int,
gasLim uint64,
blobs ...*apptypes.Blob,
) (*TxResponse, error) {
b := &apptypes.Blob{NamespaceId: nID, Data: data, ShareVersion: uint32(appconsts.DefaultShareVersion)}
if len(blobs) == 0 {
return nil, errors.New("state: no blobs provided")
}

response, err := blob.SubmitPayForBlob(
ctx,
ca.signer,
ca.coreConn,
[]*apptypes.Blob{b},
blobs,
apptypes.SetGasLimit(gasLim),
withFee(fee),
)
Expand Down

0 comments on commit fecaebf

Please sign in to comment.