Skip to content

RailRoad Implementation #16

@blurbeast

Description

@blurbeast

📌 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 self to mutate the owner field.
    • Validate that the caller is the current owner.
    • Only allow ownership change if for_sale is true and is_mortgaged is false.
  • 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 0 if the railroad is mortgaged.
  • mortgage() and lift_mortgage() should:

    • Use ref self to mutate is_mortgaged.
    • Ensure caller is the current owner before modifying.

🛠️ 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


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions