-
Notifications
You must be signed in to change notification settings - Fork 646
/
context.go
71 lines (62 loc) · 1.89 KB
/
context.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
68
69
70
71
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snow
import (
"io"
"net/http"
"sync"
"github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/triggers"
"github.com/ava-labs/gecko/utils/logging"
)
// Callable ...
type Callable interface {
Call(writer http.ResponseWriter, method, base, endpoint string, body io.Reader, headers map[string]string) error
}
// Keystore ...
type Keystore interface {
GetDatabase(username, password string) (database.Database, error)
}
// SharedMemory ...
type SharedMemory interface {
GetDatabase(id ids.ID) database.Database
ReleaseDatabase(id ids.ID)
}
// AliasLookup ...
type AliasLookup interface {
Lookup(alias string) (ids.ID, error)
PrimaryAlias(id ids.ID) (string, error)
}
// Context is information about the current execution.
// [NetworkID] is the ID of the network this context exists within.
// [ChainID] is the ID of the chain this context exists within.
// [NodeID] is the ID of this node
type Context struct {
NetworkID uint32
ChainID ids.ID
NodeID ids.ShortID
Log logging.Logger
DecisionDispatcher *triggers.EventDispatcher
ConsensusDispatcher *triggers.EventDispatcher
Lock sync.RWMutex
HTTP Callable
Keystore Keystore
SharedMemory SharedMemory
BCLookup AliasLookup
}
// DefaultContextTest ...
func DefaultContextTest() *Context {
decisionED := triggers.EventDispatcher{}
decisionED.Initialize(logging.NoLog{})
consensusED := triggers.EventDispatcher{}
consensusED.Initialize(logging.NoLog{})
return &Context{
ChainID: ids.Empty,
NodeID: ids.ShortEmpty,
Log: logging.NoLog{},
DecisionDispatcher: &decisionED,
ConsensusDispatcher: &consensusED,
BCLookup: &ids.Aliaser{},
}
}