Skip to content

Latest commit

 

History

History
94 lines (57 loc) · 4 KB

nep-7.mediawiki

File metadata and controls

94 lines (57 loc) · 4 KB

  NEP: 7
  Title: Triggers for NeoContract
  Author: Erik Zhang <[email protected]>
  Type: Standard
  Status: Final
  Created: 2017-10-16

Table of Contents

Abstract

Trigger is a mechanism for triggering execution for smart contracts. This NEP defines four different kinds of triggers, they are Verification, VerificationR, Application and ApplicationR.

Motivation

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.

Rationale

Currently, we have two kinds of triggers in NeoContract: Verification and Application. These two triggers make smart contracts able to verify the transactions and modify the states of the blockchain.

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: VerificationR and ApplicationR.

Specification

We define four kinds of triggers: Verification, VerificationR, Application and ApplicationR.

Verification

The Verification 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.

The entry point of the contract will be invoked if the contract is triggered by Verification:

main(...);

The entry point of the contract must be able to handle this type of invocation.

VerificationR

The VerificationR 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.

The entry point of the contract will be invoked if the contract is triggered by VerificationR:

main("receiving", new object[0]);

The receiving function should have the following signature:

public bool receiving()

The receiving function will be invoked automatically when a contract is receiving assets from a transfer.

Application

The Application 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.

The contract can have any form of entry point, but we recommend that all contracts should have the following entry point:

public byte[] main(string operation, params object[] args)

The functions can be invoked by creating an InvocationTransaction.

ApplicationR

The ApplicationR trigger indicates that the default function received of the contract is being invoked because it is specified as a target of an output of the transaction. The received function accepts no parameter, changes the states of the blockchain, and returns any type of value.

The entry point of the contract will be invoked if the contract is triggered by ApplicationR:

main("received", new object[0]);

The received function should have the following signature:

public byte[] received()

The received function will be invoked automatically when a contract is receiving assets from a transfer.

Backwards Compatibility

Any old contract that didn't implement the receiving and received function will lead to a FAULT VM state when triggered by VerificationR or ApplicationR. So any transfers to old contracts will be rejected and no state will be changed.

Implementation

https://github.com/neo-project/neo