Skip to content

Commit 7b6e921

Browse files
Remove the Account duplication. (#4403)
## Motivation We have the `Account` in two contexts: * The `linera-sdk/src/abis/fungible.rs` * The `linera-base/src/identifiers.rs` which is not great. This PR unifies both types. Fixes #2496 Fixes #3462 ## Proposal It is a given fact that in Linera, we will have a type `Account` that contains both the `ChainId` and the `AccountOwner`. An additional complication is that GraphQL forces to have one type in input and another type in output. The current design is to use the `fungible::Account` for the GraphQL with the following (simplified) design: ```rust #[derive(SimpleObject, InputObject)] #[graphql(input_name = "FungibleAccount")] struct Account { .... } ``` with this design the input type is `FungibleAccount` and the output type is `Account`. This is inadequate since an account could have many usage besides `FungibleAccount`. This is the error visible in issue #3462. Instead the types should reflect the nature of the type; things like `AccountInput`, `AccountOutput` and so on. Generally, we assign a specific type to the input with something like `TypeInput`. That is not great in our context. The type `Account` will mostly be on input, and rarely on output. Therefore, we choose to use `Account` on input and `AccountOutput` on output. This is done via the following: ```rust #[graphql(name = "AccountOutput", input_name = "Account")] ``` With this change, we can simplify the `FungibleAccount` into `Account` for the input. The output type `AccountOutput` concerns only the refund grant to entry for cross-chain messages. ## Test Plan The CI addresses it. However, the change from `FungibleAccount` to `Account` means that some code in other crates may need to be updated as well. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent 692d3f6 commit 7b6e921

File tree

38 files changed

+173
-140
lines changed

38 files changed

+173
-140
lines changed

Cargo.lock

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

examples/Cargo.lock

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

examples/amm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2021"
66

77
[dependencies]
88
async-graphql.workspace = true
9-
fungible.workspace = true
109
linera-sdk.workspace = true
1110
matching-engine.workspace = true
1211
num-bigint.workspace = true

examples/amm/src/contract.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
mod state;
77

88
use amm::{AmmAbi, Message, Operation, Parameters};
9-
use fungible::Account;
109
use linera_sdk::{
1110
abis::fungible::{FungibleOperation, FungibleResponse, FungibleTokenAbi},
12-
linera_base_types::{AccountOwner, Amount, ApplicationId, ChainId, WithContractAbi},
11+
linera_base_types::{Account, AccountOwner, Amount, ApplicationId, ChainId, WithContractAbi},
1312
views::{RootView, View},
1413
Contract, ContractRuntime,
1514
};

examples/amm/src/state.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright (c) Zefchain Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use fungible::Account;
54
use linera_sdk::{
6-
linera_base_types::Amount,
5+
linera_base_types::{Account, Amount},
76
views::{linera_views, MapView, RegisterView, RootView, ViewStorageContext},
87
};
98

examples/crowd-funding/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
mod state;
77

88
use crowd_funding::{CrowdFundingAbi, InstantiationArgument, Message, Operation};
9-
use fungible::{Account, FungibleTokenAbi};
9+
use fungible::FungibleTokenAbi;
1010
use linera_sdk::{
1111
abis::fungible::FungibleOperation,
12-
linera_base_types::{AccountOwner, Amount, ApplicationId, WithContractAbi},
12+
linera_base_types::{Account, AccountOwner, Amount, ApplicationId, WithContractAbi},
1313
views::{RootView, View},
1414
Contract, ContractRuntime,
1515
};

examples/fungible/src/contract.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
mod state;
77

88
use fungible::{
9-
Account, FungibleOperation, FungibleResponse, FungibleTokenAbi, InitialState, Message,
10-
Parameters,
9+
FungibleOperation, FungibleResponse, FungibleTokenAbi, InitialState, Message, Parameters,
1110
};
1211
use linera_sdk::{
13-
linera_base_types::{AccountOwner, Amount, WithContractAbi},
12+
linera_base_types::{Account, AccountOwner, Amount, WithContractAbi},
1413
views::{RootView, View},
1514
Contract, ContractRuntime,
1615
};

examples/fungible/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use async_graphql::scalar;
77
pub use linera_sdk::abis::fungible::*;
8-
use linera_sdk::linera_base_types::{AccountOwner, Amount};
8+
use linera_sdk::linera_base_types::{Account, AccountOwner, Amount};
99
use serde::{Deserialize, Serialize};
1010
#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
1111
use {

examples/fungible/tests/cross_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
#![cfg(not(target_arch = "wasm32"))]
77

8-
use fungible::{Account, FungibleTokenAbi, InitialState, InitialStateBuilder, Parameters};
8+
use fungible::{FungibleTokenAbi, InitialState, InitialStateBuilder, Parameters};
99
use linera_sdk::{
1010
abis::fungible::FungibleOperation,
11-
linera_base_types::{AccountOwner, Amount},
11+
linera_base_types::{Account, AccountOwner, Amount},
1212
test::{MessageAction, TestValidator},
1313
};
1414

examples/fungible/web-frontend/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const MAKE_PAYMENT = gql`
3535
mutation Transfer(
3636
$owner: AccountOwner!
3737
$amount: Amount!
38-
$targetAccount: FungibleAccount!
38+
$targetAccount: Account!
3939
) {
4040
transfer(owner: $owner, amount: $amount, targetAccount: $targetAccount)
4141
}

0 commit comments

Comments
 (0)