-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbInfo.go
34 lines (29 loc) · 857 Bytes
/
dbInfo.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
package testHelper
import (
"github.com/DCNT-developer/dcnt/common/directoryBlock/dbInfo"
)
func CreateTestDirBlockInfo(prev *dbInfo.DirBlockInfo) *dbInfo.DirBlockInfo {
dbi := dbInfo.NewDirBlockInfo()
if prev == nil {
dbi.DBHeight = 0
} else {
dbi.DBHeight = prev.DBHeight + 1
}
height := dbi.DBHeight
dbi.DBHash.UnmarshalBinary(IntToByteSlice(int(height)))
dbi.Timestamp = int64(height)
dbi.BTCTxHash.UnmarshalBinary(IntToByteSlice(int(height)))
dbi.BTCTxOffset = int32(int(height))
dbi.BTCBlockHeight = int32(height)
dbi.BTCBlockHash.UnmarshalBinary(IntToByteSlice(255 - int(height)))
dbi.DBMerkleRoot.UnmarshalBinary(IntToByteSlice(255 - int(height)))
dbi.BTCConfirmed = height%2 == 1
return dbi
}
func IntToByteSlice(n int) []byte {
answer := make([]byte, 32)
for i := range answer {
answer[i] = byte(n)
}
return answer
}