Skip to content

Commit d998cfb

Browse files
Fix: tezgen type INt unmarshalling
1 parent f7f28dd commit d998cfb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/tezgen/types.go

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

33
import (
44
"encoding/hex"
5-
"errors"
65
"math/big"
76
"strconv"
87
"time"
@@ -120,15 +119,20 @@ func NewInt(val int64) Int {
120119
// UnmarshalJSON -
121120
func (i *Int) UnmarshalJSON(data []byte) error {
122121
if i.Int == nil {
123-
return errors.New("nil Int value")
122+
i.Int = big.NewInt(0)
123+
}
124+
if len(data) > 2 {
125+
if data[0] == '"' && data[len(data)-1] == '"' {
126+
data = data[1 : len(data)-1]
127+
}
124128
}
125129
return i.Int.UnmarshalJSON(data)
126130
}
127131

128132
// MarshalJSON -
129133
func (i Int) MarshalJSON() ([]byte, error) {
130134
if i.Int == nil {
131-
return nil, errors.New("nil Int value")
135+
i.Int = big.NewInt(0)
132136
}
133137
return i.Int.MarshalJSON()
134138
}

0 commit comments

Comments
 (0)