es/contract/aci.js
function transform (type, value) {
  let { t, generic } = readType(type)

  // contract TestContract = ...
  // fn(ct: TestContract)
  if (typeof value === 'string' && value.slice(0, 2) === 'ct') t = SOPHIA_TYPES.address // Handle Contract address transformation

  switch (t) {
    case SOPHIA_TYPES.string:
      return `"${value}"`
    case SOPHIA_TYPES.list:
      return `[${value.map(el => transform(generic, el))}]`
    case SOPHIA_TYPES.tuple:
      return `(${value.map((el, i) => transform(generic[i], el))})`
    case SOPHIA_TYPES.address:
      return `#${decode(value).toString('hex')}`
    case SOPHIA_TYPES.record:
      return `{${generic.reduce(
        (acc, { name, type }, i) => {
          if (i !== 0) acc += ','
          acc += `${name} = ${transform(type[0], value[name])}`
          return acc
        },
        ''
      )}}`
  }

  return `${value}`
}
function transform (type, value) {
  let { t, generic } = readType(type)

  // contract TestContract = ...
  // fn(ct: TestContract)
  if (typeof value === 'string' && value.slice(0, 2) === 'ct') t = SOPHIA_TYPES.address // Handle Contract address transformation

  switch (t) {
    case SOPHIA_TYPES.string:
      return `"${value}"`
    case SOPHIA_TYPES.list:
      return `[${value.map(el => transform(generic, el))}]`
    case SOPHIA_TYPES.tuple:
      return `(${value.map((el, i) => transform(generic[i], el))})`
    case SOPHIA_TYPES.address:
      return `#${decode(value).toString('hex')}`
    case SOPHIA_TYPES.record:
      return `{${generic.reduce(
        (acc, { name, type }, i) => {
          if (i !== 0) acc += ','
          acc += `${name} = ${transform(type[0], value[name])}`
          return acc
        },
        ''
      )}}`
  }

  return `${value}`
}
function transform ( type , value ) { let { t , generic } = readType ( type ) // contract TestContract = ... // fn(ct: TestContract) if ( typeof value === 'string' && value . slice ( 0 , 2 ) === 'ct' ) t = SOPHIA_TYPES . address // Handle Contract address transformation switch ( t ) { case SOPHIA_TYPES . string : return ` ${ value } ` case SOPHIA_TYPES . list : return ` ${ value . map ( el => transform ( generic , el ) ) } ` case SOPHIA_TYPES . tuple : return ` ${ value . map ( ( el , i ) => transform ( generic [ i ] , el ) ) } ` case SOPHIA_TYPES . address : return ` ${ decode ( value ) . toString ( 'hex' ) } ` case SOPHIA_TYPES . record : return ` ${ generic . reduce ( ( acc , { name , type } , i ) => { if ( i !== 0 ) acc += ',' acc += ` ${ name } ${ transform ( type [ 0 ] , value [ name ] ) } ` return acc } , '' ) } ` } return ` ${ value } ` }
Transform JS type to Sophia-type
@param type
@param value
@return {string}
Transform JS type to Sophia - type