constructContractInvocationOperation static method

dynamic constructContractInvocationOperation(
  1. String publicKeyHash,
  2. int counter,
  3. String contract,
  4. int amount,
  5. dynamic entrypoint,
  6. String parameters,
  7. TezosParameterFormat parameterFormat,
)

Implementation

static constructContractInvocationOperation(
    String publicKeyHash,
    int counter,
    String contract,
    int amount,
    entrypoint,
    String parameters,
    TezosParameterFormat parameterFormat) {
  OperationModel transaction = new OperationModel(
    destination: contract,
    amount: amount.toString(),
    counter: counter,
    source: publicKeyHash,
  );

  if (parameters != '') {
    if (parameterFormat == TezosParameterFormat.Michelson) {
      var michelineParams =
          TezosLanguageUtil.translateMichelsonExpressionToMicheline(
              parameters)!;
      transaction.parameters = {
        'entrypoint': entrypoint.isEmpty ? 'default' : entrypoint,
        'value': jsonDecode(michelineParams)
      };
    } else if (parameterFormat == TezosParameterFormat.Micheline) {
      transaction.parameters = {
        'entrypoint': entrypoint.isEmpty ? 'default' : entrypoint,
        'value': jsonDecode(parameters)
      };
    } else if (parameterFormat == TezosParameterFormat.MichelsonLambda) {
      var michelineLambda =
          TezosLanguageUtil.translateMichelsonExpressionToMicheline(
              'code $parameters')!;
      transaction.parameters = {
        'entrypoint': entrypoint.isEmpty ? 'default' : entrypoint,
        'value': jsonDecode(michelineLambda)
      };
    }
  } else if (entrypoint != null) {
    transaction.parameters = {'entrypoint': entrypoint, 'value': []};
  }
  return transaction;
}