-
Notifications
You must be signed in to change notification settings - Fork 0
Machine
Machine is used to design and define process consensus. Each machine consists of several nodes that are connected in a serial or parallel manner, and process collaborators can advance to the next node according to the permissions and conditions defined by the current node. The execution instance of a machine object is a progress object, and once a machine is published, it will be locked for editing and will allow the generation and operation of progress instances.
Definition
// When bPaused and bPublished are both true, allowing progress generation
struct Machine has key {
id: UID,
description: String,
// Progress nodes: key-value pairs of node names and node data
nodes: LinkedTable<String, NodeBody>,
// Committed data consensus repository
consensus_repositories: vector, // named repository declared
// Additional web2 information, which can be a URL
endpoint: Option<String>,
// Permission management
permission: address,
// Whether to pause the generation of progress: true (pause), false (open)
bPaused: bool,
// Whether published: true (production environment, nodes will no longer be editable, and progress generation is allowed); false (editing environment, nodes can be modified, and progress generation is not allowed)
bPublished: bool,
}
struct NodeBody has store, copy, drop {
description: String,
// Node pairs: key-value pairs of the previous node name and the information of this node pair
pairs: VecMap<String, NodePair>,
}
struct NodePair has store, drop, copy {
// Migration threshold. The threshold condition that must be met to transition from the previous node to the next node
threshold: u64,
// All paths from the previous node to the next node: key-value pairs of path names and path information
forwards: VecMap<String, Forward>,
}
// The namedOperator (if defined) and machine permission (if defined) can both potentially become operators to complete the path
struct Forward has store, copy, drop {
// The progress operator of the path (e.g., the buyer in different orders), which is assigned by the progress
namedOperator: String,
// Path weight. When the cumulative weight of paths executed between two nodes exceeds the NodePair.threshold (in parallel), it means jumping from the previous node to the next node
weight: u64, // op weight
// Path guard. The conditions that the operator must meet to complete the path, such as completing certain on-chain operations, etc.
guard: Option<address>,
// The permission index requirements that the path operator must meet as stipulated by the machine permission (belongs to a custom permission index, must be greater than 10000)
permission_index: Option<u64>,
}
// The carrier of NodeBody, which can be built, owned, and edited by the operator; if permission allows, NodeBody can be published to the machine or retrieved from the machine
struct Node has key, store {
id: UID,
name: String,
body: NodeBody,
}
// The maximum number of nodes allowed for a machine
const MAX_NODE_COUNT: u64 = 200;
Operations
Launch machine (shared object)
create(machine: Machine): address
Set a new permission. The operation permission must satisfy being the builder of the old permission.
permission_set(machine: &mut Machine, old: &Permission, new: &Permission)
[Permission index: 600] Create a new machine
new(description: String, endpoint_url: Option<String>, permission: &Permission) : Machine
[Permission index: 601] Set description
description_set(machine: &mut Machine, description: String, permission: &Permission)
[Permission index: 602] Add consensus repository
repository_add(machine: &mut Machine, repository: &Repository, permission: &Permission)
[Permission index: 603] Remove consensus repository
repository_remove(machine: &mut Machine, repositories: vector<address>, permission: &Permission)
[Permission index: 603] Remove all consensus repositorys
repository_remove_all(machine: &mut Machine, permission: &Permission)
[Permission index: 604] Clone the current machine to create a new machine. Can be used for re-editing and then launching
clone(machine: &Machine, permission: &Permission) : Machine
[Permission index: 606] Add nodes to the machine. Must satisfy that the existing nodes in the machine do not have the same name
node_add(machine: &mut Machine, nodes: vector<Node>, permission: &Permission)
[Permission index: 607] Remove nodes from the machine and package them as Node objects to send to the operator. If bTransferMyself=true, the removed nodes will be sent as Node objects to the signer's address, and the signer can freely edit the Node before re-adding it to the machine
node_remove(machine: &mut Machine, nodes: vector<String>, bTransferMyself: bool, permission: &Permission)
[Permission index: 608] Set endpoint
endpoint_set(machine: &mut Machine, endpoint_url: Option<String>, permission: &Permission)
[Permission index: 609] Pause or start the machine
pause(machine: &mut Machine, bPaused: bool, permission: &Permission)
[Permission index: 610] Publish the machine to the production environment (while machine.bPaused=false). The machine nodes will no longer be editable, and progress instance generation is allowed.
publish(machine: &mut Machine, permission: &Permission)
Operations with passport
new_with_passport(passport: &mut Passport, description: String, endpoint_url: Option<String>, permission: &Permission) : Machine
description_set_with_passport(passport: &mut Passport, machine: &mut Machine, description: String, permission: &Permission)
repository_add_with_passport(passport: &mut Passport, machine: &mut Machine, repository: &Repository, permission: &Permission)
repository_remove_with_passport(passport: &mut Passport, machine: &mut Machine, repositories: vector<address>, permission: &Permission)
repository_remove_all_with_passport(passport: &mut Passport, machine: &mut Machine, permission: &Permission)
clone_with_passport(passport: &mut Passport, machine: &Machine, permission: &Permission) : Machine
node_add_with_passport(passport: &mut Passport, machine: &mut Machine, nodes: vector<Node>, permission: &Permission)
node_remove_with_passport(passport: &mut Passport, machine: &mut Machine, nodes: vector<String>, bTransferMyself, permission: &Permission)
endpoint_set_with_passport(passport: &mut Passport, machine: &mut Machine, endpoint_url: Option<String>, permission: &Permission)
pause_with_passport(passport: &mut Passport, machine: &mut Machine, bPaused: bool, permission: &Permission)
publish_with_passport(passport: &mut Passport, machine: &mut Machine, permission: &Permission)
Operations for Node
// Create a new Node (owned object)
new(name: String, description: String, ctx: &mut TxContext) : Node
// Destroy Node
destroy(node: Node)
// Clone a new Node from an existing Node
clone(node: &Node) : Node
// Create a new path between node pairs (and set Guard)
forward(namedOperator: String, weight: u64, guard: &Guard, permission_index: Option<u64>) : Forward
// Create a new path between node pairs
forward2(namedOperator: String, weight: u64, permission_index: Option<u64>) : Forward
// Add the path to the node pair
forward_add(node: &mut Node, node_prior: String, forward_name: String, threshold: Option<u64>, forward: Forward)
// Remove the path from the node pair
forward_remove(node: &mut Node, node_prior: String, forward_name: String)
// Set the migration threshold of the node pair
threshold_set(node: &mut Node, node_prior: String, threshold: Option<u64>)
On-chain query for Guard
[Query: 1] Machine permission [address]; input: none
[Query: 2] Machine.bPaused [bool]; input: none
[Query: 3] Machine.bPublished [bool]; input: none
[Query: 5] Whether the repository is a consensus repository of the machine [bool]; input: repository id [address]
[Query: 6] Whether the machine endpoint is set [bool]; input: none
[Query: 7] Machine endpoint [string]; input: none
Errors
160002: Refused to create progress, please check machine.bPaused=false
160008: The machine has been published, machine nodes are not editable
160010: Refused to create progress, please check machine.bPublished=true
160012: Exceeded the maximum number of nodes