-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
76 lines (65 loc) · 2.06 KB
/
store.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
72
73
74
75
76
// Apla Software includes an integrated development
// environment with a multi-level system for the management
// of access rights to data, interfaces, and Smart contracts. The
// technical characteristics of the Apla Software are indicated in
// Apla Technical Paper.
// Apla Users are granted a permission to deal in the Apla
// Software without restrictions, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of Apla Software, and to permit persons
// to whom Apla Software is furnished to do so, subject to the
// following conditions:
// * the copyright notice of GenesisKernel and EGAAS S.A.
// and this permission notice shall be included in all copies or
// substantial portions of the software;
// * a result of the dealing in Apla Software cannot be
// implemented outside of the Apla Platform environment.
// THE APLA SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY
// OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, ERROR FREE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
// THE USE OR OTHER DEALINGS IN THE APLA SOFTWARE.
package main
import (
"github.com/google/logger"
"github.com/recoilme/pudge"
)
const (
lastId = `lastID`
)
var (
store *pudge.Db
)
func StoreOpen() {
var err error
store, err = pudge.Open(cfg.StoreFile, &pudge.Config{
StoreMode: 0})
if err != nil {
logger.Fatal(err)
}
}
func StoreClose() {
pudge.CloseAll()
}
// LastID Returns the last block id in the previous start
func LastID() int64 {
var ret int64
store.Get(lastId, &ret)
return ret
}
func StoreBlock(block BlockInfo) {
store.Set(block.ID, block.Hash)
store.Set(lastId, block.ID)
}
func GetHash(id int64) []byte {
var hash []byte
err := store.Get(id, &hash)
if err != nil {
logger.Fatal(err)
}
return hash
}