Skip to content

Documentation / @cashconnect-js/templates-dev / helpers/resolve

Resolve

Defined in: packages/templates-dev/src/helpers/resolve.ts:3

Constructors

Constructor

ts
new Resolve(): Resolve;
Returns

Resolve

Methods

createState()

ts
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
ParameterTypeDescription
prefixstringThe namespace prefix for the state (e.g., 'match')
schemaTThe state schema defining required fields
fieldsRecord<keyof T, string>Values for all fields in the schema
Returns

Record<string, string>

Example
ts
Resolve.create('match', MatchState, {
  matchTxHash: expr`createMatchTxHash`,
  matchAmount: expr`matchAmount`,
})

forwardState()

ts
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
ParameterTypeDescription
prefixstringThe namespace prefix for the state (e.g., 'offerNo')
schemaTThe 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
ts
Resolve.forward('offerNo', OfferState, {
  offerTxHash: expr`createMatchTxHash`,
  liquidityAmount: expr`noRemainingLiquidity`,
})

copyState()

ts
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
ParameterTypeDescription
fromPrefixstringThe source namespace prefix (e.g., 'offerYes')
toPrefixstringThe destination namespace prefix (e.g., 'offer')
schemaTThe 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
ts
// Copy with selective overrides
Resolve.copyState('offerYes', 'offer', OfferState, {
  offerTxHash: expr`newTxHash`,
})
// Result: { 'offer__offerTxHash': 'newTxHash', 'offer__field2': '<offerYes__field2>', ... }

flattenState()

ts
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
ParameterTypeDescription
prefixstringThe namespace prefix of the source state (e.g., 'offerYes')
schemaTThe state schema defining available fields
Returns

Record<string, string>

Example
ts
lockingBytecode: {
  script: '#EventsBchOffer.lock',
  resolve: Resolve.flatten('offerYes', OfferContractParams),
}