wip
This commit is contained in:
		@@ -93,18 +93,18 @@
 | 
				
			|||||||
	function transact() {
 | 
						function transact() {
 | 
				
			||||||
		var to = document.querySelector("#address").value;
 | 
							var to = document.querySelector("#address").value;
 | 
				
			||||||
        if( to.length == 0 ) {
 | 
					        if( to.length == 0 ) {
 | 
				
			||||||
		    to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3";
 | 
					            to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3";
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            to = "0x"+to;
 | 
					            to = "0x"+to;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
		var value = parseInt( document.querySelector("#amount").value );
 | 
					        var value = parseInt( document.querySelector("#amount").value );
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
		contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( to, value );
 | 
					        contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( to, value );
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
	reflesh();
 | 
					    reflesh();
 | 
				
			||||||
</script>
 | 
					        </script>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,75 +1,75 @@
 | 
				
			|||||||
<!doctype>
 | 
					<!doctype>
 | 
				
			||||||
<html>
 | 
					<html>
 | 
				
			||||||
<head>
 | 
					    <head>
 | 
				
			||||||
<title>Ethereum</title>
 | 
					        <title>Ethereum</title>
 | 
				
			||||||
<script type="text/javascript" src="../ext/bignumber.min.js"></script>
 | 
					        <script type="text/javascript" src="../ext/bignumber.min.js"></script>
 | 
				
			||||||
<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script>
 | 
					        <script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script>
 | 
				
			||||||
<style type="text/css">
 | 
					        <style type="text/css">
 | 
				
			||||||
    body {
 | 
					            body {
 | 
				
			||||||
        font-family: Helvetica;
 | 
					                font-family: Helvetica;
 | 
				
			||||||
    }
 | 
					            }
 | 
				
			||||||
    div.logo {
 | 
					        div.logo {
 | 
				
			||||||
        width: 192px;
 | 
					            width: 192px;
 | 
				
			||||||
        margin: 40px auto;
 | 
					            margin: 40px auto;
 | 
				
			||||||
    }
 | 
					        }
 | 
				
			||||||
</style>
 | 
					        </style>
 | 
				
			||||||
</head>
 | 
					    </head>
 | 
				
			||||||
<body>
 | 
					    <body>
 | 
				
			||||||
    <div class="logo"><img src="logo.png"></img></div>
 | 
					        <div class="logo"><img src="logo.png"></img></div>
 | 
				
			||||||
    <h1>Info</h1>
 | 
					        <h1>Info</h1>
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
	<table width="100%">
 | 
					        <table width="100%">
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Block number</td>
 | 
					                <td>Block number</td>
 | 
				
			||||||
			<td id="number"></td>
 | 
					                <td id="number"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Peer count</td>
 | 
					                <td>Peer count</td>
 | 
				
			||||||
			<td id="peer_count"></td>
 | 
					                <td id="peer_count"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Accounts</td>
 | 
					                <td>Accounts</td>
 | 
				
			||||||
			<td id="accounts"></td>
 | 
					                <td id="accounts"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Gas price</td>
 | 
					                <td>Gas price</td>
 | 
				
			||||||
			<td id="gas_price"></td>
 | 
					                <td id="gas_price"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Mining</td>
 | 
					                <td>Mining</td>
 | 
				
			||||||
			<td id="mining"></td>
 | 
					                <td id="mining"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Listening</td>
 | 
					                <td>Listening</td>
 | 
				
			||||||
			<td id="listening"></td>
 | 
					                <td id="listening"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
		<tr>
 | 
					            <tr>
 | 
				
			||||||
			<td>Coinbase</td>
 | 
					                <td>Coinbase</td>
 | 
				
			||||||
			<td id="coinbase"></td>
 | 
					                <td id="coinbase"></td>
 | 
				
			||||||
		</tr>
 | 
					            </tr>
 | 
				
			||||||
	</table>
 | 
					        </table>
 | 
				
			||||||
</body>
 | 
					    </body>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
<script type="text/javascript">
 | 
					    <script type="text/javascript">
 | 
				
			||||||
    var web3 = require('web3');
 | 
					        var web3 = require('web3');
 | 
				
			||||||
    var eth = web3.eth;
 | 
					        var eth = web3.eth;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
 | 
					        web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    document.querySelector("#number").innerHTML = eth.number;
 | 
					        document.querySelector("#number").innerHTML = eth.number;
 | 
				
			||||||
    document.querySelector("#coinbase").innerHTML = eth.coinbase
 | 
					        document.querySelector("#coinbase").innerHTML = eth.coinbase
 | 
				
			||||||
    document.querySelector("#peer_count").innerHTML = eth.peerCount;
 | 
					        document.querySelector("#peer_count").innerHTML = eth.peerCount;
 | 
				
			||||||
    document.querySelector("#accounts").innerHTML = eth.accounts;
 | 
					        document.querySelector("#accounts").innerHTML = eth.accounts;
 | 
				
			||||||
    document.querySelector("#gas_price").innerHTML = eth.gasPrice;
 | 
					        document.querySelector("#gas_price").innerHTML = eth.gasPrice;
 | 
				
			||||||
    document.querySelector("#mining").innerHTML = eth.mining;
 | 
					        document.querySelector("#mining").innerHTML = eth.mining;
 | 
				
			||||||
    document.querySelector("#listening").innerHTML = eth.listening;
 | 
					        document.querySelector("#listening").innerHTML = eth.listening;
 | 
				
			||||||
</script>
 | 
					        </script>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,21 +24,43 @@
 | 
				
			|||||||
package miner
 | 
					package miner
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"math/big"
 | 
						"math/big"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/eth"
 | 
						"github.com/ethereum/c-ethash/go-ethash"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/ethutil"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/pow"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/pow/ezp"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/state"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core"
 | 
						"github.com/ethereum/go-ethereum/core"
 | 
				
			||||||
	"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/eth"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/ethutil"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/event"
 | 
						"github.com/ethereum/go-ethereum/event"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/logger"
 | 
						"github.com/ethereum/go-ethereum/logger"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/pow"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/state"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var dx = []byte{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}
 | 
				
			||||||
 | 
					var dy = []byte{0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const epochLen = uint64(1000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getSeed(chainMan *core.ChainManager, block *types.Block) (x []byte, y []byte) {
 | 
				
			||||||
 | 
						if block.Number().Uint64() == 0 {
 | 
				
			||||||
 | 
							return dx, dy
 | 
				
			||||||
 | 
						} else if block.Number().Uint64()%epochLen == 0 {
 | 
				
			||||||
 | 
							x, y = getSeed(chainMan, chainMan.GetBlock(block.ParentHash()))
 | 
				
			||||||
 | 
							if (block.Number().Uint64()/epochLen)%2 > 0 {
 | 
				
			||||||
 | 
								y = crypto.Sha3(append(y, block.ParentHash()...))
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								x = crypto.Sha3(append(x, block.ParentHash()...))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return x, y
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return getSeed(chainMan, chainMan.GetBlock(block.ParentHash()))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type LocalTx struct {
 | 
					type LocalTx struct {
 | 
				
			||||||
	To       []byte `json:"to"`
 | 
						To       []byte `json:"to"`
 | 
				
			||||||
	Data     []byte `json:"data"`
 | 
						Data     []byte `json:"data"`
 | 
				
			||||||
@@ -77,7 +99,6 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner {
 | 
				
			|||||||
	return &Miner{
 | 
						return &Miner{
 | 
				
			||||||
		eth:                 eth,
 | 
							eth:                 eth,
 | 
				
			||||||
		powQuitCh:           make(chan struct{}),
 | 
							powQuitCh:           make(chan struct{}),
 | 
				
			||||||
		pow:                 ezp.New(),
 | 
					 | 
				
			||||||
		mining:              false,
 | 
							mining:              false,
 | 
				
			||||||
		localTxs:            make(map[int]*LocalTx),
 | 
							localTxs:            make(map[int]*LocalTx),
 | 
				
			||||||
		MinAcceptedGasPrice: big.NewInt(10000000000000),
 | 
							MinAcceptedGasPrice: big.NewInt(10000000000000),
 | 
				
			||||||
@@ -213,6 +234,13 @@ 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)
 | 
				
			||||||
 | 
						self.pow, err = ethash.New(append(x, y...), block)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("err", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Find a valid nonce
 | 
						// Find a valid nonce
 | 
				
			||||||
	nonce := self.pow.Search(block, self.powQuitCh)
 | 
						nonce := self.pow.Search(block, self.powQuitCh)
 | 
				
			||||||
	if nonce != nil {
 | 
						if nonce != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user