Skip to content

Commit

Permalink
Fix for issue connecting to Parity. Still has a bug right now. For ref
Browse files Browse the repository at this point in the history
  • Loading branch information
SomniaStellarum committed Nov 24, 2018
1 parent 3240276 commit 88da98d
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
return nil, ethereum.NotFound
}
// Decode header and transactions.
var localHeader *Header
var head *types.Header
var body rpcBlock
if err := json.Unmarshal(raw, &head); err != nil {
if err = json.Unmarshal(raw, &localHeader); err != nil {
return nil, err
}
// Convert to *types.Header
if head, err = localHeader.convertHeader(); err != nil {
return nil, err
}
if err := json.Unmarshal(raw, &body); err != nil {
Expand Down
136 changes: 136 additions & 0 deletions ethclient/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions ethclient/header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package ethclient

import (
"encoding/json"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
)

// Header represents a block header in the Ethereum blockchain.
// Local version to ethclient to allow non-required fields.
// Bloom and BlockNonce are []byte. Do json.Unmarshall on them when creating
// types.Header.
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom []byte `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce []byte `json:"nonce"`
}

// field type overrides for gencodec
type headerMarshaling struct {
Difficulty *hexutil.Big
Number *hexutil.Big
GasLimit hexutil.Uint64
GasUsed hexutil.Uint64
Time *hexutil.Big
Extra hexutil.Bytes
}

func (h *Header) convertHeader() (header *types.Header, err error) {
header.ParentHash = h.ParentHash
header.UncleHash = h.UncleHash
header.Coinbase = h.Coinbase
header.Root = h.Root
header.TxHash = h.TxHash
header.ReceiptHash = h.ReceiptHash
if err := json.Unmarshal(h.Bloom, header.Bloom); err != nil {
return nil, errors.New("Unmarshalling Bloom Error")
}
header.Difficulty = h.Difficulty
header.Number = h.Number
header.GasLimit = h.GasLimit
header.GasUsed = h.GasUsed
header.Time = h.Time
header.Extra = h.Extra
header.MixDigest = h.MixDigest
fmt.Println(header.MixDigest)
// if h.MixDigest == nil {
// header.MixDigest = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
// } else {
// header.MixDigest = h.MixDigest
// }
if h.Nonce == nil {
header.Nonce = types.EncodeNonce(0)
} else {
if err := json.Unmarshal(h.Nonce, header.Nonce); err != nil {
return nil, errors.New("Unmarshalling Nonce Error")
}
}
return header, nil
}

0 comments on commit 88da98d

Please sign in to comment.