diff --git a/api/migrations/migrations.go b/api/migrations/migrations.go index f2f45a8..8915b51 100644 --- a/api/migrations/migrations.go +++ b/api/migrations/migrations.go @@ -70,8 +70,19 @@ var Migrations = []migrate.Migration{ { Name: "2022-08-22.1.add-inserted-at.sql", SQL: ` - ALTER TABLE trees + ALTER TABLE trees ADD COLUMN "inserted_at" timestamptz NOT NULL DEFAULT now(); `, }, + { + Name: "2022-08-30.0.packed-bool.sql", + SQL: ` + UPDATE trees SET packed = true + WHERE packed IS NULL; + + ALTER TABLE trees + ALTER COLUMN packed + SET NOT NULL; + `, + }, } diff --git a/api/tree.go b/api/tree.go index a110896..2e4b2f4 100644 --- a/api/tree.go +++ b/api/tree.go @@ -1,7 +1,6 @@ package api import ( - "database/sql" "encoding/json" "errors" "net/http" @@ -74,32 +73,6 @@ func addrPacked(leaf []byte, ltd []string) common.Address { return common.Address{} } -type jsonNullBool struct { - sql.NullBool -} - -func (jnb *jsonNullBool) UnmarshalJSON(d []byte) error { - var b *bool - if err := json.Unmarshal(d, &b); err != nil { - return err - } - if b == nil { - jnb.Valid = false - return nil - } - - jnb.Valid = true - jnb.Bool = *b - return nil -} - -func (jnb jsonNullBool) MarshalJSON() ([]byte, error) { - if jnb.Valid { - return json.Marshal(jnb.Bool) - } - return json.Marshal(nil) -} - func encodeProof(p [][]byte) []string { var res []string for i := range p { @@ -111,7 +84,7 @@ func encodeProof(p [][]byte) []string { type createTreeReq struct { Leaves []hexutil.Bytes `json:"unhashedLeaves"` Ltd []string `json:"leafTypeDescriptor"` - Packed jsonNullBool `json:"packedEncoding"` + Packed bool `json:"packedEncoding"` } type createTreeResp struct { @@ -158,7 +131,7 @@ func (s *Server) CreateTree(w http.ResponseWriter, r *http.Request) { } proofs = append(proofs, proofItem{ Leaf: hexutil.Encode(l), - Addr: leaf2Addr(l, req.Ltd, req.Packed.Bool).Hex(), + Addr: leaf2Addr(l, req.Ltd, req.Packed).Hex(), Proof: encodeProof(pf), }) } @@ -177,7 +150,7 @@ func (s *Server) CreateTree(w http.ResponseWriter, r *http.Request) { tree.Root(), req.Leaves, req.Ltd, - req.Packed.NullBool, + req.Packed, proofs, ) if err != nil { @@ -192,7 +165,7 @@ type getTreeResp struct { UnhashedLeaves []hexutil.Bytes `json:"unhashedLeaves"` LeafCount int `json:"leafCount"` Ltd []string `json:"leafTypeDescriptor"` - Packed jsonNullBool `json:"packedEncoding"` + Packed bool `json:"packedEncoding"` } func (s *Server) GetTree(w http.ResponseWriter, r *http.Request) {