block-sdk/lanes/mev/utils.go
Alex Johnson 0346c07e86
chore: update all deps (#184)
* deps

* lint fix

* update proto and format

* proto update deps

* remove cmd
2023-11-02 14:27:10 -04:00

37 lines
1.0 KiB
Go

package mev
import (
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)
// GetMsgAuctionBidFromTx attempts to retrieve a MsgAuctionBid from an sdk.Tx if
// one exists. If a MsgAuctionBid does exist and other messages are also present,
// an error is returned. If no MsgAuctionBid is present, <nil, nil> is returned.
func GetMsgAuctionBidFromTx(tx sdk.Tx) (*auctiontypes.MsgAuctionBid, error) {
auctionBidMsgs := make([]*auctiontypes.MsgAuctionBid, 0)
for _, msg := range tx.GetMsgs() {
t, ok := msg.(*auctiontypes.MsgAuctionBid)
if ok {
auctionBidMsgs = append(auctionBidMsgs, t)
}
}
switch {
case len(auctionBidMsgs) == 0:
// a normal transaction without a MsgAuctionBid message
return nil, nil
case len(auctionBidMsgs) == 1 && len(tx.GetMsgs()) == 1:
// a single MsgAuctionBid message transaction
return auctionBidMsgs[0], nil
default:
// a transaction with at at least one MsgAuctionBid message
return nil, errors.New("invalid MsgAuctionBid transaction")
}
}