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

Function decode_change_ledger

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

Source from the content-addressed store, hash-verified

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