spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Support `Accounts` in `Pending` State #467

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

This issue is preparation work for the Self-Spawn. We want SVM to support having an Account in a Pending State (i.e., inactive).

That Account won't have any Template attached to it, and therefore it can't run any code. That said, it can have a non-negative balance and be part of the Global State. To stay efficient, looking up an Account should work the same regardless of whether it's active or not.

This issue turns the current Account into ActiveAccount, creates a new PendingAccount, and adds a new enum called Account.

That enum will enforce giving attention throughout the codebase of whether any Account would work or whether we expect it to be active or pending.

I think it's safer than just having a new is_active boolean added to the current Account.

Implementation Proposal

pub enum Account {
  Active(ActiveAccount),
  Pending(PendingAccount)
}

impl Account {
  pub is_active(&self) -> bool {
     //
  }

  pub is_pending(&self) -> bool {
    !(self.is_active())
  }

  pub addr(&self) -> &Address {
    //
  }

  pub balance(&self) -> u64 {
    //
  }

  pub name(&self) -> &str {
    //
  }

  pub counter(&self) -> u128 {
    //
  }
}