Skip to content

Commit

Permalink
base64 blocks input data
Browse files Browse the repository at this point in the history
  • Loading branch information
jdutchak committed Jul 19, 2024
1 parent bec2123 commit 9e202bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pkg/api/handlers_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,11 @@ func (api *API) GetBlocks() gin.HandlerFunc {
InputData interface{} `json:"input_data"`
TransactionHash string `json:"transaction_hash"`
PreviousHash string `json:"previous_hash"`
TransactionNonce int `json:"transaction_nonce"`
TransactionNonce int `json:"nonce"`
}

type Blocks struct {
BlockData []BlockData `json:"block_data"`
BlockData []BlockData `json:"blocks"`
}
var existingBlocks Blocks
blocks := chain.GetBlockchain(api.Node.Blockchain)
Expand All @@ -884,7 +884,7 @@ func (api *API) GetBlocks() gin.HandlerFunc {
}

blockData := BlockData{
InputData: inputData,
InputData: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v", inputData))),
TransactionHash: fmt.Sprintf("%x", block.Hash),
PreviousHash: fmt.Sprintf("%x", block.Link),
TransactionNonce: int(block.Nonce),
Expand Down
2 changes: 1 addition & 1 deletion pkg/chain/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (pos *ProofOfStake) Run() (int64, []byte) {
var hashInt big.Int
currentTime := time.Now().Unix()

logrus.WithFields(logrus.Fields{"block_content": string(pos.Block.Data)}).Info("Running Proof of Stake...")
logrus.WithFields(logrus.Fields{"timestamp": currentTime}).Info("Running Proof of Stake...")
spinner := []string{"|", "/", "-", "\\"}
i := 0
for {
Expand Down
7 changes: 4 additions & 3 deletions pkg/oracle_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -370,11 +371,11 @@ type BlockData struct {
InputData interface{} `json:"input_data"`
TransactionHash string `json:"transaction_hash"`
PreviousHash string `json:"previous_hash"`
TransactionNonce int `json:"transaction_nonce"`
TransactionNonce int `json:"nonce"`
}

type Blocks struct {
BlockData []BlockData `json:"block_data"`
BlockData []BlockData `json:"blocks"`
}

type BlockEvents struct{}
Expand Down Expand Up @@ -412,7 +413,7 @@ func updateBlocks(ctx context.Context, node *OracleNode) {
}

blockData := BlockData{
InputData: inputData,
InputData: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v", inputData))),
TransactionHash: fmt.Sprintf("%x", block.Hash),
PreviousHash: fmt.Sprintf("%x", block.Link),
TransactionNonce: int(block.Nonce),
Expand Down
22 changes: 6 additions & 16 deletions pkg/workers/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,10 @@ func SendWork(node *masa.OracleNode, m *pubsub2.Message) {
msg := &pubsub2.Message{}
err = json.Unmarshal([]byte(response.Value), msg)
if err != nil {
_, err = getResponseMessage(result.(*messages.Response))
msg, err = getResponseMessage(result.(*messages.Response))
if err != nil {
logrus.Debugf("Error getting response message: %v", err)
return
} else {
// don't send back failed messages here
workerDoneCh <- &pubsub2.Message{ValidatorData: err.Error()}
return
}
}
Expand Down Expand Up @@ -394,22 +392,14 @@ func SubscribeToWorkers(node *masa.OracleNode) {
// marshals the data to JSON, and writes it to the database using the WriteData function.
// The monitoring continues until the context is done.
func MonitorWorkers(ctx context.Context, node *masa.OracleNode) {
if node == nil {
logrus.Error("MonitorWorkers: node is nil")
return
}
if node.ActorRemote == nil {
logrus.Error("MonitorWorkers: node.ActorRemote is nil")
return
}
// Register self as a remote node for the network
node.ActorRemote.Register("peer", actor.PropsFromProducer(NewWorker(node)))

if node.WorkerTracker == nil || node.WorkerTracker.WorkerStatusCh == nil {
logrus.Debug("MonitorWorkers: WorkerTracker or WorkerStatusCh is nil")
return
}

// Register self as a remote node for the network
node.ActorRemote.Register("peer", actor.PropsFromProducer(NewWorker(node)))

ticker := time.NewTicker(time.Second * 10)
defer ticker.Stop()
rcm := pubsub.GetResponseChannelMap()
Expand Down Expand Up @@ -510,7 +500,7 @@ func processWork(data *pubsub2.Message, work string, startTime *time.Time, node
Duration: duration.Seconds(),
Timestamp: time.Now().Unix(),
}
logrus.Infof("[+] Work event: %v", workEvent)
logrus.Infof("[+] Work event for : %s", workEvent.PeerId)

_ = node.PubSubManager.Publish(config.TopicWithVersion(config.BlockTopic), workEvent.Payload)

Expand Down

0 comments on commit 9e202bc

Please sign in to comment.