File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,25 @@ func (bn BlockNumber) Int64() int64 {
119119 return (int64 )(bn )
120120}
121121
122+ func (e * EpochNumber ) UnmarshalJSON (data []byte ) error {
123+ input := trimData (data )
124+ if input == "latest" {
125+ * e = LatestEpochNumber
126+ return nil
127+ }
128+
129+ eNum , err := hexutil .DecodeUint64 (input )
130+ if err != nil {
131+ return err
132+ }
133+ if eNum > math .MaxInt64 {
134+ return fmt .Errorf ("EpochNumber too high" )
135+ }
136+
137+ * e = EpochNumber (eNum )
138+ return nil
139+ }
140+
122141func (e EpochNumber ) Int64 () int64 {
123142 return (int64 )(e )
124143}
@@ -217,3 +236,11 @@ func BlockNumberOrHashWithHash(hash common.Hash, canonical bool) BlockNumberOrHa
217236 RequireCanonical : canonical ,
218237 }
219238}
239+
240+ func trimData (data []byte ) string {
241+ input := strings .TrimSpace (string (data ))
242+ if len (input ) >= 2 && input [0 ] == '"' && input [len (input )- 1 ] == '"' {
243+ input = input [1 : len (input )- 1 ]
244+ }
245+ return input
246+ }
You can’t perform that action at this time.
0 commit comments