We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e334786 commit 5b65fb5Copy full SHA for 5b65fb5
types/types.go
@@ -5,6 +5,7 @@ import (
5
"fmt"
6
"math/big"
7
"strings"
8
+ "time"
9
)
10
11
type HexNumber big.Int
@@ -39,3 +40,20 @@ func (i *HexNumber) UnmarshalJSON(data []byte) error {
39
40
41
return nil
42
}
43
+
44
+var Zero = big.NewInt(0)
45
46
+// ToBig converts HexNumber to *big.Int.
47
+// if HexNumber is nil, it returns a pointer to Zero.
48
+func (i *HexNumber) ToBig() *big.Int {
49
+ if i == nil {
50
+ return Zero
51
+ }
52
53
+ return (*big.Int)(i)
54
+}
55
56
+// HexNumberToUnix converts HexNumber to time.Time by interpreting it as a Unix timestamp.
57
+func HexNumberToUnix(n *HexNumber) time.Time {
58
+ return time.Unix(n.ToBig().Int64(), 0)
59
0 commit comments