Skip to content

Progress

wowok-ai edited this page May 15, 2024 · 1 revision

Progress is the execution instance of a machine. A machine can create multiple completely independent progresses. Progress-related permission operations inherit the permission defined by its machine.

Definition

struct Holder has store, drop, copy {
    who: Option<address>,
    sub_progress: Option<address>, // child progress-id or else, if any
    deliverables: Option<address>, // deliverables-id, if any
    accomplished: bool, // the flag of accomplished
}

struct Session has store, drop, copy {
    forwards: VecMap<String, Holder>, // map of forward - Holder
    weights: u64, // total weights completed
}

struct History has store, drop {
    node: String, // current node name
    next_node: String, // next node name
    session: VecMap<String, Session>, // sessions for this node-pair
}

struct Parent has store, drop {
    session_index: u64, // parent progress session_index_current
    parent: address, // parent progress id
}

struct Progress has key {
    id: UID,
    // The machine that constructs this progress
    machine: address,
    // Whether it is a child progress of another progress
    parent: Option<Parent>
    // The consensus database of this progress. Can be used to share collaborative data of this progress
    context_repository: Option<address>,  
    // The name of the current node. The initial node name is ""
    current: String,
    // The object served by the progress. For example, it is the service progress of a certain order
    task: Option<address>,
    // Progress operator. Key-value pairs of the operator name (defined by machine.Forward) and the address (operator of this Forward)
    namedOperator: VecMap<String, vector<address>>,
    // Node running session; the next node name and the session information of these two nodes
    session: VecMap<String, Session>, // node-name - session
    // Node running history; when the node migration occurs, progress session will be saved to progress history; and progress session will be cleared to start a new session record
    history: TableVec<History>,
    
    lists: LinkedTable<String, vector<Session>>, 
}

// Session information during the operation at this node, including the record of the path (Forward) operator and the completion status
struct Session has store, drop {
    // Node departure path information. Key-value pairs of the path name and operator information
    events: VecMap<String, Holder>,
    // The total weight completed in the node session. If it exceeds the threshold of the node pair (threshold), it will enter the next node
    weights: u64,
    // Node session completion flag. true (session completed, migrated to the next node), false (node session in progress)
    closed: bool,
}

struct Holder {
    // Address operating the path
    who: Option<address>,
    // Other progressions upon which the path completion depends
    sub: Option<address>,
    // Deliverables of the path completion
    deliverables: Option<address>, 
    // Whether the path has been completed
    accomplished: bool, 
}

// The maximum number of progress operators
const MAX_NAMED_OPERATOR_COUNT: u64 = 100;
// The progress operator name of the order payer
const ORDER_PAYER: vector = b"order payer";
// The initial node name
const INITIAL_NODE_NAME: vector = b"";

Operations

Launch progress (shared object)

create(progress: Progress) : address

Hold operation of the path operator at the current node, declaring that the task required by this operator to complete the path is undertaken by them. Before this operator Unhold (either the operator themselves or someone with permission related to machine permission can Unhold), others will not be able to submit the task. bHold: true (Hold), false (Unhold)

hold(progress:&mut Progress, machine: &Machine, next_node:String,forward:String, bHold:bool, permission:&Permission)

The task of the current node's path is completed, and the operator submits the task. If another operator holds the path task, the submission fails; if a Guard is set for this path, the submission fails (next_with_passport must be used).

next(progress:&mut Progress, machine: &Machine, next_node:String, forward:String, deliverables:Option<address>, sub_progress_id:Option<address>, permission:&Permission)

The task of the current node's path is completed, and the operator submits the task. If another operator has held the path task, the submission will fail; if a Guard is set for this path, a passport that meets this Guard must be created and provided. If the passport verification fails, the submission will fail.

next_with_passport(passport:&mut Passport, progress:&mut Progress, machine: &Machine, next_node:String, forward:String, deliverables:Option<address>, sub_progress_id:Option<address>, permission:&Permission) 

[Permission index: 650] Create a new progress

new(machine: &mut Machine, permission: &Permission) : Progress

[Permission index: 651] Set progress operator

namedOperator_set(progress: &mut Progress, name: String, addr: vector<address>, machine: &Machine, permission: &Permission)

[Permission index: 652] Set the object served by Progress (e.g., the service progress of an order)

task_set(progress: &mut Progress, task: address, machine: &Machine, permission: &Permission)

[Permission index: 653] Set the collaborative consensus repository

context_repository_set(progress: &mut Progress, repository: &Repository, machine: &Machine, permission: &Permission)

[Permission index: 653] Remove the collaborative consensus repository

context_repository_none(progress: &mut Progress, machine: &Machine, permission: &Permission)

[Permission index: 654] Unhold a path(operation). Can be used to cancel an operator who has been holding the path operation for a long time.

unhold(progress: &mut Progress, machine: &Machine, next_node: String, forward: String, permission: &Permission)

[Permission index: 655] Set the parent progress; parent_id is the parent progress ID, session_index is the session of the parent progress

parent_set(progress:&mut Progress, machine:&Machine, parent_id:address, session_index:u64, permission:&Permission, ctx:&mut TxContext)  

[Permission index: 655] Cancel setting the parent progress

parent_none(progress: &mut Progress, machine: &Machine, permission: &Permission, ctx: &mut TxContext)

Operations with passport

new_with_passport(passport: &mut Passport, machine: &mut Machine, permission: &Permission) : Progress
namedOperator_set_with_passport(passport: &mut Passport, progress: &mut Progress, name: String, addr: vector<address>, machine: &Machine, permission: &Permission)
task_set_with_passport(passport: &mut Passport, progress: &mut Progress, task: address, machine: &Machine, permission: &Permission)
context_repository_set_with_passport(passport: &mut Passport, progress: &mut Progress, repository: &Repository, machine: &Machine, permission: &Permission)
context_repository_none_with_passport(passport: &mut Passport, progress: &mut Progress, machine: &Machine, permission: &Permission)
unhold_with_passport(passport: &mut Passport, progress: &mut Progress, machine: &Machine, next_node: String, forward: String, permission: &Permission)
parent_set_with_passport(passport: &mut Passport, progress: &mut Progress, machine: &Machine, parent: address, session_index: u64, permission: &Permission, ctx: &mut TxContext)
parent_none_with_passport(passport: &mut Passport, progress: &mut Progress, machine: &Machine, permission: &Permission, ctx: &mut TxContext)

On-chain query for Guard

[Query: 1] Machine of progress[address]; input: none

[Query: 2] Current progress [vector]; input: none

[Query: 3] Whether parent progress is set [bool]; input: none

[Query: 4] Parent progress id [address]; must satisfy [query: 3]. input: none

[Query: 5] Whether progress task is set [bool]; input: none

[Query: 6] progress task [address]; must satisfy [query: 5]. input: none

[Query: 7] Whether a certain namedOperator is set [bool]; input: namedOperator name [vector]

[Query: 8] Whether a certain namedOperator includes a certain address [bool]; must satisfy [query: 7]. input: namedOperator name [vector] address [address]

[Query: 9] Whether context_repository is set [bool]; input: none

[Query: 10] Context_repository id [address]; must satisfy [query: 9]. input: none

Errors

162000: The operator does not belong to the permission index and NamedOperator.
162008: The progress task already exists.
162010: The number of dynamic operator addresses has reached its maximum.
162018: The progress does not match with the machine.
Clone this wiki locally