AbstractBlockchainAnchorClient

Abstract base class for blockchain anchor client implementations.

Provides common functionality shared across blockchain adapters:

  • Strictly opt-in in-memory test fallback (see OPTION_IN_MEMORY_TEST_MODE)

  • Common error handling patterns

  • AnchorRef construction helpers

  • Transaction hash generation utilities

Fail-closed behavior: when the client has no usable chain credentials/connection (canSubmitTransaction returns false) and inMemoryTestMode is not enabled, writePayload throws BlockchainException.ConfigurationFailed instead of fabricating a transaction hash. The in-memory fallback is ONLY active when the caller explicitly opts in via options["inMemoryTestMode"] = true — it is intended for tests and demos, never production: payloads are NOT anchored on any chain.

Subclasses should implement:

Constructors

Link copied to clipboard
constructor(chainId: String, options: Map<String, Any?>)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Estimate the native-token fee that an operation would cost on this chain. Plugins compute this from the chain's native API (eth_feeHistory, Algorand suggested params, Cardano protocol params, Bitcoin estimatesmartfee, …). The default returns TokenAmount.unknown for plugins that have not yet implemented the payment plane.

Link copied to clipboard
open suspend override fun readPayload(ref: AnchorRef): AnchorResult

Reads a payload from the blockchain using an anchor reference.

Link copied to clipboard
open suspend override fun verifyAnchor(payload: JsonElement, ref: AnchorRef): Boolean

Boolean verification. An anchor served from the in-memory test fallback is NOT chain evidence, so it only counts as verified when this client was explicitly constructed with inMemoryTestMode = true (tests/demos, where memory is the only store). A client without explicit test mode can never serve from memory, and a testMode-flagged result that reaches it anyway (foreign ref) yields false. Use verifyAnchorDetailed to see the testMode flag.

Link copied to clipboard
open suspend override fun verifyAnchorDetailed(payload: JsonElement, ref: AnchorRef, requireCanonicalEnvelope: Boolean): AnchorVerification

Same result as BlockchainAnchorClient.verifyAnchorDetailed; additionally calls onLegacyDigestAccepted, once per client instance, when a legacy (non-JCS) digest envelope was accepted (see OPTION_REQUIRE_CANONICAL_ENVELOPE).

Link copied to clipboard
open suspend override fun writePayload(payload: JsonElement, mediaType: String = "application/json"): AnchorResult

Writes a payload to the blockchain and returns an anchor reference.

open suspend fun writePayload(payload: JsonElement, ctx: PaymentContext, mediaType: String = "application/json"): AnchorResult

Payment-aware write. Plugins that opt into the payment plane override this; the default delegates to the legacy writePayload so existing implementations keep compiling.