Skip to content

Commit 0504e24

Browse files
authored
Merge pull request #85 from darcys22/dev
Dev
2 parents 232dbe7 + 8f75d40 commit 0504e24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+124499
-661
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ release
4444
/build/cache/
4545
/build/bin/
4646
build/_vendor/pkg
47+
cert

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ VERSION ?= latest
33
PLATFORMS := linux
44
os = $(word 1, $@)
55

6+
GOBIN = ./build/bin GO ?= latest
7+
GORUN = env GO111MODULE=on go run
8+
69
.PHONY: $(PLATFORMS)
710
$(PLATFORMS):
811
mkdir -p release/$(BINARY)-$(os)-x64-v$(VERSION)/
@@ -14,7 +17,45 @@ release: linux
1417
PHONY: clean
1518
clean:
1619
rm -rf release/
20+
rm -rf cert/
1721

1822
travis:
1923
GO111MODULE=on go run utils/ci.go install
2024
GO111MODULE=on go run utils/ci.go test -coverage $$TEST_PACKAGES
25+
26+
linux-arm-7:
27+
mkdir -p release/$(BINARY)-arm7-v$(VERSION)/
28+
env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 GO111MODULE=on go build -o release/$(BINARY)-arm7-v$(VERSION)/ ./...
29+
30+
linux-arm-64:
31+
mkdir -p release/$(BINARY)-arm64-v$(VERSION)/
32+
env CC=aarch64-linux-gnu-gcc CXX=aarch-linux-gnu-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -o release/$(BINARY)-arm64-v$(VERSION)/ ./...
33+
34+
godbledger-linux-arm: godbledger-linux-arm-5 godbledger-linux-arm-6 godbledger-linux-arm-7 godbledger-linux-arm64
35+
@echo "Linux ARM cross compilation done:"
36+
@ls -ld $(GOBIN)/godbledger-linux-* | grep arm
37+
38+
godbledger-linux-arm-5:
39+
$(GORUN) utils/ci.go xgo -- --go=$(GO) --targets=linux/arm-5 -v ./..
40+
@echo "Linux ARMv5 cross compilation done:"
41+
@ls -ld $(GOBIN)/godbledger-linux-* | grep arm-5
42+
43+
godbledger-linux-arm-6:
44+
$(GORUN) utils/ci.go xgo -- --go=$(GO) --targets=linux/arm-6 -v ./godbledger
45+
@echo "Linux ARMv6 cross compilation done:"
46+
@ls -ld $(GOBIN)/godbledger-linux-* | grep arm-6
47+
48+
godbledger-linux-arm-7:
49+
$(GORUN) utils/ci.go xgo -- --go=$(GO) --targets=linux/arm-7 -v ./godbledger
50+
@echo "Linux ARMv7 cross compilation done:"
51+
@ls -ld $(GOBIN)/godbledger-linux-* | grep arm-7
52+
53+
godbledger-linux-arm64:
54+
$(GORUN) utils/ci.go xgo -- --go=$(GO) --targets=linux/arm64 -v ./godbledger
55+
@echo "Linux ARM64 cross compilation done:"
56+
@ls -ld $(GOBIN)/godbledger-linux-* | grep arm64
57+
58+
.PHONY: cert
59+
cert:
60+
mkdir -p cert/
61+
cd cert; ../utils/gen.sh; cd ..

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ SELECT * FROM accounts where account_id in (select account_id from account_tag w
8686

8787
### TODO
8888
- Create Yurnell - programmable journal entries
89-
- run GoDBLedger on a separate server and access the open port through the network
89+
- Create GUI - https://github.com/darcys22/GoDBLedger-Journal-Viewer-MacOS

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ require (
77
github.com/cespare/cp v1.1.1 // indirect
88
github.com/ethereum/go-ethereum v1.9.15
99
github.com/go-sql-driver/mysql v1.5.0
10+
github.com/gogo/protobuf v1.1.1
1011
github.com/golang/protobuf v1.4.2
12+
github.com/gophers/xgo v0.0.0-20200104073656-1317f74b9001 // indirect
1113
github.com/joyt/godate v0.0.0-20150226210126-7151572574a7
14+
github.com/karalabe/xgo v0.0.0-20191115072854-c5ccff8648a7 // indirect
1215
github.com/marcmak/calc v0.0.0-20150509200512-5bbbfc3b3149
1316
github.com/mattn/go-colorable v0.1.7
1417
github.com/mattn/go-sqlite3 v2.0.3+incompatible
@@ -20,4 +23,5 @@ require (
2023
github.com/urfave/cli/v2 v2.2.0
2124
github.com/x-cray/logrus-prefixed-formatter v0.5.2
2225
google.golang.org/grpc v1.30.0
26+
src.techknowlogick.com/xgo v1.0.1-0.20200717030703-5c3bb7fc435e // indirect
2327
)

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq
6161
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
6262
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
6363
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
64+
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
6465
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
6566
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
6667
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
@@ -80,6 +81,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
8081
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
8182
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
8283
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
84+
github.com/gophers/xgo v0.0.0-20200104073656-1317f74b9001 h1:5UcJnp2/fZ9MGc8O9Tb3mBXr+WMd2hUpdlfFWv90MaU=
85+
github.com/gophers/xgo v0.0.0-20200104073656-1317f74b9001/go.mod h1:HENK69XtUT+Fbtp4t7ijgCw8c5khHVOuzzzZcKGC57A=
8386
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
8487
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
8588
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
@@ -93,6 +96,8 @@ github.com/joyt/godate v0.0.0-20150226210126-7151572574a7 h1:2wH5antjhmU3EuWyidm
9396
github.com/joyt/godate v0.0.0-20150226210126-7151572574a7/go.mod h1:R+UgFL3iylLhx9N4w35zZ2HdhDlgorRDx4SxbchWuN0=
9497
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
9598
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
99+
github.com/karalabe/xgo v0.0.0-20191115072854-c5ccff8648a7 h1:AYzjK/SHz6m6mg5iuFwkrAhCc14jvCpW9d6frC9iDPE=
100+
github.com/karalabe/xgo v0.0.0-20191115072854-c5ccff8648a7/go.mod h1:iYGcTYIPUvEWhFo6aKUuLchs+AV4ssYdyuBbQJZGcBk=
96101
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
97102
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
98103
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -248,3 +253,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
248253
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
249254
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
250255
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
256+
src.techknowlogick.com/xgo v1.0.1-0.20200717030703-5c3bb7fc435e h1:cNlfcCyMwIq/KyKPgpuPohdDr9EjtxX0b44sGYSV2Ic=
257+
src.techknowlogick.com/xgo v1.0.1-0.20200717030703-5c3bb7fc435e/go.mod h1:31CE1YKtDOrKTk9PSnjTpe6YbO6W/0LTYZ1VskL09oU=

godbledger/cmd/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88

99
"github.com/BurntSushi/toml"
10-
//"github.com/urfave/cli"
1110
"github.com/urfave/cli/v2"
1211

1312
"github.com/sirupsen/logrus"
@@ -16,7 +15,11 @@ import (
1615
var log = logrus.WithField("prefix", "Config")
1716

1817
type LedgerConfig struct {
18+
Host string // Host defines the address that the RPC will be opened on. Combined with RPC Port
1919
RPCPort string // RPCPort defines the port that the server will listen for transactions on
20+
CACert string // CACertFlag defines a flag for the server's Certificate Authority certificate.
21+
Cert string // CertFlag defines a flag for the server's TLS certificate.
22+
Key string // KeyFlag defines a flag for the server's TLS key.
2023
DataDirectory string // DataDirectory defines the host systems folder directory holding the database and config files
2124
LogVerbosity string // LogVerbosity defines the logging level {debug, info, warn, error, fatal, panic}
2225
ConfigFile string // Location of the TOML config file, including directory path
@@ -50,6 +53,7 @@ var (
5053
}
5154

5255
defaultLedgerConfig = &LedgerConfig{
56+
Host: "127.0.0.1",
5357
RPCPort: "50051",
5458
DataDirectory: DefaultDataDir(),
5559
LogVerbosity: "debug",
@@ -61,7 +65,6 @@ var (
6165

6266
func MakeConfig(cli *cli.Context) (error, *LedgerConfig) {
6367

64-
log.Infof("Setting up configuration")
6568
config := defaultLedgerConfig
6669
//set logrus verbosity
6770
level, err := logrus.ParseLevel(config.LogVerbosity)
@@ -73,8 +76,6 @@ func MakeConfig(cli *cli.Context) (error, *LedgerConfig) {
7376
if len(cli.String("config")) > 0 {
7477
config.ConfigFile = cli.String("config")
7578
}
76-
77-
log.Debugf("Filepath to config file: %s", config.ConfigFile)
7879
err = InitConfig(config)
7980
if err != nil {
8081
log.Debugf("Error initialising config: %s", err)
@@ -96,14 +97,15 @@ func MakeConfig(cli *cli.Context) (error, *LedgerConfig) {
9697
return err, nil
9798
}
9899
logrus.SetLevel(level)
100+
log.WithField("Config File", config.ConfigFile).Debug("Configuration Successfully loaded")
99101

100102
return nil, config
101103
}
102104

103105
func InitConfig(config *LedgerConfig) error {
104106
_, err := os.Stat(config.ConfigFile)
105107
if os.IsNotExist(err) {
106-
log.Infof("Config File doesn't exist creating at %s", config.ConfigFile)
108+
log.Debugf("Config File doesn't exist creating at %s", config.ConfigFile)
107109
os.MkdirAll(filepath.Dir(config.ConfigFile), os.ModePerm)
108110
buf := new(bytes.Buffer)
109111
if err := toml.NewEncoder(buf).Encode(config); err != nil {

godbledger/cmd/flags.go

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"runtime"
99

10-
//"github.com/urfave/cli"
1110
"github.com/urfave/cli/v2"
1211
)
1312

@@ -59,6 +58,46 @@ var (
5958
Name: "config",
6059
Usage: "TOML configuration file",
6160
}
61+
// RPCHost defines the host on which the RPC server should listen.
62+
RPCHost = &cli.StringFlag{
63+
Name: "rpc-host",
64+
Usage: "Host on which the RPC server should listen",
65+
}
66+
// RPCPort defines a beacon node RPC port to open.
67+
RPCPort = &cli.StringFlag{
68+
Name: "rpc-port",
69+
Usage: "RPC port exposed by GoDBLedger",
70+
}
71+
// CertFlag defines a flag for the node's TLS CA certificate.
72+
CACertFlag = &cli.StringFlag{
73+
Name: "ca-cert",
74+
Usage: "Certificate Authority certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
75+
}
76+
// CertFlag defines a flag for the node's TLS certificate.
77+
CertFlag = &cli.StringFlag{
78+
Name: "tls-cert",
79+
Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
80+
}
81+
// KeyFlag defines a flag for the node's TLS key.
82+
KeyFlag = &cli.StringFlag{
83+
Name: "tls-key",
84+
Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.",
85+
}
86+
// LogFileName specifies the log output file name.
87+
LogFileName = &cli.StringFlag{
88+
Name: "log-file",
89+
Usage: "Specify log file name, relative or absolute",
90+
}
91+
// DatabaseType specifies the backend for GoDBLedger
92+
DatabaseTypeFlag = &cli.StringFlag{
93+
Name: "database",
94+
Usage: "Specify database type, sqlite3 or mysql",
95+
}
96+
// DatabaseLocation specifies file location for Sqlite or connection string for MySQL
97+
DatabaseLocationFlag = &cli.StringFlag{
98+
Name: "database-location",
99+
Usage: "location of database file or connection string",
100+
}
62101
)
63102

64103
func setConfig(ctx *cli.Context, cfg *LedgerConfig) {
@@ -72,4 +111,25 @@ func setConfig(ctx *cli.Context, cfg *LedgerConfig) {
72111
if ctx.IsSet(DataDirFlag.Name) {
73112
cfg.ConfigFile = ctx.String(DataDirFlag.Name)
74113
}
114+
if ctx.IsSet(RPCHost.Name) {
115+
cfg.Host = ctx.String(RPCHost.Name)
116+
}
117+
if ctx.IsSet(RPCPort.Name) {
118+
cfg.RPCPort = ctx.String(RPCPort.Name)
119+
}
120+
if ctx.IsSet(CACertFlag.Name) {
121+
cfg.CACert = ctx.String(CACertFlag.Name)
122+
}
123+
if ctx.IsSet(CertFlag.Name) {
124+
cfg.Cert = ctx.String(CertFlag.Name)
125+
}
126+
if ctx.IsSet(KeyFlag.Name) {
127+
cfg.Key = ctx.String(KeyFlag.Name)
128+
}
129+
if ctx.IsSet(DatabaseTypeFlag.Name) {
130+
cfg.DatabaseType = ctx.String(DatabaseTypeFlag.Name)
131+
}
132+
if ctx.IsSet(DatabaseLocationFlag.Name) {
133+
cfg.DatabaseLocation = ctx.String(DatabaseLocationFlag.Name)
134+
}
75135
}

godbledger/cmd/logutil.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"io"
5+
"os"
6+
7+
"github.com/sirupsen/logrus"
8+
)
9+
10+
// ConfigurePersistentLogging adds a log-to-file writer. File content is identical to stdout.
11+
func ConfigurePersistentLogging(logFileName string) error {
12+
logrus.WithField("logFileName", logFileName).Info("Logs will be made persistent")
13+
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
14+
if err != nil {
15+
return err
16+
}
17+
18+
mw := io.MultiWriter(os.Stdout, f)
19+
logrus.SetOutput(mw)
20+
21+
logrus.Info("File logging initialized")
22+
return nil
23+
}

godbledger/db/database.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ type Database interface {
3434
AddUser(usr *core.User) error
3535
SafeAddUser(usr *core.User) error
3636
GetTB(date time.Time) (*[]core.TBAccount, error)
37+
GetListing(startdate, enddate time.Time) (*[]core.Transaction, error)
3738
Query(query string, args ...interface{}) (*sql.Rows, error)
3839
}

0 commit comments

Comments
 (0)