OZContextRuleType

public enum OZContextRuleType : Sendable, Hashable

Type of context rule that determines which operations it applies to.

Context rules use pattern matching to determine when signers and policies should be enforced. Four types of context matching are supported:

  • Default: Matches any operation (fallback rule)
  • CallContract: Matches invocations to a specific contract address
  • CreateContract: Matches contract deployments using a specific WASM hash
  • CreateContractExternalRef: Matches contract deployments from the executable reference that an owner contract stores under a tag (CAP-0085)

Example:

// Default rule applies to all operations
let defaultRule = OZContextRuleType.defaultRule

// Rule for calling a specific token contract
let tokenRule = OZContextRuleType.callContract(contractAddress: "CBCD1234...")

// Rule for deploying contracts with a specific WASM hash
let deployRule = OZContextRuleType.createContract(wasmHash: wasmHashData)
  • Matches any operation (fallback / default rule).

    Declaration

    Swift

    case defaultRule
  • Matches invocations to a specific contract address (C…, 56 characters).

    Declaration

    Swift

    case callContract(contractAddress: String)
  • Matches contract deployments using a specific 32-byte WASM hash.

    Declaration

    Swift

    case createContract(wasmHash: Data)
  • Matches contract deployments from a CAP-0085 executable reference: the WASM hash that the contract owner stores under tag.

    The hash is resolved when the contract is deployed, so the rule trusts the owner contract to keep the reference pointing at acceptable code. An account build without this rule kind, such as stellar-accounts 0.7, rejects it during simulation.

    owner is the address of the contract that stores the executable reference, a C… address for a rule built with createCreateContractExternalRefContextType(owner:tag:); a rule read from the chain keeps the stored address as its strkey. Two rules compare their tags by UTF-8 bytes, as the contract does.

    Declaration

    Swift

    case createContractExternalRef(owner: String, tag: String)
  • Declaration

    Swift

    public static func == (lhs: OZContextRuleType, rhs: OZContextRuleType) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • Converts the context rule type to its on-chain SCValXDR representation.

    The on-chain representation is:

    • Default: SCValXDR.vec([Symbol("Default")])
    • CallContract: SCValXDR.vec([Symbol("CallContract"), Address(contractAddress)])
    • CreateContract: SCValXDR.vec([Symbol("CreateContract"), Bytes(wasmHash)])
    • CreateContractExternalRef: SCValXDR.vec([Symbol("CreateContractExternalRef"), Address(owner), String(tag)])

    Throws

    InvalidAddress when the call-contract address or the external-reference owner cannot be converted to an SCAddressXDR.

    Declaration

    Swift

    public func toScVal() throws -> SCValXDR

    Return Value

    The SCValXDR representation of this context rule type.