[CLD-2461]: feat(datastore): new WriteMetadata util#1007
[CLD-2461]: feat(datastore): new WriteMetadata util#1007graham-chainlink wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
Pull request overview
Adds a WriteMetadata utility to the datastore package to simplify writing common deployment artifacts (address refs, contract metadata, chain metadata, env metadata) into a mutable in-memory datastore.
Changes:
- Introduces a new
Metadatastruct and(*MemoryDataStore).WriteMetadata(...)helper for writing/upserting multiple datastore record types. - Adds unit tests covering no-op behavior, address duplicate handling, and upsert overwrites.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| datastore/memory_datastore.go | Adds Metadata and WriteMetadata helper to write/upsert datastore records in one call. |
| datastore/memory_datastore_test.go | Adds test coverage for WriteMetadata behavior (no-op, duplicates, overwrites). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbfef2b to
7a812d8
Compare
7a812d8 to
a2019d0
Compare
Chainlink CCIP tooling api provides [WriteMetadataToDatastore util](https://github.com/smartcontractkit/chainlink-ccip/blob/298ed1c38d5cda61a688beb2494a96a5409daf3d/deployment/utils/sequences/sequences.go#L76), this is heavily used in their changets. I have integrated this into the datastore package with the MutableDatastore and added the ability to add addresses as well as that is a common pattern. JIRA: https://smartcontract-it.atlassian.net/browse/CLD-2461
a2019d0 to
ff3fcbf
Compare
|
| } | ||
|
|
||
| // WriteMetadataToDatastore adds address refs and upserts contract and chain metadata and sets env metadata. | ||
| func WriteMetadataToDatastore(ds MutableDataStore, bundle MetadataBundle) error { |
There was a problem hiding this comment.
Instead of extending the interface of MutableDataStore to include WriteMetadata, i just introduce a helper function here so any variable of type MutableDataStore can use this
| // WriteMetadataToDatastore adds address refs and upserts contract and chain metadata and sets env metadata. | ||
| func WriteMetadataToDatastore(ds MutableDataStore, bundle MetadataBundle) error { | ||
| for _, ref := range bundle.Addresses { | ||
| if err := ds.Addresses().Add(ref); err != nil { |
There was a problem hiding this comment.
Why not Upsert? Using Add would fail if, for example, someone called WriteMetadata intending to update an existing AddressRef
| // Contracts defines any metadata pertaining to contracts that were deployed. | ||
| Contracts []ContractMetadata | ||
| // Chain defines any metadata pertaining to the chain that was operated against. | ||
| Chain *ChainMetadata |
There was a problem hiding this comment.
I get why Chain isn't a slice here, but as we generalize this CCIP-specific logic into a broadly available API, could this become a limitation? It's technically possible to have multiple ChainMetadata records per domain/environment, and other users might need that.


Chainlink CCIP tooling api provides WriteMetadataToDatastore util, this is heavily used in their changets.
I have integrated this into the datastore package with the MutableDatastore and added the ability to add addresses as well as that is a common pattern.
JIRA: https://smartcontract-it.atlassian.net/browse/CLD-2461