-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
114 lines (93 loc) · 2.75 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"math/big"
"github.com/Open-Material/open-material/crypto"
"github.com/Open-Material/open-material/database"
"github.com/Open-Material/open-material/proposal"
"github.com/Open-Material/open-material/utils"
badger "github.com/dgraph-io/badger/v3"
)
func main() {
//signProposal()
//tryDatabase()
signAddDb()
}
func signAddDb() {
walletKeyStore, _ := crypto.ReadFromKeyStoreFile()
proposalWithoutSig := proposal.Proposal{
Nonce: 1,
Proposer: &walletKeyStore.Address,
Title: "Test",
Pos: new(big.Int).SetInt64(1),
Height: new(big.Int).SetInt64(12),
FWHMLeft: new(big.Int).SetInt64(35),
DSpacing: new(big.Int).SetInt64(19),
RelIntensity: new(big.Int).SetInt64(100),
}
parsedPriv, err := crypto.ToECDSA(walletKeyStore.PrivateKey)
if err != nil {
fmt.Println("Error parsing private key")
}
signedProposal, err := proposal.SignProposal(&proposalWithoutSig, parsedPriv)
if err != nil {
fmt.Println("Error signing proposal")
}
rlpWithSig, _ := utils.EncodeProposalWithSig(signedProposal)
fmt.Println(rlpWithSig)
handleDatabase([]byte("Cu2S"), rlpWithSig)
}
func handleDatabase(name []byte, proposal []byte) {
opts := badger.DefaultOptions("/tmp/badger")
opts = opts.WithLogger(nil)
db, err := badger.Open(opts)
if err != nil {
fmt.Println(err)
}
defer db.Close()
localdb := database.Database{Db: db}
//localdb.View(name)
localdb.Write(name, proposal)
value := localdb.View(name)
fmt.Println(value)
fmt.Println("Rlp decoded")
}
func createNewWallet() {
wallet := crypto.NewWallet()
fmt.Println(*wallet)
//fmt.Println(crypto.KeyStoreDirExists())
if !crypto.KeyStoreDirExists() {
crypto.CreateKeyStoreDir()
}
crypto.CreateKeyStoreFile(wallet)
}
func signProposal() {
walletFromKeyStore, _ := crypto.ReadFromKeyStoreFile()
fmt.Println(*walletFromKeyStore)
proposalWithoutSig := proposal.Proposal{
Nonce: 1,
Proposer: &walletFromKeyStore.Address,
Title: "Test",
Pos: new(big.Int).SetInt64(1),
Height: new(big.Int).SetInt64(12),
FWHMLeft: new(big.Int).SetInt64(35),
DSpacing: new(big.Int).SetInt64(19),
RelIntensity: new(big.Int).SetInt64(100),
}
rlp, err := utils.EncodeProposal(&proposalWithoutSig)
if err != nil {
fmt.Println("Error encoding RLP")
}
fmt.Println("RLP Encoded", rlp)
//fmt.Println("Hash of the proposal", proposalWithoutSig.Hash())
parsedPriv, err := crypto.ToECDSA(walletFromKeyStore.PrivateKey)
if err != nil {
fmt.Println("Error parsing private key")
}
signedProposal, err := proposal.SignProposal(&proposalWithoutSig, parsedPriv)
if err != nil {
fmt.Println("Error signing proposal")
}
fmt.Printf("%+v\n", *signedProposal)
fmt.Println(proposal.ValidateProposal(signedProposal))
}