Agreement
Financial Agreement written in DSL between two or more users
Agreement contract that is used to implement any custom logic of a
financial agreement. Ex. lender-borrower agreement
recordIds
uint256[] recordIds
parser
address parser
contextProgram
address contextProgram
contextDSL
address contextDSL
ownerAddr
address ownerAddr
records
mapping(uint256 => struct IAgreement.Record) records
onlyOwner
modifier onlyOwner()
constructor
constructor(address _parser, address _ownerAddr, address _dslContext) public
Sets parser address, creates new contextProgram instance, and setups contextProgram
receive
receive() external payable
hex4Bytes
function hex4Bytes(string _str) external pure returns (bytes4)
Apply keccak256 to _str
, cut the result to the first 4 bytes
Parameters
Name |
Type |
Description |
_str |
string |
Input string |
Return Values
Name |
Type |
Description |
[0] |
bytes4 |
bytes4(keccak256(str)) |
archiveRecord
function archiveRecord(uint256 _recordId) external
archive any of the existing records by recordId.
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
unarchiveRecord
function unarchiveRecord(uint256 _recordId) external
unarchive any of the existing records by recordId
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
activateRecord
function activateRecord(uint256 _recordId) external
activates the existing records by recordId, only awailable for ownerAddr
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
deactivateRecord
function deactivateRecord(uint256 _recordId) external
deactivates the existing records by recordId, only awailable for ownerAddr
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
parseFinished
function parseFinished() external view returns (bool _result)
returns true if parsing was finished for the record including
conditions otherwise, it returns false
The finished parsing
therm means that all record and conditions
already parsed and have got their bytecodes, so all bytecodes
already storing in the Agreement smart contract
parse
function parse(address _preProc) external returns (bool _result)
Parse DSL code from the user and set the program bytecode in Agreement contract
Parameters
Name |
Type |
Description |
_preProc |
address |
Preprocessor address |
_parse
function _parse(uint256 _recordId, address _preProc, string _code, bool _isRecord) internal
Parse DSL code and set the program bytecode in Agreement contract
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
_preProc |
address |
Preprocessor address |
_code |
string |
DSL code for the record of the condition |
_isRecord |
bool |
a flag that shows if provided _code is a record or not (a condition then) |
update
function update(uint256 _recordId, uint256[] _requiredRecords, address[] _signatories, string _recordString, string[] _conditionStrings) public
Updates Agreement contract by DSL code for the record
and its conditions. All records that will be updated still
need to be parsed. Please, check the parse
function for more details
TODO: rename this function to addRecord
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
_requiredRecords |
uint256[] |
array of required records in the record |
_signatories |
address[] |
array of signatories in the record |
_recordString |
string |
string of record DSL transaction |
_conditionStrings |
string[] |
the array of conditions string for the record |
execute
function execute(uint256 _recordId) external payable virtual
Check if the recorcID is executable (validate all conditions before
record execution, check signatures).
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
_verifyRecord
function _verifyRecord(uint256 _recordId) internal
conditionString
function conditionString(uint256 _recordId, uint256 i) external view returns (string)
Returns the condition string for provided recordID
and index for the searching condition string
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
i |
uint256 |
|
getActiveRecords
function getActiveRecords() external view returns (uint256[])
Sorted all records and return array of active records in Agreement
Return Values
Name |
Type |
Description |
[0] |
uint256[] |
activeRecords array of active records in Agreement |
getRecord
function getRecord(uint256 _recordId) external view returns (uint256[] _requiredRecords, address[] _signatories, string[] _conditions, string _record, bool _isActive)
return valuses for preview record before execution
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
Return Values
Name |
Type |
Description |
_requiredRecords |
uint256[] |
array of required records in the record |
_signatories |
address[] |
array of signatories in the record |
_conditions |
string[] |
array of conditions in the record |
_record |
string |
string of record DSL transaction |
_isActive |
bool |
true if the record is active |
_checkSignatories
function _checkSignatories(address[] _signatories) internal view
Checks input _signatures that only one 'ANYONE' address exists in the
list or that 'ANYONE' address does not exist in signatures at all
Parameters
Name |
Type |
Description |
_signatories |
address[] |
the list of addresses |
_verify
function _verify(uint256 _recordId) internal view returns (bool)
Verify that the user who wants to execute the record is amoung the signatories for this Record
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
ID of the record |
Return Values
Name |
Type |
Description |
[0] |
bool |
true if the user is allowed to execute the record, false - otherwise |
_validateRequiredRecords
function _validateRequiredRecords(uint256 _recordId) internal view returns (bool)
Check that all records required by this records were executed
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
ID of the record |
Return Values
Name |
Type |
Description |
[0] |
bool |
true all the required records were executed, false - otherwise |
_addRecordBlueprint
function _addRecordBlueprint(uint256 _recordId, uint256[] _requiredRecords, address[] _signatories) internal
Define some basic values for a new record
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
is the ID of a transaction |
_requiredRecords |
uint256[] |
transactions ids that have to be executed |
_signatories |
address[] |
addresses that can execute the chosen transaction |
_addRecordCondition
function _addRecordCondition(uint256 _recordId, string _conditionStr) internal
Conditional Transaction: Append a condition to already existing conditions
inside Record
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
_conditionStr |
string |
DSL code for condition |
_addRecordTransaction
function _addRecordTransaction(uint256 _recordId, string _recordString) internal
Adds a transaction that should be executed if all
conditions inside Record are met
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID |
_recordString |
string |
DSL code for record string |
_validateConditions
function _validateConditions(uint256 _recordId, uint256 _msgValue) internal returns (bool)
Validate all conditions for the certain record ID
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID to execute |
_msgValue |
uint256 |
Value that were sent along with function execution // TODO: possibly remove this argument |
_fulfill
function _fulfill(uint256 _recordId, uint256 _msgValue, address _signatory) internal returns (bool result)
Fulfill Record
Parameters
Name |
Type |
Description |
_recordId |
uint256 |
Record ID to execute |
_msgValue |
uint256 |
Value that were sent along with function execution // TODO: possibly remove this argument |
_signatory |
address |
The user that is executing the Record |
Return Values
Name |
Type |
Description |
result |
bool |
Boolean whether the record was successfully executed or not |
_activeRecordsLen
function _activeRecordsLen() internal view returns (uint256)
return length of active records for getActiveRecords
Return Values
Name |
Type |
Description |
[0] |
uint256 |
count length of active records array |
conditionStringsLen
function conditionStringsLen(uint256 _recordId) public view returns (uint256)