1.0.10 • Published 3 years ago

sdk-fabric v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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;
    }
}
1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago