Skip to content

Commit

Permalink
Implements Oracle.WriteResponses()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Jul 31, 2024
1 parent 539f015 commit f7bcbf2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions node_util/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
}
}

0 comments on commit f7bcbf2

Please sign in to comment.