Skip to content

Commit

Permalink
Changed key index type to uint32 (#712)
Browse files Browse the repository at this point in the history
* Changed key index type to uint32

* fixed mocks

* updated flow-go
  • Loading branch information
janezpodhostnik authored Jul 17, 2024
1 parent b82ed9b commit 4474608
Show file tree
Hide file tree
Showing 9 changed files with 1,400 additions and 104 deletions.
12 changes: 6 additions & 6 deletions adapters/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,41 +466,41 @@ func (a *AccessAdapter) GetAccountBalanceAtBlockHeight(ctx context.Context, addr
return account.Balance, nil
}

func (a *AccessAdapter) GetAccountKeyAtLatestBlock(_ context.Context, address flowgo.Address, keyIndex uint64) (*flowgo.AccountPublicKey, error) {
func (a *AccessAdapter) GetAccountKeyAtLatestBlock(_ context.Context, address flowgo.Address, keyIndex uint32) (*flowgo.AccountPublicKey, error) {
account, err := a.emulator.GetAccount(address)
if err != nil {
return nil, convertError(err, codes.Internal)
}

for _, key := range account.Keys {
if uint64(key.Index) == keyIndex {
if key.Index == keyIndex {
return &key, nil
}
}

a.logger.Debug().
Stringer("address", address).
Uint64("keyIndex", keyIndex).
Uint32("keyIndex", keyIndex).
Msg("👤 GetAccountKeyAtLatestBlock called")

return nil, status.Errorf(codes.NotFound, "failed to get account key by index: %d", keyIndex)
}

func (a *AccessAdapter) GetAccountKeyAtBlockHeight(_ context.Context, address flowgo.Address, keyIndex uint64, height uint64) (*flowgo.AccountPublicKey, error) {
func (a *AccessAdapter) GetAccountKeyAtBlockHeight(_ context.Context, address flowgo.Address, keyIndex uint32, height uint64) (*flowgo.AccountPublicKey, error) {
account, err := a.emulator.GetAccountAtBlockHeight(address, height)
if err != nil {
return nil, convertError(err, codes.Internal)
}

for _, key := range account.Keys {
if uint64(key.Index) == keyIndex {
if key.Index == keyIndex {
return &key, nil
}
}

a.logger.Debug().
Stringer("address", address).
Uint64("keyIndex", keyIndex).
Uint32("keyIndex", keyIndex).
Uint64("height", height).
Msg("👤 GetAccountKeyAtBlockHeight called")

Expand Down
12 changes: 6 additions & 6 deletions convert/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func FlowIdentifiersToSDK(flowIdentifiers []flowgo.Identifier) []sdk.Identifier
func SDKProposalKeyToFlow(sdkProposalKey sdk.ProposalKey) flowgo.ProposalKey {
return flowgo.ProposalKey{
Address: SDKAddressToFlow(sdkProposalKey.Address),
KeyIndex: uint64(sdkProposalKey.KeyIndex),
KeyIndex: sdkProposalKey.KeyIndex,
SequenceNumber: sdkProposalKey.SequenceNumber,
}
}

func FlowProposalKeyToSDK(flowProposalKey flowgo.ProposalKey) sdk.ProposalKey {
return sdk.ProposalKey{
Address: FlowAddressToSDK(flowProposalKey.Address),
KeyIndex: int(flowProposalKey.KeyIndex),
KeyIndex: flowProposalKey.KeyIndex,
SequenceNumber: flowProposalKey.SequenceNumber,
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func SDKTransactionSignatureToFlow(sdkTransactionSignature sdk.TransactionSignat
return flowgo.TransactionSignature{
Address: SDKAddressToFlow(sdkTransactionSignature.Address),
SignerIndex: sdkTransactionSignature.SignerIndex,
KeyIndex: uint64(sdkTransactionSignature.KeyIndex),
KeyIndex: sdkTransactionSignature.KeyIndex,
Signature: sdkTransactionSignature.Signature,
}
}
Expand All @@ -108,7 +108,7 @@ func FlowTransactionSignatureToSDK(flowTransactionSignature flowgo.TransactionSi
return sdk.TransactionSignature{
Address: FlowAddressToSDK(flowTransactionSignature.Address),
SignerIndex: flowTransactionSignature.SignerIndex,
KeyIndex: int(flowTransactionSignature.KeyIndex),
KeyIndex: flowTransactionSignature.KeyIndex,
Signature: flowTransactionSignature.Signature,
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func FlowEventsToSDK(flowEvents []flowgo.Event) ([]sdk.Event, error) {
return ret, nil
}

func FlowAccountPublicKeyToSDK(flowPublicKey flowgo.AccountPublicKey, index int) (sdk.AccountKey, error) {
func FlowAccountPublicKeyToSDK(flowPublicKey flowgo.AccountPublicKey, index uint32) (sdk.AccountKey, error) {

return sdk.AccountKey{
Index: index,
Expand Down Expand Up @@ -272,7 +272,7 @@ func SDKAccountKeysToFlow(keys []*sdk.AccountKey) ([]flowgo.AccountPublicKey, er
func FlowAccountPublicKeysToSDK(flowPublicKeys []flowgo.AccountPublicKey) ([]*sdk.AccountKey, error) {
ret := make([]*sdk.AccountKey, len(flowPublicKeys))
for i, flowPublicKey := range flowPublicKeys {
v, err := FlowAccountPublicKeyToSDK(flowPublicKey, i)
v, err := FlowAccountPublicKeyToSDK(flowPublicKey, uint32(i))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion emulator/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func TestAddAccountKey(t *testing.T) {

script := []byte("transaction { execute {} }")

var newKeyID = 1 // new key will have ID 1
var newKeyID = uint32(1) // new key will have ID 1
var newKeySequenceNum uint64 = 0

tx2 := flowsdk.NewTransaction().
Expand Down
2 changes: 1 addition & 1 deletion emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

type ServiceKey struct {
Index int
Index uint32
Address flowgosdk.Address
SequenceNumber uint64
PrivateKey sdkcrypto.PrivateKey
Expand Down
2 changes: 1 addition & 1 deletion emulator/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func TestSubmitTransaction_Invalid(t *testing.T) {
GasLimit: flowgo.DefaultMaxTransactionGasLimit,
ProposalKey: flowgo.ProposalKey{
Address: convert.SDKAddressToFlow(b.ServiceKey().Address),
KeyIndex: uint64(b.ServiceKey().Index),
KeyIndex: b.ServiceKey().Index,
SequenceNumber: b.ServiceKey().SequenceNumber,
},
Payer: convert.SDKAddressToFlow(b.ServiceKey().Address),
Expand Down
48 changes: 24 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/improbable-eng/grpc-web v0.15.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/onflow/cadence v1.0.0-preview.37
github.com/onflow/cadence v1.0.0-preview.38
github.com/onflow/crypto v0.25.1
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0
github.com/onflow/flow-go v0.36.1-0.20240716023350-c24b664f1064
github.com/onflow/flow-go-sdk v1.0.0-preview.39
github.com/onflow/flow-go v0.36.2-0.20240717162253-d5d2e606ef53
github.com/onflow/flow-go-sdk v1.0.0-preview.41
github.com/onflow/flow-nft/lib/go/contracts v1.2.1
github.com/onflow/flow/protobuf/go/flow v0.4.5
github.com/prometheus/client_golang v1.18.0
Expand All @@ -42,26 +42,28 @@ require (
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
Expand All @@ -71,20 +73,20 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ef-ds/deque v1.0.4 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-ethereum v1.13.10 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
Expand All @@ -104,7 +106,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/holiman/uint256 v1.3.0 // indirect
github.com/huandu/go-clone v1.6.0 // indirect
github.com/huandu/go-clone/generic v1.7.2 // indirect
github.com/huin/goupnp v1.3.0 // indirect
Expand Down Expand Up @@ -155,7 +157,7 @@ require (
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 // indirect
github.com/onflow/flow-ft/lib/go/templates v1.0.0 // indirect
github.com/onflow/flow-nft/lib/go/templates v1.2.0 // indirect
github.com/onflow/go-ethereum v1.13.4 // indirect
github.com/onflow/go-ethereum v1.14.7 // indirect
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 // indirect
github.com/onflow/sdks v0.6.0-preview.1 // indirect
github.com/onflow/wal v1.0.2 // indirect
Expand Down Expand Up @@ -208,16 +210,14 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/api v0.162.0 // indirect
Expand Down
Loading

0 comments on commit 4474608

Please sign in to comment.