Exemplo n.º 1
0
        private ContractTask Finish(ApplicationEngine engine)
        {
            if (engine.InvocationStack.Count != 2)
            {
                throw new InvalidOperationException();
            }
            if (engine.GetInvocationCounter() != 1)
            {
                throw new InvalidOperationException();
            }
            Transaction    tx       = (Transaction)engine.ScriptContainer;
            OracleResponse response = tx.GetAttribute <OracleResponse>();

            if (response == null)
            {
                throw new ArgumentException("Oracle response was not found");
            }
            OracleRequest request = GetRequest(engine.Snapshot, response.Id);

            if (request == null)
            {
                throw new ArgumentException("Oracle request was not found");
            }
            engine.SendNotification(Hash, "OracleResponse", new VM.Types.Array(engine.ReferenceCounter)
            {
                response.Id, request.OriginalTxid.ToArray()
            });
            StackItem userData = BinarySerializer.Deserialize(request.UserData, engine.Limits, engine.ReferenceCounter);

            return(engine.CallFromNativeContract(Hash, request.CallbackContract, request.CallbackMethod, request.Url, userData, (int)response.Code, response.Result));
        }
Exemplo n.º 2
0
        private UInt256 GetOriginalTxid(ApplicationEngine engine)
        {
            Transaction    tx       = (Transaction)engine.ScriptContainer;
            OracleResponse response = tx.GetAttribute <OracleResponse>();

            if (response is null)
            {
                return(tx.Hash);
            }
            OracleRequest request = GetRequest(engine.Snapshot, response.Id);

            return(request.OriginalTxid);
        }
Exemplo n.º 3
0
        private void Finish(ApplicationEngine engine)
        {
            Transaction    tx       = (Transaction)engine.ScriptContainer;
            OracleResponse response = tx.GetAttribute <OracleResponse>();

            if (response == null)
            {
                throw new ArgumentException("Oracle response was not found");
            }
            OracleRequest request = GetRequest(engine.Snapshot, response.Id);

            if (request == null)
            {
                throw new ArgumentException("Oracle request was not found");
            }
            engine.SendNotification(Hash, "OracleResponse", new VM.Types.Array {
                response.Id, request.OriginalTxid.ToArray()
            });
            StackItem userData = BinarySerializer.Deserialize(request.UserData, engine.Limits.MaxStackSize, engine.Limits.MaxItemSize, engine.ReferenceCounter);

            engine.CallFromNativeContract(Hash, request.CallbackContract, request.CallbackMethod, request.Url, userData, (int)response.Code, response.Result);
        }