diff --git a/common/util.go b/common/util.go index 64c8d5c..16a574b 100644 --- a/common/util.go +++ b/common/util.go @@ -2,17 +2,8 @@ package common import ( "regexp" - - "github.com/ipfs/go-cid" ) -func CidV1(c cid.Cid) cid.Cid { - if c.Version() == 1 { - return c - } - return cid.NewCidV1(c.Type(), c.Hash()) -} - const ( cidTrimPrefix = 6 cidTrimSuffix = 8 diff --git a/cron/trackdeals.go b/cron/trackdeals.go index 96a981b..a50336c 100644 --- a/cron/trackdeals.go +++ b/cron/trackdeals.go @@ -252,7 +252,7 @@ var trackDeals = &cli.Command{ var labelCid *string if lc, err := cid.Parse(d.Proposal.Label); err == nil { - lcs := common.CidV1(lc).String() + lcs := lc.String() labelCid = &lcs } diff --git a/misc/pg_schema.sql b/misc/pg_schema.sql index 76e7819..9053abc 100644 --- a/misc/pg_schema.sql +++ b/misc/pg_schema.sql @@ -50,6 +50,14 @@ AS $$ SELECT SUBSTRING( $1 FROM 1 FOR 2 ) = 'ba' $$; +CREATE OR REPLACE + FUNCTION evergreen.valid_cid(TEXT) RETURNS BOOLEAN + LANGUAGE sql IMMUTABLE PARALLEL SAFE +AS $$ + SELECT ( SUBSTRING( $1 FROM 1 FOR 2 ) = 'ba' OR SUBSTRING( $1 FROM 1 FOR 2 ) = 'Qm' ) +$$; + + CREATE OR REPLACE FUNCTION evergreen.update_entry_timestamp() RETURNS TRIGGER LANGUAGE plpgsql @@ -99,7 +107,7 @@ CREATE INDEX IF NOT EXISTS pieces_padded_size_idx ON evergreen.pieces ( padded_s CREATE TABLE IF NOT EXISTS evergreen.payloads ( piece_cid TEXT NOT NULL REFERENCES evergreen.pieces ( piece_cid ), - payload_cid TEXT NOT NULL CONSTRAINT valid_rcid CHECK ( evergreen.valid_cid_v1( payload_cid ) ), + payload_cid TEXT NOT NULL CONSTRAINT valid_rcid CHECK ( evergreen.valid_cid( payload_cid ) ), CONSTRAINT payload_piece UNIQUE ( payload_cid, piece_cid ), CONSTRAINT temp_single_root UNIQUE ( piece_cid ), meta JSONB @@ -154,7 +162,7 @@ CREATE TABLE IF NOT EXISTS evergreen.published_deals ( provider_id TEXT NOT NULL REFERENCES evergreen.providers ( provider_id ), client_id TEXT NOT NULL REFERENCES evergreen.clients ( client_id ), label BYTEA NOT NULL, - decoded_label TEXT CONSTRAINT valid_cid CHECK ( evergreen.valid_cid_v1( decoded_label ) ), + decoded_label TEXT CONSTRAINT valid_label_cid CHECK ( evergreen.valid_cid( decoded_label ) ), is_filplus BOOL NOT NULL, status TEXT NOT NULL, status_meta TEXT,