|
@ -16,18 +16,33 @@ func explore(client *btcrpcclient.Client, blockHash string) { |
|
|
block, err := client.GetBlockVerbose(bh) |
|
|
block, err := client.GetBlockVerbose(bh) |
|
|
check(err) |
|
|
check(err) |
|
|
|
|
|
|
|
|
|
|
|
var newBlock BlockModel |
|
|
|
|
|
newBlock.Hash = block.Hash |
|
|
|
|
|
newBlock.Height = block.Height |
|
|
|
|
|
newBlock.Confirmations = block.Confirmations |
|
|
|
|
|
|
|
|
|
|
|
//get Fee value
|
|
|
th, err := chainhash.NewHashFromStr(block.Tx[0]) |
|
|
th, err := chainhash.NewHashFromStr(block.Tx[0]) |
|
|
check(err) |
|
|
check(err) |
|
|
tx, err := client.GetRawTransactionVerbose(th) |
|
|
tx, err := client.GetRawTransactionVerbose(th) |
|
|
check(err) |
|
|
check(err) |
|
|
|
|
|
|
|
|
var totalFee float64 |
|
|
var totalFee float64 |
|
|
for _, Vo := range tx.Vout { |
|
|
for _, Vo := range tx.Vout { |
|
|
totalFee = totalFee + Vo.Value |
|
|
totalFee = totalFee + Vo.Value |
|
|
} |
|
|
} |
|
|
|
|
|
newBlock.Fee = totalFee |
|
|
|
|
|
|
|
|
//for each Tx, get the Tx value
|
|
|
//for each Tx, get the Tx value
|
|
|
var totalAmount float64 |
|
|
var totalAmount float64 |
|
|
|
|
|
/*inside each block, there are []Tx |
|
|
|
|
|
inside each Tx, if is the Tx[0], is the Fees |
|
|
|
|
|
in the Tx[n] where n>0, each Tx is independent, |
|
|
|
|
|
and inside each Tx there are []Vout. |
|
|
|
|
|
Usually Vout[0] is the real Tx value |
|
|
|
|
|
and the Vout[1] is the rest of the amount in the original wallet. |
|
|
|
|
|
Each Tx moves all the wallet amount, and the realTx amount is sent to the destination |
|
|
|
|
|
and the rest of the wallet amount, is send to another owned wallet |
|
|
|
|
|
*/ |
|
|
for k, txHash := range block.Tx { |
|
|
for k, txHash := range block.Tx { |
|
|
//first Tx is the Fee
|
|
|
//first Tx is the Fee
|
|
|
//after first Tx is the Sent Amount
|
|
|
//after first Tx is the Sent Amount
|
|
@ -36,21 +51,37 @@ func explore(client *btcrpcclient.Client, blockHash string) { |
|
|
check(err) |
|
|
check(err) |
|
|
tx, err := client.GetRawTransactionVerbose(th) |
|
|
tx, err := client.GetRawTransactionVerbose(th) |
|
|
check(err) |
|
|
check(err) |
|
|
|
|
|
var originAddress string |
|
|
|
|
|
for _, Vi := range tx.Vin { |
|
|
|
|
|
th, err := chainhash.NewHashFromStr(Vi.Txid) |
|
|
|
|
|
check(err) |
|
|
|
|
|
txVi, err := client.GetRawTransactionVerbose(th) |
|
|
|
|
|
check(err) |
|
|
|
|
|
if len(txVi.Vout[0].ScriptPubKey.Addresses) > 0 { |
|
|
|
|
|
originAddress = txVi.Vout[0].ScriptPubKey.Addresses[0] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
for _, Vo := range tx.Vout { |
|
|
for _, Vo := range tx.Vout { |
|
|
totalAmount = totalAmount + Vo.Value |
|
|
totalAmount = totalAmount + Vo.Value |
|
|
|
|
|
|
|
|
|
|
|
var blockTx TxModel |
|
|
|
|
|
blockTx.Txid = tx.Txid |
|
|
|
|
|
blockTx.Amount = Vo.Value |
|
|
|
|
|
blockTx.From = originAddress |
|
|
|
|
|
blockTx.To = Vo.ScriptPubKey.Addresses[0] |
|
|
|
|
|
newBlock.Tx = append(newBlock.Tx, blockTx) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if totalAmount > 0 { |
|
|
if totalAmount > 0 { |
|
|
var newBlock BlockModel |
|
|
|
|
|
newBlock.Hash = block.Hash |
|
|
|
|
|
newBlock.Height = block.Height |
|
|
|
|
|
newBlock.Confirmations = block.Confirmations |
|
|
|
|
|
newBlock.Amount = totalAmount |
|
|
newBlock.Amount = totalAmount |
|
|
newBlock.Fee = totalFee |
|
|
|
|
|
saveBlock(blockCollection, newBlock) |
|
|
saveBlock(blockCollection, newBlock) |
|
|
|
|
|
fmt.Print("Height: ") |
|
|
fmt.Println(newBlock.Height) |
|
|
fmt.Println(newBlock.Height) |
|
|
|
|
|
fmt.Print("Amount: ") |
|
|
fmt.Println(newBlock.Amount) |
|
|
fmt.Println(newBlock.Amount) |
|
|
|
|
|
fmt.Print("Fee: ") |
|
|
fmt.Println(newBlock.Fee) |
|
|
fmt.Println(newBlock.Fee) |
|
|
fmt.Println("-----") |
|
|
fmt.Println("-----") |
|
|
realBlocks++ |
|
|
realBlocks++ |
|
@ -58,6 +89,9 @@ func explore(client *btcrpcclient.Client, blockHash string) { |
|
|
|
|
|
|
|
|
//set the next block
|
|
|
//set the next block
|
|
|
blockHash = block.NextHash |
|
|
blockHash = block.NextHash |
|
|
|
|
|
|
|
|
|
|
|
//analyze block creator
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
fmt.Print("realBlocks (blocks with Fee and Amount values): ") |
|
|
fmt.Print("realBlocks (blocks with Fee and Amount values): ") |
|
|
fmt.Println(realBlocks) |
|
|
fmt.Println(realBlocks) |
|
|