Skip to content

Commit 9164b47

Browse files
committed
support 7702 in rpc
1 parent 3998a41 commit 9164b47

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

rpc/types/utils.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,56 @@ func NewRPCTransaction(
225225
} else {
226226
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
227227
}
228+
229+
case ethtypes.BlobTxType:
230+
al := tx.AccessList()
231+
yparity := hexutil.Uint64(v.Sign())
232+
result.Accesses = &al
233+
result.ChainID = (*hexutil.Big)(tx.ChainId())
234+
result.YParity = &yparity
235+
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
236+
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
237+
// if the transaction has been mined, compute the effective gas price
238+
if baseFee != nil && blockHash != (common.Hash{}) {
239+
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
240+
} else {
241+
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
242+
}
243+
result.MaxFeePerBlobGas = (*hexutil.Big)(tx.BlobGasFeeCap())
244+
result.BlobVersionedHashes = tx.BlobHashes()
245+
246+
case ethtypes.SetCodeTxType:
247+
al := tx.AccessList()
248+
yparity := hexutil.Uint64(v.Sign())
249+
result.Accesses = &al
250+
result.ChainID = (*hexutil.Big)(tx.ChainId())
251+
result.YParity = &yparity
252+
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
253+
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
254+
// if the transaction has been mined, compute the effective gas price
255+
if baseFee != nil && blockHash != (common.Hash{}) {
256+
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
257+
} else {
258+
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
259+
}
260+
result.AuthorizationList = tx.SetCodeAuthorizations()
228261
}
229262

230263
return result, nil
231264
}
232265

266+
// effectiveGasPrice computes the transaction gas fee, based on the given basefee value.
267+
//
268+
// price = min(gasTipCap + baseFee, gasFeeCap)
269+
func effectiveGasPrice(tx *ethtypes.Transaction, baseFee *big.Int) *big.Int {
270+
fee := tx.GasTipCap()
271+
fee = fee.Add(fee, baseFee)
272+
if tx.GasFeeCapIntCmp(fee) < 0 {
273+
return tx.GasFeeCap()
274+
}
275+
return fee
276+
}
277+
233278
// BaseFeeFromEvents parses the feemarket basefee from cosmos events
234279
func BaseFeeFromEvents(events []abci.Event) *big.Int {
235280
for _, event := range events {

0 commit comments

Comments
 (0)