Class

FabricContractAdapter

FabricContractAdapter()

Constructor

# new FabricContractAdapter()

Provides a CouchDB-like interface for interacting with the Fabric state database from within a chaincode contract

Adapter for Hyperledger Fabric chaincode state database operations

sequenceDiagram participant Contract participant FabricContractAdapter participant Stub participant StateDB Contract->>FabricContractAdapter: create(tableName, id, model, transient, ctx) FabricContractAdapter->>FabricContractAdapter: Serialize model to JSON FabricContractAdapter->>Stub: putState(id, serializedData) Stub->>StateDB: Write data StateDB-->>Stub: Success Stub-->>FabricContractAdapter: Success FabricContractAdapter-->>Contract: model

View Source contracts/ContractAdapter.ts, line 55

Example
```typescript
// In a Fabric chaincode contract class
import { FabricContractAdapter } from '@decaf-ts/for-fabric';

export class MyContract extends Contract {
  private adapter = new FabricContractAdapter();

  

Classes

FabricContractAdapter

Initializes an adapter for interacting with the Fabric state database

FabricContractAdapter

Initializes an adapter for interacting with the Fabric state database

Members

# Context

Overrides the base Context constructor with FabricContractContext

Context constructor for this adapter

View Source contracts/ContractAdapter.ts, line 460

# textDecoder

Text decoder for converting binary data to strings

.

Text decoder for converting binary data to strings

View Source contracts/ContractAdapter.ts, line 454

Methods

# protected Context() → {Constructor.<FabricContractContext>}

Overrides the base Context constructor with FabricContractContext

Context constructor for this adapter

View Source contracts/ContractAdapter.ts, line 1712

Constructor.<FabricContractContext>

# async create(tableName, id, model, transient, …args) → {Promise.<Record.<string, any>>}

Serializes a model and stores it in the Fabric state database

Creates a record in the state database

Parameters:
Name Type Attributes Description
tableName string

The name of the table/collection

id string | number

The record identifier

model Record.<string, any>

The record data

transient Record.<string, any>

Transient data (not used in this implementation)

args Array.<any> <repeatable>

Additional arguments, including the chaincode stub and logger

View Source contracts/ContractAdapter.ts, line 1742

Promise resolving to the created record

Promise.<Record.<string, any>>

# protected decode(buffer) → {string}

Converts a Uint8Array to a string using UTF-8 encoding

Decodes binary data to string

Parameters:
Name Type Description
buffer Uint8Array

The binary data to decode

View Source contracts/ContractAdapter.ts, line 1797

The decoded string

string

# async delete(tableName, id, …args) → {Promise.<Record.<string, any>>}

Retrieves a record and then removes it from the Fabric state database

Deletes a record from the state database

Parameters:
Name Type Attributes Description
tableName string

The name of the table/collection

id string | number

The record identifier to delete

args Array.<any> <repeatable>

Additional arguments, including the chaincode stub and logger

View Source contracts/ContractAdapter.ts, line 1788

Promise resolving to the deleted record

Promise.<Record.<string, any>>

# async protected flags(operation, model, flags, ctx) → {FabricContractFlags}

Merges default flags with Fabric-specific context information

Creates operation flags for Fabric contract operations

Parameters:
Name Type Description
operation OperationKeys

The operation being performed

model Constructor.<M>

The model constructor

flags Partial.<FabricContractFlags>

Partial flags to merge with defaults

ctx Ctx

The Fabric chaincode context

View Source contracts/ContractAdapter.ts, line 1811

The merged flags

# protected index(models) → {Promise.<void>}

This method is not implemented for Fabric contracts and returns a resolved promise

Creates an index for a model

Parameters:
Name Type Description
models Constructor.<M>

The model constructor

View Source contracts/ContractAdapter.ts, line 1821

Promise that resolves immediately

Promise.<void>

# prepare(model, pk, args) → {PreparedModel|object}

Parameters:
Name Type Description
model
pk string
args

View Source contracts/ContractAdapter.ts, line 1906

PreparedModel | object

# async rangeList(clazz, attributesopt, …args) → {Promise.<Array.<M>>}

Iterates records via getStateByPartialCompositeKey (public) and getPrivateDataByPartialCompositeKey (private/shared), following the same collection-routing logic as raw() but using Fabric range queries instead of Mango selectors. Unlike raw(), this method is safe to use in the same transaction as writes because range queries are deterministic and do not block subsequent putState/putPrivateData calls.

Lists all records of a model using range queries (deterministic, write-safe)

Parameters:
Name Type Attributes Default Description
clazz Constructor.<M>

The model constructor

attributes Array.<string> <optional>
[]

Partial composite key attributes to filter by (empty = all records)

args ContextualArgs.<FabricContractContext> <repeatable>

Contextual arguments including the chaincode context

View Source contracts/ContractAdapter.ts, line 1897

Promise resolving to an array of reconstructed model instances

Promise.<Array.<M>>

# async raw(rawInput, docsOnly, …args) → {Promise.<R>}

Performs a rich query using CouchDB syntax against the Fabric state database

Executes a raw query against the state database

sequenceDiagram participant Caller participant FabricContractAdapter participant Stub participant StateDB Caller->>FabricContractAdapter: raw(rawInput, docsOnly, ctx) FabricContractAdapter->>FabricContractAdapter: Extract limit and skip alt With pagination FabricContractAdapter->>Stub: getQueryResultWithPagination(query, limit, skip) else Without pagination FabricContractAdapter->>Stub: getQueryResult(query) end Stub->>StateDB: Execute query StateDB-->>Stub: Iterator Stub-->>FabricContractAdapter: Iterator FabricContractAdapter->>FabricContractAdapter: resultIterator(log, iterator) FabricContractAdapter-->>Caller: results
Parameters:
Name Type Attributes Description
rawInput MangoQuery

The Mango Query to execute

docsOnly boolean

Whether to return only documents (not used in this implementation)

args Array.<any> <repeatable>

Additional arguments, including the chaincode stub and logger

View Source contracts/ContractAdapter.ts, line 1881

Promise resolving to the query results

Promise.<R>

# async read(tableName, id, …args) → {Promise.<Record.<string, any>>}

Retrieves and deserializes a record from the Fabric state database

Reads a record from the state database

Parameters:
Name Type Attributes Description
tableName string

The name of the table/collection

id string | number

The record identifier

args Array.<any> <repeatable>

Additional arguments, including the chaincode stub and logger

View Source contracts/ContractAdapter.ts, line 1753

Promise resolving to the retrieved record

Promise.<Record.<string, any>>

# async readAll(tableName, id, …args)

Fetches multiple records with the given IDs from the specified table

Retrieves multiple records from the database

Parameters:
Name Type Attributes Description
tableName string

The name of the table to read from

id

The identifiers of the records to retrieve

args Array.<any> <repeatable>

Additional arguments specific to the adapter implementation

View Source contracts/ContractAdapter.ts, line 1764

A promise that resolves to an array of retrieved records

# repository() → {Constructor.<Repository.<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>}

Returns the FabricContractRepository constructor for creating repositories

Gets the repository constructor for this adapter

View Source contracts/ContractAdapter.ts, line 1720

The repository constructor

Constructor.<Repository.<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>

# async protected resultIterator(log, iterator, isHistoryopt) → {Promise.<Array.<any>>}

Iterates through query results and converts them to a structured format

Processes results from a state query iterator

sequenceDiagram participant Caller participant ResultIterator participant Iterator Caller->>ResultIterator: resultIterator(log, iterator, isHistory) loop Until done ResultIterator->>Iterator: next() Iterator-->>ResultIterator: { value, done } alt Has value ResultIterator->>ResultIterator: Process value based on isHistory ResultIterator->>ResultIterator: Add to results array end end ResultIterator->>Iterator: close() ResultIterator-->>Caller: allResults
Parameters:
Name Type Attributes Default Description
log Logger

Logger instance for debugging

iterator Iterators.StateQueryIterator

The state query iterator

isHistory boolean <optional>
false

Whether this is a history query

View Source contracts/ContractAdapter.ts, line 1850

Promise resolving to an array of processed results

Promise.<Array.<any>>

# async update(tableName, id, model, transient, …args) → {Promise.<Record.<string, any>>}

Serializes a model and updates it in the Fabric state database

Updates a record in the state database

Parameters:
Name Type Attributes Description
tableName string

The name of the table/collection

id string | number

The record identifier

model Record.<string, any>

The updated record data

transient Record.<string, any>

Transient data (not used in this implementation)

args Array.<any> <repeatable>

Additional arguments, including the chaincode stub and logger

View Source contracts/ContractAdapter.ts, line 1777

Promise resolving to the updated record

Promise.<Record.<string, any>>

# static decoration() → {void}

Overrides/extends decaf decoration with Fabric-specific functionality

Static method for decoration overrides

View Source contracts/ContractAdapter.ts, line 1915

void