Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting problems #623

Merged
merged 18 commits into from Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
189 changes: 89 additions & 100 deletions v3/tutorials/02-proof-of-existence/index.mdx
Expand Up @@ -122,32 +122,32 @@ Therefore, the first step is to remove some files and content from the files in

1. Add a skeleton set of pallet dependencies and [macros](/v3/runtime/macros) that the custom pallet requires by copying the following code:

```rust
// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_std::vec::Vec; // Step 3.1 will include this in `Cargo.toml`
#[pallet::config] // <-- Step 2. code block will replace this.
#[pallet::event] // <-- Step 3. code block will replace this.
#[pallet::error] // <-- Step 4. code block will replace this.
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::generate_storage_info]
pub struct Pallet<T>(_);
#[pallet::storage] // <-- Step 5. code block will replace this.
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call] // <-- Step 6. code block will replace this.
}
```

You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_.
```rust
// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_std::vec::Vec; // Step 3.1 will include this in `Cargo.toml`

#[pallet::config] // <-- Step 2. code block will replace this.
#[pallet::event] // <-- Step 3. code block will replace this.
#[pallet::error] // <-- Step 4. code block will replace this.
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::generate_storage_info]
pub struct Pallet<T>(_);

#[pallet::storage] // <-- Step 5. code block will replace this.
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call] // <-- Step 6. code block will replace this.
}
```

You now have a framework that includes placeholders for _events_, _errors_, _storage_, and _callable functions_.

1. Save your changes.

Expand All @@ -167,8 +167,8 @@ To define the `Config` trait for the proof-of-existence pallet:
/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
```

Expand Down Expand Up @@ -199,10 +199,10 @@ To implement the pallet events:
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event emitted when a proof has been claimed. [who, claim]
ClaimCreated(T::AccountId, Vec<u8>),
/// Event emitted when a claim is revoked by the owner. [who, claim]
ClaimRevoked(T::AccountId, Vec<u8>),
/// Event emitted when a proof has been claimed. [who, claim]
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
ClaimCreated(T::AccountId, Vec<u8>),
/// Event emitted when a claim is revoked by the owner. [who, claim]
ClaimRevoked(T::AccountId, Vec<u8>),
}
```

Expand Down Expand Up @@ -242,8 +242,8 @@ To add the `sp-std` crate to the pallet:
[features]
default = ['std']
std = [
# -- snip --
'sp-std/std',
# -- snip --
'sp-std/std',
]
```

Expand All @@ -270,13 +270,13 @@ To implement the errors for the proof-of-existence pallet:
```rust
#[pallet::error]
pub enum Error<T> {
/// The proof has already been claimed.
ProofAlreadyClaimed,
/// The proof does not exist, so it cannot be revoked.
NoSuchProof,
/// The proof is claimed by another account, so caller can't revoke it.
NotProofOwner,
}
/// The proof has already been claimed.
ProofAlreadyClaimed,
/// The proof does not exist, so it cannot be revoked.
NoSuchProof,
/// The proof is claimed by another account, so caller can't revoke it.
NotProofOwner,
}
```

1. Save your changes.
Expand Down Expand Up @@ -325,58 +325,58 @@ To implement this logic in the proof-of-existence pallet:
// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(1_000)]
pub fn create_claim(
origin: OriginFor<T>,
proof: Vec<u8>,
#[pallet::weight(1_000)]
pub fn create_claim(
origin: OriginFor<T>,
proof: Vec<u8>,
) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
// https://docs.substrate.io/v3/runtime/origins
let sender = ensure_signed(origin)?;
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
// https://docs.substrate.io/v3/runtime/origins
let sender = ensure_signed(origin)?;

// Verify that the specified proof has not already been claimed.
ensure!(!Proofs::<T>::contains_key(&proof), Error::<T>::ProofAlreadyClaimed);
// Verify that the specified proof has not already been claimed.
ensure!(!Proofs::<T>::contains_key(&proof), Error::<T>::ProofAlreadyClaimed);

// Get the block number from the FRAME System pallet.
let current_block = <frame_system::Pallet<T>>::block_number();
// Get the block number from the FRAME System pallet.
let current_block = <frame_system::Pallet<T>>::block_number();

// Store the proof with the sender and block number.
Proofs::<T>::insert(&proof, (&sender, current_block));
// Store the proof with the sender and block number.
Proofs::<T>::insert(&proof, (&sender, current_block));

// Emit an event that the claim was created.
Self::deposit_event(Event::ClaimCreated(sender, proof));
// Emit an event that the claim was created.
Self::deposit_event(Event::ClaimCreated(sender, proof));

Ok(())
}
Ok(())
}

#[pallet::weight(10_000)]
pub fn revoke_claim(
#[pallet::weight(10_000)]
pub fn revoke_claim(
origin: OriginFor<T>,
proof: Vec<u8>,
) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
// https://docs.substrate.io/v3/runtime/origins
let sender = ensure_signed(origin)?;
) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
// https://docs.substrate.io/v3/runtime/origins
let sender = ensure_signed(origin)?;

// Verify that the specified proof has been claimed.
ensure!(Proofs::<T>::contains_key(&proof), Error::<T>::NoSuchProof);
// Verify that the specified proof has been claimed.
ensure!(Proofs::<T>::contains_key(&proof), Error::<T>::NoSuchProof);

// Get owner of the claim.
let (owner, _) = Proofs::<T>::get(&proof);
// Get owner of the claim.
let (owner, _) = Proofs::<T>::get(&proof);

// Verify that sender of the current call is the claim owner.
ensure!(sender == owner, Error::<T>::NotProofOwner);
// Verify that sender of the current call is the claim owner.
ensure!(sender == owner, Error::<T>::NotProofOwner);

// Remove claim from storage.
Proofs::<T>::remove(&proof);
// Remove claim from storage.
Proofs::<T>::remove(&proof);

// Emit an event that the claim was erased.
Self::deposit_event(Event::ClaimRevoked(sender, proof));
Ok(())
}
}
// Emit an event that the claim was erased.
Self::deposit_event(Event::ClaimRevoked(sender, proof));
Ok(())
}
}
```

1. Save your changes and close the file.
Expand All @@ -388,13 +388,13 @@ To implement this logic in the proof-of-existence pallet:
```

<Message
type={'yellow'}
title={'Information'}
text="There is a full Node Template solution
[here](https://github.com/substrate-developer-hub/substrate-node-template/tree/tut-sol/proof-of-existence%2Flatest)
to use as a reference if you\'re stuck. Check the
[commit diff from the base `latest` template](https://github.com/substrate-developer-hub/substrate-node-template/compare/latest...tutorials/solutions/proof-of-existence?expand=1)
for the exact changes."
type={'yellow'}
title={'Information'}
text="There is a full Node Template solution
[here](https://github.com/substrate-developer-hub/substrate-node-template/tree/tut-sol/proof-of-existence%2Flatest)
to use as a reference if you\'re stuck. Check the
[commit diff from the base `latest` template](https://github.com/substrate-developer-hub/substrate-node-template/compare/latest...tutorials/solutions/proof-of-existence?expand=1)
for the exact changes."
/>

## Build the runtime with your new pallet
Expand Down Expand Up @@ -515,20 +515,11 @@ The React component enables you to expose the proof-of-existence capabilities an
<Form success={!!digest && !isClaimed()} warning={isClaimed()}>
<Form.Field>
{/* File selector with a callback to `handleFileChosen`. */}
<Input
type="file"
id="file"
label="Your File"
onChange={e => handleFileChosen(e.target.files[0])}
/>
<Input type="file" id="file" label="Your File" onChange={e => handleFileChosen(e.target.files[0])} />
{/* Show this message if the file is available to be claimed */}
<Message success header="File Digest Unclaimed" content={digest} />
{/* Show this message if the file is already claimed. */}
<Message
warning
header="File Digest Claimed"
list={[digest, `Owner: ${owner}`, `Block: ${block}`]}
/>
<Message warning header="File Digest Claimed" list={[digest, `Owner: ${owner}`, `Block: ${block}`]} />
</Form.Field>
{/* Buttons for interacting with the component. */}
<Form.Field>
Expand Down Expand Up @@ -570,9 +561,7 @@ The React component enables you to expose the proof-of-existence capabilities an

export default function TemplateModule(props) {
const { api } = useSubstrate()
return api.query.templateModule && api.query.templateModule.proofs ? (
<Main {...props} />
) : null
return api.query.templateModule && api.query.templateModule.proofs ? <Main {...props} /> : null
}
```

Expand Down
54 changes: 27 additions & 27 deletions v3/tutorials/03-permissioned-network/index.mdx
Expand Up @@ -180,19 +180,19 @@ use frame_system::EnsureRoot;
/* --snip-- */

parameter_types! {
pub const MaxWellKnownNodes: u32 = 8;
pub const MaxPeerIdLength: u32 = 128;
pub const MaxWellKnownNodes: u32 = 8;
pub const MaxPeerIdLength: u32 = 128;
}

impl pallet_node_authorization::Config for Runtime {
type Event = Event;
type MaxWellKnownNodes = MaxWellKnownNodes;
type MaxPeerIdLength = MaxPeerIdLength;
type AddOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type SwapOrigin = EnsureRoot<AccountId>;
type ResetOrigin = EnsureRoot<AccountId>;
type WeightInfo = ();
type Event = Event;
type MaxWellKnownNodes = MaxWellKnownNodes;
type MaxPeerIdLength = MaxPeerIdLength;
type AddOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type SwapOrigin = EnsureRoot<AccountId>;
type ResetOrigin = EnsureRoot<AccountId>;
type WeightInfo = ();
}

/* --snip-- */
Expand Down Expand Up @@ -252,28 +252,28 @@ Adding our genesis config in the helper function `testnet_genesis`,
```rust
/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {

/* --snip-- */

/*** Add This Block Item ***/
node_authorization: NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone()
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone()
),
],
}),
node_authorization: NodeAuthorizationConfig {
nodes: vec![
(
OpaquePeerId(bs58::decode("12D3KooWBmAwcd4PJNJvfV89HwE48nwkRmAgo8Vy3uQEyNNHBox2").into_vec().unwrap()),
endowed_accounts[0].clone()
),
(
OpaquePeerId(bs58::decode("12D3KooWQYV9dGMFoRzNStwpXztXaBUjtPqi6aU76ZgUriHhKust").into_vec().unwrap()),
endowed_accounts[1].clone()
),
],
}),

/* --snip-- */

Expand Down