diff --git a/node_util/oracle.go b/node_util/oracle.go index 79f532a..ec2b156 100644 --- a/node_util/oracle.go +++ b/node_util/oracle.go @@ -8,8 +8,16 @@ You should have received a copy of the GNU General Public License along with thi */ package node_util +import ( + "crypto/sha256" + "encoding/json" + "fmt" +) + type OracleType uint64 +const ORACLE_RESPONSE_PREFIX = "ORACLE" + const ( NilType OracleType = iota ) @@ -51,3 +59,16 @@ func (o *Oracle) Step() { } o.Requests = []OracleRequest{} } + +func (o *Oracle) WriteResponses(transition StateTransition) { + for _, res := range o.Responses { + requestStr := []byte(fmt.Sprintf("%v", res.Request)) + requestHash := sha256.Sum256(requestStr) + key := fmt.Sprintf("%s%s", ORACLE_RESPONSE_PREFIX, string(requestHash[:])) + val, err := json.Marshal(res) + if err != nil { + panic(err) + } + transition.UpdatedData[key] = val + } +}