'use strict' ; import * as vscode from 'vscode' ; import { UserInputUtil , IBlockchainQuickPickItem } from './UserInputUtil' ; import { ExtensionCommands } from '../../ExtensionCommands' ; import { FabricEnvironmentManager } from '../fabric/environments/FabricEnvironmentManager' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { IFabricEnvironmentConnection , LogType } from 'ibm-blockchain-platform-common' ; import { FabricDebugConfigurationProvider } from '../debug/FabricDebugConfigurationProvider' ; export async function debugCommandList ( commandName ? ) { const debugSession = vscode . debug . activeDebugSession ; if ( ! debugSession || debugSession . configuration . debugEvent !== FabricDebugConfigurationProvider . debugEvent ) { VSCodeBlockchainOutputAdapter . instance ( ) . log ( LogType . ERROR , undefined , 'The current debug session is not debugging a smart contract, this command can only be run when debugging a smart contract' ) ; return ; } const chaincodeContainerName = debugSession . configuration . env . CORE_CHAINCODE_ID_NAME ; const smartContractName = chaincodeContainerName . split ( ':' ) [ 0 ] ; const connection = FabricEnvironmentManager . instance ( ) . getConnection ( ) ; if ( ! connection ) { VSCodeBlockchainOutputAdapter . instance ( ) . log ( LogType . ERROR , undefined , 'No connection to a blockchain found' ) ; return ; } const channelMap = await connection . createChannelMap ( ) ; const channelName = Array . from ( channelMap . keys ( ) ) [ 0 ] ; const peerNames = channelMap . get ( channelName ) ; if ( ! commandName ) { const commands = [ { name : 'Submit Transaction' , command : ExtensionCommands . SUBMIT_TRANSACTION } , { name : 'Evaluate Transaction' , command : ExtensionCommands . EVALUATE_TRANSACTION } ] ; const chosenCommand = await UserInputUtil . showDebugCommandList ( commands , 'Choose a command to execute' ) ; if ( ! chosenCommand ) { return ; } commandName = chosenCommand . data ; } if ( commandName === ExtensionCommands . SUBMIT_TRANSACTION || commandName === ExtensionCommands . EVALUATE_TRANSACTION ) { const connected = await FabricDebugConfigurationProvider . connectToGateway ( ) ; if ( ! connected ) { return ; } await vscode . commands . executeCommand ( commandName , undefined , channelName , smartContractName ) ; } else { await vscode . commands . executeCommand ( commandName , undefined , channelName , peerNames ) ; } }