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

42 lines
926 B
Go
Raw Normal View History

package geth
import (
2018-01-15 17:21:08 +00:00
"strings"
2018-01-06 20:31:53 +00:00
"github.com/vulcanize/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 21:27:45 +00:00
func ToCoreLogs(gethLogs []types.Log) []core.Log {
2018-01-15 20:44:47 +00:00
var logs []core.Log
for _, log := range gethLogs {
2018-01-15 21:27:45 +00:00
log := ToCoreLog(log)
2018-01-15 20:44:47 +00:00
logs = append(logs, log)
}
return logs
}
2018-01-15 21:27:45 +00:00
func makeTopics(topics []common.Hash) core.Topics {
2018-01-15 20:44:47 +00:00
var hexTopics core.Topics
for i, topic := range topics {
hexTopics[i] = topic.Hex()
}
2018-01-15 20:44:47 +00:00
return hexTopics
}
2018-01-15 21:27:45 +00:00
func ToCoreLog(gethLog types.Log) core.Log {
2018-01-15 20:44:47 +00:00
topics := gethLog.Topics
2018-01-15 21:27:45 +00:00
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),
}
}