forked from cerc-io/ipld-eth-server
82fd73ba3f
- 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)
24 lines
544 B
Go
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
|
|
}
|