@arkade-os/sdk Documentation - v0.4.0-next.8
    Preparing search index...

    Interface ContractHandler<P, S>

    Handler for a specific contract type.

    Each contract type (default, vhtlc, etc.) has a handler that knows how to:

    1. Create the VtxoScript from parameters
    2. Serialize/deserialize parameters for storage
    3. Select the appropriate spending path based on context
    const vhtlcHandler: ContractHandler = {
    type: "vhtlc",
    createScript(params) {
    return new VHTLC.Script(this.deserializeParams(params));
    },
    selectPath(script, contract, context) {
    const vhtlc = script as VHTLC.Script;
    const preimage = contract.data?.preimage;
    if (context.collaborative && preimage) {
    return { leaf: vhtlc.claim(), extraWitness: [hex.decode(preimage)] };
    }
    // ... other paths
    },
    // ...
    };
    interface ContractHandler<
        P = Record<string, unknown>,
        S extends VtxoScript = VtxoScript,
    > {
        type: string;
        createScript(params: Record<string, string>): S;
        deserializeParams(params: Record<string, string>): P;
        getAllSpendingPaths(
            script: S,
            contract: Contract,
            context: PathContext,
        ): PathSelection[];
        getSpendablePaths(
            script: S,
            contract: Contract,
            context: PathContext,
        ): PathSelection[];
        selectPath(
            script: S,
            contract: Contract,
            context: PathContext,
        ): PathSelection | null;
        serializeParams(params: P): Record<string, string>;
    }

    Type Parameters

    Index

    Properties

    type: string

    The contract type this handler manages

    Methods

    • Create the VtxoScript from serialized parameters.

      Parameters

      • params: Record<string, string>

      Returns S

    • Deserialize string key-value pairs to typed parameters.

      Parameters

      • params: Record<string, string>

      Returns P

    • Serialize typed parameters to string key-value pairs.

      Parameters

      • params: P

      Returns Record<string, string>