Skip to content
Snippets Groups Projects
Commit 35327557 authored by Miguel Montes's avatar Miguel Montes
Browse files

Agregado reporte de transferencias

parent 89e163ff
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,10 @@ func (bigInt *BigInt) UnmarshalJSON(b []byte) error {
}
func (bigInt *BigInt) String() string {
return (*big.Int)(bigInt).String()
}
func (bigInt *BigInt) Int64() int64 {
return (*big.Int)(bigInt).Int64()
}
......@@ -36,6 +40,10 @@ func (bigInt *BigInt) Uint64() uint64 {
return (*big.Int)(bigInt).Uint64()
}
func (bigInt *BigInt) IsZero() bool {
return (*big.Int)(bigInt).BitLen() == 0
}
type Uint64 uint64
func (u *Uint64) UnmarshalJSON(b []byte) (err error) {
......
......@@ -3,6 +3,7 @@ package bfa
import (
. "../util"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
......@@ -65,6 +66,11 @@ func (node *Node) BlockNumber() int64 {
return bn.Int64()
}
func (node *Node) GasPrice() (gp int64) {
node.Call(&gp, "eth_gasPrice")
return gp
}
func (node *Node) Accounts() (accounts []string) {
node.Call(&accounts, "eth_accounts")
return
......@@ -142,6 +148,12 @@ func (node *Node) BlockByHash(hash common.Hash) (block Block) {
return
}
func (node *Node) BlockTransactionCount(blockNumber int64) (count int64) {
var num hexutil.Uint64
node.Call(&num, "eth_getBlockTransactionCountByNumber", hexBlockNumber(blockNumber))
return int64(num)
}
func (node *Node) BlockSigner(blockNumber int64) (signer common.Address) {
if blockNumber == 0 { // we return an empty signer for genesis block
return
......
......@@ -502,6 +502,76 @@ func snapshot() {
util.PrintJson(snapshot)
}
func transfers() {
type Transfer struct {
From string `json:"from"`
To string `json:"to"`
Amount *big.Int `json:"amount"`
BlockNumber int64 `json:"blockNumber"`
}
var (
first, last, end int64
)
description = "Muestra transferencias en un rango de bloques, y opcionalmente, restringidas a ciertas direcciones."
otherArgs = "[dirección...]"
setFlags()
flags.Int64Var(&first, "first-block", latest, "Primer bloque del rango (-1 para especificar el último bloque)")
flags.Int64Var(&last, "last-block", latest, "Último bloque del rango (-1 para especificar el último bloque)")
parseFlags(true)
url = updateURL(url)
node, err := bfa.Dial(url)
util.Check(err)
defer node.Close()
set := make(map[common.Address]bool)
txs := make([]Transfer, 0)
for i := 0; i < flags.NArg(); i++ {
address := flags.Arg(i)
util.Ensure(util.IsAddress(address), "'%v' no es una dirección válida", address)
set[common.HexToAddress(address)] = true
}
latest := node.BlockNumber()
if first < 0 {
first = latest
}
if last < 0 || last > latest {
end = latest + 1
} else {
end = last + 1
}
for first < end {
for i := first; i < end; i++ {
if node.BlockTransactionCount(i) > 0 {
block := node.BlockByNumber(i)
for _, transaction := range block.Transactions {
if !transaction.Value.IsZero() {
src := transaction.From
dst := transaction.To
if len(set) == 0 || set[src] || set[dst] {
if json {
txs = append(txs, Transfer{src.Hex(), dst.Hex(), (*big.Int)(transaction.Value), i})
} else {
fmt.Printf("%v -> %v: %v (%v)\n", src.Hex(), dst.Hex(), transaction.Value, transaction.BlockNumber)
}
}
}
}
}
}
first = end
if last < 0 || last > end {
latest = node.BlockNumber()
if latest < last {
end = latest + 1
} else {
end = last + 1
}
}
}
if json {
util.PrintJson(txs)
}
}
func main() {
var (
commands = map[string]func(){
......@@ -512,6 +582,7 @@ func main() {
"status": status,
"block": block,
"snapshot": snapshot,
"transfers": transfers,
}
validCommands []string
command func()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment