import { TezosConseilClient } from '../../reporting/tezos/TezosConseilClient' ; import { TezosLanguageUtil } from './TezosLanguageUtil' ; import { EntryPoint } from '../../types/tezos/ContractIntrospectionTypes' ; import { ConseilServerInfo } from '../../types/conseil/QueryTypes' ; import * as EntryPointTemplate from './lexer/EntryPointTemplate' ; import * as nearley from 'nearley' ; /**
 * Functions for performing contract introspection, such as generating the entry points of a smart contract.
 */ export namespace TezosContractIntrospector { param { string } params returns { EntryPoint [ ] } export function generateEntryPointsFromParams ( params ) { const parser = new nearley . Parser ( nearley . Grammar . fromCompiled ( EntryPointTemplate . default ) ) ; parser . feed ( TezosLanguageUtil . normalizeMichelineWhiteSpace ( TezosLanguageUtil . stripComments ( params ) ) ) ; const entryPoints = parser . results [ 0 ] ; if ( entryPoints . length === 1 ) { entryPoints [ 0 ] . name = 'default' ; } return entryPoints ; } param { string } contractCode returns { EntryPoint [ ] } export function generateEntryPointsFromCode ( contractCode ) { const contractParameter = TezosLanguageUtil . preProcessMichelsonScript ( contractCode ) [ 0 ] ; return generateEntryPointsFromParams ( contractParameter ) ; } param { ConseilServerInfo } conseilServer param { string } network param { string } contractAddress returns { Promise < EntryPoint [ ] > } export async function generateEntryPointsFromAddress ( conseilServer , network , contractAddress ) { const account = await TezosConseilClient . getAccount ( conseilServer , network , contractAddress ) ; const contractCode = account . script ; return generateEntryPointsFromCode ( contractCode ) ; } }