|
|
@ -29,6 +29,17 @@ var ( |
|
|
|
newTxs []*types.Transaction |
|
|
|
newTxs []*types.Transaction |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
|
|
tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) |
|
|
|
|
|
|
|
tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) |
|
|
|
|
|
|
|
tx3, _ := types.SignTx(types.NewTransaction(2, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) |
|
|
|
|
|
|
|
pendingTxs = append(pendingTxs, tx1) |
|
|
|
|
|
|
|
pendingTxs = append(pendingTxs, tx2) |
|
|
|
|
|
|
|
pendingTxs = append(pendingTxs, tx3) |
|
|
|
|
|
|
|
tx4, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) |
|
|
|
|
|
|
|
newTxs = append(newTxs, tx4) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type testWorkerBackend struct { |
|
|
|
type testWorkerBackend struct { |
|
|
|
db ethdb.Database |
|
|
|
db ethdb.Database |
|
|
|
txPool *core.TxPool |
|
|
|
txPool *core.TxPool |
|
|
@ -36,7 +47,6 @@ type testWorkerBackend struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
gspec = core.Genesis{ |
|
|
|
gspec = core.Genesis{ |
|
|
@ -49,7 +59,10 @@ func main() { |
|
|
|
|
|
|
|
|
|
|
|
chain, _ := core.NewBlockChain(database, nil, gspec.Config, consensus.NewFaker(), vm.Config{}, nil) |
|
|
|
chain, _ := core.NewBlockChain(database, nil, gspec.Config, consensus.NewFaker(), vm.Config{}, nil) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(chain) |
|
|
|
fmt.Println(testBankAddress) |
|
|
|
|
|
|
|
fmt.Println(testUserAddress) |
|
|
|
|
|
|
|
fmt.Println(genesis.Root()) |
|
|
|
|
|
|
|
|
|
|
|
txpool := core.NewTxPool(core.DefaultTxPoolConfig, chainConfig, chain) |
|
|
|
txpool := core.NewTxPool(core.DefaultTxPoolConfig, chainConfig, chain) |
|
|
|
|
|
|
|
|
|
|
|
backend := &testWorkerBackend{ |
|
|
|
backend := &testWorkerBackend{ |
|
|
@ -60,13 +73,21 @@ func main() { |
|
|
|
backend.txPool.AddLocals(pendingTxs) |
|
|
|
backend.txPool.AddLocals(pendingTxs) |
|
|
|
|
|
|
|
|
|
|
|
// Generate a small n-block chain and an uncle block for it
|
|
|
|
// Generate a small n-block chain and an uncle block for it
|
|
|
|
n := 10 |
|
|
|
n := 3 |
|
|
|
if n > 0 { |
|
|
|
if n > 0 { |
|
|
|
blocks, _ := core.GenerateChain(chainConfig, genesis, consensus.NewFaker(), database, n, func(i int, gen *core.BlockGen) { |
|
|
|
blocks, _ := core.GenerateChain(chainConfig, genesis, consensus.NewFaker(), database, n, func(i int, gen *core.BlockGen) { |
|
|
|
gen.SetCoinbase(testBankAddress) |
|
|
|
gen.SetCoinbase(testBankAddress) |
|
|
|
|
|
|
|
gen.AddTx(pendingTxs[i]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
if _, err := chain.InsertChain(blocks); err != nil { |
|
|
|
if _, err := chain.InsertChain(blocks); err != nil { |
|
|
|
fmt.Errorf("failed to insert origin chain: %v", err) |
|
|
|
fmt.Errorf("failed to insert origin chain: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println(blocks[0].NumberU64()) |
|
|
|
|
|
|
|
fmt.Println(chain.GetBlockByNumber(0).Root()) |
|
|
|
|
|
|
|
fmt.Println(chain.GetBlockByNumber(1).Root()) |
|
|
|
|
|
|
|
fmt.Println(blocks[1].Root()) |
|
|
|
|
|
|
|
fmt.Println(chain.GetBlockByNumber(2).Root()) |
|
|
|
|
|
|
|
fmt.Println(blocks[2].Root()) |
|
|
|
|
|
|
|
fmt.Println("Yeah") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|