Skip to content

Commit

Permalink
Merge pull request #296 from numeroai/upgrade-flow-go-sdk
Browse files Browse the repository at this point in the history
Upgrade flow go sdk
  • Loading branch information
aki-eiger authored Jul 1, 2022
2 parents 5cba986 + f666f93 commit 9a47f3b
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 144 deletions.
5 changes: 4 additions & 1 deletion accounts/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,14 @@ func (s *ServiceImpl) createAccount(ctx context.Context) (*Account, string, erro
publicKeys = append(publicKeys, &clonedAccountKey)
}

flowTx := flow_templates.CreateAccount(
flowTx, err := flow_templates.CreateAccount(
publicKeys,
nil,
payer.Address,
)
if err != nil {
return nil, "", err
}

flowTx.
SetReferenceBlockID(*referenceBlockID).
Expand Down
7 changes: 1 addition & 6 deletions chain_events/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/flow-hydraulics/flow-wallet-api/flow_helpers"
"github.com/flow-hydraulics/flow-wallet-api/system"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/client"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -85,11 +84,7 @@ func (l *ListenerImpl) run(ctx context.Context, start, end uint64) error {
}

for _, t := range eventTypes {
r, err := l.fc.GetEventsForHeightRange(ctx, client.EventRangeQuery{
Type: t,
StartHeight: start,
EndHeight: end,
})
r, err := l.fc.GetEventsForHeightRange(ctx, t, start, end)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package errors
import (
"net"

"github.com/onflow/flow-go-sdk/client"
"github.com/onflow/flow-go-sdk/access/grpc"
"google.golang.org/grpc/codes"
)

Expand All @@ -29,7 +29,7 @@ func IsChainConnectionError(err error) bool {
return true
}

if err, ok := err.(client.RPCError); ok {
if err, ok := err.(grpc.RPCError); ok {
// Check for Flow Access API connection errors
for _, code := range accessAPIConnectionErrors {
if err.GRPCStatus().Code() == code {
Expand Down
12 changes: 6 additions & 6 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/onflow/flow-go-sdk/client"
access "github.com/onflow/flow-go-sdk/access/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -24,16 +24,16 @@ func TestIsChainConnectionError(t *testing.T) {

valid_errors := []error{
netErr,
client.RPCError{
access.RPCError{
GRPCErr: status.Error(codes.DeadlineExceeded, "DeadlineExceeded"),
},
client.RPCError{
access.RPCError{
GRPCErr: status.Error(codes.ResourceExhausted, "ResourceExhausted"),
},
client.RPCError{
access.RPCError{
GRPCErr: status.Error(codes.Internal, "Internal"),
},
client.RPCError{
access.RPCError{
GRPCErr: status.Error(codes.Unavailable, "Unavailable"),
},
}
Expand All @@ -56,7 +56,7 @@ func TestIsChainConnectionError(t *testing.T) {
})

t.Run("non existent gateway", func(t *testing.T) {
fc, err := client.New("non-existent-address", grpc.WithTransportCredentials(insecure.NewCredentials()))
fc, err := access.NewClient("non-existent-address", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 3 additions & 1 deletion flow/cadence/transactions/custom_create_account.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
transaction(publicKeys: [String], contracts: {String: String}) {
import Crypto

transaction(publicKeys: [Crypto.KeyListEntry], contracts: {String: String}) {
prepare(signer: AuthAccount) {
panic("Account initialized with custom script")
}
Expand Down
18 changes: 8 additions & 10 deletions flow_helpers/flow_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ import (
"github.com/jpillora/backoff"
"github.com/onflow/cadence"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/client"
"google.golang.org/grpc"
)

type FlowClient interface {
ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value, opts ...grpc.CallOption) (cadence.Value, error)
GetAccount(ctx context.Context, address flow.Address, opts ...grpc.CallOption) (*flow.Account, error)
GetAccountAtLatestBlock(ctx context.Context, address flow.Address, opts ...grpc.CallOption) (*flow.Account, error)
GetTransaction(ctx context.Context, txID flow.Identifier, opts ...grpc.CallOption) (*flow.Transaction, error)
GetTransactionResult(ctx context.Context, txID flow.Identifier, opts ...grpc.CallOption) (*flow.TransactionResult, error)
GetLatestBlockHeader(ctx context.Context, isSealed bool, opts ...grpc.CallOption) (*flow.BlockHeader, error)
GetEventsForHeightRange(ctx context.Context, query client.EventRangeQuery, opts ...grpc.CallOption) ([]client.BlockEvents, error)
SendTransaction(ctx context.Context, tx flow.Transaction, opts ...grpc.CallOption) error
ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value) (cadence.Value, error)
GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.Transaction, error)
GetTransactionResult(ctx context.Context, txID flow.Identifier) (*flow.TransactionResult, error)
GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.BlockHeader, error)
GetEventsForHeightRange(ctx context.Context, eventType string, startHeight uint64, endHeight uint64) ([]flow.BlockEvents, error)
SendTransaction(ctx context.Context, tx flow.Transaction) error
}

const hexPrefix = "0x"
Expand Down
18 changes: 8 additions & 10 deletions flow_helpers/internal/flow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@ import (

"github.com/onflow/cadence"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/client"
"google.golang.org/grpc"
)

type MockFlowClient struct {
getTransactionResultCallCount uint
}

func (c *MockFlowClient) ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value, opts ...grpc.CallOption) (cadence.Value, error) {
func (c *MockFlowClient) ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value) (cadence.Value, error) {
return nil, nil
}

func (c *MockFlowClient) GetAccount(ctx context.Context, address flow.Address, opts ...grpc.CallOption) (*flow.Account, error) {
func (c *MockFlowClient) GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error) {
return nil, nil
}

func (c *MockFlowClient) GetAccountAtLatestBlock(ctx context.Context, address flow.Address, opts ...grpc.CallOption) (*flow.Account, error) {
func (c *MockFlowClient) GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error) {
return nil, nil
}

func (c *MockFlowClient) GetTransaction(ctx context.Context, txID flow.Identifier, opts ...grpc.CallOption) (*flow.Transaction, error) {
func (c *MockFlowClient) GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.Transaction, error) {
return nil, nil
}

func (c *MockFlowClient) GetTransactionResult(ctx context.Context, txID flow.Identifier, opts ...grpc.CallOption) (*flow.TransactionResult, error) {
func (c *MockFlowClient) GetTransactionResult(ctx context.Context, txID flow.Identifier) (*flow.TransactionResult, error) {
c.getTransactionResultCallCount++
status := flow.TransactionStatusPending
if c.getTransactionResultCallCount >= 3 {
Expand All @@ -38,14 +36,14 @@ func (c *MockFlowClient) GetTransactionResult(ctx context.Context, txID flow.Ide
return &flow.TransactionResult{Status: status}, nil
}

func (c *MockFlowClient) GetLatestBlockHeader(ctx context.Context, isSealed bool, opts ...grpc.CallOption) (*flow.BlockHeader, error) {
func (c *MockFlowClient) GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.BlockHeader, error) {
return nil, nil
}

func (c *MockFlowClient) GetEventsForHeightRange(ctx context.Context, query client.EventRangeQuery, opts ...grpc.CallOption) ([]client.BlockEvents, error) {
func (c *MockFlowClient) GetEventsForHeightRange(ctx context.Context, eventType string, startHeight uint64, endHeight uint64) ([]flow.BlockEvents, error) {
return nil, nil
}

func (c *MockFlowClient) SendTransaction(ctx context.Context, tx flow.Transaction, opts ...grpc.CallOption) error {
func (c *MockFlowClient) SendTransaction(ctx context.Context, tx flow.Transaction) error {
return nil
}
48 changes: 24 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ module github.com/flow-hydraulics/flow-wallet-api
go 1.17

require (
cloud.google.com/go/kms v1.1.0
cloud.google.com/go/kms v1.4.0
github.com/aws/aws-sdk-go-v2 v1.13.0
github.com/aws/aws-sdk-go-v2/config v1.13.0
github.com/aws/aws-sdk-go-v2/service/kms v1.14.0
github.com/caarlos0/env/v6 v6.9.1
github.com/felixge/httpsnoop v1.0.2
github.com/go-gormigrate/gormigrate/v2 v2.0.0
github.com/gomodule/redigo v1.8.8
github.com/google/go-cmp v0.5.6
github.com/google/go-cmp v0.5.7
github.com/google/uuid v1.3.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/jpillora/backoff v1.0.0
github.com/lib/pq v1.10.4
github.com/onflow/cadence v0.20.1
github.com/onflow/flow-go-sdk v0.24.0
github.com/onflow/cadence v0.24.0
github.com/onflow/flow-go-sdk v0.26.0
github.com/sirupsen/logrus v1.8.1
go.uber.org/goleak v1.1.12
go.uber.org/ratelimit v0.2.0
google.golang.org/genproto v0.0.0-20220112215332-a9c7c0acf9f2
google.golang.org/grpc v1.43.0
google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
gorm.io/datatypes v1.0.5
gorm.io/driver/mysql v1.2.3
Expand All @@ -33,7 +33,9 @@ require (
)

require (
cloud.google.com/go v0.97.0 // indirect
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.3.0 // indirect
cloud.google.com/go/iam v0.1.0 // indirect
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.10.0 // indirect
Expand All @@ -45,16 +47,10 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.14.0 // indirect
github.com/aws/smithy-go v1.10.0 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 // indirect
github.com/davecgh/go-spew v1.1.1 // 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/fxamacker/cbor/v2 v2.2.1-0.20210927235116-3d6d5d1de29b // indirect
github.com/fxamacker/circlehash v0.1.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.1-0.20220515183430-ad2eae63303f // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-test/deep v1.0.8 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -71,25 +67,29 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mattn/go-sqlite3 v1.14.10 // indirect
github.com/onflow/atree v0.1.0-beta1.0.20211027184039-559ee654ece9 // indirect
github.com/onflow/flow-go/crypto v0.21.3 // indirect
github.com/onflow/flow/protobuf/go/flow v0.2.3 // indirect
github.com/onflow/atree v0.3.1-0.20220531231935-525fbc26f40a // indirect
github.com/onflow/flow-go/crypto v0.24.3 // indirect
github.com/onflow/flow/protobuf/go/flow v0.2.5 // indirect
github.com/onflow/sdks v0.4.4 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/rivo/uniseg v0.2.1-0.20211004051800-57c86be7915a // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/turbolent/prettier v0.0.0-20210613180524-3a3f5a5b49ba // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/blake3 v0.2.1 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.60.0 // indirect
google.golang.org/api v0.70.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gorm.io/driver/sqlserver v1.2.1 // indirect
Expand Down
Loading

0 comments on commit 9a47f3b

Please sign in to comment.