embedded_mips.go 972 Bytes
Newer Older
1
//go:build mips
George Hotz's avatar
George Hotz committed
2
// +build mips
3 4 5 6 7 8 9 10 11 12

package oracle

import (
	"fmt"
	"io/ioutil"
	"math/big"
	"os"

	"github.com/ethereum/go-ethereum/common"
13
	"github.com/ethereum/go-ethereum/crypto"
14 15
)

George Hotz's avatar
George Hotz committed
16
var preimages = make(map[common.Hash][]byte)
17

George Hotz's avatar
George Hotz committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
func Preimage(hash common.Hash) []byte {
	val, ok := preimages[hash]
	if !ok {
		f, err := os.Open(fmt.Sprintf("/tmp/eth/%s", hash))
		if err != nil {
			panic("missing preimage")
		}

		defer f.Close()
		ret, err := ioutil.ReadAll(f)
		if err != nil {
			panic("preimage read failed")
		}

		realhash := crypto.Keccak256Hash(ret)
		if realhash != hash {
			panic("preimage has wrong hash")
		}

		preimages[hash] = ret
		return ret
39
	}
George Hotz's avatar
George Hotz committed
40
	return val
41 42 43 44 45 46
}

// these are stubs in embedded world
func PrefetchStorage(blockNumber *big.Int, addr common.Address, skey common.Hash) {}
func PrefetchAccount(blockNumber *big.Int, addr common.Address)                   {}
func PrefetchCode(blockNumber *big.Int, addrHash common.Hash)                     {}