Documentation ¶
Index ¶
- Constants
- type Validator
- func (v *Validator) LoadBlock(block types.Block)
- func (v *Validator) LoadBlockResponse(data []byte) error
- func (v *Validator) LoadReceipts(receipts []types.Receipt)
- func (v *Validator) LoadReceiptsResponse(data []byte) error
- func (v *Validator) LoadReplayResponse(data []byte) error
- func (v *Validator) LoadReplays(replays []types.TransactionReplay)
- func (v *Validator) LoadTraceBlockResponse(data []byte) error
- func (v *Validator) LoadTraces(traces []types.Trace)
- func (v *Validator) LoadUncles(uncles []types.Block)
- func (v *Validator) LoadUnclesResponse(data []byte) error
- func (v *Validator) Run() (bool, error)
Examples ¶
Constants ¶
View Source
const Block = "block"
View Source
const Receipts = "receipts"
View Source
const Replays = "replays"
View Source
const Traces = "traces"
View Source
const Uncles = "uncles"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Validator ¶
type Validator struct { Block types.Block Uncles []types.Block Receipts []types.Receipt Traces []types.Trace Replays []types.TransactionReplay // contains filtered or unexported fields }
Validator is intended for validating the logical integrity of JSONRPC responses coming from parity
func (*Validator) LoadBlockResponse ¶
func (*Validator) LoadReceipts ¶ added in v0.0.2
func (*Validator) LoadReceiptsResponse ¶
func (*Validator) LoadReplayResponse ¶
func (*Validator) LoadReplays ¶ added in v0.0.2
func (v *Validator) LoadReplays(replays []types.TransactionReplay)
func (*Validator) LoadTraceBlockResponse ¶
func (*Validator) LoadTraces ¶ added in v0.0.2
func (*Validator) LoadUncles ¶ added in v0.0.2
func (*Validator) LoadUnclesResponse ¶
func (*Validator) Run ¶
Run executes all the available verifiers and returns (true, nil) if the block is valid or (false, error) if the block is not valid
Example ¶
const cache = "../testdata/web3_cache" const file = "000007700162.json" var dirs = []string{ "eth_getBlockByNumber", "eth_getTransactionReceipt", "eth_getUncleByBlockHashAndIndex", "trace_block", "trace_replayBlockTransactions", } v := New() for _, dir := range dirs { path := cache + "/" + dir + "/" + file // Make sure the file exists before trying to read it _, err := os.Stat(path) if os.IsNotExist(err) { continue } else if err != nil { log.Fatal("could not read file: ", err) } data, err := ioutil.ReadFile(cache + "/" + dir + "/" + file) if err != nil { log.Fatal("could not read file: ", err) } switch dir { case "eth_getBlockByNumber": err = v.LoadBlockResponse(data) case "eth_getTransactionReceipt": err = v.LoadReceiptsResponse(data) case "eth_getUncleByBlockHashAndIndex": err = v.LoadUnclesResponse(data) case "trace_block": err = v.LoadTraceBlockResponse(data) case "trace_replayBlockTransactions": err = v.LoadReplayResponse(data) } if err != nil { log.Fatal("could not load data into validator: ", err) } } ok, err := v.Run() if err != nil { log.Fatal(err) } fmt.Printf("Validator response for block %s: %s", file, func(valid bool) string { if valid { return "valid" } else { return "not valid" } }(ok))
Output: Validator response for block 000007700162.json: valid
Click to show internal directories.
Click to hide internal directories.