contract

package
v0.0.0-...-b096497 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindActiveContractByInstanceAddress

func FindActiveContractByInstanceAddress(ctx context.Context, stateService apiv2.StateServiceClient, parties []string, templateId string, instanceAddress contracts.InstanceAddress) (*apiv2.ActiveContract, error)

FindActiveContractByInstanceAddress resolves a contract by Canton instance address (hex of instanceId bytes).

It queries the ACS at ledger end, filtering by template and by every party in parties (typically from LedgerQueryParties). A match is accepted when the created event's instanceId and sole signatory produce the same InstanceAddress as the target. The first matching contract wins; duplicate stream entries for the same contract ID (common when multiple parties see the same contract) are ignored.

Returns an error when parties is empty, when no contract matches, or when more than one distinct contract matches the same instance address. The ActiveContract includes CreatedEventBlob when the template filter requests it (required for explicit disclosures on submit).

func FindActiveContractIDByInstanceAddress

func FindActiveContractIDByInstanceAddress(ctx context.Context, stateService apiv2.StateServiceClient, parties []string, templateId string, instanceAddress contracts.InstanceAddress) (string, error)

FindActiveContractIDByInstanceAddress is a convenience wrapper around FindActiveContractByInstanceAddress that returns only the ledger contract ID.

func LedgerQueryParties

func LedgerQueryParties(participant canton.Participant) []string

LedgerQueryParties builds the party list for ledger ACS reads (GetActiveContracts, etc.).

The operator participant may ActAs one party while holding CanReadAs for others (for example CCIP owner parties under MCMS). Contract visibility is per-party: a token pool might only be readable via ReadAs party B even when ActAs party A cannot see it. Callers should pass the returned slice to FindActiveContractByInstanceAddress rather than picking a single party.

Order is ActAs party first, then ReadAs parties in config order. Duplicates and empty strings are omitted.

func NewBatchOperationFromExercises

func NewBatchOperationFromExercises(outs []ExerciseOutput) (mcms_types.BatchOperation, error)

NewBatchOperationFromExercises constructs an MCMS BatchOperation from a slice of ExerciseOutputs. It filters out any ExerciseOutputs that have already been executed. Returns an error if the ExerciseOutputs target multiple chains. If all ExerciseOutputs are executed, it returns an empty BatchOperation and no error.

func NewCantonTransaction

func NewCantonTransaction(
	rawInstanceAddress string,
	instanceAddress contracts.InstanceAddress,
	encodedChoice *bind.EncodedChoice,
	contractType deployment.ContractType,
	targetTemplateID string,
) (mcms_types.Transaction, error)

NewCantonTransaction converts an EncodedChoice into an MCMS Transaction with Canton-specific AdditionalFields. rawInstanceAddress must be in "instanceId@partyId" format (e.g. "globalconfig-abc12@party::hash") as required by the Canton MCMS SDK for Merkle leaf hashing. instanceAddress is the 32-byte Keccak256 hash used for the Transaction.To field. targetTemplateID is the Daml template ID (e.g. "#pkg:Module:Entity") of the target contract, used by the MCMS SDK to dynamically resolve the contract ID at execution time.

func NewDeploy

NewDeploy creates a new deploy operation for the given contract template. The operation's return value is an AddressRef, the Address of which will be a contracts.RawInstanceAddress.

InstanceId: The template *must* have an InstanceId field of type types.TEXT. If InstanceId is empty, it is generated using the provided prefix and a random suffix. If InstanceId is set by the caller, that value is preserved.

func NewExercise

func NewExercise[ARGS any](params ExerciseParams[ARGS]) *operations.Operation[ChoiceInput[ARGS], ExerciseOutput, canton.Chain]

func ValidateCantonAdditionalFields

func ValidateCantonAdditionalFields(raw json.RawMessage) error

ValidateCantonAdditionalFields validates that AdditionalFields JSON can be unmarshaled and has the required fields populated.

Types

type ChoiceInput

type ChoiceInput[ARGS any] struct {
	// The InstanceAddress this operation is targeting. Will be resolved to an active contract.
	InstanceAddress contracts.InstanceAddress `json:"instanceAddress"`
	// RawInstanceAddress is the "instanceId@partyId" format required by the Canton MCMS SDK
	// for AdditionalFields.TargetInstanceAddress. Must be set when MCMSEnabled is true.
	RawInstanceAddress string `json:"rawInstanceAddress,omitempty"`
	Args               ARGS   `json:"args"`
	MCMSEnabled        bool   `json:"mcmsEnabled,omitempty"`
	DisclosedContracts []DisclosedContract
}

type DeployInput

type DeployInput[TT common.Template] struct {
	Qualifier  *string     `json:"qualifier,omitempty"`
	Template   TT          `json:"createCommand"`
	OwnerParty types.PARTY `json:"ownerParty"`
}

type DeployParams

type DeployParams[ARGS any] struct {
	// Name is the name of the operation.
	Name string
	// TypeAndVersion is the type and version of the contract that's being deployed.
	TypeAndVersion deployment.TypeAndVersion
	// Description is a brief description of the operation.
	Description string
	// Validate is an optional function to validate the constructor arguments before deployment.
	Validate func(template ARGS) error
	// TODO remove and make part of template itself
	PackageName string
	// Prefix is the prefix used to create this contract's InstanceID.
	Prefix string `json:"prefix"`
}

type DisclosedContract

type DisclosedContract struct {
	TemplateId       contracts.TemplateID `json:"template_id"`
	ContractId       string               `json:"contract_id"`
	CreatedEventBlob []byte               `json:"created_event_blob"`
	SynchronizerId   string               `json:"synchronizer_id"`
}

DisclosedContract copies the regenerated protobuf message. The generated protobufs cannot be used as an operation's input since they contain unexported fields.

func DisclosedContractsFromProto

func DisclosedContractsFromProto(dcs []*apiv2.DisclosedContract) []DisclosedContract

type ExecInfo

type ExecInfo struct {
	// The ID of the update that was confirmed as the result of this execution.
	UpdateID string `json:"update_id"`
}

type ExerciseOutput

type ExerciseOutput struct {
	ChainSelector uint64                 `json:"chainSelector"`
	Tx            mcms_types.Transaction `json:"tx"`
	ExecInfo      *ExecInfo              `json:"execInfo,omitempty"`
}

func (ExerciseOutput) Executed

func (o ExerciseOutput) Executed() bool

type ExerciseParams

type ExerciseParams[ARGS any] struct {
	// Name is the name of the operation.
	Name string
	// Version is the version of the operation.
	Version *semver.Version
	// Description is a brief description of the operation.
	Description string
	// ContractType is the type of the target contract.
	ContractType deployment.ContractType
	// Modifier can be used to modify the argument for this exercise.
	Modifier func(chain canton.Chain, input ARGS) (ARGS, error)
	// Validate is an optional function to validate the input arguments.
	Validate func(input ARGS) error

	// Template is the binding struct of the target contract.
	Template common.Template
	// Method is the bindings method to call the choice.
	Method func(contractID string, args ARGS) *model.ExerciseCommand

	// EncodeMethod encodes the choice args to hex for MCMS proposals.
	// Uses the binding's Encoder (e.g., globalConfig.Encoder().ApplyDestChainConfigUpdates).
	// When nil, MCMS encoding is not available for this operation.
	EncodeMethod func(args ARGS) (*bind.EncodedChoice, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL