ethchain

package
v0.5.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2014 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxPre = iota
	TxPost
)
View Source
const (
	// 0x0 range - arithmetic ops
	STOP = 0x00
	ADD  = 0x01
	MUL  = 0x02
	SUB  = 0x03
	DIV  = 0x04
	SDIV = 0x05
	MOD  = 0x06
	SMOD = 0x07
	EXP  = 0x08
	NEG  = 0x09
	LT   = 0x0a
	GT   = 0x0b
	SLT  = 0x0c
	SGT  = 0x0d
	EQ   = 0x0e
	NOT  = 0x0f

	// 0x10 range - bit ops
	AND  = 0x10
	OR   = 0x11
	XOR  = 0x12
	BYTE = 0x13

	// 0x20 range - crypto
	SHA3 = 0x20

	// 0x30 range - closure state
	ADDRESS      = 0x30
	BALANCE      = 0x31
	ORIGIN       = 0x32
	CALLER       = 0x33
	CALLVALUE    = 0x34
	CALLDATALOAD = 0x35
	CALLDATASIZE = 0x36
	CALLDATACOPY = 0x37
	CODESIZE     = 0x38
	CODECOPY     = 0x39
	GASPRICE     = 0x3a

	// 0x40 range - block operations
	PREVHASH   = 0x40
	COINBASE   = 0x41
	TIMESTAMP  = 0x42
	NUMBER     = 0x43
	DIFFICULTY = 0x44
	GASLIMIT   = 0x45

	// 0x50 range - 'storage' and execution
	POP     = 0x50
	DUP     = 0x51
	SWAP    = 0x52
	MLOAD   = 0x53
	MSTORE  = 0x54
	MSTORE8 = 0x55
	SLOAD   = 0x56
	SSTORE  = 0x57
	JUMP    = 0x58
	JUMPI   = 0x59
	PC      = 0x5a
	MSIZE   = 0x5b
	GAS     = 0x5c

	// 0x60 range
	PUSH1  = 0x60
	PUSH2  = 0x61
	PUSH3  = 0x62
	PUSH4  = 0x63
	PUSH5  = 0x64
	PUSH6  = 0x65
	PUSH7  = 0x66
	PUSH8  = 0x67
	PUSH9  = 0x68
	PUSH10 = 0x69
	PUSH11 = 0x6a
	PUSH12 = 0x6b
	PUSH13 = 0x6c
	PUSH14 = 0x6d
	PUSH15 = 0x6e
	PUSH16 = 0x6f
	PUSH17 = 0x70
	PUSH18 = 0x71
	PUSH19 = 0x72
	PUSH20 = 0x73
	PUSH21 = 0x74
	PUSH22 = 0x75
	PUSH23 = 0x76
	PUSH24 = 0x77
	PUSH25 = 0x78
	PUSH26 = 0x79
	PUSH27 = 0x7a
	PUSH28 = 0x7b
	PUSH29 = 0x7c
	PUSH30 = 0x7d
	PUSH31 = 0x7e
	PUSH32 = 0x7f

	// 0xf0 range - closures
	CREATE = 0xf0
	CALL   = 0xf1
	RETURN = 0xf2

	// 0x70 range - other
	LOG     = 0xfe // XXX Unofficial
	SUICIDE = 0xff
)

Op codes

Variables

View Source
var (
	GasStep    = big.NewInt(1)
	GasSha     = big.NewInt(20)
	GasSLoad   = big.NewInt(20)
	GasSStore  = big.NewInt(100)
	GasBalance = big.NewInt(20)
	GasCreate  = big.NewInt(100)
	GasCall    = big.NewInt(20)
	GasMemory  = big.NewInt(1)
	GasData    = big.NewInt(5)
	GasTx      = big.NewInt(500)

	LogTyPretty byte = 0x1
	LogTyDiff   byte = 0x2
)
View Source
var BlockReward *big.Int = big.NewInt(1.5e+18)
View Source
var ContractAddr = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
View Source
var EmptyShaList = ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{}))
View Source
var Found bool
View Source
var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}}
View Source
var GenesisHeader = []interface{}{

	ZeroHash256,

	ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{})),

	ZeroHash160,

	"",

	"",

	ethutil.BigPow(2, 22),

	ethutil.Big0,

	ethutil.Big0,

	big.NewInt(1000000),

	ethutil.Big0,

	ethutil.Big0,

	nil,

	ethcrypto.Sha3Bin(big.NewInt(42).Bytes()),
}
View Source
var OpCodes = map[string]byte{

	"STOP": 0x00,
	"ADD":  0x01,
	"MUL":  0x02,
	"SUB":  0x03,
	"DIV":  0x04,
	"SDIV": 0x05,
	"MOD":  0x06,
	"SMOD": 0x07,
	"EXP":  0x08,
	"NEG":  0x09,
	"LT":   0x0a,
	"GT":   0x0b,
	"EQ":   0x0c,
	"NOT":  0x0d,

	"AND":  0x10,
	"OR":   0x11,
	"XOR":  0x12,
	"BYTE": 0x13,

	"SHA3": 0x20,

	"ADDRESS":      0x30,
	"BALANCE":      0x31,
	"ORIGIN":       0x32,
	"CALLER":       0x33,
	"CALLVALUE":    0x34,
	"CALLDATALOAD": 0x35,
	"CALLDATASIZE": 0x36,
	"GASPRICE":     0x38,

	"PREVHASH":   0x40,
	"COINBASE":   0x41,
	"TIMESTAMP":  0x42,
	"NUMBER":     0x43,
	"DIFFICULTY": 0x44,
	"GASLIMIT":   0x45,

	"POP":     0x51,
	"DUP":     0x52,
	"SWAP":    0x53,
	"MLOAD":   0x54,
	"MSTORE":  0x55,
	"MSTORE8": 0x56,
	"SLOAD":   0x57,
	"SSTORE":  0x58,
	"JUMP":    0x59,
	"JUMPI":   0x5a,
	"PC":      0x5b,
	"MSIZE":   0x5c,

	"PUSH1":  0x60,
	"PUSH2":  0x61,
	"PUSH3":  0x62,
	"PUSH4":  0x63,
	"PUSH5":  0x64,
	"PUSH6":  0x65,
	"PUSH7":  0x66,
	"PUSH8":  0x67,
	"PUSH9":  0x68,
	"PUSH10": 0x69,
	"PUSH11": 0x6a,
	"PUSH12": 0x6b,
	"PUSH13": 0x6c,
	"PUSH14": 0x6d,
	"PUSH15": 0x6e,
	"PUSH16": 0x6f,
	"PUSH17": 0x70,
	"PUSH18": 0x71,
	"PUSH19": 0x72,
	"PUSH20": 0x73,
	"PUSH21": 0x74,
	"PUSH22": 0x75,
	"PUSH23": 0x76,
	"PUSH24": 0x77,
	"PUSH25": 0x78,
	"PUSH26": 0x70,
	"PUSH27": 0x7a,
	"PUSH28": 0x7b,
	"PUSH29": 0x7c,
	"PUSH30": 0x7d,
	"PUSH31": 0x7e,
	"PUSH32": 0x7f,

	"CREATE": 0xf0,
	"CALL":   0xf1,
	"RETURN": 0xf2,

	"LOG":     0xfe,
	"SUICIDE": 0x7f,
}

Op codes for assembling

View Source
var Pow256 = ethutil.BigPow(2, 256)
View Source
var UncleInclusionReward *big.Int = big.NewInt(1.875e+17)
View Source
var UncleReward *big.Int = big.NewInt(1.125e+18)
View Source
var ZeroHash160 = make([]byte, 20)
View Source
var ZeroHash256 = make([]byte, 32)

Functions

func AddTestNetFunds

func AddTestNetFunds(block *Block)

func CalculateBlockReward

func CalculateBlockReward(block *Block, uncleLength int) *big.Int

func CalculateUncleReward

func CalculateUncleReward(block *Block) *big.Int

func Call

func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error)

func CreateTxSha

func CreateTxSha(receipts Receipts) (sha []byte)

func DaggerVerify

func DaggerVerify(hash, diff, nonce *big.Int) bool

func Disassemble

func Disassemble(script []byte) (asm []string)

func IsContractAddr

func IsContractAddr(addr []byte) bool

func IsGasLimitErr

func IsGasLimitErr(err error) bool

func IsNonceErr

func IsNonceErr(err error) bool

func IsOpCode

func IsOpCode(s string) bool

func IsOutOfGasErr

func IsOutOfGasErr(err error) bool

func IsParentErr

func IsParentErr(err error) bool

func IsValidationErr

func IsValidationErr(err error) bool

func ParentError

func ParentError(hash []byte) error

func Sum

func Sum(sha hash.Hash) []byte

Types

type Block

type Block struct {
	// Hash to the previous block
	PrevHash []byte
	// Uncles of this block
	Uncles   []*Block
	UncleSha []byte
	// The coin base address
	Coinbase []byte

	// Difficulty for the current block
	Difficulty *big.Int
	// Creation time
	Time int64
	// The block number
	Number *big.Int
	// Minimum Gas Price
	MinGasPrice *big.Int
	// Gas limit
	GasLimit *big.Int
	// Gas used
	GasUsed *big.Int
	// Extra data
	Extra string
	// Block Nonce for verification
	Nonce []byte

	TxSha []byte
	// contains filtered or unexported fields
}

func CreateBlock

func CreateBlock(root interface{},
	prevHash []byte,
	base []byte,
	Difficulty *big.Int,
	Nonce []byte,
	extra string) *Block

func NewBlockFromBytes

func NewBlockFromBytes(raw []byte) *Block

func NewBlockFromData

func NewBlockFromData(raw []byte) *Block

New block takes a raw encoded string XXX DEPRICATED

func NewBlockFromRlpValue

func NewBlockFromRlpValue(rlpValue *ethutil.Value) *Block

New block takes a raw encoded string

func NewUncleBlockFromValue

func NewUncleBlockFromValue(header *ethutil.Value) *Block

func (*Block) BlockInfo

func (block *Block) BlockInfo() BlockInfo

func (*Block) CalcGasLimit

func (block *Block) CalcGasLimit(parent *Block) *big.Int

func (*Block) GetRoot

func (block *Block) GetRoot() interface{}

func (*Block) GetTransaction

func (self *Block) GetTransaction(hash []byte) *Transaction

func (*Block) Hash

func (block *Block) Hash() []byte

Returns a hash of the block

func (*Block) HashNoNonce

func (block *Block) HashNoNonce() []byte

func (*Block) PayFee

func (block *Block) PayFee(addr []byte, fee *big.Int) bool

func (*Block) Receipts

func (self *Block) Receipts() []*Receipt

func (*Block) RlpDecode

func (block *Block) RlpDecode(data []byte)

func (*Block) RlpEncode

func (block *Block) RlpEncode() []byte

func (*Block) RlpValueDecode

func (block *Block) RlpValueDecode(decoder *ethutil.Value)

func (*Block) SetReceipts

func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction)

func (*Block) SetTxHash

func (self *Block) SetTxHash(receipts Receipts)

func (*Block) SetUncles

func (block *Block) SetUncles(uncles []*Block)

func (*Block) State

func (block *Block) State() *State

func (*Block) String

func (block *Block) String() string

func (*Block) Sync

func (block *Block) Sync()

Sync the block's state and contract respectively

func (*Block) Transactions

func (block *Block) Transactions() []*Transaction

func (*Block) Undo

func (block *Block) Undo()

func (*Block) Value

func (block *Block) Value() *ethutil.Value

type BlockChain

type BlockChain struct {
	Ethereum EthManager

	// Last known total difficulty
	TD *big.Int

	LastBlockNumber uint64

	CurrentBlock  *Block
	LastBlockHash []byte
	// contains filtered or unexported fields
}

func NewBlockChain

func NewBlockChain(ethereum EthManager) *BlockChain

func (*BlockChain) Add

func (bc *BlockChain) Add(block *Block)

Add a block to the chain and record addition information

func (*BlockChain) BlockInfo

func (bc *BlockChain) BlockInfo(block *Block) BlockInfo

func (*BlockChain) BlockInfoByHash

func (bc *BlockChain) BlockInfoByHash(hash []byte) BlockInfo

func (*BlockChain) CalculateBlockTD

func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int

func (*BlockChain) FindCanonicalChain

func (bc *BlockChain) FindCanonicalChain(blocks []*Block, commonBlockHash []byte) bool

Is tasked by finding the CanonicalChain and resetting the chain if we are not the Conical one Return true if we are the using the canonical chain false if not

func (*BlockChain) FindCanonicalChainFromMsg

func (bc *BlockChain) FindCanonicalChainFromMsg(msg *ethwire.Msg, commonBlockHash []byte) bool

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *Block

func (*BlockChain) GenesisBlock

func (bc *BlockChain) GenesisBlock() *Block

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash []byte) *Block

func (*BlockChain) GetChain

func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block

func (*BlockChain) GetChainFromHash

func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{}

Get chain return blocks from hash up to max in RLP format

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash []byte) bool

func (*BlockChain) HasBlockWithPrevHash

func (bc *BlockChain) HasBlockWithPrevHash(hash []byte) bool

TODO: At one point we might want to save a block by prevHash in the db to optimise this...

func (*BlockChain) NewBlock

func (bc *BlockChain) NewBlock(coinbase []byte) *Block

func (*BlockChain) ResetTillBlockHash

func (bc *BlockChain) ResetTillBlockHash(hash []byte) error

func (*BlockChain) SetTotalDifficulty

func (bc *BlockChain) SetTotalDifficulty(td *big.Int)

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

type BlockInfo

type BlockInfo struct {
	Number uint64
	Hash   []byte
	Parent []byte
}

func (*BlockInfo) RlpDecode

func (bi *BlockInfo) RlpDecode(data []byte)

func (*BlockInfo) RlpEncode

func (bi *BlockInfo) RlpEncode() []byte

type BlockProcessor

type BlockProcessor interface {
	ProcessBlock(block *Block)
}

type Closure

type Closure struct {
	Script []byte
	State  *State

	Gas, UsedGas, Price *big.Int

	Args []byte
	// contains filtered or unexported fields
}

Basic inline closure object which implement the 'closure' interface

func NewClosure

func NewClosure(caller ClosureRef, object *StateObject, script []byte, state *State, gas, price *big.Int) *Closure

Create a new closure for the given data items

func (*Closure) Address

func (c *Closure) Address() []byte

func (*Closure) Call

func (c *Closure) Call(vm *Vm, args []byte) ([]byte, *big.Int, error)

func (*Closure) Caller

func (c *Closure) Caller() ClosureRef

func (*Closure) Get

func (c *Closure) Get(x *big.Int) *ethutil.Value

func (*Closure) GetStorage

func (c *Closure) GetStorage(x *big.Int) *ethutil.Value

Retuns the x element in data slice

func (*Closure) Gets

func (c *Closure) Gets(x, y *big.Int) *ethutil.Value

func (*Closure) N

func (c *Closure) N() *big.Int

func (*Closure) Object

func (c *Closure) Object() *StateObject

func (*Closure) Return

func (c *Closure) Return(ret []byte) []byte

func (*Closure) ReturnGas

func (c *Closure) ReturnGas(gas, price *big.Int, state *State)

Implement the caller interface

func (*Closure) SetStorage

func (c *Closure) SetStorage(x *big.Int, val *ethutil.Value)

func (*Closure) UseGas

func (c *Closure) UseGas(gas *big.Int) bool

type ClosureRef

type ClosureRef interface {
	ReturnGas(*big.Int, *big.Int, *State)
	Address() []byte
	GetStorage(*big.Int) *ethutil.Value
	SetStorage(*big.Int, *ethutil.Value)
	N() *big.Int
}

type Code

type Code []byte

func (Code) String

func (self Code) String() string

type Dagger

type Dagger struct {
	// contains filtered or unexported fields
}

func (*Dagger) Eval

func (dag *Dagger) Eval(N *big.Int) *big.Int

func (*Dagger) Find

func (dag *Dagger) Find(obj *big.Int, resChan chan int64)

func (*Dagger) Node

func (dag *Dagger) Node(L uint64, i uint64) *big.Int

func (*Dagger) Search

func (dag *Dagger) Search(hash, diff *big.Int) *big.Int

func (*Dagger) Verify

func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool

type Debugger

type Debugger interface {
	BreakHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
	StepHook(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
	BreakPoints() []int64
	SetCode(byteCode []byte)
}

type EasyPow

type EasyPow struct {
	HashRate int64
	// contains filtered or unexported fields
}

func (*EasyPow) GetHashrate

func (pow *EasyPow) GetHashrate() int64

func (*EasyPow) Search

func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte

func (*EasyPow) SetHash

func (pow *EasyPow) SetHash(hash *big.Int)

func (*EasyPow) Verify

func (pow *EasyPow) Verify(hash []byte, diff *big.Int, nonce []byte) bool

type EthManager

type EthManager interface {
	StateManager() *StateManager
	BlockChain() *BlockChain
	TxPool() *TxPool
	Broadcast(msgType ethwire.MsgType, data []interface{})
	Reactor() *ethutil.ReactorEngine
	PeerCount() int
	IsMining() bool
	IsListening() bool
	Peers() *list.List
	KeyManager() *ethcrypto.KeyManager
	ClientIdentity() ethwire.ClientIdentity
}

type GasLimitErr

type GasLimitErr struct {
	Message string
	Is, Max *big.Int
}

func GasLimitError

func GasLimitError(is, max *big.Int) *GasLimitErr

func (*GasLimitErr) Error

func (err *GasLimitErr) Error() string

type Manifest

type Manifest struct {
	// contains filtered or unexported fields
}

Object manifest

The object manifest is used to keep changes to the state so we can keep track of the changes that occurred during a state transitioning phase.

func NewManifest

func NewManifest() *Manifest

func (*Manifest) AddObjectChange

func (m *Manifest) AddObjectChange(stateObject *StateObject)

func (*Manifest) AddStorageChange

func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte, storage *big.Int)

func (*Manifest) Reset

func (m *Manifest) Reset()

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

func (*Memory) Data

func (m *Memory) Data() []byte

func (*Memory) Get

func (m *Memory) Get(offset, size int64) []byte

func (*Memory) Len

func (m *Memory) Len() int

func (*Memory) Print

func (m *Memory) Print()

func (*Memory) Resize

func (m *Memory) Resize(size uint64)

func (*Memory) Set

func (m *Memory) Set(offset, size int64, value []byte)

type NonceErr

type NonceErr struct {
	Message string
	Is, Exp uint64
}

func NonceError

func NonceError(is, exp uint64) *NonceErr

func (*NonceErr) Error

func (err *NonceErr) Error() string

type OpCode

type OpCode int

func (OpCode) String

func (o OpCode) String() string

type OpType

type OpType int

type OutOfGasErr

type OutOfGasErr struct {
	Message string
}

func OutOfGasError

func OutOfGasError() *OutOfGasErr

func (*OutOfGasErr) Error

func (self *OutOfGasErr) Error() string

type ParentErr

type ParentErr struct {
	Message string
}

Parent error. In case a parent is unknown this error will be thrown by the block manager

func (*ParentErr) Error

func (err *ParentErr) Error() string

type Peer

type Peer interface {
	Inbound() bool
	LastSend() time.Time
	LastPong() int64
	Host() []byte
	Port() uint16
	Version() string
	PingTime() string
	Connected() *int32
}

type PoW

type PoW interface {
	Search(block *Block, reactChan chan ethutil.React) []byte
	Verify(hash []byte, diff *big.Int, nonce []byte) bool
	GetHashrate() int64
}

type Receipt

type Receipt struct {
	Tx                *Transaction
	PostState         []byte
	CumulativeGasUsed *big.Int
}

func NewRecieptFromValue

func NewRecieptFromValue(val *ethutil.Value) *Receipt

func (*Receipt) Cmp

func (self *Receipt) Cmp(other *Receipt) bool

func (*Receipt) RlpData

func (self *Receipt) RlpData() interface{}

func (*Receipt) RlpValueDecode

func (self *Receipt) RlpValueDecode(decoder *ethutil.Value)

func (*Receipt) String

func (self *Receipt) String() string

type Receipts

type Receipts []*Receipt

type RuntimeVars

type RuntimeVars struct {
	Origin      []byte
	Block       *Block
	BlockNumber *big.Int
	PrevHash    []byte
	Coinbase    []byte
	Time        int64
	Diff        *big.Int
	TxData      []string
	Value       *big.Int
}

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Simple push/pop stack mechanism

func NewStack

func NewStack() *Stack

func (*Stack) Data

func (st *Stack) Data() []*big.Int

func (*Stack) Get

func (st *Stack) Get(amount *big.Int) []*big.Int

func (*Stack) Len

func (st *Stack) Len() int

func (*Stack) Peek

func (st *Stack) Peek() *big.Int

func (*Stack) Peekn

func (st *Stack) Peekn() (*big.Int, *big.Int)

func (*Stack) Pop

func (st *Stack) Pop() *big.Int

func (*Stack) Popn

func (st *Stack) Popn() (*big.Int, *big.Int)

func (*Stack) Print

func (st *Stack) Print()

func (*Stack) Push

func (st *Stack) Push(d *big.Int)

type State

type State struct {
	// contains filtered or unexported fields
}

States within the ethereum protocol are used to store anything within the merkle trie. States take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts

func NewState

func NewState(trie *ethtrie.Trie) *State

Create a new state from a given trie

func (*State) Cmp

func (s *State) Cmp(other *State) bool

func (*State) Copy

func (self *State) Copy() *State

func (*State) CreateOutputForDiff

func (self *State) CreateOutputForDiff()

Debug stuff

func (*State) DeleteStateObject

func (self *State) DeleteStateObject(stateObject *StateObject)

Delete the given state object and delete it from the state trie

func (*State) EachStorage

func (s *State) EachStorage(cb ethtrie.EachCallback)

Iterate over each storage address and yield callback

func (*State) Empty

func (self *State) Empty()

func (*State) GetAccount

func (self *State) GetAccount(addr []byte) *StateObject

Deprecated

func (*State) GetBalance

func (self *State) GetBalance(addr []byte) *big.Int

Retrieve the balance from the given address or 0 if object not found

func (*State) GetNonce

func (self *State) GetNonce(addr []byte) uint64

func (*State) GetOrNewStateObject

func (self *State) GetOrNewStateObject(addr []byte) *StateObject

Retrieve a state object or create a new state object if nil

func (*State) GetStateObject

func (self *State) GetStateObject(addr []byte) *StateObject

Retrieve a state object given my the address. Nil if not found

func (*State) NewStateObject

func (self *State) NewStateObject(addr []byte) *StateObject

Create a state object whether it exist in the trie or not

func (*State) Reset

func (s *State) Reset()

Resets the trie and all siblings

func (*State) Root

func (s *State) Root() interface{}

func (*State) Set

func (self *State) Set(state *State)

func (*State) Sync

func (s *State) Sync()

Syncs the trie and all siblings

func (*State) Update

func (self *State) Update()

func (*State) UpdateStateObject

func (self *State) UpdateStateObject(stateObject *StateObject)

Update the given state object and apply it to state trie

type StateManager

type StateManager struct {

	// Proof of work used for validating
	Pow PoW
	// The ethereum manager interface
	Ethereum EthManager
	// contains filtered or unexported fields
}

func NewStateManager

func NewStateManager(ethereum EthManager) *StateManager

func (*StateManager) AccumelateRewards

func (sm *StateManager) AccumelateRewards(state *State, block *Block) error

func (*StateManager) ApplyDiff

func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts Receipts, err error)

func (*StateManager) BlockChain

func (sm *StateManager) BlockChain() *BlockChain

func (*StateManager) CalculateTD

func (sm *StateManager) CalculateTD(block *Block) bool

func (*StateManager) CurrentState

func (sm *StateManager) CurrentState() *State

func (*StateManager) MiningState

func (sm *StateManager) MiningState() *State

func (*StateManager) NewMiningState

func (sm *StateManager) NewMiningState() *State

func (*StateManager) Process

func (sm *StateManager) Process(block *Block, dontReact bool) (err error)

func (*StateManager) ProcessTransactions

func (self *StateManager) ProcessTransactions(coinbase *StateObject, state *State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, error)

func (*StateManager) Stop

func (sm *StateManager) Stop()

func (*StateManager) TransState

func (sm *StateManager) TransState() *State

func (*StateManager) ValidateBlock

func (sm *StateManager) ValidateBlock(block *Block) error

Validates the current block. Returns an error if the block was invalid, an uncle or anything that isn't on the current block chain. Validation validates easy over difficult (dagger takes longer time = difficult)

type StateObject

type StateObject struct {

	// Shared attributes
	Amount     *big.Int
	ScriptHash []byte
	Nonce      uint64
	// contains filtered or unexported fields
}

func MakeContract

func MakeContract(tx *Transaction, state *State) *StateObject

Converts an transaction in to a state object

func NewContract

func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject

func NewStateObject

func NewStateObject(addr []byte) *StateObject

func NewStateObjectFromBytes

func NewStateObjectFromBytes(address, data []byte) *StateObject

func (*StateObject) AddAmount

func (c *StateObject) AddAmount(amount *big.Int)

func (*StateObject) Address

func (c *StateObject) Address() []byte

Returns the address of the contract/account

func (*StateObject) BuyGas

func (self *StateObject) BuyGas(gas, price *big.Int) error

func (*StateObject) ConvertGas

func (c *StateObject) ConvertGas(gas, price *big.Int) error

func (*StateObject) Copy

func (self *StateObject) Copy() *StateObject

func (*StateObject) GetAddr

func (c *StateObject) GetAddr(addr []byte) *ethutil.Value

func (*StateObject) GetInstr

func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value

func (*StateObject) GetStorage

func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value

func (*StateObject) Init

func (c *StateObject) Init() Code

Returns the initialization script

func (*StateObject) MarkForDeletion

func (self *StateObject) MarkForDeletion()

func (*StateObject) N

func (c *StateObject) N() *big.Int

func (*StateObject) RefundGas

func (self *StateObject) RefundGas(gas, price *big.Int)

func (*StateObject) Reset

func (self *StateObject) Reset()

func (*StateObject) ReturnGas

func (c *StateObject) ReturnGas(gas, price *big.Int, state *State)

Return the gas back to the origin. Used by the Virtual machine or Closures

func (*StateObject) RlpDecode

func (c *StateObject) RlpDecode(data []byte)

func (*StateObject) RlpEncode

func (c *StateObject) RlpEncode() []byte

State object encoding methods

func (*StateObject) Script

func (c *StateObject) Script() Code

Returns the main script body

func (*StateObject) Set

func (self *StateObject) Set(stateObject *StateObject)

func (*StateObject) SetAddr

func (c *StateObject) SetAddr(addr []byte, value interface{})

func (*StateObject) SetAmount

func (c *StateObject) SetAmount(amount *big.Int)

func (*StateObject) SetGasPool

func (self *StateObject) SetGasPool(gasLimit *big.Int)

func (*StateObject) SetStorage

func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value)

func (*StateObject) State

func (c *StateObject) State() *State

func (*StateObject) SubAmount

func (c *StateObject) SubAmount(amount *big.Int)

func (*StateObject) Sync

func (self *StateObject) Sync()

type StateTransition

type StateTransition struct {
	// contains filtered or unexported fields
}

* The State transitioning model * * A state transition is a change made when a transaction is applied to the current world state * The state transitioning model does all all the necessary work to work out a valid new state root. * 1) Nonce handling * 2) Pre pay / buy gas of the coinbase (miner) * 3) Create a new state object if the recipient is \0*32 * 4) Value transfer * == If contract creation == * 4a) Attempt to run transaction data * 4b) If valid, use result as code for the new state object * == end == * 5) Run Script section * 6) Derive new state root

func NewStateTransition

func NewStateTransition(coinbase *StateObject, tx *Transaction, state *State, block *Block) *StateTransition

func (*StateTransition) AddGas

func (self *StateTransition) AddGas(amount *big.Int)

func (*StateTransition) BuyGas

func (self *StateTransition) BuyGas() error

func (*StateTransition) Coinbase

func (self *StateTransition) Coinbase() *StateObject

func (*StateTransition) Eval

func (self *StateTransition) Eval(script []byte, context *StateObject, typ string) (ret []byte, err error)

func (*StateTransition) MakeStateObject

func (self *StateTransition) MakeStateObject(state *State, tx *Transaction) *StateObject

func (*StateTransition) Receiver

func (self *StateTransition) Receiver() *StateObject

func (*StateTransition) RefundGas

func (self *StateTransition) RefundGas()

func (*StateTransition) Sender

func (self *StateTransition) Sender() *StateObject

func (*StateTransition) TransitionState

func (self *StateTransition) TransitionState() (err error)

func (*StateTransition) UseGas

func (self *StateTransition) UseGas(amount *big.Int) error

type Storage

type Storage map[string]*ethutil.Value

func (Storage) Copy

func (self Storage) Copy() Storage

type StorageState

type StorageState struct {
	StateAddress []byte
	Address      []byte
	Value        *big.Int
}

Storage change object. Used by the manifest for notifying changes to the sub channels.

type Transaction

type Transaction struct {
	Nonce     uint64
	Recipient []byte
	Value     *big.Int
	Gas       *big.Int
	GasPrice  *big.Int
	Data      []byte
	// contains filtered or unexported fields
}

func FindTx

func FindTx(pool *list.List, finder func(*Transaction, *list.Element) bool) *Transaction

func NewContractCreationTx

func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction

func NewTransactionFromBytes

func NewTransactionFromBytes(data []byte) *Transaction

func NewTransactionFromValue

func NewTransactionFromValue(val *ethutil.Value) *Transaction

func NewTransactionMessage

func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction

func (*Transaction) CreatesContract

func (tx *Transaction) CreatesContract() bool

func (*Transaction) CreationAddress

func (tx *Transaction) CreationAddress() []byte

func (*Transaction) GasValue

func (self *Transaction) GasValue() *big.Int

func (*Transaction) Hash

func (tx *Transaction) Hash() []byte

func (*Transaction) IsContract

func (tx *Transaction) IsContract() bool

Deprecated

func (*Transaction) PublicKey

func (tx *Transaction) PublicKey() []byte

func (*Transaction) RlpData

func (tx *Transaction) RlpData() interface{}

func (*Transaction) RlpDecode

func (tx *Transaction) RlpDecode(data []byte)

func (*Transaction) RlpEncode

func (tx *Transaction) RlpEncode() []byte

func (*Transaction) RlpValue

func (tx *Transaction) RlpValue() *ethutil.Value

func (*Transaction) RlpValueDecode

func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value)

func (*Transaction) Sender

func (tx *Transaction) Sender() []byte

func (*Transaction) Sign

func (tx *Transaction) Sign(privk []byte) error

func (*Transaction) Signature

func (tx *Transaction) Signature(key []byte) []byte

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) TotalValue

func (self *Transaction) TotalValue() *big.Int

type Transactions

type Transactions []*Transaction

Transaction slice type for basic sorting

func (Transactions) Len

func (s Transactions) Len() int

func (Transactions) Swap

func (s Transactions) Swap(i, j int)

type TxByNonce

type TxByNonce struct{ Transactions }

func (TxByNonce) Less

func (s TxByNonce) Less(i, j int) bool

type TxCallback

type TxCallback func(opType OpType) bool

type TxMsg

type TxMsg struct {
	Tx   *Transaction
	Type TxMsgTy
}

type TxMsgTy

type TxMsgTy byte

type TxPool

type TxPool struct {
	Ethereum EthManager

	SecondaryProcessor TxProcessor
	// contains filtered or unexported fields
}

The tx pool a thread safe transaction pool handler. In order to guarantee a non blocking pool we use a queue channel which can be independently read without needing access to the actual pool. If the pool is being drained or synced for whatever reason the transactions will simple queue up and handled when the mutex is freed.

func NewTxPool

func NewTxPool(ethereum EthManager) *TxPool

func (*TxPool) CurrentTransactions

func (pool *TxPool) CurrentTransactions() []*Transaction

func (*TxPool) Flush

func (pool *TxPool) Flush() []*Transaction

func (*TxPool) QueueTransaction

func (pool *TxPool) QueueTransaction(tx *Transaction)

func (*TxPool) RemoveInvalid

func (pool *TxPool) RemoveInvalid(state *State)

func (*TxPool) Start

func (pool *TxPool) Start()

func (*TxPool) Stop

func (pool *TxPool) Stop()

func (*TxPool) ValidateTransaction

func (pool *TxPool) ValidateTransaction(tx *Transaction) error

type TxPoolHook

type TxPoolHook chan *Transaction

type TxProcessor

type TxProcessor interface {
	ProcessTransaction(tx *Transaction)
}

type ValidationErr

type ValidationErr struct {
	Message string
}

Block validation error. If any validation fails, this error will be thrown

func ValidationError

func ValidationError(format string, v ...interface{}) *ValidationErr

func (*ValidationErr) Error

func (err *ValidationErr) Error() string

type Vm

type Vm struct {
	Verbose bool

	// Debugging
	Dbg Debugger

	BreakPoints []int64
	Stepping    bool
	Fn          string
	// contains filtered or unexported fields
}

func NewVm

func NewVm(state *State, stateManager *StateManager, vars RuntimeVars) *Vm

func (*Vm) Endl

func (self *Vm) Endl() *Vm

func (*Vm) Printf

func (self *Vm) Printf(format string, v ...interface{}) *Vm

func (*Vm) RunClosure

func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL