Skip to content

Commit

Permalink
quiz events
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Sep 5, 2024
1 parent 67a4218 commit 075a08a
Show file tree
Hide file tree
Showing 21 changed files with 102,698 additions and 53 deletions.
3 changes: 3 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ language = "en"
multilingual = false
src = "src"
title = "Substrate-recipes"


[preprocessor.quiz]
20 changes: 19 additions & 1 deletion book/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded "><a href="using_events.html"><strong aria-hidden="true">1.</strong> Using Events</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>

<!-- Track and set sidebar scroll position -->
Expand Down Expand Up @@ -192,6 +194,22 @@ <h1 id="document-not-found-404"><a class="header" href="#document-not-found-404"

</div>

<!-- Livereload script (if served using the cli tool) -->
<script>
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
const socket = new WebSocket(wsAddress);
socket.onmessage = function (event) {
if (event.data === "reload") {
socket.close();
location.reload();
}
};

window.onbeforeunload = function() {
socket.close();
}
</script>



Expand Down
37 changes: 27 additions & 10 deletions book/css/chrome.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* CSS for UI elements (a.k.a. chrome) */

@import 'variables.css';

html {
scrollbar-color: var(--scrollbar) var(--bg);
}
Expand Down Expand Up @@ -269,8 +267,14 @@ pre > .buttons button {
/* On mobile, make it easier to tap buttons. */
padding: 0.3rem 1rem;
}

.sidebar-resize-indicator {
/* Hide resize indicator on devices with limited accuracy */
display: none;
}
}
pre > code {
display: block;
padding: 1rem;
}

Expand Down Expand Up @@ -422,22 +426,35 @@ ul#searchresults span.teaser em {
position: absolute;
cursor: col-resize;
width: 0;
right: 0;
right: calc(var(--sidebar-resize-indicator-width) * -1);
top: 0;
bottom: 0;
display: flex;
align-items: center;
}

.sidebar-resize-handle .sidebar-resize-indicator {
width: 100%;
height: 12px;
background-color: var(--icons);
margin-inline-start: var(--sidebar-resize-indicator-space);
}

[dir=rtl] .sidebar .sidebar-resize-handle {
left: calc(var(--sidebar-resize-indicator-width) * -1);
right: unset;
}
[dir=rtl] .sidebar .sidebar-resize-handle { right: unset; left: 0; }
.js .sidebar .sidebar-resize-handle {
cursor: col-resize;
width: 5px;
width: calc(var(--sidebar-resize-indicator-width) - var(--sidebar-resize-indicator-space));
}
/* sidebar-hidden */
#sidebar-toggle-anchor:not(:checked) ~ .sidebar {
transform: translateX(calc(0px - var(--sidebar-width)));
transform: translateX(calc(0px - var(--sidebar-width) - var(--sidebar-resize-indicator-width)));
z-index: -1;
}
[dir=rtl] #sidebar-toggle-anchor:not(:checked) ~ .sidebar {
transform: translateX(var(--sidebar-width));
transform: translateX(calc(var(--sidebar-width) + var(--sidebar-resize-indicator-width)));
}
.sidebar::-webkit-scrollbar {
background: var(--sidebar-bg);
Expand All @@ -448,15 +465,15 @@ ul#searchresults span.teaser em {

/* sidebar-visible */
#sidebar-toggle-anchor:checked ~ .page-wrapper {
transform: translateX(var(--sidebar-width));
transform: translateX(calc(var(--sidebar-width) + var(--sidebar-resize-indicator-width)));
}
[dir=rtl] #sidebar-toggle-anchor:checked ~ .page-wrapper {
transform: translateX(calc(0px - var(--sidebar-width)));
transform: translateX(calc(0px - var(--sidebar-width) - var(--sidebar-resize-indicator-width)));
}
@media only screen and (min-width: 620px) {
#sidebar-toggle-anchor:checked ~ .page-wrapper {
transform: none;
margin-inline-start: var(--sidebar-width);
margin-inline-start: calc(var(--sidebar-width) + var(--sidebar-resize-indicator-width));
}
[dir=rtl] #sidebar-toggle-anchor:checked ~ .page-wrapper {
transform: none;
Expand Down
2 changes: 0 additions & 2 deletions book/css/general.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Base styles and content styles */

@import 'variables.css';

:root {
/* Browser default font-size is 16px, this way 1 rem = 10px */
font-size: 62.5%;
Expand Down
2 changes: 1 addition & 1 deletion book/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

#page-wrapper.page-wrapper {
transform: none;
transform: none !important;
margin-inline-start: 0px;
overflow-y: initial;
}
Expand Down
2 changes: 2 additions & 0 deletions book/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

:root {
--sidebar-width: 300px;
--sidebar-resize-indicator-width: 8px;
--sidebar-resize-indicator-space: 2px;
--page-padding: 15px;
--content-max-width: 750px;
--menu-bar-height: 50px;
Expand Down
50 changes: 49 additions & 1 deletion book/highlight.js

Large diffs are not rendered by default.

38 changes: 29 additions & 9 deletions book/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded "><a href="using_events.html" class="active"><strong aria-hidden="true">1.</strong> Using Events</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>

<!-- Track and set sidebar scroll position -->
Expand Down Expand Up @@ -193,19 +195,21 @@ <h1 id="using-events"><a class="header" href="#using-events">Using Events</a></h
#[pallet::weight(T::WeightInfo::do_something())]
pub fn do_something(origin: OriginFor&lt;T&gt;, something: u32) -&gt; DispatchResult {
// Check that the extrinsic was signed and get the signer.
let who = ensure_signed(origin)?;
let who = ensure_signed(origin)?;

// Update storage.
Something::&lt;T&gt;::put(something);
// Update storage.
Something::&lt;T&gt;::put(something);

// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });
// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });

// Return a successful `DispatchResult`
Ok(())
// Return a successful `DispatchResult`
Ok(())
}
<span class="boring">}</span></code></pre></pre>

<h2 id="quiz"><a class="header" href="#quiz">Quiz</a></h2>
<div class="quiz-placeholder" data-quiz-name="using_events" data-quiz-questions="{&quot;questions&quot;:[{&quot;id&quot;:&quot;463d3dec-49f2-4748-baa4-75fee31d49d4&quot;,&quot;type&quot;:&quot;MultipleChoice&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;A notification mechanism&quot;},&quot;prompt&quot;:{&quot;distractors&quot;:[&quot;Transaction on the blockchain&quot;,&quot;A smart contract function&quot;,&quot;A consensus algorithm&quot;],&quot;prompt&quot;:&quot;Which of the following best describes an event in the context of substrate blockchain runtime?\n&quot;}},{&quot;context&quot;:&quot;It may display as a wrong answer, even if the answer is correct, if the spacing does not match. Please ignore it if this happens.&quot;,&quot;id&quot;:&quot;b317de89-93f8-48d1-8157-3c8c28fb5b13&quot;,&quot;type&quot;:&quot;ShortAnswer&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;Self::deposit_event(Event::MemberAdded { member_id, who });&quot;},&quot;prompt&quot;:{&quot;prompt&quot;:&quot;Emit the `MemberAdded` event with `member_id` and `who`.\n\n```rust\n#[pallet::event]\n#[pallet::generate_deposit(pub(super) fn deposit_event)]\npub enum Event&lt;T: Config&gt; {\n MemberAdded {\n member_id: u32,\n who: T::AccountId,\n },\n}\n\n#[pallet::call_index(0)]\n#[pallet::weight(T::WeightInfo::add_member())]\npub fn add_member(origin: OriginFor&lt;T&gt;, member_id: u32) -&gt; DispatchResult {\n let who = ensure_signed(origin)?;\n\n MemberId::&lt;T&gt;::put(member_id);\n\n // Emit an event.\n ______________________\n\n Ok(())\n}\n```\n&quot;}}]}" ></div>
<script type="text/javascript" src="quiz/quiz-embed.iife.js"></script><link rel="stylesheet" type="text/css" href="quiz/style.css">
</main>

<nav class="nav-wrapper" aria-label="Page navigation">
Expand All @@ -223,6 +227,22 @@ <h1 id="using-events"><a class="header" href="#using-events">Using Events</a></h

</div>

<!-- Livereload script (if served using the cli tool) -->
<script>
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
const socket = new WebSocket(wsAddress);
socket.onmessage = function (event) {
if (event.data === "reload") {
socket.close();
location.reload();
}
};

window.onbeforeunload = function() {
socket.close();
}
</script>



Expand Down
38 changes: 29 additions & 9 deletions book/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded "><a href="using_events.html"><strong aria-hidden="true">1.</strong> Using Events</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>

<!-- Track and set sidebar scroll position -->
Expand Down Expand Up @@ -194,19 +196,21 @@ <h1 id="using-events"><a class="header" href="#using-events">Using Events</a></h
#[pallet::weight(T::WeightInfo::do_something())]
pub fn do_something(origin: OriginFor&lt;T&gt;, something: u32) -&gt; DispatchResult {
// Check that the extrinsic was signed and get the signer.
let who = ensure_signed(origin)?;
let who = ensure_signed(origin)?;

// Update storage.
Something::&lt;T&gt;::put(something);
// Update storage.
Something::&lt;T&gt;::put(something);

// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });
// Emit an event.
Self::deposit_event(Event::SomethingStored { something, who });

// Return a successful `DispatchResult`
Ok(())
// Return a successful `DispatchResult`
Ok(())
}
<span class="boring">}</span></code></pre></pre>

<h2 id="quiz"><a class="header" href="#quiz">Quiz</a></h2>
<div class="quiz-placeholder" data-quiz-name="using_events" data-quiz-questions="{&quot;questions&quot;:[{&quot;id&quot;:&quot;463d3dec-49f2-4748-baa4-75fee31d49d4&quot;,&quot;type&quot;:&quot;MultipleChoice&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;A notification mechanism&quot;},&quot;prompt&quot;:{&quot;distractors&quot;:[&quot;Transaction on the blockchain&quot;,&quot;A smart contract function&quot;,&quot;A consensus algorithm&quot;],&quot;prompt&quot;:&quot;Which of the following best describes an event in the context of substrate blockchain runtime?\n&quot;}},{&quot;context&quot;:&quot;It may display as a wrong answer, even if the answer is correct, if the spacing does not match. Please ignore it if this happens.&quot;,&quot;id&quot;:&quot;b317de89-93f8-48d1-8157-3c8c28fb5b13&quot;,&quot;type&quot;:&quot;ShortAnswer&quot;,&quot;answer&quot;:{&quot;answer&quot;:&quot;Self::deposit_event(Event::MemberAdded { member_id, who });&quot;},&quot;prompt&quot;:{&quot;prompt&quot;:&quot;Emit the `MemberAdded` event with `member_id` and `who`.\n\n```rust\n#[pallet::event]\n#[pallet::generate_deposit(pub(super) fn deposit_event)]\npub enum Event&lt;T: Config&gt; {\n MemberAdded {\n member_id: u32,\n who: T::AccountId,\n },\n}\n\n#[pallet::call_index(0)]\n#[pallet::weight(T::WeightInfo::add_member())]\npub fn add_member(origin: OriginFor&lt;T&gt;, member_id: u32) -&gt; DispatchResult {\n let who = ensure_signed(origin)?;\n\n MemberId::&lt;T&gt;::put(member_id);\n\n // Emit an event.\n ______________________\n\n Ok(())\n}\n```\n&quot;}}]}" ></div>
<script type="text/javascript" src="quiz/quiz-embed.iife.js"></script><link rel="stylesheet" type="text/css" href="quiz/style.css">
</main>

<nav class="nav-wrapper" aria-label="Page navigation">
Expand All @@ -224,6 +228,22 @@ <h1 id="using-events"><a class="header" href="#using-events">Using Events</a></h

</div>

<!-- Livereload script (if served using the cli tool) -->
<script>
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
const socket = new WebSocket(wsAddress);
socket.onmessage = function (event) {
if (event.data === "reload") {
socket.close();
location.reload();
}
};

window.onbeforeunload = function() {
socket.close();
}
</script>



Expand Down
Loading

0 comments on commit 075a08a

Please sign in to comment.