# 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
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
# Context
Overrides the base Context constructor with FabricContractContext
Context constructor for this adapter
# textDecoder
Text decoder for converting binary data to strings
.Text decoder for converting binary data to strings
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 |
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 |
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 |
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 |
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 |
Promise that resolves immediately
Promise.<void>
# prepare(model, pk, args) → {PreparedModel}
Parameters:
| Name | Type | Description |
|---|---|---|
model |
||
pk |
string
|
|
args |
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
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 |
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 |
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
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
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 |
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 |
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
void