Skip to content

Commit

Permalink
remove extraneous dangling error
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl-ffl committed Sep 25, 2024
1 parent 0f6a377 commit e0d0de9
Showing 1 changed file with 33 additions and 61 deletions.
94 changes: 33 additions & 61 deletions protobuf/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ func (s *Substate) Decode(lookup dbGetCode, block uint64, tx int) (*substate.Sub
return nil, err
}

environment, err := s.GetBlockEnv().decode()
if err != nil {
return nil, err
}
environment := s.GetBlockEnv().decode()

message, err := s.GetTxMessage().decode(lookup)
if err != nil {
return nil, err
}

contractAddress := s.GetTxMessage().getContractAddress()
result, err := s.GetResult().decode(contractAddress)
if err != nil {
return nil, err
}
result := s.GetResult().decode(contractAddress)

return &substate.Substate{
InputSubstate: *input,
Expand All @@ -58,16 +52,9 @@ func (alloc *Substate_Alloc) decode(lookup dbGetCode) (*substate.WorldState, err
world := make(substate.WorldState, len(alloc.GetAlloc()))

for _, entry := range alloc.GetAlloc() {
addr, acct, err := entry.decode()
if err != nil {
return nil, fmt.Errorf("Error decoding alloc entry; %w", err)
}

addr, acct := entry.decode()
address := types.BytesToAddress(addr)
nonce, balance, _, codehash, err := acct.decode()
if err != nil {
return nil, fmt.Errorf("Error decoding entry account; %w", err)
}
nonce, balance, _, codehash := acct.decode()

code, err := lookup(codehash)
if err != nil && !errors.Is(err, leveldb.ErrNotFound) {
Expand All @@ -76,45 +63,36 @@ func (alloc *Substate_Alloc) decode(lookup dbGetCode) (*substate.WorldState, err

world[address] = substate.NewAccount(nonce, balance, code)
for _, storage := range acct.GetStorage() {
key, value, err := storage.decode()
if err != nil {
return nil, fmt.Errorf("Error decoding account storage entry; %w", err)
}
key, value := storage.decode()
world[address].Storage[key] = value
}
}

return &world, nil
}

func (entry *Substate_AllocEntry) decode() ([]byte, *Substate_Account, error) {
return entry.GetAddress(), entry.GetAccount(), nil
func (entry *Substate_AllocEntry) decode() ([]byte, *Substate_Account) {
return entry.GetAddress(), entry.GetAccount()
}

func (acct *Substate_Account) decode() (uint64, *big.Int, []byte, types.Hash, error) {
func (acct *Substate_Account) decode() (uint64, *big.Int, []byte, types.Hash) {
return acct.GetNonce(),
types.BytesToBigInt(acct.GetBalance()),
acct.GetCode(),
types.BytesToHash(acct.GetCodeHash()),
nil
types.BytesToHash(acct.GetCodeHash())
}

func (entry *Substate_Account_StorageEntry) decode() (types.Hash, types.Hash, error) {
return types.BytesToHash(entry.GetKey()),
types.BytesToHash(entry.GetValue()),
nil
func (entry *Substate_Account_StorageEntry) decode() (types.Hash, types.Hash) {
return types.BytesToHash(entry.GetKey()), types.BytesToHash(entry.GetValue())
}

// decode converts protobuf-encoded Substate_BlockEnv into aida-comprehensible Env
func (env *Substate_BlockEnv) decode() (*substate.Env, error) {
func (env *Substate_BlockEnv) decode() *substate.Env {
var blockHashes map[uint64]types.Hash = nil
if env.GetBlockHashes() != nil {
blockHashes = make(map[uint64]types.Hash, len(env.GetBlockHashes()))
for _, entry := range env.GetBlockHashes() {
key, value, err := entry.decode()
if err != nil {
return nil, err
}
key, value := entry.decode()
blockHashes[key] = types.BytesToHash(value)
}
}
Expand All @@ -129,11 +107,11 @@ func (env *Substate_BlockEnv) decode() (*substate.Env, error) {
BaseFee: BytesValueToBigInt(env.GetBaseFee()),
Random: BytesValueToHash(env.GetRandom()),
BlobBaseFee: BytesValueToBigInt(env.GetBlobBaseFee()),
}, nil
}
}

func (entry *Substate_BlockEnv_BlockHashEntry) decode() (uint64, []byte, error) {
return entry.GetKey(), entry.GetValue(), nil
func (entry *Substate_BlockEnv_BlockHashEntry) decode() (uint64, []byte) {
return entry.GetKey(), entry.GetValue()
}

// decode converts protobuf-encoded Substate_TxMessage into aida-comprehensible Message
Expand Down Expand Up @@ -171,10 +149,7 @@ func (msg *Substate_TxMessage) decode(lookup dbGetCode) (*substate.Message, erro

accessList = make([]types.AccessTuple, len(msg.GetAccessList()))
for i, entry := range msg.GetAccessList() {
addr, keys, err := entry.decode()
if err != nil {
return nil, err
}
addr, keys := entry.decode()

address := types.BytesToAddress(addr)
storageKeys := make([]types.Hash, len(keys))
Expand Down Expand Up @@ -204,14 +179,15 @@ func (msg *Substate_TxMessage) decode(lookup dbGetCode) (*substate.Message, erro
var blobHashes []types.Hash = nil
switch txType {
case Substate_TxMessage_TXTYPE_BLOB:
msgBlobHashes := msg.GetBlobHashes()
if msgBlobHashes == nil {
break
}
blobHashes = make([]types.Hash, len(msgBlobHashes))
for i, hash := range msgBlobHashes {
blobHashes[i] = types.BytesToHash(hash)
}
msgBlobHashes := msg.GetBlobHashes()
if msgBlobHashes == nil {
break
}

blobHashes = make([]types.Hash, len(msgBlobHashes))
for i, hash := range msgBlobHashes {
blobHashes[i] = types.BytesToHash(hash)
}
}

return &substate.Message{
Expand All @@ -231,8 +207,8 @@ func (msg *Substate_TxMessage) decode(lookup dbGetCode) (*substate.Message, erro
}, nil
}

func (entry *Substate_TxMessage_AccessListEntry) decode() ([]byte, [][]byte, error) {
return entry.GetAddress(), entry.GetStorageKeys(), nil
func (entry *Substate_TxMessage_AccessListEntry) decode() ([]byte, [][]byte) {
return entry.GetAddress(), entry.GetStorageKeys()
}

// getContractAddress returns the address of the newly created contract if any.
Expand All @@ -251,14 +227,10 @@ func (msg *Substate_TxMessage) getContractAddress() common.Address {
}

// decode converts protobuf-encoded Substate_Result into aida-comprehensible Result
func (res *Substate_Result) decode(contractAddress common.Address) (*substate.Result, error) {
var err error = nil
func (res *Substate_Result) decode(contractAddress common.Address) *substate.Result {
logs := make([]*types.Log, len(res.GetLogs()))
for i, log := range res.GetLogs() {
logs[i], err = log.decode()
if err != nil {
return nil, fmt.Errorf("Error decoding result; %w", err)
}
logs[i] = log.decode()
}

return substate.NewResult(
Expand All @@ -267,10 +239,10 @@ func (res *Substate_Result) decode(contractAddress common.Address) (*substate.Re
logs, // Logs
types.BytesToAddress(contractAddress.Bytes()), // ContractAddress
res.GetGasUsed(), // GasUsed
), nil
)
}

func (log *Substate_Result_Log) decode() (*types.Log, error) {
func (log *Substate_Result_Log) decode() *types.Log {
topics := make([]types.Hash, len(log.GetTopics()))
for i, topic := range log.GetTopics() {
topics[i] = types.BytesToHash(topic)
Expand All @@ -280,5 +252,5 @@ func (log *Substate_Result_Log) decode() (*types.Log, error) {
Address: types.BytesToAddress(log.GetAddress()),
Topics: topics,
Data: log.GetData(),
}, nil
}
}

0 comments on commit e0d0de9

Please sign in to comment.