1

I encounter the below error message when compiling the code on LIGO Playground.

Error: ligo: in file "tmp-1CAIKM1VUeRgb.ligo", 
line 29, characters 98-112. different kinds:  {"a":"unit","b":"(type_operator: Big Map (address,record[creditAmount -> nat , initialTime -> timestamp]))"}

which is for line starting as Big_map.add...

function addCreditor (const creditor : address ; const lendingValue : nat ; var s : contract_storage) : contract_storage is
 begin
  // If debtor and the creditor is same, skip
  if s.debtor = creditor then skip;
  else block {
      case (Map.find_opt (creditor, s.creditorsMap)) of
        // if creditor is found, he cannot participate in again.
        | Some (c) -> 
          failwith("Creditor contract does not reach maturity")
        // if no record found, add it
        | None -> {
          s.totalCredits := s.totalCredits + lendingValue;
          Big_map.add(creditor, record [ initialTime = Tezos.now ; creditAmount = lendingValue ], s.creditorsMap)
        }
      end;
  }
 end with s

The relevant declaration,

type counter is record
    initialTime : timestamp;
    creditAmount : nat;
end

type action is
| AddCreditor of (address * nat)
| RemoveCreditor of (address)

type contract_storage is record
  debtor : address;
  totalCredits : nat;
  creditorsMap : big_map(address, counter);
end

The main function,

 function main (const p : action ; const s : contract_storage) :
  (list(operation) * contract_storage) is
 block { 
   // Reject any transaction that try to transfer token to this contract
   if amount =/= 0tz then failwith ("This contract do not accept token");
   else skip;
  } with case p of
  | AddCreditor(n) -> ((nil : list(operation)), addCreditor(n.0, n.1, s))
  | RemoveCreditor(n) -> ((nil : list(operation)), removeCreditor(n.0, s))
 end

1 Answer 1

1

The one I raised the question above, map.add is not a function that returns a map, instead it returns unsigned int. So, one of the correct ways is,

function addCreditor (const creditor : address ; const lendingValue : nat ; var s : contract_storage) : contract_storage is
 begin
  // If debtor and the creditor is same, skip
  if s.debtor = creditor then failwith("Creditor contract does not exist");
  else block {
      case s.creditorsMap[creditor] of
        // if creditor is found, he cannot participate in again.
        | Some (c) -> 
          failwith("Creditor contract does not reach maturity")
        // if no record found, add it
        | None -> {
          const logging : counter =
              record [
                initialTime       = Tezos.now;
                creditAmount = lendingValue;
              ];
          const updated_map : register = Map.add(creditor,logging,s.creditorsMap);
          s.creditorsMap := updated_map;
          s.totalCredits := s.totalCredits + lendingValue;
        }
      end;
  }
 end with s

Also, set aside the above issue, a few more bugs were consecutively found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.