-
Notifications
You must be signed in to change notification settings - Fork 3
RailRoad Implementation #16
Copy link
Copy link
Open
Description
📌 Issue: Complete Implementation of RailRoadTrait for Railroad Model
🧩 Description
The RailRoadTrait defines key functionalities for managing railroad properties in the game. While the structure is in place, the methods are currently incomplete or incorrectly defined ( missing logic).
This issue tracks the implementation and correction of all trait functions.
✅ Acceptance Criteria
-
change_railroad_ownership()should:- Use
ref selfto mutate theownerfield. - Validate that the caller is the current owner.
- Only allow ownership change if
for_saleis true andis_mortgagedis false.
- Use
-
get_rent_amount()should:- Be a pure/read-only method (no
mut). - Return correct rent based on how many railroads are owned (1 to 4).
- Return
0if the railroad is mortgaged.
- Be a pure/read-only method (no
-
mortgage()andlift_mortgage()should:- Use
ref selfto mutateis_mortgaged. - Ensure caller is the current owner before modifying.
- Use
🛠️ Example Fixes
fn change_railroad_ownership(ref self: RailRoad, new_owner: ContractAddress, owner: ContractAddress) -> bool {
if self.owner != owner || self.is_mortgaged || !self.for_sale {
return false;
}
self.owner = new_owner;
self.for_sale = false;
true
}
fn get_rent_amount(railroad: RailRoad, railroad_owned: u8) -> u256 {
if railroad.is_mortgaged {
return 0;
}
match railroad_owned {
1 => 25,
2 => 50,
3 => 100,
4 => 200,
_ => 0,
}
}
fn mortgage(ref self: RailRoad, owner: ContractAddress) {
if self.owner == owner {
self.is_mortgaged = true;
}
}
fn lift_mortgage(ref self: RailRoad, owner: ContractAddress) {
if self.owner == owner {
self.is_mortgaged = false;
}
}📘 Status
Build: ✅ Should build successfully
Validation: 🚧 Pending full logic implementation
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels