Commit 64f35ba8 authored by obscuren's avatar obscuren

merge errors fixed

parents 616066a5 99481a24
...@@ -9,11 +9,9 @@ import ( ...@@ -9,11 +9,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire" "github.com/ethereum/go-ethereum/wire"
) )
...@@ -312,11 +310,10 @@ out: ...@@ -312,11 +310,10 @@ out:
} }
if len(blocks) > 0 { if len(blocks) > 0 {
chainManager := self.eth.ChainManager() chainman := self.eth.ChainManager()
// Test and import
bchain := chain.NewChain(blocks) err := chainman.InsertChain(blocks)
_, err := chainManager.TestChain(bchain) if err != nil {
if err != nil && !chain.IsTDError(err) {
poollogger.Debugln(err) poollogger.Debugln(err)
self.Reset() self.Reset()
...@@ -330,16 +327,10 @@ out: ...@@ -330,16 +327,10 @@ out:
self.peer.StopWithReason(DiscBadPeer) self.peer.StopWithReason(DiscBadPeer)
self.td = ethutil.Big0 self.td = ethutil.Big0
self.peer = nil self.peer = nil
} else { }
if !chain.IsTDError(err) {
chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
self.eth.EventMux().Post(messages)
for _, block := range blocks {
self.Remove(block.Hash()) self.Remove(block.Hash())
})
}
} }
} }
} }
......
...@@ -187,6 +187,7 @@ func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Mes ...@@ -187,6 +187,7 @@ func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Mes
defer sm.mutex.Unlock() defer sm.mutex.Unlock()
if sm.bc.HasBlock(block.Hash()) { if sm.bc.HasBlock(block.Hash()) {
fmt.Println("already having this block")
return nil, nil, nil return nil, nil, nil
} }
...@@ -213,7 +214,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I ...@@ -213,7 +214,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
fmt.Printf("## %x %x ##\n", block.Hash(), block.Number) fmt.Printf("## %x %x ##\n", block.Hash(), block.Number)
} }
receipts, err := sm.ApplyDiff(state, parent, block) _, err = sm.ApplyDiff(state, parent, block)
if err != nil { if err != nil {
return return
} }
...@@ -224,11 +225,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I ...@@ -224,11 +225,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return return
} }
/*
receiptSha := types.DeriveSha(receipts) receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 { if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha) err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
return return
} }
*/
// Block validation // Block validation
if err = sm.ValidateBlock(block, parent); err != nil { if err = sm.ValidateBlock(block, parent); err != nil {
...@@ -241,14 +244,16 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I ...@@ -241,14 +244,16 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return return
} }
/*
//block.receipts = receipts // although this isn't necessary it be in the future //block.receipts = receipts // although this isn't necessary it be in the future
rbloom := types.CreateBloom(receipts) rbloom := types.CreateBloom(receipts)
if bytes.Compare(rbloom, block.LogsBloom) != 0 { if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom) err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
return return
} }
*/
state.Update(nil) state.Update(ethutil.Big0)
if !block.State().Cmp(state) { if !block.State().Cmp(state) {
err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root()) err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root())
...@@ -268,6 +273,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I ...@@ -268,6 +273,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
sm.transState = state.Copy() sm.transState = state.Copy()
sm.eth.TxPool().RemoveSet(block.Transactions()) sm.eth.TxPool().RemoveSet(block.Transactions())
fmt.Println("TD", td)
return td, messages, nil return td, messages, nil
} else { } else {
......
package chain package chain
import ( import (
"bytes"
"container/list"
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
) )
var chainlogger = logger.NewLogger("CHAIN") var chainlogger = logger.NewLogger("CHAIN")
...@@ -56,8 +53,6 @@ type ChainManager struct { ...@@ -56,8 +53,6 @@ type ChainManager struct {
CurrentBlock *types.Block CurrentBlock *types.Block
LastBlockHash []byte LastBlockHash []byte
workingChain *BlockChain
} }
func NewChainManager() *ChainManager { func NewChainManager() *ChainManager {
...@@ -186,15 +181,6 @@ func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain ...@@ -186,15 +181,6 @@ func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain
func (self *ChainManager) GetBlock(hash []byte) *types.Block { func (self *ChainManager) GetBlock(hash []byte) *types.Block {
data, _ := ethutil.Config.Db.Get(hash) data, _ := ethutil.Config.Db.Get(hash)
if len(data) == 0 { if len(data) == 0 {
if self.workingChain != nil {
// Check the temp chain
for e := self.workingChain.Front(); e != nil; e = e.Next() {
if bytes.Compare(e.Value.(*link).Block.Hash(), hash) == 0 {
return e.Value.(*link).Block
}
}
}
return nil return nil
} }
...@@ -264,103 +250,22 @@ func (bc *ChainManager) Stop() { ...@@ -264,103 +250,22 @@ func (bc *ChainManager) Stop() {
} }
} }
func (self *ChainManager) NewIterator(startHash []byte) *ChainIterator { func (self *ChainManager) InsertChain(chain Blocks) error {
return &ChainIterator{self, self.GetBlock(startHash)} for _, block := range chain {
} td, messages, err := self.Ethereum.BlockManager().Process(block)
// This function assumes you've done your checking. No checking is done at this stage anymore
func (self *ChainManager) InsertChain(chain *BlockChain, call func(*types.Block, state.Messages)) {
for e := chain.Front(); e != nil; e = e.Next() {
link := e.Value.(*link)
self.add(link.Block)
self.SetTotalDifficulty(link.Td)
call(link.Block, link.Messages)
}
b, e := chain.Front(), chain.Back()
if b != nil && e != nil {
front, back := b.Value.(*link).Block, e.Value.(*link).Block
chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4])
}
}
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
self.workingChain = chain
defer func() { self.workingChain = nil }()
for e := chain.Front(); e != nil; e = e.Next() {
var (
l = e.Value.(*link)
block = l.Block
parent = self.GetBlock(block.PrevHash)
)
if parent == nil {
err = fmt.Errorf("incoming chain broken on hash %x\n", block.PrevHash[0:4])
return
}
var messages state.Messages
td, messages, err = self.processor.ProcessWithParent(block, parent) //self.eth.BlockManager().ProcessWithParent(block, parent)
if err != nil { if err != nil {
chainlogger.Infoln(err) if IsKnownBlockErr(err) {
chainlogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4]) continue
chainlogger.Debugln(block)
err = fmt.Errorf("incoming chain failed %v\n", err)
return
}
l.Td = td
l.Messages = messages
} }
if td.Cmp(self.TD) <= 0 { return err
err = &TDError{td, self.TD}
return
} }
self.workingChain = nil self.add(block)
self.SetTotalDifficulty(td)
return self.Ethereum.EventMux().Post(NewBlockEvent{block})
} self.Ethereum.EventMux().Post(messages)
type link struct {
Block *types.Block
Messages state.Messages
Td *big.Int
}
type BlockChain struct {
*list.List
}
func NewChain(blocks types.Blocks) *BlockChain {
chain := &BlockChain{list.New()}
for _, block := range blocks {
chain.PushBack(&link{block, nil, nil})
}
return chain
}
func (self *BlockChain) RlpEncode() []byte {
dat := make([]interface{}, 0)
for e := self.Front(); e != nil; e = e.Next() {
dat = append(dat, e.Value.(*link).Block.RlpData())
} }
return ethutil.Encode(dat) return nil
}
type ChainIterator struct {
cm *ChainManager
block *types.Block // current block in the iterator
}
func (self *ChainIterator) Prev() *types.Block {
self.block = self.cm.GetBlock(self.block.PrevHash)
return self.block
} }
...@@ -126,3 +126,16 @@ func IsTDError(e error) bool { ...@@ -126,3 +126,16 @@ func IsTDError(e error) bool {
_, ok := e.(*TDError) _, ok := e.(*TDError)
return ok return ok
} }
type KnownBlockError struct {
number uint64
hash []byte
}
func (self *KnownBlockError) Error() string {
return fmt.Sprintf("block %d already known (%x)", self.number, self.hash[0:4])
}
func IsKnownBlockErr(e error) bool {
_, ok := e.(*KnownBlockError)
return ok
}
...@@ -103,11 +103,15 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { ...@@ -103,11 +103,15 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
block := pool.Ethereum.ChainManager().CurrentBlock block := pool.Ethereum.ChainManager().CurrentBlock
// Something has gone horribly wrong if this happens // Something has gone horribly wrong if this happens
if block == nil { if block == nil {
return fmt.Errorf("[TXPL] No last block on the block chain") return fmt.Errorf("No last block on the block chain")
} }
if len(tx.Recipient) != 0 && len(tx.Recipient) != 20 { if len(tx.Recipient) != 0 && len(tx.Recipient) != 20 {
return fmt.Errorf("[TXPL] Invalid recipient. len = %d", len(tx.Recipient)) return fmt.Errorf("Invalid recipient. len = %d", len(tx.Recipient))
}
if tx.v > 28 || tx.v < 27 {
return fmt.Errorf("tx.v != (28 || 27)")
} }
if tx.GasPrice.Cmp(MinGasPrice) < 0 { if tx.GasPrice.Cmp(MinGasPrice) < 0 {
...@@ -115,19 +119,18 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { ...@@ -115,19 +119,18 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
} }
// Get the sender // Get the sender
//sender := pool.Ethereum.BlockManager().procState.GetAccount(tx.Sender())
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender()) sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value) totAmount := new(big.Int).Set(tx.Value)
// Make sure there's enough in the sender's account. Having insufficient // Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it. // funds won't invalidate this transaction but simple ignores it.
if sender.Balance().Cmp(totAmount) < 0 { if sender.Balance().Cmp(totAmount) < 0 {
return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender()) return fmt.Errorf("Insufficient amount in sender's (%x) account", tx.Sender())
} }
if tx.IsContract() { if tx.IsContract() {
if tx.GasPrice.Cmp(big.NewInt(minGasPrice)) < 0 { if tx.GasPrice.Cmp(big.NewInt(minGasPrice)) < 0 {
return fmt.Errorf("[TXPL] Gasprice too low, %s given should be at least %d.", tx.GasPrice, minGasPrice) return fmt.Errorf("Gasprice too low, %s given should be at least %d.", tx.GasPrice, minGasPrice)
} }
} }
...@@ -137,6 +140,34 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { ...@@ -137,6 +140,34 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return nil return nil
} }
func (self *TxPool) Add(tx *types.Transaction) error {
hash := tx.Hash()
foundTx := FindTx(self.pool, func(tx *Transaction, e *list.Element) bool {
return bytes.Compare(tx.Hash(), hash) == 0
})
if foundTx != nil {
return fmt.Errorf("Known transaction (%x)", hash[0:4])
}
err := self.ValidateTransaction(tx)
if err != nil {
return err
}
self.addTransaction(tx)
tmp := make([]byte, 4)
copy(tmp, tx.Recipient)
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers
self.Ethereum.EventMux().Post(TxPreEvent{tx})
return nil
}
func (pool *TxPool) queueHandler() { func (pool *TxPool) queueHandler() {
out: out:
for { for {
...@@ -173,10 +204,6 @@ out: ...@@ -173,10 +204,6 @@ out:
} }
} }
func (pool *TxPool) QueueTransaction(tx *types.Transaction) {
pool.queueChan <- tx
}
func (pool *TxPool) CurrentTransactions() []*types.Transaction { func (pool *TxPool) CurrentTransactions() []*types.Transaction {
pool.mutex.Lock() pool.mutex.Lock()
defer pool.mutex.Unlock() defer pool.mutex.Unlock()
......
...@@ -79,12 +79,7 @@ func (tx *Transaction) IsContract() bool { ...@@ -79,12 +79,7 @@ func (tx *Transaction) IsContract() bool {
func (tx *Transaction) CreationAddress(state *state.State) []byte { func (tx *Transaction) CreationAddress(state *state.State) []byte {
// Generate a new address // Generate a new address
addr := crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:] return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
//for i := uint64(0); state.GetStateObject(addr) != nil; i++ {
// addr = crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce + i}).Encode())[12:]
//}
return addr
} }
func (tx *Transaction) Signature(key []byte) []byte { func (tx *Transaction) Signature(key []byte) []byte {
......
...@@ -25,7 +25,6 @@ import ( ...@@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
) )
type plugin struct { type plugin struct {
...@@ -45,12 +44,12 @@ func (gui *Gui) LogPrint(level logger.LogLevel, msg string) { ...@@ -45,12 +44,12 @@ func (gui *Gui) LogPrint(level logger.LogLevel, msg string) {
} }
*/ */
} }
func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (*xeth.JSReceipt, error) { func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (string, error) {
var data string var data string
if len(recipient) == 0 { if len(recipient) == 0 {
code, err := ethutil.Compile(d, false) code, err := ethutil.Compile(d, false)
if err != nil { if err != nil {
return nil, err return "", err
} }
data = ethutil.Bytes2Hex(code) data = ethutil.Bytes2Hex(code)
} else { } else {
......
...@@ -128,7 +128,10 @@ func (self *UiLib) PastPeers() *ethutil.List { ...@@ -128,7 +128,10 @@ func (self *UiLib) PastPeers() *ethutil.List {
func (self *UiLib) ImportTx(rlpTx string) { func (self *UiLib) ImportTx(rlpTx string) {
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(rlpTx)) tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(rlpTx))
self.eth.TxPool().QueueTransaction(tx) err := self.eth.TxPool().Add(tx)
if err != nil {
guilogger.Infoln("import tx failed ", err)
}
} }
func (self *UiLib) EvalJavascriptFile(path string) { func (self *UiLib) EvalJavascriptFile(path string) {
...@@ -306,7 +309,7 @@ func mapToTxParams(object map[string]interface{}) map[string]string { ...@@ -306,7 +309,7 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
return conv return conv
} }
func (self *UiLib) Transact(params map[string]interface{}) (*xeth.JSReceipt, error) { func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
object := mapToTxParams(params) object := mapToTxParams(params)
return self.JSXEth.Transact( return self.JSXEth.Transact(
......
...@@ -62,6 +62,16 @@ func S256(x *big.Int) *big.Int { ...@@ -62,6 +62,16 @@ func S256(x *big.Int) *big.Int {
} }
} }
func FirstBitSet(v *big.Int) int {
for i := 0; i < v.BitLen(); i++ {
if v.Bit(i) > 0 {
return i
}
}
return v.BitLen()
}
// Big to bytes // Big to bytes
// //
// Returns the bytes of a big integer with the size specified by **base** // Returns the bytes of a big integer with the size specified by **base**
......
...@@ -29,7 +29,6 @@ import ( ...@@ -29,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/chain/types"
...@@ -205,7 +204,7 @@ func (self *Miner) mine() { ...@@ -205,7 +204,7 @@ func (self *Miner) mine() {
// Accumulate the rewards included for this block // Accumulate the rewards included for this block
blockManager.AccumelateRewards(block.State(), block, parent) blockManager.AccumelateRewards(block.State(), block, parent)
block.State().Update(nil) block.State().Update(ethutil.Big0)
minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions))
...@@ -213,15 +212,10 @@ func (self *Miner) mine() { ...@@ -213,15 +212,10 @@ func (self *Miner) mine() {
nonce := self.pow.Search(block, self.powQuitCh) nonce := self.pow.Search(block, self.powQuitCh)
if nonce != nil { if nonce != nil {
block.Nonce = nonce block.Nonce = nonce
lchain := chain.NewChain(types.Blocks{block}) err := chainMan.InsertChain(types.Blocks{block})
_, err := chainMan.TestChain(lchain)
if err != nil { if err != nil {
minerlogger.Infoln(err) minerlogger.Infoln(err)
} else { } else {
chainMan.InsertChain(lchain, func(block *types.Block, _ state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
})
self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val}) self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val})
minerlogger.Infof("🔨 Mined block %x\n", block.Hash()) minerlogger.Infof("🔨 Mined block %x\n", block.Hash())
......
...@@ -430,7 +430,12 @@ func (p *Peer) HandleInbound() { ...@@ -430,7 +430,12 @@ func (p *Peer) HandleInbound() {
// processing when a new block is found // processing when a new block is found
for i := 0; i < msg.Data.Len(); i++ { for i := 0; i < msg.Data.Len(); i++ {
tx := types.NewTransactionFromValue(msg.Data.Get(i)) tx := types.NewTransactionFromValue(msg.Data.Get(i))
p.ethereum.TxPool().QueueTransaction(tx) err := p.ethereum.TxPool().Add(tx)
if err != nil {
peerlogger.Infoln(err)
} else {
peerlogger.Infof("tx OK (%x)\n", tx.Hash()[0:4])
}
} }
case wire.MsgGetPeersTy: case wire.MsgGetPeersTy:
// Peer asked for list of connected peers // Peer asked for list of connected peers
......
...@@ -249,7 +249,6 @@ func (s *State) Reset() { ...@@ -249,7 +249,6 @@ func (s *State) Reset() {
continue continue
} }
//stateObject.state.Reset()
stateObject.Reset() stateObject.Reset()
} }
...@@ -281,6 +280,7 @@ func (self *State) Update(gasUsed *big.Int) { ...@@ -281,6 +280,7 @@ func (self *State) Update(gasUsed *big.Int) {
var deleted bool var deleted bool
// Refund any gas that's left // Refund any gas that's left
// XXX THIS WILL CHANGE IN POC8
uhalf := new(big.Int).Div(gasUsed, ethutil.Big2) uhalf := new(big.Int).Div(gasUsed, ethutil.Big2)
for addr, refs := range self.refund { for addr, refs := range self.refund {
for _, ref := range refs { for _, ref := range refs {
...@@ -289,6 +289,7 @@ func (self *State) Update(gasUsed *big.Int) { ...@@ -289,6 +289,7 @@ func (self *State) Update(gasUsed *big.Int) {
self.GetStateObject([]byte(addr)).AddBalance(refund.Mul(refund, ref.price)) self.GetStateObject([]byte(addr)).AddBalance(refund.Mul(refund, ref.price))
} }
} }
self.refund = make(map[string][]refund)
for _, stateObject := range self.stateObjects { for _, stateObject := range self.stateObjects {
if stateObject.remove { if stateObject.remove {
......
...@@ -212,7 +212,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error { ...@@ -212,7 +212,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
func (self *StateObject) SetGasPool(gasLimit *big.Int) { func (self *StateObject) SetGasPool(gasLimit *big.Int) {
self.gasPool = new(big.Int).Set(gasLimit) self.gasPool = new(big.Int).Set(gasLimit)
statelogger.DebugDetailf("%x: fuel (+ %v)", self.Address(), self.gasPool) statelogger.Debugf("%x: gas (+ %v)", self.Address(), self.gasPool)
} }
func (self *StateObject) BuyGas(gas, price *big.Int) error { func (self *StateObject) BuyGas(gas, price *big.Int) error {
......
{ {
"genesis_rlp_hex": "f9012ff9012aa00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0", "genesis_rlp_hex": "f9012ef90129a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0",
"genesis_state_root": "c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718c", "genesis_state_root": "c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718c",
"initial_alloc": { "initial_alloc": {
"51ba59315b3a95761d0863b05ccc7a7f54703d99": "1606938044258990275541962092341162602522202993782792835301376", "51ba59315b3a95761d0863b05ccc7a7f54703d99": "1606938044258990275541962092341162602522202993782792835301376",
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
"e6716f9544a56c530d868e4bfbacb172315bdead": "1606938044258990275541962092341162602522202993782792835301376", "e6716f9544a56c530d868e4bfbacb172315bdead": "1606938044258990275541962092341162602522202993782792835301376",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4": "1606938044258990275541962092341162602522202993782792835301376" "1a26338f0d905e295fccb71fa9ea849ffa12aaf4": "1606938044258990275541962092341162602522202993782792835301376"
}, },
"genesis_hash": "955f36d073ccb026b78ab3424c15cf966a7563aa270413859f78702b9e8e22cb" "genesis_hash": "779b1b620b03c0fb24963e183d5e88e3dbe4484e3f6e2aa05942e3be7b48e179"
} }
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
"currentTimestamp" : 1, "currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
}, },
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : { "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
......
This diff is collapsed.
{
"makeMoney" : {
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs" : {
},
"out" : "0x",
"post" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000010",
"code" : "0x7b601080600c6000396000f200600035541560095700602035600035556000526000600060006000601773aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecf1",
"nonce" : "0",
"storage" : {
}
},
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" : {
"balance" : "850",
"code" : "0x",
"nonce" : "0",
"storage" : {
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "140",
"code" : "0x",
"nonce" : "1",
"storage" : {
}
},
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000",
"code" : "0x600160015532600255",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"code" : "0x7b601080600c6000396000f200600035541560095700602035600035556000526000600060006000601773aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecf1",
"nonce" : "0",
"storage" : {
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000",
"code" : "0x",
"nonce" : "0",
"storage" : {
}
},
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000",
"code" : "0x600160015532600255",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" : {
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "10"
}
}
}
\ No newline at end of file
{ {
"singleItem": { "singleItem": {
"in": { "in": [
"A": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ["A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
}, ],
"root": "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab" "root": "0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab"
}, },
"dogs": { "dogs": {
"in": { "in": [
"doe": "reindeer", ["doe", "reindeer"],
"dog": "puppy", ["dog", "puppy"],
"dogglesworth": "cat" ["dogglesworth", "cat"]
}, ],
"root": "8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3" "root": "0x8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"
}, },
"puppy": { "puppy": {
"in": { "in": [
"do": "verb", ["do", "verb"],
"horse": "stallion", ["horse", "stallion"],
"doge": "coin", ["doge", "coin"],
"dog": "puppy" ["dog", "puppy"]
}, ],
"root": "5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84" "root": "0x5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84"
}, },
"emptyValues": { "emptyValues": {
"in": { "in": [
"do": "verb", ["do", "verb"],
"ether": "wookiedoo", ["ether", "wookiedoo"],
"horse": "stallion", ["horse", "stallion"],
"shaman": "horse", ["shaman", "horse"],
"doge": "coin", ["doge", "coin"],
"ether": "", ["ether", ""],
"dog": "puppy", ["dog", "puppy"],
"shaman": "" ["shaman", ""]
}, ],
"root": "4505cb6d817068bcd68fb225ab4d5ab70860461d3b35738bf6bcf7b44d702d0d" "root": "0x5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84"
}, },
"foo": { "foo": {
"in": { "in": [
"foo": "bar", ["foo", "bar"],
"food": "bat", ["food", "bat"],
"food": "bass" ["food", "bass"]
}, ],
"root": "17beaa1648bafa633cda809c90c04af50fc8aed3cb40d16efbddee6fdf63c4c3" "root": "0x17beaa1648bafa633cda809c90c04af50fc8aed3cb40d16efbddee6fdf63c4c3"
}, },
"smallValues": { "smallValues": {
"in": { "in": [
"be": "e", ["be", "e"],
"dog": "puppy", ["dog", "puppy"],
"bed": "d" ["bed", "d"]
}, ],
"root": "3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b" "root": "0x3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b"
}, },
"testy": { "testy": {
"in": { "in": [
"test": "test", ["test", "test"],
"te": "testy" ["te", "testy"]
}, ],
"root": "8452568af70d8d140f58d941338542f645fcca50094b20f3c3d8c3df49337928" "root": "0x8452568af70d8d140f58d941338542f645fcca50094b20f3c3d8c3df49337928"
}, },
"hex": { "hex": {
"in": { "in": [
"0x0045": "0x0123456789", ["0x0045", "0x0123456789"],
"0x4500": "0x9876543210" ["0x4500", "0x9876543210"]
}, ],
"root": "285505fcabe84badc8aa310e2aae17eddc7d120aabec8a476902c8184b3a3503" "root": "0x285505fcabe84badc8aa310e2aae17eddc7d120aabec8a476902c8184b3a3503"
}, },
"jeff": { "jeff": {
"in": { "in": [
"0x0000000000000000000000000000000000000000000000000000000000000045": "0x22b224a1420a802ab51d326e29fa98e34c4f24ea", ["0x0000000000000000000000000000000000000000000000000000000000000045", "0x22b224a1420a802ab51d326e29fa98e34c4f24ea"],
"0x0000000000000000000000000000000000000000000000000000000000000046": "0x67706c2076330000000000000000000000000000000000000000000000000000", ["0x0000000000000000000000000000000000000000000000000000000000000046", "0x67706c2076330000000000000000000000000000000000000000000000000000"],
"0x0000000000000000000000000000000000000000000000000000001234567890": "0x697c7b8c961b56f675d570498424ac8de1a918f6", ["0x0000000000000000000000000000000000000000000000000000001234567890", "0x697c7b8c961b56f675d570498424ac8de1a918f6"],
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6": "0x1234567890", ["0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6", "0x1234567890"],
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2": "0x4655474156000000000000000000000000000000000000000000000000000000", ["0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2", "0x4655474156000000000000000000000000000000000000000000000000000000"],
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1": "0x4e616d6552656700000000000000000000000000000000000000000000000000", ["0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1", "0x4e616d6552656700000000000000000000000000000000000000000000000000"],
"0x4655474156000000000000000000000000000000000000000000000000000000": "0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2", ["0x4655474156000000000000000000000000000000000000000000000000000000", "0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"],
"0x4e616d6552656700000000000000000000000000000000000000000000000000": "0xec4f34c97e43fbb2816cfd95e388353c7181dab1", ["0x4e616d6552656700000000000000000000000000000000000000000000000000", "0xec4f34c97e43fbb2816cfd95e388353c7181dab1"],
"0x0000000000000000000000000000000000000000000000000000001234567890": "", ["0x0000000000000000000000000000000000000000000000000000001234567890", ""],
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6": "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000", ["0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6", "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"],
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000": "0x697c7b8c961b56f675d570498424ac8de1a918f6" ["0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000", "0x697c7b8c961b56f675d570498424ac8de1a918f6"]
}, ],
"root": "088c8e162c91c75ca9efa63f21530bbc6964cff7453a5d6af8404d090292a3e7" "root": "0x9f6221ebb8efe7cff60a716ecb886e67dd042014be444669f0159d8e68b42100"
} }
} }
This diff is collapsed.
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9698", "gas" : "9698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -64,6 +66,8 @@ ...@@ -64,6 +66,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9698", "gas" : "9698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -107,6 +111,8 @@ ...@@ -107,6 +111,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9698", "gas" : "9698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -150,6 +156,8 @@ ...@@ -150,6 +156,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9898", "gas" : "9898",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -192,6 +200,8 @@ ...@@ -192,6 +200,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9698", "gas" : "9698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -235,6 +245,8 @@ ...@@ -235,6 +245,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9698", "gas" : "9698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -64,6 +66,8 @@ ...@@ -64,6 +66,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"cd1722f3947def4cf144679da39c4c32bdc35681" : { "cd1722f3947def4cf144679da39c4c32bdc35681" : {
...@@ -107,6 +111,8 @@ ...@@ -107,6 +111,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999878", "gas" : "99999999878",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -156,6 +162,8 @@ ...@@ -156,6 +162,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999678", "gas" : "99999999678",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -199,6 +207,8 @@ ...@@ -199,6 +207,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999656", "gas" : "99999999656",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -242,6 +252,8 @@ ...@@ -242,6 +252,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999656", "gas" : "99999999656",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -291,7 +303,9 @@ ...@@ -291,7 +303,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999692", "gas" : "99999999691",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -334,7 +348,9 @@ ...@@ -334,7 +348,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999692", "gas" : "99999999691",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -378,6 +394,8 @@ ...@@ -378,6 +394,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999892", "gas" : "99999999892",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -420,6 +438,8 @@ ...@@ -420,6 +438,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999697", "gas" : "99999999697",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -463,6 +483,8 @@ ...@@ -463,6 +483,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999697", "gas" : "99999999697",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -506,6 +528,8 @@ ...@@ -506,6 +528,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999697", "gas" : "99999999697",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -549,6 +573,8 @@ ...@@ -549,6 +573,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -592,6 +618,8 @@ ...@@ -592,6 +618,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -635,6 +663,8 @@ ...@@ -635,6 +663,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -678,6 +708,8 @@ ...@@ -678,6 +708,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -721,6 +753,8 @@ ...@@ -721,6 +753,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -763,7 +797,9 @@ ...@@ -763,7 +797,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999692", "gas" : "99999999691",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -806,7 +842,9 @@ ...@@ -806,7 +842,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999692", "gas" : "99999999691",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -850,6 +888,8 @@ ...@@ -850,6 +888,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -892,7 +932,9 @@ ...@@ -892,7 +932,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999690", "gas" : "99999999689",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -950,6 +992,8 @@ ...@@ -950,6 +992,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999695", "gas" : "99999999695",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -1007,6 +1051,8 @@ ...@@ -1007,6 +1051,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999697", "gas" : "99999999697",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -1064,6 +1110,8 @@ ...@@ -1064,6 +1110,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -1107,6 +1155,8 @@ ...@@ -1107,6 +1155,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999698", "gas" : "99999999698",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......
This diff is collapsed.
This diff is collapsed.
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "99999999677", "gas" : "99999999677",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -64,6 +66,8 @@ ...@@ -64,6 +66,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9676", "gas" : "9676",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -107,6 +111,8 @@ ...@@ -107,6 +111,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9676", "gas" : "9676",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -129,8 +135,6 @@ ...@@ -129,8 +135,6 @@
} }
}, },
"sha3_3" : { "sha3_3" : {
"callcreates" : [
],
"env" : { "env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256", "currentDifficulty" : "256",
...@@ -149,17 +153,6 @@ ...@@ -149,17 +153,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x620fffff6103e820600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : { "pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
...@@ -171,8 +164,6 @@ ...@@ -171,8 +164,6 @@
} }
}, },
"sha3_4" : { "sha3_4" : {
"callcreates" : [
],
"env" : { "env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256", "currentDifficulty" : "256",
...@@ -191,17 +182,6 @@ ...@@ -191,17 +182,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6064640fffffffff20600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : { "pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
...@@ -213,8 +193,6 @@ ...@@ -213,8 +193,6 @@
} }
}, },
"sha3_5" : { "sha3_5" : {
"callcreates" : [
],
"env" : { "env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256", "currentDifficulty" : "256",
...@@ -233,17 +211,6 @@ ...@@ -233,17 +211,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x640fffffffff61271020600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : { "pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
...@@ -255,8 +222,6 @@ ...@@ -255,8 +222,6 @@
} }
}, },
"sha3_6" : { "sha3_6" : {
"callcreates" : [
],
"env" : { "env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256", "currentDifficulty" : "256",
...@@ -275,17 +240,6 @@ ...@@ -275,17 +240,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff20600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : { "pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9949", "gas" : "9949",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -93,6 +95,8 @@ ...@@ -93,6 +95,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9824", "gas" : "9824",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -141,6 +145,8 @@ ...@@ -141,6 +145,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9971", "gas" : "9971",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
...@@ -183,6 +189,8 @@ ...@@ -183,6 +189,8 @@
"value" : "1000000000000000000" "value" : "1000000000000000000"
}, },
"gas" : "9999", "gas" : "9999",
"logs" : {
},
"out" : "0x", "out" : "0x",
"post" : { "post" : {
"cd1722f3947def4cf144679da39c4c32bdc35681" : { "cd1722f3947def4cf144679da39c4c32bdc35681" : {
......
...@@ -9,6 +9,8 @@ module.exports = { ...@@ -9,6 +9,8 @@ module.exports = {
txtest: require('./BasicTests/txtest'), txtest: require('./BasicTests/txtest'),
StateTests: { StateTests: {
stPreCompiledContracts: require('./StateTests/stPreCompiledContracts'), stPreCompiledContracts: require('./StateTests/stPreCompiledContracts'),
stRecursiveCreate: require('./StateTests/stRecursiveCreate'),
stSpecial: require('./StateTests/stSpecialTest'),
stSystemOperationsTest: require('./StateTests/stSystemOperationsTest'), stSystemOperationsTest: require('./StateTests/stSystemOperationsTest'),
}, },
VMTests: { VMTests: {
...@@ -17,8 +19,9 @@ module.exports = { ...@@ -17,8 +19,9 @@ module.exports = {
vmBlockInfoTest: require('./VMTests/vmBlockInfoTest'), vmBlockInfoTest: require('./VMTests/vmBlockInfoTest'),
vmEnvironmentalInfoTest: require('./VMTests/vmEnvironmentalInfoTest'), vmEnvironmentalInfoTest: require('./VMTests/vmEnvironmentalInfoTest'),
vmIOandFlowOperationsTest: require('./VMTests/vmIOandFlowOperationsTest'), vmIOandFlowOperationsTest: require('./VMTests/vmIOandFlowOperationsTest'),
vmLogTest: require('./VMTests/vmLogTest'),
vmPushDupSwapTest: require('./VMTests/vmPushDupSwapTest'), vmPushDupSwapTest: require('./VMTests/vmPushDupSwapTest'),
vmSha3Test: require('./VMTests/vmSha3Test'), vmSha3Test: require('./VMTests/vmSha3Test'),
vmtestst: require('./VMTests/vmtests'), vmtests: require('./VMTests/vmtests'),
} }
}; };
...@@ -3,6 +3,7 @@ package helper ...@@ -3,6 +3,7 @@ package helper
import ( import (
"math/big" "math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm" "github.com/ethereum/go-ethereum/vm"
...@@ -66,3 +67,17 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, e ...@@ -66,3 +67,17 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, e
return ret, execution.Gas, err return ret, execution.Gas, err
} }
func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, error) {
address := FromHex(tx["to"])
keyPair, _ := crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
caller := state.GetOrNewStateObject(keyPair.Address())
vmenv := NewEnvFromMap(state, env, tx)
vmenv.origin = caller.Address()
evm := vm.New(vmenv, vm.DebugVmTy)
execution := vm.NewExecution(evm, address, FromHex(tx["data"]), ethutil.Big(tx["gasLimit"]), ethutil.Big(tx["gasPrice"]), ethutil.Big(tx["value"]))
ret, err := execution.Exec(address, caller)
return ret, execution.Gas, err
}
package vm package vm
<<<<<<< HEAD
// import ( // import (
// "bytes" // "bytes"
// "testing" // "testing"
...@@ -133,3 +134,185 @@ package vm ...@@ -133,3 +134,185 @@ package vm
// const fn = "../files/vmtests/vmtests.json" // const fn = "../files/vmtests/vmtests.json"
// RunVmTest(fn, t) // RunVmTest(fn, t)
// } // }
=======
import (
"bytes"
"math/big"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
type Account struct {
Balance string
Code string
Nonce string
Storage map[string]string
}
func StateObjectFromAccount(addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr))
obj.SetBalance(ethutil.Big(account.Balance))
if ethutil.IsHex(account.Code) {
account.Code = account.Code[2:]
}
obj.Code = ethutil.Hex2Bytes(account.Code)
obj.Nonce = ethutil.Big(account.Nonce).Uint64()
return obj
}
type Env struct {
CurrentCoinbase string
CurrentDifficulty string
CurrentGasLimit string
CurrentNumber string
CurrentTimestamp interface{}
PreviousHash string
}
type VmTest struct {
Callcreates interface{}
//Env map[string]string
Env Env
Exec map[string]string
Transaction map[string]string
Gas string
Out string
Post map[string]Account
Pre map[string]Account
}
func RunVmTest(p string, t *testing.T) {
tests := make(map[string]VmTest)
helper.CreateFileTests(t, p, &tests)
for name, test := range tests {
state := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
state.SetStateObject(obj)
}
// XXX Yeah, yeah...
env := make(map[string]string)
env["currentCoinbase"] = test.Env.CurrentCoinbase
env["currentDifficulty"] = test.Env.CurrentDifficulty
env["currentGasLimit"] = test.Env.CurrentGasLimit
env["currentNumber"] = test.Env.CurrentNumber
env["previousHash"] = test.Env.PreviousHash
if n, ok := test.Env.CurrentTimestamp.(float64); ok {
env["currentTimestamp"] = strconv.Itoa(int(n))
} else {
env["currentTimestamp"] = test.Env.CurrentTimestamp.(string)
}
var (
ret []byte
gas *big.Int
err error
)
if len(test.Exec) > 0 {
ret, gas, err = helper.RunVm(state, env, test.Exec)
} else {
ret, gas, err = helper.RunState(state, env, test.Transaction)
}
// When an error is returned it doesn't always mean the tests fails.
// Have to come up with some conditional failing mechanism.
if err != nil {
helper.Log.Infoln(err)
}
rexp := helper.FromHex(test.Out)
if bytes.Compare(rexp, ret) != 0 {
t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
}
if len(test.Gas) > 0 {
gexp := ethutil.Big(test.Gas)
if gexp.Cmp(gas) != 0 {
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
}
}
for addr, account := range test.Post {
obj := state.GetStateObject(helper.FromHex(addr))
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
if bytes.Compare(v, vexp) != 0 {
t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
}
}
}
}
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
func TestVMArithmetic(t *testing.T) {
const fn = "../files/vmtests/vmArithmeticTest.json"
RunVmTest(fn, t)
}
func TestBitwiseLogicOperation(t *testing.T) {
const fn = "../files/vmtests/vmBitwiseLogicOperationTest.json"
RunVmTest(fn, t)
}
func TestBlockInfo(t *testing.T) {
const fn = "../files/vmtests/vmBlockInfoTest.json"
RunVmTest(fn, t)
}
func TestEnvironmentalInfo(t *testing.T) {
const fn = "../files/vmtests/vmEnvironmentalInfoTest.json"
RunVmTest(fn, t)
}
func TestFlowOperation(t *testing.T) {
const fn = "../files/vmtests/vmIOandFlowOperationsTest.json"
RunVmTest(fn, t)
}
func TestPushDupSwap(t *testing.T) {
const fn = "../files/vmtests/vmPushDupSwapTest.json"
RunVmTest(fn, t)
}
func TestVMSha3(t *testing.T) {
const fn = "../files/vmtests/vmSha3Test.json"
RunVmTest(fn, t)
}
func TestVm(t *testing.T) {
const fn = "../files/vmtests/vmtests.json"
RunVmTest(fn, t)
}
func TestStateSystemOperations(t *testing.T) {
const fn = "../files/StateTests/stSystemOperationsTest.json"
RunVmTest(fn, t)
}
func TestStatePreCompiledContracts(t *testing.T) {
const fn = "../files/StateTests/stPreCompiledContracts.json"
RunVmTest(fn, t)
}
func TestStateRecursiveCreate(t *testing.T) {
const fn = "../files/StateTests/stRecursiveCreate.json"
RunVmTest(fn, t)
}
func TestStateSpecialTest(t *testing.T) {
const fn = "../files/StateTests/stSpecialTest.json"
RunVmTest(fn, t)
}
>>>>>>> develop
...@@ -31,12 +31,16 @@ func sha256Func(in []byte) []byte { ...@@ -31,12 +31,16 @@ func sha256Func(in []byte) []byte {
} }
func ripemd160Func(in []byte) []byte { func ripemd160Func(in []byte) []byte {
return ethutil.RightPadBytes(crypto.Ripemd160(in), 32) return ethutil.LeftPadBytes(crypto.Ripemd160(in), 32)
} }
func ecrecoverFunc(in []byte) []byte { func ecrecoverFunc(in []byte) []byte {
// In case of an invalid sig. Defaults to return nil // In case of an invalid sig. Defaults to return nil
defer func() { recover() }() defer func() { recover() }()
return crypto.Ecrecover(in) hash := in[:32]
v := ethutil.BigD(in[32:64]).Bytes()[0] - 27
sig := append(in[64:], v)
return ethutil.LeftPadBytes(crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:])[12:], 32)
} }
...@@ -64,7 +64,7 @@ func (c *Closure) GetOp(x int) OpCode { ...@@ -64,7 +64,7 @@ func (c *Closure) GetOp(x int) OpCode {
} }
func (c *Closure) GetByte(x int) byte { func (c *Closure) GetByte(x int) byte {
if x < len(c.Code) { if x > -1 && x < len(c.Code) {
return c.Code[x] return c.Code[x]
} }
......
...@@ -69,6 +69,7 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte, ...@@ -69,6 +69,7 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte,
if self.Gas.Cmp(p.Gas) >= 0 { if self.Gas.Cmp(p.Gas) >= 0 {
ret = p.Call(self.input) ret = p.Call(self.input)
self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret) self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret)
self.vm.Endl()
} }
} else { } else {
// Create a new callable closure // Create a new callable closure
......
...@@ -163,7 +163,7 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) { ...@@ -163,7 +163,7 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
// Stack checks only // Stack checks only
case ISZERO, CALLDATALOAD, POP, JUMP, NOT: // 1 case ISZERO, CALLDATALOAD, POP, JUMP, NOT: // 1
require(1) require(1)
case ADD, SUB, DIV, SDIV, MOD, SMOD, EXP, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2 case ADD, SUB, DIV, SDIV, MOD, SMOD, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2
require(2) require(2)
case ADDMOD, MULMOD: // 3 case ADDMOD, MULMOD: // 3
require(3) require(3)
...@@ -181,6 +181,16 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) { ...@@ -181,6 +181,16 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
reqGs.Set(GasLog) reqGs.Set(GasLog)
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog)) addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
addStepGasUsage(new(big.Int).Add(mSize, mStart)) addStepGasUsage(new(big.Int).Add(mSize, mStart))
case EXP:
require(2)
exp := new(big.Int).Set(stack.data[stack.Len()-2])
nbytes := 0
for exp.Cmp(ethutil.Big0) > 0 {
nbytes += 1
exp.Rsh(exp, 8)
}
gas.Set(big.NewInt(int64(nbytes + 1)))
// Gas only // Gas only
case STOP: case STOP:
reqGas.Set(ethutil.Big0) reqGas.Set(ethutil.Big0)
...@@ -281,7 +291,6 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) { ...@@ -281,7 +291,6 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
addStepGasUsage(memGasUsage) addStepGasUsage(memGasUsage)
mem.Resize(newMemSize.Uint64())
} }
} }
...@@ -295,6 +304,8 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) { ...@@ -295,6 +304,8 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
return nil, new(big.Int), OOG(reqGas, gas) return nil, new(big.Int), OOG(reqGas, gas)
} }
mem.Resize(newMemSize.Uint64())
switch op { switch op {
// 0x20 range // 0x20 range
case ADD: case ADD:
......
...@@ -178,19 +178,25 @@ func (self *JSXEth) FromNumber(str string) string { ...@@ -178,19 +178,25 @@ func (self *JSXEth) FromNumber(str string) string {
return ethutil.BigD(ethutil.Hex2Bytes(str)).String() return ethutil.BigD(ethutil.Hex2Bytes(str)).String()
} }
func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
var hash []byte var (
var contractCreation bool to []byte
if len(toStr) == 0 { value = ethutil.NewValue(valueStr)
contractCreation = true gas = ethutil.NewValue(gasStr)
} else { gasPrice = ethutil.NewValue(gasPriceStr)
// Check if an address is stored by this address data []byte
addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes() )
if len(addr) > 0 {
hash = addr if ethutil.IsHex(codeStr) {
data = ethutil.Hex2Bytes(codeStr[2:])
} else { } else {
hash = ethutil.Hex2Bytes(toStr) data = ethutil.Hex2Bytes(codeStr)
} }
if ethutil.IsHex(toStr) {
to = ethutil.Hex2Bytes(toStr[2:])
} else {
to = ethutil.Hex2Bytes(toStr)
} }
var keyPair *crypto.KeyPair var keyPair *crypto.KeyPair
...@@ -202,15 +208,41 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr ...@@ -202,15 +208,41 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
} }
if err != nil { if err != nil {
return nil, err return "", err
} }
tx, err := self.XEth.Transact(keyPair, to, value, gas, gasPrice, data)
if err != nil {
return "", err
}
if chain.IsContractAddr(to) {
return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil
}
return ethutil.Bytes2Hex(tx.Hash()), nil
/*
var hash []byte
var contractCreation bool
if len(toStr) == 0 {
contractCreation = true
} else {
// Check if an address is stored by this address
addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes()
if len(addr) > 0 {
hash = addr
} else {
hash = ethutil.Hex2Bytes(toStr)
}
}
var ( var (
value = ethutil.Big(valueStr) value = ethutil.Big(valueStr)
gas = ethutil.Big(gasStr) gas = ethutil.Big(gasStr)
gasPrice = ethutil.Big(gasPriceStr) gasPrice = ethutil.Big(gasPriceStr)
data []byte data []byte
tx *types.Transaction tx *chain.Transaction
) )
if ethutil.IsHex(codeStr) { if ethutil.IsHex(codeStr) {
...@@ -220,9 +252,9 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr ...@@ -220,9 +252,9 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
} }
if contractCreation { if contractCreation {
tx = types.NewContractCreationTx(value, gas, gasPrice, data) tx = chain.NewContractCreationTx(value, gas, gasPrice, data)
} else { } else {
tx = types.NewTransactionMessage(hash, value, gas, gasPrice, data) tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data)
} }
acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address()) acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
...@@ -238,11 +270,16 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr ...@@ -238,11 +270,16 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
} }
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
*/
} }
func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
self.obj.TxPool().QueueTransaction(tx) err := self.obj.TxPool().Add(tx)
if err != nil {
return nil, err
}
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment