Skip to content
This repository was archived by the owner on Feb 28, 2021. It is now read-only.

Commit 4c697c2

Browse files
author
Thomas Scholtes
authored
Merge pull request #205 from radicle-dev/core-state-entities
Properly isolate and document core state entities
2 parents 8a0140e + 2d1965a commit 4c697c2

20 files changed

+179
-470
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ members = [
55
"core",
66
"node",
77
"runtime",
8-
"registry-spec",
98
"test-utils"
109
]

README.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ See [`DEVELOPING.md`][dev-manual] for developer information.
1616
- [Account Keys](#account-keys)
1717
- [Developing with the Client](#developing-with-the-client)
1818
- [Using the CLI](#using-the-cli)
19-
- [Registry Specification](#registry-specification)
2019
- [License](#license)
2120

2221
<!-- tocstop -->
@@ -148,32 +147,6 @@ learn more run `cargo run -p radicle-registry-cli -- --help`.
148147
[wasm-gc]: https://github.com/alexcrichton/wasm-gc
149148

150149

151-
Registry Specification
152-
--------------------
153-
154-
In the `registry-spec` folder, there is a Rust crate that details the Oscoin
155-
registry specification with traits, types and a sizable amount of documentation.
156-
157-
It is intended to bridge the formal description of the registry from the
158-
whitepaper with the registry's future implementation, providing a "sandbox"
159-
with which to test and discuss design ideas before implementing them in
160-
earnest.
161-
162-
The `registry-spec` crate is meant to evolve with the project, and at each point
163-
in time its contents will reflect the team's requirements from and
164-
understanding of the Oscoin registry.
165-
166-
Note that although there is no actual implementation of any function or
167-
datatype in the crate, it compiles and is part of the build process.
168-
169-
### Structure
170-
171-
`registry-spec` is a library with three modules:
172-
* `lib.rs`, defining the main traits with which to interact with the Oscoin
173-
registry
174-
* `error.rs` defining errors that may arise when interacting with the registry.
175-
* `types.rs`, defining the primitive types that will populate the registry state.
176-
177150
License
178151
-------
179152

client/src/interface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ pub trait ClientT {
8080
) -> Result<Response<TransactionApplied<Message_>, Error>, Error>;
8181

8282
/// Fetch the nonce for the given account from the chain state
83-
async fn account_nonce(&self, account_id: &AccountId) -> Result<Index, Error>;
83+
async fn account_nonce(&self, account_id: &AccountId) -> Result<state::Index, Error>;
8484

8585
/// Return the gensis hash of the chain we are communicating with.
8686
fn genesis_hash(&self) -> Hash;
8787

8888
async fn free_balance(&self, account_id: &AccountId) -> Result<Balance, Error>;
8989

90-
async fn get_project(&self, id: ProjectId) -> Result<Option<Project>, Error>;
90+
async fn get_project(&self, id: ProjectId) -> Result<Option<state::Project>, Error>;
9191

9292
async fn list_projects(&self) -> Result<Vec<ProjectId>, Error>;
9393

94-
async fn get_checkpoint(&self, id: CheckpointId) -> Result<Option<Checkpoint>, Error>;
94+
async fn get_checkpoint(&self, id: CheckpointId) -> Result<Option<state::Checkpoint>, Error>;
9595
}

client/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,17 @@ impl ClientT for Client {
208208
self.backend.get_genesis_hash()
209209
}
210210

211-
async fn account_nonce(&self, account_id: &AccountId) -> Result<Index, Error> {
211+
async fn account_nonce(&self, account_id: &AccountId) -> Result<state::Index, Error> {
212212
self.fetch_map_value::<frame_system::AccountNonce<Runtime>, _, _>(*account_id)
213213
.await
214214
}
215215

216-
async fn free_balance(&self, account_id: &AccountId) -> Result<Balance, Error> {
216+
async fn free_balance(&self, account_id: &AccountId) -> Result<state::AccountBalance, Error> {
217217
self.fetch_map_value::<balances::FreeBalance<Runtime>, _, _>(account_id.clone())
218218
.await
219219
}
220220

221-
async fn get_project(&self, id: ProjectId) -> Result<Option<Project>, Error> {
221+
async fn get_project(&self, id: ProjectId) -> Result<Option<state::Project>, Error> {
222222
self.fetch_map_value::<registry::store::Projects, _, _>(id)
223223
.await
224224
}
@@ -235,7 +235,7 @@ impl ClientT for Client {
235235
Ok(project_ids)
236236
}
237237

238-
async fn get_checkpoint(&self, id: CheckpointId) -> Result<Option<Checkpoint>, Error> {
238+
async fn get_checkpoint(&self, id: CheckpointId) -> Result<Option<state::Checkpoint>, Error> {
239239
self.fetch_map_value::<registry::store::Checkpoints, _, _>(id)
240240
.await
241241
}

client/src/transaction.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@
1414
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

1616
//! Provides [Transaction] and [TransactionExtra].
17-
use crate::TxHash;
17+
use core::marker::PhantomData;
1818
use parity_scale_codec::Encode;
19-
pub use radicle_registry_core::{AccountId, Balance, Project, ProjectId};
20-
use radicle_registry_runtime::Hashing;
21-
use radicle_registry_runtime::UncheckedExtrinsic;
22-
pub use sp_core::crypto::{Pair as CryptoPair, Public as CryptoPublic};
23-
pub use sp_core::ed25519;
2419
use sp_runtime::generic::{Era, SignedPayload};
25-
use sp_runtime::traits::Hash as _;
26-
use sp_runtime::traits::SignedExtension;
27-
use std::marker::PhantomData;
20+
use sp_runtime::traits::{Hash as _, SignedExtension};
2821

29-
pub use crate::message::Message;
30-
pub use radicle_registry_runtime::{Call as RuntimeCall, Hash, Index, SignedExtra};
22+
use crate::{ed25519, message::Message, CryptoPair as _, TxHash};
23+
use radicle_registry_core::state::Index;
24+
use radicle_registry_runtime::{
25+
Call as RuntimeCall, Hash, Hashing, SignedExtra, UncheckedExtrinsic,
26+
};
3127

3228
#[derive(Clone, Debug)]
3329
/// Transaction the can be submitted to the blockchain.

client/tests/end_to_end.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async fn register_project() {
4848
);
4949

5050
let checkpoint = client.get_checkpoint(checkpoint_id).await.unwrap().unwrap();
51-
let checkpoint_ = Checkpoint {
51+
let checkpoint_ = state::Checkpoint {
5252
parent: None,
5353
hash: project_hash,
5454
};

core/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@ cover all edge cases. The documentation for a message has the following sections
2626
<dd>Describes the validations that are required for the message to be applied
2727
successfully and that depend on the current ledger state state.</dd>
2828
</dd>
29+
30+
State
31+
-----
32+
33+
All entities that are stored in the ledger state are defined in the `state`
34+
module.
35+
36+
For each entity the documentation has the following sections
37+
38+
<dl>
39+
<dt>Storage</dt>
40+
<dd>Describes how the entity is stored in the state and how the state storage
41+
key is calculated.</dd>
42+
<dt>Invariants</dt>
43+
<dd>Describes the invariants of the data in the state entity that always hold.</dd>
44+
<dt>Relevant messages</dt>
45+
<dd>Links to message types that effect or use the entity.</dd>
46+
</dd>

core/src/lib.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020

2121
extern crate alloc;
2222

23-
use alloc::prelude::v1::*;
24-
25-
use parity_scale_codec::{Decode, Encode};
2623
use sp_core::{ed25519, H256};
2724
use sp_runtime::traits::BlakeTwo256;
2825

2926
pub use sp_runtime::DispatchError;
3027

3128
pub mod message;
29+
pub mod state;
3230

3331
pub mod bytes128;
3432
pub use bytes128::Bytes128;
@@ -42,42 +40,20 @@ pub use project_domain::ProjectDomain;
4240
mod error;
4341
pub use error::RegistryError;
4442

45-
/// Index of a transaction in the chain.
46-
pub type Index = u32;
47-
4843
/// The hashing algorightm to use
4944
pub type Hashing = BlakeTwo256;
5045

51-
/// Some way of identifying an account on the chain. We intentionally make it equivalent
52-
/// to the public key of our transaction signing scheme.
46+
/// Identifier for accounts, an Ed25519 public key.
47+
///
48+
/// Each account has an associated [message::AccountBalance] and [message::Index].
5349
pub type AccountId = ed25519::Public;
5450

5551
/// Balance of an account.
5652
pub type Balance = u128;
5753

58-
/// # Registry types
59-
6054
/// The name a project is registered with.
6155
pub type ProjectName = String32;
6256

6357
pub type ProjectId = (ProjectName, ProjectDomain);
6458

6559
pub type CheckpointId = H256;
66-
67-
/// A project's version. Used in checkpointing.
68-
pub type Version = String;
69-
70-
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
71-
pub struct Checkpoint {
72-
pub parent: Option<CheckpointId>,
73-
pub hash: H256,
74-
}
75-
76-
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
77-
pub struct Project {
78-
pub id: ProjectId,
79-
pub account_id: AccountId,
80-
pub members: Vec<AccountId>,
81-
pub current_cp: CheckpointId,
82-
pub metadata: Bytes128,
83-
}

core/src/message.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
//! See the README.md for more information on how to document messages.
1919
extern crate alloc;
2020

21-
use crate::{AccountId, Balance, Bytes128, CheckpointId, ProjectId};
21+
use crate::{AccountId, Balance, Bytes128, CheckpointId, ProjectId, H256};
2222
use parity_scale_codec::{Decode, Encode};
23-
use sp_core::H256;
2423

2524
/// Registers a project on the Radicle Registry with the given ID.
2625
///
2726
/// # State changes
2827
///
29-
/// If successful, a new [crate::Project] with the given properties is added to the state.
28+
/// If successful, a new [crate::state::Project] with the given properties is added to the state.
3029
///
31-
/// [crate::Project::members] is initialized with the transaction author as the only member.
30+
/// [crate::state::Project::members] is initialized with the transaction author as the only member.
3231
///
33-
/// [crate::Project::account_id] is generated randomly.
32+
/// [crate::state::Project::account_id] is generated randomly.
3433
///
3534
/// # State-dependent validations
3635
///
@@ -54,7 +53,7 @@ pub struct RegisterProject {
5453
///
5554
/// # State changes
5655
///
57-
/// If successful, adds a new [crate::Checkpoint] with the given parameters to the state.
56+
/// If successful, adds a new [crate::state::Checkpoint] with the given parameters to the state.
5857
///
5958
/// # State-dependent validations
6059
///
@@ -65,19 +64,19 @@ pub struct CreateCheckpoint {
6564
pub previous_checkpoint_id: Option<CheckpointId>,
6665
}
6766

68-
/// Updates [crate::Project::current_cp].
67+
/// Updates [crate::state::Project::current_cp].
6968
///
7069
/// # State changes
7170
///
72-
/// If successful, adds a new [crate::Checkpoint] with the given parameters to the state.
71+
/// If successful, adds a new [crate::state::Checkpoint] with the given parameters to the state.
7372
///
7473
/// # State-dependent validations
7574
///
7675
/// The project `project_id` must exist.
7776
///
7877
/// The checkpoint `new_checkpoint_id` must exist.
7978
///
80-
/// The transaction author must be in [crate::Project::members] of the given project.
79+
/// The transaction author must be in [crate::state::Project::members] of the given project.
8180
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
8281
pub struct SetCheckpoint {
8382
pub project_id: ProjectId,
@@ -89,14 +88,14 @@ pub struct SetCheckpoint {
8988
/// # State changes
9089
///
9190
/// If successful, `balance` is deducated from the project account and added to the the recipient
92-
/// account. The project account is given by [crate::Project::account_id] of the given project.
91+
/// account. The project account is given by [crate::state::Project::account_id] of the given project.
9392
///
9493
/// If the recipient account did not exist before, it is created. The recipient account may be a
9594
/// user account or a project account.
9695
///
9796
/// # State-dependent validations
9897
///
99-
/// The author must be a member of [crate::Project::members].
98+
/// The author must be a member of [crate::state::Project::members].
10099
///
101100
/// The project account must have a balance of at least `balance`.
102101
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)