2017-12-11 21:08:00 +00:00
|
|
|
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"
|
2017-12-11 21:08:00 +00:00
|
|
|
"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
|
2017-12-12 21:55:26 +00:00
|
|
|
for i, topic := range topics {
|
|
|
|
hexTopics[i] = topic.Hex()
|
2017-12-11 21:08:00 +00:00
|
|
|
}
|
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)
|
2017-12-11 21:08:00 +00:00
|
|
|
return core.Log{
|
2018-01-15 17:21:08 +00:00
|
|
|
Address: strings.ToLower(gethLog.Address.Hex()),
|
2017-12-11 21:08:00 +00:00
|
|
|
|
|
|
|
BlockNumber: int64(gethLog.BlockNumber),
|
|
|
|
Topics: hexTopics,
|
|
|
|
TxHash: gethLog.TxHash.Hex(),
|
2017-12-12 21:55:26 +00:00
|
|
|
Index: int64(gethLog.Index),
|
2017-12-11 21:08:00 +00:00
|
|
|
Data: hexutil.Encode(gethLog.Data),
|
|
|
|
}
|
|
|
|
}
|