Skip to content

feat: audit reconciliation, branches, transfer history, specific errors - #1687

Merged
yusuftomilola merged 3 commits into
DistinctCodes:mainfrom
khaadish:fix/1497-1500-audit-branch-history-errors
Oct 17, 2026
Merged

yusuftomilola merged 3 commits into
DistinctCodes:mainfrom
khaadish:fix/1497-1500-audit-branch-history-errors

Conversation

@khaadish

@khaadish khaadish commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements khaadish's assigned issues for the assetsup contract.

Closes #1497 — Documented on-chain/off-chain audit reconciliation

audit.rs now documents the contract between the on-chain AuditEntry log and
the backend audit-logs service: the on-chain log is the source of truth, each
entry is identified by (asset_id, action, actor, timestamp), replaying a ledger
range is idempotent under that key, and divergence is resolved in favour of the
chain. details is display-only and must not be used for matching.

Closes #1498 — Branch assignment validates the branch exists

Adds register_branch (admin-gated) and assign_asset_to_branch, which now
rejects an unknown branch with BranchNotFound and an unknown asset with
AssetNotFound before writing. Without the branch check an asset could be
pointed at a stale or misspelled branch id and silently vanish from that
branch's inventory. Adds get_branch / get_branch_assets reads and the
branch_registered / asset_assigned_to_branch events.

Closes #1499 — Queryable on-chain transfer history

transfer_asset_ownership now appends a TransferRecord to a per-asset,
append-only TransferHistory, and get_asset_transfer_history returns it oldest
first. The chain of custody is no longer only reconstructable by replaying
events, and an unknown asset returns AssetNotFound rather than an empty list.

Closes #1500 — Specific error variants

Replaces reused generic variants in insurance with precise ones:
PolicyNotFound, ClaimNotFound, InvalidPolicyStatus, InvalidClaimStatus,
InvalidPolicyTerms, InvalidClaimAmount, PolicyAlreadyExists,
ClaimAlreadyExists. Status-transition failures no longer masquerade as
Unauthorized, and bad policy terms no longer surface as InvalidPayment, so an
integrator can tell causes apart.

Notes

Closes DistinctCodes#1497
Closes DistinctCodes#1498
Closes DistinctCodes#1499
Closes DistinctCodes#1500

- assetsup/audit: document the reconciliation contract between the on-chain
  audit log (the source of truth) and the backend `audit-logs` service,
  including the composite identity that makes replay idempotent and how
  divergence is resolved (DistinctCodes#1497).
- assetsup/branch: add `register_branch` and `assign_asset_to_branch`. The
  latter rejects an unknown branch (`BranchNotFound`) and an unknown asset
  (`AssetNotFound`), so an asset can never be pointed at a stale or misspelled
  branch id. Adds `get_branch`/`get_branch_assets` reads and the
  `branch_registered` / `asset_assigned_to_branch` events (DistinctCodes#1498).
- assetsup/asset: append every ownership change to a per-asset
  `TransferHistory` and expose `get_asset_transfer_history`, so the full chain
  of custody is queryable on-chain and not just the current owner (DistinctCodes#1499).
- assetsup/error + insurance: replace reused generic variants with precise ones
  (`PolicyNotFound`, `ClaimNotFound`, `InvalidPolicyStatus`,
  `InvalidClaimStatus`, `InvalidPolicyTerms`, `InvalidClaimAmount`,
  `PolicyAlreadyExists`, `ClaimAlreadyExists`) so integrators can tell failure
  causes apart (DistinctCodes#1500). Codes 187 onward are allocated, reserving 187 for the
  insurance expiry reminder from DistinctCodes#1491.
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown

@khaadish is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@khaadish Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@yusuftomilola
yusuftomilola merged commit 66b1a3f into DistinctCodes:main Oct 17, 2026
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants