Skip to content

Commit

Permalink
Support protocol 7 (#10)
Browse files Browse the repository at this point in the history
* Get rid of warnings

* Updated submodule and generated new code, documented build process

* Changelog

* Update go in CI
  • Loading branch information
Victor-N-Suadicani authored Sep 4, 2024
1 parent a9be887 commit 02723ed
Show file tree
Hide file tree
Showing 21 changed files with 7,280 additions and 7,262 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fmt-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.21'

- name: Format sources
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased changes

- Added support for protocol version 7.

## 0.2.0

- Added support for GRPC V2 `GetWinningBakersEpoch` for getting a list of bakers that won the lottery in a particular historical epoch. Only available when querying a node with version at least 6.1.
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/Concordium/concordium-go-sdk">
</div>



## Getting Started

### Installing
Expand Down Expand Up @@ -199,4 +197,27 @@ All RPC interfaces follow the [concordium protocol docs](https://developer.conco

### More Examples

For more examples, see the `v2/examples/` or `v2/tests/` folders.
For more examples, see the `v2/examples/` or `v2/tests/` folders.

## Building

To update the generated protobuf files, ensure that you have the GRPC API repository pulled down:
```bash
git submodule update --init --recursive
```
Then ensure that you have the prerequisite tooling installed for protobuf. First install the Protobuf compiler, then install the Go and Go GRPC protobuf plugins:
```bash
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```
Be sure to add `~/go/bin` to your path, where these executables are installed.

Then, to generate the protobuf files, run the following command:

```
protoc --go_out=./v2 --go-grpc_out=./v2 --proto_path=concordium-grpc-api concordium-grpc-api/v2/concordium/*.proto
```
Now, you should be able to easily build the project:
```
go build ./v2
```
2 changes: 1 addition & 1 deletion concordium-grpc-api
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
module github.com/Concordium/concordium-go-sdk

go 1.19
go 1.21

toolchain go1.23.0

require (
github.com/btcsuite/btcutil v1.0.2
github.com/caarlos0/env/v6 v6.10.1
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.32.0
google.golang.org/grpc v1.66.0
google.golang.org/protobuf v1.34.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 13 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
Expand All @@ -39,26 +36,23 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe h1:bQnxqljG/wqi4NTXu2+DJ3n7APcEA882QZ1JvhQAq9o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
5 changes: 3 additions & 2 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"crypto/tls"
"crypto/x509"

"github.com/Concordium/concordium-go-sdk/v2/pb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -25,7 +26,7 @@ type Client struct {
// NewClient creates new concordium grpc client.
func NewClient(config Config) (_ *Client, err error) {
if config.TlsCredentials != nil {
conn, err := grpc.Dial(
conn, err := grpc.NewClient(
config.NodeAddress,
grpc.WithTransportCredentials(config.TlsCredentials),
)
Expand All @@ -36,7 +37,7 @@ func NewClient(config Config) (_ *Client, err error) {

return &Client{GrpcClient: client, ClientConn: conn, config: config}, nil
} else {
conn, err := grpc.Dial(
conn, err := grpc.NewClient(
config.NodeAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
Expand Down
2 changes: 1 addition & 1 deletion v2/getaccountlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *Client) GetAccountList(ctx context.Context, req isBlockHashInput) (_ []

var accounts []*pb.AccountAddress

for err == nil {
for {
account, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
2 changes: 1 addition & 1 deletion v2/getaccountnonfinalizedtransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Client) GetAccountNonFinalizedTransactions(ctx context.Context, req *Ac

var transactionHashes []*pb.TransactionHash

for err == nil {
for {
transactionHash, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
2 changes: 1 addition & 1 deletion v2/getancestors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *Client) GetAncestors(ctx context.Context, amount uint64, b isBlockHashI

var ancestorsBlockHashes []*pb.BlockHash

for err == nil {
for {
ancestorBlockHash, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
2 changes: 1 addition & 1 deletion v2/getblockitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *Client) GetBlockItems(ctx context.Context, req isBlockHashInput) (_ []*

var blockItems []*pb.BlockItem

for err == nil {
for {
blockItem, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
2 changes: 1 addition & 1 deletion v2/getinstancelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Client) GetInstanceList(ctx context.Context, req isBlockHashInput) (_ [

var contractAddresses []*pb.ContractAddress

for err == nil {
for {
contractAddress, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
2 changes: 1 addition & 1 deletion v2/getmodulelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *Client) GetModuleList(ctx context.Context, req isBlockHashInput) (_ []*

var moduleRefs []*pb.ModuleRef

for err == nil {
for {
moduleRef, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" {
Expand Down
40 changes: 20 additions & 20 deletions v2/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

var (
// InvalidPayloadType indicated that payload type is invalid.
InvalidPayloadType = errors.New("invalid payload type")
// InvalidRawPayloadSize indicated that raw payload size is invalid.
InvalidRawPayloadSize = errors.New("invalid raw payload size")
// ErrInvalidPayloadType indicated that payload type is invalid.
ErrInvalidPayloadType = errors.New("invalid payload type")
// ErrInvalidRawPayloadSize indicated that raw payload size is invalid.
ErrInvalidRawPayloadSize = errors.New("invalid raw payload size")
)

const PayloadTypeSize = 1
Expand Down Expand Up @@ -48,13 +48,13 @@ func GetPayloadType(payload AccountTransactionPayload) (PayloadType, error) {
case *TransferWithMemo:
return TransferWithMemoPayloadType, nil
}
return 0xff, InvalidPayloadType
return 0xff, ErrInvalidPayloadType
}

// decode parses specific Payload from bytes.
func decode(payloadBytes []byte) (payload *AccountTransactionPayload, err error) {
if len(payloadBytes) <= 1 {
return nil, InvalidRawPayloadSize
return nil, ErrInvalidRawPayloadSize
}

payload = new(AccountTransactionPayload)
Expand Down Expand Up @@ -112,7 +112,7 @@ func (rawPayload RawPayload) Size() PayloadSize {
// This also checks that all data is used, i.e., that there are no remaining trailing bytes.
func (rawPayload RawPayload) Decode() (*AccountTransactionPayload, error) {
if rawPayload.Value == nil {
return &AccountTransactionPayload{}, InvalidRawPayloadSize
return &AccountTransactionPayload{}, ErrInvalidRawPayloadSize
}
return decode(rawPayload.Value)
}
Expand Down Expand Up @@ -159,13 +159,13 @@ func (payload *DeployModulePayload) Encode() *RawPayload {
// Decode decodes bytes into DeployModulePayload.
func (payload *DeployModulePayload) Decode(source []byte) error {
if len(source) <= 5 {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

version := moduleVersion(source[:1][0])
moduleSize := binary.BigEndian.Uint32(source[1:5])
if len(source) != int(moduleSize+5) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

module := make([]byte, 0, moduleSize)
Expand Down Expand Up @@ -220,7 +220,7 @@ func (payload *InitContractPayload) Encode() *RawPayload {
// Decode decodes bytes into InitContractPayload.
func (payload *InitContractPayload) Decode(source []byte) error {
if len(source) <= 42 {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Amount = &Amount{Value: binary.BigEndian.Uint64(source[:8])}
Expand All @@ -232,14 +232,14 @@ func (payload *InitContractPayload) Decode(source []byte) error {

initNameSize := binary.BigEndian.Uint16(source[40:42])
if len(source) <= int(initNameSize+44) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.InitName = &InitName{Value: string(source[42 : 42+initNameSize])}

parameterSize := binary.BigEndian.Uint16(source[42+initNameSize : initNameSize+44])
if len(source) != int(initNameSize+parameterSize+44) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Parameter = &Parameter{Value: source[44+initNameSize:]}
Expand Down Expand Up @@ -279,12 +279,12 @@ func (payload *RegisterDataPayload) Encode() *RawPayload {
// Decode decodes bytes into RegisterDataPayload.
func (payload *RegisterDataPayload) Decode(source []byte) error {
if len(source) <= 2 {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

registerDataSize := binary.BigEndian.Uint16(source[:2])
if len(source) != int(registerDataSize+2) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Data = &RegisteredData{Value: source[2:]}
Expand Down Expand Up @@ -323,7 +323,7 @@ func (payload *TransferPayload) Encode() *RawPayload {
// Decode decodes bytes into TransferPayload.
func (payload *TransferPayload) Decode(source []byte) error {
if len(source) != payload.Size() {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

if payload.Receiver == nil {
Expand Down Expand Up @@ -373,7 +373,7 @@ func (payload *TransferWithMemoPayload) Encode() *RawPayload {
// Decode decodes bytes into TransferWithMemoPayload.
func (payload *TransferWithMemoPayload) Decode(source []byte) error {
if len(source) <= 34 {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

if payload.Receiver == nil {
Expand All @@ -383,7 +383,7 @@ func (payload *TransferWithMemoPayload) Decode(source []byte) error {

memoSize := binary.BigEndian.Uint16(source[32:34])
if len(source) != int(42+memoSize) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Memo = &Memo{Value: source[34 : 34+memoSize]}
Expand Down Expand Up @@ -439,7 +439,7 @@ func (payload *UpdateContractPayload) Encode() *RawPayload {
// Decode decodes bytes into UpdateContractPayload.
func (payload *UpdateContractPayload) Decode(source []byte) error {
if len(source) <= 26 {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Amount = &Amount{Value: binary.BigEndian.Uint64(source[:8])}
Expand All @@ -452,14 +452,14 @@ func (payload *UpdateContractPayload) Decode(source []byte) error {

receiveNameSize := binary.BigEndian.Uint16(source[24:26])
if len(source) <= int(receiveNameSize+28) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.ReceiveName = &ReceiveName{Value: string(source[26 : 26+receiveNameSize])}

parameterSize := binary.BigEndian.Uint16(source[26+receiveNameSize : receiveNameSize+28])
if len(source) != int(receiveNameSize+parameterSize+28) {
return InvalidRawPayloadSize
return ErrInvalidRawPayloadSize
}

payload.Parameter = &Parameter{Value: source[28+receiveNameSize:]}
Expand Down
Loading

0 comments on commit 02723ed

Please sign in to comment.