|
9 | 9 | "math/big" |
10 | 10 |
|
11 | 11 | "github.com/ethereum/go-ethereum/common" |
| 12 | + "github.com/ethereum/go-ethereum/common/hexutil" |
12 | 13 | "github.com/ethereum/go-ethereum/core/types" |
13 | 14 | "github.com/ethereum/go-ethereum/params" |
14 | 15 | "github.com/ethereum/go-ethereum/rollup/rcfg" |
@@ -153,6 +154,22 @@ func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int { |
153 | 154 | return new(big.Int).Add(l1Gas, overhead) |
154 | 155 | } |
155 | 156 |
|
| 157 | +// DeriveL1GasInfo reads L1 gas related information to be included |
| 158 | +// on the receipt |
| 159 | +func DeriveL1GasInfo(msg Message, state StateDB) (*big.Int, *big.Int, *big.Int, *big.Float, error) { |
| 160 | + tx := asTransaction(msg) |
| 161 | + raw, err := rlpEncode(tx) |
| 162 | + fmt.Println(hexutil.Encode(raw)) |
| 163 | + if err != nil { |
| 164 | + return nil, nil, nil, nil, err |
| 165 | + } |
| 166 | + |
| 167 | + l1GasPrice, overhead, scalar := readGPOStorageSlots(rcfg.L2GasPriceOracleAddress, state) |
| 168 | + l1GasUsed := CalculateL1GasUsed(raw, overhead) |
| 169 | + l1Fee := CalculateL1Fee(raw, overhead, l1GasPrice, scalar) |
| 170 | + return l1Fee, l1GasPrice, l1GasUsed, scalar, nil |
| 171 | +} |
| 172 | + |
156 | 173 | func readGPOStorageSlots(addr common.Address, state StateDB) (*big.Int, *big.Int, *big.Float) { |
157 | 174 | l1GasPrice := state.GetState(addr, rcfg.L1GasPriceSlot) |
158 | 175 | overhead := state.GetState(addr, rcfg.OverheadSlot) |
@@ -183,7 +200,7 @@ func rlpEncode(tx *types.Transaction) ([]byte, error) { |
183 | 200 |
|
184 | 201 | r, v, s := tx.RawSignatureValues() |
185 | 202 | if r.Cmp(common.Big0) != 0 || v.Cmp(common.Big0) != 0 || s.Cmp(common.Big0) != 0 { |
186 | | - return []byte{}, errTransactionSigned |
| 203 | + return nil, errTransactionSigned |
187 | 204 | } |
188 | 205 |
|
189 | 206 | // Slice off the 0 bytes representing the signature |
|
0 commit comments