-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align RPC with geth #1841
Align RPC with geth #1841
Changes from all commits
c36ee46
9284f97
90b58cc
bbc441d
50d6d0b
3fa1306
979ddc1
d41e924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,8 @@ func EstimateGasValidate(reqParams []any, builder *CallBuilder[CallParamsWithBlo | |
} | ||
|
||
builder.From = callMsg.From | ||
builder.Param = &CallParamsWithBlock{callMsg, blockNumber} | ||
// todo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: What needs to be done here or can be this todo removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to support retrieval by hash. Currently it only works by height |
||
builder.Param = &CallParamsWithBlock{callMsg, blockNumber.BlockNumber} | ||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ func GetTransactionExecute(builder *CallBuilder[gethcommon.Hash, RpcTransaction] | |
// Unlike in the Geth impl, we hardcode the use of a London signer. | ||
// todo (#1553) - once the enclave's genesis.json is set, retrieve the signer type using `types.MakeSigner` | ||
signer := types.NewLondonSigner(tx.ChainId()) | ||
rpcTx := newRPCTransaction(tx, blockHash, blockNumber, index, gethcommon.Big0, signer) | ||
rpcTx := newRPCTransaction(tx, blockHash, blockNumber, index, rpc.config.BaseFee, signer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity.. do we want to have it configurable? Before it was hardcoded to 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently we have a static configured base fee. |
||
builder.ReturnValue = rpcTx | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ package rpc | |
import ( | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ten-protocol/go-ten/go/enclave/evm/ethchainadapter" | ||
|
||
"github.com/ten-protocol/go-ten/go/enclave/core" | ||
|
||
|
@@ -13,7 +17,7 @@ import ( | |
"github.com/ten-protocol/go-ten/go/enclave/events" | ||
) | ||
|
||
func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcommon.Hash, types.Receipt], _ *EncryptionManager) error { | ||
func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcommon.Hash, map[string]interface{}], _ *EncryptionManager) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the geth api actually returns a map when you ask for receipts. |
||
// Parameters are [Hash] | ||
if len(reqParams) < 1 { | ||
builder.Err = fmt.Errorf("unexpected number of parameters") | ||
|
@@ -30,12 +34,12 @@ func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcom | |
return nil | ||
} | ||
|
||
func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, types.Receipt], rpc *EncryptionManager) error { | ||
func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, map[string]interface{}], rpc *EncryptionManager) error { | ||
txHash := *builder.Param | ||
// todo - optimise these calls. This can be done with a single sql | ||
rpc.logger.Trace("Get receipt for ", log.TxKey, txHash) | ||
// We retrieve the transaction. | ||
tx, _, _, _, err := rpc.storage.GetTransaction(txHash) //nolint:dogsled | ||
tx, blockHash, number, txIndex, err := rpc.storage.GetTransaction(txHash) //nolint:dogsled | ||
if err != nil { | ||
rpc.logger.Trace("error getting tx ", log.TxKey, txHash, log.ErrKey, err) | ||
if errors.Is(err, errutil.ErrNotFound) { | ||
|
@@ -78,6 +82,51 @@ func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, types.Re | |
} | ||
|
||
rpc.logger.Trace("Successfully retrieved receipt for ", log.TxKey, txHash, "rec", txReceipt) | ||
builder.ReturnValue = txReceipt | ||
signer := types.MakeSigner(ethchainadapter.ChainParams(big.NewInt(rpc.config.ObscuroChainID)), big.NewInt(int64(number)), 0) | ||
r := marshalReceipt(txReceipt, blockHash, number, signer, tx, int(txIndex)) | ||
builder.ReturnValue = &r | ||
return nil | ||
} | ||
|
||
// marshalReceipt marshals a transaction receipt into a JSON object. | ||
// taken from geth | ||
func marshalReceipt(receipt *types.Receipt, blockHash gethcommon.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int) map[string]interface{} { | ||
from, _ := types.Sender(signer, tx) | ||
|
||
fields := map[string]interface{}{ | ||
"blockHash": blockHash, | ||
"blockNumber": hexutil.Uint64(blockNumber), | ||
"transactionHash": tx.Hash(), | ||
"transactionIndex": hexutil.Uint64(txIndex), | ||
"from": from, | ||
"to": tx.To(), | ||
"gasUsed": hexutil.Uint64(receipt.GasUsed), | ||
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed), | ||
"contractAddress": nil, | ||
"logs": receipt.Logs, | ||
"logsBloom": receipt.Bloom, | ||
"type": hexutil.Uint(tx.Type()), | ||
"effectiveGasPrice": (*hexutil.Big)(receipt.EffectiveGasPrice), | ||
} | ||
|
||
// Assign receipt status or post state. | ||
if len(receipt.PostState) > 0 { | ||
fields["root"] = hexutil.Bytes(receipt.PostState) | ||
} else { | ||
fields["status"] = hexutil.Uint(receipt.Status) | ||
} | ||
if receipt.Logs == nil { | ||
fields["logs"] = []*types.Log{} | ||
} | ||
|
||
if tx.Type() == types.BlobTxType { | ||
fields["blobGasUsed"] = hexutil.Uint64(receipt.BlobGasUsed) | ||
fields["blobGasPrice"] = (*hexutil.Big)(receipt.BlobGasPrice) | ||
} | ||
|
||
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation | ||
if receipt.ContractAddress != (gethcommon.Address{}) { | ||
fields["contractAddress"] = receipt.ContractAddress | ||
} | ||
return fields | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the geth api can send either a block number or a hash.
We currently only support the former, but this change creates the plumbing for both