getTransaction (#24)

This commit is contained in:
Dror Tirosh 2024-08-11 21:25:59 +03:00 committed by GitHub
parent a6cb9caa28
commit 4513a3d59c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 79 additions and 19 deletions

View file

@ -1329,7 +1329,7 @@ func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inc
type RPCTransaction struct { type RPCTransaction struct {
BlockHash *common.Hash `json:"blockHash"` BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"` BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from"` From common.Address `json:"from,omitempty"`
Gas hexutil.Uint64 `json:"gas"` Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"` GasPrice *hexutil.Big `json:"gasPrice"`
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
@ -1338,17 +1338,43 @@ type RPCTransaction struct {
Hash common.Hash `json:"hash"` Hash common.Hash `json:"hash"`
Input hexutil.Bytes `json:"input"` Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"` Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to"` To *common.Address `json:"to,omitempty"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"` Value *hexutil.Big `json:"value"`
Type hexutil.Uint64 `json:"type"` Type hexutil.Uint64 `json:"type"`
Accesses *types.AccessList `json:"accessList,omitempty"` Accesses *types.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"` ChainID *hexutil.Big `json:"chainId,omitempty"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v,omitempty"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r,omitempty"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s,omitempty"`
YParity *hexutil.Uint64 `json:"yParity,omitempty"` YParity *hexutil.Uint64 `json:"yParity,omitempty"`
// Introduced by RIP-7560 Transaction
Sender *common.Address `json:"sender,omitempty"`
Signature *hexutil.Bytes `json:"signature,omitempty"`
Paymaster *common.Address `json:"paymaster,omitempty"`
PaymasterData *hexutil.Bytes `json:"paymasterData,omitempty"`
Deployer *common.Address `json:"deployer,omitempty"`
DeployerData *hexutil.Bytes `json:"deployerData,omitempty"`
BuilderFee *hexutil.Big `json:"builderFee,omitempty"`
ValidationGas *hexutil.Uint64 `json:"verificationGasLimit,omitempty"`
PaymasterValidationGasLimit *hexutil.Uint64 `json:"paymasterVerificationGasLimit,omitempty"`
PostOpGas *hexutil.Uint64 `json:"paymasterPostOpGasLimit,omitempty"`
}
func toBytes(data []byte) *hexutil.Bytes {
if len(data) == 0 {
return nil
}
return (*hexutil.Bytes)(&data)
}
func conditional_uint64(v uint64, addr *common.Address) *hexutil.Uint64 {
if addr == nil {
return nil
}
return (*hexutil.Uint64)(&v)
} }
// newRPCTransaction returns a transaction that will serialize to the RPC // newRPCTransaction returns a transaction that will serialize to the RPC
@ -1407,6 +1433,37 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap()) result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
} }
case types.Rip7560Type:
rip7560Tx := tx.Rip7560TransactionData()
result.S = nil
result.R = nil
result.V = nil
result.Input = rip7560Tx.Data
result.Sender = rip7560Tx.Sender
result.Signature = toBytes(rip7560Tx.Signature)
result.Gas = hexutil.Uint64(tx.Gas())
result.Paymaster = rip7560Tx.Paymaster
result.PaymasterData = toBytes(rip7560Tx.PaymasterData)
result.Deployer = rip7560Tx.Deployer
result.DeployerData = toBytes(rip7560Tx.DeployerData)
result.BuilderFee = (*hexutil.Big)(rip7560Tx.BuilderFee)
result.ValidationGas = (*hexutil.Uint64)(&rip7560Tx.ValidationGasLimit)
result.PaymasterValidationGasLimit = conditional_uint64(rip7560Tx.PaymasterValidationGasLimit, rip7560Tx.Paymaster)
result.PostOpGas = conditional_uint64(rip7560Tx.PostOpGas, rip7560Tx.Paymaster)
//shared fields with DynamicFeeTxType
result.ChainID = (*hexutil.Big)(tx.ChainId())
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
// if the transaction has been mined, compute the effective gas price
if baseFee != nil && blockHash != (common.Hash{}) {
// price = min(gasTipCap + baseFee, gasFeeCap)
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
} else {
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
}
case types.BlobTxType: case types.BlobTxType:
al := tx.AccessList() al := tx.AccessList()
yparity := hexutil.Uint64(v.Sign()) yparity := hexutil.Uint64(v.Sign())

View file

@ -501,6 +501,13 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int) *core.Message {
} }
} }
func toUint64(b *hexutil.Uint64) uint64 {
if b == nil {
return 0
}
return uint64(*b)
}
// ToTransaction converts the arguments to a transaction. // ToTransaction converts the arguments to a transaction.
// This assumes that setDefaults has been called. // This assumes that setDefaults has been called.
func (args *TransactionArgs) ToTransaction() *types.Transaction { func (args *TransactionArgs) ToTransaction() *types.Transaction {
@ -529,13 +536,9 @@ func (args *TransactionArgs) ToTransaction() *types.Transaction {
Deployer: args.Deployer, Deployer: args.Deployer,
DeployerData: *args.DeployerData, DeployerData: *args.DeployerData,
BuilderFee: (*big.Int)(args.BuilderFee), BuilderFee: (*big.Int)(args.BuilderFee),
ValidationGasLimit: uint64(*args.ValidationGas), ValidationGasLimit: toUint64(args.ValidationGas),
} PaymasterValidationGasLimit: toUint64(args.PaymasterGas),
if args.PaymasterGas != nil { PostOpGas: toUint64(args.PostOpGas),
aatx.PaymasterValidationGasLimit = uint64(*args.PaymasterGas)
}
if args.PostOpGas != nil {
aatx.PostOpGas = uint64(*args.PostOpGas)
} }
data = &aatx data = &aatx
hash := types.NewTx(data).Hash() hash := types.NewTx(data).Hash()