Documentation / @cashconnect-js/templates-dev / helpers/resolve
Resolve
Defined in: packages/templates-dev/src/helpers/resolve.ts:3
Constructors
Constructor
new Resolve(): Resolve;Returns
Methods
createState()
static createState<T>(
prefix,
schema,
fields): Record<string, string>;Defined in: packages/templates-dev/src/helpers/resolve.ts:18
Creates a new state by mapping fields to a prefixed namespace. All fields in the schema must be provided - use for initializing new state objects.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix for the state (e.g., 'match') |
schema | T | The state schema defining required fields |
fields | Record<keyof T, string> | Values for all fields in the schema |
Returns
Record<string, string>
Example
Resolve.create('match', MatchState, {
matchTxHash: expr`createMatchTxHash`,
matchAmount: expr`matchAmount`,
})forwardState()
static forwardState<T>(
prefix,
schema,
overrides?): Record<string, string>;Defined in: packages/templates-dev/src/helpers/resolve.ts:46
Forwards all fields from a prefixed state, allowing selective overrides. Fields without overrides pass through unchanged.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix for the state (e.g., 'offerNo') |
schema | T | The state schema defining available fields |
overrides? | Partial<Record<keyof T, string>> | Optional field values to override instead of passing through |
Returns
Record<string, string>
Example
Resolve.forward('offerNo', OfferState, {
offerTxHash: expr`createMatchTxHash`,
liquidityAmount: expr`noRemainingLiquidity`,
})copyState()
static copyState<T>(
fromPrefix,
toPrefix,
schema,
overrides?): Record<string, string>;Defined in: packages/templates-dev/src/helpers/resolve.ts:77
Copies all fields from one prefixed state to another prefix, allowing selective overrides. Useful when transferring state between different namespaces (e.g., copying offer state to a new context).
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
fromPrefix | string | The source namespace prefix (e.g., 'offerYes') |
toPrefix | string | The destination namespace prefix (e.g., 'offer') |
schema | T | The state schema defining available fields |
overrides? | Partial<Record<keyof T, string>> | Optional field values to override instead of copying from source |
Returns
Record<string, string>
Example
// Copy with selective overrides
Resolve.copyState('offerYes', 'offer', OfferState, {
offerTxHash: expr`newTxHash`,
})
// Result: { 'offer__offerTxHash': 'newTxHash', 'offer__field2': '<offerYes__field2>', ... }flattenState()
static flattenState<T>(prefix, schema): Record<string, string>;Defined in: packages/templates-dev/src/helpers/resolve.ts:105
Flattens a prefixed state into unprefixed keys for script resolve blocks.
Type Parameters
| Type Parameter |
|---|
T extends Record<string, | { type: "array"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: "object"; properties: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodEnum<{ string: "string"; number: "number"; transaction: "transaction"; enum: "enum"; address: "address"; bytes: "bytes"; publicKey: "publicKey"; satoshis: "satoshis"; signature: "signature"; transactionHash: "transactionHash"; }>; name: z.ZodString; required: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>; }, z.core.$strip>], "type">>; required?: boolean; } | { type: | "string" | "number" | "transaction" | "enum" | "address" | "bytes" | "publicKey" | "satoshis" | "signature" | "transactionHash"; name: string; required?: boolean; }> |
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | The namespace prefix of the source state (e.g., 'offerYes') |
schema | T | The state schema defining available fields |
Returns
Record<string, string>
Example
lockingBytecode: {
script: '#EventsBchOffer.lock',
resolve: Resolve.flatten('offerYes', OfferContractParams),
}