11package api
22
33import (
4- "database/sql"
54 "encoding/json"
65 "errors"
76 "net/http"
@@ -74,32 +73,6 @@ func addrPacked(leaf []byte, ltd []string) common.Address {
7473 return common.Address {}
7574}
7675
77- type jsonNullBool struct {
78- sql.NullBool
79- }
80-
81- func (jnb * jsonNullBool ) UnmarshalJSON (d []byte ) error {
82- var b * bool
83- if err := json .Unmarshal (d , & b ); err != nil {
84- return err
85- }
86- if b == nil {
87- jnb .Valid = false
88- return nil
89- }
90-
91- jnb .Valid = true
92- jnb .Bool = * b
93- return nil
94- }
95-
96- func (jnb jsonNullBool ) MarshalJSON () ([]byte , error ) {
97- if jnb .Valid {
98- return json .Marshal (jnb .Bool )
99- }
100- return json .Marshal (nil )
101- }
102-
10376func encodeProof (p [][]byte ) []string {
10477 var res []string
10578 for i := range p {
@@ -111,7 +84,7 @@ func encodeProof(p [][]byte) []string {
11184type createTreeReq struct {
11285 Leaves []hexutil.Bytes `json:"unhashedLeaves"`
11386 Ltd []string `json:"leafTypeDescriptor"`
114- Packed jsonNullBool `json:"packedEncoding"`
87+ Packed bool `json:"packedEncoding"`
11588}
11689
11790type createTreeResp struct {
@@ -158,7 +131,7 @@ func (s *Server) CreateTree(w http.ResponseWriter, r *http.Request) {
158131 }
159132 proofs = append (proofs , proofItem {
160133 Leaf : hexutil .Encode (l ),
161- Addr : leaf2Addr (l , req .Ltd , req .Packed . Bool ).Hex (),
134+ Addr : leaf2Addr (l , req .Ltd , req .Packed ).Hex (),
162135 Proof : encodeProof (pf ),
163136 })
164137 }
@@ -177,7 +150,7 @@ func (s *Server) CreateTree(w http.ResponseWriter, r *http.Request) {
177150 tree .Root (),
178151 req .Leaves ,
179152 req .Ltd ,
180- req .Packed . NullBool ,
153+ req .Packed ,
181154 proofs ,
182155 )
183156 if err != nil {
@@ -192,7 +165,7 @@ type getTreeResp struct {
192165 UnhashedLeaves []hexutil.Bytes `json:"unhashedLeaves"`
193166 LeafCount int `json:"leafCount"`
194167 Ltd []string `json:"leafTypeDescriptor"`
195- Packed jsonNullBool `json:"packedEncoding"`
168+ Packed bool `json:"packedEncoding"`
196169}
197170
198171func (s * Server ) GetTree (w http.ResponseWriter , r * http.Request ) {
0 commit comments