Skip to content

Commit 8cfabeb

Browse files
authored
Merge pull request #407 from blinklabs-io/chore/golines
chore: run golines
2 parents 9dbe90e + 255c3b5 commit 8cfabeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1198
-277
lines changed

cbor/cbor.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ func (d *DecodeStoreCbor) Cbor() []byte {
7171
}
7272

7373
// UnmarshalCbor decodes the specified CBOR into the destination object and saves the original CBOR
74-
func (d *DecodeStoreCbor) UnmarshalCbor(cborData []byte, dest DecodeStoreCborInterface) error {
74+
func (d *DecodeStoreCbor) UnmarshalCbor(
75+
cborData []byte,
76+
dest DecodeStoreCborInterface,
77+
) error {
7578
if err := DecodeGeneric(cborData, dest); err != nil {
7679
return err
7780
}

cbor/decode.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func DecodeIdFromList(cborData []byte) (int, error) {
7777
func ListLength(cborData []byte) (int, error) {
7878
// If the list length is <= the max simple uint, then we can extract the length
7979
// value straight from the byte slice (with a little math)
80-
if cborData[0] >= CborTypeArray && cborData[0] <= (CborTypeArray+CborMaxUintSimple) {
80+
if cborData[0] >= CborTypeArray &&
81+
cborData[0] <= (CborTypeArray+CborMaxUintSimple) {
8182
return int(cborData[0]) - int(CborTypeArray), nil
8283
}
8384
// If we couldn't use the shortcut above, actually decode the list
@@ -90,7 +91,10 @@ func ListLength(cborData []byte) (int, error) {
9091

9192
// Decode CBOR list data by the leading value of each list item. It expects CBOR data and
9293
// a map of numbers to object pointers to decode into
93-
func DecodeById(cborData []byte, idMap map[int]interface{}) (interface{}, error) {
94+
func DecodeById(
95+
cborData []byte,
96+
idMap map[int]interface{},
97+
) (interface{}, error) {
9498
id, err := DecodeIdFromList(cborData)
9599
if err != nil {
96100
return nil, err
@@ -112,7 +116,8 @@ func DecodeGeneric(cborData []byte, dest interface{}) error {
112116
// We do this so that we can bypass any custom UnmarshalCBOR() function on the
113117
// destination object
114118
valueDest := reflect.ValueOf(dest)
115-
if valueDest.Kind() != reflect.Pointer || valueDest.Elem().Kind() != reflect.Struct {
119+
if valueDest.Kind() != reflect.Pointer ||
120+
valueDest.Elem().Kind() != reflect.Struct {
116121
return fmt.Errorf("destination must be a pointer to a struct")
117122
}
118123
typeDestElem := valueDest.Elem().Type()

cbor/decode_test.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ func TestDecode(t *testing.T) {
5656
}
5757
if test.BytesRead > 0 {
5858
if bytesRead != test.BytesRead {
59-
t.Fatalf("expected to read %d bytes, read %d instead", test.BytesRead, bytesRead)
59+
t.Fatalf(
60+
"expected to read %d bytes, read %d instead",
61+
test.BytesRead,
62+
bytesRead,
63+
)
6064
}
6165
}
6266
if !reflect.DeepEqual(dest, test.Object) {
63-
t.Fatalf("CBOR did not decode to expected object\n got: %#v\n wanted: %#v", dest, test.Object)
67+
t.Fatalf(
68+
"CBOR did not decode to expected object\n got: %#v\n wanted: %#v",
69+
dest,
70+
test.Object,
71+
)
6472
}
6573
}
6674
}
@@ -102,10 +110,18 @@ func TestListLen(t *testing.T) {
102110
}
103111
listLen, err := cbor.ListLength(cborData)
104112
if !reflect.DeepEqual(err, test.Error) {
105-
t.Fatalf("did not find expected error\n got: %#v\n wanted: %#v", err, test.Error)
113+
t.Fatalf(
114+
"did not find expected error\n got: %#v\n wanted: %#v",
115+
err,
116+
test.Error,
117+
)
106118
}
107119
if listLen != test.Length {
108-
t.Fatalf("did not get expected length, got: %d, wanted: %d", listLen, test.Length)
120+
t.Fatalf(
121+
"did not get expected length, got: %d, wanted: %d",
122+
listLen,
123+
test.Length,
124+
)
109125
}
110126
}
111127
}
@@ -152,10 +168,18 @@ func TestDecodeIdFromList(t *testing.T) {
152168
}
153169
id, err := cbor.DecodeIdFromList(cborData)
154170
if !reflect.DeepEqual(err, test.Error) {
155-
t.Fatalf("did not find expected error\n got: %#v\n wanted: %#v", err, test.Error)
171+
t.Fatalf(
172+
"did not find expected error\n got: %#v\n wanted: %#v",
173+
err,
174+
test.Error,
175+
)
156176
}
157177
if id != test.Id {
158-
t.Fatalf("did not get expected ID, got: %d, wanted: %d", id, test.Id)
178+
t.Fatalf(
179+
"did not get expected ID, got: %d, wanted: %d",
180+
id,
181+
test.Id,
182+
)
159183
}
160184
}
161185
}
@@ -232,10 +256,18 @@ func TestDecodeById(t *testing.T) {
232256
}
233257
obj, err := cbor.DecodeById(cborData, decodeByIdObjectMap)
234258
if !reflect.DeepEqual(err, test.Error) {
235-
t.Fatalf("did not find expected error\n got: %#v\n wanted: %#v", err, test.Error)
259+
t.Fatalf(
260+
"did not find expected error\n got: %#v\n wanted: %#v",
261+
err,
262+
test.Error,
263+
)
236264
}
237265
if !reflect.DeepEqual(obj, test.Object) {
238-
t.Fatalf("CBOR did not decode to expected object\n got: %#v\n wanted: %#v", obj, test.Object)
266+
t.Fatalf(
267+
"CBOR did not decode to expected object\n got: %#v\n wanted: %#v",
268+
obj,
269+
test.Object,
270+
)
239271
}
240272
}
241273
}

cbor/encode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func EncodeGeneric(src interface{}) ([]byte, error) {
4141
// We do this so that we can bypass any custom UnmarshalCBOR() function on the
4242
// destination object
4343
valueSrc := reflect.ValueOf(src)
44-
if valueSrc.Kind() != reflect.Pointer || valueSrc.Elem().Kind() != reflect.Struct {
44+
if valueSrc.Kind() != reflect.Pointer ||
45+
valueSrc.Elem().Kind() != reflect.Struct {
4546
return nil, fmt.Errorf("source must be a pointer to a struct")
4647
}
4748
typeSrcElem := valueSrc.Elem().Type()

cbor/encode_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func TestEncode(t *testing.T) {
4242
}
4343
cborHex := hex.EncodeToString(cborData)
4444
if cborHex != test.CborHex {
45-
t.Fatalf("object did not encode to expected CBOR\n got: %s\n wanted: %s", cborHex, test.CborHex)
45+
t.Fatalf(
46+
"object did not encode to expected CBOR\n got: %s\n wanted: %s",
47+
cborHex,
48+
test.CborHex,
49+
)
4650
}
4751
}
4852
}

cbor/value.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ func (v *Value) processMap(data []byte) (err error) {
161161
// deferred function to recover from a possible panic and return an error
162162
defer func() {
163163
if r := recover(); r != nil {
164-
err = fmt.Errorf("decode failure, probably due to type unsupported by Go: %v", r)
164+
err = fmt.Errorf(
165+
"decode failure, probably due to type unsupported by Go: %v",
166+
r,
167+
)
165168
}
166169
}()
167170
tmpValue := map[Value]Value{}

cbor/value_test.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ var testDefs = []struct {
4848
},
4949
// Invalid map key type
5050
{
51-
cborHex: "A1810000",
52-
expectedDecodeError: fmt.Errorf("decode failure, probably due to type unsupported by Go: runtime error: hash of unhashable type []interface {}"),
51+
cborHex: "A1810000",
52+
expectedDecodeError: fmt.Errorf(
53+
"decode failure, probably due to type unsupported by Go: runtime error: hash of unhashable type []interface {}",
54+
),
5355
},
5456
// [1, 2, 3]
5557
{
@@ -59,8 +61,11 @@ var testDefs = []struct {
5961
},
6062
// {1: 2, 3: 4}
6163
{
62-
cborHex: "A201020304",
63-
expectedObject: map[any]any{uint64(1): uint64(2), uint64(3): uint64(4)},
64+
cborHex: "A201020304",
65+
expectedObject: map[any]any{
66+
uint64(1): uint64(2),
67+
uint64(3): uint64(4),
68+
},
6469
expectedAstJson: `{"map":[{"k":{"int":1},"v":{"int":2}},{"k":{"int":3},"v":{"int":4}}]}`,
6570
},
6671
// {1: [2], 3: [4]}
@@ -93,7 +98,11 @@ func TestValueDecode(t *testing.T) {
9398
if _, err := cbor.Decode(cborData, &tmpValue); err != nil {
9499
if testDef.expectedDecodeError != nil {
95100
if err.Error() != testDef.expectedDecodeError.Error() {
96-
t.Fatalf("did not receive expected decode error, got: %s, wanted: %s", err, testDef.expectedDecodeError)
101+
t.Fatalf(
102+
"did not receive expected decode error, got: %s, wanted: %s",
103+
err,
104+
testDef.expectedDecodeError,
105+
)
97106
}
98107
continue
99108
} else {
@@ -106,7 +115,11 @@ func TestValueDecode(t *testing.T) {
106115
}
107116
newObj := tmpValue.Value()
108117
if !reflect.DeepEqual(newObj, testDef.expectedObject) {
109-
t.Fatalf("CBOR did not decode to expected object\n got: %#v\n wanted: %#v", newObj, testDef.expectedObject)
118+
t.Fatalf(
119+
"CBOR did not decode to expected object\n got: %#v\n wanted: %#v",
120+
newObj,
121+
testDef.expectedObject,
122+
)
110123
}
111124
}
112125
}
@@ -142,7 +155,11 @@ func TestValueMarshalJSON(t *testing.T) {
142155
)
143156
}
144157
if !test.JsonStringsEqual(jsonData, []byte(fullExpectedJson)) {
145-
t.Fatalf("CBOR did not marshal to expected JSON\n got: %s\n wanted: %s", jsonData, fullExpectedJson)
158+
t.Fatalf(
159+
"CBOR did not marshal to expected JSON\n got: %s\n wanted: %s",
160+
jsonData,
161+
fullExpectedJson,
162+
)
146163
}
147164
}
148165
}
@@ -157,7 +174,11 @@ func TestLazyValueDecode(t *testing.T) {
157174
if _, err := cbor.Decode(cborData, &tmpValue); err != nil {
158175
if testDef.expectedDecodeError != nil {
159176
if err.Error() != testDef.expectedDecodeError.Error() {
160-
t.Fatalf("did not receive expected decode error, got: %s, wanted: %s", err, testDef.expectedDecodeError)
177+
t.Fatalf(
178+
"did not receive expected decode error, got: %s, wanted: %s",
179+
err,
180+
testDef.expectedDecodeError,
181+
)
161182
}
162183
continue
163184
} else {
@@ -168,7 +189,11 @@ func TestLazyValueDecode(t *testing.T) {
168189
if err != nil {
169190
if testDef.expectedDecodeError != nil {
170191
if err.Error() != testDef.expectedDecodeError.Error() {
171-
t.Fatalf("did not receive expected decode error, got: %s, wanted: %s", err, testDef.expectedDecodeError)
192+
t.Fatalf(
193+
"did not receive expected decode error, got: %s, wanted: %s",
194+
err,
195+
testDef.expectedDecodeError,
196+
)
172197
}
173198
continue
174199
} else {
@@ -180,7 +205,11 @@ func TestLazyValueDecode(t *testing.T) {
180205
}
181206
}
182207
if !reflect.DeepEqual(newObj, testDef.expectedObject) {
183-
t.Fatalf("CBOR did not decode to expected object\n got: %#v\n wanted: %#v", newObj, testDef.expectedObject)
208+
t.Fatalf(
209+
"CBOR did not decode to expected object\n got: %#v\n wanted: %#v",
210+
newObj,
211+
testDef.expectedObject,
212+
)
184213
}
185214
}
186215
}
@@ -216,7 +245,11 @@ func TestLazyValueMarshalJSON(t *testing.T) {
216245
)
217246
}
218247
if !test.JsonStringsEqual(jsonData, []byte(fullExpectedJson)) {
219-
t.Fatalf("CBOR did not marshal to expected JSON\n got: %s\n wanted: %s", jsonData, fullExpectedJson)
248+
t.Fatalf(
249+
"CBOR did not marshal to expected JSON\n got: %s\n wanted: %s",
250+
jsonData,
251+
fullExpectedJson,
252+
)
220253
}
221254
}
222255
}

cmd/block-fetch/main.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ func main() {
4040
}
4141
f.Flagset.Uint64Var(&f.slot, "slot", 0, "slot for single block to fetch")
4242
f.Flagset.StringVar(&f.hash, "hash", "", "hash for single block to fetch")
43-
f.Flagset.BoolVar(&f.all, "all", false, "show all available detail for block")
43+
f.Flagset.BoolVar(
44+
&f.all,
45+
"all",
46+
false,
47+
"show all available detail for block",
48+
)
4449
f.Parse()
4550
// Create connection
4651
conn := common.CreateClientConnection(f.GlobalFlags)
@@ -69,7 +74,9 @@ func main() {
6974
fmt.Printf("ERROR: failed to decode block hash: %s\n", err)
7075
os.Exit(1)
7176
}
72-
block, err := o.BlockFetch().Client.GetBlock(ocommon.NewPoint(f.slot, blockHash))
77+
block, err := o.BlockFetch().Client.GetBlock(
78+
ocommon.NewPoint(f.slot, blockHash),
79+
)
7380
if err != nil {
7481
fmt.Printf("ERROR: failed to fetch block: %s\n", err)
7582
os.Exit(1)
@@ -86,13 +93,21 @@ func main() {
8693
}
8794
if f.all {
8895
issuerVkey := block.IssuerVkey()
89-
fmt.Printf("\nMinted by: %s (%s)\n", issuerVkey.PoolId(), issuerVkey.Hash())
96+
fmt.Printf(
97+
"\nMinted by: %s (%s)\n",
98+
issuerVkey.PoolId(),
99+
issuerVkey.Hash(),
100+
)
90101
// Display transaction info
91102
fmt.Printf("\nTransactions:\n")
92103
for _, tx := range block.Transactions() {
93104
fmt.Printf(" Hash: %s\n", tx.Hash())
94105
if tx.Metadata() != nil {
95-
fmt.Printf(" Metadata:\n %#v (%x)\n", tx.Metadata().Value(), tx.Metadata().Cbor())
106+
fmt.Printf(
107+
" Metadata:\n %#v (%x)\n",
108+
tx.Metadata().Value(),
109+
tx.Metadata().Cbor(),
110+
)
96111
}
97112
fmt.Printf(" Inputs:\n")
98113
for _, input := range tx.Inputs() {
@@ -113,15 +128,21 @@ func main() {
113128
fmt.Printf(" Policy assets:\n")
114129
for _, assetName := range assets.Assets(policyId) {
115130
fmt.Printf(" Asset name: %s\n", assetName)
116-
fmt.Printf(" Amount: %d\n", assets.Asset(policyId, assetName))
131+
fmt.Printf(
132+
" Amount: %d\n",
133+
assets.Asset(policyId, assetName),
134+
)
117135
fmt.Println("")
118136
}
119137
}
120138
}
121139
if output.Datum() != nil {
122140
jsonData, err := json.Marshal(output.Datum())
123141
if err != nil {
124-
fmt.Printf(" Datum (hex): %x\n", output.Datum().Cbor())
142+
fmt.Printf(
143+
" Datum (hex): %x\n",
144+
output.Datum().Cbor(),
145+
)
125146
} else {
126147
fmt.Printf(" Datum: %s\n", jsonData)
127148
}

cmd/common/cmdline.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,37 @@ func NewGlobalFlags() *GlobalFlags {
3636
f := &GlobalFlags{
3737
Flagset: flag.NewFlagSet(os.Args[0], flag.ExitOnError),
3838
}
39-
f.Flagset.StringVar(&f.Socket, "socket", "", "UNIX socket path to connect to")
40-
f.Flagset.StringVar(&f.Address, "address", "", "TCP address to connect to in address:port format")
39+
f.Flagset.StringVar(
40+
&f.Socket,
41+
"socket",
42+
"",
43+
"UNIX socket path to connect to",
44+
)
45+
f.Flagset.StringVar(
46+
&f.Address,
47+
"address",
48+
"",
49+
"TCP address to connect to in address:port format",
50+
)
4151
f.Flagset.BoolVar(&f.UseTls, "tls", false, "enable TLS")
42-
f.Flagset.BoolVar(&f.NtnProto, "ntn", false, "use node-to-node protocol (defaults to node-to-client)")
43-
f.Flagset.StringVar(&f.Network, "network", "preview", "specifies network that node is participating in")
44-
f.Flagset.IntVar(&f.NetworkMagic, "network-magic", 0, "specifies network magic value. this overrides the -network option")
52+
f.Flagset.BoolVar(
53+
&f.NtnProto,
54+
"ntn",
55+
false,
56+
"use node-to-node protocol (defaults to node-to-client)",
57+
)
58+
f.Flagset.StringVar(
59+
&f.Network,
60+
"network",
61+
"preview",
62+
"specifies network that node is participating in",
63+
)
64+
f.Flagset.IntVar(
65+
&f.NetworkMagic,
66+
"network-magic",
67+
0,
68+
"specifies network magic value. this overrides the -network option",
69+
)
4570
return f
4671
}
4772

0 commit comments

Comments
 (0)