ipld-eth-server/pkg/geth/converters/common/header_converter.go
Rob Mulholand 82fd73ba3f (VDB-68) Verify log block hash matches header block hash
- Delete header on conflict to prompt data refresh (cascade deletes all
  data associated with that block)
- Derive header hash from rpc payload rather than computing it from data
  (prevents hash mismatch between blockchain and cache)
2018-11-13 14:51:39 -06:00

24 lines
544 B
Go

package common
import (
"encoding/json"
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/core"
)
type HeaderConverter struct{}
func (converter HeaderConverter) Convert(gethHeader *types.Header, blockHash string) (core.Header, error) {
rawHeader, err := json.Marshal(gethHeader)
if err != nil {
panic(err)
}
coreHeader := core.Header{
Hash: blockHash,
BlockNumber: gethHeader.Number.Int64(),
Raw: rawHeader,
Timestamp: gethHeader.Time.String(),
}
return coreHeader, nil
}