-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Tipped Transaction Type. #2930
Tipped Transaction Type. #2930
Changes from 15 commits
ab34400
d36dc9a
a18be8c
55d39cf
a4e2816
58ae208
c7fe8bf
e47bf96
78dde21
7326e5a
a568a9b
b3f69cb
557f6c5
8e713aa
b110af6
23df80d
83721a4
bd28f0d
120de20
0d1de9d
6836f6b
7191a7d
0846065
12ecfcc
bf99e73
4824776
fb42e4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #[test] | ||
| #[ignore] | ||
| fn ui() { | ||
| let t = trybuild::TestCases::new(); | ||
| t.compile_fail("tests/ui/*.rs"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,25 +19,29 @@ | |||||
|
|
||||||
| use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay}; | ||||||
| use crate::weights::{Weighable, Weight}; | ||||||
| use crate::generic::tip::{Tip, Tippable}; | ||||||
|
|
||||||
| /// Definition of something that the external world might want to say; its | ||||||
| /// existence implies that it has been checked and is good, particularly with | ||||||
| /// regards to the signature. | ||||||
| #[derive(PartialEq, Eq, Clone)] | ||||||
| #[cfg_attr(feature = "std", derive(Debug))] | ||||||
| pub struct CheckedExtrinsic<AccountId, Index, Call> { | ||||||
| pub struct CheckedExtrinsic<AccountId, Index, Call, Balance> { | ||||||
| /// Who this purports to be from and the number of extrinsics have come before | ||||||
| /// from the same signer, if anyone (note this is not a signature). | ||||||
| pub signed: Option<(AccountId, Index)>, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could theoretically be an option, but as long as it's compact encoded, then there's no point since zero compact encoded is a big as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make sure
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it is part of the signature then it is only visible in signed txs which is the point of the current option. Hence, |
||||||
| /// The function that should be called. | ||||||
| pub function: Call, | ||||||
| /// The validated tip value for this transaction. | ||||||
| pub tip: Tip<Balance>, | ||||||
| } | ||||||
|
|
||||||
| impl<AccountId, Index, Call> traits::Applyable for CheckedExtrinsic<AccountId, Index, Call> | ||||||
| impl<AccountId, Index, Call, Balance> traits::Applyable for CheckedExtrinsic<AccountId, Index, Call, Balance> | ||||||
| where | ||||||
| AccountId: Member + MaybeDisplay, | ||||||
| Index: Member + MaybeDisplay + SimpleArithmetic, | ||||||
| Call: Member, | ||||||
| Balance: Member, | ||||||
| { | ||||||
| type Index = Index; | ||||||
| type AccountId = AccountId; | ||||||
|
|
@@ -56,11 +60,21 @@ where | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl<AccountId, Index, Call> Weighable for CheckedExtrinsic<AccountId, Index, Call> | ||||||
| impl<AccountId, Index, Call, Balance> Weighable for CheckedExtrinsic<AccountId, Index, Call, Balance> | ||||||
| where | ||||||
| Call: Weighable, | ||||||
| { | ||||||
| fn weight(&self, len: usize) -> Weight { | ||||||
| self.function.weight(len) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl<AccountId, Index, Call, Balance> Tippable<Balance> | ||||||
| for CheckedExtrinsic<AccountId, Index, Call, Balance> | ||||||
| where | ||||||
| Balance: Clone, | ||||||
| { | ||||||
| fn tip(&self) -> Tip<Balance> { | ||||||
| self.tip.clone() | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2019 Parity Technologies (UK) Ltd. | ||
| // This file is part of Substrate. | ||
|
|
||
| // Substrate is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Tip structure for a transaction. | ||
|
|
||
| use crate::codec::{Encode, Decode}; | ||
|
|
||
| /// Representation of a transaction tip. | ||
| /// | ||
| /// Upon decoding, all transaction types try and decode this from the end of the encoded byte | ||
| /// stream. | ||
| /// If non-existent, the default implementation will be used. | ||
| #[cfg_attr(feature = "std", derive(Debug))] | ||
| #[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)] | ||
| pub enum Tip<Balance> { | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// This transaction does not include any tips. | ||
| None, | ||
| /// The sender of the transaction has included some tip. | ||
| Sender(Balance), | ||
| } | ||
|
|
||
| /// Default implementation for tip. | ||
| impl<Balance> Default for Tip<Balance> { | ||
| fn default() -> Self { | ||
| Tip::None | ||
| } | ||
| } | ||
|
|
||
| /// A trait for a generic transaction that contains a tip. The tip itself might yield something | ||
| /// that translates to "no tip" but this trait must always be implemented for `UncheckedExtrinsic`. | ||
| pub trait Tippable<Balance> { | ||
| /// Return the tip associated with this transaction. | ||
| fn tip(&self) -> Tip<Balance>; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.