{"modulePath":"github.com/data-preservation-programs/singularity","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package model\n\n## Constants\n\n```go\nconst (\n\t// PDPProofSetMaxPieceSize is Singularity's current PDP max piece size policy:\n\t// 1 GiB minus FR32 expansion overhead.\n\tPDPProofSetMaxPieceSize int64 = (1 \u003c\u003c 30) * 127 / 128 // 1,065,353,216 bytes\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrInvalidCIDEntry         = errors.New(\"invalid CID entry in the database\")\n\tErrInvalidStringSliceEntry = errors.New(\"invalid string slice entry in the database\")\n\tErrInvalidStringMapEntry   = errors.New(\"invalid string map entry in the database\")\n\tErrInvalidHTTPConfigEntry  = errors.New(\"invalid ClientConfig entry in the database\")\n)\n```\n\n```go\nvar DealStateStrings = []string{\n\tstring(DealProposed),\n\tstring(DealPublished),\n\tstring(DealActive),\n\tstring(DealExpired),\n\tstring(DealProposalExpired),\n\tstring(DealRejected),\n\tstring(DealSlashed),\n\tstring(DealErrored),\n}\n```\n\n```go\nvar DealStates = []DealState{\n\tDealProposed,\n\tDealPublished,\n\tDealActive,\n\tDealExpired,\n\tDealProposalExpired,\n\tDealRejected,\n\tDealSlashed,\n\tDealErrored,\n}\n```\n\n```go\nvar DealTypeStrings = []string{\n\tstring(DealTypeMarket),\n\tstring(DealTypePDP),\n\tstring(DealTypeDDO),\n}\n```\n\n```go\nvar DealTypes = []DealType{\n\tDealTypeMarket,\n\tDealTypePDP,\n\tDealTypeDDO,\n}\n```\n\n```go\nvar ErrInvalidJobState = errors.New(\"invalid job state\")\n```\n\n```go\nvar JobStateStrings = []string{\n\tstring(Created),\n\tstring(Ready),\n\tstring(Paused),\n\tstring(Processing),\n\tstring(Complete),\n\tstring(Error),\n}\n```\n\n```go\nvar JobStates = []JobState{\n\tCreated,\n\tReady,\n\tPaused,\n\tProcessing,\n\tComplete,\n\tError,\n}\n```\n\n```go\nvar JobTypeStrings = []string{\n\tstring(Scan),\n\tstring(Pack),\n\tstring(DagGen),\n}\n```\n\n```go\nvar JobTypes = []JobType{\n\tScan,\n\tPack,\n\tDagGen,\n}\n```\n\n```go\nvar ScheduleStateStrings = []string{\n\tstring(ScheduleActive),\n\tstring(SchedulePaused),\n\tstring(ScheduleError),\n\tstring(ScheduleCompleted),\n}\n```\n\n```go\nvar ScheduleStates = []ScheduleState{\n\tScheduleActive,\n\tSchedulePaused,\n\tScheduleError,\n\tScheduleCompleted,\n}\n```\n\n```go\nvar Tables = []any{\n\t\u0026Worker{},\n\t\u0026Global{},\n\t\u0026Preparation{},\n\t\u0026Storage{},\n\t\u0026OutputAttachment{},\n\t\u0026SourceAttachment{},\n\t\u0026Job{},\n\t\u0026File{},\n\t\u0026FileRange{},\n\t\u0026Directory{},\n\t\u0026Car{},\n\t\u0026CarBlock{},\n\t\u0026Deal{},\n\t\u0026Schedule{},\n\t\u0026Actor{},\n\t\u0026Wallet{},\n\t\u0026PDPProofSet{},\n}\n```\n\n## Functions\n\n```go\nfunc AutoMigrate(db *gorm.DB) error\n```\nAutoMigrate attempts to automatically migrate the database schema.\n\nThis function performs a few operations:\n\n 1. Automatically migrates the tables in the database to match the structures defined in the application.\n 2. Migrates FK constraints that changed from CASCADE to SET NULL (for fast prep deletion).\n 3. Creates an instance ID if it doesn't already exist.\n 4. Generates a new encryption salt and stores it in the database if it doesn't already exist.\n\nThe purpose of the auto-migration feature is to simplify schema changes and manage basic system configurations without manually altering the database. This is especially useful during development or when deploying updates that include schema changes.\n\nParameters:\n\n  - db: A pointer to a gorm.DB object, which provides database access.\n\nReturns:\n\n  - An error if any issues arise during the process, otherwise nil.\n\n```go\nfunc DropAll(db *gorm.DB) error\n```\nDropAll removes all tables specified in the Tables slice from the database.\n\nThis function is typically used during development or testing where a clean database slate is required. It iterates over the predefined Tables list and drops each table. Care should be taken when using this function in production environments as it will result in data loss.\n\nParameters:\n\n  - db: A pointer to a gorm.DB object, which provides database access.\n\nReturns:\n\n  - An error if any issues arise during the table drop process, otherwise nil.\n\n```go\nfunc IsSecretConfigName(key string) bool\n```\n\n## Types\n\n```go\ntype Actor struct {\n\tID      string `gorm:\"primaryKey;size:15\" json:\"id\"`      // actor ID (f0...)\n\tAddress string `gorm:\"index\"              json:\"address\"` // filecoin address\n\n}\n```\non-chain actor identity tracked by singularity. actors we control have a Wallet with ActorID pointing here. actors we don't control (counterparties) exist as bare records.\n\n```go\nfunc (Actor) TableName() string\n```\nGORM will rename \"wallets\" table to \"actors\" on AutoMigrate\n\n```go\ntype CID cid.Cid\n```\n\n```go\nfunc (c CID) MarshalBinary() ([]byte, error)\n```\n\n```go\nfunc (c CID) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (c *CID) Scan(src any) error\n```\n\n```go\nfunc (c CID) String() string\n```\n\n```go\nfunc (c *CID) UnmarshalBinary(b []byte) error\n```\n\n```go\nfunc (c *CID) UnmarshalJSON(b []byte) error\n```\n\n```go\nfunc (c CID) Value() (driver.Value, error)\n```\n\n```go\ntype Car struct {\n\tID                  CarID      `cbor:\"-\"                    gorm:\"primaryKey\"                                        json:\"id\"                                  table:\"verbose\"`\n\tCreatedAt           time.Time  `cbor:\"-\"                    json:\"createdAt\"                                         table:\"verbose;format:2006-01-02 15:04:05\"`\n\tPieceType           PieceType  `cbor:\"0,keyasint,omitempty\" json:\"pieceType\"                                         swaggertype:\"string\"` // PieceType indicates whether this is a data piece or DAG piece\n\tPieceCID            CID        `cbor:\"1,keyasint,omitempty\" gorm:\"column:piece_cid;index;type:bytes;size:255\"        json:\"pieceCid\"                            swaggertype:\"string\"`\n\tPieceSize           int64      `cbor:\"2,keyasint,omitempty\" json:\"pieceSize\"`\n\tRootCID             CID        `cbor:\"3,keyasint,omitempty\" gorm:\"column:root_cid;type:bytes\"                        json:\"rootCid\"                             swaggertype:\"string\"`\n\tFileSize            int64      `cbor:\"4,keyasint,omitempty\" json:\"fileSize\"`\n\tMinPieceSizePadding int64      `cbor:\"5,keyasint,omitempty\" json:\"minPieceSizePadding\"` // MinPieceSizePadding tracks virtual padding for inline mode only. Inline: stores padding amount, PieceReader serves zeros virtually. Non-inline: always 0, literal zeros are written to CAR file for Curio TreeD compatibility.\n\tStorageID           *StorageID `cbor:\"-\"                    gorm:\"index\"                                             json:\"storageId\"                                         table:\"verbose\"`\n\tStorage             *Storage   `cbor:\"-\"                    gorm:\"foreignKey:StorageID;constraint:OnDelete:SET NULL\" json:\"storage,omitempty\"                   swaggerignore:\"true\" table:\"expand\"`\n\tStoragePath         string     `cbor:\"-\"                    json:\"storagePath\"` // StoragePath is the path to the CAR file inside the storage. If the StorageID is nil but StoragePath is not empty, it means the CAR file is stored at the local absolute path.\n\tNumOfFiles          int64      `cbor:\"-\"                    json:\"numOfFiles\"                                        table:\"verbose\"`\n\n\t// Association - SET NULL for fast prep deletion, async cleanup\n\tPreparationID *PreparationID      `cbor:\"-\" gorm:\"index\"                                                 json:\"preparationId\"         table:\"-\"`\n\tPreparation   *Preparation        `cbor:\"-\" gorm:\"foreignKey:PreparationID;constraint:OnDelete:SET NULL\" json:\"preparation,omitempty\" swaggerignore:\"true\" table:\"-\"`\n\tAttachmentID  *SourceAttachmentID `cbor:\"-\" gorm:\"index\"                                                 json:\"attachmentId\"          table:\"-\"`\n\tAttachment    *SourceAttachment   `cbor:\"-\" gorm:\"foreignKey:AttachmentID;constraint:OnDelete:SET NULL\"  json:\"attachment,omitempty\"  swaggerignore:\"true\" table:\"-\"`\n\tJobID         *JobID              `cbor:\"-\" gorm:\"index\"                                                 json:\"jobId,omitempty\"       table:\"-\"`\n\tJob           *Job                `cbor:\"-\" gorm:\"foreignKey:JobID;constraint:OnDelete:SET NULL\"         json:\"job,omitempty\"         swaggerignore:\"true\" table:\"-\"`\n}\n```\nCar makes a reference to a CAR file that has been potentially exported to the disk. In the case of inline preparation, the path may be empty so the Car should be constructed on the fly using CarBlock. The index on PieceCID is to find all CARs that can matches the PieceCID\n\n```go\ntype CarBlock struct {\n\tID             CarBlockID `cbor:\"-\"                    gorm:\"primaryKey\"                           json:\"id\"`\n\tCID            CID        `cbor:\"1,keyasint,omitempty\" gorm:\"index;column:cid;type:bytes;size:255\" json:\"cid\" swaggertype:\"string\"` // CID is the CID of the block.\n\tCarOffset      int64      `cbor:\"2,keyasint,omitempty\" json:\"carOffset\"`                                                            // Offset of the block in the Car\n\tCarBlockLength int32      `cbor:\"3,keyasint,omitempty\" json:\"carBlockLength\"`                                                       // Length of the block in the Car, including varint, CID and raw block\n\tVarint         []byte     `cbor:\"4,keyasint,omitempty\" json:\"varint\"`                                                               // Varint is the varint that represents the length of the block and the CID.\n\tRawBlock       []byte     `cbor:\"5,keyasint,omitempty\" json:\"rawBlock\"`                                                             // Raw block\n\tFileOffset     int64      `cbor:\"6,keyasint,omitempty\" gorm:\"index:idx_car_blocks_file_span,priority:2\" json:\"fileOffset\"`          // Offset of the block in the File\n\n\t// Associations - SET NULL for fast prep deletion, async cleanup\n\tCarID  *CarID  `cbor:\"-\"                    gorm:\"index\"                                          json:\"carId\"`\n\tCar    *Car    `cbor:\"-\"                    gorm:\"foreignKey:CarID;constraint:OnDelete:SET NULL\"  json:\"car,omitempty\"  swaggerignore:\"true\"`\n\tFileID *FileID `cbor:\"7,keyasint,omitempty\" gorm:\"index:idx_car_blocks_file_span,priority:1\"            json:\"fileId\"`\n\tFile   *File   `cbor:\"-\"                    gorm:\"foreignKey:FileID;constraint:OnDelete:SET NULL\" json:\"file,omitempty\" swaggerignore:\"true\"`\n\t// contains filtered or unexported fields\n}\n```\nCarBlock tells us the CIDs of all blocks inside a Car and the offset of those blocks. From this table we can determine how to get the block by CID from a Car. Or we can determine how to assemble a CAR file from blocks from File. It is also possible to get all Car that are associated with File. The index on CarID is used to find all blocks in a Car. The index on CID is used to find a specific block with CID.\n\n```go\nfunc (c CarBlock) BlockLength() int32\n```\nBlockLength computes and returns the length of the block data in bytes. If the block length has already been calculated and stored, it returns the stored value. Otherwise, it calculates the block length based on the raw block data if it is available, or by subtracting the CID byte length and varint length from the total CarBlock length.\n\nReturns:\n\n  - An int32 representing the length of the block data in bytes.\n\n```go\ntype CarBlockID uint64\n```\n\n```go\ntype CarID uint32\n```\n\n```go\ntype ClientConfig struct {\n\tConnectTimeout          *time.Duration    `cbor:\"1,keyasint,omitempty\"  json:\"connectTimeout,omitempty\"          swaggertype:\"primitive,integer\"` // HTTP Client Connect timeout\n\tTimeout                 *time.Duration    `cbor:\"2,keyasint,omitempty\"  json:\"timeout,omitempty\"                 swaggertype:\"primitive,integer\"` // IO idle timeout\n\tExpectContinueTimeout   *time.Duration    `cbor:\"3,keyasint,omitempty\"  json:\"expectContinueTimeout,omitempty\"   swaggertype:\"primitive,integer\"` // Timeout when using expect / 100-continue in HTTP\n\tInsecureSkipVerify      *bool             `cbor:\"4,keyasint,omitempty\"  json:\"insecureSkipVerify,omitempty\"`                                      // Do not verify the server SSL certificate (insecure)\n\tNoGzip                  *bool             `cbor:\"5,keyasint,omitempty\"  json:\"noGzip,omitempty\"`                                                  // Don't set Accept-Encoding: gzip\n\tUserAgent               *string           `cbor:\"6,keyasint,omitempty\"  json:\"userAgent,omitempty\"`                                               // Set the user-agent to a specified string\n\tCaCert                  []string          `cbor:\"7,keyasint,omitempty\"  json:\"caCert,omitempty\"`                                                  // Paths to CA certificate used to verify servers\n\tClientCert              *string           `cbor:\"8,keyasint,omitempty\"  json:\"clientCert,omitempty\"`                                              // Path to Client SSL certificate (PEM) for mutual TLS auth\n\tClientKey               *string           `cbor:\"9,keyasint,omitempty\"  json:\"clientKey,omitempty\"`                                               // Path to Client SSL private key (PEM) for mutual TLS auth\n\tHeaders                 map[string]string `cbor:\"10,keyasint,omitempty\" json:\"headers,omitempty\"`                                                 // Set HTTP header for all transactions\n\tDisableHTTP2            *bool             `cbor:\"11,keyasint,omitempty\" json:\"disableHttp2,omitempty\"`                                            // Disable HTTP/2 in the transport\n\tDisableHTTPKeepAlives   *bool             `cbor:\"12,keyasint,omitempty\" json:\"disableHttpKeepAlives,omitempty\"`                                   // Disable HTTP keep-alives and use each connection once.\n\tRetryMaxCount           *int              `cbor:\"13,keyasint,omitempty\" json:\"retryMaxCount,omitempty\"`                                           // Maximum number of retries. Default is 10 retries.\n\tRetryDelay              *time.Duration    `cbor:\"14,keyasint,omitempty\" json:\"retryDelay,omitempty\"              swaggertype:\"primitive,integer\"` // Delay between retries. Default is 1s.\n\tRetryBackoff            *time.Duration    `cbor:\"15,keyasint,omitempty\" json:\"retryBackoff,omitempty\"            swaggertype:\"primitive,integer\"` // Constant backoff between retries. Default is 1s.\n\tRetryBackoffExponential *float64          `cbor:\"16,keyasint,omitempty\" json:\"retryBackoffExponential,omitempty\"`                                 // Exponential backoff between retries. Default is 1.0.\n\tSkipInaccessibleFile    *bool             `cbor:\"17,keyasint,omitempty\" json:\"skipInaccessibleFile,omitempty\"`                                    // Skip inaccessible files. Default is false.\n\tUseServerModTime        *bool             `cbor:\"18,keyasint,omitempty\" json:\"useServerModTime,omitempty\"`                                        // Use server modified time instead of object metadata\n\tLowLevelRetries         *int              `cbor:\"19,keyasint,omitempty\" json:\"lowlevelRetries,omitempty\"`                                         // Maximum number of retries for low-level client errors. Default is 10 retries.\n\tScanConcurrency         *int              `cbor:\"20,keyasint,omitempty\" json:\"scanConcurrency,omitempty\"`                                         // Maximum number of concurrent scan requests. Default is 1.\n}\n```\n\n```go\nfunc (c ClientConfig) MarshalJSON() ([]byte, error)\n```\nMarshalJSON redacts header values in API responses. Value() bypasses this for persistence.\n\n```go\nfunc (c *ClientConfig) Scan(src any) error\n```\n\n```go\nfunc (c ClientConfig) String() string\n```\n\n```go\nfunc (c ClientConfig) Value() (driver.Value, error)\n```\n\n```go\ntype ConfigMap map[string]string\n```\n\n```go\nfunc (m ConfigMap) MarshalJSON() ([]byte, error)\n```\nMarshalJSON redacts secret-named values in API responses. Value() bypasses this for persistence, and the rclone backend build reads the map directly.\n\n```go\nfunc (m *ConfigMap) Scan(src any) error\n```\n\n```go\nfunc (m ConfigMap) String() string\n```\n\n```go\nfunc (m ConfigMap) Value() (driver.Value, error)\n```\n\n```go\ntype DDOAllocationStatus struct {\n\tActivated    bool\n\tSectorNumber uint64\n}\n```\n\n```go\ntype Deal struct {\n\tID               DealID     `gorm:\"primaryKey\"                      json:\"id\"                                  table:\"verbose\"`\n\tCreatedAt        time.Time  `json:\"createdAt\"                       table:\"verbose;format:2006-01-02 15:04:05\"`\n\tUpdatedAt        time.Time  `json:\"updatedAt\"                       table:\"verbose;format:2006-01-02 15:04:05\"`\n\tLastVerifiedAt   *time.Time `json:\"lastVerifiedAt\"                  table:\"verbose;format:2006-01-02 15:04:05\"` // LastVerifiedAt is the last time the deal was verified as active by the tracker\n\tDealID           *uint64    `gorm:\"unique\"                          json:\"dealId\"`\n\tState            DealState  `gorm:\"index:idx_pending\"               json:\"state\"`\n\tDealType         DealType   `gorm:\"index;default:'market'\"          json:\"dealType\"`\n\tProvider         string     `json:\"provider\"`\n\tProposalID       string     `json:\"proposalId\"                      table:\"verbose\"`\n\tLabel            string     `json:\"label\"                           table:\"verbose\"`\n\tPieceCID         CID        `gorm:\"column:piece_cid;index;size:255\" json:\"pieceCid\"                            swaggertype:\"string\"`\n\tPieceSize        int64      `json:\"pieceSize\"`\n\tStartEpoch       int32      `json:\"startEpoch\"`\n\tEndEpoch         int32      `json:\"endEpoch\"                        table:\"verbose\"`\n\tSectorStartEpoch int32      `json:\"sectorStartEpoch\"                table:\"verbose\"`\n\tPrice            string     `json:\"price\"`\n\tVerified         bool       `json:\"verified\"`\n\tErrorMessage     string     `json:\"errorMessage\"                    table:\"verbose\"`\n\n\t// PDP-specific fields (only populated for DealTypePDP)\n\tProofSetID         *uint64 `json:\"proofSetId,omitempty\"         table:\"verbose\"` // ProofSetID is the on-chain proof set ID for PDP deals\n\tProofSetLive       *bool   `json:\"proofSetLive,omitempty\"       table:\"verbose\"` // ProofSetLive indicates if the proof set is live (actively being challenged)\n\tNextChallengeEpoch *int32  `json:\"nextChallengeEpoch,omitempty\" table:\"verbose\"` // NextChallengeEpoch is the next epoch when a challenge proof is due\n\n\t// DDO-specific fields (only populated for DealTypeDDO)\n\tDDOAllocationID *uint64 `json:\"ddoAllocationId,omitempty\" table:\"verbose\"`\n\tDDORailID       *uint64 `json:\"ddoRailId,omitempty\"       table:\"verbose\"`\n\tDDOPaymentToken *string `json:\"ddoPaymentToken,omitempty\" table:\"verbose\"`\n\n\t// Associations\n\tScheduleID *ScheduleID `json:\"scheduleId\"                                         table:\"verbose\"`\n\tSchedule   *Schedule   `gorm:\"foreignKey:ScheduleID;constraint:OnDelete:SET NULL\" json:\"schedule,omitempty\" swaggerignore:\"true\" table:\"expand\"`\n\tClientID   string      `gorm:\"index:idx_pending\"                                  json:\"clientId\"`\n\tWalletID   *uint       `gorm:\"index:idx_deal_wallet\"                              json:\"walletId,omitempty\"  table:\"verbose\"`\n\tWallet     *Wallet     `gorm:\"foreignKey:WalletID;constraint:OnDelete:SET NULL\"   json:\"wallet,omitempty\"    swaggerignore:\"true\" table:\"expand\"`\n}\n```\nDeal is the deal model for all deals made by deal pusher or tracked by the tracker. index on PieceCID tracks replication of same piece index on State and ClientID calculates pending deals\n\n```go\nfunc (d Deal) Key() string\n```\nKey returns a mostly unique key to match deal from locally proposed deals and deals from the chain.\n\n```go\ntype DealID uint64\n```\n\n```go\ntype DealState string\n```\n\n```go\nconst (\n\tDealProposed        DealState = \"proposed\"\n\tDealPublished       DealState = \"published\"\n\tDealActive          DealState = \"active\"\n\tDealExpired         DealState = \"expired\"\n\tDealProposalExpired DealState = \"proposal_expired\"\n\tDealRejected        DealState = \"rejected\"\n\tDealSlashed         DealState = \"slashed\"\n\tDealErrored         DealState = \"error\"\n)\n```\n\n```go\ntype DealType string\n```\nDealType represents the type of deal (legacy market vs PDP)\n\n```go\nconst (\n\t// DealTypeMarket represents legacy f05 market actor deals\n\tDealTypeMarket DealType = \"market\"\n\t// DealTypePDP represents f41 PDP (Proof of Data Possession) deals\n\tDealTypePDP DealType = \"pdp\"\n\t// DealTypeDDO represents DDO (Direct Data Onboarding) allocation deals\n\tDealTypeDDO DealType = \"ddo\"\n)\n```\n\n```go\ntype Directory struct {\n\tID       DirectoryID `gorm:\"primaryKey\"            json:\"id\"`\n\tCID      CID         `gorm:\"column:cid;type:bytes\" json:\"cid\" swaggertype:\"string\"` // CID is the CID of the directory.\n\tData     []byte      `gorm:\"column:data\"           json:\"-\"   swaggerignore:\"true\"` // Data is the serialized directory data.\n\tName     string      `json:\"name\"`                                                  // Name is the name of the directory.\n\tExported bool        `json:\"exported\"`                                              // Exported is a flag that indicates whether the directory has been exported to the DAG.\n\n\t// Associations - AttachmentID SET NULL for fast prep deletion, async cleanup\n\tAttachmentID *SourceAttachmentID `gorm:\"index:directory_source_parent\"                        json:\"attachmentId\"`\n\tAttachment   *SourceAttachment   `gorm:\"foreignKey:AttachmentID;constraint:OnDelete:SET NULL\" json:\"attachment,omitempty\" swaggerignore:\"true\"`\n\tParentID     *DirectoryID        `gorm:\"index:directory_source_parent\"                        json:\"parentId\"`\n\tParent       *Directory          `gorm:\"foreignKey:ParentID;constraint:OnDelete:CASCADE\"      json:\"parent,omitempty\"     swaggerignore:\"true\"`\n}\n```\nDirectory is a link between parent and child directories. The index on AttachmentID and ParentID is used to find all root directories, as well as all directories in a directory.\n\n```go\ntype DirectoryID uint64\n```\n\n```go\ntype File struct {\n\tID               FileID `cbor:\"1,keyasint,omitempty\" gorm:\"primaryKey\"                     json:\"id\"`\n\tCID              CID    `cbor:\"-\"                    gorm:\"column:cid;type:bytes;size:255\" json:\"cid\"  swaggertype:\"string\"` // CID is the CID of the file.\n\tPath             string `cbor:\"2,keyasint,omitempty\" gorm:\"index\"                          json:\"path\"`                      // Path is the relative path to the file inside the storage.\n\tHash             string `cbor:\"3,keyasint,omitempty\" json:\"hash\"`                                                            // Hash is the hash of the file.\n\tSize             int64  `cbor:\"4,keyasint,omitempty\" json:\"size\"`                                                            // Size is the size of the file in bytes.\n\tLastModifiedNano int64  `cbor:\"5,keyasint,omitempty\" json:\"lastModifiedNano\"`\n\n\t// Associations - AttachmentID SET NULL for fast prep deletion, async cleanup\n\tAttachmentID *SourceAttachmentID `cbor:\"-\" gorm:\"index\"                                                json:\"attachmentId\"`\n\tAttachment   *SourceAttachment   `cbor:\"-\" gorm:\"foreignKey:AttachmentID;constraint:OnDelete:SET NULL\" json:\"attachment,omitempty\" swaggerignore:\"true\"`\n\tDirectoryID  *DirectoryID        `cbor:\"-\" gorm:\"index\"                                                json:\"directoryId\"`\n\tDirectory    *Directory          `cbor:\"-\" gorm:\"foreignKey:DirectoryID;constraint:OnDelete:CASCADE\"   json:\"directory,omitempty\"  swaggerignore:\"true\"`\n\tFileRanges   []FileRange         `cbor:\"-\" gorm:\"constraint:OnDelete:CASCADE\"                          json:\"fileRanges,omitempty\"`\n}\n```\nFile makes a reference to the source storage file, e.g., a local file. The index on Path is used as part of scanning to find existing file and add new versions. The index on DirectoryID is used to find all files in a directory.\n\n```go\nfunc (i File) FileName() string\n```\n\n```go\ntype FileID uint64\n```\n\n```go\ntype FileRange struct {\n\tID     FileRangeID `gorm:\"primaryKey\"            json:\"id\"`\n\tOffset int64       `json:\"offset\"`                                                // Offset is the offset of the range inside the file.\n\tLength int64       `json:\"length\"`                                                // Length is the length of the range in bytes.\n\tCID    CID         `gorm:\"column:cid;type:bytes\" json:\"cid\" swaggertype:\"string\"` // CID is the CID of the range.\n\n\t// Associations\n\tJobID  *JobID `gorm:\"index\"                                         json:\"jobId\"`\n\tJob    *Job   `gorm:\"foreignKey:JobID;constraint:OnDelete:SET NULL\" json:\"job,omitempty\"  swaggerignore:\"true\"`\n\tFileID FileID `gorm:\"index\"                                         json:\"fileId\"`\n\tFile   *File  `gorm:\"foreignKey:FileID;constraint:OnDelete:CASCADE\" json:\"file,omitempty\" swaggerignore:\"true\"`\n}\n```\nFileRange is a range of bytes inside File. The index on FileID is used to find all FileRange in a file. The index on JobID is used to find all FileRange in a job.\n\n```go\ntype FileRangeID uint64\n```\n\n```go\ntype Global struct {\n\tKey   string `gorm:\"primaryKey\" json:\"key\"`\n\tValue string `json:\"value\"`\n}\n```\n\n```go\ntype Job struct {\n\tID              JobID    `gorm:\"primaryKey\"           json:\"id\"`\n\tType            JobType  `gorm:\"index:job_type_state\" json:\"type\"`\n\tState           JobState `gorm:\"index:job_type_state\" json:\"state\"`\n\tErrorMessage    string   `json:\"errorMessage\"`\n\tErrorStackTrace string   `json:\"errorStackTrace\"      table:\"verbose\"`\n\n\t// Associations - AttachmentID SET NULL for fast prep deletion, async cleanup\n\tWorkerID     *string             `gorm:\"size:63;index\"                                                  json:\"workerId,omitempty\"`\n\tWorker       *Worker             `gorm:\"foreignKey:WorkerID;references:ID;constraint:OnDelete:SET NULL\" json:\"worker,omitempty\"     swaggerignore:\"true\" table:\"verbose;expand\"`\n\tAttachmentID *SourceAttachmentID `gorm:\"index\"                                                          json:\"attachmentId\"         table:\"verbose\"`\n\tAttachment   *SourceAttachment   `gorm:\"foreignKey:AttachmentID;constraint:OnDelete:SET NULL\"           json:\"attachment,omitempty\" swaggerignore:\"true\" table:\"expand\"`\n\tFileRanges   []FileRange         `gorm:\"foreignKey:JobID;constraint:OnDelete:SET NULL\"                  json:\"fileRanges,omitempty\" swaggerignore:\"true\" table:\"-\"`\n}\n```\nJob is a job that is executed by a worker. The composite index on Type and State is used to find jobs that are ready to be executed.\n\n```go\ntype JobID uint64\n```\n\n```go\ntype JobState string\n```\n\n```go\nconst (\n\t// Created means the job has been created and is not ready for processing.\n\tCreated JobState = \"created\"\n\t// Ready means the job is ready for processing.\n\tReady JobState = \"ready\"\n\t// Paused means the job is ready but has been paused and should not be picked up for processing.\n\tPaused JobState = \"paused\"\n\t// Processing means the job is currently being processed.\n\tProcessing JobState = \"processing\"\n\t// Complete means the job is complete.\n\tComplete JobState = \"complete\"\n\t// Error means the job has some error.\n\tError JobState = \"error\"\n)\n```\n\n```go\nfunc (js *JobState) Set(value string) error\n```\n\n```go\nfunc (js *JobState) String() string\n```\n\n```go\ntype JobType string\n```\n\n```go\nconst (\n\tScan   JobType = \"scan\"\n\tPack   JobType = \"pack\"\n\tDagGen JobType = \"daggen\"\n)\n```\n\n```go\ntype OutputAttachment struct {\n\tID OutputAttachmentID `gorm:\"primaryKey\" json:\"id\"`\n\n\t// Associations\n\tPreparationID PreparationID `gorm:\"uniqueIndex:prep_output\"                              json:\"preparationId\"`\n\tPreparation   *Preparation  `gorm:\"foreignKey:PreparationID;constraint:OnDelete:CASCADE\" json:\"preparation,omitempty\" swaggerignore:\"true\"`\n\tStorageID     StorageID     `gorm:\"uniqueIndex:prep_output\"                              json:\"storageId\"`\n\tStorage       *Storage      `gorm:\"foreignKey:StorageID;constraint:OnDelete:CASCADE\"     json:\"storage,omitempty\"     swaggerignore:\"true\"`\n}\n```\nOutputAttachment is a link between a Preparation and a Storage that is used as an output.\n\n```go\ntype OutputAttachmentID uint32\n```\n\n```go\ntype PDPProofSet struct {\n\tSetID          uint64               `gorm:\"primaryKey;autoIncrement:false\" json:\"setId\"`\n\tClientAddress  string               `gorm:\"not null;index\"                 json:\"clientAddress\"`\n\tProvider       string               `gorm:\"not null\"                       json:\"provider\"`\n\tIsLive         bool                 `gorm:\"default:false\"                  json:\"isLive\"`\n\tChallengeEpoch *int64               `                                      json:\"challengeEpoch,omitempty\"`\n\tCreatedBlock   int64                `gorm:\"not null\"                       json:\"createdBlock\"`\n\tDeleted        bool                 `gorm:\"default:false\"                  json:\"deleted\"`\n\tHandoffState   ProofSetHandoffState `gorm:\"default:'assembling'\"           json:\"handoffState\"`\n\tPieceCount     int                  `gorm:\"default:0\"                      json:\"pieceCount\"`\n\t// ClientDataSetID is the per-(payer, set) nonce the client signs into\n\t// CreateDataSet/AddPieces extraData. FWSS rejects reused IDs via its\n\t// clientNonces[payer][id] check, so we persist before signing to make\n\t// retries idempotent. Stored decimal because uint256 doesn't fit any\n\t// native int.\n\tClientDataSetID string `                                      json:\"clientDataSetId,omitempty\"`\n\t// ServiceURL caches the SP's PDP HTTP endpoint, fetched from\n\t// ServiceProviderRegistry the first time we push to this provider.\n\tServiceURL string `                                      json:\"serviceUrl,omitempty\"`\n}\n```\nPDPProofSet tracks on-chain PDP proof set state derived from contract events. This is a materialized view built from Shovel-indexed events, replacing the per-cycle RPC scans of GetProofSets/GetProofSetsForClient.\n\n```go\ntype PieceType string\n```\n\n```go\nconst (\n\tDataPiece PieceType = \"data\"\n\tDagPiece  PieceType = \"dag\"\n)\n```\n\n```go\ntype Preparation struct {\n\tID                PreparationID `gorm:\"primaryKey\"        json:\"id\"`\n\tName              string        `gorm:\"unique\"            json:\"name\"`\n\tCreatedAt         time.Time     `json:\"createdAt\"         table:\"verbose;format:2006-01-02 15:04:05\"`\n\tUpdatedAt         time.Time     `json:\"updatedAt\"         table:\"verbose;format:2006-01-02 15:04:05\"`\n\tDeleteAfterExport bool          `json:\"deleteAfterExport\"` // DeleteAfterExport is a flag that indicates whether the source files should be deleted after export.\n\tMaxSize           int64         `json:\"maxSize\"`\n\tPieceSize         int64         `json:\"pieceSize\"`\n\tMinPieceSize      int64         `json:\"minPieceSize\"` // Minimum piece size for the preparation, applies only to DAG and remainder pieces\n\tNoInline          bool          `json:\"noInline\"`\n\tNoDag             bool          `json:\"noDag\"`\n\n\t// Associations\n\tWalletID       *uint     `json:\"walletId,omitempty\"`\n\tWallet         *Wallet   `gorm:\"foreignKey:WalletID;constraint:OnDelete:SET NULL\" json:\"wallet,omitempty\" swaggerignore:\"true\" table:\"expand\"`\n\tSourceStorages []Storage `gorm:\"many2many:source_attachments;constraint:OnDelete:CASCADE\" json:\"sourceStorages,omitempty\" table:\"expand;header:Source Storages:\"`\n\tOutputStorages []Storage `gorm:\"many2many:output_attachments;constraint:OnDelete:CASCADE\" json:\"outputStorages,omitempty\" table:\"expand;header:Output Storages:\"`\n}\n```\nPreparation is a data preparation definition that can attach multiple source storages and up to one output storage.\n\n```go\nfunc (s *Preparation) FindByIDOrName(db *gorm.DB, name string, preloads ...string) error\n```\n\n```go\nfunc (p *Preparation) GetMinPieceSize() int64\n```\nGetMinPieceSize returns the minimum piece size for the preparation, with a fallback to 1MiB if not set. This ensures backward compatibility with older preparations that don't have minPieceSize set.\n\n```go\nfunc (s *Preparation) SourceAttachments(db *gorm.DB, preloads ...string) ([]SourceAttachment, error)\n```\n\n```go\ntype PreparationID uint32\n```\n\n```go\ntype ProofSetHandoffState string\n```\n\n```go\nconst (\n\tProofSetAssembling  ProofSetHandoffState = \"assembling\"\n\tProofSetTransferred ProofSetHandoffState = \"transferred\"\n)\n```\n\n```go\ntype Schedule struct {\n\tID                    ScheduleID    `gorm:\"primaryKey\"                          json:\"id\"`\n\tCreatedAt             time.Time     `json:\"createdAt\"                           table:\"verbose;format:2006-01-02 15:04:05\"`\n\tUpdatedAt             time.Time     `json:\"updatedAt\"                           table:\"verbose;format:2006-01-02 15:04:05\"`\n\tURLTemplate           string        `json:\"urlTemplate\"                         table:\"verbose\"`\n\tHTTPHeaders           ConfigMap     `gorm:\"type:JSON\"                           json:\"httpHeaders\"                         table:\"verbose\"`\n\tProvider              string        `json:\"provider\"`\n\tPricePerGBEpoch       float64       `json:\"pricePerGbEpoch\"                     table:\"verbose\"`\n\tPricePerGB            float64       `json:\"pricePerGb\"                          table:\"verbose\"`\n\tPricePerDeal          float64       `json:\"pricePerDeal\"                        table:\"verbose\"`\n\tTotalDealNumber       int           `json:\"totalDealNumber\"                     table:\"verbose\"`\n\tTotalDealSize         int64         `json:\"totalDealSize\"`\n\tVerified              bool          `json:\"verified\"`\n\tKeepUnsealed          bool          `json:\"keepUnsealed\"                        table:\"verbose\"`\n\tAnnounceToIPNI        bool          `gorm:\"column:announce_to_ipni\"             json:\"announceToIpni\"                      table:\"verbose\"`\n\tStartDelay            time.Duration `json:\"startDelay\"                          swaggertype:\"primitive,integer\"`\n\tDuration              time.Duration `json:\"duration\"                            swaggertype:\"primitive,integer\"`\n\tState                 ScheduleState `json:\"state\"`\n\tScheduleCron          string        `json:\"scheduleCron\"`\n\tScheduleCronPerpetual bool          `json:\"scheduleCronPerpetual\"`\n\tScheduleDealNumber    int           `json:\"scheduleDealNumber\"`\n\tScheduleDealSize      int64         `json:\"scheduleDealSize\"`\n\tMaxPendingDealNumber  int           `json:\"maxPendingDealNumber\"`\n\tMaxPendingDealSize    int64         `json:\"maxPendingDealSize\"`\n\tGroup                 string        `json:\"group\"                               table:\"verbose\"`\n\tNotes                 string        `json:\"notes\"`\n\tErrorMessage          string        `json:\"errorMessage\"                        table:\"verbose\"`\n\tAllowedPieceCIDs      StringSlice   `gorm:\"type:JSON;column:allowed_piece_cids\" json:\"allowedPieceCids\"                    table:\"verbose\"`\n\tForce                 bool          `json:\"force\"`\n\tDealType              DealType      `gorm:\"index;default:'market'\"              json:\"dealType\"`\n\n\t// Associations\n\tPreparationID PreparationID `json:\"preparationId\"`\n\tPreparation   *Preparation  `gorm:\"foreignKey:PreparationID;constraint:OnDelete:CASCADE\" json:\"preparation,omitempty\" swaggerignore:\"true\" table:\"expand\"`\n}\n```\n\n```go\ntype ScheduleID uint32\n```\n\n```go\ntype ScheduleState string\n```\n\n```go\nconst (\n\tScheduleActive    ScheduleState = \"active\"\n\tSchedulePaused    ScheduleState = \"paused\"\n\tScheduleError     ScheduleState = \"error\"\n\tScheduleCompleted ScheduleState = \"completed\"\n)\n```\n\n```go\ntype SourceAttachment struct {\n\tID SourceAttachmentID `gorm:\"primaryKey\" json:\"id\"`\n\n\t// Associations\n\tPreparationID PreparationID `gorm:\"uniqueIndex:prep_source\"                              json:\"preparationId\"`\n\tPreparation   *Preparation  `gorm:\"foreignKey:PreparationID;constraint:OnDelete:CASCADE\" json:\"preparation,omitempty\" swaggerignore:\"true\"`\n\tStorageID     StorageID     `gorm:\"uniqueIndex:prep_source\"                              json:\"storageId\"`\n\tStorage       *Storage      `gorm:\"foreignKey:StorageID;constraint:OnDelete:CASCADE\"     json:\"storage,omitempty\"     swaggerignore:\"true\"`\n}\n```\nSourceAttachment is a link between a Preparation and a Storage that is used as a source.\n\n```go\nfunc (s *SourceAttachment) FindByPreparationAndSource(db *gorm.DB, preparation string, source string) error\n```\n\n```go\nfunc (s *SourceAttachment) RootDirectoryCID(ctx context.Context, db *gorm.DB) (cid.Cid, error)\n```\n\n```go\nfunc (s *SourceAttachment) RootDirectoryID(ctx context.Context, db *gorm.DB) (DirectoryID, error)\n```\n\n```go\ntype SourceAttachmentID uint32\n```\n\n```go\ntype Storage struct {\n\tID           StorageID    `cbor:\"-\"                    gorm:\"primaryKey\" json:\"id\"`\n\tName         string       `cbor:\"-\"                    gorm:\"unique\"     json:\"name\"`\n\tCreatedAt    time.Time    `cbor:\"-\"                    json:\"createdAt\"  table:\"verbose;format:2006-01-02 15:04:05\"`\n\tUpdatedAt    time.Time    `cbor:\"-\"                    json:\"updatedAt\"  table:\"verbose;format:2006-01-02 15:04:05\"`\n\tType         string       `cbor:\"1,keyasint,omitempty\" json:\"type\"`\n\tPath         string       `cbor:\"2,keyasint,omitempty\" json:\"path\"`                                                                  // Path is the path to the storage root.\n\tConfig       ConfigMap    `cbor:\"3,keyasint,omitempty\" gorm:\"type:JSON\"  json:\"config\"                              table:\"verbose\"` // Config is a map of key-value pairs that can be used to store RClone options.\n\tClientConfig ClientConfig `cbor:\"4,keyasint,omitempty\" gorm:\"type:JSON\"  json:\"clientConfig\"                        table:\"verbose\"` // ClientConfig is the HTTP configuration for the storage, if applicable.\n\n\t// Associations\n\tPreparationsAsSource []Preparation `cbor:\"-\" gorm:\"many2many:source_attachments;constraint:OnDelete:CASCADE\" json:\"preparationsAsSource,omitempty\" table:\"expand;header:As Source: \"`\n\tPreparationsAsOutput []Preparation `cbor:\"-\" gorm:\"many2many:output_attachments;constraint:OnDelete:CASCADE\" json:\"preparationsAsOutput,omitempty\" table:\"expand;header:As Output: \"`\n}\n```\nStorage is a storage system definition that can be used as either source or output of a Preparation.\n\n```go\nfunc (s *Storage) FindByIDOrName(db *gorm.DB, name string, preloads ...string) error\n```\n\n```go\ntype StorageID uint32\n```\n\n```go\ntype StringSlice []string\n```\n\n```go\nfunc (ss *StringSlice) Scan(src any) error\n```\n\n```go\nfunc (ss StringSlice) Value() (driver.Value, error)\n```\n\n```go\ntype Wallet struct {\n\tID uint `gorm:\"primaryKey\" json:\"id\"`\n\n\tKeyPath  string `gorm:\"uniqueIndex;not null\" json:\"keyPath\"`      // keystore-relative name (typically the address)\n\tKeyStore string `gorm:\"default:'local';not null\" json:\"keyStore\"` // local, yubikey, aws-kms, etc\n\tAddress  string `gorm:\"index;not null\" json:\"address\"`            // filecoin address (f1.../f3...)\n\tName     string `json:\"name,omitempty\"`                           // optional label\n\n\tActorID *string `gorm:\"index;size:15\" json:\"actorId,omitempty\"` // nullable, links to on-chain actor f0...\n\n\tActor *Actor `gorm:\"foreignKey:ActorID;references:ID;constraint:OnDelete:SET NULL\" json:\"actor,omitempty\" swaggerignore:\"true\" table:\"expand\"`\n}\n```\nprivate key stored in external keystore, can be linked to on-chain actor wallets can exist before actors are created on-chain\n\n```go\nfunc (Wallet) TableName() string\n```\nGORM will rename \"wallet\\_keys\" table to \"wallets\" on AutoMigrate\n\n```go\ntype Worker struct {\n\tID            string     `gorm:\"primaryKey\"    json:\"id\"`\n\tLastHeartbeat time.Time  `json:\"lastHeartbeat\"`\n\tHostname      string     `json:\"hostname\"`\n\tType          WorkerType `json:\"type\"`\n}\n```\n\n```go\ntype WorkerType string\n```\n\n```go\nconst (\n\tDealTracker   WorkerType = \"deal_tracker\"\n\tDealPusher    WorkerType = \"deal_pusher\"\n\tDatasetWorker WorkerType = \"dataset_worker\"\n\tPDPTracker    WorkerType = \"pdp_tracker\"\n)\n```\n\n","path":"github.com/data-preservation-programs/singularity/model","name":"model","synopsis":"","isRedistributable":true}
