forked from celestiaorg/celestia-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_tx.go
51 lines (45 loc) · 1.6 KB
/
check_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package app
import (
"fmt"
"github.com/celestiaorg/celestia-app/pkg/blob"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
abci "github.com/tendermint/tendermint/abci/types"
)
// CheckTx implements the ABCI interface and executes a tx in CheckTx mode. This
// method wraps the default Baseapp's method so that it can parse and check
// transactions that contain blobs.
func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
tx := req.Tx
// check if the transaction contains blobs
btx, isBlob := blob.UnmarshalBlobTx(tx)
if !isBlob {
// reject transactions that can't be decoded
sdkTx, err := app.txConfig.TxDecoder()(tx)
if err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
}
// reject transactions that have a MsgPFB but no blobs attached to the tx
for _, msg := range sdkTx.GetMsgs() {
if _, ok := msg.(*blobtypes.MsgPayForBlobs); !ok {
continue
}
return sdkerrors.ResponseCheckTxWithEvents(blobtypes.ErrNoBlobs, 0, 0, []abci.Event{}, false)
}
// don't do anything special if we have a normal transaction
return app.BaseApp.CheckTx(req)
}
switch req.Type {
// new transactions must be checked in their entirety
case abci.CheckTxType_New:
err := blobtypes.ValidateBlobTx(app.txConfig, btx)
if err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
}
case abci.CheckTxType_Recheck:
default:
panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
}
req.Tx = btx.Tx
return app.BaseApp.CheckTx(req)
}