This repository was archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 747
State interface #2
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package state | ||
|
|
||
| // Batch | ||
| type Batch struct{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package state | ||
|
|
||
| import ( | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| ) | ||
|
|
||
| // BatchProcessor is used to process a batch of transactions | ||
| type BatchProcessor struct{} | ||
|
|
||
| // ProcessBatch processes all transactions inside a batch | ||
| func (b *BatchProcessor) ProcessBatch(batch Batch) error { | ||
| return nil | ||
| } | ||
|
|
||
| // ProcessTransaction processes a transaction inside a batch | ||
| func (b *BatchProcessor) ProcessTransaction(tx types.Transaction) error { | ||
| return nil | ||
| } | ||
|
|
||
| // CheckTransaction checks a transaction is valid inside a batch context | ||
| func (b *BatchProcessor) CheckTransaction(tx types.Transaction) error { | ||
| return nil | ||
| } | ||
|
|
||
|
Contributor
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. I'm missing a function:
Contributor
Author
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. Method added |
||
| // Commits the batch state into state | ||
| func (b *BatchProcessor) Commit() (*common.Hash, *Proof, error) { | ||
| return nil, nil, nil | ||
| } | ||
|
|
||
| // Rollback does not apply batch state into state | ||
| func (b *BatchProcessor) Rollback() error { | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package db | ||
|
|
||
| // KeyValuer interface that a compatible DB backend should implement | ||
| type KeyValuer interface { | ||
| Put(key string, data []byte) error | ||
| // Get IMPORTANT: should return nil, nil in case of no data found!!!! | ||
| Get(key string) ([]byte, error) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package state | ||
|
|
||
| // Proof | ||
| type Proof struct{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package evm | ||
|
|
||
| // EVM is the Ethereum Virtual Machine | ||
| type EVM struct { | ||
| } | ||
|
|
||
| // NewEVM creates a new EVM | ||
| func NewEVM() *EVM { | ||
| return &EVM{} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package evm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package evm | ||
|
|
||
| import "github.com/holiman/uint256" | ||
|
|
||
| type Memory struct { | ||
| data []byte | ||
| } | ||
|
|
||
| // NewMemory is the constructor | ||
| func NewMemory() *Memory { | ||
| return &Memory{} | ||
| } | ||
|
|
||
| // Set sets a value at memory offset | ||
| func (m *Memory) Set(offset uint64, size uint64, value []byte) { | ||
| if size > 0 { | ||
| if offset+size > uint64(len(m.data)) { | ||
| panic("invalid memory") | ||
| } | ||
| copy(m.data[offset:offset+size], value) | ||
| } | ||
| } | ||
|
|
||
| // Set32 sets the 32 bytes starting at offset to the value of val, left-padded with zeroes to | ||
| // 32 bytes. | ||
| func (m *Memory) Set32(offset uint64, val *uint256.Int) { | ||
| // length of store may never be less than offset + size. | ||
| // The store should be resized PRIOR to setting the memory | ||
| if offset+32 > uint64(len(m.data)) { | ||
| panic("invalid memory: store empty") | ||
| } | ||
| // Zero the memory area | ||
| copy(m.data[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) | ||
| // Fill in relevant bits | ||
| val.WriteToSlice(m.data[offset:]) | ||
| } | ||
|
|
||
| // Get returns size bytes from memory offset as a new slice | ||
| func (m *Memory) GetCopy(offset, size int64) (cpy []byte) { | ||
| if size == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| if len(m.data) > int(offset) { | ||
| cpy = make([]byte, size) | ||
| copy(cpy, m.data[offset:offset+size]) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // GetPtr returns size bytes from memory offset | ||
| func (m *Memory) GetPtr(offset, size int64) []byte { | ||
| if size == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| if len(m.data) > int(offset) { | ||
| return m.data[offset : offset+size] | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Len returns the length of the backing slice | ||
| func (m *Memory) Len() int { | ||
| return len(m.data) | ||
| } | ||
|
|
||
| // Data returns the backing slice | ||
| func (m *Memory) Data() []byte { | ||
| return m.data | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.