Skip to content

Commit

Permalink
merge BlockNonce (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiD authored Mar 30, 2021
1 parent 52672a9 commit 3e50c81
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions x/evm/watcher/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package watcher

import (
"encoding/binary"
"encoding/json"
"math/big"
"strconv"
Expand Down Expand Up @@ -157,11 +158,38 @@ type MsgBlock struct {
block string
}

// A BlockNonce is a 64-bit hash which proves (combined with the
// mix-hash) that a sufficient amount of computation has been carried
// out on a block.
type BlockNonce [8]byte

// EncodeNonce converts the given integer to a block nonce.
func EncodeNonce(i uint64) BlockNonce {
var n BlockNonce
binary.BigEndian.PutUint64(n[:], i)
return n
}

// Uint64 returns the integer value of a block nonce.
func (n BlockNonce) Uint64() uint64 {
return binary.BigEndian.Uint64(n[:])
}

// MarshalText encodes n as a hex string with 0x prefix.
func (n BlockNonce) MarshalText() ([]byte, error) {
return hexutil.Bytes(n[:]).MarshalText()
}

// UnmarshalText implements encoding.TextUnmarshaler.
func (n *BlockNonce) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
}

type EthBlock struct {
Number hexutil.Uint64 `json:"number"`
Hash common.Hash `json:"hash"`
ParentHash common.Hash `json:"parentHash"`
Nonce uint64 `json:"nonce"`
Nonce BlockNonce `json:"nonce"`
Sha3Uncles common.Hash `json:"sha3Uncles"`
LogsBloom ethtypes.Bloom `json:"logsBloom"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
Expand All @@ -185,7 +213,7 @@ func NewMsgBlock(height uint64, blockBloom ethtypes.Bloom, blockHash common.Hash
Number: hexutil.Uint64(height),
Hash: blockHash,
ParentHash: common.BytesToHash(header.LastBlockId.Hash),
Nonce: 0,
Nonce: BlockNonce{},
Sha3Uncles: common.Hash{},
LogsBloom: blockBloom,
TransactionsRoot: common.BytesToHash(header.DataHash),
Expand Down

0 comments on commit 3e50c81

Please sign in to comment.