validator

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2019 License: MIT Imports: 5 Imported by: 2

Documentation

Index

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 New

func New() *Validator

New returns a new Validator instance

func (*Validator) LoadBlock added in v0.0.2

func (v *Validator) LoadBlock(block types.Block)

func (*Validator) LoadBlockResponse

func (v *Validator) LoadBlockResponse(data []byte) error

func (*Validator) LoadReceipts added in v0.0.2

func (v *Validator) LoadReceipts(receipts []types.Receipt)

func (*Validator) LoadReceiptsResponse

func (v *Validator) LoadReceiptsResponse(data []byte) error

func (*Validator) LoadReplayResponse

func (v *Validator) LoadReplayResponse(data []byte) error

func (*Validator) LoadReplays added in v0.0.2

func (v *Validator) LoadReplays(replays []types.TransactionReplay)

func (*Validator) LoadTraceBlockResponse

func (v *Validator) LoadTraceBlockResponse(data []byte) error

func (*Validator) LoadTraces added in v0.0.2

func (v *Validator) LoadTraces(traces []types.Trace)

func (*Validator) LoadUncles added in v0.0.2

func (v *Validator) LoadUncles(uncles []types.Block)

func (*Validator) LoadUnclesResponse

func (v *Validator) LoadUnclesResponse(data []byte) error

func (*Validator) Run

func (v *Validator) Run() (bool, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL