This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
/
loader.go
97 lines (76 loc) · 2.6 KB
/
loader.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
package main
import (
"log"
"os"
"time"
"github.com/pkg/errors"
erpc "github.com/Varunram/essentials/rpc"
wallet "github.com/Varunram/essentials/xlm/wallet"
)
// StartTeller starts the teller
func StartTeller() error {
var err error
client = erpc.SetupLocalHttpsClient(os.Getenv("HOME")+"/go/src/github.com/YaleOpenLab/opensolar/server.crt", 60*time.Second)
err = login(loginUsername, loginPwhash)
if err != nil {
return errors.Wrap(err, "Error while logging on to the platform")
}
LocalProject, err = getLocalProjectDetails(loginProjIndex)
if err != nil {
return errors.Wrap(err, "couldn't get local project details")
}
if LocalProject.Index == 0 {
return errors.New("couldn't retrieve project from the database, quitting")
}
projIndex, err := getProjectIndex(AssetName)
if err != nil {
return errors.Wrap(err, "couldn't get project index")
}
if projIndex != LocalProject.Index {
log.Println("Project indices don't match, quitting!")
return errors.New("project indices don't match, quitting")
}
go refreshLogin(loginUsername, loginPwhash) // update local copy of the recipient every 5 minutes
go readEnergyData()
seed, err := wallet.DecryptSeed(LocalRecipient.U.StellarWallet.EncryptedSeed, LocalSeedPwd)
if err != nil {
return errors.Wrap(err, "Error while decrypting seed")
}
pubkey, err := wallet.ReturnPubkey(seed)
if err != nil {
return errors.Wrap(err, "Error while returning publickey")
}
if pubkey != LocalRecipient.U.StellarWallet.PublicKey {
log.Println("PUBLIC KEYS DON'T MATCH, QUITTING!")
return errors.New("public keys don't match, quitting")
}
if LocalProject.Stage < 4 {
log.Println("TRYING TO INSTALL A PROJECT THAT HASN'T BEEN FUNDED YET, QUITTING!")
return errors.New("trying to install a project that hasn't been funded yet, quitting")
}
// check for device id and set if none is set
err = checkDeviceID()
if err != nil {
return errors.Wrap(err, "could not check device id")
}
DeviceId, err = getDeviceID() // Stores DeviceId
if err != nil {
return errors.Wrap(err, "could not get device id from local storage")
}
err = storeStartTime()
if err != nil {
return errors.Wrap(err, "could not store start time locally")
}
// store location at the start because if a person changes location, it is likely that the
// teller goes offline and we get notified
err = storeLocation(Mapskey) // stores DeviceLocation
if err != nil {
colorOutput(RedColor, "could not store location of teller")
}
err = getPlatformEmail()
if err != nil {
return errors.Wrap(err, "could not store platform email")
}
DeviceInfo = "Raspberry Pi3 Model B+"
return nil
}