@@ -14,7 +14,7 @@ import (
14
14
"github.com/opheelia/blockchainbeat/config"
15
15
)
16
16
17
- var number_of_blocks = 500
17
+ var number_of_blocks = 2
18
18
19
19
// Blockchainbeat configuration.
20
20
type Blockchainbeat struct {
@@ -102,23 +102,39 @@ func GetBlockTransaction(result interface{}, block_number int) {
102
102
func SendBlockTransactionsToElastic (last_block int , b * beat.Beat , bt * Blockchainbeat , counter int ){
103
103
//Get block transactions up to last block number
104
104
105
- for index := last_block - number_of_blocks ; index <= last_block ; index ++ {
105
+ for index := last_block - number_of_blocks + 1 ; index <= last_block ; index ++ {
106
106
logp .Info (fmt .Sprint (index ))
107
107
var result map [string ]interface {}
108
108
GetBlockTransaction (& result , index )
109
109
logp .Info (fmt .Sprintf ("Transaction for block %v" , index ))
110
110
logp .Info (fmt .Sprint (result ))
111
111
112
+ // Parse timeStamp field to get a date
113
+ data := result ["result" ].(map [string ]interface {})
114
+ block_date := getBlockTimeFormat (data ["timeStamp" ].(string ))
115
+ logp .Info (fmt .Sprintf ("New time is %v, %T" , block_date , block_date ))
112
116
event := beat.Event {
113
117
Timestamp : time .Now (),
114
118
Fields : common.MapStr {
115
119
"type" : b .Info .Name ,
116
120
"counter" : counter ,
117
- "message" : result ,
121
+ "message" : result ["message" ],
122
+ "blockNumber" : data ["blockNumber" ],
123
+ "blockTime" : block_date ,
124
+ "blockMiner" : data ["blockMiner" ],
118
125
},
119
126
}
120
127
bt .client .Publish (event )
121
128
logp .Info ("Event sent" )
122
129
}
130
+ }
123
131
132
+ func getBlockTimeFormat (timestamp string ) (time.Time ) {
133
+ i , err := strconv .ParseInt (timestamp , 10 , 64 )
134
+ if err != nil {
135
+ logp .Info (fmt .Sprint ("Timestamp cannot be parsed" ))
136
+ }
137
+ //logp.Info(fmt.Sprintf("Before parsing %v is a %T", i, i))
138
+ tm := time .Unix (i ,0 )
139
+ return tm
124
140
}
0 commit comments