Skip to content

Commit 308a0dc

Browse files
committed
Add droneci, fix linter errors
1 parent 52e11d8 commit 308a0dc

Some content is hidden

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

90 files changed

+5051
-5431
lines changed

.drone.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
kind: pipeline
2+
name: TzGo Pipeline
3+
platform:
4+
os: linux
5+
arch: amd64
6+
7+
trigger:
8+
event:
9+
- push
10+
# paths:
11+
# include:
12+
# - README.md
13+
14+
environment:
15+
CGO_ENABLED: 0
16+
17+
steps:
18+
- name: run linter
19+
image: golangci/golangci-lint:v1.45-alpine
20+
commands:
21+
- golangci-lint run
22+
23+
- name: scan the files
24+
image: aquasec/trivy:0.24.3
25+
commands:
26+
- trivy fs --exit-code 1 --security-checks vuln,config ./
27+
- trivy config --exit-code 1 ./
28+
29+
- name: go build
30+
image: golang:1.19.0-alpine3.16
31+
commands:
32+
- go vet ./...
33+
- go test ./...
34+
- go build ./examples/...

.golangci.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
linters:
2+
enable:
3+
- bodyclose
4+
- goconst
5+
- gocritic
6+
- gofmt
7+
- govet
8+
- prealloc
9+
- unconvert
10+
- unparam
11+
- deadcode
12+
- gosimple
13+
- structcheck
14+
- varcheck
15+
- unused
16+
disable:
17+
- errcheck

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## TzGo – Go SDK for Tezos by Blockwatch Data
22

3+
[![Build Status](https://drone.bwd.cx/api/badges/blockwatch-cc/poly/status.svg?ref=refs/heads/kuba/droneCI)](https://drone.bwd.cx/blockwatch-cc/poly)
4+
35
TzGo is the officially supported Tezos Go client library by [Blockwatch](https://blockwatch.cc). This SDK is free to use in commercial and non-commercial projects with a permissive license. Blockwatch is committed to keeping interfaces stable, providing long-term support, and updating TzGo on a regular basis to stay compliant with the most recent Tezos network protocol.
46

57
Our main focus is on **correctness**, **stability**, and **compliance** with the Tezos protocol. TzGo supports binary and JSON encodings for all Tezos types including the Micheline smart contract data and all transaction formats so it's perfectly suited for high-performance applications that read and write to the Tezos blockchain.
@@ -371,4 +373,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
371373
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
372374
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
373375
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
374-
THE SOFTWARE.
376+
THE SOFTWARE.

base58/base58check.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ func checksum(input []byte) (cksum [4]byte) {
3434
func CheckEncode(input []byte, version []byte) string {
3535
bi := bufPool.Get()
3636
b := bi.([]byte)[:0]
37-
b = append(b, version[:]...)
38-
b = append(b, input[:]...)
37+
b = append(b, version...)
38+
b = append(b, input...)
3939
cksum := checksum(b)
4040
b = append(b, cksum[:]...)
4141
res := Encode(b)
42-
b = b[:0]
4342
bufPool.Put(bi)
4443
return res
4544
}

base58/base58check_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ func TestBase58Check(t *testing.T) {
3838

3939
// test decoding
4040
res, version, err := base58.CheckDecode(test.out, 1, nil)
41-
if err != nil {
41+
switch {
42+
case err != nil:
4243
t.Errorf("CheckDecode test #%d failed with err: %v", x, err)
43-
} else if version[0] != test.version {
44+
case version[0] != test.version:
4445
t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version)
45-
} else if string(res) != test.in {
46+
case string(res) != test.in:
4647
t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in)
4748
}
4849
}
@@ -57,7 +58,7 @@ func TestBase58Check(t *testing.T) {
5758
// bytes are missing).
5859
testString := ""
5960
for len := 0; len < 4; len++ {
60-
testString = testString + "x"
61+
testString += "x"
6162
_, _, err = base58.CheckDecode(testString, 1, nil)
6263
if err != base58.ErrInvalidFormat {
6364
t.Error("Checkdecode test failed, expected ErrInvalidFormat")

codec/activate_account.go

+40-40
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,67 @@
44
package codec
55

66
import (
7-
"bytes"
8-
"fmt"
9-
"io"
10-
"strconv"
7+
"bytes"
8+
"fmt"
9+
"io"
10+
"strconv"
1111

12-
"blockwatch.cc/tzgo/tezos"
12+
"blockwatch.cc/tzgo/tezos"
1313
)
1414

1515
// ActivateAccount represents "activate_account" operation
1616
type ActivateAccount struct {
17-
Simple
18-
PublicKeyHash tezos.Address `json:"pkh"`
19-
Secret tezos.HexBytes `json:"secret"`
17+
Simple
18+
PublicKeyHash tezos.Address `json:"pkh"`
19+
Secret tezos.HexBytes `json:"secret"`
2020
}
2121

2222
func (o ActivateAccount) Kind() tezos.OpType {
23-
return tezos.OpTypeActivateAccount
23+
return tezos.OpTypeActivateAccount
2424
}
2525

2626
func (o ActivateAccount) MarshalJSON() ([]byte, error) {
27-
buf := bytes.NewBuffer(nil)
28-
buf.WriteByte('{')
29-
buf.WriteString(`"kind":`)
30-
buf.WriteString(strconv.Quote(o.Kind().String()))
31-
buf.WriteString(`,"pkh":`)
32-
buf.WriteString(strconv.Quote(o.PublicKeyHash.String()))
33-
buf.WriteString(`,"secret":`)
34-
buf.WriteString(strconv.Quote(o.Secret.String()))
35-
buf.WriteByte('}')
36-
return buf.Bytes(), nil
27+
buf := bytes.NewBuffer(nil)
28+
buf.WriteByte('{')
29+
buf.WriteString(`"kind":`)
30+
buf.WriteString(strconv.Quote(o.Kind().String()))
31+
buf.WriteString(`,"pkh":`)
32+
buf.WriteString(strconv.Quote(o.PublicKeyHash.String()))
33+
buf.WriteString(`,"secret":`)
34+
buf.WriteString(strconv.Quote(o.Secret.String()))
35+
buf.WriteByte('}')
36+
return buf.Bytes(), nil
3737
}
3838

3939
func (o ActivateAccount) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error {
40-
buf.WriteByte(o.Kind().TagVersion(p.OperationTagsVersion))
41-
buf.Write(o.PublicKeyHash.Hash) // only place where a 20 byte address is used (!)
42-
buf.Write(o.Secret.Bytes())
43-
return nil
40+
buf.WriteByte(o.Kind().TagVersion(p.OperationTagsVersion))
41+
buf.Write(o.PublicKeyHash.Hash) // only place where a 20 byte address is used (!)
42+
buf.Write(o.Secret.Bytes())
43+
return nil
4444
}
4545

4646
func (o *ActivateAccount) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) error {
47-
if err := ensureTagAndSize(buf, o.Kind(), p.OperationTagsVersion); err != nil {
48-
return err
49-
}
50-
o.PublicKeyHash = tezos.NewAddress(tezos.AddressTypeEd25519, buf.Next(20))
51-
if !o.PublicKeyHash.IsValid() {
52-
return fmt.Errorf("invalid address type=%s len=%d", o.PublicKeyHash.Type, len(o.PublicKeyHash.Hash))
53-
}
54-
o.Secret = make([]byte, 20)
55-
copy(o.Secret, buf.Next(20))
56-
if len(o.Secret) != 20 {
57-
return io.ErrShortBuffer
58-
}
59-
return nil
47+
if err := ensureTagAndSize(buf, o.Kind(), p.OperationTagsVersion); err != nil {
48+
return err
49+
}
50+
o.PublicKeyHash = tezos.NewAddress(tezos.AddressTypeEd25519, buf.Next(20))
51+
if !o.PublicKeyHash.IsValid() {
52+
return fmt.Errorf("invalid address type=%s len=%d", o.PublicKeyHash.Type, len(o.PublicKeyHash.Hash))
53+
}
54+
o.Secret = make([]byte, 20)
55+
copy(o.Secret, buf.Next(20))
56+
if len(o.Secret) != 20 {
57+
return io.ErrShortBuffer
58+
}
59+
return nil
6060
}
6161

6262
func (o ActivateAccount) MarshalBinary() ([]byte, error) {
63-
buf := bytes.NewBuffer(nil)
64-
err := o.EncodeBuffer(buf, tezos.DefaultParams)
65-
return buf.Bytes(), err
63+
buf := bytes.NewBuffer(nil)
64+
err := o.EncodeBuffer(buf, tezos.DefaultParams)
65+
return buf.Bytes(), err
6666
}
6767

6868
func (o *ActivateAccount) UnmarshalBinary(data []byte) error {
69-
return o.DecodeBuffer(bytes.NewBuffer(data), tezos.DefaultParams)
69+
return o.DecodeBuffer(bytes.NewBuffer(data), tezos.DefaultParams)
7070
}

codec/ballot.go

+51-51
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,78 @@
44
package codec
55

66
import (
7-
"bytes"
8-
"encoding/binary"
9-
"strconv"
7+
"bytes"
8+
"encoding/binary"
9+
"strconv"
1010

11-
"blockwatch.cc/tzgo/tezos"
11+
"blockwatch.cc/tzgo/tezos"
1212
)
1313

1414
// Ballot represents "ballot" operation
1515
type Ballot struct {
16-
Simple
17-
Source tezos.Address `json:"source"`
18-
Period int32 `json:"period"`
19-
Proposal tezos.ProtocolHash `json:"proposal"`
20-
Ballot tezos.BallotVote `json:"ballot"`
16+
Simple
17+
Source tezos.Address `json:"source"`
18+
Period int32 `json:"period"`
19+
Proposal tezos.ProtocolHash `json:"proposal"`
20+
Ballot tezos.BallotVote `json:"ballot"`
2121
}
2222

2323
func (o Ballot) Kind() tezos.OpType {
24-
return tezos.OpTypeBallot
24+
return tezos.OpTypeBallot
2525
}
2626

2727
func (o Ballot) MarshalJSON() ([]byte, error) {
28-
buf := bytes.NewBuffer(nil)
29-
buf.WriteByte('{')
30-
buf.WriteString(`"kind":`)
31-
buf.WriteString(strconv.Quote(o.Kind().String()))
32-
buf.WriteString(`,"source":`)
33-
buf.WriteString(strconv.Quote(o.Source.String()))
34-
buf.WriteString(`,"period":`)
35-
buf.WriteString(strconv.Itoa(int(o.Period)))
36-
buf.WriteString(`,"proposal":`)
37-
buf.WriteString(strconv.Quote(o.Proposal.String()))
38-
buf.WriteString(`,"ballot":`)
39-
buf.WriteString(strconv.Quote(o.Ballot.String()))
40-
buf.WriteByte('}')
41-
return buf.Bytes(), nil
28+
buf := bytes.NewBuffer(nil)
29+
buf.WriteByte('{')
30+
buf.WriteString(`"kind":`)
31+
buf.WriteString(strconv.Quote(o.Kind().String()))
32+
buf.WriteString(`,"source":`)
33+
buf.WriteString(strconv.Quote(o.Source.String()))
34+
buf.WriteString(`,"period":`)
35+
buf.WriteString(strconv.Itoa(int(o.Period)))
36+
buf.WriteString(`,"proposal":`)
37+
buf.WriteString(strconv.Quote(o.Proposal.String()))
38+
buf.WriteString(`,"ballot":`)
39+
buf.WriteString(strconv.Quote(o.Ballot.String()))
40+
buf.WriteByte('}')
41+
return buf.Bytes(), nil
4242
}
4343

4444
func (o Ballot) EncodeBuffer(buf *bytes.Buffer, p *tezos.Params) error {
45-
buf.WriteByte(o.Kind().TagVersion(p.OperationTagsVersion))
46-
buf.Write(o.Source.Bytes())
47-
binary.Write(buf, enc, o.Period)
48-
buf.Write(o.Proposal.Bytes())
49-
buf.WriteByte(o.Ballot.Tag())
50-
return nil
45+
buf.WriteByte(o.Kind().TagVersion(p.OperationTagsVersion))
46+
buf.Write(o.Source.Bytes())
47+
binary.Write(buf, enc, o.Period)
48+
buf.Write(o.Proposal.Bytes())
49+
buf.WriteByte(o.Ballot.Tag())
50+
return nil
5151
}
5252

5353
func (o *Ballot) DecodeBuffer(buf *bytes.Buffer, p *tezos.Params) (err error) {
54-
if err = ensureTagAndSize(buf, o.Kind(), p.OperationTagsVersion); err != nil {
55-
return
56-
}
57-
if err = o.Source.UnmarshalBinary(buf.Next(21)); err != nil {
58-
return
59-
}
60-
o.Period, err = readInt32(buf.Next(4))
61-
if err != nil {
62-
return
63-
}
64-
if err = o.Proposal.UnmarshalBinary(buf.Next(32)); err != nil {
65-
return
66-
}
67-
if err = o.Ballot.UnmarshalBinary(buf.Next(1)); err != nil {
68-
return
69-
}
70-
return nil
54+
if err = ensureTagAndSize(buf, o.Kind(), p.OperationTagsVersion); err != nil {
55+
return
56+
}
57+
if err = o.Source.UnmarshalBinary(buf.Next(21)); err != nil {
58+
return
59+
}
60+
o.Period, err = readInt32(buf.Next(4))
61+
if err != nil {
62+
return
63+
}
64+
if err = o.Proposal.UnmarshalBinary(buf.Next(32)); err != nil {
65+
return
66+
}
67+
if err = o.Ballot.UnmarshalBinary(buf.Next(1)); err != nil {
68+
return
69+
}
70+
return nil
7171
}
7272

7373
func (o Ballot) MarshalBinary() ([]byte, error) {
74-
buf := bytes.NewBuffer(nil)
75-
err := o.EncodeBuffer(buf, tezos.DefaultParams)
76-
return buf.Bytes(), err
74+
buf := bytes.NewBuffer(nil)
75+
err := o.EncodeBuffer(buf, tezos.DefaultParams)
76+
return buf.Bytes(), err
7777
}
7878

7979
func (o *Ballot) UnmarshalBinary(data []byte) error {
80-
return o.DecodeBuffer(bytes.NewBuffer(data), tezos.DefaultParams)
80+
return o.DecodeBuffer(bytes.NewBuffer(data), tezos.DefaultParams)
8181
}

0 commit comments

Comments
 (0)