Skip to content

Commit

Permalink
Merge pull request #37 from blinklabs-io/chore/golines
Browse files Browse the repository at this point in the history
chore: run golines
  • Loading branch information
wolf31o2 committed Oct 26, 2023
2 parents 8d555bc + 0c4fb8d commit 3877d4e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
34 changes: 28 additions & 6 deletions bursa.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ type Wallet struct {
StakeSKey KeyFile `json:"stake_skey"`
}

func NewWallet(mnemonic, network string, accountId uint, paymentId, stakeId, addressId uint32) (*Wallet, error) {
func NewWallet(
mnemonic, network string,
accountId uint,
paymentId, stakeId, addressId uint32,
) (*Wallet, error) {
rootKey, err := GetRootKeyFromMnemonic(mnemonic)
if err != nil {
return nil, fmt.Errorf("failed to get root key from mnemonic: %s", err)
Expand Down Expand Up @@ -124,7 +128,9 @@ func GetPaymentVKey(paymentKey bip32.XPrv) KeyFile {
}

func GetPaymentSKey(paymentKey bip32.XPrv) KeyFile {
keyCbor, err := cbor.Marshal(GetExtendedPrivateKey(paymentKey, paymentKey.Public().PublicKey()))
keyCbor, err := cbor.Marshal(
GetExtendedPrivateKey(paymentKey, paymentKey.Public().PublicKey()),
)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -152,7 +158,9 @@ func GetStakeVKey(stakeKey bip32.XPrv) KeyFile {
}

func GetStakeSKey(stakeKey bip32.XPrv) KeyFile {
keyCbor, err := cbor.Marshal(GetExtendedPrivateKey(stakeKey, stakeKey.Public().PublicKey()))
keyCbor, err := cbor.Marshal(
GetExtendedPrivateKey(stakeKey, stakeKey.Public().PublicKey()),
)
if err != nil {
panic(err)
}
Expand All @@ -163,13 +171,27 @@ func GetStakeSKey(stakeKey bip32.XPrv) KeyFile {
}
}

func GetAddress(accountKey bip32.XPrv, net string, num uint32) *address.BaseAddress {
func GetAddress(
accountKey bip32.XPrv,
net string,
num uint32,
) *address.BaseAddress {
nw := network.TestNet()
if net == "mainnet" {
nw = network.MainNet()
}
paymentKeyPublicHash := GetPaymentKey(accountKey, num).Public().PublicKey().Hash()
stakeKeyPublicHash := GetStakeKey(accountKey, num).Public().PublicKey().Hash()
paymentKeyPublicHash := GetPaymentKey(
accountKey,
num,
).Public().
PublicKey().
Hash()
stakeKeyPublicHash := GetStakeKey(
accountKey,
num,
).Public().
PublicKey().
Hash()
addr := address.NewBaseAddress(
nw,
&address.StakeCredential{
Expand Down
6 changes: 5 additions & 1 deletion cmd/bursa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func apiMain() {
cfg := config.GetConfig()
logger := logging.GetLogger()
// Start API listener
logger.Infof("starting API listener on %s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort)
logger.Infof(
"starting API listener on %s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort,
)
if err := api.Start(cfg); err != nil {
logger.Fatalf("failed to start API: %s", err)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,19 @@ func handleWalletCreate(c *gin.Context) {
if err != nil {
logger.Errorf("failed to load mnemonic: %s", err)
c.JSON(500, fmt.Sprintf("failed to load mnemonic: %s", err))
_= ginmetrics.GetMonitor().GetMetric("bursa_wallets_fail_count").Inc(nil)
_ = ginmetrics.GetMonitor().
GetMetric("bursa_wallets_fail_count").
Inc(nil)
return
}

w, err := bursa.NewDefaultWallet(mnemonic)
if err != nil {
logger.Errorf("failed to initialize wallet: %s", err)
c.JSON(500, fmt.Sprintf("failed to initialize wallet: %s", err))
_= ginmetrics.GetMonitor().GetMetric("bursa_wallets_fail_count").Inc(nil)
_ = ginmetrics.GetMonitor().
GetMetric("bursa_wallets_fail_count").
Inc(nil)
return
}
c.JSON(200, w)
Expand Down
6 changes: 5 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import (

func Run() {
fs := flag.NewFlagSet("cli", flag.ExitOnError)
flagOutput := fs.String("output", "", "output directory for files, otherwise uses STDOUT")
flagOutput := fs.String(
"output",
"",
"output directory for files, otherwise uses STDOUT",
)
if len(os.Args) >= 2 {
_ = fs.Parse(os.Args[2:]) // ignore parse errors
}
Expand Down
5 changes: 4 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func GetConfig() *Config {

func LoadConfig() (*Config, error) {
if err := envconfig.Process("bursa", &globalConfig); err != nil {
return nil, fmt.Errorf("failed loading config from environment: %s", err)
return nil, fmt.Errorf(
"failed loading config from environment: %s",
err,
)
}
return &globalConfig, nil
}
8 changes: 6 additions & 2 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func Setup() {
// Change timestamp key name
loggerConfig.EncoderConfig.TimeKey = "timestamp"
// Use a human readable time format
loggerConfig.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(time.RFC3339)
loggerConfig.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(
time.RFC3339,
)

// Set level
if cfg.Logging.Level != "" {
Expand Down Expand Up @@ -50,5 +52,7 @@ func GetDesugaredLogger() *zap.Logger {
}

func GetAccessLogger() *zap.Logger {
return globalLogger.Desugar().With(zap.String("type", "access")).WithOptions(zap.WithCaller(false))
return globalLogger.Desugar().
With(zap.String("type", "access")).
WithOptions(zap.WithCaller(false))
}

0 comments on commit 3877d4e

Please sign in to comment.