From 47421f23f4c61972821ca1b06aa9fe2ad2416570 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 5 Nov 2020 22:51:08 +0300 Subject: [PATCH] native: add events to oracle contract Follow neo-project/neo#2036. --- pkg/core/native/oracle.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/core/native/oracle.go b/pkg/core/native/oracle.go index dfcc47287..0a3b475b5 100644 --- a/pkg/core/native/oracle.go +++ b/pkg/core/native/oracle.go @@ -131,6 +131,13 @@ func newOracle() *Oracle { md = newMethodAndPrice(getOnPersistWrapper(pp), 0, smartcontract.AllowModifyStates) o.AddMethod(md, desc, false) + o.AddEvent("OracleRequest", manifest.NewParameter("Id", smartcontract.IntegerType), + manifest.NewParameter("RequestContract", smartcontract.Hash160Type), + manifest.NewParameter("Url", smartcontract.StringType), + manifest.NewParameter("Filter", smartcontract.StringType)) + o.AddEvent("OracleResponse", manifest.NewParameter("Id", smartcontract.IntegerType), + manifest.NewParameter("OriginalTx", smartcontract.Hash256Type)) + return o } @@ -235,6 +242,15 @@ func (o *Oracle) FinishInternal(ic *interop.Context) error { return ErrRequestNotFound } + ic.Notifications = append(ic.Notifications, state.NotificationEvent{ + ScriptHash: o.Hash, + Name: "OracleResponse", + Item: stackitem.NewArray([]stackitem.Item{ + stackitem.Make(resp.ID), + stackitem.Make(req.OriginalTxID.BytesBE()), + }), + }) + r := io.NewBinReaderFromBuf(req.UserData) userData := stackitem.DecodeBinaryStackItem(r) args := stackitem.NewArray([]stackitem.Item{ @@ -306,6 +322,16 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url, filter, cb string, us return ErrBigArgument } + ic.Notifications = append(ic.Notifications, state.NotificationEvent{ + ScriptHash: o.Hash, + Name: "OracleRequest", + Item: stackitem.NewArray([]stackitem.Item{ + stackitem.Make(id), + stackitem.Make(ic.VM.GetCallingScriptHash().BytesBE()), + stackitem.Make(url), + stackitem.Make(filter), + }), + }) req := &state.OracleRequest{ OriginalTxID: o.getOriginalTxID(ic.DAO, ic.Tx), GasForResponse: gas.Uint64(),