|
| 1 | +// Copyright (c) Zefchain Labs, Inc. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#![cfg_attr(target_arch = "wasm32", no_main)] |
| 5 | + |
| 6 | +mod state; |
| 7 | + |
| 8 | +use linera_sdk::{ |
| 9 | + linera_base_types::WithContractAbi, |
| 10 | + views::{RootView, View}, |
| 11 | + Contract, ContractRuntime, |
| 12 | +}; |
| 13 | +use track_instantiation::TrackInstantiationAbi; |
| 14 | + |
| 15 | +use self::state::TrackInstantiationState; |
| 16 | + |
| 17 | +pub struct TrackInstantiationContract { |
| 18 | + state: TrackInstantiationState, |
| 19 | + runtime: ContractRuntime<Self>, |
| 20 | +} |
| 21 | + |
| 22 | +linera_sdk::contract!(TrackInstantiationContract); |
| 23 | + |
| 24 | +impl WithContractAbi for TrackInstantiationContract { |
| 25 | + type Abi = TrackInstantiationAbi; |
| 26 | +} |
| 27 | + |
| 28 | +impl Contract for TrackInstantiationContract { |
| 29 | + type Message = (); |
| 30 | + type InstantiationArgument = (); |
| 31 | + type Parameters = (); |
| 32 | + type EventValue = (); |
| 33 | + |
| 34 | + async fn load(runtime: ContractRuntime<Self>) -> Self { |
| 35 | + let state = TrackInstantiationState::load(runtime.root_view_storage_context()) |
| 36 | + .await |
| 37 | + .expect("Failed to load state"); |
| 38 | + |
| 39 | + TrackInstantiationContract { state, runtime } |
| 40 | + } |
| 41 | + |
| 42 | + async fn instantiate(&mut self, _argument: ()) { |
| 43 | + self.runtime.application_parameters(); |
| 44 | + |
| 45 | + // Send message to creator chain about instantiation |
| 46 | + let creator_chain = self.runtime.application_creator_chain_id(); |
| 47 | + self.runtime |
| 48 | + .prepare_message(()) |
| 49 | + .with_authentication() |
| 50 | + .send_to(creator_chain); |
| 51 | + } |
| 52 | + |
| 53 | + async fn execute_operation(&mut self, _operation: ()) { |
| 54 | + panic!("No operation being executed"); |
| 55 | + } |
| 56 | + |
| 57 | + async fn execute_message(&mut self, _message: ()) { |
| 58 | + let count = self.state.stats.get_mut(); |
| 59 | + *count += 1; |
| 60 | + } |
| 61 | + |
| 62 | + async fn store(mut self) { |
| 63 | + self.state.save().await.expect("Failed to save state"); |
| 64 | + } |
| 65 | +} |
0 commit comments