Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Extend the Runtime to create a new Account with its Immutable Data (for Non-Self Spawn) #477

Open
YaronWittenstein opened this issue Dec 22, 2021 · 0 comments
Assignees
Labels
AA Related to the Accounts Abstraction simple-coin-iteration-3 svm svm-core SVM core change

Comments

@YaronWittenstein
Copy link
Contributor

YaronWittenstein commented Dec 22, 2021

Depends on: #470 #471

When we run a Spawn Transaction (the Non-Self Spawn if to be precise) we want to create the Account
and assign it its immutable_data given in the transaction input.

For now, we'll set the TxKind to TxKind::Spawn since we don't support the Self-Spawn yet.
For more info about TxKind see issue #470

impl Runtime {
  pub fn spawn(
        &mut self,
        envelope: &Envelope,
        message: &[u8],
        context: &Context,
    ) -> SpawnReceipt { 
  info!("Runtime `spawn`");

  let gas_left = GasTank::new(envelope.gas_limit());
  let spawn = SpawnAccount::decode_bytes(message).expect(ERR_VALIDATE_SPAWN);

  // If the `Principal` is a `Pending Account` (a.k.a a `Stub Account`)
  // then we say we're running a `Self-Spawn` transaction.
  let self_spawn = ...

  if self_spawn {
    todo!("Simple Coin Iteration #4")
  }
  else {
    // now the `self.create_account` expects an additional `immutable_data` param
    self.create_account(
            &target,
            template_addr.clone(),
            account.name().to_string(),
            0,
            0,
            &spawn.immutable_data;
        )
        .unwrap();

     self.call_ctor(&spawn, target, envelope, context, gas_left)
   }
 }

 pub fn create_account(
        &mut self,
        account_addr: &Address,
        template_addr: TemplateAddr,
        name: String,
        balance: u64,
        counter: u128,
        immutable_data: &[u8] 
    ) -> Result<()> {
   let mut account = AccountStorage::create(
            self.gs.clone(),
            account_addr,
            name,
            template_addr,
            balance,
            counter,
        )
        .unwrap();

    // We might want `AccountStorage::create` to receive `immutable_data`.
    // as a parameter, at at least as `Option<Vec<u8>>>` (when creating a `Pending Account`) 
    // However, the `Pending Account` is part of the `Self-Spawn` or `Simple Coin Iteration #4`
    account.set_immutable(immutable_data);

    Ok(())
  }
}
@YaronWittenstein YaronWittenstein added AA Related to the Accounts Abstraction simple-coin-iteration-3 svm svm-core SVM core change labels Dec 22, 2021
@YaronWittenstein YaronWittenstein changed the title Store Account Immutable Data only after a successful ctor run Extend the Runtime to create a new Account with its Immutable Data (for Non-Self Spawn) Dec 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AA Related to the Accounts Abstraction simple-coin-iteration-3 svm svm-core SVM core change
Projects
None yet
Development

No branches or pull requests

2 participants