Skip to content

Commit

Permalink
Changed key index type to uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Jul 15, 2024
1 parent a798897 commit e7c884d
Show file tree
Hide file tree
Showing 9 changed files with 1,208 additions and 24 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
6 changes: 3 additions & 3 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.37.0.20240715155222-3860a034ebfa
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.20240712213451-aa5cd6ac0360
github.com/onflow/flow-go-sdk v1.0.0-preview.39
github.com/onflow/flow-go v0.36.1-0.20240715172335-192f26e669b0
github.com/onflow/flow-go-sdk v1.0.0-preview.39.0.20240715160201-3f4dc11e843a
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 Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2050,8 +2050,8 @@ github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs
github.com/onflow/atree v0.7.0-rc.2 h1:mZmVrl/zPlfI44EjV3FdR2QwIqT8nz1sCONUBFcML/U=
github.com/onflow/atree v0.7.0-rc.2/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM=
github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8=
github.com/onflow/cadence v1.0.0-preview.37 h1:CclIG7GXEBJCwk5d5jumJ6cU8xj/Q1A9cfVJKIxvLH8=
github.com/onflow/cadence v1.0.0-preview.37/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0=
github.com/onflow/cadence v1.0.0-preview.37.0.20240715155222-3860a034ebfa h1:JRQJpsUXtgm9OZyFvA8o9PpqccAz/ufw32GGyqLmgLQ=
github.com/onflow/cadence v1.0.0-preview.37.0.20240715155222-3860a034ebfa/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0=
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
Expand All @@ -2063,11 +2063,11 @@ github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/
github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs=
github.com/onflow/flow-ft/lib/go/templates v1.0.0/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
github.com/onflow/flow-go v0.36.1-0.20240712213451-aa5cd6ac0360 h1:lVAezQE5ylt4D/2KaOAYpMzwnMSDAjuKWSOr8SMGSrs=
github.com/onflow/flow-go v0.36.1-0.20240712213451-aa5cd6ac0360/go.mod h1:Bdv8cvDzTiNhoUDDLPNcmaLmyolnpjxcS2SXbXjBxHE=
github.com/onflow/flow-go v0.36.1-0.20240715172335-192f26e669b0 h1:p4X0Y5m4a3kD3BSinSLCqgQT4CmPa3YOwhVb9SpCwvM=
github.com/onflow/flow-go v0.36.1-0.20240715172335-192f26e669b0/go.mod h1:WXQ8hg7ceMXmuHEpmR4e7ZcktGqeVXK7XOR1bZhMaWE=
github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo=
github.com/onflow/flow-go-sdk v1.0.0-preview.39 h1:LAFqq8fph9BnnbYO/PuT4+bZHrfDCZOBG9RytJbrBZ4=
github.com/onflow/flow-go-sdk v1.0.0-preview.39/go.mod h1:/72XLyAy6//wS4Xnt2sp6FgR+MtWPqrLwrkVzbjSE44=
github.com/onflow/flow-go-sdk v1.0.0-preview.39.0.20240715160201-3f4dc11e843a h1:H6/XVGB7Wisybb1fU6/JOWA+u4hZjfmuZUIqkkN3xE4=
github.com/onflow/flow-go-sdk v1.0.0-preview.39.0.20240715160201-3f4dc11e843a/go.mod h1:zRwbRUi79nhBpeTtWJ2UUc+LKXMj4HRBPFUwEQgwipc=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1 h1:woAAS5z651sDpi7ihAHll8NvRS9uFXIXkL6xR+bKFZY=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1/go.mod h1:2gpbza+uzs1k7x31hkpBPlggIRkI53Suo0n2AyA2HcE=
github.com/onflow/flow-nft/lib/go/templates v1.2.0 h1:JSQyh9rg0RC+D1930BiRXN8lrtMs+ubVMK6aQPon6Yc=
Expand Down
Loading

0 comments on commit e7c884d

Please sign in to comment.