hyperledger / fabric-sdk-node

Hyperledger Fabric SDK for Node https://wiki.hyperledger.org/display/fabric
https://hyperledger.github.io/fabric-sdk-node/
Apache License 2.0
793 stars 516 forks source link

Module '"fabric-protos"' has no exported member 'uint64ToNumber' #667

Closed sandeepnRES closed 1 year ago

sandeepnRES commented 1 year ago

In file: fabric-protos/index.js, I can see it has following line:

module.exports.uint64ToNumber = (uint64Value) => {
    const value = protobuf.util.longFromHash(uint64Value, true);
    return typeof value === 'number' ? value : value.toInt();
}

But when I do following:

import { uint64ToNumber } from 'fabric-protos';

It throws error: Module '"fabric-protos"' has no exported member 'uint64ToNumber'

Is this expected? Because I was trying to add a number to blockNumber from a block which is of type uint64, but not number, and the typescript compiler throws error that uint64 or Long doesn't overlap with type number. I thought importing above function from fabric-protos would help, but not able to import. Any help would be appreciated. Thanks.

bestbeforetoday commented 1 year ago

That exported function is used in the fabric-common code here:

https://github.com/hyperledger/fabric-sdk-node/blob/6565522a7638f1c15ca64b4187f07e6ac959667e/fabric-common/lib/BlockDecoder.js#L702

That function really is only there to support the fabric-common implementation and it should generally not be necessary for application code since the BlockEvent exposed by the SDK to the application defines the block number as a Long object:

https://hyperledger.github.io/fabric-sdk-node/main/module-fabric-network.BlockEvent.html

The Long object has an add() method to produce another Long result, and a toNumber() method to convert to a JavaScript number.

sandeepnRES commented 1 year ago

okay, thanks that helps.