Skip to content

Commit

Permalink
Remove InitializationArgument/Parameters from ContractAbi/ServiceAbi (#…
Browse files Browse the repository at this point in the history
…1844)

## Motivation

#1839

## Proposal

Remove them from `ContractAbi`

## Test Plan

CI
  • Loading branch information
Andre da Silva authored Apr 4, 2024
1 parent 350bdae commit 8c3a20b
Show file tree
Hide file tree
Showing 49 changed files with 341 additions and 209 deletions.
4 changes: 3 additions & 1 deletion examples/amm/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

mod state;

use amm::{AmmAbi, AmmError, Message, Operation};
use amm::{AmmAbi, AmmError, Message, Operation, Parameters};
use async_trait::async_trait;
use fungible::{Account, FungibleTokenAbi};
use linera_sdk::{
Expand Down Expand Up @@ -34,6 +34,8 @@ impl Contract for AmmContract {
type Storage = ViewStateStorage<Self>;
type State = Amm;
type Message = Message;
type InitializationArgument = ();
type Parameters = Parameters;

async fn new(state: Amm, runtime: ContractRuntime<Self>) -> Result<Self, Self::Error> {
Ok(AmmContract { state, runtime })
Expand Down
3 changes: 0 additions & 3 deletions examples/amm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,13 @@ use thiserror::Error;
pub struct AmmAbi;

impl ContractAbi for AmmAbi {
type InitializationArgument = ();
type Parameters = Parameters;
type Operation = Operation;
type Response = ();
}

impl ServiceAbi for AmmAbi {
type Query = Request;
type QueryResponse = Response;
type Parameters = Parameters;
}

/// Operations that can be sent to the application.
Expand Down
3 changes: 2 additions & 1 deletion examples/amm/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod state;

use std::sync::Arc;

use amm::{AmmError, Operation};
use amm::{AmmError, Operation, Parameters};
use async_graphql::{EmptySubscription, Object, Request, Response, Schema};
use linera_sdk::{base::WithServiceAbi, Service, ServiceRuntime, ViewStateStorage};

Expand All @@ -27,6 +27,7 @@ impl Service for AmmService {
type Error = AmmError;
type Storage = ViewStateStorage<Self>;
type State = Amm;
type Parameters = Parameters;

async fn new(state: Self::State, _runtime: ServiceRuntime<Self>) -> Result<Self, Self::Error> {
Ok(AmmService {
Expand Down
2 changes: 2 additions & 0 deletions examples/counter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl Contract for CounterContract {
type Storage = SimpleStateStorage<Self>;
type State = Counter;
type Message = ();
type InitializationArgument = u64;
type Parameters = ();

async fn new(state: Counter, runtime: ContractRuntime<Self>) -> Result<Self, Self::Error> {
Ok(CounterContract { state, runtime })
Expand Down
3 changes: 0 additions & 3 deletions examples/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ use linera_sdk::base::{ContractAbi, ServiceAbi};
pub struct CounterAbi;

impl ContractAbi for CounterAbi {
type InitializationArgument = u64;
type Parameters = ();
type Operation = u64;
type Response = u64;
}

impl ServiceAbi for CounterAbi {
type Query = Request;
type QueryResponse = Response;
type Parameters = ();
}
1 change: 1 addition & 0 deletions examples/counter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Service for CounterService {
type Error = Error;
type Storage = SimpleStateStorage<Self>;
type State = Counter;
type Parameters = ();

async fn new(state: Self::State, _runtime: ServiceRuntime<Self>) -> Result<Self, Self::Error> {
Ok(CounterService { state })
Expand Down
5 changes: 3 additions & 2 deletions examples/counter/tests/single_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use linera_sdk::test::TestValidator;
/// which is then checked.
#[tokio::test(flavor = "multi_thread")]
async fn single_chain_test() {
let (validator, bytecode_id) = TestValidator::with_current_bytecode().await;
let (validator, bytecode_id) =
TestValidator::with_current_bytecode::<counter::CounterAbi, (), u64>().await;
let mut chain = validator.new_chain().await;

let initial_state = 42u64;
let application_id = chain
.create_application::<counter::CounterAbi>(bytecode_id, (), initial_state, vec![])
.create_application(bytecode_id, (), initial_state, vec![])
.await;

let increment = 15u64;
Expand Down
2 changes: 2 additions & 0 deletions examples/crowd-funding/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl Contract for CrowdFundingContract {
type Storage = ViewStateStorage<Self>;
type State = CrowdFunding;
type Message = Message;
type InitializationArgument = InitializationArgument;
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;

async fn new(state: CrowdFunding, runtime: ContractRuntime<Self>) -> Result<Self, Self::Error> {
Ok(CrowdFundingContract { state, runtime })
Expand Down
5 changes: 1 addition & 4 deletions examples/crowd-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,19 @@ query {

use async_graphql::{Request, Response, SimpleObject};
use linera_sdk::{
base::{AccountOwner, Amount, ApplicationId, ContractAbi, ServiceAbi, Timestamp},
base::{AccountOwner, Amount, ContractAbi, ServiceAbi, Timestamp},
graphql::GraphQLMutationRoot,
};
use serde::{Deserialize, Serialize};

pub struct CrowdFundingAbi;

impl ContractAbi for CrowdFundingAbi {
type InitializationArgument = InitializationArgument;
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;
type Operation = Operation;
type Response = ();
}

impl ServiceAbi for CrowdFundingAbi {
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;
type Query = Request;
type QueryResponse = Response;
}
Expand Down
5 changes: 4 additions & 1 deletion examples/crowd-funding/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use std::sync::Arc;
use async_graphql::{EmptySubscription, Request, Response, Schema};
use crowd_funding::Operation;
use linera_sdk::{
base::WithServiceAbi, graphql::GraphQLMutationRoot, Service, ServiceRuntime, ViewStateStorage,
base::{ApplicationId, WithServiceAbi},
graphql::GraphQLMutationRoot,
Service, ServiceRuntime, ViewStateStorage,
};
use state::CrowdFunding;
use thiserror::Error;
Expand All @@ -29,6 +31,7 @@ impl Service for CrowdFundingService {
type Error = Error;
type Storage = ViewStateStorage<Self>;
type State = CrowdFunding;
type Parameters = ApplicationId<fungible::FungibleTokenAbi>;

async fn new(state: Self::State, _runtime: ServiceRuntime<Self>) -> Result<Self, Self::Error> {
Ok(CrowdFundingService {
Expand Down
21 changes: 16 additions & 5 deletions examples/crowd-funding/tests/campaign_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use std::iter;

use crowd_funding::{CrowdFundingAbi, InitializationArgument, Operation};
use fungible::FungibleTokenAbi;
use linera_sdk::{
base::{AccountOwner, Amount, Timestamp},
base::{AccountOwner, Amount, ApplicationId, Timestamp},
test::TestValidator,
};

Expand All @@ -24,7 +25,12 @@ async fn collect_pledges() {
let target_amount = Amount::from_tokens(220);
let pledge_amount = Amount::from_tokens(75);

let (validator, bytecode_id) = TestValidator::with_current_bytecode().await;
let (validator, bytecode_id) = TestValidator::with_current_bytecode::<
CrowdFundingAbi,
ApplicationId<FungibleTokenAbi>,
InitializationArgument,
>()
.await;

let fungible_publisher_chain = validator.new_chain().await;
let mut campaign_chain = validator.new_chain().await;
Expand All @@ -47,7 +53,7 @@ async fn collect_pledges() {
target: target_amount,
};
let campaign_id = campaign_chain
.create_application::<CrowdFundingAbi>(
.create_application(
bytecode_id,
token_id,
campaign_state,
Expand Down Expand Up @@ -121,7 +127,12 @@ async fn cancel_successful_campaign() {
let target_amount = Amount::from_tokens(220);
let pledge_amount = Amount::from_tokens(75);

let (validator, bytecode_id) = TestValidator::with_current_bytecode().await;
let (validator, bytecode_id) = TestValidator::with_current_bytecode::<
CrowdFundingAbi,
ApplicationId<FungibleTokenAbi>,
InitializationArgument,
>()
.await;

let fungible_publisher_chain = validator.new_chain().await;
let mut campaign_chain = validator.new_chain().await;
Expand All @@ -144,7 +155,7 @@ async fn cancel_successful_campaign() {
target: target_amount,
};
let campaign_id = campaign_chain
.create_application::<CrowdFundingAbi>(
.create_application(
bytecode_id,
token_id,
campaign_state,
Expand Down
6 changes: 5 additions & 1 deletion examples/fungible/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ mod state;
use std::str::FromStr;

use async_trait::async_trait;
use fungible::{Account, FungibleResponse, FungibleTokenAbi, Message, Operation};
use fungible::{
Account, FungibleResponse, FungibleTokenAbi, InitialState, Message, Operation, Parameters,
};
use linera_sdk::{
base::{AccountOwner, Amount, WithContractAbi},
ensure, Contract, ContractRuntime, ViewStateStorage,
Expand All @@ -34,6 +36,8 @@ impl Contract for FungibleTokenContract {
type Storage = ViewStateStorage<Self>;
type State = FungibleToken;
type Message = Message;
type Parameters = Parameters;
type InitializationArgument = InitialState;

async fn new(
state: FungibleToken,
Expand Down
2 changes: 1 addition & 1 deletion examples/fungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub enum Message {
#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
pub async fn create_with_accounts(
validator: &TestValidator,
bytecode_id: BytecodeId<FungibleTokenAbi>,
bytecode_id: BytecodeId<FungibleTokenAbi, Parameters, InitialState>,
initial_amounts: impl IntoIterator<Item = Amount>,
) -> (
ApplicationId<FungibleTokenAbi>,
Expand Down
3 changes: 2 additions & 1 deletion examples/fungible/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod state;
use std::sync::{Arc, Mutex};

use async_graphql::{EmptySubscription, Object, Request, Response, Schema};
use fungible::Operation;
use fungible::{Operation, Parameters};
use linera_sdk::{
base::{AccountOwner, Amount, WithServiceAbi},
graphql::GraphQLMutationRoot,
Expand All @@ -35,6 +35,7 @@ impl Service for FungibleTokenService {
type Error = Error;
type Storage = ViewStateStorage<Self>;
type State = FungibleToken;
type Parameters = Parameters;

async fn new(state: Self::State, runtime: ServiceRuntime<Self>) -> Result<Self, Self::Error> {
Ok(FungibleTokenService {
Expand Down
28 changes: 13 additions & 15 deletions examples/fungible/tests/cross_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#![cfg(not(target_arch = "wasm32"))]

use fungible::{Account, InitialStateBuilder, Operation, Parameters};
use fungible::{
Account, FungibleTokenAbi, InitialState, InitialStateBuilder, Operation, Parameters,
};
use linera_sdk::{
base::{AccountOwner, Amount},
test::TestValidator,
Expand All @@ -21,19 +23,19 @@ async fn test_cross_chain_transfer() {
let initial_amount = Amount::from_tokens(20);
let transfer_amount = Amount::from_tokens(15);

let (validator, bytecode_id) = TestValidator::with_current_bytecode().await;
let (validator, bytecode_id) = TestValidator::with_current_bytecode::<
fungible::FungibleTokenAbi,
Parameters,
InitialState,
>()
.await;
let mut sender_chain = validator.new_chain().await;
let sender_account = AccountOwner::from(sender_chain.public_key());

let initial_state = InitialStateBuilder::default().with_account(sender_account, initial_amount);
let params = Parameters::new("FUN");
let application_id = sender_chain
.create_application::<fungible::FungibleTokenAbi>(
bytecode_id,
params,
initial_state.build(),
vec![],
)
.create_application(bytecode_id, params, initial_state.build(), vec![])
.await;

let receiver_chain = validator.new_chain().await;
Expand Down Expand Up @@ -79,19 +81,15 @@ async fn test_bouncing_tokens() {
let initial_amount = Amount::from_tokens(19);
let transfer_amount = Amount::from_tokens(7);

let (validator, bytecode_id) = TestValidator::with_current_bytecode().await;
let (validator, bytecode_id) =
TestValidator::with_current_bytecode::<FungibleTokenAbi, Parameters, InitialState>().await;
let mut sender_chain = validator.new_chain().await;
let sender_account = AccountOwner::from(sender_chain.public_key());

let initial_state = InitialStateBuilder::default().with_account(sender_account, initial_amount);
let params = Parameters::new("RET");
let application_id = sender_chain
.create_application::<fungible::FungibleTokenAbi>(
bytecode_id,
params,
initial_state.build(),
vec![],
)
.create_application(bytecode_id, params, initial_state.build(), vec![])
.await;

let receiver_chain = validator.new_chain().await;
Expand Down
5 changes: 4 additions & 1 deletion examples/matching-engine/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use linera_sdk::{
ensure, Contract, ContractRuntime, ViewStateStorage,
};
use matching_engine::{
product_price_amount, MatchingEngineAbi, Message, Operation, Order, OrderId, OrderNature, Price,
product_price_amount, MatchingEngineAbi, Message, Operation, Order, OrderId, OrderNature,
Parameters, Price,
};
use state::{LevelView, MatchingEngine, MatchingEngineError};

Expand Down Expand Up @@ -56,6 +57,8 @@ impl Contract for MatchingEngineContract {
type Storage = ViewStateStorage<Self>;
type State = MatchingEngine;
type Message = Message;
type InitializationArgument = ();
type Parameters = Parameters;

async fn new(
state: MatchingEngine,
Expand Down
3 changes: 0 additions & 3 deletions examples/matching-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,11 @@ use serde::{Deserialize, Serialize};
pub struct MatchingEngineAbi;

impl ContractAbi for MatchingEngineAbi {
type InitializationArgument = ();
type Parameters = Parameters;
type Operation = Operation;
type Response = ();
}

impl ServiceAbi for MatchingEngineAbi {
type Parameters = Parameters;
type Query = Request;
type QueryResponse = Response;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/matching-engine/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use async_graphql::{EmptySubscription, Request, Response, Schema};
use linera_sdk::{
base::WithServiceAbi, graphql::GraphQLMutationRoot, Service, ServiceRuntime, ViewStateStorage,
};
use matching_engine::Operation;
use matching_engine::{Operation, Parameters};

use crate::state::{MatchingEngine, MatchingEngineError};

Expand All @@ -29,6 +29,7 @@ impl Service for MatchingEngineService {
type Error = MatchingEngineError;
type Storage = ViewStateStorage<Self>;
type State = MatchingEngine;
type Parameters = Parameters;

async fn new(state: Self::State, _runtime: ServiceRuntime<Self>) -> Result<Self, Self::Error> {
Ok(MatchingEngineService {
Expand Down
Loading

0 comments on commit 8c3a20b

Please sign in to comment.