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

Commit 8a0140e

Browse files
author
Thomas Scholtes
authored
Merge pull request #189 from radicle-dev/message-doc
Add ledger message documentation to core
2 parents f46c588 + 6c0d199 commit 8a0140e

File tree

4 files changed

+102
-131
lines changed

4 files changed

+102
-131
lines changed

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Packages
6363
transactions and read state.
6464
* `core` contains basic types used throughout the Radicle Registry.
6565
If e.g. a trait or a datatype is used by more than one of the above packages,
66-
it should probably go into `core`.
66+
it should probably go into `core`. See `./core/README.md` for details.
6767

6868

6969
Running checks and tests

core/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
radicle-registry-core
2+
=====================
3+
4+
This package provides the types that constitute the registry ledger and provides
5+
exhaustive documentation how these types behave in the ledger.
6+
7+
These types are the entities that are stored in the state, the different
8+
transaction message types, and their constituent types.
9+
10+
Transaction Messages
11+
--------------------
12+
13+
Transaction messages effect a change in the ledger state. They are submitted to
14+
the ledger as part of a transaction. All possible transaction messages are
15+
defined in the `message` module.
16+
17+
For each message we document how it changes the state and what preconditions
18+
must be satisfied. The documentation must be comprehensive and exhaustive and
19+
cover all edge cases. The documentation for a message has the following sections
20+
21+
<dl>
22+
<dt>State changes</dt>
23+
<dd>Describes which entities are added, removed, or updated in the ledger
24+
state.</dd>
25+
<dt>State-dependent validations</dt>
26+
<dd>Describes the validations that are required for the message to be applied
27+
successfully and that depend on the current ledger state state.</dd>
28+
</dd>

core/src/message.rs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,111 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

16-
//! Transaction related types used in the Radicle Registry.
17-
16+
//! All transaction messages that can be submitted to the ledger
17+
//!
18+
//! See the README.md for more information on how to document messages.
1819
extern crate alloc;
1920

2021
use crate::{AccountId, Balance, Bytes128, CheckpointId, ProjectId};
2122
use parity_scale_codec::{Decode, Encode};
2223
use sp_core::H256;
2324

25+
/// Registers a project on the Radicle Registry with the given ID.
26+
///
27+
/// # State changes
28+
///
29+
/// If successful, a new [crate::Project] with the given properties is added to the state.
30+
///
31+
/// [crate::Project::members] is initialized with the transaction author as the only member.
32+
///
33+
/// [crate::Project::account_id] is generated randomly.
34+
///
35+
/// # State-dependent validations
36+
///
37+
/// A project with the same ID must not yet exist.
38+
///
39+
/// A checkpoint with the given ID must exist.
2440
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
2541
pub struct RegisterProject {
2642
pub id: ProjectId,
43+
44+
/// Initial checkpoint of the project.
2745
pub checkpoint_id: CheckpointId,
46+
47+
/// Opaque metadata that cannot be changed.
48+
///
49+
/// Used by the application.
2850
pub metadata: Bytes128,
2951
}
3052

53+
/// Add a new checkpoint to the state.
54+
///
55+
/// # State changes
56+
///
57+
/// If successful, adds a new [crate::Checkpoint] with the given parameters to the state.
58+
///
59+
/// # State-dependent validations
60+
///
61+
/// If `previous_checkpoint_id` is provided a checkpoint with the given ID must exist in the state.
3162
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
3263
pub struct CreateCheckpoint {
3364
pub project_hash: H256,
3465
pub previous_checkpoint_id: Option<CheckpointId>,
3566
}
3667

68+
/// Updates [crate::Project::current_cp].
69+
///
70+
/// # State changes
71+
///
72+
/// If successful, adds a new [crate::Checkpoint] with the given parameters to the state.
73+
///
74+
/// # State-dependent validations
75+
///
76+
/// The project `project_id` must exist.
77+
///
78+
/// The checkpoint `new_checkpoint_id` must exist.
79+
///
80+
/// The transaction author must be in [crate::Project::members] of the given project.
3781
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
3882
pub struct SetCheckpoint {
3983
pub project_id: ProjectId,
4084
pub new_checkpoint_id: CheckpointId,
4185
}
4286

87+
/// Transfer funds from a project account to an account
88+
///
89+
/// # State changes
90+
///
91+
/// 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.
93+
///
94+
/// If the recipient account did not exist before, it is created. The recipient account may be a
95+
/// user account or a project account.
96+
///
97+
/// # State-dependent validations
98+
///
99+
/// The author must be a member of [crate::Project::members].
100+
///
101+
/// The project account must have a balance of at least `balance`.
43102
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
44103
pub struct TransferFromProject {
45104
pub project: ProjectId,
46105
pub recipient: AccountId,
47106
pub value: Balance,
48107
}
49108

109+
/// Transfer funds from one account to another.
110+
///
111+
/// # State changes
112+
///
113+
/// If successful, `balance` is deducated from the transaction author account and added to the the
114+
/// recipient account. If the recipient account did not exist before, it is created.
115+
///
116+
/// The recipient account may be a user account or a project account.
117+
///
118+
/// # State-dependent validations
119+
///
120+
/// The author account must have a balance of at least `balance`.
50121
#[derive(Decode, Encode, Clone, Debug, Eq, PartialEq)]
51122
pub struct Transfer {
52123
pub recipient: AccountId,

registry-spec/src/lib.rs

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -23,134 +23,6 @@
2323
pub mod error;
2424
pub mod types;
2525

26-
/// A trait exposing the Radicle registry transactions described in the
27-
/// whitepaper.
28-
///
29-
/// The methods here return `Result<types::TxHash, E>` for some error type `E` as they
30-
/// will be applying a modification on the Registry global state, and return
31-
/// the hash of the applied transaction if they succeed.
32-
pub trait RegistryTransactions {
33-
/// Transfer an amount of currency from one account to another.
34-
///
35-
/// Method preconditions:
36-
/// * Amount to be transferred is greater than or equal to 1 (one) unit of
37-
/// currency.
38-
fn transfer_oscoin(
39-
// Account from which to send currency.
40-
from_acc: types::AccountId,
41-
// Account into which currency will be transferred.
42-
to_acc: types::AccountId,
43-
amount: types::Balance,
44-
) -> Result<types::TxHash, error::TransferError>;
45-
46-
/// Registers a project on the Radicle Registry and returns the new project’s ID.
47-
///
48-
/// The transaction’s sender account becomes the initial maintainer of the
49-
/// project, once it has been accepted into the registry.
50-
///
51-
/// After submitting this transaction, the project will enter the
52-
/// `PendingRegistrations` set, after which it can either be accepted or
53-
/// rejected by an account in the `ROOT_ACCOUNT`s set with the appropriate
54-
/// `accept_project/reject_project` transaction.
55-
///
56-
/// Further, after submitting this transaction, regardless of whether the
57-
/// project is later accepted or rejected, the registration fee is deducted
58-
/// from the transaction sender's account - if no such available balance is
59-
/// found, it will result in an error.
60-
fn register_project(
61-
// Requested name of the project to be registered.
62-
project_id: types::ProjectId,
63-
project_checkpoint: types::CheckpointId,
64-
project_contract: types::Contract,
65-
project_ownership_proof: types::ProjectOwnershipProof,
66-
project_meta: types::Meta,
67-
) -> Result<types::TxHash, error::RegisterProjectError>;
68-
69-
/// Accept a project that has been submitted for registration.
70-
///
71-
/// It is then removed from the pending registrations set, and can then be
72-
/// retrieved using the `get_project()` method from `RegistryView`.
73-
fn accept_project(
74-
// Hash of the `register_project` transaction for the `Project` in
75-
// question.
76-
t_hash: types::TxHash,
77-
) -> Result<types::ProjectId, error::ProjectRegistrationVoteError>;
78-
79-
/// Reject a project that has been submitted for registration.
80-
/// It is then removed from the pending registrations set.
81-
fn reject_project(
82-
// Hash of the `register_project` transaction for the `Project` in
83-
// question.
84-
t_hash: types::TxHash,
85-
) -> Result<types::TxHash, error::ProjectRegistrationVoteError>;
86-
87-
/// Transaction used to annul a previous `register_project` transaction,
88-
/// if it has not been approved/rejected yet.
89-
///
90-
/// If successful, the project referred to will be removed from the
91-
/// pending registrations set
92-
/// (see RegistryView::get_pending_project_registrations).
93-
fn withdraw_project(
94-
// Hash of the `register_project` whose candidacy is being withdrawn.
95-
t_hash: types::TxHash,
96-
) -> Result<types::TxHash, error::WithdrawProjectError>;
97-
98-
/// Unregistering a project from the Radicle Registry.
99-
///
100-
/// As is the case above, this transaction may also be handled outside the
101-
/// registry.
102-
fn unregister_project(
103-
id: types::ProjectId,
104-
) -> Result<types::TxHash, error::UnregisterProjectError>;
105-
106-
/// Checkpointing a project in Radicle's registry.
107-
fn checkpoint(
108-
// Hash of the previous `checkpoint` associated with this project.
109-
parent: Option<types::CheckpointId>,
110-
// New project hash - if `set-checkpoint` if used with this checkpoint,
111-
// this will become the project's current state hash.
112-
new_project_hash: types::Hash,
113-
new_project_version: types::Version,
114-
// Hash-linked list of the checkpoint's contributions. To see more
115-
// about this type, go to types::Contribution.
116-
contribution_list: types::ContributionList,
117-
// A vector of dependency updates. See types::DependencyUpdate
118-
// for more information.
119-
//
120-
// It is to be treated as a list i.e. processed from left to right.
121-
dependency_updates: Vec<types::DependencyUpdate>,
122-
) -> Result<types::TxHash, error::CheckpointError>;
123-
124-
/// Set a project's checkpoint in the Radicle registry.
125-
///
126-
/// If a `set_checkpoint` transaction is successful, the project's new
127-
/// checkpoint in the Radicle Registry will be the one passed to the
128-
/// transaction.
129-
///
130-
/// Anyone is allowed to execute this transaction.
131-
///
132-
/// The project's first checkpoint, `k_0`, must be an ancestor of the
133-
/// supplied checkpoint.
134-
fn set_checkpoint(
135-
// Id of the project to be updated.
136-
project_id: types::ProjectId,
137-
// Id of the checkpoint to be associated to the above project.
138-
checkpoint_id: types::CheckpointId,
139-
) -> Result<types::TxHash, error::SetCheckpointError>;
140-
141-
/// Set a project's contract in the Radicle registry.
142-
///
143-
/// If successful, it will set the project's contract to the one that was
144-
/// supplied in the transaction.
145-
fn set_contract(
146-
// Id of the project whose contract is to be updated.
147-
id: types::ProjectId,
148-
//
149-
// New contract to be associated to the project.
150-
contract: types::Contract,
151-
) -> Result<types::TxHash, error::SetContractError>;
152-
}
153-
15426
/// Functions to access information from the registry state.
15527
pub trait RegistryView {
15628
/// Returns the project registered at the given address.

0 commit comments

Comments
 (0)