Registry
The registry is a JSON-file backed index of compiled artifacts and confirmed deployments. It provides mutex-protected, atomic read/write access to the daemon's local state.
Source file: internal/registry/registry.go
The registry is a JSON-file backed index of compiled artifacts and confirmed deployments. It provides mutex-protected, atomic read/write access to the daemon's local state.
Design decisions
JSON file backend
The registry persists to a single JSON file (default: registry.json in the project root). On startup, Open(path) loads the file or creates it if absent. Every write atomically marshals the full state and overwrites the file. This is simple and crash-safe for the single-daemon use case.
type fileStore struct {
Artifacts map[string]ArtifactRecord `json:"artifacts"`
Deployments map[string]DeploymentRecord `json:"deployments"`
ActiveChain string `json:"active_chain_id,omitempty"`
}
Mutex-protected access
All reads acquire RLock, all writes acquire Lock. The save() method acquires RLock for marshaling (the data snapshot) then writes to disk. This keeps concurrent API handlers safe.
Flat key space
- Artifacts:
projectID:contractName(e.g.,a1b2c3d4e5f6g7h8:MyToken) - Deployments:
idempotencyKey:chainID(e.g.,deploy-v1:125)
Both use simple string concatenation with : as separator.
Data types
ArtifactRecord
type ArtifactRecord struct {
ProjectID string `json:"project_id"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
ABI json.RawMessage `json:"abi"`
Bytecode string `json:"bytecode"`
DeployedBytecode string `json:"deployedBytecode,omitempty"`
Compiler json.RawMessage `json:"compiler,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
DeploymentRecord
type DeploymentRecord struct {
IdempotencyKey string `json:"idempotency_key"`
ChainID string `json:"chain_id"`
Contract string `json:"contract"`
Address string `json:"address"`
TxHash string `json:"tx_hash,omitempty"`
Confirmed bool `json:"confirmed"`
ProjectID string `json:"project_id,omitempty"`
}
Operations
| Method | Description |
|---|---|
PutArtifact(rec) | Index a compiled contract (overwrites if key exists) |
GetArtifact(projectID, name) | Fetch by project and contract name |
ListArtifacts(projectID) | List all artifacts for a project (or all if empty) |
PutDeployment(rec) | Store a deployment record |
GetDeployment(idempotencyKey, chainID) | Look up by idempotency key and chain |
ActiveChainID() | Return the selected chain profile id |
SetActiveChain(chainID) | Store the active chain id |
API conversion
ToTypesArtifact(rec ArtifactRecord) types.Artifact converts a registry record to the API type, deserializing the Compiler JSON field into *types.CompilerSettings.
Modifying the registry
| What to change | Where |
|---|---|
| Add artifact field | internal/registry/registry.go - ArtifactRecord + ToTypesArtifact |
| Add deployment field | internal/registry/registry.go - DeploymentRecord |
| Change storage backend | Replace fileStore with Postgres/SQLite implementation |
| Add listing API | internal/registry/registry.go - ListDeployments |
