2018-07-17 21:23:07 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-10-11 20:25:14 +00:00
|
|
|
"encoding/json"
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HeaderConverter struct{}
|
|
|
|
|
|
|
|
func (converter HeaderConverter) Convert(gethHeader *types.Header) (core.Header, error) {
|
2018-10-11 20:25:14 +00:00
|
|
|
rawHeader, err := json.Marshal(gethHeader)
|
2018-07-17 21:23:07 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
coreHeader := core.Header{
|
|
|
|
Hash: gethHeader.Hash().Hex(),
|
|
|
|
BlockNumber: gethHeader.Number.Int64(),
|
2018-10-11 20:25:14 +00:00
|
|
|
Raw: rawHeader,
|
|
|
|
Timestamp: gethHeader.Time.String(),
|
2018-07-17 21:23:07 +00:00
|
|
|
}
|
|
|
|
return coreHeader, nil
|
|
|
|
}
|