Flow Model
The flow
model provides a framework for creating and managing multi-step workflows, particularly those requiring digital signatures. It is designed to orchestrate a sequence of actions that must be completed in a specific order.
Core Components
1. Flow
The top-level container for a workflow.
flow_uuid
: A unique identifier for the entire flow, used for external references.name
: A human-readable name for the flow (e.g., "Document Approval Process").status
: The overall status of the flow (e.g., "Pending", "InProgress", "Completed").steps
: AVec<FlowStep>
that defines the sequence of steps in the workflow.
2. FlowStep
Represents a single, distinct step within a Flow
.
step_order
: Au32
that determines the position of this step in the sequence.description
: An optional text description of what this step entails.status
: The status of this individual step.
3. SignatureRequirement
Defines a requirement for a digital signature within a FlowStep
. A single step can have multiple signature requirements.
flow_step_id
: A foreign key linking the requirement to its parentFlowStep
.public_key
: The public key of the entity that is required to sign.message
: The plaintext message that needs to be signed.signature
: The resulting signature, once provided.status
: The status of the signature requirement (e.g., "Pending", "Signed", "Failed").
Usage
The models use a builder pattern to construct complex flows. You create a Flow
, add FlowStep
s to it, and associate SignatureRequirement
s with each step.
use heromodels::models::flow::{Flow, FlowStep, SignatureRequirement};
use uuid::Uuid;
// 1. Define a signature requirement
let requirement = SignatureRequirement::new(
0, // ID is managed by the database
1, // Belongs to flow step 1
"0xPublicKey1...",
"I approve this document."
);
// 2. Create a flow step
// In a real application, you would add the signature requirement to the step.
let step1 = FlowStep::new(0, 1) // ID, step_order
.description("Initial review and approval");
// 3. Create the main flow and add the step
let flow = Flow::new(Uuid::new_v4().to_string())
.name("Contract Signing Flow")
.add_step(step1);