From 539f0153d624fac07f6c13b4169ffd21ccfd2222 Mon Sep 17 00:00:00 2001 From: Ashy5000 Date: Tue, 30 Jul 2024 16:25:36 -0700 Subject: [PATCH] Implements oracle response generation framework --- node_util/oracle.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 node_util/oracle.go diff --git a/node_util/oracle.go b/node_util/oracle.go new file mode 100644 index 0000000..79f532a --- /dev/null +++ b/node_util/oracle.go @@ -0,0 +1,53 @@ +// Copyright 2024, Asher Wrobel +/* +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see . +*/ +package node_util + +type OracleType uint64 + +const ( + NilType OracleType = iota +) + +type OracleRequest struct { + Body []byte + Type OracleType +} + +type OracleResponse struct { + Body []byte + Type OracleType + Request OracleRequest +} + +type Oracle struct { + Requests []OracleRequest + Responses []OracleResponse +} + +func CalculateOracleResponse(request OracleRequest) OracleResponse { + switch request.Type { + case NilType: + return OracleResponse{ + Body: []byte("NULL"), + Type: 0, + Request: OracleRequest{}, + } + } + panic("Unknown oracle type.") +} + +func (o *Oracle) Step() { + if len(o.Requests) == 0 { + return + } + for _, req := range o.Requests { + o.Responses = append(o.Responses, CalculateOracleResponse(req)) + } + o.Requests = []OracleRequest{} +}