DefaultSmartContractService
Default in-memory implementation of SmartContractService.
This is a simple implementation suitable for testing and development. Production implementations should use persistent storage.
All state changes of one contract are serialised by a per-contract Mutex and written with a compare-and-set against the record that was read, so two concurrent executions of the same ACTIVE contract cannot both execute it. A slow credential issuance, anchor write or engine evaluation therefore only delays the one contract it belongs to, never an unrelated one; the mutex of a contract exists only while an operation on it is running or waiting.
Lifecycle rules.
A contract can only become ACTIVE (through activateContract or updateStatus) once bindContract bound a credential to it, and, when a blockchain registry is configured, an anchor.
updateStatus refuses ContractStatus.EXECUTED: a contract is executed only by executeContract, which evaluates its conditions first. A ExecutionModel.Manual contract has no engine; it executes when its terms contain no conditions (conditions cannot be evaluated automatically, so such a contract is refused rather than executed unchecked).
Re-binding replaces the previous credential and drops everything this service kept for it.
Parameters
optional lookup for contract credentials that this instance did not issue itself; used by verifyContract.
optional extra policy deciding which issuers may vouch for a contract in verifyContract. Without it, the credential issuer must be a party to the contract or the issuer DID this service itself used when issuing the credential.
when true, verifyContract also checks that the anchored payload attests to this contract and credential (default false). Fails closed: a contract with no anchor, or whose anchor's chain has no client in the registry, does not verify.
capacity limits of the in-memory stores, see ContractStoreLimits.
Constructors
Functions
Activate a contract (move from PENDING to ACTIVE).
Anchor contract to blockchain for audit trail.
Bind a contract (issue credential and anchor to blockchain).
Create a contract draft.
DSL form of SmartContractService.createDraft.
Convenience alias for SmartContractService.createDraft.
Evaluate contract conditions.
DSL form of SmartContractService.evaluateConditions.
Execute contract based on execution model.
DSL form of SmartContractService.executeContract.
Execute a contract with event data supplied as key/value pairs.
Execute a contract with parametric trigger data supplied as key/value pairs.
Get contract by ID.
Issue verifiable credential for the contract.
Convenience alias for SmartContractService.issueContractCredential.
Recorded status changes (including reason and metadata) for contractId, oldest first.
Update contract status.
Verifies the contract bound to credentialId.