Skip to content

Commit ff769cd

Browse files
committed
chore(op): add uint64 converter to block-number
1 parent 45e63a1 commit ff769cd

File tree

1 file changed

+11
-0
lines changed
  • rolling-shutter/medley/encodeable/number

1 file changed

+11
-0
lines changed

rolling-shutter/medley/encodeable/number/block.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package number
22

33
import (
44
"bytes"
5+
"errors"
56
"math/big"
67
)
78

@@ -11,6 +12,8 @@ var (
1112
LatestStr = []byte("latest")
1213
)
1314

15+
var ErrLatestBlockToUint = errors.New("'latest' block can't be converted to uint64")
16+
1417
func BigToBlockNumber(i *big.Int) *BlockNumber {
1518
return &BlockNumber{
1619
Int: i,
@@ -46,6 +49,14 @@ func (k *BlockNumber) IsLatest() bool {
4649
return k.Equal(LatestBlock)
4750
}
4851

52+
func (k *BlockNumber) ToUInt64() (uint64, error) {
53+
p := k.ToUInt64Ptr()
54+
if p == nil {
55+
return 0, ErrLatestBlockToUint
56+
}
57+
return *p, nil
58+
}
59+
4960
func (k *BlockNumber) ToUInt64Ptr() *uint64 {
5061
if k.IsLatest() {
5162
return nil

0 commit comments

Comments
 (0)