Skip to content

Commit 7d43598

Browse files
authored
NEP: Triggers for NeoContract (#15)
1 parent 63e1170 commit 7d43598

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

README.mediawiki

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ First review [[nep-1.mediawiki|NEP-1]]. Then clone the repository and add your N
5151
| Standard
5252
| Final
5353
|-
54-
| [https://github.com/neo-project/proposals/pull/15 7]
54+
| [[nep-7.mediawiki|7]]
5555
| Triggers for NeoContract
5656
| Erik Zhang
5757
| Standard
58-
| Accepted
58+
| Final
5959
|-
6060
| [https://github.com/neo-project/proposals/pull/22 8]
6161
| Stack Isolation for NeoVM

nep-7.mediawiki

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<pre>
2+
NEP: 7
3+
Title: Triggers for NeoContract
4+
Author: Erik Zhang <[email protected]>
5+
Type: Standard
6+
Status: Final
7+
Created: 2017-10-16
8+
</pre>
9+
10+
==Abstract==
11+
12+
Trigger is a mechanism for triggering execution for smart contracts. This NEP defines four different kinds of triggers, they are <code>Verification</code>, <code>VerificationR</code>, <code>Application</code> and <code>ApplicationR</code>.
13+
14+
==Motivation==
15+
16+
A blockchain that provides smart contract system should provide multiple triggers for the smart contracts running on it, makes them to function in different contexts.
17+
18+
==Rationale==
19+
20+
Currently, we have two kinds of triggers in NeoContract: <code>Verification</code> and <code>Application</code>. These two triggers make smart contracts able to verify the transactions and modify the states of the blockchain.
21+
22+
But there is no way for smart contracts to refuse a transfer, or to modify the states of the blockchain while accepting a transfer. We need two new triggers to do it: <code>VerificationR</code> and <code>ApplicationR</code>.
23+
24+
==Specification==
25+
26+
We define four kinds of triggers: <code>Verification</code>, <code>VerificationR</code>, <code>Application</code> and <code>ApplicationR</code>.
27+
28+
===Verification===
29+
30+
The <code>Verification</code> trigger indicates that the contract is being invoked as a verification function. The verification function can accept multiple parameters, and should return a boolean value that indicates the validity of the transaction or block.
31+
32+
The entry point of the contract will be invoked if the contract is triggered by <code>Verification</code>:
33+
34+
<code>
35+
main(...);
36+
</code>
37+
38+
The entry point of the contract must be able to handle this type of invocation.
39+
40+
===VerificationR===
41+
42+
The <code>VerificationR</code> trigger indicates that the contract is being invoked as a verification function because it is specified as a target of an output of the transaction. The verification function accepts no parameter, and should return a boolean value that indicates the validity of the transaction.
43+
44+
The entry point of the contract will be invoked if the contract is triggered by <code>VerificationR</code>:
45+
46+
<code>
47+
main("receiving", new object[0]);
48+
</code>
49+
50+
The <code>receiving</code> function should have the following signature:
51+
52+
<code>
53+
public bool receiving()
54+
</code>
55+
56+
The <code>receiving</code> function will be invoked automatically when a contract is receiving assets from a transfer.
57+
58+
===Application===
59+
60+
The <code>Application</code> trigger indicates that the contract is being invoked as an application function. The application function can accept multiple parameters, change the states of the blockchain, and return any type of value.
61+
62+
The contract can have any form of entry point, but we recommend that all contracts should have the following entry point:
63+
64+
<code>
65+
public byte[] main(string operation, params object[] args)
66+
</code>
67+
68+
The functions can be invoked by creating an <code>InvocationTransaction</code>.
69+
70+
===ApplicationR===
71+
72+
The <code>ApplicationR</code> trigger indicates that the '''default''' function <code>received</code> of the contract is being invoked because it is specified as a target of an output of the transaction. The <code>received</code> function accepts no parameter, changes the states of the blockchain, and returns any type of value.
73+
74+
The entry point of the contract will be invoked if the contract is triggered by <code>ApplicationR</code>:
75+
76+
<code>
77+
main("received", new object[0]);
78+
</code>
79+
80+
The <code>received</code> function should have the following signature:
81+
82+
<code>
83+
public byte[] received()
84+
</code>
85+
86+
The <code>received</code> function will be invoked automatically when a contract is receiving assets from a transfer.
87+
88+
==Backwards Compatibility==
89+
90+
Any old contract that didn't implement the <code>receiving</code> and <code>received</code> function will lead to a <code>FAULT</code> VM state when triggered by <code>VerificationR</code> or <code>ApplicationR</code>. So any transfers to old contracts will be rejected and no state will be changed.
91+
92+
==Implementation==
93+
94+
https://github.com/neo-project/neo

0 commit comments

Comments
 (0)