Skip to content

feat(contract): add transfer_meter_ownership function for meter handover #193

Description

@Dev-AdeTutu

Feature Request

Area: Smart Contract
File: contracts/solar_grid/src/lib.rs

Description

Meters are permanently tied to the original owner. There is no way to transfer ownership when a household sells their solar setup or a provider reassigns a meter to a new customer.

Implementation Guide

Add to lib.rs:

pub fn transfer_ownership(env: Env, meter_id: Symbol, new_owner: Address) {
    let key = DataKey::Meter(meter_id);
    let mut meter: Meter = env.storage().persistent().get(&key).expect("meter not found");
    meter.owner.require_auth(); // current owner must sign
    meter.owner = new_owner;
    env.storage().persistent().set(&key, &meter);
}

Ensure the new_owner address is a valid Stellar account before storing.

Definition of Done

  • Current owner can transfer ownership by signing the transaction
  • New owner address stored correctly
  • Old owner can no longer call make_payment without re-auth
  • Unit test covers transfer and subsequent payment by new owner
  • Unit test verifies unauthorized transfer is rejected

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions