Skip to content

Commit

Permalink
feat(fabric-connector): add getChainInfo, improve getBlock output
Browse files Browse the repository at this point in the history
- Add new method `getChainInfo` for quering chain information from qscc.
- Add `GetChainInfoEndpointV1` to allow calling `getChainInfo` remotely.
- Refactor `getBlock` so it can return same custom block formats
  as `WatchBlocks`. Default remains the same (full decode block).
  BREAKING CHANGE: It accepts `type` instead of `skipDecode` flag.
- Move common block formatting logic to `cacti-block-formatters.ts`.
- Add tests for new features. Move test common to quering `qscc` to single file
  to increase CI speed.

Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH authored and petermetz committed Jul 4, 2024
1 parent 9eefa66 commit 8c030ae
Show file tree
Hide file tree
Showing 41 changed files with 2,928 additions and 686 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { json2str } from "@hyperledger/cactus-cmd-socketio-server";
import { AssetTradeStatus } from "./define";
import {
WatchBlocksCactusTransactionsEventV1 as FabricWatchBlocksCactusTransactionsEventV1,
CactiBlockTransactionEventV1,
WatchBlocksListenerTypeV1 as FabricWatchBlocksListenerTypeV1,
WatchBlocksResponseV1 as FabricWatchBlocksResponseV1,
} from "@hyperledger/cactus-plugin-ledger-connector-fabric";
Expand Down Expand Up @@ -242,19 +242,19 @@ export class BusinessLogicAssetTrade extends BusinessLogicBase {
const fabricApiClient = getFabricApiClient();
const watchObservable = fabricApiClient.watchBlocksDelegatedSignV1({
channelName: config.assetTradeInfo.fabric.channelName,
type: FabricWatchBlocksListenerTypeV1.CactusTransactions,
type: FabricWatchBlocksListenerTypeV1.CactiTransactions,
signerCertificate: getSignerIdentity().credentials.certificate,
signerMspID: getSignerIdentity().mspId,
uniqueTransactionData: createSigningToken("watchBlock"),
});
const watchSub = watchObservable.subscribe({
next: (event: FabricWatchBlocksResponseV1) => {
if (!("cactusTransactionsEvents" in event)) {
if (!("cactiTransactionsEvents" in event)) {
logger.error("Wrong input block format!", event);
return;
}

for (const ev of event.cactusTransactionsEvents) {
for (const ev of event.cactiTransactionsEvents) {
logger.debug(`##in onEventFabric()`);

try {
Expand Down Expand Up @@ -363,7 +363,7 @@ export class BusinessLogicAssetTrade extends BusinessLogicBase {
}

executeNextTransaction(
txInfo: FabricWatchBlocksCactusTransactionsEventV1 | Web3TransactionReceipt,
txInfo: CactiBlockTransactionEventV1 | Web3TransactionReceipt,
txId: string,
): void {
let transactionInfo: TransactionInfo | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Configuration,
FabricContractInvocationType,
RunTransactionRequest,
GetBlockResponseTypeV1,
} from "@hyperledger/cactus-plugin-ledger-connector-fabric";
import { NetworkDetails, ObtainLedgerStrategy } from "./obtain-ledger-strategy";
import {
Expand Down Expand Up @@ -170,7 +171,7 @@ export class StrategyFabric implements ObtainLedgerStrategy {
query: {
transactionId: txId,
},
skipDecode: false,
type: GetBlockResponseTypeV1.Full,
};

const getBlockResponse = await api.getBlockV1(getBlockReq);
Expand Down
11 changes: 6 additions & 5 deletions packages/cactus-plugin-ledger-connector-fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ Corresponds directly to `BlockType` from `fabric-common`:
- `WatchBlocksListenerTypeV1.Full`,
- `WatchBlocksListenerTypeV1.Private`,

##### Cacti (custom)
Parses the data and returns custom formatted block.
- `WatchBlocksListenerTypeV1.CactiTransactions`: Returns transactions summary. Compatible with legacy `fabric-socketio` monitoring operation.
- `WatchBlocksListenerTypeV1.CactiFullBlock`: Returns full block summary.

### 1.6 Delegated Signature
- Custom signature callback can be used when increased security is needed or currently available options are not sufficient.
- Signature callback is used whenever fabric request must be signed.
Expand Down Expand Up @@ -365,17 +370,13 @@ await apiClient.runDelegatedSignTransactionV1({

// Monitor for transactions:
apiClient.watchBlocksDelegatedSignV1({
type: WatchBlocksListenerTypeV1.CactusTransactions,
type: WatchBlocksListenerTypeV1.CactiTransactions,
signerCertificate: adminIdentity.credentials.certificate,
signerMspID: adminIdentity.mspId,
channelName: ledgerChannelName,
})
```

##### Cactus (custom)
Parses the data and returns custom formatted block.
- `WatchBlocksListenerTypeV1.CactusTransactions`: Returns transactions summary. Compatible with legacy `fabric-socketio` monitoring operation.

## 2. Architecture
The sequence diagrams for various endpoints are mentioned below

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"form-data": "4.0.0",
"http-status-codes": "2.1.4",
"jsrsasign": "11.0.0",
"long": "5.2.3",
"multer": "1.4.5-lts.1",
"ngo": "2.7.0",
"node-ssh": "13.1.0",
Expand Down
Loading

0 comments on commit 8c030ae

Please sign in to comment.