sdk-fabric
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

Hyperledger Fabric sdk utils

sdk of fabric and so on.

Supported Hyperledger Fabric versions

This library has been tested against the v2.0.0 version of Hyperledger

demo

import { CreateSDK } from 'sdk-fabric';
import { ISDKBuilder } from 'sdk-fabric/dist/lib/builder';
import { SetLog } from 'sdk-fabric/dist/util/log'
import { Config } from 'sdk-fabric/dist/lib/director';

//配置日志模块
const sdklog=GetLogger('sdk');
SetLog(sdklog);

// 创建sdk
const conf={} as Config
const sdkbuild = await CreateSDK(conf);
if (sdkbuild) {
    return sdkbuild;
}
/**
 * 根据高度获取块信息
 * @param {string} channelName
 * @param {number} blockNum
 */
public async QueryBlockByNum(blockNum: number): Promise<Result> {
    const res = {} as Result;
    try {
        const contract = this.sdk.getNetWork().getContract('qscc');
        const resultByte = await contract.evaluateTransaction(
            'GetBlockByNumber',
            conf.sdk.channel,
            String(blockNum),
        );
        const resultJson = await decodeBlock(resultByte);
        const bl = await BlockDecode(resultJson);
        res.data = bl;
        return res;
    } catch (error) {
        logger.error(`Failed to get block ${blockNum} from channel ${conf.sdk.channel} err:${error} `);
        res.error = error;
        if (error.responses.length > 0) {
            res.message = error.responses[0].response.message;
        }
        return res;
    }
}

Readme

Keywords

Package Sidebar

Install

npm i sdk-fabric

Weekly Downloads

0

Version

1.0.10

License

ISC

Unpacked Size

83.6 kB

Total Files

38

Last publish

Collaborators

  • lihui7800