Commit f1ba1df1 authored by obscuren's avatar obscuren

Added key address and key generation

parent 827f341c
...@@ -3,7 +3,7 @@ Ethereum ...@@ -3,7 +3,7 @@ Ethereum
[![Build Status](https://travis-ci.org/ethereum/go-ethereum.png?branch=master)](https://travis-ci.org/ethereum/go-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 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). 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 ...@@ -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 manually. (If you want to contribute by just writing tests that's fine
too!) too!)
### Copy
69bce990a619e747b4f57483724b0e8a1732bb3b44ccf70b0dd6abd272af94550fc9d8b21232d33ebf30d38a148612f68e936094b4daeb9ea7174088a439070401 0255c78815d4f056f84c96de438ed9e38c69c0f8af24f5032248be5a79fe9071c3
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()
}
...@@ -149,7 +149,8 @@ func (i *Console) ParseInput(input string) bool { ...@@ -149,7 +149,8 @@ func (i *Console) ParseInput(input string) bool {
fmt.Println("recipient err:", err) fmt.Println("recipient err:", err)
} else { } else {
tx := ethchain.NewTransaction(recipient, ethutil.Big(tokens[2]), []string{""}) 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()) fmt.Printf("%x\n", tx.Hash())
i.ethereum.TxPool.QueueTransaction(tx) i.ethereum.TxPool.QueueTransaction(tx)
} }
......
...@@ -2,12 +2,11 @@ package main ...@@ -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 ( ...@@ -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) { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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())
} }
} }
}() }()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment