Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: sendBundle return bundle hash #20

Merged
merged 1 commit into from
Apr 18, 2024
Merged
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
22 changes: 14 additions & 8 deletions internal/ethapi/api_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

Expand Down Expand Up @@ -35,9 +36,9 @@ func (s *PrivateTxBundleAPI) BundlePrice(ctx context.Context) *big.Int {

// SendBundle will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce and ensuring validity
func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBundleArgs) error {
func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBundleArgs) (common.Hash, error) {
if len(args.Txs) == 0 {
return newBundleError(errors.New("bundle missing txs"))
return common.Hash{}, newBundleError(errors.New("bundle missing txs"))
}

currentHeader := s.b.CurrentHeader()
Expand All @@ -48,30 +49,30 @@ func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBund
}

if args.MaxBlockNumber != 0 && args.MaxBlockNumber > currentHeader.Number.Uint64()+MaxBundleAliveBlock {
return newBundleError(errors.New("the maxBlockNumber should not be lager than currentBlockNum + 100"))
return common.Hash{}, newBundleError(errors.New("the maxBlockNumber should not be lager than currentBlockNum + 100"))
}

if args.MaxTimestamp != nil && args.MinTimestamp != nil && *args.MaxTimestamp != 0 && *args.MinTimestamp != 0 {
if *args.MaxTimestamp <= *args.MinTimestamp {
return newBundleError(errors.New("the maxTimestamp should not be less than minTimestamp"))
return common.Hash{}, newBundleError(errors.New("the maxTimestamp should not be less than minTimestamp"))
}
}

if args.MaxTimestamp != nil && *args.MaxTimestamp != 0 && *args.MaxTimestamp < currentHeader.Time {
return newBundleError(errors.New("the maxTimestamp should not be less than currentBlockTimestamp"))
return common.Hash{}, newBundleError(errors.New("the maxTimestamp should not be less than currentBlockTimestamp"))
}

if (args.MaxTimestamp != nil && *args.MaxTimestamp > currentHeader.Time+MaxBundleAliveTime) ||
(args.MinTimestamp != nil && *args.MinTimestamp > currentHeader.Time+MaxBundleAliveTime) {
return newBundleError(errors.New("the minTimestamp/maxTimestamp should not be later than currentBlockTimestamp + 5 minutes"))
return common.Hash{}, newBundleError(errors.New("the minTimestamp/maxTimestamp should not be later than currentBlockTimestamp + 5 minutes"))
}

var txs types.Transactions

for _, encodedTx := range args.Txs {
tx := new(types.Transaction)
if err := tx.UnmarshalBinary(encodedTx); err != nil {
return err
return common.Hash{}, err
}
txs = append(txs, tx)
}
Expand All @@ -94,7 +95,12 @@ func (s *PrivateTxBundleAPI) SendBundle(ctx context.Context, args types.SendBund
RevertingTxHashes: args.RevertingTxHashes,
}

return s.b.SendBundle(ctx, bundle)
err := s.b.SendBundle(ctx, bundle)
if err != nil {
return common.Hash{}, err
}

return bundle.Hash(), nil
}

func newBundleError(err error) *bundleError {
Expand Down
Loading