-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adc4f0c
commit c7f0dc4
Showing
5 changed files
with
113 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2023, Offchain Labs, Inc. | ||
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE | ||
|
||
package server_api | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/offchainlabs/nitro/util/jsonapi" | ||
"github.com/offchainlabs/nitro/validator" | ||
) | ||
|
||
type BatchInfoJson struct { | ||
Number uint64 | ||
DataB64 string | ||
} | ||
|
||
type ValidationInputJson struct { | ||
Id uint64 | ||
HasDelayedMsg bool | ||
DelayedMsgNr uint64 | ||
PreimagesB64 jsonapi.PreimagesMapJson | ||
BatchInfo []BatchInfoJson | ||
DelayedMsgB64 string | ||
StartState validator.GoGlobalState | ||
} | ||
|
||
func ValidationInputToJson(entry *validator.ValidationInput) *ValidationInputJson { | ||
res := &ValidationInputJson{ | ||
Id: entry.Id, | ||
HasDelayedMsg: entry.HasDelayedMsg, | ||
DelayedMsgNr: entry.DelayedMsgNr, | ||
DelayedMsgB64: base64.StdEncoding.EncodeToString(entry.DelayedMsg), | ||
StartState: entry.StartState, | ||
PreimagesB64: jsonapi.NewPreimagesMapJson(entry.Preimages), | ||
} | ||
for _, binfo := range entry.BatchInfo { | ||
encData := base64.StdEncoding.EncodeToString(binfo.Data) | ||
res.BatchInfo = append(res.BatchInfo, BatchInfoJson{binfo.Number, encData}) | ||
} | ||
return res | ||
} | ||
|
||
func ValidationInputFromJson(entry *ValidationInputJson) (*validator.ValidationInput, error) { | ||
valInput := &validator.ValidationInput{ | ||
Id: entry.Id, | ||
HasDelayedMsg: entry.HasDelayedMsg, | ||
DelayedMsgNr: entry.DelayedMsgNr, | ||
StartState: entry.StartState, | ||
Preimages: entry.PreimagesB64.Map, | ||
} | ||
delayed, err := base64.StdEncoding.DecodeString(entry.DelayedMsgB64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
valInput.DelayedMsg = delayed | ||
for _, binfo := range entry.BatchInfo { | ||
data, err := base64.StdEncoding.DecodeString(binfo.DataB64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
decInfo := validator.BatchInfo{ | ||
Number: binfo.Number, | ||
Data: data, | ||
} | ||
valInput.BatchInfo = append(valInput.BatchInfo, decInfo) | ||
} | ||
return valInput, nil | ||
} | ||
|
||
type MachineStepResultJson struct { | ||
Hash common.Hash | ||
Position uint64 | ||
Status uint8 | ||
GlobalState validator.GoGlobalState | ||
} | ||
|
||
func MachineStepResultToJson(result *validator.MachineStepResult) *MachineStepResultJson { | ||
return &MachineStepResultJson{ | ||
Hash: result.Hash, | ||
Position: result.Position, | ||
Status: uint8(result.Status), | ||
GlobalState: result.GlobalState, | ||
} | ||
} | ||
|
||
func MachineStepResultFromJson(resultJson *MachineStepResultJson) (*validator.MachineStepResult, error) { | ||
|
||
return &validator.MachineStepResult{ | ||
Hash: resultJson.Hash, | ||
Position: resultJson.Position, | ||
Status: validator.MachineStatus(resultJson.Status), | ||
GlobalState: resultJson.GlobalState, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters