Skip to content
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

refactoring!(state): extend SubmitPayForBlob method #1963

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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