Skip to content

Commit bb53e8b

Browse files
authored
Merge pull request #357 from zachyo/fix-253-contract-implement-asset-transfer-between-branches
Implement asset transfer between branches
2 parents 737a18d + 76bc2d3 commit bb53e8b

31 files changed

+5395
-617
lines changed

.marscode/deviceInfo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deviceId": "7f91adcb12118e2c9981ba3eb11750e017f0b03a54e70479c08f7b5a3e2b3d76"
3+
}

contracts/assetsup/src/asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Asset {
1515
pub name: String,
1616
pub asset_type: AssetType,
1717
pub category: String,
18-
pub branch_id: u64,
18+
pub branch_id: BytesN<32>,
1919
pub department_id: u64,
2020
pub status: AssetStatus,
2121
pub purchase_date: u64,

contracts/assetsup/src/audit.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use soroban_sdk::{Address, BytesN, Env, String, Vec, contracttype};
2+
3+
use crate::types::ActionType;
4+
5+
#[contracttype]
6+
#[derive(Clone, Debug, Eq, PartialEq)]
7+
pub enum DataKey {
8+
AuditLog(BytesN<32>), // Key for asset-specific audit log
9+
}
10+
11+
#[contracttype]
12+
#[derive(Clone, Debug, Eq, PartialEq)]
13+
pub struct AuditEntry {
14+
pub actor: Address,
15+
pub action: ActionType,
16+
pub timestamp: u64,
17+
pub note: String,
18+
}
19+
20+
pub fn log_action(
21+
env: &Env,
22+
asset_id: &BytesN<32>,
23+
actor: Address,
24+
action: ActionType,
25+
note: String,
26+
) {
27+
let key = DataKey::AuditLog(asset_id.clone());
28+
let mut log: Vec<AuditEntry> = env
29+
.storage()
30+
.persistent()
31+
.get(&key)
32+
.unwrap_or_else(|| Vec::new(env));
33+
34+
let entry = AuditEntry {
35+
actor,
36+
action,
37+
timestamp: env.ledger().timestamp(),
38+
note,
39+
};
40+
41+
log.push_back(entry);
42+
env.storage().persistent().set(&key, &log);
43+
}
44+
45+
pub fn get_asset_log(env: &Env, asset_id: &BytesN<32>) -> Vec<AuditEntry> {
46+
let key = DataKey::AuditLog(asset_id.clone());
47+
env.storage()
48+
.persistent()
49+
.get(&key)
50+
.unwrap_or_else(|| Vec::new(env))
51+
}

contracts/assetsup/src/audit_log.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

contracts/assetsup/src/errors.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)