当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Channel.newChannelEventHub方法代码示例

本文整理汇总了TypeScript中fabric-client.Channel.newChannelEventHub方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Channel.newChannelEventHub方法的具体用法?TypeScript Channel.newChannelEventHub怎么用?TypeScript Channel.newChannelEventHub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fabric-client.Channel的用法示例。


在下文中一共展示了Channel.newChannelEventHub方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Promise

			return new Promise((resolve, reject) => {
				// get a new ChannelEventHub when registering a listener
				// with startBlock or endBlock when doing a replay
				// The ChannelEventHub must not have been connected or have other
				// listeners.
				let channel_event_hub: ChannelEventHub = channel.newChannelEventHub('peer0.org1.example.com');

				let handle = setTimeout(() => {
					t.fail('Timeout - Failed to receive replay the event for event1');
					channel_event_hub.unregisterTxEvent(query_tx_id);
					channel_event_hub.disconnect(); //shutdown down since we are done
				}, 10000);

				channel_event_hub.registerTxEvent(query_tx_id, (txnid, code, block_num) => {
					clearTimeout(handle);
					t.pass('Event has been replayed with transaction code:' + code + ' for transaction id:' + txnid + ' for block_num:' + block_num);
					resolve('Got the replayed transaction');
				}, (error) => {
					clearTimeout(handle);
					t.fail('Failed to receive event replay for Event for transaction id ::' + query_tx_id);
					throw (error);
				},
					// a real application would have remembered the last block number
					// received and used that value to start the replay
					// Setting the disconnect to true as we do not want to use this
					// ChannelEventHub after the event we are looking for comes in
					{ startBlock: 0, disconnect: true }
				);
				t.pass('Successfully registered transaction replay for ' + query_tx_id);

				channel_event_hub.connect(); //connect to receive filtered blocks
				t.pass('Successfully called connect on the transaction replay event hub for filtered blocks');
			});
开发者ID:asararatnakar,项目名称:fabric-sdk-node-v11-v12-compatibility,代码行数:33,代码来源:test.ts

示例2: Error

		}).then((results: ProposalResponseObject) => {
			let proposalResponses: ProposalResponse[] = results[0];
			let proposal: Proposal = results[1];
			let all_good = true;
			// Will check to be sure that we see two responses as there are two peers defined on this
			// channel that are endorsing peers
			let endorsed_responses = 0;
			for (let i in proposalResponses) {
				let one_good = false;
				endorsed_responses++;
				let proposal_response: ProposalResponse = proposalResponses[i];
				if (proposal_response.response && proposal_response.response.status === 200) {
					t.pass('transaction proposal has response status of good');
					one_good = true;
				} else {
					t.fail('transaction proposal was bad');
					if (proposal_response.response && proposal_response.response.status) {
						t.comment(' response status:' + proposal_response.response.status +
							' message:' + proposal_response.response.message);
					} else {
						t.fail('transaction response was unknown');
						logger.error('transaction response was unknown %s', proposal_response);
					}
				}
				all_good = all_good && one_good;
			}
			t.equals(endorsed_responses, 2, 'Checking that there are the correct number of endorsed responses');
			if (!all_good) {
				t.fail('Failed to send invoke Proposal or receive valid response. Response null or status is not 200. exiting...');
				throw new Error('Failed to send invoke Proposal or receive valid response. Response null or status is not 200. exiting...');
			}
			let request: TransactionRequest = {
				proposalResponses: proposalResponses,
				proposal: proposal,
				admin: true
			};

			let promises = [];

			// be sure to get an channel event hub the current user is authorized to use
			let eventhub = channel.newChannelEventHub('peer0.org1.example.com');

			let txPromise = new Promise((resolve, reject) => {
				let handle = setTimeout(() => {
					eventhub.unregisterTxEvent(query_tx_id);
					eventhub.disconnect();
					t.fail('REQUEST_TIMEOUT --- eventhub did not report back');
					reject(new Error('REQUEST_TIMEOUT:' + eventhub.getPeerAddr()));
				}, 30000);

				eventhub.registerTxEvent(query_tx_id, (tx, code, block_num) => {
					clearTimeout(handle);
					if (code !== 'VALID') {
						t.fail('transaction was invalid, code = ' + code);
						reject(new Error('INVALID:' + code));
					} else {
						t.pass('transaction has been committed on peer ' + eventhub.getPeerAddr());
						resolve('COMMITTED');
					}
				}, (error) => {
					clearTimeout(handle);
					t.fail('transaction event failed:' + error);
					reject(error);
				},
					{ disconnect: true } //since this is a test and we will not be using later
				);
			});
			// connect(true) to receive full blocks (user must have read rights to the channel)
			// should connect after registrations so that there is an error callback
			// to receive errors if there is a problem on the connect.
			eventhub.connect(true);

			promises.push(txPromise);
			promises.push(channel.sendTransaction(request));

			return Promise.all(promises);
		}).then((results) => {
开发者ID:asararatnakar,项目名称:fabric-sdk-node-v11-v12-compatibility,代码行数:77,代码来源:test.ts


注:本文中的fabric-client.Channel.newChannelEventHub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。