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