2017-11-02 19:37:07 +00:00
|
|
|
package geth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/8thlight/vulcanizedb/core"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2017-11-02 14:36:53 +00:00
|
|
|
"strconv"
|
2017-11-02 19:37:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func gethTransToCoreTrans(transaction *types.Transaction) core.Transaction {
|
|
|
|
to := transaction.To()
|
|
|
|
toHex := convertTo(to)
|
|
|
|
return core.Transaction{
|
|
|
|
Hash: transaction.Hash().Hex(),
|
|
|
|
Data: transaction.Data(),
|
|
|
|
Nonce: transaction.Nonce(),
|
|
|
|
To: toHex,
|
|
|
|
GasLimit: transaction.Gas().Int64(),
|
|
|
|
GasPrice: transaction.GasPrice().Int64(),
|
|
|
|
Value: transaction.Value().Int64(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GethBlockToCoreBlock(gethBlock *types.Block) core.Block {
|
|
|
|
transactions := []core.Transaction{}
|
|
|
|
for _, gethTransaction := range gethBlock.Transactions() {
|
|
|
|
transactions = append(transactions, gethTransToCoreTrans(gethTransaction))
|
|
|
|
}
|
|
|
|
return core.Block{
|
2017-11-02 14:36:53 +00:00
|
|
|
Difficulty: gethBlock.Difficulty().Int64(),
|
2017-11-02 19:37:07 +00:00
|
|
|
GasLimit: gethBlock.GasLimit().Int64(),
|
|
|
|
GasUsed: gethBlock.GasUsed().Int64(),
|
2017-11-02 14:36:53 +00:00
|
|
|
Hash: gethBlock.Hash().Hex(),
|
|
|
|
Nonce: strconv.FormatUint(gethBlock.Nonce(), 10),
|
|
|
|
Number: gethBlock.Number().Int64(),
|
|
|
|
ParentHash: gethBlock.ParentHash().Hex(),
|
|
|
|
Size: gethBlock.Size().Int64(),
|
2017-11-02 19:37:07 +00:00
|
|
|
Time: gethBlock.Time().Int64(),
|
|
|
|
Transactions: transactions,
|
2017-11-02 14:36:53 +00:00
|
|
|
UncleHash: gethBlock.UncleHash().Hex(),
|
2017-11-02 19:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertTo(to *common.Address) string {
|
|
|
|
if to == nil {
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
return to.Hex()
|
|
|
|
}
|
|
|
|
}
|