Skip to content

Commit 31ea0c3

Browse files
authored
Add State suffix to template's state type (#2987)
* Add `State` suffix to template's state type The `Contract` and `Service` traits are no longer implemented for that type, so the type no longer represents the application itself. Make it clearer that the type just holds the application's persisted state. * Add `State` suffix to AMM state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to Counter state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to Crowd-Funding state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to Etherum-Tracker state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to Fungible Token state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to GenNFT state type Use the new convention of adding a `State` suffix to the suffix types. * Remove `state` module from LLM example It is not used anywhere. * Add `State` suffix to Matching Engine state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to NonFungible Token state type Use the new convention of adding a `State` suffix to the suffix types. * Add `State` suffix to Social state type Use the new convention of adding a `State` suffix to the suffix types.
1 parent 8e5e236 commit 31ea0c3

File tree

35 files changed

+79
-91
lines changed

35 files changed

+79
-91
lines changed

examples/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/amm/src/contract.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use linera_sdk::{
1515
use num_bigint::BigUint;
1616
use num_traits::{cast::FromPrimitive, ToPrimitive};
1717

18-
use self::state::Amm;
18+
use self::state::AmmState;
1919

2020
pub struct AmmContract {
21-
state: Amm,
21+
state: AmmState,
2222
runtime: ContractRuntime<Self>,
2323
}
2424

@@ -34,7 +34,7 @@ impl Contract for AmmContract {
3434
type Parameters = Parameters;
3535

3636
async fn load(runtime: ContractRuntime<Self>) -> Self {
37-
let state = Amm::load(runtime.root_view_storage_context())
37+
let state = AmmState::load(runtime.root_view_storage_context())
3838
.await
3939
.expect("Failed to load state");
4040
AmmContract { state, runtime }

examples/amm/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use linera_sdk::{
1313
base::WithServiceAbi, graphql::GraphQLMutationRoot, views::View, Service, ServiceRuntime,
1414
};
1515

16-
use self::state::Amm;
16+
use self::state::AmmState;
1717

1818
pub struct AmmService {
19-
state: Arc<Amm>,
19+
state: Arc<AmmState>,
2020
}
2121

2222
linera_sdk::service!(AmmService);
@@ -29,7 +29,7 @@ impl Service for AmmService {
2929
type Parameters = Parameters;
3030

3131
async fn new(runtime: ServiceRuntime<Self>) -> Self {
32-
let state = Amm::load(runtime.root_view_storage_context())
32+
let state = AmmState::load(runtime.root_view_storage_context())
3333
.await
3434
.expect("Failed to load state");
3535
AmmService {

examples/amm/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use linera_sdk::{
99

1010
#[derive(RootView, async_graphql::SimpleObject)]
1111
#[view(context = "ViewStorageContext")]
12-
pub struct Amm {
12+
pub struct AmmState {
1313
pub shares: MapView<Account, Amount>,
1414
pub total_shares_supply: RegisterView<Amount>,
1515
}

examples/counter/src/contract.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use linera_sdk::{
1212
Contract, ContractRuntime,
1313
};
1414

15-
use self::state::Counter;
15+
use self::state::CounterState;
1616

1717
pub struct CounterContract {
18-
state: Counter,
18+
state: CounterState,
1919
runtime: ContractRuntime<Self>,
2020
}
2121

@@ -31,7 +31,7 @@ impl Contract for CounterContract {
3131
type Parameters = ();
3232

3333
async fn load(runtime: ContractRuntime<Self>) -> Self {
34-
let state = Counter::load(runtime.root_view_storage_context())
34+
let state = CounterState::load(runtime.root_view_storage_context())
3535
.await
3636
.expect("Failed to load state");
3737
CounterContract { state, runtime }
@@ -64,7 +64,7 @@ mod tests {
6464
use futures::FutureExt as _;
6565
use linera_sdk::{util::BlockingWait, views::View, Contract, ContractRuntime};
6666

67-
use super::{Counter, CounterContract};
67+
use super::{CounterContract, CounterState};
6868

6969
#[test]
7070
fn operation() {
@@ -117,7 +117,7 @@ mod tests {
117117
fn create_and_instantiate_counter(initial_value: u64) -> CounterContract {
118118
let runtime = ContractRuntime::new().with_application_parameters(());
119119
let mut contract = CounterContract {
120-
state: Counter::load(runtime.root_view_storage_context())
120+
state: CounterState::load(runtime.root_view_storage_context())
121121
.blocking_wait()
122122
.expect("Failed to read from mock key value store"),
123123
runtime,

examples/counter/src/service.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ mod state;
88
use async_graphql::{EmptySubscription, Object, Request, Response, Schema};
99
use linera_sdk::{base::WithServiceAbi, views::View, Service, ServiceRuntime};
1010

11-
use self::state::Counter;
11+
use self::state::CounterState;
1212

1313
pub struct CounterService {
14-
state: Counter,
14+
state: CounterState,
1515
}
1616

1717
linera_sdk::service!(CounterService);
@@ -24,7 +24,7 @@ impl Service for CounterService {
2424
type Parameters = ();
2525

2626
async fn new(runtime: ServiceRuntime<Self>) -> Self {
27-
let state = Counter::load(runtime.root_view_storage_context())
27+
let state = CounterState::load(runtime.root_view_storage_context())
2828
.await
2929
.expect("Failed to load state");
3030
CounterService { state }
@@ -70,13 +70,13 @@ mod tests {
7070
use linera_sdk::{util::BlockingWait, views::View, Service, ServiceRuntime};
7171
use serde_json::json;
7272

73-
use super::{Counter, CounterService};
73+
use super::{CounterService, CounterState};
7474

7575
#[test]
7676
fn query() {
7777
let value = 61_098_721_u64;
7878
let runtime = ServiceRuntime::<CounterService>::new();
79-
let mut state = Counter::load(runtime.root_view_storage_context())
79+
let mut state = CounterState::load(runtime.root_view_storage_context())
8080
.blocking_wait()
8181
.expect("Failed to read from mock key value store");
8282
state.value.set(value);

examples/counter/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ use linera_sdk::views::{linera_views, RegisterView, RootView, ViewStorageContext
66
/// The application state.
77
#[derive(RootView)]
88
#[view(context = "ViewStorageContext")]
9-
pub struct Counter {
9+
pub struct CounterState {
1010
pub value: RegisterView<u64>,
1111
}

examples/crowd-funding/src/contract.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use linera_sdk::{
1212
views::{RootView, View},
1313
Contract, ContractRuntime,
1414
};
15-
use state::{CrowdFunding, Status};
15+
use state::{CrowdFundingState, Status};
1616

1717
pub struct CrowdFundingContract {
18-
state: CrowdFunding,
18+
state: CrowdFundingState,
1919
runtime: ContractRuntime<Self>,
2020
}
2121

@@ -31,7 +31,7 @@ impl Contract for CrowdFundingContract {
3131
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;
3232

3333
async fn load(runtime: ContractRuntime<Self>) -> Self {
34-
let state = CrowdFunding::load(runtime.root_view_storage_context())
34+
let state = CrowdFundingState::load(runtime.root_view_storage_context())
3535
.await
3636
.expect("Failed to load state");
3737
CrowdFundingContract { state, runtime }

examples/crowd-funding/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use linera_sdk::{
1515
views::View,
1616
Service, ServiceRuntime,
1717
};
18-
use state::CrowdFunding;
18+
use state::CrowdFundingState;
1919

2020
pub struct CrowdFundingService {
21-
state: Arc<CrowdFunding>,
21+
state: Arc<CrowdFundingState>,
2222
}
2323

2424
linera_sdk::service!(CrowdFundingService);
@@ -31,7 +31,7 @@ impl Service for CrowdFundingService {
3131
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;
3232

3333
async fn new(runtime: ServiceRuntime<Self>) -> Self {
34-
let state = CrowdFunding::load(runtime.root_view_storage_context())
34+
let state = CrowdFundingState::load(runtime.root_view_storage_context())
3535
.await
3636
.expect("Failed to load state");
3737
CrowdFundingService {

examples/crowd-funding/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ scalar!(Status);
2626
/// The crowd-funding campaign's state.
2727
#[derive(RootView, async_graphql::SimpleObject)]
2828
#[view(context = "ViewStorageContext")]
29-
pub struct CrowdFunding {
29+
pub struct CrowdFundingState {
3030
/// The status of the campaign.
3131
pub status: RegisterView<Status>,
3232
/// The map of pledges that will be collected if the campaign succeeds.

0 commit comments

Comments
 (0)