From 57f95c1dc7f2e3412d7d78cfdab7074ce1dbbf09 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 4 Feb 2015 17:35:49 -0800 Subject: fixed test --- cmd/evm/main.go | 1 + eth/protocol_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cmd/evm/main.go b/cmd/evm/main.go index f819386fe..432cbd001 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -128,6 +128,7 @@ func (self *VMEnv) Difficulty() *big.Int { return ethutil.Big1 } func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) } +func (self *VMEnv) VmType() vm.Type { return vm.StdVmTy } func (self *VMEnv) Depth() int { return 0 } func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) GetHash(n uint64) []byte { diff --git a/eth/protocol_test.go b/eth/protocol_test.go index 224b59abd..1fe6d8f6b 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -80,6 +80,8 @@ func (self *testTxPool) AddTransactions(txs []*types.Transaction) { } } +func (self *testTxPool) GetTransactions() types.Transactions { return nil } + func (self *testChainManager) GetBlockHashesFromHash(hash []byte, amount uint64) (hashes [][]byte) { if self.getBlockHashes != nil { hashes = self.getBlockHashes(hash, amount) -- cgit v1.2.3 From a1b4547a53c4c738e435c1968c1e606935912e47 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 4 Feb 2015 18:26:23 -0800 Subject: set uncles regardless of empty uncle list. Fixes invalid blocks being mined --- miner/miner.go | 4 +--- pow/ezp/pow.go | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/miner/miner.go b/miner/miner.go index 52dd5687d..11d09d953 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -184,9 +184,7 @@ func (self *Miner) mine() { block.Header().Extra = self.Extra // Apply uncles - if len(self.uncles) > 0 { - block.SetUncles(self.uncles) - } + block.SetUncles(self.uncles) parent := chainMan.GetBlock(block.ParentHash()) coinbase := state.GetOrNewStateObject(block.Coinbase()) diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index 64d3230c9..2791c4b0b 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -1,6 +1,7 @@ package ezp import ( + "fmt" "math/big" "math/rand" "time" @@ -53,13 +54,13 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte { elapsed := time.Now().UnixNano() - start hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000 pow.HashRate = int64(hashes) - //powlogger.Infoln("Hashing @", pow.HashRate, "khash") t = time.Now() } sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) if verify(hash, diff, sha) { + fmt.Printf("HASH: %x\nDIFF %v\nSHA %x\n", hash, diff, sha) return sha } } @@ -83,7 +84,7 @@ func verify(hash []byte, diff *big.Int, nonce []byte) bool { sha.Write(d) verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff) - res := ethutil.U256(ethutil.BigD(sha.Sum(nil))) + res := ethutil.BigD(sha.Sum(nil)) return res.Cmp(verification) <= 0 } -- cgit v1.2.3 From db7c34a9df19d5a8a3a02a5e3d4cafcffa18dcb8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 4 Feb 2015 18:34:29 -0800 Subject: Default gas price and default gas for rpc --- cmd/mist/assets/examples/coin.html | 4 ++-- pow/ezp/pow.go | 2 -- rpc/args.go | 10 ---------- rpc/packages.go | 17 +++++++++++++---- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cmd/mist/assets/examples/coin.html b/cmd/mist/assets/examples/coin.html index a84a828af..ed5063a05 100644 --- a/cmd/mist/assets/examples/coin.html +++ b/cmd/mist/assets/examples/coin.html @@ -62,7 +62,7 @@ ], }]; - var address = "";//web3.db.get("jevcoin", "address"); + var address = web3.db.get("jevcoin", "address"); if( address.length == 0 ) { var code = "0x60056011565b60b88060356000396000f35b64e8d4a51000600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a68146028578063d0679d34146034578063e3d670d714604657005b602e60b3565b60006000f35b60406004356024356059565b60006000f35b604f6004356091565b8060005260206000f35b8060005281600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660206000a25050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156"; address = web3.eth.transact({ @@ -77,7 +77,7 @@ contract.Changed({to: "0xaa"}).changed(function(e) { console.log("e: " + JSON.stringify(e)); }); - contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( "0xaa", 10000 ); + contract.send( "0xaa", 10000 ); function reflesh() { document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase); diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go index 2791c4b0b..e4caa076a 100644 --- a/pow/ezp/pow.go +++ b/pow/ezp/pow.go @@ -1,7 +1,6 @@ package ezp import ( - "fmt" "math/big" "math/rand" "time" @@ -60,7 +59,6 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte { sha := crypto.Sha3(big.NewInt(r.Int63()).Bytes()) if verify(hash, diff, sha) { - fmt.Printf("HASH: %x\nDIFF %v\nSHA %x\n", hash, diff, sha) return sha } } diff --git a/rpc/args.go b/rpc/args.go index 34e706b98..84b076d4a 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -37,16 +37,6 @@ type NewTxArgs struct { Data string `json:"data"` } -func (a *NewTxArgs) requirements() error { - if a.Gas == "" { - return NewErrorResponse("Transact requires a 'gas' value as argument") - } - if a.GasPrice == "" { - return NewErrorResponse("Transact requires a 'gasprice' value as argument") - } - return nil -} - type PushTxArgs struct { Tx string `json:"tx"` } diff --git a/rpc/packages.go b/rpc/packages.go index a98d99d6c..047bbda9a 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -40,6 +40,11 @@ import ( "github.com/ethereum/go-ethereum/xeth" ) +const ( + defaultGasPrice = "10000000000000" + defaultGas = "10000" +) + type EthereumApi struct { xeth *xeth.XEth filterManager *filter.FilterManager @@ -116,10 +121,14 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error { } func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error { - err := args.requirements() - if err != nil { - return err + if len(args.Gas) == 0 { + args.Gas = defaultGas + } + + if len(args.GasPrice) == 0 { + args.GasPrice = defaultGasPrice } + result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data) *reply = result return nil @@ -387,7 +396,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } return p.FilterChanged(args, reply) case "eth_gasPrice": - *reply = "10000000000000" + *reply = defaultGasPrice return nil case "web3_sha3": args, err := req.ToSha3Args() -- cgit v1.2.3