2015-03-10 17:52:45 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2015-03-23 15:59:09 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2015-03-25 15:50:30 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2015-03-10 17:52:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type BlockRes struct {
|
|
|
|
fullTx bool
|
|
|
|
|
2015-03-31 17:04:02 +00:00
|
|
|
BlockNumber *hexnum `json:"number"`
|
|
|
|
BlockHash *hexdata `json:"hash"`
|
|
|
|
ParentHash *hexdata `json:"parentHash"`
|
|
|
|
Nonce *hexnum `json:"nonce"`
|
|
|
|
Sha3Uncles *hexdata `json:"sha3Uncles"`
|
|
|
|
LogsBloom *hexdata `json:"logsBloom"`
|
|
|
|
TransactionRoot *hexdata `json:"transactionRoot"`
|
|
|
|
StateRoot *hexdata `json:"stateRoot"`
|
|
|
|
Miner *hexdata `json:"miner"`
|
|
|
|
Difficulty *hexnum `json:"difficulty"`
|
|
|
|
TotalDifficulty *hexnum `json:"totalDifficulty"`
|
|
|
|
Size *hexnum `json:"size"`
|
|
|
|
ExtraData *hexdata `json:"extraData"`
|
|
|
|
GasLimit *hexnum `json:"gasLimit"`
|
|
|
|
MinGasPrice *hexnum `json:"minGasPrice"`
|
|
|
|
GasUsed *hexnum `json:"gasUsed"`
|
|
|
|
UnixTimestamp *hexnum `json:"timestamp"`
|
2015-03-10 17:52:45 +00:00
|
|
|
Transactions []*TransactionRes `json:"transactions"`
|
2015-03-31 17:04:02 +00:00
|
|
|
Uncles []*hexdata `json:"uncles"`
|
2015-03-10 17:52:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 11:18:30 +00:00
|
|
|
func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
|
|
|
|
// TODO respect fullTx flag
|
|
|
|
|
2015-03-11 00:34:07 +00:00
|
|
|
if block == nil {
|
|
|
|
return &BlockRes{}
|
|
|
|
}
|
|
|
|
|
2015-03-10 17:52:45 +00:00
|
|
|
res := new(BlockRes)
|
2015-04-01 11:18:30 +00:00
|
|
|
res.fullTx = fullTx
|
2015-03-31 17:04:02 +00:00
|
|
|
res.BlockNumber = newHexNum(block.Number())
|
|
|
|
res.BlockHash = newHexData(block.Hash())
|
|
|
|
res.ParentHash = newHexData(block.ParentHash())
|
|
|
|
res.Nonce = newHexNum(block.Header().Nonce)
|
|
|
|
res.Sha3Uncles = newHexData(block.Header().UncleHash)
|
|
|
|
res.LogsBloom = newHexData(block.Bloom())
|
|
|
|
res.TransactionRoot = newHexData(block.Header().TxHash)
|
|
|
|
res.StateRoot = newHexData(block.Root())
|
|
|
|
res.Miner = newHexData(block.Header().Coinbase)
|
|
|
|
res.Difficulty = newHexNum(block.Difficulty())
|
|
|
|
res.TotalDifficulty = newHexNum(block.Td)
|
|
|
|
res.Size = newHexNum(block.Size())
|
|
|
|
res.ExtraData = newHexData(block.Header().Extra)
|
|
|
|
res.GasLimit = newHexNum(block.GasLimit())
|
2015-03-10 17:52:45 +00:00
|
|
|
// res.MinGasPrice =
|
2015-03-31 17:04:02 +00:00
|
|
|
res.GasUsed = newHexNum(block.GasUsed())
|
|
|
|
res.UnixTimestamp = newHexNum(block.Time())
|
2015-04-01 11:18:51 +00:00
|
|
|
|
|
|
|
res.Transactions = make([]*TransactionRes, len(block.Transactions()))
|
|
|
|
for i, tx := range block.Transactions() {
|
|
|
|
res.Transactions[i] = NewTransactionRes(tx)
|
|
|
|
res.Transactions[i].BlockHash = res.BlockHash
|
|
|
|
res.Transactions[i].BlockNumber = res.BlockNumber
|
|
|
|
res.Transactions[i].TxIndex = newHexNum(i)
|
|
|
|
}
|
|
|
|
|
2015-03-31 17:04:02 +00:00
|
|
|
res.Uncles = make([]*hexdata, len(block.Uncles()))
|
2015-03-10 17:52:45 +00:00
|
|
|
for i, uncle := range block.Uncles() {
|
2015-03-31 17:04:02 +00:00
|
|
|
res.Uncles[i] = newHexData(uncle.Hash())
|
2015-03-10 17:52:45 +00:00
|
|
|
}
|
2015-04-01 11:18:51 +00:00
|
|
|
|
2015-03-10 17:52:45 +00:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
type TransactionRes struct {
|
2015-03-31 17:04:02 +00:00
|
|
|
Hash *hexdata `json:"hash"`
|
|
|
|
Nonce *hexnum `json:"nonce"`
|
|
|
|
BlockHash *hexdata `json:"blockHash"`
|
|
|
|
BlockNumber *hexnum `json:"blockNumber"`
|
|
|
|
TxIndex *hexnum `json:"transactionIndex"`
|
|
|
|
From *hexdata `json:"from"`
|
|
|
|
To *hexdata `json:"to"`
|
|
|
|
Value *hexnum `json:"value"`
|
|
|
|
Gas *hexnum `json:"gas"`
|
|
|
|
GasPrice *hexnum `json:"gasPrice"`
|
|
|
|
Input *hexdata `json:"input"`
|
2015-03-10 17:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTransactionRes(tx *types.Transaction) *TransactionRes {
|
|
|
|
var v = new(TransactionRes)
|
2015-03-31 17:04:02 +00:00
|
|
|
v.Hash = newHexData(tx.Hash())
|
|
|
|
v.Nonce = newHexNum(tx.Nonce())
|
|
|
|
// v.BlockHash =
|
|
|
|
// v.BlockNumber =
|
|
|
|
// v.TxIndex =
|
|
|
|
from, _ := tx.From()
|
|
|
|
v.From = newHexData(from)
|
|
|
|
v.To = newHexData(tx.To())
|
|
|
|
v.Value = newHexNum(tx.Value())
|
|
|
|
v.Gas = newHexNum(tx.Gas())
|
|
|
|
v.GasPrice = newHexNum(tx.GasPrice())
|
|
|
|
v.Input = newHexData(tx.Data())
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2015-03-31 15:40:35 +00:00
|
|
|
// type FilterLogRes struct {
|
|
|
|
// Hash string `json:"hash"`
|
|
|
|
// Address string `json:"address"`
|
|
|
|
// Data string `json:"data"`
|
|
|
|
// BlockNumber string `json:"blockNumber"`
|
|
|
|
// TransactionHash string `json:"transactionHash"`
|
|
|
|
// BlockHash string `json:"blockHash"`
|
|
|
|
// TransactionIndex string `json:"transactionIndex"`
|
|
|
|
// LogIndex string `json:"logIndex"`
|
|
|
|
// }
|
2015-03-10 17:52:45 +00:00
|
|
|
|
2015-03-31 15:40:35 +00:00
|
|
|
// type FilterWhisperRes struct {
|
|
|
|
// Hash string `json:"hash"`
|
|
|
|
// From string `json:"from"`
|
|
|
|
// To string `json:"to"`
|
|
|
|
// Expiry string `json:"expiry"`
|
|
|
|
// Sent string `json:"sent"`
|
|
|
|
// Ttl string `json:"ttl"`
|
|
|
|
// Topics string `json:"topics"`
|
|
|
|
// Payload string `json:"payload"`
|
|
|
|
// WorkProved string `json:"workProved"`
|
|
|
|
// }
|
2015-03-19 18:19:52 +00:00
|
|
|
|
|
|
|
type LogRes struct {
|
2015-03-31 17:04:02 +00:00
|
|
|
Address *hexdata `json:"address"`
|
|
|
|
Topics []*hexdata `json:"topics"`
|
|
|
|
Data *hexdata `json:"data"`
|
|
|
|
BlockNumber *hexnum `json:"blockNumber"`
|
|
|
|
Hash *hexdata `json:"hash"`
|
|
|
|
LogIndex *hexnum `json:"logIndex"`
|
|
|
|
BlockHash *hexdata `json:"blockHash"`
|
|
|
|
TransactionHash *hexdata `json:"transactionHash"`
|
|
|
|
TransactionIndex *hexnum `json:"transactionIndex"`
|
2015-03-25 15:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewLogRes(log state.Log) LogRes {
|
|
|
|
var l LogRes
|
2015-03-31 17:04:02 +00:00
|
|
|
l.Topics = make([]*hexdata, len(log.Topics()))
|
2015-03-25 15:50:30 +00:00
|
|
|
for j, topic := range log.Topics() {
|
2015-03-31 17:04:02 +00:00
|
|
|
l.Topics[j] = newHexData(topic)
|
2015-03-25 15:50:30 +00:00
|
|
|
}
|
2015-03-31 17:04:02 +00:00
|
|
|
l.Address = newHexData(log.Address())
|
|
|
|
l.Data = newHexData(log.Data())
|
|
|
|
l.BlockNumber = newHexNum(log.Number())
|
2015-03-25 15:50:30 +00:00
|
|
|
|
2015-03-31 17:04:02 +00:00
|
|
|
return l
|
2015-03-19 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewLogsRes(logs state.Logs) (ls []LogRes) {
|
|
|
|
ls = make([]LogRes, len(logs))
|
|
|
|
|
|
|
|
for i, log := range logs {
|
2015-03-25 15:50:30 +00:00
|
|
|
ls[i] = NewLogRes(log)
|
2015-03-19 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|