Neo: New API for NeoContract: System.Runtime.GetNotifications

Created on 9 Jul 2018  路  17Comments  路  Source: neo-project/neo

System.Runtime.GetNotifications receives a scripthash as an argument, and returns all notifications from that contract in current InvocationTransaction.

Consider that we have an InvocationTransaction with the following Script:

APPCALL <A>
APPCALL <B>
SYSCALL System.Runtime.GetNotifications <A>
discussion

Most helpful comment

@shargon @erikzhang @vncoelho time to implement this. I was sure it had passed already haha took time to find this here, still open.
I think we can have parameter one, saying which scripthash to look for, and if empty scripthash, we receive all notifications. Result can be an array stack item, filled with Notification interopinterfaces.
We will need two more interop calls: System.Notification.GetScriptHash, and
System.Notification.GetMessage. probably a third one, System.Notification.GetAttributes, where one of these attributes is if notification is currently hidden (we could flag other interesting things too, lets think)

All 17 comments

Will be the notification that was sent with System.Runtime.Notify right?

Will be the notification that was sent with System.Runtime.Notify right?

Yes.

Oh, I love new things :) but what is a possible application for this? hahahah

Oh, I love new things :) but what is a possible application for this? hahahah

Consider a contract to run a decentralized exchange. When a user needs to deposit, he will first transfer some NEP-5 tokens to this contract and then call its deposit method. In the deposit method, the contract can confirm that the user actually transferred the tokens by calling System.Runtime.GetNotifications.

@erikzhang Couldn't they just check that the tokens were deposited by querying the smart contract? System.Runtime.GetNotifications seems unreliable, at least in the dynamic call case - what happens if the contract incorrectly implements the notifications? I.e. at a high level, notifications are not the source of truth.

@erikzhang will any Verification contracts be able to produce (and store) such notifications (verified later in Application)? That would be amazingly useful!
Will this GetNotifications be able to filter them somehow by some prefix? Or the whole list will be returned?

@igormcoelho System.Runtime.GetNotifications can get the notifications that sent from the same InvocationTransaction.

Is there a way to check if the invocation faulted?

Why is this in the 3.0 Milestone? Wouldn't this be applicable in e.g. 2.7?

Is there a way to check if the invocation faulted?

If the invocation faulted, it will not continue to execute. There is currently no way to recover from an exception.

I have planned to add a mechanism for smart contract exception handling in NEO 3.0. https://github.com/neo-project/neo/issues/310

Why is this in the 3.0 Milestone? Wouldn't this be applicable in e.g. 2.7?

It can be applicable in 2.x if necessary.

If the invocation faulted, it will not continue to execute. There is currently no way to recover from an exception.

So this mean System.Runtime.GetNotifications will never have notifications after faulting, even if a notify opcode was done before that? In the current version, execution results are not cleared, so this notification remains.

In the current version, execution results are not cleared, so this notification remains.

https://github.com/neo-project/neo/blob/9cf0d94f0979ea579e6b9d660359e0c49625532b/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.cs#L590-L593

If the invocation faulted, everything will be rolled back.

Yes that is true, state changes are not committed, but the notifications are still added to execution results as a copy:

https://github.com/neo-project/neo/blob/9cf0d94f0979ea579e6b9d660359e0c49625532b/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.cs#L601

Just confirming the behavior should not be the same for this API.

Edit: Actually GetNotifications would simply read from the actual state, so that goes without saying. Thanks!

Scripthash will be included too, right? For that other proposal of Native contracts (https://github.com/neo-project/neo/issues/303), it would be nice to each contract having an unique name (as explained there), and that would be useful here too... so if we are catching a notification from contract named "Neo.Native.NEO" regarding a "transfer"... transfer is done, utxo is gone ;)

@shargon @erikzhang @vncoelho time to implement this. I was sure it had passed already haha took time to find this here, still open.
I think we can have parameter one, saying which scripthash to look for, and if empty scripthash, we receive all notifications. Result can be an array stack item, filled with Notification interopinterfaces.
We will need two more interop calls: System.Notification.GetScriptHash, and
System.Notification.GetMessage. probably a third one, System.Notification.GetAttributes, where one of these attributes is if notification is currently hidden (we could flag other interesting things too, lets think)

@igormcoelho @shargon to clarify, this only applies to notifications from the current transaction right? (Sorry if this is an obvious question, I haven't been following NEO 3.0 changes too closely - yet anyways)

Yes @dicarlo2 exactly as you said

Was this page helpful?
0 / 5 - 0 ratings

Related issues

superboyiii picture superboyiii  路  30Comments

lock9 picture lock9  路  62Comments

Tommo-L picture Tommo-L  路  30Comments

erikzhang picture erikzhang  路  31Comments

EdgeDLT picture EdgeDLT  路  59Comments