Enum mpl_token_auth_rules::state::Rule
source · pub enum Rule {
Show 17 variants
All {
rules: Vec<Rule>,
},
Any {
rules: Vec<Rule>,
},
Not {
rule: Box<Rule>,
},
AdditionalSigner {
account: Pubkey,
},
PubkeyMatch {
pubkey: Pubkey,
field: String,
},
PubkeyListMatch {
pubkeys: Vec<Pubkey>,
field: String,
},
PubkeyTreeMatch {
root: [u8; 32],
pubkey_field: String,
proof_field: String,
},
PDAMatch {
program: Option<Pubkey>,
pda_field: String,
seeds_field: String,
},
ProgramOwned {
program: Pubkey,
field: String,
},
ProgramOwnedList {
programs: Vec<Pubkey>,
field: String,
},
ProgramOwnedTree {
root: [u8; 32],
pubkey_field: String,
proof_field: String,
},
Amount {
amount: u64,
operator: CompareOp,
field: String,
},
Frequency {
authority: Pubkey,
},
IsWallet {
field: String,
},
Pass,
ProgramOwnedSet {
programs: HashSet<Pubkey>,
field: String,
},
Namespace,
}
Expand description
The struct containing every type of Rule and its associated data.
Variants§
All
Group AND, where every rule contained must pass.
Any
Group OR, where at least one rule contained must pass.
Not
Negation, where the contained rule must fail.
AdditionalSigner
An additional signer must be present. When the Validate
instruction is called, this rule
does not require any Payload
values, but the additional signer account must be provided
to Validate
via the additional_rule_accounts
argument so that whether it is a signer
can be retrieved from its AccountInfo
struct.
PubkeyMatch
Fields
Direct comparison between Pubkey
s. When the Validate
instruction is called, this rule
requires a PayloadType
value of PayloadType::Pubkey
. The field
value in the rule is
used to locate the Pubkey
in the payload to compare to the Pubkey
in the rule.
PubkeyListMatch
Fields
The comparing Pubkey
must be in the list of Pubkey
s. When the Validate
instruction
is called, this rule requires a PayloadType
value of PayloadType::Pubkey
. The field
value in the Rule is used to locate the Pubkey
in the payload to compare to the Pubkey
list in the rule.
PubkeyTreeMatch
Fields
The comparing Pubkey
must be a member of the Merkle tree in the rule. When the
Validate
instruction is called, this rule requires PayloadType
values of
PayloadType::Pubkey
and PayloadType::MerkleProof
. The field
values in the Rule are
used to locate them in the Payload
. The Pubkey
and the proof are used to calculate
a Merkle root which is compared against the root stored in the rule.
PDAMatch
Fields
A resulting PDA derivation of seeds must prove the account is a PDA. When the Validate
instruction is called, this rule requires PayloadType
values of PayloadType::Seeds
.
The field
values in the Rule are used to locate them in the Payload
. The seeds in the
Payload
and the program ID stored in the Rule are used to derive the PDA from the
Payload
.
ProgramOwned
Fields
The Pubkey
must be owned by a given program. When the Validate
instruction is called,
this rule requires a PayloadType
value of PayloadType::Pubkey
. The field
value in
the rule is used to locate the Pubkey
in the payload for which the owner must be the
program in the rule. Note this same Pubkey
account must also be provided to Validate
via the additional_rule_accounts
argument. This is so that the Pubkey
’s owner can be
found from its AccountInfo
struct.
ProgramOwnedList
Fields
The Pubkey
must be owned by a program in the list of Pubkey
s. When the Validate
instruction is called, this rule requires a PayloadType
value of PayloadType::Pubkey
.
The field
value in the rule is used to locate the Pubkey
in the payload for which the
owner must be a program in the list in the rule. Note this same Pubkey
account must also
be provided to Validate
via the additional_rule_accounts
argument. This is so that the
Pubkey
’s owner can be found from its AccountInfo
struct.
ProgramOwnedTree
Fields
The Pubkey
must be owned by a member of the Merkle tree in the rule. When the Validate
instruction is called, this rule requires PayloadType
values of PayloadType::Pubkey
and
PayloadType::MerkleProof
. The field
values in the Rule are used to locate them in the
Payload
. Note this same Pubkey
account must also be provided to Validate
via the
additional_rule_accounts
argument. This is so that the Pubkey
’s owner can be found
from its AccountInfo
struct. The owner and the proof are then used to calculate a Merkle
root, which is compared against the root stored in the rule.
Amount
Fields
Comparison against the amount of tokens being transferred. When the Validate
instruction is called, this rule requires a PayloadType
value of PayloadType::Amount
.
The field
value in the Rule is used to locate the numerical amount in the payload to
compare to the amount stored in the rule, using the comparison operator stored in the rule.
Frequency
Fields
The authority of the frequency account.
Comparison based on time between operations. Currently not implemented. This rule
is planned check to ensure a certain amount of time has passed. This rule will make use
of the rule_set_state_pda
optional account passed into Validate
, and will require
the optional rule_authority
account to sign.
IsWallet
The true test if a pubkey can be signed from a client and therefore is a true wallet account.
The details of this rule are as follows: a wallet is defined as being both owned by the
System Program and the address is on-curve. The field
value in the rule is used to
locate the Pubkey
in the payload that must be on-curve and for which the owner must be
the System Program. Note this same Pubkey
account must also be provided to Validate
via the additional_rule_accounts
argument. This is so that the Pubkey
’s owner can be
found from its AccountInfo
struct.
Pass
An operation that always succeeds.
ProgramOwnedSet
Fields
The Pubkey
must be owned by a program in the set of Pubkey
s. When the Validate
instruction is called, this rule requires a PayloadType
value of PayloadType::Pubkey
.
The field
value in the rule is used to locate the Pubkey
in the payload for which the
owner must be a program in the set in the rule. Note this same Pubkey
account must also
be provided to Validate
via the additional_rule_accounts
argument. This is so that the
Pubkey
’s owner can be found from its AccountInfo
struct.
Namespace
A rule that tells the operation finder to use the default namespace rule.
Implementations§
source§impl Rule
impl Rule
sourcepub fn validate(
&self,
accounts: &HashMap<Pubkey, &AccountInfo<'_>>,
payload: &Payload,
update_rule_state: bool,
rule_set_state_pda: &Option<&AccountInfo<'_>>,
rule_authority: &Option<&AccountInfo<'_>>
) -> ProgramResult
pub fn validate( &self, accounts: &HashMap<Pubkey, &AccountInfo<'_>>, payload: &Payload, update_rule_state: bool, rule_set_state_pda: &Option<&AccountInfo<'_>>, rule_authority: &Option<&AccountInfo<'_>> ) -> ProgramResult
The top level validation function which parses an entire rule tree.
sourcepub fn low_level_validate(
&self,
accounts: &HashMap<Pubkey, &AccountInfo<'_>>,
payload: &Payload,
_update_rule_state: bool,
_rule_set_state_pda: &Option<&AccountInfo<'_>>,
rule_authority: &Option<&AccountInfo<'_>>
) -> RuleResult
pub fn low_level_validate( &self, accounts: &HashMap<Pubkey, &AccountInfo<'_>>, payload: &Payload, _update_rule_state: bool, _rule_set_state_pda: &Option<&AccountInfo<'_>>, rule_authority: &Option<&AccountInfo<'_>> ) -> RuleResult
Lower level validation function which iterates through a rule tree and applies boolean logic to rule results.
sourcepub fn to_error(&self) -> ProgramError
pub fn to_error(&self) -> ProgramError
Convert the rule to a corresponding error resulting from the rule failure.