Skip to content

Commit bb1a8cc

Browse files
committed
Sprint 2 is over
1 parent 825a6f0 commit bb1a8cc

File tree

5 files changed

+425
-1410
lines changed

5 files changed

+425
-1410
lines changed

_meta/fields.yml

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
required: true
88
description: >
99
PLEASE UPDATE DOCUMENTATION
10+
- name: blockTime
11+
type: date
12+
required: true
13+
description: >

beater/blockchainbeat.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/opheelia/blockchainbeat/config"
1515
)
1616

17-
var number_of_blocks = 500
17+
var number_of_blocks = 2
1818

1919
// Blockchainbeat configuration.
2020
type Blockchainbeat struct {
@@ -102,23 +102,39 @@ func GetBlockTransaction(result interface{}, block_number int) {
102102
func SendBlockTransactionsToElastic(last_block int, b *beat.Beat, bt *Blockchainbeat, counter int){
103103
//Get block transactions up to last block number
104104

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++ {
106106
logp.Info(fmt.Sprint(index))
107107
var result map[string]interface{}
108108
GetBlockTransaction(&result, index)
109109
logp.Info(fmt.Sprintf("Transaction for block %v", index))
110110
logp.Info(fmt.Sprint(result))
111111

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))
112116
event := beat.Event{
113117
Timestamp: time.Now(),
114118
Fields: common.MapStr{
115119
"type": b.Info.Name,
116120
"counter": counter,
117-
"message": result,
121+
"message": result["message"],
122+
"blockNumber": data["blockNumber"],
123+
"blockTime": block_date,
124+
"blockMiner": data["blockMiner"],
118125
},
119126
}
120127
bt.client.Publish(event)
121128
logp.Info("Event sent")
122129
}
130+
}
123131

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
124140
}

blockchainbeat.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
blockchainbeat:
66
# Defines how often an event is sent to the output
7-
period: 15s
7+
period: 1s
88

9+
setup.template.overwrite: true
910
#================================ General =====================================
1011

1112
# The name of the shipper that publishes the network data. It can be used to group

0 commit comments

Comments
 (0)