-
Notifications
You must be signed in to change notification settings - Fork 0
Demand
Demand is used for personalized demand fulfillment through a reward-based bounty. By offering a reward (bounty), it attracts services that meet the demand. Once a service is picked, its presenter can receive the bounty. If there is no service that meets the criteria, the bounty can be increased, or it can be reclaimed after the reward window period (demand.time_expire).
Definition
struct Demand<T:key + store> has key {
id: UID,
// Demand description
description: String,
// Bounty. Can be dynamically increased via deposit
bounty: vector,
// Deadline for accepting present services. After this time, if bounty has not been awarded to the service presenter, it can be reclaimed
time_expire: Option<u64>,
// Conditions that the present service must meet
guard: Option<address>,
// List of present services. Key-value pairs of service id and Tips
presenters: Table<address, Tips>,
// The final picked service, and bounty will be paid to the presenter of this service
yes: Option<address>,
// Permission table
permission: address,
}
struct Tips has store, copy, drop {
// Recommendation
tips: String,
// Presenter, who provided this service information
who: address,
}
// Maximum number of bounty shares allowed
const MAX_bounty_COUNT: u64 = 200;
// Maximum number of service presenters allowed
const MAX_PRESENTERS_COUNT: u64 = 200;
Operations
Launch demand (shared object)
create<T: key + store>(demand: Demand<T>) : address
Set a new permission. The operation permission must satisfy being the builder of the old permission.
permission_set<T: key + store>(demand: &mut Demand<T>, old: &Permission, new: &Permission, ctx: &mut TxContext)
Deposit bounty reward
deposit<T: key + store>(demand: &mut Demand<T>, bounty: T)
Provide service information for the demand; if the demand guard is set, present_with_passport must be called
present<T: key + store, K>(demand: &mut Demand<T>, service: &Service<K>, tips: String, ctx: &mut TxContext)
Provide service information for the demand, passport is required to pass the demand guard
present_with_passport<T: key + store, K>(passport: &mut Passport, demand: &mut Demand<T>, service: &Service<K>, tips: String, ctx: &mut TxContext)
[Permission index: 260] Create a new demand
new<T: key + store>(description: String, bounty: T, permission: &Permission, ctx: &mut TxContext) : Demand<T>
[Permission index: 261] Reclaim bounty, must satisfy being after the demand.time_expire (if set)
refund<T: key + store>(demand: &mut Demand<T>, clock: &Clock, permission: &Permission, ctx: &mut TxContext)
[Permission index: 262] Extend the time for the demand to accept present services; if demand.time_expire is not yet set, extend it on top of the current transaction time. minutes_duration: the number of minutes to extend
time_expand<T: key + store>(demand: &mut Demand<T>, minutes_duration: u64, clock: &Clock, permission: &Permission, ctx: &mut TxContext)
[Permission index: 263] Set the guard condition for presenting services
guard_set<T: key + store>(demand: &mut Demand<T>, guard: &Guard, permission: &Permission, ctx: &mut TxContext)
[Permission index: 263] Remove the guard condition for presenting services
guard_none<T: key + store>(demand: &mut Demand<T>, permission: &Permission, ctx: &mut TxContext)
[Permission index: 264] Set the description
description_set<T: key + store>(demand: &mut Demand<T>, description: String, permission: &Permission, ctx: &mut TxContext)
[Permission index: 265] Pick a service and pay bounty to the presenter of that service
yes<T: key + store>(demand: &mut Demand<T>, service: address, permission: &Permission, ctx: &mut TxContext)
Operations with passport
new_with_passport<T: key + store>(passport: &mut Passport, description: String, bounty: T, permission: &Permission, ctx: &mut TxContext) : Demand<T>
refund_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, clock: &Clock, permission: &Permission, ctx: &mut TxContext)
time_expand_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, minutes_duration: u64, clock: &Clock, permission: &Permission, ctx: &mut TxContext)
guard_set_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, guard: &Guard, permission: &Permission, ctx: &mut TxContext)
guard_none_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, permission: &Permission, ctx: &mut TxContext)
description_set_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, description: String, permission: &Permission, ctx: &mut TxContext)
yes_with_passport<T: key + store>(passport: &mut Passport, demand: &mut Demand<T>, service: address, permission: &Permission, ctx: &mut TxContext)
On-chain query for Guard
[Query: 1] Demand permission [address]; input: none
[Query: 2] Whether demand.time_expire is set [bool]; input: none
[Query: 3] Demand.time_expire [u64]; must satisfy [query: 2]. input: none
[Query: 4] The portion of demand bounty [u64]; input: none
[Query: 5] Whether demand guard is set [bool]; input: none
[Query: 6] Demand guard id [address]; must satisfy [query: 5]. input: none
[Query: 7] Whether the service has been picked and the bounty has been paid [bool]; input: none
[Query: 8] The picked service demand.yes [address]; must satisfy [query: 7]. input: none
[Query: 9] The number of demand presenters [u64]; input: none
[Query: 10] Whether demand presenters contains a certain service [bool]; input: service id [address]
[Query: 11] The provider's address of a certain service in demand presenters [address]; must satisfy [query: 10]. input: service id [address]
Errors
183002: Exceeded the maximum number of reward shares
183004: Reclaiming the reward must be after the time demand.time_expire
183006: A passport is required
183008: The number of demand presenters exceeds the maximum number