Skip to content
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
73 changes: 61 additions & 12 deletions simulators/ethereum/engine/helper/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package helper
import (
"encoding/json"
"fmt"
"math/big"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"math/big"
"strconv"
)

type GenesisAlloc interface {
Expand All @@ -19,12 +20,13 @@ type GenesisAlloc interface {
type GenesisAccount interface {
// Balance holds the balance of the account
Balance() *big.Int
SetBalance()
SetBalance(balance *big.Int)
Code() []byte
SetCode(code []byte)
SetConstructor(constructor []byte)
Constructor() []byte
}

type Genesis interface {
Config() *params.ChainConfig
SetConfig(config *params.ChainConfig)
Expand All @@ -43,7 +45,7 @@ type Genesis interface {
Coinbase() common.Address
SetCoinbase(address common.Address)
Alloc() GenesisAlloc
AllocGenesis(address common.Address, account GenesisAccount)
AllocGenesis(address common.Address, account Account)
UpdateTimestamp(timestamp string)

// Used for testing
Expand Down Expand Up @@ -74,11 +76,59 @@ type Builtin struct {

type Account map[string]interface{}

//struct {
// Balance string `json:"balance,omitempty"`
// Constructor string `json:"constructor,omitempty"`
// Builtin Builtin `json:"builtin,omitempty"`
//}
// struct {
// Balance string `json:"balance,omitempty"`
// Constructor string `json:"constructor,omitempty"`
// Builtin Builtin `json:"builtin,omitempty"`
// }
func NewAccount() Account {
return make(Account, 0)
}

// GetCode returns theaccount balance if it was set,
// otherwise returns common.Big0
func (a Account) GetBalance() *big.Int {
hexBalance, ok := a["balance"]
if !ok {
return common.Big0
}
hexStr := hexBalance.(string)
balance := common.Big0
_ = balance.FillBytes(common.Hex2Bytes(hexStr))
return balance
}

func (a Account) SetBalance(balance *big.Int) {
a["balance"] = common.BigToHash(balance)
}

// GetCode returns the hex representation of code if it was set,
// otherwise returns ""
func (a Account) GetCode() string {
code, ok := a["code"]
if !ok {
return ""
}
return fmt.Sprintf("%x", code.(string))
}

func (a Account) SetCode(code []byte) {
a["code"] = common.Bytes2Hex(code)
}

// GetConstructor returns the hex representation of constructor if it was set,
// otherwise returns ""
func (a Account) GetConstructor() string {
constructor, ok := a["constructor"]
if !ok {
return ""
}
return fmt.Sprintf("%x", constructor.(string))
}

func (a Account) SetConstructor(constructor []byte) {
a["constructor"] = common.Bytes2Hex(constructor)
}

type NethermindGenesis struct {
Seal struct {
Expand Down Expand Up @@ -266,9 +316,8 @@ func (n *NethermindChainSpec) Alloc() GenesisAlloc {
panic("implement me")
}

func (n *NethermindChainSpec) AllocGenesis(address common.Address, account GenesisAccount) {
//TODO implement me
panic("implement me")
func (n *NethermindChainSpec) AllocGenesis(address common.Address, account Account) {
n.Accounts[address.Hex()] = account
}

func (n *NethermindChainSpec) Number() uint64 {
Expand Down
4 changes: 1 addition & 3 deletions simulators/ethereum/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ type ClientGenesis interface {

// Load the genesis based on each client

// getTimestamp of the next 2 minutes
func getTimestamp(spec test.SpecInterface) int64 {
now := time.Now()

Expand All @@ -95,14 +94,13 @@ func getTimestamp(spec test.SpecInterface) int64 {
preShapellaBlock = 1
}

// Calculate the start of the next 2 minutes
nextMinute := now.Truncate(time.Minute).Add(time.Duration(preShapellaBlock) * 3 * time.Minute).Add(time.Minute)
// Create a time.Time value from the int64 timestamp
//tUnix := time.Unix(nex, 0)

// Format the time in a human-readable way
formattedTime := nextMinute.Format("2006-01-02 15:04:05")
fmt.Sprintf("Formatted timestamp: %v\n", formattedTime)
fmt.Printf("Formatted timestamp: %v\n", formattedTime)

// Get the Unix timestamp of the next 2 minutes
return nextMinute.Unix()
Expand Down
Loading