Skip to content

Commit 39dd4ee

Browse files
authored
chore: make format golines swagger (#183)
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
1 parent a45045d commit 39dd4ee

6 files changed

Lines changed: 73 additions & 23 deletions

File tree

cmd/vpn-cli/datum_ref.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func decodeRefDatumFlexible(datumCBOR []byte) ([]plan, []string, error) {
2727
// [ ....,...] OR Constructor( [ plans, regions, ... ] )
2828
seq, ok := toSlice(v)
2929
if !ok {
30-
return nil, nil, errors.New("refdatum: top-level is not a list/constructor")
30+
return nil, nil, errors.New(
31+
"refdatum: top-level is not a list/constructor",
32+
)
3133
}
3234

3335
// conisdered first list of (int,int) as plans and the first "list of string" as regions.

cmd/vpn-cli/kupo_ref.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func getKupoClient() (*kugo.Client, error) {
2424
return k, nil
2525
}
2626

27-
func loadReferenceFromKugoClient(ctx context.Context) (database.Reference, error) {
27+
func loadReferenceFromKugoClient(
28+
ctx context.Context,
29+
) (database.Reference, error) {
2830
cfg := config.GetConfig()
2931
if strings.TrimSpace(cfg.TxBuilder.KupoUrl) == "" {
3032
return database.Reference{}, errors.New("kupo url not configured")
@@ -43,17 +45,26 @@ func loadReferenceFromKugoClient(ctx context.Context) (database.Reference, error
4345
return refByKugoMatches(ctx, k, addr)
4446
}
4547

46-
return database.Reference{}, errors.New("neither reference token nor script address configured")
48+
return database.Reference{}, errors.New(
49+
"neither reference token nor script address configured",
50+
)
4751
}
4852

49-
func refByKugoMatches(ctx context.Context, k *kugo.Client, pattern string) (database.Reference, error) {
53+
func refByKugoMatches(
54+
ctx context.Context,
55+
k *kugo.Client,
56+
pattern string,
57+
) (database.Reference, error) {
5058
// Query matches by pattern (address).
5159
matches, err := k.Matches(ctx, kugo.Pattern(pattern))
5260
if err != nil {
5361
return database.Reference{}, fmt.Errorf("kupo matches: %w", err)
5462
}
5563
if len(matches) == 0 {
56-
return database.Reference{}, fmt.Errorf("no matches for pattern %q", pattern)
64+
return database.Reference{}, fmt.Errorf(
65+
"no matches for pattern %q",
66+
pattern,
67+
)
5768
}
5869
match := matches[0]
5970

@@ -69,14 +80,19 @@ func refByKugoMatches(ctx context.Context, k *kugo.Client, pattern string) (data
6980
case strings.TrimSpace(getDatumHash(match)) != "":
7081
hexStr, derr := k.Datum(ctx, parseHex(getDatumHash(match)))
7182
if derr != nil {
72-
return database.Reference{}, fmt.Errorf("fetch datum by hash: %w", derr)
83+
return database.Reference{}, fmt.Errorf(
84+
"fetch datum by hash: %w",
85+
derr,
86+
)
7387
}
7488
datumCBOR, err = hex.DecodeString(parseHex(hexStr))
7589
if err != nil {
7690
return database.Reference{}, fmt.Errorf("datum decode: %w", err)
7791
}
7892
default:
79-
return database.Reference{}, errors.New("reference utxo has no datum (no bytes/hash)")
93+
return database.Reference{}, errors.New(
94+
"reference utxo has no datum (no bytes/hash)",
95+
)
8096
}
8197

8298
// Decode reference plans and regions from datumCBOR

cmd/vpn-cli/signup.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,29 @@ var rootCmd = &cobra.Command{
3131
}
3232

3333
func init() {
34-
rootCmd.PersistentFlags().StringVarP(&outPath, "out", "o", "", "output file (default: stdout)")
35-
rootCmd.PersistentFlags().StringVar(&format, "format", "hex", "output format: hex|cbor")
34+
rootCmd.PersistentFlags().
35+
StringVarP(&outPath, "out", "o", "", "output file (default: stdout)")
36+
rootCmd.PersistentFlags().
37+
StringVar(&format, "format", "hex", "output format: hex|cbor")
3638

3739
cmd := &cobra.Command{
3840
Use: "signup",
3941
Short: "Build an unsigned signup transaction",
4042
RunE: runSignup,
4143
}
42-
cmd.Flags().StringVar(&flagPaymentAddr, "payment", "", "client payment bech32 address")
44+
cmd.Flags().
45+
StringVar(&flagPaymentAddr, "payment", "", "client payment bech32 address")
4346
cmd.Flags().StringVar(&flagOwnerAddr, "owner", "", "owner bech32 address")
4447
cmd.Flags().IntVar(&flagPrice, "price", 0, "plan price in lovelace")
45-
cmd.Flags().IntVar(&flagDuration, "duration", 0, "plan duration in milliseconds")
48+
cmd.Flags().
49+
IntVar(&flagDuration, "duration", 0, "plan duration in milliseconds")
4650
cmd.Flags().StringVar(&flagRegion, "region", "", "region code")
4751

4852
// Load from on chain using Kupo/Ogmios
49-
cmd.Flags().StringVar(&flagOgmiosURL, "ogmios-url", "", "Ogmios endpoint (optional)")
50-
cmd.Flags().StringVar(&flagKupoURL, "kupo-url", "", "Kupo endpoint (used if --refdata not provided)")
53+
cmd.Flags().
54+
StringVar(&flagOgmiosURL, "ogmios-url", "", "Ogmios endpoint (optional)")
55+
cmd.Flags().
56+
StringVar(&flagKupoURL, "kupo-url", "", "Kupo endpoint (used if --refdata not provided)")
5157

5258
_ = cmd.MarkFlagRequired("payment")
5359
_ = cmd.MarkFlagRequired("price")

internal/api/tx.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ func (a *Api) handleTxSignup(w http.ResponseWriter, r *http.Request) {
8383
var validationErr txbuilder.InputValidationError
8484
if errors.As(err, &validationErr) {
8585
w.WriteHeader(http.StatusBadRequest)
86-
_, _ = fmt.Fprintf(w, `{"error":"Invalid request: %s"}`, validationErr)
86+
_, _ = fmt.Fprintf(
87+
w,
88+
`{"error":"Invalid request: %s"}`,
89+
validationErr,
90+
)
8791
} else {
8892
w.WriteHeader(http.StatusInternalServerError)
8993
_, _ = w.Write([]byte(`{"error":"Internal server error"}`))
@@ -156,7 +160,11 @@ func (a *Api) handleTxRenew(w http.ResponseWriter, r *http.Request) {
156160
var validationErr txbuilder.InputValidationError
157161
if errors.As(err, &validationErr) {
158162
w.WriteHeader(http.StatusBadRequest)
159-
_, _ = fmt.Fprintf(w, `{"error":"Invalid request: %s"}`, validationErr)
163+
_, _ = fmt.Fprintf(
164+
w,
165+
`{"error":"Invalid request: %s"}`,
166+
validationErr,
167+
)
160168
} else {
161169
w.WriteHeader(http.StatusInternalServerError)
162170
_, _ = w.Write([]byte(`{"error":"Internal server error"}`))
@@ -226,7 +234,11 @@ func (a *Api) handleTxTransfer(w http.ResponseWriter, r *http.Request) {
226234
var validationErr txbuilder.InputValidationError
227235
if errors.As(err, &validationErr) {
228236
w.WriteHeader(http.StatusBadRequest)
229-
_, _ = fmt.Fprintf(w, `{"error":"Invalid request: %s"}`, validationErr)
237+
_, _ = fmt.Fprintf(
238+
w,
239+
`{"error":"Invalid request: %s"}`,
240+
validationErr,
241+
)
230242
} else {
231243
w.WriteHeader(http.StatusInternalServerError)
232244
_, _ = w.Write([]byte(`{"error":"Internal server error"}`))

internal/txbuilder/renew.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func BuildRenewTransferTx(
6969
if ownerAddress != "" && ownerAddress != paymentAddress {
7070
ownerAddr, err := serAddress.DecodeAddress(ownerAddress)
7171
if err != nil {
72-
return nil, NewInputValidationError("failed to decode owner address")
72+
return nil, NewInputValidationError(
73+
"failed to decode owner address",
74+
)
7375
}
7476
ownerCredential = ownerAddr.PaymentPart
7577
}
@@ -133,7 +135,9 @@ func BuildRenewTransferTx(
133135
if price > 0 && duration > 0 {
134136
selectionId, err = determinePlanSelection(refData, price, duration)
135137
if err != nil {
136-
return nil, NewInputValidationError("could not determine plan selection from provided price/duration")
138+
return nil, NewInputValidationError(
139+
"could not determine plan selection from provided price/duration",
140+
)
137141
}
138142
}
139143
// Get last known slot

internal/txbuilder/signup.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ func BuildSignupTx(
5050
return nil, nil, NewInputValidationError("empty region provided")
5151
}
5252
if paymentAddress == "" {
53-
return nil, nil, NewInputValidationError("empty payment address provided")
53+
return nil, nil, NewInputValidationError(
54+
"empty payment address provided",
55+
)
5456
}
5557
cfg := config.GetConfig()
5658
cc, err := apolloBackend()
@@ -60,14 +62,18 @@ func BuildSignupTx(
6062
// Decode payment address
6163
paymentAddr, err := serAddress.DecodeAddress(paymentAddress)
6264
if err != nil {
63-
return nil, nil, NewInputValidationError("failed to decode payment address")
65+
return nil, nil, NewInputValidationError(
66+
"failed to decode payment address",
67+
)
6468
}
6569
// Determine owner credential
6670
ownerCredential := paymentAddr.PaymentPart
6771
if ownerAddress != "" && ownerAddress != paymentAddress {
6872
ownerAddr, err := serAddress.DecodeAddress(ownerAddress)
6973
if err != nil {
70-
return nil, nil, NewInputValidationError("failed to decode owner address")
74+
return nil, nil, NewInputValidationError(
75+
"failed to decode owner address",
76+
)
7177
}
7278
ownerCredential = ownerAddr.PaymentPart
7379
}
@@ -92,7 +98,9 @@ func BuildSignupTx(
9298
return nil, nil, fmt.Errorf("reference data: %w", err)
9399
}
94100
default:
95-
return nil, nil, errors.New("reference data not provided (missing deps.Ref and deps.DB)")
101+
return nil, nil, errors.New(
102+
"reference data not provided (missing deps.Ref and deps.DB)",
103+
)
96104
}
97105
// Validate region
98106
foundRegion := false
@@ -131,7 +139,9 @@ func BuildSignupTx(
131139
// Determine plan selection ID from price/duration
132140
selectionId, err := determinePlanSelection(refData, price, duration)
133141
if err != nil {
134-
return nil, nil, NewInputValidationError("could not determine plan selection from provided price/duration")
142+
return nil, nil, NewInputValidationError(
143+
"could not determine plan selection from provided price/duration",
144+
)
135145
}
136146
// Get last known slot
137147
curSlot, err := cc.LastBlockSlot()

0 commit comments

Comments
 (0)