Skip to content

Commit

Permalink
Merge pull request #214 from flow-hydraulics/latenssi/update-some-dep…
Browse files Browse the repository at this point in the history
…endencies

Update dependencies, fix changed APIs, fix sometimes failing tests
  • Loading branch information
latenssi authored Nov 18, 2021
2 parents 526afc7 + 2c9cb68 commit cb3d577
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 379 deletions.
16 changes: 10 additions & 6 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,21 @@ func AddContract(
return err
}

flowTx := flow.NewTransaction()
flowTx.
flowTx := flow.NewTransaction().
SetReferenceBlockID(*referenceBlockID).
SetProposalKey(proposer.Address, proposer.Key.Index, proposer.Key.SequenceNumber).
SetPayer(payer.Address).
SetGasLimit(maxGasLimit).
SetScript([]byte(template_strings.AddAccountContractWithAdmin))
SetScript([]byte(template_strings.AddAccountContractWithAdmin)).
AddAuthorizer(payer.Address)

flowTx.AddArgument(cadence.NewString(contract.Name)) // nolint
flowTx.AddArgument(cadence.NewString(contract.SourceHex())) // nolint
flowTx.AddAuthorizer(payer.Address)
if err := flowTx.AddArgument(cadence.String(contract.Name)); err != nil {
return err
}

if err := flowTx.AddArgument(cadence.String(contract.SourceHex())); err != nil {
return err
}

// Proposer signs the payload
if proposer.Address.Hex() != payer.Address.Hex() {
Expand Down
20 changes: 16 additions & 4 deletions chain_events/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"gorm.io/gorm"
)

type GetEventTypes func() []string
type GetEventTypes func() ([]string, error)

type Listener struct {
ticker *time.Ticker
Expand Down Expand Up @@ -57,7 +57,10 @@ func NewListener(
func (l *Listener) run(ctx context.Context, start, end uint64) error {
events := make([]flow.Event, 0)

eventTypes := l.getTypes()
eventTypes, err := l.getTypes()
if err != nil {
return err
}

for _, t := range eventTypes {
r, err := l.fc.GetEventsForHeightRange(ctx, client.EventRangeQuery{
Expand Down Expand Up @@ -123,6 +126,11 @@ func (l *Listener) Start() *Listener {
start := status.LatestHeight + 1 // LatestHeight has already been checked, add 1
end := min(latestBlock.Height, start+l.maxBlocks) // Limit maximum end
if err := l.run(ctx, start, end); err != nil {
if strings.Contains(err.Error(), "database is locked") {
// Sqlite throws this error from time to time when accessing it from
// multiple threads; listener is run in a separate thread.
return nil
}
return err
}
status.LatestHeight = end
Expand Down Expand Up @@ -170,7 +178,11 @@ func (l *Listener) initHeight() error {

func (l *Listener) Stop() {
l.logger.Println("stopping...")
l.ticker.Stop()
l.done <- true
if l.ticker != nil {
l.ticker.Stop()
}
if l.done != nil {
l.done <- true
}
l.ticker = nil
}
3 changes: 1 addition & 2 deletions chain_events/store_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"

"gorm.io/gorm"
"gorm.io/gorm/clause"
)

type GormStore struct {
Expand All @@ -22,7 +21,7 @@ func (s *GormStore) LockedStatus(fn func(status *ListenerStatus) error) error {
txErr := s.db.Transaction(func(tx *gorm.DB) error {
status := ListenerStatus{}

if err := tx.Clauses(clause.Locking{Strength: "UPDATE", Options: "NOWAIT"}).FirstOrCreate(&status).Error; err != nil {
if err := tx.FirstOrCreate(&status).Error; err != nil {
return err // rollback
}

Expand Down
8 changes: 0 additions & 8 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ type RequestError struct {
func (e *RequestError) Error() string {
return e.Err.Error()
}

type JobQueueFull struct {
Err error
}

func (e *JobQueueFull) Error() string {
return e.Err.Error()
}
55 changes: 33 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@ module github.com/flow-hydraulics/flow-wallet-api
go 1.16

require (
cloud.google.com/go v0.81.0
github.com/aws/aws-sdk-go-v2 v1.9.2
github.com/aws/aws-sdk-go-v2/config v1.8.3
github.com/aws/aws-sdk-go-v2/service/kms v1.7.0
github.com/caarlos0/env/v6 v6.6.2
cloud.google.com/go/kms v1.1.0
github.com/aws/aws-sdk-go-v2 v1.11.0
github.com/aws/aws-sdk-go-v2/config v1.10.1
github.com/aws/aws-sdk-go-v2/service/kms v1.10.0
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/caarlos0/env/v6 v6.7.2
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/envoyproxy/go-control-plane v0.10.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/ethereum/go-ethereum v1.10.12 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/go-gormigrate/gormigrate/v2 v2.0.0
github.com/go-test/deep v1.0.8 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.2.0
github.com/google/uuid v1.3.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
github.com/joho/godotenv v1.3.0
github.com/joho/godotenv v1.4.0
github.com/jpillora/backoff v1.0.0
github.com/lib/pq v1.6.0 // indirect
github.com/mattn/go-sqlite3 v1.14.7 // indirect
github.com/onflow/cadence v0.16.0
github.com/onflow/flow-go-sdk v0.20.0
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/onflow/cadence v0.20.0
github.com/onflow/flow-go-sdk v0.23.0
github.com/onflow/flow/protobuf/go/flow v0.2.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/zeebo/blake3 v0.2.1 // indirect
go.uber.org/goleak v1.1.12
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c // indirect
google.golang.org/api v0.45.0 // indirect
google.golang.org/genproto v0.0.0-20210427215850-f767ed18ee4d
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0
gorm.io/driver/mysql v1.1.2
gorm.io/driver/postgres v1.1.0
gorm.io/driver/sqlite v1.1.4
golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8 // indirect
golang.org/x/net v0.0.0-20211116231205-47ca1ff31462 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c // indirect
google.golang.org/api v0.60.0 // indirect
google.golang.org/genproto v0.0.0-20211116182654-e63d96a377c4
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gorm.io/driver/mysql v1.2.0
gorm.io/driver/postgres v1.2.2
gorm.io/driver/sqlite v1.2.4
gorm.io/driver/sqlserver v1.0.9 // indirect
gorm.io/gorm v1.21.15
gorm.io/gorm v1.22.3
)
Loading

0 comments on commit cb3d577

Please sign in to comment.