Skip to content

Commit

Permalink
Merge branch 'main' into feat-spv-790-Create-outputs-template-and-sto…
Browse files Browse the repository at this point in the history
…re-evaluated-template-in-destination
  • Loading branch information
ac4ch authored May 27, 2024
2 parents e8397e3 + 38fd49f commit cfcc1e9
Show file tree
Hide file tree
Showing 51 changed files with 420 additions and 3,061 deletions.
6 changes: 5 additions & 1 deletion .make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ uninstall: ## Uninstall the application (and remove files)

.PHONY: update
update: ## Update all project dependencies
@echo "updating dependencies..."
@echo "updating dependencies in root..."
@go get -u ./... && go mod tidy
@echo "updating dependencies in engine..."
@(cd engine && go get -u ./... && go mod tidy)
@echo "updating dependencies in models..."
@(cd models && go get -u ./... && go mod tidy)

.PHONY: update-linter
update-linter: ## Update the golangci-lint package (macOS only)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ Ports which are used:
- 5432 - PostgreSQL DB
- 6379 - Redis
- 8080 - Block Headers Service
- 27017 - MongoDB
- 80 - in case of exposing on the paymail domain and its subdomains
- 443 - in case of exposing on the paymail domain and its subdomains
<br/>
Expand Down
12 changes: 1 addition & 11 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ db:
datastore:
# enable datastore debug mode
debug: false
# datastore engine - sqlite/postgresql/mysql/mongodb (experimental)
# datastore engine - sqlite/postgresql
engine: sqlite
# prefix for all tables
table_prefix: xapi
mongodb:
database_name: xapi
debug: false
max_connection_idle_time: 0s
max_connection_time: 0s
max_idle_connections: 0
max_open_connections: 0
table_prefix: ""
transactions: false
uri: mongodb://localhost:27017/xapi
sql:
debug: false
driver: postgresql
Expand Down
6 changes: 2 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ type RedisConfig struct {
type DbConfig struct {
// Datastore general config.
Datastore *DatastoreConfig `json:"datastore" mapstructure:"datastore"`
// Mongo is a config for MongoDb. Works only if datastore engine is set to mongodb.
Mongo *datastore.MongoDBConfig `json:"mongodb" mapstructure:"mongodb"`
// SQL is a config for PostgreSQL or MySQL. Works only if datastore engine is set to postgresql or mysql.
// SQL is a config for PostgreSQL. Works only if datastore engine is set to postgresql.
SQL *datastore.SQLConfig `json:"sql" mapstructure:"sql"`
// SQLite is a config for SQLite. Works only if datastore engine is set to sqlite.
SQLite *datastore.SQLiteConfig `json:"sqlite" mapstructure:"sqlite"`
Expand All @@ -135,7 +133,7 @@ type DbConfig struct {
type DatastoreConfig struct {
// TablePrefix is the prefix for all table names in the database.
TablePrefix string `json:"table_prefix" mapstructure:"table_prefix"`
// Engine is the database to be used, mysql, sqlite, postgresql.
// Engine is the database to be used, sqlite, postgresql.
Engine datastore.Engine `json:"engine" mapstructure:"engine"`
// Debug is a flag that decides whether additional output (such as sql statements) should be produced from datastore.
Debug bool `json:"debug" mapstructure:"debug"`
Expand Down
56 changes: 0 additions & 56 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,60 +143,4 @@ func TestAppConfig_Validate(t *testing.T) {
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid sql config", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MySQL
app.Db.SQL = nil
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid sql user", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MySQL
app.Db.SQL.User = ""
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid sql name", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MySQL
app.Db.SQL.Name = ""
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid sql host", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MySQL
app.Db.SQL.Host = ""
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid mongo config", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MongoDB
app.Db.Mongo = nil
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid mongo uri", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MongoDB
app.Db.Mongo.URI = ""
err := app.Validate()
assert.Error(t, err)
})

t.Run("datastore - invalid mongo database name", func(t *testing.T) {
app, _ := baseTestConfig(t)
app.Db.Datastore.Engine = datastore.MongoDB
app.Db.Mongo.DatabaseName = ""
err := app.Validate()
assert.Error(t, err)
})
}
29 changes: 11 additions & 18 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,18 @@ func getDbDefaults() *DbConfig {
Engine: "sqlite",
TablePrefix: "xapi",
},
Mongo: &datastore.MongoDBConfig{
DatabaseName: "xapi",
ExistingConnection: nil,
Transactions: false,
URI: "mongodb://localhost:27017/xapi",
},
SQL: &datastore.SQLConfig{
Driver: "postgresql",
ExistingConnection: nil,
Host: "localhost",
Name: "xapi",
Password: "",
Port: "5432",
Replica: false,
SkipInitializeWithVersion: true,
TimeZone: "UTC",
TxTimeout: 10 * time.Second,
User: "postgres",
SslMode: "disable",
Driver: "postgresql",
ExistingConnection: nil,
Host: "localhost",
Name: "xapi",
Password: "",
Port: "5432",
Replica: false,
TimeZone: "UTC",
TxTimeout: 10 * time.Second,
User: "postgres",
SslMode: "disable",
},
SQLite: &datastore.SQLiteConfig{
DatabasePath: "./spv-wallet.db",
Expand Down
12 changes: 1 addition & 11 deletions config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func loadDatastore(options []engine.ClientOps, appConfig *AppConfig, testMode bo
DatabasePath: appConfig.Db.SQLite.DatabasePath, // "" for in memory
Shared: appConfig.Db.SQLite.Shared,
}))
} else if appConfig.Db.Datastore.Engine == datastore.MySQL || appConfig.Db.Datastore.Engine == datastore.PostgreSQL {
} else if appConfig.Db.Datastore.Engine == datastore.PostgreSQL {
tablePrefix := appConfig.Db.Datastore.TablePrefix
if len(appConfig.Db.SQL.TablePrefix) > 0 {
tablePrefix = appConfig.Db.SQL.TablePrefix
Expand All @@ -349,16 +349,6 @@ func loadDatastore(options []engine.ClientOps, appConfig *AppConfig, testMode bo
SslMode: appConfig.Db.SQL.SslMode,
}))

} else if appConfig.Db.Datastore.Engine == datastore.MongoDB {

debug := appConfig.Db.Datastore.Debug
tablePrefix := appConfig.Db.Datastore.TablePrefix
if len(appConfig.Db.Mongo.TablePrefix) > 0 {
tablePrefix = appConfig.Db.Mongo.TablePrefix
}
appConfig.Db.Mongo.Debug = debug
appConfig.Db.Mongo.TablePrefix = tablePrefix
options = append(options, engine.WithMongoDB(appConfig.Db.Mongo))
} else {
return nil, errors.New("unsupported datastore engine: " + appConfig.Db.Datastore.Engine.String())
}
Expand Down
11 changes: 2 additions & 9 deletions config/validate_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (d *DbConfig) Validate() error {
if d.SQLite == nil {
return errors.New("missing sqlite config")
}
} else if d.Datastore.Engine == datastore.MySQL || d.Datastore.Engine == datastore.PostgreSQL {
} else if d.Datastore.Engine == datastore.PostgreSQL {
if d.SQL == nil {
return errors.New("missing sql config")
} else if len(d.SQL.Host) == 0 {
Expand All @@ -26,14 +26,7 @@ func (d *DbConfig) Validate() error {
} else if len(d.SQL.Name) == 0 {
return errors.New("missing sql db name")
}
} else if d.Datastore.Engine == datastore.MongoDB {
if d.Mongo == nil {
return errors.New("missing mongo config")
} else if len(d.Mongo.URI) == 0 {
return errors.New("missing mongo uri")
} else if len(d.Mongo.DatabaseName) == 0 {
return errors.New("missing mongo database name")
}
}

return nil
}
3 changes: 0 additions & 3 deletions config/validate_datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestDatastoreConfig_Validate(t *testing.T) {
t.Run("valid datastore config", func(t *testing.T) {
d := DbConfig{
Datastore: &DatastoreConfig{Engine: datastore.SQLite},
Mongo: &datastore.MongoDBConfig{},
SQL: &datastore.SQLConfig{},
SQLite: &datastore.SQLiteConfig{},
}
Expand All @@ -27,7 +26,6 @@ func TestDatastoreConfig_Validate(t *testing.T) {
t.Run("empty datastore", func(t *testing.T) {
d := DbConfig{
Datastore: &DatastoreConfig{Engine: datastore.Empty},
Mongo: &datastore.MongoDBConfig{},
SQL: &datastore.SQLConfig{},
SQLite: &datastore.SQLiteConfig{},
}
Expand All @@ -40,7 +38,6 @@ func TestDatastoreConfig_Validate(t *testing.T) {
t.Run("invalid datastore engine", func(t *testing.T) {
d := DbConfig{
Datastore: &DatastoreConfig{Engine: ""},
Mongo: &datastore.MongoDBConfig{},
SQL: &datastore.SQLConfig{},
SQLite: &datastore.SQLiteConfig{},
}
Expand Down
19 changes: 0 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,6 @@ services:
timeout: 5s
retries: 3

wallet-mongodb:
image: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: mongo
MONGO_INITDB_ROOT_PASSWORD: mongo
MONGO_INITDB_DATABASE: xapi
ports:
- '27017:27017'
volumes:
- wallet-mongodb-data:/data/db
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
start_period: 40s

wallet-gateway:
image: traefik:v2.11
container_name: traefik
Expand Down Expand Up @@ -165,8 +148,6 @@ volumes:
driver: local
wallet-redis-data:
driver: local
wallet-mongodb-data:
driver: local
block-headers-service-data:
driver: local
wallet-gateway-data:
Expand Down
34 changes: 17 additions & 17 deletions engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
## Table of Contents

- [SPV Wallet Engine](#spv-wallet-engine)
- [Table of Contents](#table-of-contents)
- [About](#about)
- [DISCLAIMER](#disclaimer)
- [SPV Wallet Engine: Out-of-the-box Features:](#spv-wallet-engine-out-of-the-box-features)
- [**Project Assumptions: MVP**](#project-assumptions-mvp)
- [Installation](#installation)
- [Documentation](#documentation)
- [Built-in Features](#built-in-features)
- [Usage](#usage)
- [Examples \& Tests](#examples--tests)
- [Benchmarks](#benchmarks)
- [Code Standards](#code-standards)
- [Usage](#usage-1)
- [Contributing](#contributing)
- [License](#license)
- [SPV Wallet Engine](#spv-wallet-engine)
- [Table of Contents](#table-of-contents)
- [About](#about)
- [DISCLAIMER](#disclaimer)
- [SPV Wallet Engine: Out-of-the-box Features:](#spv-wallet-engine-out-of-the-box-features)
- [**Project Assumptions: MVP**](#project-assumptions-mvp)
- [Installation](#installation)
- [Documentation](#documentation)
- [Built-in Features](#built-in-features)
- [Usage](#usage)
- [Examples \& Tests](#examples--tests)
- [Benchmarks](#benchmarks)
- [Code Standards](#code-standards)
- [Usage](#usage-1)
- [Contributing](#contributing)
- [License](#license)

<br/>

Expand All @@ -61,7 +61,7 @@
#### SPV Wallet Engine: Out-of-the-box Features:

- xPub & UTXO State Management (state, balance, utxos, destinations)
- Bring your own Database ([PostgreSQL](https://www.postgresql.org/), [SQLite](https://www.sqlite.org), [MySQL](https://www.mysql.com/), [Mongo](https://www.mongodb.com/) or [interface](./datastore/interface.go) your own)
- Bring your own Database ([PostgreSQL](https://www.postgresql.org/), [SQLite](https://www.sqlite.org), or [interface](./datastore/interface.go) your own)
- Caching ([FreeCache](https://github.com/github.com/coocood/freecache), [Redis](https://redis.io/) or [interface](https://github.com/mrz1836/go-cachestore/blob/master/interface.go) your own)
- Task Management ([TaskQ](https://github.com/vmihailenco/taskq) or [interface](taskmanager/interface.go) your own)
- Transaction Syncing (queue, broadcast, push to mempool or on-chain, or [interface](chainstate/interface.go) your own)
Expand Down
2 changes: 1 addition & 1 deletion engine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type (
cacheStore *cacheStoreOptions // Configuration options for Cachestore (ristretto, redis, etc.)
cluster *clusterOptions // Configuration options for the cluster coordinator
chainstate *chainstateOptions // Configuration options for Chainstate (broadcast, sync, etc.)
dataStore *dataStoreOptions // Configuration options for the DataStore (MySQL, etc.)
dataStore *dataStoreOptions // Configuration options for the DataStore (PostgreSQL, etc.)
debug bool // If the client is in debug mode
encryptionKey string // Encryption key for encrypting sensitive information (IE: paymail xPub) (hex encoded key)
httpClient HTTPInterface // HTTP interface to use
Expand Down
Loading

0 comments on commit cfcc1e9

Please sign in to comment.