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
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,30 @@ type Verifier interface {
}
```

# stdoutwriter

```go
import "github.com/bartossh/Computantis/stdoutwriter"
```

## Index

- [type Logger](<#type-logger>)
- [func (l Logger) Write(p []byte) (n int, err error)](<#func-logger-write>)


## type [Logger](<https://github.com/bartossh/Computantis/blob/main/stdoutwriter/stdoutwriter.go#L5>)

```go
type Logger struct{}
```

### func \(Logger\) [Write](<https://github.com/bartossh/Computantis/blob/main/stdoutwriter/stdoutwriter.go#L7>)

```go
func (l Logger) Write(p []byte) (n int, err error)
```

# stress

```go
Expand Down Expand Up @@ -2568,15 +2592,15 @@ var (
)
```

## func [Run](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L87>)
## func [Run](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L89>)

```go
func Run(ctx context.Context, cfg Config, srw StatusReadWriter, log logger.Logger, ver Verifier, wh WebhookCreateRemovePoster, wallet *wallet.Wallet) error
```

Run initializes routing and runs the validator. To stop the validator cancel the context. Validator connects to the central server via websocket and listens for new blocks. It will block until the context is canceled.

## type [Config](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L62-L66>)
## type [Config](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L63-L67>)

Config contains configuration of the validator.

Expand Down Expand Up @@ -2604,7 +2628,7 @@ type CreateRemoveUpdateHookRequest struct {
}
```

## type [Status](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L35-L41>)
## type [Status](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L36-L42>)

Status is a status of each received block by the validator. It keeps track of invalid blocks in case of blockchain corruption.

Expand All @@ -2618,7 +2642,7 @@ type Status struct {
}
```

## type [StatusReadWriter](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L44-L47>)
## type [StatusReadWriter](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L45-L48>)

StatusReadWriter provides methods to bulk read and single write validator status.

Expand All @@ -2629,7 +2653,7 @@ type StatusReadWriter interface {
}
```

## type [Verifier](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L57-L59>)
## type [Verifier](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L58-L60>)

Verifier provides methods to verify the signature of the message.

Expand All @@ -2651,7 +2675,7 @@ type WebHookNewBlockMessage struct {
}
```

## type [WebhookCreateRemovePoster](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L50-L54>)
## type [WebhookCreateRemovePoster](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L51-L55>)

WebhookCreateRemovePoster provides methods to create, remove webhooks and post messages to webhooks.

Expand Down
3 changes: 2 additions & 1 deletion cmd/central/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/bartossh/Computantis/logging"
"github.com/bartossh/Computantis/reactive"
"github.com/bartossh/Computantis/server"
"github.com/bartossh/Computantis/stdoutwriter"
"github.com/bartossh/Computantis/wallet"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func main() {
panic(fmt.Sprintf("error with logger: %s", err))
}

log := logging.New(callbackOnErr, callbackOnFatal, db)
log := logging.New(callbackOnErr, callbackOnFatal, db, stdoutwriter.Logger{})

if err := blockchain.GenesisBlock(ctx, db); err != nil {
fmt.Println(err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/bartossh/Computantis/configuration"
"github.com/bartossh/Computantis/fileoperations"
"github.com/bartossh/Computantis/logging"
"github.com/bartossh/Computantis/stdoutwriter"
"github.com/bartossh/Computantis/validator"
"github.com/bartossh/Computantis/wallet"
"github.com/bartossh/Computantis/webhooks"
Expand Down Expand Up @@ -40,14 +41,14 @@ func main() {
defer db.Disconnect(ctxx)

callbackOnErr := func(err error) {
fmt.Println("error with logger: ", err)
fmt.Println("logger error: ", err)
}

callbackOnFatal := func(err error) {
panic(fmt.Sprintf("error with logger: %s", err))
panic(fmt.Sprintf("fatal error: %s", err))
}

log := logging.New(callbackOnErr, callbackOnFatal, db)
log := logging.New(callbackOnErr, callbackOnFatal, db, stdoutwriter.Logger{})

go func() {
<-c
Expand All @@ -70,6 +71,5 @@ func main() {

if err := validator.Run(ctx, cfg.Validator, db, log, verify, wh, &wl); err != nil {
log.Error(err.Error())
fmt.Println(err.Error())
}
}
2 changes: 1 addition & 1 deletion docker-compose-postgresql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: computantis_postgresql
image: postgres:latest
environment:
POSTGRES_USER: ${POSTGRES_DB_USER}
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: ${POSTGRES_DB_PASSWORD}
volumes:
- ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
Expand Down
2 changes: 1 addition & 1 deletion docker_postgres_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ CREATE INDEX validator_created_at ON validatorStatus USING BTREE (created_at);
CREATE TABLE IF NOT EXISTS nodes (
id serial PRIMARY KEY,
node VARCHAR ( 64 ) UNIQUE NOT NULL,
websocket VARCHAR ( 256 ) UNIQUE NOT NULL,
websocket VARCHAR ( 256 ) UNIQUE NOT NULL
);

CREATE INDEX nodes_index ON nodes USING HASH (node);
Expand Down
36 changes: 30 additions & 6 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,30 @@ type Verifier interface {
}
```

# stdoutwriter

```go
import "github.com/bartossh/Computantis/stdoutwriter"
```

## Index

- [type Logger](<#type-logger>)
- [func (l Logger) Write(p []byte) (n int, err error)](<#func-logger-write>)


## type [Logger](<https://github.com/bartossh/Computantis/blob/main/stdoutwriter/stdoutwriter.go#L5>)

```go
type Logger struct{}
```

### func \(Logger\) [Write](<https://github.com/bartossh/Computantis/blob/main/stdoutwriter/stdoutwriter.go#L7>)

```go
func (l Logger) Write(p []byte) (n int, err error)
```

# stress

```go
Expand Down Expand Up @@ -2487,15 +2511,15 @@ var (
)
```

## func [Run](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L87>)
## func [Run](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L89>)

```go
func Run(ctx context.Context, cfg Config, srw StatusReadWriter, log logger.Logger, ver Verifier, wh WebhookCreateRemovePoster, wallet *wallet.Wallet) error
```

Run initializes routing and runs the validator. To stop the validator cancel the context. Validator connects to the central server via websocket and listens for new blocks. It will block until the context is canceled.

## type [Config](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L62-L66>)
## type [Config](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L63-L67>)

Config contains configuration of the validator.

Expand Down Expand Up @@ -2523,7 +2547,7 @@ type CreateRemoveUpdateHookRequest struct {
}
```

## type [Status](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L35-L41>)
## type [Status](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L36-L42>)

Status is a status of each received block by the validator. It keeps track of invalid blocks in case of blockchain corruption.

Expand All @@ -2537,7 +2561,7 @@ type Status struct {
}
```

## type [StatusReadWriter](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L44-L47>)
## type [StatusReadWriter](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L45-L48>)

StatusReadWriter provides methods to bulk read and single write validator status.

Expand All @@ -2548,7 +2572,7 @@ type StatusReadWriter interface {
}
```

## type [Verifier](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L57-L59>)
## type [Verifier](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L58-L60>)

Verifier provides methods to verify the signature of the message.

Expand All @@ -2570,7 +2594,7 @@ type WebHookNewBlockMessage struct {
}
```

## type [WebhookCreateRemovePoster](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L50-L54>)
## type [WebhookCreateRemovePoster](<https://github.com/bartossh/Computantis/blob/main/validator/validator.go#L51-L55>)

WebhookCreateRemovePoster provides methods to create, remove webhooks and post messages to webhooks.

Expand Down
9 changes: 8 additions & 1 deletion queries_postgresql/insert_token.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
INSERT INTO tokens (token, valid, expiration_date) VALUES ('80fda91a43989fa81347aa011e0f1e0fdde4eaabb408bf426166a62c80456c30', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('ykkeD6Tr6xikkYwC805kVoFThm8VGEHStTFk1lIU6RgEf7p3vjFpPQFI3VP9SYeARjYh2jecMSYsmgddjZZcy32iySHijJQ', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('8CdWLXrx5GGSSu3je0m6SbCqIuEj7emrsrt7lvm6AeaIQl8d6MCNZKMS00ODA6TrjVYKg4NB9Js4xlSetRdZ4edYupHgBKwX', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('G8OH7lHu5qfWVumWom0ySN29lakog8nhzSPEwROMjvhdI6VgZ6GoPcdJmoIo7sF3lxQNJMOTKxpYBr6zF992WN86uB7xTEJZ', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('jykkeD6Tr6xikkYwC805kVoFThm8VGEHStTFk1lIU6RgEf7p3vjFpPQFI3VP9SYeARjYh2jecMSYsmgddjZZcy32iySHijJQ', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('bIJZyIQLw9hTP0rnbOwmK1G4xlcAXT46IPEkqFdF03gpb2YDuASjWyYVtJIDFdbJm5cRueIbEozhxN8DeevIuapj4BPwfK3d', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('wGrKWMTNzVT5kqtBWPAlRz58L2AOY3BSZ9PN7WGm1EonyGStnOFNX9y3Tr0p635vbe5dD1TiONgCGiP7yIVc2tVEzfCnYL15', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('ZepH88DsFcoPoZUzIE0AI3gRcCrQ8KhDpzESbxoQiyrB77CtKn7MZnjcj9cRla4aucjrgpnTMtM1AtkegwhXnE6iAKRv6hON', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('w4NXZ8H5vebzhfgvfanFXzEIaoPwyWeZpZjRheo4LnG8vjWlMQeNVBz9lCMhTiBbj1PjVFWXHiUyZW21P7o6DkTlrx5x3tJ1', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('a6858eLd1GHvoGXrq6nNhEiHrEmkRN3tXu5dYqCjiMUL9sRfUz1iBns0kEnPizzrLfj2TZGU2Wel52fJ6YDNiVrdtvf2kZm4', true, 9223372036854775807);
INSERT INTO tokens (token, valid, expiration_date) VALUES ('80fda91a43989fa81347aa011e0f1e0fdde4eaabb408bf426166a62c80456c30', true, 9223372036854775807);
3 changes: 0 additions & 3 deletions queries_postgresql/set_tokens _true.sql

This file was deleted.

2 changes: 0 additions & 2 deletions server/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ func (s *server) wsWrapper(c *fiber.Ctx) error {
client.readPump()
}

fmt.Println("serving ws", c.IP())

return websocket.New(serveWs)(c)
}

Expand Down
10 changes: 10 additions & 0 deletions stdoutwriter/stdoutwriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package stdoutwriter

import "fmt"

type Logger struct{}

func (l Logger) Write(p []byte) (n int, err error) {
fmt.Println(string(p))
return len(p), nil
}
8 changes: 5 additions & 3 deletions validator/check.go → validator/block.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package validator

import "github.com/bartossh/Computantis/block"
import (
"github.com/bartossh/Computantis/block"
)

func (a app) validateBlock(block *block.Block) error {
func (a *app) validateBlock(block *block.Block) error {
if a.lastBlock.Index != 0 {
if block.Index != a.lastBlock.Index+1 {
return ErrBlockIndexIsInvalid
Expand All @@ -11,7 +13,7 @@ func (a app) validateBlock(block *block.Block) error {
return ErrBlockPrevHashIsInvalid
}
}
if !block.Validate(block.TrxHashes) { // TODO: use hashes of received transactions after sending transactions is implemented
if !block.Validate(block.TrxHashes) {
return ErrProofBlockIsInvalid
}
return nil
Expand Down
12 changes: 12 additions & 0 deletions validator/socket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package validator

import (
"context"

"github.com/fasthttp/websocket"
)

type socket struct {
conn *websocket.Conn
cancel context.CancelFunc
}
Loading