|
|
@ -2,12 +2,11 @@ package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/hex" |
|
|
|
"encoding/hex" |
|
|
|
"flag" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"github.com/ethereum/eth-go" |
|
|
|
"github.com/ethereum/eth-go" |
|
|
|
"github.com/ethereum/ethchain-go" |
|
|
|
"github.com/ethereum/ethchain-go" |
|
|
|
"github.com/ethereum/ethutil-go" |
|
|
|
"github.com/ethereum/ethutil-go" |
|
|
|
_ "github.com/ethereum/ethwire-go" |
|
|
|
"github.com/obscuren/secp256k1-go" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/signal" |
|
|
|
"os/signal" |
|
|
@ -16,22 +15,6 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
const Debug = true |
|
|
|
const Debug = true |
|
|
|
|
|
|
|
|
|
|
|
var StartConsole bool |
|
|
|
|
|
|
|
var StartMining bool |
|
|
|
|
|
|
|
var UseUPnP bool |
|
|
|
|
|
|
|
var OutboundPort string |
|
|
|
|
|
|
|
var ShowGenesis bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Init() { |
|
|
|
|
|
|
|
flag.BoolVar(&StartConsole, "c", false, "debug and testing console") |
|
|
|
|
|
|
|
flag.BoolVar(&StartMining, "m", false, "start dagger mining") |
|
|
|
|
|
|
|
flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits") |
|
|
|
|
|
|
|
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") |
|
|
|
|
|
|
|
flag.StringVar(&OutboundPort, "port", "30303", "listening port") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register interrupt handlers so we can stop the ethereum
|
|
|
|
// Register interrupt handlers so we can stop the ethereum
|
|
|
|
func RegisterInterupts(s *eth.Ethereum) { |
|
|
|
func RegisterInterupts(s *eth.Ethereum) { |
|
|
|
// Buffered chan of one is enough
|
|
|
|
// Buffered chan of one is enough
|
|
|
@ -47,6 +30,17 @@ func RegisterInterupts(s *eth.Ethereum) { |
|
|
|
}() |
|
|
|
}() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func CreateKeyPair(force bool) { |
|
|
|
|
|
|
|
data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) |
|
|
|
|
|
|
|
if len(data) == 0 || force { |
|
|
|
|
|
|
|
log.Println("Generating new address and keypair") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub, prv := secp256k1.GenerateKeyPair() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ethutil.Config.Db.Put([]byte("KeyRing"), prv) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU()) |
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU()) |
|
|
|
Init() |
|
|
|
Init() |
|
|
@ -57,10 +51,31 @@ func main() { |
|
|
|
// Instantiated a eth stack
|
|
|
|
// Instantiated a eth stack
|
|
|
|
ethereum, err := eth.New(eth.CapDefault, UseUPnP) |
|
|
|
ethereum, err := eth.New(eth.CapDefault, UseUPnP) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
log.Println("eth start err:", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if GenAddr { |
|
|
|
|
|
|
|
fmt.Println("This action overwrites your old private key. Are you sure? (y/n)") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var r string |
|
|
|
|
|
|
|
fmt.Scanln(&r) |
|
|
|
|
|
|
|
for ; ; fmt.Scanln(&r) { |
|
|
|
|
|
|
|
if r == "n" || r == "y" { |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt.Println("Yes or no?", r) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if r == "y" { |
|
|
|
|
|
|
|
CreateKeyPair(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
CreateKeyPair(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ShowGenesis { |
|
|
|
if ShowGenesis { |
|
|
|
fmt.Println(ethereum.BlockManager.BlockChain().Genesis()) |
|
|
|
fmt.Println(ethereum.BlockManager.BlockChain().Genesis()) |
|
|
|
os.Exit(0) |
|
|
|
os.Exit(0) |
|
|
@ -68,6 +83,9 @@ func main() { |
|
|
|
|
|
|
|
|
|
|
|
log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver) |
|
|
|
log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the max peers
|
|
|
|
|
|
|
|
ethereum.MaxPeers = MaxPeer |
|
|
|
|
|
|
|
|
|
|
|
if StartConsole { |
|
|
|
if StartConsole { |
|
|
|
err := os.Mkdir(ethutil.Config.ExecPath, os.ModePerm) |
|
|
|
err := os.Mkdir(ethutil.Config.ExecPath, os.ModePerm) |
|
|
|
// Error is OK if the error is ErrExist
|
|
|
|
// Error is OK if the error is ErrExist
|
|
|
@ -97,14 +115,16 @@ func main() { |
|
|
|
block := ethereum.BlockManager.BlockChain().NewBlock(addr, txs) |
|
|
|
block := ethereum.BlockManager.BlockChain().NewBlock(addr, txs) |
|
|
|
// Apply all transactions to the block
|
|
|
|
// Apply all transactions to the block
|
|
|
|
ethereum.BlockManager.ApplyTransactions(block, block.Transactions()) |
|
|
|
ethereum.BlockManager.ApplyTransactions(block, block.Transactions()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ethereum.BlockManager.AccumelateRewards(block, block) |
|
|
|
|
|
|
|
|
|
|
|
// Search the nonce
|
|
|
|
// Search the nonce
|
|
|
|
block.Nonce = pow.Search(block) |
|
|
|
block.Nonce = pow.Search(block) |
|
|
|
err := ethereum.BlockManager.ProcessBlock(block) |
|
|
|
err := ethereum.BlockManager.ProcessBlock(block) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
log.Println(err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.RlpValue().Value})
|
|
|
|
log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockManager.BlockChain().CurrentBlock) |
|
|
|
log.Println("\n+++++++ MINED BLK +++++++\n", block.String()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|