forked from cerc-io/plugeth
Changed transaction hash for poc 5
This commit is contained in:
parent
7d3e99a2ab
commit
2bd377a3de
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -214,7 +215,12 @@ func (block *Block) SetUncles(uncles []*Block) {
|
|||||||
func (block *Block) SetTransactions(txs []*Transaction) {
|
func (block *Block) SetTransactions(txs []*Transaction) {
|
||||||
block.transactions = txs
|
block.transactions = txs
|
||||||
|
|
||||||
block.TxSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpTxs()))
|
trie := ethutil.NewTrie(ethutil.Config.Db, "")
|
||||||
|
for i, tx := range txs {
|
||||||
|
trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
|
||||||
|
}
|
||||||
|
|
||||||
|
block.TxSha = trie.Root.([]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (block *Block) Value() *ethutil.Value {
|
func (block *Block) Value() *ethutil.Value {
|
||||||
@ -293,45 +299,10 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
|
|||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
func (block *Block) String() string {
|
|
||||||
//return fmt.Sprintf("Block(%x):\nPrevHash:%x\nUncleSha:%x\nCoinbase:%x\nRoot:%x\nTxSha:%x\nDiff:%v\nNonce:%x\nTxs:%d\n", block.Hash(), block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce, len(block.transactions))
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
Block(%x):
|
|
||||||
PrevHash: %x
|
|
||||||
UncleSha: %x
|
|
||||||
Coinbase: %x
|
|
||||||
Root: %x
|
|
||||||
TxSha: %x
|
|
||||||
Difficulty: %v
|
|
||||||
Number: %v
|
|
||||||
MinGas: %v
|
|
||||||
MaxLimit: %v
|
|
||||||
GasUsed: %v
|
|
||||||
Time: %v
|
|
||||||
Extra: %v
|
|
||||||
Nonce: %x
|
|
||||||
`,
|
|
||||||
block.Hash(),
|
|
||||||
block.PrevHash,
|
|
||||||
block.UncleSha,
|
|
||||||
block.Coinbase,
|
|
||||||
block.state.trie.Root,
|
|
||||||
block.TxSha,
|
|
||||||
block.Difficulty,
|
|
||||||
block.Number,
|
|
||||||
block.MinGasPrice,
|
|
||||||
block.GasLimit,
|
|
||||||
block.GasUsed,
|
|
||||||
block.Time,
|
|
||||||
block.Extra,
|
|
||||||
block.Nonce)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (block *Block) GetRoot() interface{} {
|
func (block *Block) GetRoot() interface{} {
|
||||||
return block.state.trie.Root
|
return block.state.trie.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////// UNEXPORTED /////////////////
|
|
||||||
func (block *Block) header() []interface{} {
|
func (block *Block) header() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
// Sha of the previous block
|
// Sha of the previous block
|
||||||
@ -362,3 +333,36 @@ func (block *Block) header() []interface{} {
|
|||||||
block.Nonce,
|
block.Nonce,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (block *Block) String() string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
BLOCK(%x):
|
||||||
|
PrevHash: %x
|
||||||
|
UncleSha: %x
|
||||||
|
Coinbase: %x
|
||||||
|
Root: %x
|
||||||
|
TxSha: %x
|
||||||
|
Difficulty: %v
|
||||||
|
Number: %v
|
||||||
|
MinGas: %v
|
||||||
|
MaxLimit: %v
|
||||||
|
GasUsed: %v
|
||||||
|
Time: %v
|
||||||
|
Extra: %v
|
||||||
|
Nonce: %x
|
||||||
|
`,
|
||||||
|
block.Hash(),
|
||||||
|
block.PrevHash,
|
||||||
|
block.UncleSha,
|
||||||
|
block.Coinbase,
|
||||||
|
block.state.trie.Root,
|
||||||
|
block.TxSha,
|
||||||
|
block.Difficulty,
|
||||||
|
block.Number,
|
||||||
|
block.MinGasPrice,
|
||||||
|
block.GasLimit,
|
||||||
|
block.GasUsed,
|
||||||
|
block.Time,
|
||||||
|
block.Extra,
|
||||||
|
block.Nonce)
|
||||||
|
}
|
||||||
|
@ -70,6 +70,22 @@ func (bc *BlockChain) NewBlock(coinbase []byte, txs []*Transaction) *Block {
|
|||||||
diff.Mul(diff, mul)
|
diff.Mul(diff, mul)
|
||||||
diff.Add(diff, bc.CurrentBlock.Difficulty)
|
diff.Add(diff, bc.CurrentBlock.Difficulty)
|
||||||
block.Difficulty = diff
|
block.Difficulty = diff
|
||||||
|
|
||||||
|
block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1)
|
||||||
|
|
||||||
|
// max(10000, (parent gas limit * (1024 - 1) + (parent gas used * 6 / 5)) / 1024)
|
||||||
|
base := new(big.Int)
|
||||||
|
base2 := new(big.Int)
|
||||||
|
parentGL := bc.CurrentBlock.GasLimit
|
||||||
|
parentUsed := bc.CurrentBlock.GasUsed
|
||||||
|
|
||||||
|
base.Mul(parentGL, big.NewInt(1024-1))
|
||||||
|
base2.Mul(parentUsed, big.NewInt(6))
|
||||||
|
base2.Div(base2, big.NewInt(5))
|
||||||
|
base.Add(base, base2)
|
||||||
|
base.Div(base, big.NewInt(1024))
|
||||||
|
|
||||||
|
block.GasLimit = ethutil.BigMax(big.NewInt(10000), base)
|
||||||
}
|
}
|
||||||
|
|
||||||
return block
|
return block
|
||||||
|
@ -22,9 +22,8 @@ var GenesisHeader = []interface{}{
|
|||||||
ZeroHash160,
|
ZeroHash160,
|
||||||
// Root state
|
// Root state
|
||||||
"",
|
"",
|
||||||
//EmptyShaList,
|
// tx sha
|
||||||
ZeroHash256,
|
ZeroHash256,
|
||||||
//ethutil.Sha3Bin(ethutil.Encode(ZeroHash256)),
|
|
||||||
// Difficulty
|
// Difficulty
|
||||||
ethutil.BigPow(2, 22),
|
ethutil.BigPow(2, 22),
|
||||||
// Number
|
// Number
|
||||||
|
Loading…
Reference in New Issue
Block a user