As said in Quick Start (please check, if you don't know what is going on here), Contract
command looks like:
'Contract' command
Let's consider syntax of basic 'Contract' command, which allows introducing contract description on Ursus lang.
'Contract' ContractName ';'
'Send To' InterfaceName1 InterfaceName2 ';'
'Types'
'Record' Name1Record ':= {'
Name1RecordMemberName ':' Type1 ';'
Name1RecordMemberName ':' Type2 ';'
...
NameNRecordMemberName ':' TypeN
}
'Record' Name2Record ':= {'
...
}
...
'Record' NameLastRecord ':= {'
...
}
';'
'Constants'
'Definition' Constant1Name ':' Type1 ':=' value1
'Definition' Constant2Name ':' Type2 ':=' value2
...
'Definition' ConstantLastName ':' TypeLast ':=' valueLast
';'
'Record Contract' ':= {'
'#[' AccessRights ']' Name1ContractMember ':' Type1 ';'
'#[' AccessRights ']' Name2ContractMember ':' Type2 ';'
...
NameNContractMember ':' TypeN
'}.'
For example:
Contract MultisigWallet ;
Sends To Itmp ;
Types
Record Transaction := {
Transaction_ι_id : uint64;
Transaction_ι_confirmationsMask : uint32;
}
Record UpdateRequest := {
UpdateRequest_ι_id : uint64;
UpdateRequest_ι_index : uint8;
UpdateRequest_ι_signs : uint8;
trans : (_ResolveName "Transaction");
};
Constants
Definition FLAG_SEND_ALL_REMAINING : uint8 := 128
Definition FLAG_IGNORE_ERRORS : uint8 := 2
;
Record Contract := {
#[static] _pubkey : uint256;
#[static] _foo : uint256;
m_requiredVotes : uint8;
m_defaultRequiredConfirmations : uint8;
last_transaction : (_ResolveName "Transaction")
}.
Let's consider more precisely this command with each section:
- After keyword
Contract
here is name of the described contract - Keyword
Sends To
is used to declare which interfaces are used for sending messages. - Keyword
Types
is used to declare new strutures that will be used below. - Keyword
Constant
is used to declare constants, which will be used in the contract. Important to mention that value, which will be assignment here must be literal. - Record
Contract
contains fields of the contract, which can have attribute#[public]
,#[static]
or nothing. It's important(!) to use custom type/structures here with wrapper_ResolveName
becauseContract
command doesn't know such types before creating all notations.
This part was expressed in Quick Start too.
After command Contract
it needs to use command SetUrsusOptions.
and UseLocal ...
. In the UseLocal list important to notice that customtypes must be used with special name. For example, if you have structure name Foo, you need to use FooLRecord name.
Next is going to describe function and modifier declaration, but there.
End of declaring contract comes with two command EndContract Implements Interface1 Interface2 ... .
and End ContactName.
where:
- ContractName is module name, which this contract located;
- Interface1 and Interface2 are implemented interfaces, which means that signatures and function names from these interfaces are the same as in folowing interfaces.
In the last version is possible to create interface using signatures of declared contract via command EndContract ImplementsAuto.