Cartouche.Sleuth (Cartouche v0.2.0)

Copy Markdown View Source

Sleuth allows you to run a contract call as a single eth_call call.

Note: Cartouche.Contract.Sleuth generated from mix cartouche.gen --prefix cartouche/contract ./priv/Sleuth.json

Summary

Functions

Runs a Sleuth contract query: deploys bytecode on-chain via eth_call with query calldata and decodes the result against selector. Returns the decoded values without struct annotations.

Same as query/4, but tags each decoded value with its ABI type for callers that need both type and value (e.g. when re-encoding).

Single-argument form of query_by/2: defaults fun to :query and opts to [].

Convenience wrapper that derives bytecode, query calldata, and selector from a generated contract module. Resolves mod.bytecode/0, mod.encode_<fun>/0, and mod.<fun>_selector/0 and forwards the rest to query/4.

Three-argument form of query_by/2: explicit fun and opts.

Variant of query/4 that exposes the full set of decode options (:annotated, :decode_binaries, :decode_structs, :named_returns, :sleuth_address) as keyword opts. Returns results with named-return annotations when configured.

Functions

query(bytecode, query, selector, opts \\ [])

@spec query(binary(), binary(), ABI.FunctionSelector.t(), Keyword.t()) ::
  {:ok, term()} | {:error, String.t()}

Runs a Sleuth contract query: deploys bytecode on-chain via eth_call with query calldata and decodes the result against selector. Returns the decoded values without struct annotations.

query_annotated(bytecode, query, selector, opts \\ [])

@spec query_annotated(binary(), binary(), ABI.FunctionSelector.t(), Keyword.t()) ::
  {:ok, term()} | {:error, String.t()}

Same as query/4, but tags each decoded value with its ABI type for callers that need both type and value (e.g. when re-encoding).

query_by(mod)

@spec query_by(module()) :: {:ok, term()} | {:error, String.t()}

Single-argument form of query_by/2: defaults fun to :query and opts to [].

query_by(mod, fun)

@spec query_by(module(), atom() | Keyword.t()) :: {:ok, term()} | {:error, String.t()}

Convenience wrapper that derives bytecode, query calldata, and selector from a generated contract module. Resolves mod.bytecode/0, mod.encode_<fun>/0, and mod.<fun>_selector/0 and forwards the rest to query/4.

query_by(mod, fun, opts)

@spec query_by(module(), atom(), Keyword.t()) :: {:ok, term()} | {:error, String.t()}

Three-argument form of query_by/2: explicit fun and opts.

query_v2(bytecode, query, selector, opts \\ [])

@spec query_v2(binary(), binary(), ABI.FunctionSelector.t(), Keyword.t()) ::
  {:ok, term()} | {:error, String.t()}

Variant of query/4 that exposes the full set of decode options (:annotated, :decode_binaries, :decode_structs, :named_returns, :sleuth_address) as keyword opts. Returns results with named-return annotations when configured.