MCPcopy Create free account
hub / github.com/dfinity/orbit / create

Method create

core/control-panel/impl/src/services/artifact.rs:33–58  ·  view source on GitHub ↗

Creates a new artifact with the given artifact bytes. If the artifact already exists, the existing artifact id is returned.

(&self, artifact: Vec<u8>)

Source from the content-addressed store, hash-verified

31 ///
32 /// If the artifact already exists, the existing artifact id is returned.
33 pub fn create(&self, artifact: Vec<u8>) -> ServiceResult<ArtifactId> {
34 let artifact = Artifact::new(artifact);
35
36 match self.artifact_repository.find_by_hash(artifact.hash()) {
37 Some(artifact_id) => {
38 let mut artifact = self.find_by_id(&artifact_id)?;
39
40 artifact.increment_rc();
41
42 self.artifact_repository
43 .insert(*artifact.id(), artifact.clone());
44
45 Ok(artifact_id)
46 }
47 None => {
48 let artifact_id = artifact.id();
49
50 artifact.validate()?;
51
52 self.artifact_repository
53 .insert(*artifact_id, artifact.clone());
54
55 Ok(*artifact_id)
56 }
57 }
58 }
59
60 /// Finds an artifact by its id.
61 ///

Callers 7

test_get_artifactFunction · 0.45
add_registry_entryMethod · 0.45
test_createFunction · 0.45
test_remove_by_idFunction · 0.45

Calls 7

find_by_hashMethod · 0.80
find_by_idMethod · 0.80
increment_rcMethod · 0.80
idMethod · 0.80
hashMethod · 0.45
insertMethod · 0.45
validateMethod · 0.45

Tested by 6

test_get_artifactFunction · 0.36
test_createFunction · 0.36
test_remove_by_idFunction · 0.36