## 4 Case Studies: Supply Chain and Public Tender
### Automatic Applications to Public Calls  
In many countries, like for instance in Italy, career advancements in the public sector require a public tender to be won by a candidate employee. A public call is usually advertised on an official repository, instructing candidates on when and how they should submit their applications. Under such hypotheses, application submission management can easily become a trust-critical scenario where the adoption of BCT and smart contracts may introduce great advantages, by easily preventing situations where _(i)_ one or more submitters lie about the timing of their applications, _(ii)_ one or more corrupted employees tamper with one or more applications, or _(iii)_ one or more applications are disclosed  
Figure 7: Time-reactive state diagram for the SC in Listing 1.  
before the public submission period is over. The smart contract described below can be exploited as a countermeasure to the aforementioned issues. Listing 2 shows the source code of an autonomous smart contract aimed at managing submissions. After deployment, and as long as the application period is open, it continuously collects submissions sent by other smart contracts or end users. More precisely, _(i)_ it knows when to open and close applications, since this information is provided as input upon deployment; _(ii)_ after deployment, there are only two possible situations: either applications are already open or they should be opened in a later moment; _(iii)_ in the latter case, application opening is scheduled for the opening date provided as input upon SC deployment; _(iv)_ in any case, after applications have been opened, the SC accepts submissions as long as the tender is open; finally _(v)_ it exposes applications for public inspection only after the application period has been closed. It is worth emphasizing what are the enablers of the greater expressiveness exhibited by Tenderfone smart contracts w.r.t. the state of the art: _(i)_ computational autonomy, enabling smart contracts to set their own goals upon deployment and act as soon as applications need to be opened/closed without the need for external stimuli, and _(ii)_ temporal situatedness, enabling them to perceive time and perform time-dependant computations. ```
Zassuepening#closingdateareprovideduponSCdepolyementi init([OpeningDate,ClosingDate]):- ClosingDate>OpeningDate,Zclosingdatemustbeafteropemingdate now(Now),Nov<ClosingDate,Zclosingdateshouldbeinthefuture set_data(opening_date,OpeningDate),Zstoreopendingdateforlaterusage set_data(closing_date,ClosingDate),Zstoreclosingdateaswell set_initial_status(Now,OpeningDate),ZsettheinitialstateofthisSC set_initial_status(Now,OpeningDate):-Zwhensettingtheinitialstate... Now>=OpeningDate,Z...iftheopeningdateisinthepast set_data(status,open).Zifmeanssubmissionsarealreadyopen set_initial_status(Now,OpeningDate):-Zotherwise... Now<OpeningDate,Z...iftheopeningdateisinthefuture set_data(status,wait_opening),Zitemssubmissionsarenotopen,yet wmmm(OpeningDate,open_populations).Zthusopeningisscheduled receive(open_applications,Sender):-Zwhenfryingtoopenapplications self(Sender),Zonlythissmartcontractcompenapplications get_data(status,will_open),Zensurenotalreadyopen set_data(status,open),Zapplicationsarenowopen set_data(closing_date,ClosingDate),ZretrieecisclosingwhenClosingDate,close_applications).Zscheduleapplicationsclosing receive(close_applications,Sender):-Zwhenfryingtocloseapplications self(Sender),Zonlythissmartcontractcompeapplications get_data(status,open),Zensureapplicationsareopes set_data(status,closed).Zapplicationsarenowclosed receive(application(Details),Sender):-Zwhensubmittinganapplication get_data(status,open),Zensureapplicationsareopes set_data(status,open),Zensureapplicationsareopes set_data(application(Details)).Zstoreapplication answer(application(Applicant),-Details):-Zwhengueringanapplication get_data(status,closed),Zensureapplicationsareclosed get_data(applicant(Applicant),Details).Zretrieecisetheapplication
```  
Listing 2: A Tenderfone SC autonomously managinganapplicationsubmissionsystem.