packageDocumentation module hidden import { isObject , isArray } from '@harmony-js/utils' ; import { BN } from '@harmony-js/crypto' ; export const jsonInterfaceMethodToString = ( json ) : string => { if ( isObject ( json ) && json . name && json . name . includes ( '(' ) ) { return json . name ; } return `${ json . name }(${ flattenTypes ( false , json . inputs ) . join ( ',' ) })` ; } ; export const flattenTypes = ( includeTuple , puts ) => { const types = [ ] ; puts . forEach ( ( param ) => { if ( typeof param . components === 'object' ) { if ( param . type . substring ( 0 , 5 ) !== 'tuple' ) { throw new Error ( 'components found but type is not tuple; report on GitHub' ) ; } let suffix = '' ; const arrayBracket = param . type . indexOf ( '[' ) ; if ( arrayBracket >= 0 ) { suffix = param . type . substring ( arrayBracket ) ; } const result = flattenTypes ( includeTuple , param . components ) ; if ( isArray ( result ) && includeTuple ) { types . push ( `tuple(${ result . join ( ',' ) })${ suffix }` ) ; } else if ( ! includeTuple ) { types . push ( `(${ result . join ( ',' ) })${ suffix }` ) ; } else { types . push ( `(${ result })` ) ; } } else { types . push ( param . type ) ; } } ) ; return types ; } ; export function bnToString ( result ) { if ( BN . isBN ( result ) ) { return result . toString ( ) ; } else { return result ; } }