MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / decode_change_ledger

Function decode_change_ledger

atomic-cli/src/commands/rpc.rs:2428–2469  ·  view source on GitHub ↗
(
    ledger: &[pb::VersionedBytes],
    hashes: &[pb::Hash],
)

Source from the content-addressed store, hash-verified

2426}
2427
2428fn decode_change_ledger(
2429 ledger: &[pb::VersionedBytes],
2430 hashes: &[pb::Hash],
2431) -> CliResult<Vec<(Merkle, atomic_core::change::ProvenanceGraph)>> {
2432 if ledger.len() != hashes.len() {
2433 return Err(CliError::Internal(anyhow::anyhow!(
2434 "provenance ledger/hash count mismatch ({} graphs, {} hashes); \
2435 if using an older service, upgrade it to return stored provenance hashes",
2436 ledger.len(),
2437 hashes.len(),
2438 )));
2439 }
2440 ledger
2441 .iter()
2442 .zip(hashes)
2443 .map(|(bytes, hash)| {
2444 if hash.algorithm != pb::HashAlgorithm::Blake3 as i32 {
2445 return Err(CliError::Internal(anyhow::anyhow!(
2446 "unsupported provenance hash algorithm: {}",
2447 hash.algorithm,
2448 )));
2449 }
2450 let value: [u8; 32] = hash.value.as_slice().try_into().map_err(|_| {
2451 CliError::Internal(anyhow::anyhow!(
2452 "malformed provenance hash: expected 32 bytes"
2453 ))
2454 })?;
2455 if bytes.schema != "atomic.prov.graph.v1" {
2456 return Err(CliError::Internal(anyhow::anyhow!(
2457 "unsupported provenance graph schema: {}",
2458 bytes.schema,
2459 )));
2460 }
2461 let graph = serde_json::from_slice(&bytes.payload).map_err(|error| {
2462 CliError::Internal(anyhow::anyhow!("provenance graph payload: {error}"))
2463 })?;
2464 // Use the stored identity, not a hash of the JSON or of an upgraded
2465 // graph reserialized by this client. Neither is the original artifact.
2466 Ok((Merkle(value), graph))
2467 })
2468 .collect()
2469}
2470
2471/// `atomic diff --from X --to Y` over the Diff RPC's RefPairScope arm —
2472/// the same client-side renders as the working-copy form (`--json`, the

Calls 5

MerkleClass · 0.85
lenMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45