/
index_appearance_record.go
50 lines (39 loc) · 1.13 KB
/
index_appearance_record.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
package index
import (
"encoding/binary"
"io"
)
const (
// AppRecordWidth - size of Appearance Record
AppRecordWidth = 8
)
// AppearanceRecord is a single record in the Appearance table
type AppearanceRecord struct {
BlockNumber uint32 `json:"blockNumber"`
TransactionIndex uint32 `json:"transactionIndex"`
}
func (chunk *Index) ReadAppearancesAndReset(addrRecord *AddressRecord) (apps []AppearanceRecord, err error) {
offset, err := chunk.File.Seek(0, io.SeekCurrent)
if err != nil {
return apps, err
}
apps, err = chunk.readAppearanceRecords(addrRecord)
if err != nil {
return apps, err
}
_, err = chunk.File.Seek(offset, io.SeekStart)
if err != nil {
return apps, err
}
return apps, nil
}
func (chunk *Index) readAppearanceRecords(addrRecord *AddressRecord) (apps []AppearanceRecord, err error) {
readLocation := int64(HeaderWidth + AddrRecordWidth*chunk.Header.AddressCount + AppRecordWidth*addrRecord.Offset)
_, err = chunk.File.Seek(readLocation, io.SeekStart)
if err != nil {
return
}
apps = make([]AppearanceRecord, addrRecord.Count)
err = binary.Read(chunk.File, binary.LittleEndian, &apps)
return
}