diff --git a/adapters/access.go b/adapters/access.go index 43cf7aea..1414e77b 100644 --- a/adapters/access.go +++ b/adapters/access.go @@ -438,6 +438,102 @@ func (a *AccessAdapter) GetSystemTransactionResult(_ context.Context, _ flowgo.I return nil, nil } +func (a *AccessAdapter) GetAccountBalanceAtLatestBlock(_ context.Context, address flowgo.Address) (uint64, error) { + + account, err := a.emulator.GetAccount(address) + if err != nil { + return 0, convertError(err, codes.Internal) + } + + a.logger.Debug(). + Stringer("address", address). + Msg("👤 GetAccountBalanceAtLatestBlock called") + + return account.Balance, nil +} + +func (a *AccessAdapter) GetAccountBalanceAtBlockHeight(ctx context.Context, address flowgo.Address, height uint64) (uint64, error) { + account, err := a.emulator.GetAccountAtBlockHeight(address, height) + if err != nil { + return 0, convertError(err, codes.Internal) + } + + a.logger.Debug(). + Stringer("address", address). + Uint64("height", height). + Msg("👤 GetAccountBalanceAtBlockHeight called") + + return account.Balance, nil +} + +func (a *AccessAdapter) GetAccountKeyAtLatestBlock(_ context.Context, address flowgo.Address, keyIndex uint64) (*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 { + return &key, nil + } + } + + a.logger.Debug(). + Stringer("address", address). + Uint64("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) { + 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 { + return &key, nil + } + } + + a.logger.Debug(). + Stringer("address", address). + Uint64("keyIndex", keyIndex). + Uint64("height", height). + Msg("👤 GetAccountKeyAtBlockHeight called") + + return nil, status.Errorf(codes.NotFound, "failed to get account key by index: %d", keyIndex) +} + +func (a *AccessAdapter) GetAccountKeysAtLatestBlock(_ context.Context, address flowgo.Address) ([]flowgo.AccountPublicKey, error) { + account, err := a.emulator.GetAccount(address) + if err != nil { + return nil, convertError(err, codes.Internal) + } + + a.logger.Debug(). + Stringer("address", address). + Msg("👤 GetAccountKeysAtLatestBlock called") + + return account.Keys, nil +} + +func (a *AccessAdapter) GetAccountKeysAtBlockHeight(_ context.Context, address flowgo.Address, height uint64) ([]flowgo.AccountPublicKey, error) { + account, err := a.emulator.GetAccountAtBlockHeight(address, height) + if err != nil { + return nil, convertError(err, codes.Internal) + } + + a.logger.Debug(). + Stringer("address", address). + Uint64("height", height). + Msg("👤 GetAccountKeysAtBlockHeight called") + + return account.Keys, nil +} + func (a *AccessAdapter) GetTransactionResultByIndex( _ context.Context, blockID flowgo.Identifier, diff --git a/emulator/blockchain.go b/emulator/blockchain.go index fa432563..c4f24f7a 100644 --- a/emulator/blockchain.go +++ b/emulator/blockchain.go @@ -1094,7 +1094,7 @@ func (b *Blockchain) getAccountAtBlock(address flowgo.Address, blockHeight uint6 return nil, err } - account, err := b.vm.GetAccount(b.vmCtx, address, ledger) + account, err := fvm.GetAccount(b.vmCtx, address, ledger) if fvmerrors.IsAccountNotFoundError(err) { return nil, &types.AccountNotFoundError{Address: address} } diff --git a/go.mod b/go.mod index 3a6a9bb7..db7f1155 100644 --- a/go.mod +++ b/go.mod @@ -14,13 +14,13 @@ 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.35 + github.com/onflow/cadence v1.0.0-preview.36 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.35.14-crescendo-preview.27.0.20240626210601-604590f19db9 - github.com/onflow/flow-go-sdk v1.0.0-preview.37 + github.com/onflow/flow-go-sdk v1.0.0-preview.38 github.com/onflow/flow-nft/lib/go/contracts v1.2.1 - github.com/onflow/flow/protobuf/go/flow v0.4.4 + github.com/onflow/flow/protobuf/go/flow v0.4.5 github.com/prometheus/client_golang v1.18.0 github.com/psiemens/graceland v1.0.0 github.com/psiemens/sconfig v0.1.0 @@ -236,3 +236,5 @@ require ( nhooyr.io/websocket v1.8.7 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) + +replace github.com/onflow/flow-go v0.35.14-crescendo-preview.27.0.20240626210601-604590f19db9 => github.com/AndriiDiachuk/flow-go v0.0.0-20240711140457-69e2f4007091 diff --git a/go.sum b/go.sum index 5b7d09a1..abfde686 100644 --- a/go.sum +++ b/go.sum @@ -932,6 +932,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/AndriiDiachuk/flow-go v0.0.0-20240711140457-69e2f4007091 h1:9lI8wMf2HDx8jCEXWwqxAZYBJ9+yq0U7Kd7GWQ1lviE= +github.com/AndriiDiachuk/flow-go v0.0.0-20240711140457-69e2f4007091/go.mod h1:zyDRnDHQ7am6Ial1Sk9w5dPB9gQZzAtzYLJIYyLA3z8= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= @@ -2050,8 +2052,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.35 h1:HZgt/9Foa6sCSH9SNaIFUSXK6q2ZxETg0ivsZbf+hhU= -github.com/onflow/cadence v1.0.0-preview.35/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0= +github.com/onflow/cadence v1.0.0-preview.36 h1:mbxqoYSYiVX2Uo+Plrkmu29ezrShohlN+4Ltw0cfJxU= +github.com/onflow/cadence v1.0.0-preview.36/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= @@ -2063,18 +2065,16 @@ 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.35.14-crescendo-preview.27.0.20240626210601-604590f19db9 h1:9GfHBXy9T8QEAkwX+KkmZjJadSOAVgiyn2n8s7sSueY= -github.com/onflow/flow-go v0.35.14-crescendo-preview.27.0.20240626210601-604590f19db9/go.mod h1:SE4kph7kpF6ydOXObtueEecGk3Hrjy/if/0UHY/eRO8= github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo= -github.com/onflow/flow-go-sdk v1.0.0-preview.37 h1:ujeIQheD+skzFt9+eOT9nXcc1rFxVLSCzwisEI3+2DA= -github.com/onflow/flow-go-sdk v1.0.0-preview.37/go.mod h1:2aSN7RdKzxWoCtCyOJz9W/ZNqkLgQDQS3hKLYwPlvGw= +github.com/onflow/flow-go-sdk v1.0.0-preview.38 h1:vzTXhNkklnuxFaqhFeLPry+sud6LzhRMFFQveYJuXt4= +github.com/onflow/flow-go-sdk v1.0.0-preview.38/go.mod h1:SuSH+SB9jONwjhXrb402JM7HfDLAcXRABN1wF+iYAfw= 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= github.com/onflow/flow-nft/lib/go/templates v1.2.0/go.mod h1:p+2hRvtjLUR3MW1NsoJe5Gqgr2eeH49QB6+s6ze00w0= github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231121210617-52ee94b830c2/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= -github.com/onflow/flow/protobuf/go/flow v0.4.4 h1:lD1owoZGFgLcvdLZDmP0Kc4GOuQeSU3/d7hrujFzt6k= -github.com/onflow/flow/protobuf/go/flow v0.4.4/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= +github.com/onflow/flow/protobuf/go/flow v0.4.5 h1:6o+pgYGqwXdEhqSJxu2BdnDXkOQVOkfGAb6IiXB+NPM= +github.com/onflow/flow/protobuf/go/flow v0.4.5/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk= github.com/onflow/go-ethereum v1.13.4 h1:iNO86fm8RbBbhZ87ZulblInqCdHnAQVY8okBrNsTevc= github.com/onflow/go-ethereum v1.13.4/go.mod h1:cE/gEUkAffhwbVmMJYz+t1dAfVNHNwZCgc3BWtZxBGY= github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=