-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.go
65 lines (50 loc) · 1.58 KB
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package validators
import (
"time"
"github.com/archway-network/cosmologger/database"
)
func DBRowToValidatorRecord(row database.RowType) ValidatorRecord {
if row == nil {
return ValidatorRecord{}
}
moniker := ""
if row[database.FIELD_VALIDATORS_MONIKER] != nil {
moniker = row[database.FIELD_VALIDATORS_MONIKER].(string)
}
return ValidatorRecord{
ConsAddr: row[database.FIELD_VALIDATORS_CONS_ADDR].(string),
OprAddr: row[database.FIELD_VALIDATORS_OPR_ADDR].(string),
AccAddr: row[database.FIELD_VALIDATORS_ACCOUNT_ADDR].(string),
Moniker: moniker,
}
}
func DBRowToValidatorRecords(row []database.RowType) []ValidatorRecord {
var res []ValidatorRecord
for i := range row {
res = append(res, DBRowToValidatorRecord(row[i]))
}
return res
}
func DBRowToValidatorWithTx(row database.RowType) ValidatorWithTx {
if row == nil {
return ValidatorWithTx{}
}
return ValidatorWithTx{
ValidatorRecord: ValidatorRecord{
ConsAddr: row[database.FIELD_VALIDATORS_CONS_ADDR].(string),
OprAddr: row[database.FIELD_VALIDATORS_OPR_ADDR].(string),
AccAddr: row[database.FIELD_VALIDATORS_ACCOUNT_ADDR].(string),
},
TxHash: string(row[database.FIELD_TX_EVENTS_TX_HASH].([]uint8)), //char
Height: uint64(row[database.FIELD_TX_EVENTS_HEIGHT].(int64)),
Sender: row[database.FIELD_TX_EVENTS_SENDER].(string),
LogTime: row[database.FIELD_TX_EVENTS_LOG_TIME].(time.Time),
}
}
func DBRowToValidatorWithTxs(row []database.RowType) []ValidatorWithTx {
var res []ValidatorWithTx
for i := range row {
res = append(res, DBRowToValidatorWithTx(row[i]))
}
return res
}