ipld-eth-server/pkg/geth/log_to_core_log.go

43 lines
967 B
Go
Raw Normal View History

package geth
import (
2018-01-15 17:21:08 +00:00
"strings"
"github.com/8thlight/vulcanizedb/pkg/core"
2018-01-15 20:44:47 +00:00
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
)
2018-01-15 20:44:47 +00:00
func LogsToCoreLogs(gethLogs []types.Log) []core.Log {
var logs []core.Log
for _, log := range gethLogs {
log := LogToCoreLog(log)
logs = append(logs, log)
}
return logs
}
func MakeTopics(topics []common.Hash) core.Topics {
var hexTopics core.Topics
for i, topic := range topics {
hexTopics[i] = topic.Hex()
}
2018-01-15 20:44:47 +00:00
return hexTopics
}
func LogToCoreLog(gethLog types.Log) core.Log {
topics := gethLog.Topics
hexTopics := MakeTopics(topics)
return core.Log{
2018-01-15 17:21:08 +00:00
Address: strings.ToLower(gethLog.Address.Hex()),
BlockNumber: int64(gethLog.BlockNumber),
Topics: hexTopics,
TxHash: gethLog.TxHash.Hex(),
Index: int64(gethLog.Index),
Data: hexutil.Encode(gethLog.Data),
2018-01-15 20:44:47 +00:00
Removed: gethLog.Removed,
}
}