diff --git a/cmd/relayer/main.go b/cmd/relayer/main.go index 6ecc29d..2733992 100644 --- a/cmd/relayer/main.go +++ b/cmd/relayer/main.go @@ -5,13 +5,13 @@ import ( "fmt" "math/big" "os" - "strconv" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" "github.com/tranvictor/ethashproof" "github.com/tranvictor/ethashproof/ethash" "github.com/tranvictor/ethashproof/mtree" - "github.com/tranvictor/ethutils/reader" ) type Output struct { @@ -24,24 +24,23 @@ type Output struct { func main() { if len(os.Args) < 2 { - fmt.Printf("Block number param is missing. Please run ./relayer instead.\n") + fmt.Printf("Block rlp param is missing. Please run ./relayer instead.\n") return } if len(os.Args) > 2 { - fmt.Printf("Please pass only 1 param as a block number. Please run ./relayer instead.\n") + fmt.Printf("Please pass only 1 param as a hex-encoded block rlp. Please run ./relayer instead.\n") return } - number, err := strconv.Atoi(os.Args[1]) + rlpheader, err := hexutil.Decode(os.Args[1]) if err != nil { - fmt.Printf("Please pass a number as a block number. Please run ./relayer instead.\n") + fmt.Printf("Please pass a hex as a block rlp. Please run ./relayer instead.\n") fmt.Printf("Error: %s\n", err) return } - fmt.Printf("Getting block header\n") - r := reader.NewEthReader() - header, err := r.HeaderByNumber(int64(number)) - if err != nil { - fmt.Printf("Getting header failed: %s\n", err) + fmt.Printf("Decoding block header\n") + var header *types.Header + if err := rlp.DecodeBytes(rlpheader, &header); err != nil { + fmt.Printf("RLP decoding of header failed: %s\n", err) return } @@ -70,11 +69,6 @@ func main() { fmt.Printf("Proof length: %d\n", cache.ProofLength) - rlpheader, err := ethashproof.RLPHeader(header) - if err != nil { - fmt.Printf("Can't rlp encode the header: %s\n", err) - } - output := &Output{ HeaderRLP: hexutil.Encode(rlpheader), MerkleRoot: cache.RootHash.Hex(), diff --git a/utils.go b/utils.go deleted file mode 100644 index c6d8240..0000000 --- a/utils.go +++ /dev/null @@ -1,26 +0,0 @@ -package ethashproof - -import ( - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" -) - -func RLPHeader(header *types.Header) ([]byte, error) { - return rlp.EncodeToBytes([]interface{}{ - header.ParentHash, - header.UncleHash, - header.Coinbase, - header.Root, - header.TxHash, - header.ReceiptHash, - header.Bloom, - header.Difficulty, - header.Number, - header.GasLimit, - header.GasUsed, - header.Time, - header.Extra, - header.MixDigest, - header.Nonce, - }) -}