forked from cerc-io/plugeth
Dev test mining
This commit is contained in:
parent
c636f8e3e6
commit
97882a65bb
@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/ethereum/ethchain-go"
|
"github.com/ethereum/ethchain-go"
|
||||||
"github.com/ethereum/ethdb-go"
|
"github.com/ethereum/ethdb-go"
|
||||||
"github.com/ethereum/ethutil-go"
|
"github.com/ethereum/ethutil-go"
|
||||||
"github.com/ethereum/ethwire-go"
|
_ "github.com/ethereum/ethwire-go"
|
||||||
"math/big"
|
_ "math/big"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -48,6 +48,9 @@ func (i *Console) ValidateInput(action string, argumentLength int) error {
|
|||||||
case action == "encode" && argumentLength != 1:
|
case action == "encode" && argumentLength != 1:
|
||||||
err = true
|
err = true
|
||||||
expArgCount = 1
|
expArgCount = 1
|
||||||
|
case action == "gettx" && argumentLength != 1:
|
||||||
|
err = true
|
||||||
|
expArgCount = 1
|
||||||
case action == "tx" && argumentLength != 2:
|
case action == "tx" && argumentLength != 2:
|
||||||
err = true
|
err = true
|
||||||
expArgCount = 2
|
expArgCount = 2
|
||||||
@ -125,28 +128,39 @@ func (i *Console) ParseInput(input string) bool {
|
|||||||
}
|
}
|
||||||
case "encode":
|
case "encode":
|
||||||
fmt.Printf("%q\n", ethutil.Encode(tokens[1]))
|
fmt.Printf("%q\n", ethutil.Encode(tokens[1]))
|
||||||
case "newblk":
|
/*
|
||||||
block := ethchain.CreateBlock(
|
case "newblk":
|
||||||
i.ethereum.BlockManager.BlockChain().LastBlock.State().Root,
|
block := ethchain.CreateBlock(
|
||||||
i.ethereum.BlockManager.LastBlockHash,
|
i.ethereum.BlockManager.BlockChain().LastBlock.State().Root,
|
||||||
"123",
|
i.ethereum.BlockManager.LastBlockHash,
|
||||||
big.NewInt(1),
|
"123",
|
||||||
big.NewInt(1),
|
big.NewInt(1),
|
||||||
"",
|
big.NewInt(1),
|
||||||
i.ethereum.TxPool.Flush(),
|
"",
|
||||||
)
|
i.ethereum.TxPool.Flush(),
|
||||||
i.ethereum.Broadcast(ethwire.MsgBlockTy, block.RlpData())
|
)
|
||||||
//fmt.Println(ethutil.NewRlpValue(block.RlpData()).Get(0))
|
err := i.ethereum.BlockManager.ProcessBlock(block)
|
||||||
//err := i.ethereum.BlockManager.ProcessBlock(block)
|
if err != nil {
|
||||||
//if err != nil {
|
fmt.Println(err)
|
||||||
// fmt.Println(err)
|
} else {
|
||||||
//} else {
|
i.ethereum.Broadcast(ethwire.MsgBlockTy, block.RlpData())
|
||||||
|
}
|
||||||
// }
|
//fmt.Println(ethutil.NewRlpValue(block.RlpData()).Get(0))
|
||||||
|
*/
|
||||||
case "tx":
|
case "tx":
|
||||||
tx := ethchain.NewTransaction(tokens[1], ethutil.Big(tokens[2]), []string{""})
|
tx := ethchain.NewTransaction(tokens[1], ethutil.Big(tokens[2]), []string{""})
|
||||||
|
fmt.Printf("tx: %x\n", tx.Hash())
|
||||||
|
|
||||||
i.ethereum.TxPool.QueueTransaction(tx)
|
i.ethereum.TxPool.QueueTransaction(tx)
|
||||||
|
case "gettx":
|
||||||
|
addr, _ := hex.DecodeString(tokens[1])
|
||||||
|
data, _ := ethutil.Config.Db.Get(addr)
|
||||||
|
if len(data) != 0 {
|
||||||
|
decoder := ethutil.NewRlpDecoder(data)
|
||||||
|
fmt.Println(decoder)
|
||||||
|
} else {
|
||||||
|
fmt.Println("gettx: tx not found")
|
||||||
|
}
|
||||||
case "exit", "quit", "q":
|
case "exit", "quit", "q":
|
||||||
return false
|
return false
|
||||||
case "help":
|
case "help":
|
||||||
|
30
ethereum.go
30
ethereum.go
@ -6,11 +6,14 @@ import (
|
|||||||
"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"
|
||||||
"log"
|
"log"
|
||||||
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Debug = true
|
const Debug = true
|
||||||
@ -78,21 +81,32 @@ func main() {
|
|||||||
|
|
||||||
RegisterInterupts(ethereum)
|
RegisterInterupts(ethereum)
|
||||||
|
|
||||||
if StartMining {
|
ethereum.Start()
|
||||||
log.Println("Mining started")
|
|
||||||
dagger := ðchain.Dagger{}
|
|
||||||
|
|
||||||
|
if StartMining {
|
||||||
|
log.Println("Dev Test Mining started")
|
||||||
|
|
||||||
|
// Fake block mining. It broadcasts a new block every 5 seconds
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 36))
|
time.Sleep(5 * time.Second)
|
||||||
log.Println("Res dagger", res)
|
|
||||||
//ethereum.Broadcast("blockmine", ethutil.Encode(res.String()))
|
block := ethchain.CreateBlock(
|
||||||
|
ethereum.BlockManager.BlockChain().LastBlock.State().Root,
|
||||||
|
ethereum.BlockManager.LastBlockHash,
|
||||||
|
"123",
|
||||||
|
big.NewInt(1),
|
||||||
|
big.NewInt(1),
|
||||||
|
"",
|
||||||
|
ethereum.TxPool.Flush())
|
||||||
|
|
||||||
|
ethereum.BlockManager.ProcessBlockWithState(block, block.State())
|
||||||
|
ethereum.Broadcast(ethwire.MsgBlockTy, block.RlpData())
|
||||||
|
log.Println("\n", block.String())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
ethereum.Start()
|
|
||||||
|
|
||||||
// Wait for shutdown
|
// Wait for shutdown
|
||||||
ethereum.WaitForShutdown()
|
ethereum.WaitForShutdown()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user