Skip to content
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

Return MixedCaseAddresses in RPC AccessLists #2199

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,12 +1234,20 @@ func (m *Message) SetData(data []byte) {
// AccessList is an access list.
type AccessList []AccessTuple

// MixedAccessList is an access list of MixedCaseAddresses
type MixedAccessList []MixedAccessTuple

// AccessTuple is the element type of an access list.
type AccessTuple struct {
Address common.Address `json:"address" gencodec:"required"`
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
}

type MixedAccessTuple struct {
Address common.MixedcaseAddress `json:"address" gencodec:"required"`
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
}

// StorageKeys returns the total number of storage keys in the access list.
func (al AccessList) StorageKeys() int {
sum := 0
Expand Down Expand Up @@ -1279,6 +1287,14 @@ func (al *AccessList) ProtoDecode(protoAccessList *ProtoAccessList, location com
return nil
}

func (al *AccessList) ConvertToMixedCase() *MixedAccessList {
MixedAccessList := make(MixedAccessList, 0, len(*al))
for _, tup := range *al {
MixedAccessList = append(MixedAccessList, MixedAccessTuple{tup.Address.MixedcaseAddress(), tup.StorageKeys})
}
return &MixedAccessList
}

// This function must only be used by tests
func GetInnerForTesting(tx *Transaction) TxData {
return tx.inner
Expand Down
13 changes: 8 additions & 5 deletions internal/quaiapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,9 +1156,9 @@ func newRPCTransactionFromBlockHash(b *types.WorkObject, hash common.Hash, etxs
// Its the result of the `debug_createAccessList` RPC call.
// It contains an error if the transaction itself failed.
type accessListResult struct {
Accesslist *types.AccessList `json:"accessList"`
Error string `json:"error,omitempty"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Accesslist *types.MixedAccessList `json:"accessList"`
Error string `json:"error,omitempty"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
}

// CreateAccessList creates an AccessList for the given transaction.
Expand All @@ -1179,7 +1179,7 @@ func (s *PublicBlockChainAPI) CreateAccessList(ctx context.Context, args Transac
if err != nil {
return nil, err
}
result := &accessListResult{Accesslist: &acl, GasUsed: hexutil.Uint64(gasUsed)}
result := &accessListResult{Accesslist: acl.ConvertToMixedCase(), GasUsed: hexutil.Uint64(gasUsed)}
if vmerr != nil {
result.Error = vmerr.Error()
}
Expand Down Expand Up @@ -1436,7 +1436,6 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"transactionHash": hash,
"transactionIndex": hexutil.Uint64(index),
"from": from.Hex(),
"to": tx.To().Hex(),
"gasUsed": hexutil.Uint64(receipt.GasUsed),
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
"contractAddress": nil,
Expand All @@ -1445,6 +1444,10 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"type": hexutil.Uint(tx.Type()),
}

if to := tx.To(); to != nil {
fields["to"] = to.Hex()
}

if tx.Type() == types.ExternalTxType {
fields["originatingTxHash"] = tx.OriginatingTxHash()
fields["etxType"] = hexutil.Uint(tx.EtxType())
Expand Down
2 changes: 1 addition & 1 deletion internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (s *PublicBlockChainQuaiAPI) CreateAccessList(ctx context.Context, args Tra
if err != nil {
return nil, err
}
result := &accessListResult{Accesslist: &acl, GasUsed: hexutil.Uint64(gasUsed)}
result := &accessListResult{Accesslist: acl.ConvertToMixedCase(), GasUsed: hexutil.Uint64(gasUsed)}
if vmerr != nil {
result.Error = vmerr.Error()
}
Expand Down
Loading