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 102

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 152

# Context

Overrides the base Context constructor with FabricContractContext

Context constructor for this adapter

View Source contracts/ContractAdapter.ts, line 900

# textDecoder

Text decoder for converting binary data to strings

.

Text decoder for converting binary data to strings

View Source contracts/ContractAdapter.ts, line 146

Methods

# 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 930

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 974

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 965

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 988

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 998

Promise that resolves immediately

Promise.<void>

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

Parameters:
Name Type Description
model
pk string
args

View Source contracts/ContractAdapter.ts, line 1067

PreparedModel

# 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 1058

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 941

Promise resolving to the retrieved record

Promise.<Record.<string, any>>

# 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 908

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 1027

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 954

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 1076

void