forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seek.go
67 lines (55 loc) · 1.77 KB
/
seek.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
66
67
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package seek
import (
"math"
ab "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/orderer"
)
// Type is the type of Seek request to perform.
type Type string
const (
// Oldest seeks from the first block
Oldest = "oldest"
// Newest seeks from the last block
Newest = "newest"
// FromBlock seeks from a specific block
FromBlock = "from"
)
var (
oldestPos = &ab.SeekPosition{Type: &ab.SeekPosition_Oldest{Oldest: &ab.SeekOldest{}}}
newestPos = &ab.SeekPosition{Type: &ab.SeekPosition_Newest{Newest: &ab.SeekNewest{}}}
maxPos = &ab.SeekPosition{Type: &ab.SeekPosition_Specified{Specified: &ab.SeekSpecified{Number: math.MaxUint64}}}
)
// InfoOldest returns a SeekInfo struct that indicates to the deliver server
// that we want all blocks starting from the oldest block (block 0)
func InfoOldest() *ab.SeekInfo {
return newSeekInfo(oldestPos, maxPos)
}
// InfoNewest returns a SeekInfo struct that indicates to the deliver server
// that we just want the latest blocks
func InfoNewest() *ab.SeekInfo {
return newSeekInfo(newestPos, maxPos)
}
// InfoFrom returns a SeekInfo struct that indicates to the deliver server
// that we want all blocks starting from the given block number
func InfoFrom(fromBlock uint64) *ab.SeekInfo {
return newSeekInfo(seekFromPos(fromBlock), maxPos)
}
func seekFromPos(fromBlock uint64) *ab.SeekPosition {
return &ab.SeekPosition{
Type: &ab.SeekPosition_Specified{
Specified: &ab.SeekSpecified{
Number: fromBlock,
},
},
}
}
func newSeekInfo(start *ab.SeekPosition, stop *ab.SeekPosition) *ab.SeekInfo {
return &ab.SeekInfo{
Start: start,
Stop: stop,
Behavior: ab.SeekInfo_BLOCK_UNTIL_READY,
}
}