Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 184 additions & 37 deletions README.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestFullClientApiCycle(t *testing.T) {
wallet.New)
err := issuer.ValidateApiVersion()
assert.Nil(t, err)
err = issuer.NewWallet("wpg6d0grqJjyRicC8oI0/w6IGivm5ypFNTO/wwPGW9A=")
err = issuer.NewWallet("G8OH7lHu5qfWVumWom0ySN29lakog8nhzSPEwROMjvhdI6VgZ6GoPcdJmoIo7sF3lxQNJMOTKxpYBr6zF992WN86uB7xTEJZ")
assert.Nil(t, err)

receiver := NewClient(
Expand All @@ -72,7 +72,7 @@ func TestFullClientApiCycle(t *testing.T) {
wallet.New)
err = receiver.ValidateApiVersion()
assert.Nil(t, err)
err = receiver.NewWallet("GWFuhvyFnmMg1/vhPCfoa9ct1pAMC1pWwlRg4kt0D/w=")
err = receiver.NewWallet("jykkeD6Tr6xikkYwC805kVoFThm8VGEHStTFk1lIU6RgEf7p3vjFpPQFI3VP9SYeARjYh2jecMSYsmgddjZZcy32iySHijJQ")
assert.Nil(t, err)

receiverAddr, err := receiver.Address()
Expand All @@ -89,6 +89,9 @@ func TestFullClientApiCycle(t *testing.T) {

err = receiver.ConfirmTransaction(&awaitedTrx[0])
assert.Nil(t, err)
if err != nil {
fmt.Printf("err: %v\n", err.Error())
}

issuer.FlushWalletFromMemory()
receiver.FlushWalletFromMemory()
Expand Down
3 changes: 1 addition & 2 deletions cmd/central/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/bartossh/Computantis/dataprovider"
"github.com/bartossh/Computantis/logging"
"github.com/bartossh/Computantis/reactive"
"github.com/bartossh/Computantis/repomongo"
"github.com/bartossh/Computantis/server"
"github.com/bartossh/Computantis/wallet"
)
Expand All @@ -39,7 +38,7 @@ func main() {
cancel()
}()

db, err := repomongo.Connect(ctx, cfg.Database)
db, err := cfg.Database.Connect(ctx)
if err != nil {
fmt.Println(err)
c <- os.Interrupt
Expand Down
3 changes: 1 addition & 2 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/bartossh/Computantis/configuration"
"github.com/bartossh/Computantis/fileoperations"
"github.com/bartossh/Computantis/logging"
"github.com/bartossh/Computantis/repomongo"
"github.com/bartossh/Computantis/validator"
"github.com/bartossh/Computantis/wallet"
"github.com/bartossh/Computantis/webhooks"
Expand All @@ -30,7 +29,7 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

db, err := repomongo.Connect(ctx, cfg.Database)
db, err := cfg.Database.Connect(ctx)
if err != nil {
fmt.Println(err)
c <- os.Interrupt
Expand Down
11 changes: 2 additions & 9 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@ import (
"github.com/bartossh/Computantis/bookkeeping"
"github.com/bartossh/Computantis/dataprovider"
"github.com/bartossh/Computantis/fileoperations"
"github.com/bartossh/Computantis/repohelper"
"github.com/bartossh/Computantis/server"
"github.com/bartossh/Computantis/validator"
"gopkg.in/yaml.v2"
)

// Config contains configuration for the database.
type DBConfig struct {
ConnStr string `yaml:"conn_str"` // ConnStr is the connection string to the database.
DatabaseName string `yaml:"database_name"` // DatabaseName is the name of the database.
Token string `yaml:"token"` // Token is the token that is used to confirm api clients access.
TokenExpire int64 `yaml:"token_expiration"` // TokenExpire is the number of seconds after which token expires.
}

// Configuration is the main configuration of the application that corresponds to the *.yaml file
// that holds the configuration.
type Configuration struct {
Bookkeeper bookkeeping.Config `yaml:"bookkeeper"`
Server server.Config `yaml:"server"`
Database DBConfig `yaml:"database"`
Database repohelper.DBConfig `yaml:"database"`
DataProvider dataprovider.Config `yaml:"data_provider"`
Validator validator.Config `yaml:"validator"`
FileOperator fileoperations.Config `yaml:"file_operator"`
Expand Down
22 changes: 14 additions & 8 deletions docker_postgres_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ CREATE DATABASE computantis
TABLESPACE = pg_default
CONNECTION LIMIT = -1;

CREATE USER computantis WITH PASSWORD 'computantis';

GRANT ALL PRIVILEGES ON DATABASE computantis TO computantis;
\c computantis

CREATE TABLE IF NOT EXISTS addresses (
id serial PRIMARY KEY,
Expand Down Expand Up @@ -67,8 +65,8 @@ CREATE INDEX transaction_awaiting_receiver_address ON transactionsAwaitingReceiv

CREATE TABLE IF NOT EXISTS blocks (
id serial PRIMARY KEY,
index INTEGER UNIQUE NOT NULL,
created_at INTEGER NOT NULL,
index BIGINT UNIQUE NOT NULL,
timestamp BIGINT NOT NULL,
nonce INTEGER NOT NULL,
difficulty INTEGER NOT NULL,
hash BYTEA UNIQUE NOT NULL,
Expand All @@ -79,7 +77,7 @@ CREATE TABLE IF NOT EXISTS blocks (
CREATE INDEX block_index ON blocks USING HASH (index);
CREATE INDEX block_hash ON blocks USING HASH (hash);
CREATE INDEX block_prev_hash ON blocks USING HASH (prev_hash);
CREATE INDEX block_created_at ON blocks USING BTREE (created_at);
CREATE INDEX block_created_at ON blocks USING BTREE (timestamp);

CREATE TABLE IF NOT EXISTS transactionsInBlock (
id serial PRIMARY KEY,
Expand All @@ -94,7 +92,7 @@ CREATE TABLE IF NOT EXISTS tokens (
id serial PRIMARY KEY,
token VARCHAR (100) UNIQUE NOT NULL,
valid BOOLEAN NOT NULL,
expiration_date INTEGER NOT NULL
expiration_date BIGINT NOT NULL
);

CREATE INDEX token_token ON tokens USING HASH (token);
Expand All @@ -118,4 +116,12 @@ CREATE TABLE IF NOT EXISTS validatorStatus (
);

CREATE INDEX validator_index ON validatorStatus USING HASH (index);
CREATE INDEX validator_created_at ON validatorStatus USING BTREE (created_at);
CREATE INDEX validator_created_at ON validatorStatus USING BTREE (created_at);


CREATE USER computantis WITH ENCRYPTED PASSWORD 'computantis';

GRANT ALL PRIVILEGES ON DATABASE computantis TO computantis;
GRANT ALL PRIVILEGES ON SCHEMA public TO computantis;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO computantis;
GRANT ALL ON ALL TABLES IN SCHEMA public TO computantis;
Loading