Tipping
Name | Value |
---|---|
Repository | https://github.com/anagolay/anagolay-chain/tree/main/pallets/tipping |
Pallet | Yes |
License | AGPL |
MAX_TIPS_PER_VERIFICATION_CONTEXT | 10000 |
Tipping
Overview​
The tipping pallet
will enable sending the community contributions (tips) to verified creators currently in the Anagolay native tokens and later, using fiat and many Dotsama ecosystem tokens. To prevent the misuse of the pallet and to make sure that the correct people are supported, the tipping pallet depends on the verification
pallet to get the proofs of the domain, username or repository verification, and statements
pallet for the ownership.
Tipping pallet is the core feature in our attempt to build the functionality and features to support creators’ economy in a truly decentralized manner.
Every creator can verify their revenue channels like websites, subdomains, or a username on commercial websites and accept payment from anybody in crypto.
Sending a tip to a verified online identity:
Configuration​
The runtime needs to configure the tipping pallet as follows:
impl tipping::Config for Runtime {
type Event = Event;
type Currency = Balances;
type TimeProvider = pallet_timestamp::Pallet<Runtime>;
type WeightInfo = tipping::weights::AnagolayWeight<Runtime>;
/// Limit on the maximum number of tips that will be recorded, per context.
/// This only affects the showing of the last X transactions when rpc is called
const MAX_TIPS_PER_VERIFICATION_CONTEXT: u32 = 10000;
}
There is one constant available for configuration:
MAX_TIPS_PER_VERIFICATION_CONTEXT
: specifies the amount of tips which will be recorded per verification context. Once reached this limit, the older tips are discarded. Does not affect receiving tips, and it is used to show last X of the transactions when thegetTips
RPC is called
Storage​
TippingSettingsByAccountIdAndVerificationContext
The map ofTippingSetting
s indexed by their respectiveAccountId
andVerificationContext
TipsByAccountIdAndVerificationContext
Provides a collection ofTip
s indexed by their respective receiverAccountId
andVerificationContext
Events​
TippingSettingsUpdated
produced upon tipping settings updateTipCreated
produced upon the newly created tip
Errors​
InvalidVerificationContext
happens when verification context is not associated to a successful verification request and cannot be tippedInvalidConfiguration
happens when trying to tip a verification context is not set-up to enable tipping
Types​
TippingSettings
is a structure associated withVerificationContext
, providing the tipping settingscontext
: the verification context this setting applies toenabled
: specifies that the tipping is enabled or notaccount
: specifies to which wallet to send the tips given in some kind of token
Tip
structure representing a tip, providing the following fields:amount
- quantity of tokens tippedsender
- theAccountId
that is tippingsender
- theAccountId
that is receiving the tipcreatedAt
- timestamp of the tip, in secondsblockNumber
: block where the tip was inserted
Extrinsic​
update_settings
accepts a collection ofTippingSettings
and stores it. A coherency check is performed on the rightfulness of the caller to configure each setting. Infact, the single setting won't be stored if the caller is not the holder of the verification request for the respective context, or if such request has a status different fromSuccess
. In the end, aTippingSettingsUpdated
event is raisedtip
accepts aTip
for aVerificationContext
and stores them in theTipsByAccountIdAndVerificationContext
while it transfers of the required amount from the account of the sender to the account of the receiver.
RPCs​
getTips
​
/// Get the tips for an Account and a [`VerificationContext`]
///
/// # Arguments
/// * account_id - The account to query
/// * verification_context - The [`VerificationContext`] to query
/// * offset - The index, inside the ids set, of the first Tip on the page
/// * limit - The count of Tips on the page
/// * sort - Specifies the order in which tips are sorted by their created_at field
///
/// # Return
/// Collection of [`Tip`]s
fn get_tips (
account_id: AccountId,
verification_context: VerificationContext,
offset: u64,
limit: u16,
sort: TippingSort,
) -> Vec<Tip<Balance, AccountId, BlockNumber>>;
total
​
/// Get the count of tips for a [`VerificationContext`]
///
/// # Arguments
/// * account_id - The holder of a successful [`VerificationRequest`] for the verification context
/// * verification_context - The [`VerificationContext`] to query
///
/// # Return
/// Count of [`Tip`]s for the specified verification context
fn total(
account_id: AccountId,
verification_context: VerificationContext
) -> u64;
total_received
​
/// Get the total balance of tips received for a [`VerificationContext`]
///
/// # Arguments
/// * account_id - The holder of a successful [`VerificationRequest`] for the verification context
/// * verification_context - The [`VerificationContext`] to query
///
/// # Return
/// Total balance, sum of all [`Tip`]s for the specified verification context
fn total_received(
account_id: AccountId,
verification_context: VerificationContext
) -> Balance;