You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.7 KiB
76 lines
1.7 KiB
6 years ago
|
package explorer
|
||
|
|
||
6 years ago
|
import (
|
||
|
"math/big"
|
||
|
"strconv"
|
||
|
|
||
|
"github.com/harmony-one/harmony/core/types"
|
||
|
)
|
||
6 years ago
|
|
||
6 years ago
|
/*
|
||
|
* All the code here is work of progress for the sprint.
|
||
|
*/
|
||
|
|
||
|
// Data ...
|
||
|
type Data struct {
|
||
6 years ago
|
Blocks []*Block `json:"blocks"`
|
||
|
// Block Block `json:"block"`
|
||
|
Address Address `json:"address"`
|
||
|
TX Transaction
|
||
6 years ago
|
}
|
||
|
|
||
|
// Address ...
|
||
|
type Address struct {
|
||
6 years ago
|
ID string `json:"id"`
|
||
|
Balance *big.Int `json:"balance"`
|
||
|
TXs []*Transaction `json:"txs"`
|
||
6 years ago
|
}
|
||
|
|
||
|
// Transaction ...
|
||
|
type Transaction struct {
|
||
6 years ago
|
ID string `json:"id"`
|
||
|
Timestamp string `json:"timestamp"`
|
||
|
From string `json:"from"`
|
||
|
To string `json:"to"`
|
||
|
Value *big.Int `json:"value"`
|
||
|
Bytes string `json:"bytes"`
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
// Block ...
|
||
|
type Block struct {
|
||
6 years ago
|
Height string `json:"height"`
|
||
|
ID string `json:"id"`
|
||
|
TXCount string `json:"txCount"`
|
||
|
Timestamp string `json:"timestamp"`
|
||
|
MerkleRoot string `json:"merkleRoot"`
|
||
|
PrevBlock RefBlock `json:"prevBlock"`
|
||
|
Bytes string `json:"bytes"`
|
||
|
NextBlock RefBlock `json:"nextBlock"`
|
||
|
TXs []*Transaction `json:"txs"`
|
||
6 years ago
|
}
|
||
|
|
||
|
// RefBlock ...
|
||
|
type RefBlock struct {
|
||
|
ID string `json:"id"`
|
||
6 years ago
|
Height string `json:"height"`
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
|
// GetTransaction ...
|
||
|
func GetTransaction(tx *types.Transaction, accountBlock *types.Block) *Transaction {
|
||
|
if tx.To() == nil {
|
||
|
return nil
|
||
|
}
|
||
|
msg, err := tx.AsMessage(types.HomesteadSigner{})
|
||
|
if err != nil {
|
||
|
Log.Error("Error when parsing tx into message")
|
||
|
}
|
||
|
return &Transaction{
|
||
|
ID: tx.Hash().Hex(),
|
||
|
Timestamp: strconv.Itoa(int(accountBlock.Time().Int64() * 1000)),
|
||
|
From: msg.From().Hex(),
|
||
|
To: msg.To().Hex(),
|
||
|
Value: msg.Value(),
|
||
|
Bytes: strconv.Itoa(int(tx.Size())),
|
||
|
}
|
||
|
}
|