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

Moving from App to Account terminology - Part 1 #274

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/codec/src/api/builder/app_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use svm_types::{App, SpawnApp, TemplateAddr};
use svm_types::{Account, SpawnApp, TemplateAddr};

use crate::app;

Expand All @@ -18,12 +18,12 @@ pub struct SpawnAppBuilder {
/// ```rust
/// use std::io::Cursor;
///
/// use svm_types::{App, SpawnApp, Address};
/// use svm_types::{Account, SpawnApp, Address};
/// use svm_codec::api::builder::SpawnAppBuilder;
/// use svm_codec::app;
///
/// let template_addr = Address::of("@template").into();
/// let name = "My App".to_string();
/// let name = "My Account".to_string();
/// let ctor_name = "initialize";
/// let calldata = vec![0x10, 0x20, 0x30];
///
Expand All @@ -39,7 +39,7 @@ pub struct SpawnAppBuilder {
/// let actual = app::decode(&mut cursor).unwrap();
/// let expected = SpawnApp {
/// version: 0,
/// app: App { name, template_addr },
/// app: Account { name, template_addr },
/// ctor_name: ctor_name.to_string(),
/// calldata,
/// };
Expand Down Expand Up @@ -98,7 +98,7 @@ impl SpawnAppBuilder {

let spawn = SpawnApp {
version,
app: App::new(template_addr, name),
app: Account::new(template_addr, name),
ctor_name,
calldata,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/codec/src/api/json/spawn_app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::Cursor;

use svm_types::{App, SpawnApp};
use svm_types::{Account, SpawnApp};

use serde_json::{json, Value};

Expand Down Expand Up @@ -29,7 +29,7 @@ pub fn encode_spawn_app(json: &Value) -> Result<Vec<u8>, JsonError> {

let spawn = SpawnApp {
version,
app: App::new(template, name),
app: Account::new(template, name),
ctor_name,
calldata,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/codec/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use std::io::Cursor;

use svm_types::{App, SpawnApp, TemplateAddr};
use svm_types::{Account, SpawnApp, TemplateAddr};

use crate::{calldata, version};
use crate::{Field, ParseError, ReadExt, WriteExt};
Expand All @@ -39,7 +39,7 @@ pub fn decode(cursor: &mut Cursor<&[u8]>) -> Result<SpawnApp, ParseError> {
let ctor_name = decode_ctor(cursor)?;
let calldata = decode_ctor_calldata(cursor)?;

let app = App {
let app = Account {
name,
template_addr,
};
Expand Down Expand Up @@ -130,7 +130,7 @@ mod tests {
fn encode_decode_spawn_app() {
let spawn = SpawnApp {
version: 0,
app: App {
app: Account {
name: "my-app".to_string(),
template_addr: Address::of("my-template").into(),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/runtime/src/env/default/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Cursor;
use svm_codec::{ReadExt, WriteExt};

use svm_codec::template;
use svm_types::{App, SectionKind, SpawnerAddr, Template, TemplateAddr};
use svm_types::{Account, SectionKind, SpawnerAddr, Template, TemplateAddr};

use crate::env::{self, traits};

Expand Down Expand Up @@ -66,7 +66,7 @@ impl AppDeserializer for DefaultAppDeserializer {
_ => return None,
};

let base = App::new(template, name);
let base = Account::new(template, name);
let app = ExtApp::new(&base, &spawner);

Some(app)
Expand Down
10 changes: 5 additions & 5 deletions crates/runtime/src/env/ext.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use svm_types::{App, SpawnApp, SpawnerAddr, TemplateAddr};
use svm_types::{Account, SpawnApp, SpawnerAddr, TemplateAddr};

pub struct ExtApp {
base: App,
base: Account,

spawner: SpawnerAddr,
}

impl ExtApp {
pub fn new(base: &App, spawner: &SpawnerAddr) -> Self {
pub fn new(base: &Account, spawner: &SpawnerAddr) -> Self {
Self {
base: base.clone(),
spawner: spawner.clone(),
}
}

pub fn base(&self) -> &App {
pub fn base(&self) -> &Account {
&self.base
}

Expand Down Expand Up @@ -49,7 +49,7 @@ impl ExtSpawnApp {
&self.base
}

pub fn app(&self) -> &App {
pub fn app(&self) -> &Account {
self.base.app()
}

Expand Down
12 changes: 6 additions & 6 deletions crates/types/src/app.rs → crates/types/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use crate::TemplateAddr;

/// An in-memory representation of an app.
#[derive(PartialEq, Clone)]
pub struct App {
/// `App`'s name
pub struct Account {
/// [`Account`]'s name
pub name: String,

/// `Address` of the `Template`, the App is being spawned from.
/// Address of the `Template`, the [`Account`] is being spawned from.
pub template_addr: TemplateAddr,
}

#[doc(hidden)]
impl App {
impl Account {
pub fn new(template_addr: TemplateAddr, name: String) -> Self {
Self {
name,
Expand All @@ -30,9 +30,9 @@ impl App {
}
}

impl fmt::Debug for App {
impl fmt::Debug for Account {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("App")
f.debug_struct("Account")
.field("name", &self.name())
.field("template", self.template_addr().inner())
.finish()
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#[macro_use]
mod macros;

mod account;
mod address;
mod address_of;
mod app;
mod error;
mod spawn_app;
mod state;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub use receipt::{
pub use address::{Address, AppAddr, DeployerAddr, SpawnerAddr, TemplateAddr};
pub use address_of::AddressOf;

pub use app::App;
pub use account::Account;
pub use spawn_app::SpawnApp;
pub use state::State;
pub use template::{
Expand Down
8 changes: 4 additions & 4 deletions crates/types/src/spawn_app.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::fmt;

use crate::{App, TemplateAddr};
use crate::{Account, TemplateAddr};

/// Struct representation of the parsed raw Spawn-App.
/// Struct representation of the parsed raw Spawn-Account.
#[derive(PartialEq)]
pub struct SpawnApp {
/// Transaction format version
pub version: u16,

/// Holds all `SpawnApp` non-ctor_name related data.
pub app: App,
pub app: Account,

/// ctor function name
pub ctor_name: String,
Expand All @@ -20,7 +20,7 @@ pub struct SpawnApp {

#[doc(hidden)]
impl SpawnApp {
pub fn app(&self) -> &App {
pub fn app(&self) -> &Account {
&self.app
}

Expand Down