-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from 0xPolygon/feature/remove-node-dependency
Remove cdk-validium-node dependency
- Loading branch information
Showing
55 changed files
with
10,548 additions
and
1,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/invopop/jsonschema" | ||
) | ||
|
||
// Duration is a wrapper type that parses time duration from text. | ||
type Duration struct { | ||
time.Duration `validate:"required"` | ||
} | ||
|
||
// MarshalJSON marshalls time duration into text. | ||
func (d Duration) MarshalJSON() ([]byte, error) { | ||
return []byte(`"` + d.String() + `"`), nil | ||
} | ||
|
||
// MarshalText marshalls time duration into text. | ||
func (d *Duration) MarshalText() ([]byte, error) { | ||
return []byte(d.String()), nil | ||
} | ||
|
||
// UnmarshalText unmarshalls time duration from text. | ||
func (d *Duration) UnmarshalText(data []byte) error { | ||
duration, err := time.ParseDuration(string(data)) | ||
if err != nil { | ||
return err | ||
} | ||
d.Duration = duration | ||
return nil | ||
} | ||
|
||
// NewDuration returns Duration wrapper | ||
func NewDuration(duration time.Duration) Duration { | ||
return Duration{time.Duration(duration)} | ||
} | ||
|
||
// JSONSchema returns a custom schema to be used for the JSON Schema generation of this type | ||
func (Duration) JSONSchema() *jsonschema.Schema { | ||
return &jsonschema.Schema{ | ||
Type: "string", | ||
Title: "Duration", | ||
Description: "Duration expressed in units: [ns, us, ms, s, m, h, d]", | ||
Examples: []interface{}{ | ||
"1m", | ||
"300ms", | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package types | ||
|
||
// KeystoreFileConfig has all the information needed to load a private key from a key store file | ||
type KeystoreFileConfig struct { | ||
// Path is the file path for the key store file | ||
Path string `mapstructure:"Path"` | ||
|
||
// Password is the password to decrypt the key store file | ||
Password string `mapstructure:"Password"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/0xPolygon/cdk-data-availability/log" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
) | ||
|
||
// Config provide fields to configure the pool | ||
type Config struct { | ||
// Database name | ||
Name string `mapstructure:"Name"` | ||
|
||
// Database User name | ||
User string `mapstructure:"User"` | ||
|
||
// Database Password of the user | ||
Password string `mapstructure:"Password"` | ||
|
||
// Host address of database | ||
Host string `mapstructure:"Host"` | ||
|
||
// Port Number of database | ||
Port string `mapstructure:"Port"` | ||
|
||
// EnableLog | ||
EnableLog bool `mapstructure:"EnableLog"` | ||
|
||
// MaxConns is the maximum number of connections in the pool. | ||
MaxConns int `mapstructure:"MaxConns"` | ||
} | ||
|
||
// NewSQLDB creates a new SQL DB | ||
func NewSQLDB(cfg Config) (*pgxpool.Pool, error) { | ||
config, err := pgxpool.ParseConfig(fmt.Sprintf("postgres://%s:%s@%s:%s/%s?pool_max_conns=%d", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Name, cfg.MaxConns)) | ||
if err != nil { | ||
log.Errorf("Unable to parse DB config: %v\n", err) | ||
return nil, err | ||
} | ||
if cfg.EnableLog { | ||
config.ConnConfig.Logger = logger{} | ||
} | ||
conn, err := pgxpool.ConnectConfig(context.Background(), config) | ||
if err != nil { | ||
log.Errorf("Unable to connect to database: %v\n", err) | ||
return nil, err | ||
} | ||
return conn, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.