mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 17:15:10 +00:00
Add comments to fabric.ts
Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
parent
00a2dea50b
commit
fd269237d4
1 changed files with 44 additions and 6 deletions
|
|
@ -104,11 +104,22 @@ export const createGateway = async (
|
||||||
return gateway;
|
return gateway;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the network which the asset transfer sample chaincode is running on
|
||||||
|
*
|
||||||
|
* In addion to getting the contract, the network will also be used to
|
||||||
|
* start a block event listener
|
||||||
|
*/
|
||||||
export const getNetwork = async (gateway: Gateway): Promise<Network> => {
|
export const getNetwork = async (gateway: Gateway): Promise<Network> => {
|
||||||
const network = await gateway.getNetwork(config.channelName);
|
const network = await gateway.getNetwork(config.channelName);
|
||||||
return network;
|
return network;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the asset transfer sample contract and the qscc system contract
|
||||||
|
*
|
||||||
|
* The system contract is used for the liveness REST endpoint
|
||||||
|
*/
|
||||||
export const getContracts = async (
|
export const getContracts = async (
|
||||||
network: Network
|
network: Network
|
||||||
): Promise<{ assetContract: Contract; qsccContract: Contract }> => {
|
): Promise<{ assetContract: Contract; qsccContract: Contract }> => {
|
||||||
|
|
@ -117,6 +128,13 @@ export const getContracts = async (
|
||||||
return { assetContract, qsccContract };
|
return { assetContract, qsccContract };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Starts a timer to retry transactions at regular intervals
|
||||||
|
*
|
||||||
|
* Note: there is check for whether the transaction has successfully completed
|
||||||
|
* since it could succeed between any check and the retry, so the additional
|
||||||
|
* transaction to get the status is unlikely to be worthwhile
|
||||||
|
*/
|
||||||
export const startRetryLoop = (
|
export const startRetryLoop = (
|
||||||
contracts: Map<string, Contract>,
|
contracts: Map<string, Contract>,
|
||||||
redis: Redis
|
redis: Redis
|
||||||
|
|
@ -162,6 +180,9 @@ export const startRetryLoop = (
|
||||||
retryInterval.unref();
|
retryInterval.unref();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Evaluate a transaction and handle any errors
|
||||||
|
*/
|
||||||
export const evatuateTransaction = async (
|
export const evatuateTransaction = async (
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
transactionName: string,
|
transactionName: string,
|
||||||
|
|
@ -182,6 +203,12 @@ export const evatuateTransaction = async (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Submit a transaction and handle any errors
|
||||||
|
*
|
||||||
|
* Transaction details are saved before being submitted so that they can be
|
||||||
|
* retried if any errors occur
|
||||||
|
*/
|
||||||
export const submitTransaction = async (
|
export const submitTransaction = async (
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
redis: Redis,
|
redis: Redis,
|
||||||
|
|
@ -277,6 +304,12 @@ const handleError = (transactionId: string, err: Error): Error => {
|
||||||
return new TransactionError('Transaction error', transactionId);
|
return new TransactionError('Transaction error', transactionId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retry a transaction
|
||||||
|
*
|
||||||
|
* The saved transaction details include a retry count which is used to ensure
|
||||||
|
* failing transactions are not retried indefinitely
|
||||||
|
*/
|
||||||
const retryTransaction = async (
|
const retryTransaction = async (
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
redis: Redis,
|
redis: Redis,
|
||||||
|
|
@ -347,13 +380,12 @@ const isDuplicateTransactionError = (error: {
|
||||||
/*
|
/*
|
||||||
* Block event listener to handle successful transactions
|
* Block event listener to handle successful transactions
|
||||||
*
|
*
|
||||||
* Transaction details are saved before being submitted so that
|
* Transaction details are saved before being submitted so that they can be
|
||||||
* they can be retried, and this listener deletes those transaction
|
* retried, and this listener deletes those transaction details for any
|
||||||
* details for any successful transactions
|
* successful transactions
|
||||||
*
|
*
|
||||||
* Transactions can be submitted using one of two identities
|
* Transactions can be submitted using one of two identities however one one
|
||||||
* however one one of those identities is used to listen for
|
* of those identities is used to listen for block events
|
||||||
* block events
|
|
||||||
*/
|
*/
|
||||||
export const blockEventHandler = (redis: Redis): BlockListener => {
|
export const blockEventHandler = (redis: Redis): BlockListener => {
|
||||||
const blockListener = async (event: BlockEvent) => {
|
const blockListener = async (event: BlockEvent) => {
|
||||||
|
|
@ -375,6 +407,12 @@ export const blockEventHandler = (redis: Redis): BlockListener => {
|
||||||
return blockListener;
|
return blockListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the current block height
|
||||||
|
*
|
||||||
|
* This example of using a system contract is used for the liveness REST
|
||||||
|
* endpoint
|
||||||
|
*/
|
||||||
export const getBlockHeight = async (
|
export const getBlockHeight = async (
|
||||||
qscc: Contract
|
qscc: Contract
|
||||||
): Promise<number | Long.Long> => {
|
): Promise<number | Long.Long> => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue