diff --git a/README.md b/README.md index 157601b398..a9b047c6bd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Ethereum [![Build Status](https://travis-ci.org/ethereum/go-ethereum.png?branch=master)](https://travis-ci.org/ethereum/go-ethereum) -Ethereum Go developer client (c) [0255c7881](https://github.com/ethereum/go-ethereum#copy) +Ethereum Go developer client (c) Jeffrey Wilcke A fair warning; Ethereum is not yet to be used in production. There's no test-net and you aren't mining real blocks (just one which is the genesis block). @@ -95,6 +95,3 @@ expect you to write tests for me so I don't have to test your code manually. (If you want to contribute by just writing tests that's fine too!) -### Copy - -69bce990a619e747b4f57483724b0e8a1732bb3b44ccf70b0dd6abd272af94550fc9d8b21232d33ebf30d38a148612f68e936094b4daeb9ea7174088a439070401 0255c78815d4f056f84c96de438ed9e38c69c0f8af24f5032248be5a79fe9071c3 diff --git a/config.go b/config.go new file mode 100644 index 0000000000..6b5b9b62f1 --- /dev/null +++ b/config.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" +) + +var StartConsole bool +var StartMining bool +var UseUPnP bool +var OutboundPort string +var ShowGenesis bool +var AddPeer string +var MaxPeer int +var GenAddr 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.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") + flag.StringVar(&OutboundPort, "p", "30303", "listening port") + flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers") + + flag.Parse() +} diff --git a/dev_console.go b/dev_console.go index 8ef7341b28..d2f3befb2b 100644 --- a/dev_console.go +++ b/dev_console.go @@ -149,7 +149,8 @@ func (i *Console) ParseInput(input string) bool { fmt.Println("recipient err:", err) } else { tx := ethchain.NewTransaction(recipient, ethutil.Big(tokens[2]), []string{""}) - tx.Sign([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) + privKey, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + tx.Sign(privKey) fmt.Printf("%x\n", tx.Hash()) i.ethereum.TxPool.QueueTransaction(tx) } diff --git a/ethereum.go b/ethereum.go index 659134ffd8..674f7d88c0 100644 --- a/ethereum.go +++ b/ethereum.go @@ -2,12 +2,11 @@ package main import ( "encoding/hex" - "flag" "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/ethchain-go" "github.com/ethereum/ethutil-go" - _ "github.com/ethereum/ethwire-go" + "github.com/obscuren/secp256k1-go" "log" "os" "os/signal" @@ -16,22 +15,6 @@ import ( 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 func RegisterInterupts(s *eth.Ethereum) { // 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() { runtime.GOMAXPROCS(runtime.NumCPU()) Init() @@ -57,10 +51,31 @@ func main() { // Instantiated a eth stack ethereum, err := eth.New(eth.CapDefault, UseUPnP) if err != nil { - log.Println(err) + log.Println("eth start err:", err) 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 { fmt.Println(ethereum.BlockManager.BlockChain().Genesis()) os.Exit(0) @@ -68,6 +83,9 @@ func main() { log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver) + // Set the max peers + ethereum.MaxPeers = MaxPeer + if StartConsole { err := os.Mkdir(ethutil.Config.ExecPath, os.ModePerm) // Error is OK if the error is ErrExist @@ -97,14 +115,16 @@ func main() { block := ethereum.BlockManager.BlockChain().NewBlock(addr, txs) // Apply all transactions to the block ethereum.BlockManager.ApplyTransactions(block, block.Transactions()) + + ethereum.BlockManager.AccumelateRewards(block, block) + // Search the nonce block.Nonce = pow.Search(block) err := ethereum.BlockManager.ProcessBlock(block) if err != nil { log.Println(err) } else { - //ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.RlpValue().Value}) - log.Println("\n+++++++ MINED BLK +++++++\n", block.String()) + log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockManager.BlockChain().CurrentBlock) } } }()