forked from ethereumproject/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/orb-verify: implement package as plugin-ready library
core: implement orb-verify as optional golang plugin lib fix: orb-verify binary should not exist in project root
- Loading branch information
Showing
7 changed files
with
221 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// This is a plugin-ready library. | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var errInvalidArgument = errors.New("invalid argument") | ||
var errInvalidHeader = errors.New("invalid header") | ||
|
||
type rec string | ||
|
||
var Validator rec | ||
|
||
func (r rec) Validate(in string) error { | ||
args := strings.Split(in, " ") | ||
if len(args) != 3 { | ||
return (errInvalidArgument) | ||
} | ||
|
||
headerJSON, parentJSON, isUncleStr := args[0], args[1], args[2] | ||
|
||
// Initial sanity checks that args are actually present and legit. | ||
_, err := strconv.ParseBool(isUncleStr) | ||
if err != nil { | ||
return (err) | ||
} | ||
if !strings.Contains(headerJSON, "Hash") { | ||
return fmt.Errorf("%v: %s", errInvalidArgument, headerJSON) | ||
} | ||
if !strings.Contains(parentJSON, "Hash") { | ||
return fmt.Errorf("%v: %s", errInvalidArgument, parentJSON) | ||
} | ||
|
||
var header, parent *struct { | ||
Number uint64 | ||
Hash string | ||
} | ||
|
||
if err := json.Unmarshal([]byte(headerJSON), &header); err != nil { | ||
return (err) | ||
} | ||
if err := json.Unmarshal([]byte(parentJSON), &parent); err != nil { | ||
return (err) | ||
} | ||
|
||
// TODO Implement your own header validations. | ||
|
||
if header.Number != parent.Number+1 { | ||
return fmt.Errorf("%v: %d %d", errInvalidHeader, header.Number, parent.Number) | ||
} | ||
|
||
// // Here's an example of making an upstream RPC request (to a TRUSTED source), | ||
// // then using that data to provide supplemental information for block validation. | ||
// remoteRPCAPI, err := url.Parse("http://localhost:8545") | ||
// if err != nil { | ||
// return (err) | ||
// } | ||
|
||
// req := &rpc.JSONRequest{ | ||
// // Id | ||
// Version: "2.0", | ||
// Method: "eth_blockNumber", | ||
// // Payload | ||
// } | ||
|
||
// b, err := json.Marshal(req) | ||
// if err != nil { | ||
// return (err) | ||
// } | ||
|
||
// res, err := http.Post(remoteRPCAPI.String(), "application/json", bytes.NewBuffer(b)) | ||
// if err != nil { | ||
// return (err) | ||
// } | ||
|
||
// var r *rpc.JSONResponse | ||
// err = json.NewDecoder(res.Body).Decode(&r) | ||
// if err != nil { | ||
// return (err) | ||
// } | ||
|
||
// if r.Error != nil { | ||
// return (r.Error) | ||
// } | ||
|
||
// // TODO Do some logic with response | ||
// // ... | ||
|
||
return 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
Oops, something went wrong.