I’d like to understand how the Daml language concepts compare to other smart-contract languages like Solidity. How could one represent or encode Daml contracts, parties, signatories, observers, controllers, etc. in Solidity? To what extent is such a representation possible and where would it break down?
For example, the following SimpleIou
in Daml:
data Cash = Cash with
currency : Text
amount : Decimal
deriving (Eq, Show)
template SimpleIou with
issuer : Party
owner : Party
cash : Cash
where
ensure cash.amount > 0.0
observer owner
signatory issuer
choice SimpleTransfer : ContractId SimpleIou with
newOwner : Party
controller owner
do create this with owner = newOwner
In my first attempt, I’d encode template, signatory, and ensures clause roughly as follows in Solidity. The idea is that the message sender msg.sender
carries the authorization.
contract SimpleIou {
address issuer;
address owner;
Cash cash;
constructor(Cash aCash, address aOwner) payable {
require(aCash.amount > 0.0);
issuer = msg.sender; // Convention: The message sender is the controller
owner = aOwner;
cash = aCash;
}
There’s no counterpart for observers, but if I assume that all interested parties can read all blocks, then they can themselves figure out when they are an observer to a SimpleIou
contract.
If I go for mutable Solidity SimpleIou
s, the SimpleTransfer
choice looks fairly simple:
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_
}
function simpleTransfer(address newOwner) public onlyOwner {
owner = newOwner;
}
However, if I want to retain the UTXO model and really create a new contract upon a transfer, it gets tricky: The new Iou must be created by the issuer whereas the simpleTransfer
choice must be called by the owner
. So the simpleTransfer
choice in SimpleIou
would have to call an external function in the issuer’s contract.
So maybe msg.sender
is not an adequate approach to deal with delegation. Are there better ways to deal with this in Solidity?