aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/block.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/types/block.go')
-rw-r--r--core/types/block.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/core/types/block.go b/core/types/block.go
index 23da3ea77..96df245b7 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -18,7 +18,9 @@
package types
import (
+ "database/sql/driver"
"encoding/binary"
+ "fmt"
"io"
"math/big"
"sort"
@@ -37,10 +39,15 @@ var (
EmptyUncleHash = CalcUncleHash(nil)
)
+const (
+ // Length of block nonce in bytes.
+ BlockNonceLength = 8
+)
+
// 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
+type BlockNonce [BlockNonceLength]byte
// EncodeNonce converts the given integer to a block nonce.
func EncodeNonce(i uint64) BlockNonce {
@@ -64,6 +71,24 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
}
+// Scan implements Scanner for database/sql.
+func (n *BlockNonce) Scan(src interface{}) error {
+ srcB, ok := src.([]byte)
+ if !ok {
+ return fmt.Errorf("can't scan %T into BlockNonce", src)
+ }
+ if len(srcB) != BlockNonceLength {
+ return fmt.Errorf("can't scan []byte of len %d into BlockNonce, want %d", len(srcB), BlockNonceLength)
+ }
+ copy(n[:], srcB)
+ return nil
+}
+
+// Value implements valuer for database/sql.
+func (n BlockNonce) Value() (driver.Value, error) {
+ return n[:], nil
+}
+
// WitnessData represents the witness data.
type WitnessData struct {
Root common.Hash