arnaucube
arnaucube/goBlockchainDataAnalysisPublic Self-hosted repository
store transactions info (from, to, amount, txid)
arnaucode idoctnef@openmailbox.org
Sun, 23 Jul 2017 23:34:28 +0200
commit

826ec89716254153da103dbd98784a940bead041

parent

44d832f0ed5586048e8fed77193ae43828461a35

6 files changed, 81 insertions(+), 9 deletions(-)

jump to
M .gitignore → .gitignore

@@ -14,5 +14,6 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736

.glide/ -*.conf -*.json +/*.conf +/*.json +web
M exploreBlockchain.go → exploreBlockchain.go

@@ -16,18 +16,33 @@ check(err)

block, err := client.GetBlockVerbose(bh) 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]) check(err) tx, err := client.GetRawTransactionVerbose(th) check(err) - var totalFee float64 for _, Vo := range tx.Vout { totalFee = totalFee + Vo.Value } + newBlock.Fee = totalFee //for each Tx, get the Tx value 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 { //first Tx is the Fee //after first Tx is the Sent Amount

@@ -36,21 +51,37 @@ th, err := chainhash.NewHashFromStr(txHash)

check(err) tx, err := client.GetRawTransactionVerbose(th) 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 { 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 { - var newBlock BlockModel - newBlock.Hash = block.Hash - newBlock.Height = block.Height - newBlock.Confirmations = block.Confirmations newBlock.Amount = totalAmount - newBlock.Fee = totalFee saveBlock(blockCollection, newBlock) + fmt.Print("Height: ") fmt.Println(newBlock.Height) + fmt.Print("Amount: ") fmt.Println(newBlock.Amount) + fmt.Print("Fee: ") fmt.Println(newBlock.Fee) fmt.Println("-----") realBlocks++

@@ -58,6 +89,9 @@ }

//set the next block blockHash = block.NextHash + + //analyze block creator + } fmt.Print("realBlocks (blocks with Fee and Amount values): ") fmt.Println(realBlocks)
M instructions.md → instructions.md

@@ -16,7 +16,7 @@ rpcallowip=127.0.0.1

``` execute wallet: -./FairCoind -txindex -reindex-chainstate +./faircoind -txindex -reindex-chainstate ### Configure
M main.go → main.go

@@ -9,6 +9,8 @@ "github.com/btcsuite/btcrpcclient"

) var blockCollection *mgo.Collection +var nodeCollection *mgo.Collection +var edgeCollection *mgo.Collection func main() { //read goBlockchainDataAbalysis config

@@ -19,6 +21,8 @@ readMongodbConfig("./mongodbConfig.json")

session, err := getSession() check(err) blockCollection = getCollection(session, "blocks") + nodeCollection = getCollection(session, "nodes") + edgeCollection = getCollection(session, "edges") // create new client instance client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
M mongoModels.go → mongoModels.go

@@ -1,9 +1,32 @@

package main +type TxModel struct { + Txid string + From string + To string + Amount float64 +} type BlockModel struct { Hash string Height int64 Confirmations uint64 Amount float64 Fee float64 + Tx []TxModel +} + +type NodeModel struct { + Id string + Label string + Title string + Group string + Value int + Shape string +} + +type EdgeModel struct { + From string + To string + Label string + Arrows string }
M mongoOperations.go → mongoOperations.go

@@ -63,3 +63,13 @@ }

} } +func saveNode(c *mgo.Collection, block BlockModel) { + var node NodeModel + node.Id = block.Hash + node.Label = block.Hash + node.Title = block.Hash + node.Value = 1 + node.Shape = "dot" +} +func saveEdge(c *mgo.Collection, block BlockModel) { +}