Skip to content

Implement asset transfer between branches#357

Merged
truthixify merged 5 commits intoDistinctCodes:mainfrom
zachyo:fix-253-contract-implement-asset-transfer-between-branches
Oct 5, 2025
Merged

Implement asset transfer between branches#357
truthixify merged 5 commits intoDistinctCodes:mainfrom
zachyo:fix-253-contract-implement-asset-transfer-between-branches

Conversation

@zachyo
Copy link
Copy Markdown
Contributor

@zachyo zachyo commented Oct 4, 2025

Description

This pull request implements the ability to transfer assets between different branches within the system. A new transfer_asset function allows an asset owner or an admin to move an asset to a new branch. The implementation ensures that the asset is correctly removed from the old branch's asset list and added to the new one. To ensure accountability, all asset transfers are now recorded in an audit log.

Additionally, a bug was identified and fixed where the branch_id in the Asset struct had a type mismatch (u64 instead of BytesN<32>), which would have prevented the transfer functionality from working correctly. Existing tests were updated to reflect this fix.

Changes Made

  • Implemented transfer_asset Function: Added a new function to the AssetUpContract to handle the transfer of assets between branches.
  • Added Audit Log: Created a new audit module to log asset transfers. Each log entry includes the actor performing the action, the action type (Transferred), and the timestamp of the transaction.
  • Enforced Access Control: The transfer_asset function can only be executed by the owner of the asset or the contract admin, ensuring that only
    authorized users can perform transfers.
  • Fixed branch_id Type Mismatch: Corrected the type of branch_id in the Asset struct from u64 to BytesN<32> to align with the branch ID type used throughout the contract.
  • Comprehensive Tests: A new test suite (tests/transfer.rs) was created to validate the asset transfer functionality and all existing tests were updated to align with the branch_id type fix, ensuring the entire test suite remains consistent and robust.

Testing

A new test file, tests/transfer.rs, was added with comprehensive tests for the asset transfer functionality, including:

  • Successful transfer by the asset owner.
  • Successful transfer by the contract admin.
  • Unauthorized transfer attempts.
  • Transferring an asset to the same branch (no-op).
  • Attempting to transfer a non-existent asset.
  • Attempting to transfer an asset to a non-existent branch.

Closes #253

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 4, 2025

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

A member of the Team first needs to authorize it.

@truthixify
Copy link
Copy Markdown
Collaborator

@zachyo

The CI is failing, please fix it.

@zachyo
Copy link
Copy Markdown
Contributor Author

zachyo commented Oct 5, 2025

@truthixify all checks fixed

@truthixify truthixify merged commit bb53e8b into DistinctCodes:main Oct 5, 2025
4 of 5 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

Development

Successfully merging this pull request may close these issues.

[CONTRACT] Implement Asset Transfer Between Branches

2 participants