You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/topics/appexample.rst
+34-36Lines changed: 34 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,47 +1,45 @@
1
1
Applications on Platform
2
2
########################
3
3
4
-
.. contents::
5
-
:local:
6
-
:depth: 3
7
-
8
-
An application on platform is a system of contracts, tables and interfaces that performs a certain function or provides a dedicated service. An application is not a autonomous program module - the only thing that unites the application elements is the performance of certain functions and exchange data. The boundaries of an application are not always strictly defined, since its elements can be simultaneously used in multiple applications.
4
+
5
+
An application on platform is a system of contracts, tables and interfaces that performs a certain function or provides a dedicated service. An application is not a autonomous program module - the only thing that unites the application elements is the performance of certain functions and exchange data. The boundaries of an application are not always strictly defined, since its elements can be simultaneously used in multiple applications.
9
6
10
7
The following is a typical functional fragment of an application:
11
8
12
-
1. Redirect to a page that displays:
9
+
1. Redirect to a page that displays:
13
10
14
-
* information, received from database tables (*DBFind* function),
15
-
* form fields for user input of new data,
16
-
* button (*Button* function), which calls a contract.
11
+
* information, received from database tables (*DBFind* function),
12
+
* form fields for user input of new data,
13
+
* button (*Button* function), which calls a contract.
17
14
18
-
2. On the contract call:
15
+
2. On the contract call:
19
16
20
-
* data from form fields is passed to the ``data`` section of the contract,
21
-
* the ``conditions`` section checks user rights to launch this contract and the validity of data received from the page; if for some reason the contract cannot be executed, a message is displayed on the screen (``error``, ``warning`` or ``info``), leaving the user on the same interface page,
22
-
* the ``action`` section receives additional data from tables (DBFind function) and records data into the database (using *DBUpdate* and *DBInsert* functions).
17
+
* data from form fields is passed to the ``data`` section of the contract,
18
+
* the ``conditions`` section checks user rights to launch this contract and the validity of data received from the page; if for some reason the contract cannot be executed, a message is displayed on the screen (``error``, ``warning`` or ``info``), leaving the user on the same interface page,
19
+
* the ``action`` section receives additional data from tables (DBFind function) and records data into the database (using *DBUpdate* and *DBInsert* functions).
23
20
24
-
3. After the contract has been successfully executed, the user is redirected to the page, whose name was specified in the *Page* parameter of the *Button* function that launched the contract, and the parameters listed in the *PageParams* are passed to the new page.
21
+
3. After the contract has been successfully executed, the user is redirected to the page, whose name was specified in the *Page* parameter of the *Button* function that launched the contract, and the parameters listed in the *PageParams* are passed to the new page.
25
22
26
23
A page can have more than one button to call various contracts. Buttons that call contracts and redirect to pages can be built in rows of tables that display data about objects in the user interface. In this case, object identifiers are used in button parameters, which can be used to redirect to object-related pages (for example, object editing).
27
-
24
+
28
25
29
26
Tables and Data Storage
30
27
=======================
31
28
32
-
Applications use database tables that can be conditionally divided into two types:
29
+
Applications use database tables that can be conditionally divided into two types:
33
30
34
-
1. Tables that store big arrays of structured data about objects (persons, organizations, property, etc.),
35
-
2. Document tables that store the current state of the processes implemented by a particular application (process type, stage, signatures, etc.) or data about its current operations (notifications, messages, records about voting and transactions).
31
+
1. Tables that store big arrays of structured data about objects (persons, organizations, property, etc.),
36
32
37
-
Typically, register tables contain the most up-to-date information, which means that information about objects in the registers is updated as soon as a new piece of data is received. The work with documents is based on a completely different principle. Due to the fact that the *DBFind* functions of the Simvolio and Protypo languages can request information only from a single table (which means that they don't support *JOIN*), it is necessary to record exhaustive information (IDs, names, pictures) in the tables that store documents. For example, when requesting information from a table that stores messages, we need to receive not just the ``id`` of the sender, but all information required to display the message on an interface page, including the user name and avatar (userpic). After having being saved, the data in the document tables should not be modified. It should be noted that non-normalization of data in tables is not related only to the technical limitations of *JOIN* use, but is prescribed by the very ideology of the blockchain as a temporal database that is designed to store the complete history of events. This means that a document (for example, a message), which was signed and saved in a table, should not under any circumstances be modified in the future, even, for example, in case its author changes their name in the register of users (whereas such modification is inevitable under the relational data scheme).
33
+
2. Document tables that store the current state of the processes implemented by a particular application (process type, stage, signatures, etc.) or data about its current operations (notifications, messages, records about voting and transactions).
34
+
35
+
Typically, register tables contain the most up-to-date information, which means that information about objects in the registers is updated as soon as a new piece of data is received. The work with documents is based on a completely different principle. Due to the fact that the *DBFind* functions of the Simvolio and Protypo languages can request information only from a single table (which means that they don't support *JOIN*), it is necessary to record exhaustive information (IDs, names, pictures) in the tables that store documents. For example, when requesting information from a table that stores messages, we need to receive not just the ``id`` of the sender, but all information required to display the message on an interface page, including the user name and avatar (userpic). After having being saved, the data in the document tables should not be modified. It should be noted that non-normalization of data in tables is not related only to the technical limitations of *JOIN* use, but is prescribed by the very ideology of the blockchain as a temporal database that is designed to store the complete history of events. This means that a document (for example, a message), which was signed and saved in a table, should not under any circumstances be modified in the future, even, for example, in case its author changes their name in the register of users (whereas such modification is inevitable under the relational data scheme).
38
36
39
37
40
38
Navigation
41
39
==========
42
40
43
-
Users can switch between applications using sections, displayed in the software client as tabs, or using cascading menus inside these sections. After clicking on a section tab, users are redirected to the section's main page, which can be defined from the administrative tools.
44
-
41
+
Users can switch between applications using sections, displayed in the software client as tabs, or using cascading menus inside these sections. After clicking on a section tab, users are redirected to the section's main page, which can be defined from the administrative tools.
42
+
45
43
Navigation within an application is carried out for the most part using the menus (each page has one menu liked to it). Transition between pages can be implemented using links (*LinkPage*) or button clicks (*Button*). In both cases parameters *PageParams* can be passed to the *Page* target page. Calling a new page is also possible after successful execution of a contract. In this case, the parameters of the *Button* function, which calls the contract, should include the name of the page to redirect to (*Page*) and the passed parameters *PageParams*.
46
44
47
45
Navigation in multi-user applications can be organized using ready-to-use *Notification* and *Roles* applications, which are installed by default in every ecosystem. The *Notification* application allows for display of messages to specific users or user roles in the Molis software client. A notification message consists of a header and a link to a page. Additionally, parameters can be passed using *PageParams* to the target page in the format, supported by the *LinkPage* and *Button* functions. Sometimes, a target page where, for example, a user needs to make some decision, can be accessed only from a notification, because there are no links from menus or other pages to this target page. Notifications are formed with contracts *Notifications_Single_Send* or *Notifications_Roles_Send*, which should be called from a contract that ends some functional stage of an application. After the user receives a notification, opens the target page and performs the required action (thus, executing a contract), the notification should be deactivated by calling the *Notifications_Single_Close* or *Notifications_Roles_Finishing* contract. The list of notifications and their statuses is available in the *Notification* application.
@@ -77,7 +75,7 @@ The conditions specified in the Update field specify the rights to change all
77
75
Application Example: SendTokens
78
76
===============================
79
77
80
-
The application sends tokens from one user account to another. Information about the amounts of tokens on accounts is stored in the *keys* tables (*amount* column), which are installed in ecosystems by default. This example implies that the tokens have already been distributed to user accounts.
78
+
The application sends tokens from one user account to another. Information about the amounts of tokens on accounts is stored in the *keys* tables (*amount* column), which are installed in ecosystems by default. This example implies that the tokens have already been distributed to user accounts.
81
79
82
80
83
81
System Contract
@@ -103,19 +101,19 @@ In order to prevent the execution of the TokenTransfer contract from within anot
103
101
error Sprintf("Sender %s is invalid", $Sender_AccountId)
@@ -172,8 +170,8 @@ The token sending form contains fields to input the transaction amount and the r
172
170
}
173
171
}
174
172
}
175
-
}
176
-
173
+
}
174
+
177
175
We could use the Button function to directly call the TokenTransfer transfer contract and pass the current user's (sender) account address to it, but for the purpose of demonstration of the work of contracts with confirmation we'll create an intermediary user contract SendTokens. It is important to note, that since the names of data in the data section of the contract and the names of the interface form fields are the same, we don't need to specify the Params parameters in the Button function.
178
176
179
177
The form can be placed on any page in the software client. After the contract execution has ended, the user will stay on the current page (because we didn't specify a target page Page in the Button function).
@@ -182,7 +180,7 @@ The form can be placed on any page in the software client. After the contract ex
182
180
Custom Contracts
183
181
----------------
184
182
185
-
The TokenTransfer contract is defined as a contract with confirmation, and that is why in order to call it from another contract we need to place the Signature string "signature:TokenTransfer" in the data section of our custom contract.
183
+
The TokenTransfer contract is defined as a contract with confirmation, and that is why in order to call it from another contract we need to place the Signature string "signature:TokenTransfer" in the data section of our custom contract.
186
184
The conditions section of the SendTokens contract checks the availability of the account; the action section calls the TokenTransfer contract and passes parameters to it.
187
185
188
186
.. code:: js
@@ -193,14 +191,14 @@ The conditions section of the SendTokens contract checks the availability of the
193
191
Recipient_Account string
194
192
Signature string "signature:TokenTransfer"
195
193
}
196
-
194
+
197
195
conditions {
198
196
$recipient =AddressToId($Recipient_Account)
199
197
if $recipient ==0 {
200
198
error Sprintf("Recipient %s is invalid", $Recipient_Account)
0 commit comments