forked from cerc-io/plugeth
Merge branch 'develop' into miner
This commit is contained in:
commit
ac69538707
@ -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) BlockHash() []byte { return make([]byte, 32) }
|
||||||
func (self *VMEnv) Value() *big.Int { return self.value }
|
func (self *VMEnv) Value() *big.Int { return self.value }
|
||||||
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
|
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) Depth() int { return 0 }
|
||||||
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
||||||
func (self *VMEnv) GetHash(n uint64) []byte {
|
func (self *VMEnv) GetHash(n uint64) []byte {
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
],
|
],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var address = "";//web3.db.get("jevcoin", "address");
|
var address = web3.db.get("jevcoin", "address");
|
||||||
if( address.length == 0 ) {
|
if( address.length == 0 ) {
|
||||||
var code = "0x60056011565b60b88060356000396000f35b64e8d4a51000600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a68146028578063d0679d34146034578063e3d670d714604657005b602e60b3565b60006000f35b60406004356024356059565b60006000f35b604f6004356091565b8060005260206000f35b8060005281600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660206000a25050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156";
|
var code = "0x60056011565b60b88060356000396000f35b64e8d4a51000600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a68146028578063d0679d34146034578063e3d670d714604657005b602e60b3565b60006000f35b60406004356024356059565b60006000f35b604f6004356091565b8060005260206000f35b8060005281600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660206000a25050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156";
|
||||||
address = web3.eth.transact({
|
address = web3.eth.transact({
|
||||||
@ -77,7 +77,7 @@
|
|||||||
contract.Changed({to: "0xaa"}).changed(function(e) {
|
contract.Changed({to: "0xaa"}).changed(function(e) {
|
||||||
console.log("e: " + JSON.stringify(e));
|
console.log("e: " + JSON.stringify(e));
|
||||||
});
|
});
|
||||||
contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( "0xaa", 10000 );
|
contract.send( "0xaa", 10000 );
|
||||||
function reflesh() {
|
function reflesh() {
|
||||||
document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase);
|
document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase);
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/c-ethash/go-ethash"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
@ -14,7 +15,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"github.com/ethereum/go-ethereum/pow/ezp"
|
_ "github.com/ethereum/go-ethereum/pow/ezp"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"gopkg.in/fatih/set.v0"
|
"gopkg.in/fatih/set.v0"
|
||||||
)
|
)
|
||||||
@ -62,7 +63,7 @@ func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainM
|
|||||||
sm := &BlockProcessor{
|
sm := &BlockProcessor{
|
||||||
db: db,
|
db: db,
|
||||||
mem: make(map[string]*big.Int),
|
mem: make(map[string]*big.Int),
|
||||||
Pow: ezp.New(),
|
Pow: ðash.Ethash{},
|
||||||
bc: chainManager,
|
bc: chainManager,
|
||||||
eventMux: eventMux,
|
eventMux: eventMux,
|
||||||
txpool: txpool,
|
txpool: txpool,
|
||||||
|
@ -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) {
|
func (self *testChainManager) GetBlockHashesFromHash(hash []byte, amount uint64) (hashes [][]byte) {
|
||||||
if self.getBlockHashes != nil {
|
if self.getBlockHashes != nil {
|
||||||
hashes = self.getBlockHashes(hash, amount)
|
hashes = self.getBlockHashes(hash, amount)
|
||||||
|
@ -205,9 +205,7 @@ func (self *Miner) mine() {
|
|||||||
block.Header().Extra = self.Extra
|
block.Header().Extra = self.Extra
|
||||||
|
|
||||||
// Apply uncles
|
// Apply uncles
|
||||||
if len(self.uncles) > 0 {
|
block.SetUncles(self.uncles)
|
||||||
block.SetUncles(self.uncles)
|
|
||||||
}
|
|
||||||
|
|
||||||
parent := chainMan.GetBlock(block.ParentHash())
|
parent := chainMan.GetBlock(block.ParentHash())
|
||||||
coinbase := state.GetOrNewStateObject(block.Coinbase())
|
coinbase := state.GetOrNewStateObject(block.Coinbase())
|
||||||
@ -234,10 +232,10 @@ func (self *Miner) mine() {
|
|||||||
|
|
||||||
minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions))
|
minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions))
|
||||||
|
|
||||||
x, y := getSeed(chainMan, block)
|
x, _ := getSeed(chainMan, block)
|
||||||
self.pow, err = ethash.New(append(x, y...), block)
|
self.pow, err = ethash.New(x, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("err", err)
|
fmt.Println("miner gave back err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,4 +6,5 @@ type Block interface {
|
|||||||
Difficulty() *big.Int
|
Difficulty() *big.Int
|
||||||
HashNoNonce() []byte
|
HashNoNonce() []byte
|
||||||
N() []byte
|
N() []byte
|
||||||
|
Number() *big.Int
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) []byte {
|
|||||||
elapsed := time.Now().UnixNano() - start
|
elapsed := time.Now().UnixNano() - start
|
||||||
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
|
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
|
||||||
pow.HashRate = int64(hashes)
|
pow.HashRate = int64(hashes)
|
||||||
//powlogger.Infoln("Hashing @", pow.HashRate, "khash")
|
|
||||||
|
|
||||||
t = time.Now()
|
t = time.Now()
|
||||||
}
|
}
|
||||||
@ -83,7 +82,7 @@ func verify(hash []byte, diff *big.Int, nonce []byte) bool {
|
|||||||
sha.Write(d)
|
sha.Write(d)
|
||||||
|
|
||||||
verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff)
|
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
|
return res.Cmp(verification) <= 0
|
||||||
}
|
}
|
||||||
|
10
rpc/args.go
10
rpc/args.go
@ -37,16 +37,6 @@ type NewTxArgs struct {
|
|||||||
Data string `json:"data"`
|
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 {
|
type PushTxArgs struct {
|
||||||
Tx string `json:"tx"`
|
Tx string `json:"tx"`
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,11 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultGasPrice = "10000000000000"
|
||||||
|
defaultGas = "10000"
|
||||||
|
)
|
||||||
|
|
||||||
type EthereumApi struct {
|
type EthereumApi struct {
|
||||||
xeth *xeth.XEth
|
xeth *xeth.XEth
|
||||||
filterManager *filter.FilterManager
|
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 {
|
func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
|
||||||
err := args.requirements()
|
if len(args.Gas) == 0 {
|
||||||
if err != nil {
|
args.Gas = defaultGas
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
|
||||||
*reply = result
|
*reply = result
|
||||||
return nil
|
return nil
|
||||||
@ -387,7 +396,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
}
|
}
|
||||||
return p.FilterChanged(args, reply)
|
return p.FilterChanged(args, reply)
|
||||||
case "eth_gasPrice":
|
case "eth_gasPrice":
|
||||||
*reply = "10000000000000"
|
*reply = defaultGasPrice
|
||||||
return nil
|
return nil
|
||||||
case "web3_sha3":
|
case "web3_sha3":
|
||||||
args, err := req.ToSha3Args()
|
args, err := req.ToSha3Args()
|
||||||
|
Loading…
Reference in New Issue
Block a user