Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/core/vm/environment.go

67 lines
1.6 KiB

10 years ago
package vm
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
)
// Environment is is required by the virtual machine to get information from
// it's own isolated environment. For an example see `core.VMEnv`
type Environment interface {
State() *state.StateDB
10 years ago
Origin() common.Address
BlockNumber() *big.Int
10 years ago
GetHash(n uint64) common.Hash
Coinbase() common.Address
Time() int64
Difficulty() *big.Int
GasLimit() *big.Int
Transfer(from, to Account, amount *big.Int) error
AddLog(*state.Log)
AddStructLog(StructLog)
StructLogs() []StructLog
VmType() Type
Depth() int
SetDepth(i int)
10 years ago
Call(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
CallCode(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
Create(me ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, ContextRef)
}
// StructLog is emited to the Environment each cycle and lists information about the curent internal state
// prior to the execution of the statement.
type StructLog struct {
Pc uint64
Op OpCode
Gas *big.Int
Memory []byte
Stack []*big.Int
Storage map[common.Hash][]byte
}
type Account interface {
SubBalance(amount *big.Int)
AddBalance(amount *big.Int)
Balance() *big.Int
10 years ago
Address() common.Address
}
// generic transfer method
func Transfer(from, to Account, amount *big.Int) error {
if from.Balance().Cmp(amount) < 0 {
return errors.New("Insufficient balance in account")
}
from.SubBalance(amount)
to.AddBalance(amount)
return nil
}