Skip to content

Commit

Permalink
Merge pull request #4 from FastLane-Labs/bundle-type
Browse files Browse the repository at this point in the history
Add bundle type
  • Loading branch information
jj1980a authored Sep 3, 2024
2 parents 014d509 + 766f35c commit a9e01d9
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions types/bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package types

import (
"math/big"

"github.com/ethereum/go-ethereum/common/hexutil"
)

// External representation of a bundle
type BundleRaw struct {
ChainId *hexutil.Big `json:"chainId"`
UserOperation *UserOperationRaw `json:"userOperation"`
SolverOperations SolverOperationsRaw `json:"solverOperations"`
DAppOperation *DAppOperationRaw `json:"dAppOperation"`
}

func (b *BundleRaw) Decode() *Bundle {
return &Bundle{
ChainId: b.ChainId.ToInt().Uint64(),
UserOperation: b.UserOperation.Decode(),
SolverOperations: b.SolverOperations.Decode(),
DAppOperation: b.DAppOperation.Decode(),
}
}

// Internal representation of a bundle
type Bundle struct {
ChainId uint64
UserOperation *UserOperation
SolverOperations SolverOperations
DAppOperation *DAppOperation
}

func (b *Bundle) Sanitize() {
b.UserOperation.Sanitize()
b.DAppOperation.Sanitize()
b.SolverOperations.Sanitize()
}

func (b *Bundle) EncodeToRaw() *BundleRaw {
b.Sanitize()

return &BundleRaw{
ChainId: (*hexutil.Big)(big.NewInt(int64(b.ChainId))),
UserOperation: b.UserOperation.EncodeToRaw(),
SolverOperations: b.SolverOperations.EncodeToRaw(),
DAppOperation: b.DAppOperation.EncodeToRaw(),
}
}

0 comments on commit a9e01d9

Please sign in to comment.