|
|
@ -5,7 +5,6 @@ import ( |
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/ethutil" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type BlockRes struct { |
|
|
|
type BlockRes struct { |
|
|
@ -56,23 +55,23 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// convert strict types to hexified strings
|
|
|
|
// convert strict types to hexified strings
|
|
|
|
ext.BlockNumber = ethutil.Bytes2Hex(big.NewInt(b.BlockNumber).Bytes()) |
|
|
|
ext.BlockNumber = toHex(big.NewInt(b.BlockNumber).Bytes()) |
|
|
|
ext.BlockHash = ethutil.Bytes2Hex(b.BlockHash) |
|
|
|
ext.BlockHash = toHex(b.BlockHash) |
|
|
|
ext.ParentHash = ethutil.Bytes2Hex(b.ParentHash) |
|
|
|
ext.ParentHash = toHex(b.ParentHash) |
|
|
|
ext.Nonce = ethutil.Bytes2Hex(b.Nonce) |
|
|
|
ext.Nonce = toHex(b.Nonce) |
|
|
|
ext.Sha3Uncles = ethutil.Bytes2Hex(b.Sha3Uncles) |
|
|
|
ext.Sha3Uncles = toHex(b.Sha3Uncles) |
|
|
|
ext.LogsBloom = ethutil.Bytes2Hex(b.LogsBloom) |
|
|
|
ext.LogsBloom = toHex(b.LogsBloom) |
|
|
|
ext.TransactionRoot = ethutil.Bytes2Hex(b.TransactionRoot) |
|
|
|
ext.TransactionRoot = toHex(b.TransactionRoot) |
|
|
|
ext.StateRoot = ethutil.Bytes2Hex(b.StateRoot) |
|
|
|
ext.StateRoot = toHex(b.StateRoot) |
|
|
|
ext.Miner = ethutil.Bytes2Hex(b.Miner) |
|
|
|
ext.Miner = toHex(b.Miner) |
|
|
|
ext.Difficulty = ethutil.Bytes2Hex(big.NewInt(b.Difficulty).Bytes()) |
|
|
|
ext.Difficulty = toHex(big.NewInt(b.Difficulty).Bytes()) |
|
|
|
ext.TotalDifficulty = ethutil.Bytes2Hex(big.NewInt(b.TotalDifficulty).Bytes()) |
|
|
|
ext.TotalDifficulty = toHex(big.NewInt(b.TotalDifficulty).Bytes()) |
|
|
|
ext.Size = ethutil.Bytes2Hex(big.NewInt(b.Size).Bytes()) |
|
|
|
ext.Size = toHex(big.NewInt(b.Size).Bytes()) |
|
|
|
ext.ExtraData = ethutil.Bytes2Hex(b.ExtraData) |
|
|
|
// ext.ExtraData = toHex(b.ExtraData)
|
|
|
|
ext.GasLimit = ethutil.Bytes2Hex(big.NewInt(b.GasLimit).Bytes()) |
|
|
|
ext.GasLimit = toHex(big.NewInt(b.GasLimit).Bytes()) |
|
|
|
ext.MinGasPrice = ethutil.Bytes2Hex(big.NewInt(b.MinGasPrice).Bytes()) |
|
|
|
// ext.MinGasPrice = toHex(big.NewInt(b.MinGasPrice).Bytes())
|
|
|
|
ext.GasUsed = ethutil.Bytes2Hex(big.NewInt(b.GasUsed).Bytes()) |
|
|
|
ext.GasUsed = toHex(big.NewInt(b.GasUsed).Bytes()) |
|
|
|
ext.UnixTimestamp = ethutil.Bytes2Hex(big.NewInt(b.UnixTimestamp).Bytes()) |
|
|
|
ext.UnixTimestamp = toHex(big.NewInt(b.UnixTimestamp).Bytes()) |
|
|
|
ext.Transactions = make([]interface{}, len(b.Transactions)) |
|
|
|
ext.Transactions = make([]interface{}, len(b.Transactions)) |
|
|
|
if b.fullTx { |
|
|
|
if b.fullTx { |
|
|
|
for i, tx := range b.Transactions { |
|
|
|
for i, tx := range b.Transactions { |
|
|
@ -80,12 +79,12 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for i, tx := range b.Transactions { |
|
|
|
for i, tx := range b.Transactions { |
|
|
|
ext.Transactions[i] = ethutil.Bytes2Hex(tx.Hash) |
|
|
|
ext.Transactions[i] = toHex(tx.Hash) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ext.Uncles = make([]string, len(b.Uncles)) |
|
|
|
ext.Uncles = make([]string, len(b.Uncles)) |
|
|
|
for i, v := range b.Uncles { |
|
|
|
for i, v := range b.Uncles { |
|
|
|
ext.Uncles[i] = ethutil.Bytes2Hex(v) |
|
|
|
ext.Uncles[i] = toHex(v) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return json.Marshal(ext) |
|
|
|
return json.Marshal(ext) |
|
|
@ -103,7 +102,9 @@ func NewBlockRes(block *types.Block) *BlockRes { |
|
|
|
res.StateRoot = block.Root() |
|
|
|
res.StateRoot = block.Root() |
|
|
|
res.Miner = block.Header().Coinbase |
|
|
|
res.Miner = block.Header().Coinbase |
|
|
|
res.Difficulty = block.Difficulty().Int64() |
|
|
|
res.Difficulty = block.Difficulty().Int64() |
|
|
|
|
|
|
|
if block.Td != nil { |
|
|
|
res.TotalDifficulty = block.Td.Int64() |
|
|
|
res.TotalDifficulty = block.Td.Int64() |
|
|
|
|
|
|
|
} |
|
|
|
res.Size = int64(block.Size()) |
|
|
|
res.Size = int64(block.Size()) |
|
|
|
// res.ExtraData =
|
|
|
|
// res.ExtraData =
|
|
|
|
res.GasLimit = block.GasLimit().Int64() |
|
|
|
res.GasLimit = block.GasLimit().Int64() |
|
|
@ -154,17 +155,17 @@ func (t *TransactionRes) MarshalJSON() ([]byte, error) { |
|
|
|
Input string `json:"input"` |
|
|
|
Input string `json:"input"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ext.Hash = ethutil.Bytes2Hex(t.Hash) |
|
|
|
ext.Hash = toHex(t.Hash) |
|
|
|
ext.Nonce = ethutil.Bytes2Hex(big.NewInt(t.Nonce).Bytes()) |
|
|
|
ext.Nonce = toHex(big.NewInt(t.Nonce).Bytes()) |
|
|
|
ext.BlockHash = ethutil.Bytes2Hex(t.BlockHash) |
|
|
|
ext.BlockHash = toHex(t.BlockHash) |
|
|
|
ext.BlockNumber = ethutil.Bytes2Hex(big.NewInt(t.BlockNumber).Bytes()) |
|
|
|
ext.BlockNumber = toHex(big.NewInt(t.BlockNumber).Bytes()) |
|
|
|
ext.TxIndex = ethutil.Bytes2Hex(big.NewInt(t.TxIndex).Bytes()) |
|
|
|
ext.TxIndex = toHex(big.NewInt(t.TxIndex).Bytes()) |
|
|
|
ext.From = ethutil.Bytes2Hex(t.From) |
|
|
|
ext.From = toHex(t.From) |
|
|
|
ext.To = ethutil.Bytes2Hex(t.To) |
|
|
|
ext.To = toHex(t.To) |
|
|
|
ext.Value = ethutil.Bytes2Hex(big.NewInt(t.Value).Bytes()) |
|
|
|
ext.Value = toHex(big.NewInt(t.Value).Bytes()) |
|
|
|
ext.Gas = ethutil.Bytes2Hex(big.NewInt(t.Gas).Bytes()) |
|
|
|
ext.Gas = toHex(big.NewInt(t.Gas).Bytes()) |
|
|
|
ext.GasPrice = ethutil.Bytes2Hex(big.NewInt(t.GasPrice).Bytes()) |
|
|
|
ext.GasPrice = toHex(big.NewInt(t.GasPrice).Bytes()) |
|
|
|
ext.Input = ethutil.Bytes2Hex(t.Input) |
|
|
|
ext.Input = toHex(t.Input) |
|
|
|
|
|
|
|
|
|
|
|
return json.Marshal(ext) |
|
|
|
return json.Marshal(ext) |
|
|
|
} |
|
|
|
} |
|
|
|