Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump deps, cleanup actions #44

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .github/workflows/shiroclient-sdk-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ name: CI Tests
on:
pull_request:
branches:
- main
- main
jobs:
build-test:
runs-on: ubuntu-latest
container:
image: luthersystems/build-go:v0.0.79
steps:
- uses: actions/checkout@v3.5.0
- name: Set license file
run: echo $LUTHER_LICENSE | base64 -d > .luther-license.yaml
env:
LUTHER_LICENSE: ${{ secrets.LUTHER_LICENSE }}
- name: Run CI tests
run: make citest
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: false
- name: Set license file
run: echo $LUTHER_LICENSE | base64 -d > .luther-license.yaml
env:
LUTHER_LICENSE: ${{ secrets.LUTHER_LICENSE }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.57
- name: Run CI tests
run: make citest
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ GO_TEST_TIMEOUT_10=${GO_TEST_BASE} -timeout 10m
go-test:
${GO_TEST_TIMEOUT_10} ./...

.PHONY: static-checks
static-checks:
./scripts/static-checks.sh

.PHONY: test
test: static-checks go-test
test: go-test
@

${STATIC_PRESIGN_DUMMY}: ${LICENSE_FILE}
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/luthersystems/shiroclient-sdk-go

go 1.21
go 1.22

require (
github.com/golang/protobuf v1.5.3
Expand All @@ -11,7 +11,7 @@ require (
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.33.0
)

require (
Expand All @@ -26,9 +26,9 @@ require (
github.com/oklog/run v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // 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-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ3
go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM=
go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc=
go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
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/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -65,19 +65,19 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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/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.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA=
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
24 changes: 14 additions & 10 deletions internal/rpc/shiroclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ var _ types.ShiroClient = (*rpcShiroClient)(nil)
var tracePropagator = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{})

type rpcShiroClient struct {
baseConfig []types.Config
tracer trace.Tracer
defaultLog *logrus.Logger
httpClient http.Client
tracer trace.Tracer
baseConfig []types.Config
}

// rpcres is a type for a partially decoded RPC response.
type rpcres struct {
errorLevel int
result interface{}
code interface{}
message interface{}
data interface{}
txID string
errorLevel int
}

// scError wraps errors from shiroclient.
type scError struct {
err error
message string
code int
err error
}

// Unwrap implements the Wrapper interface from the errors package.
Expand Down Expand Up @@ -89,8 +89,8 @@ func (r *rpcres) getShiroClientError() error {

func (c *rpcShiroClient) doRequest(ctx context.Context, httpClient *http.Client, httpReq *http.Request, log *logrus.Logger) ([]byte, error) {
type result struct {
msg []byte
err error
msg []byte
}
resultCh := make(chan result, 1)

Expand All @@ -107,7 +107,7 @@ func (c *rpcShiroClient) doRequest(ctx context.Context, httpClient *http.Client,
// On error, any Response can be ignored. A non-nil Response with a
// non-nil error only occurs when CheckRedirect fails, and even then
// the returned Response.Body is already closed.
resultCh <- result{nil, err}
resultCh <- result{err, nil}
return
}

Expand All @@ -130,9 +130,9 @@ func (c *rpcShiroClient) doRequest(ctx context.Context, httpClient *http.Client,
}

if err != nil {
resultCh <- result{nil, err}
resultCh <- result{err, nil}
} else {
resultCh <- result{msg, nil}
resultCh <- result{nil, msg}
}
}()

Expand Down Expand Up @@ -353,8 +353,8 @@ func urlQueryAppend(u *url.URL, vals url.Values) {
// may already contain a query string. Attempting to parse the query can
// be a lossy conversion in the case of malformed input.
paramStr := vals.Encode()
switch {
case u.RawQuery == "":
switch u.RawQuery {
case "":
u.RawQuery = paramStr
default:
u.RawQuery += "&" + paramStr
Expand Down Expand Up @@ -532,6 +532,10 @@ func (c *rpcShiroClient) Call(ctx context.Context, method string, configs ...typ
req["params"].(map[string]interface{})["target_endpoints"] = opt.TargetEndpoints
}

if len(opt.NotTargetEndpoints) > 0 {
req["params"].(map[string]interface{})["not_target_endpoints"] = opt.NotTargetEndpoints
}

res, err := c.reqres(ctx, req, opt)
if err != nil {
return nil, err
Expand Down
36 changes: 19 additions & 17 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,29 @@ func ApplyConfigs(log *logrus.Logger, configs ...Config) *RequestOptions {
// the With* functions. There is no need for a consumer of this
// library to directly manipulate objects of this type.
type RequestOptions struct {
HTTPClient *http.Client
Params interface{}
Target *interface{}
Log *logrus.Logger
LogFields logrus.Fields
Headers map[string]string
Endpoint string
CcFetchURLProxy *url.URL
HTTPClient *http.Client
TimestampGenerator func(context.Context) string
Transient map[string][]byte
ID string
Endpoint string
NewPhylumVersion string
PhylumVersion string
DependentBlock string
AuthToken string
Params interface{}
Transient map[string][]byte
Target *interface{}
TimestampGenerator func(context.Context) string
MspFilter []string
TargetEndpoints []string
MinEndorsers int
Creator string
DependentTxID string
NotTargetEndpoints []string
TargetEndpoints []string
MspFilter []string
MinEndorsers int
DisableWritePolling bool
CcFetchURLDowngrade bool
CcFetchURLProxy *url.URL
DependentBlock string
PhylumVersion string
NewPhylumVersion string
}

// ShiroResponse is a wrapper for a response from a shiro
Expand Down Expand Up @@ -151,16 +152,17 @@ type Error interface {
func NewFailureResponse(code int, message string, data []byte) *failureResponse {
return &failureResponse{
err: failureError{
code: code, message: message, data: data},
code: code, message: message, data: data,
},
}
}

var _ ShiroResponse = (*failureResponse)(nil)

type failureError struct {
code int
message string
data []byte
code int
}

func (s *failureError) Code() int {
Expand Down Expand Up @@ -204,8 +206,8 @@ func (s *failureResponse) Error() Error {
var _ ShiroResponse = (*successResponse)(nil)

type successResponse struct {
result []byte
txID string
result []byte
}

func NewSuccessResponse(result []byte, txID string) *successResponse {
Expand Down Expand Up @@ -247,8 +249,8 @@ func NewTransaction(id string, reason string, event []byte, ccID string) *transa
type transaction struct {
id string
reason string
event []byte
ccID string
event []byte
}

func (t *transaction) ID() string {
Expand Down
9 changes: 0 additions & 9 deletions scripts/static-checks.sh

This file was deleted.

8 changes: 8 additions & 0 deletions shiroclient/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ func WithTargetEndpoints(nameOrURL []string) Config {
})
}

// WithoutTargetEndpoints allows specifying which exact peers will not
// be used to process the transaction. Specifcy a name or URL of the peer.
func WithoutTargetEndpoints(nameOrURL []string) Config {
return types.Opt(func(r *types.RequestOptions) {
r.NotTargetEndpoints = append([]string(nil), nameOrURL...)
})
}

// WithMinEndorsers allows specifying the minimum number of endorsing
// peers. Has no effect in mock mode.
func WithMinEndorsers(minEndorsers int) Config {
Expand Down