I have created a simple interface and its implementation and I would like to understand the type signatures. I guess these are not obvious because some transformations happen under the hood.
In the code below I have marked type signatures emitted by VSCode in different parts of the code for give
, because in different parts these are different.
module Interfaces where
import Daml.Script
data GiveableView =
GiveableView {viewIssuer : Party, viewOwner : Party, viewId : Text }
interface Giveable where
viewtype GiveableView
give : Party -> Update (ContractId Giveable)
-- ^ give : Giveable -> Party -> Update (ContractId Giveable)
choice Give : ContractId Giveable
with
newOwner : Party
controller (view this).viewOwner
do
give this newOwner
template Token
with
tokenIssuer : Party
tokenOwner : Party
tokenId : Text
where
signatory tokenIssuer
interface instance Giveable for Token where
view = GiveableView tokenIssuer tokenOwner tokenId
give newOwner = do
-- ^ give : Party -> Update (ContractId Giveable)
tokenCid <- create this with tokenOwner = newOwner
return $ toInterfaceContractId tokenCid
test : Script (ContractId Giveable)
test = do
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
tokenCid <- submit alice do
createCmd (Token alice alice "AliceToken")
submit alice do
exerciseCmd (toInterfaceContractId @Giveable tokenCid) (Give bob)
In general, I know that Haskell treats field names as functions and the field data types specified in the record declaration syntax are actually the return types of these functions, but there are some missing puzzle pieces for me here.