-
Notifications
You must be signed in to change notification settings - Fork 127
/
queue.go
47 lines (43 loc) · 1.21 KB
/
queue.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
package kernel
import (
"github.com/MixinNetwork/mixin/common"
)
func (node *Node) QueueTransaction(tx *common.VersionedTransaction) (string, error) {
err := tx.Validate(node.persistStore)
if err != nil {
return "", err
}
err = node.persistStore.CachePutTransaction(tx)
if err != nil {
return "", err
}
chain := node.GetOrCreateChain(node.IdForNetwork)
s := &common.Snapshot{
Version: common.SnapshotVersion,
NodeId: node.IdForNetwork,
Transaction: tx.PayloadHash(),
}
err = chain.AppendSelfEmpty(s)
return tx.PayloadHash().String(), err
}
func (node *Node) LoadCacheToQueue() error {
chain := node.GetOrCreateChain(node.IdForNetwork)
return node.persistStore.CacheListTransactions(func(tx *common.VersionedTransaction) error {
s := &common.Snapshot{
Version: common.SnapshotVersion,
NodeId: node.IdForNetwork,
Transaction: tx.PayloadHash(),
}
return chain.AppendSelfEmpty(s)
})
}
func (chain *Chain) clearAndQueueSnapshotOrPanic(s *common.Snapshot) error {
if chain.ChainId != s.NodeId {
panic("should never be here")
}
return chain.AppendSelfEmpty(&common.Snapshot{
Version: common.SnapshotVersion,
NodeId: s.NodeId,
Transaction: s.Transaction,
})
}