From c0a2c11418d5d31891ba6bcc5aebc377ae317892 Mon Sep 17 00:00:00 2001 From: Carter Jernigan Date: Wed, 1 Feb 2023 05:14:55 -0500 Subject: [PATCH] [#615] Refactor lightwalletd client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#615] Refactor lightwalletd client This moves the lightwalletd client code to a separate Gradle module, but does not yet do much clean up the public API (e.g. hiding generated GRPC objects). That will be a followon change via #673 I’ve prototyped a safer version of the API that would be implemented for #673 for two specific calls: obtaining the current block height and obtaining the light wallet info. These were the easiest endpoints to update and they provide a useful exploration for the future changes needed. * Fix benchmarking for networking module - Moved to fixture and build type check components to the new networking module, so it's accessible from all needed parts of the projects - Changed fixture return type to fit to all needed usages * Align with previous review comment * Fix wrong merge * Add basic sanity test - To satisfy tests requirements on emulators.wtf service * Remove grpc dependency from sdk-lib module * Repackage cash.z.wallet.sdk.rpc to cash.z.wallet.sdk.internal.rpc * Fix BuildConfig path * Update demo-app paths to rpc * Fix broken grpc services locations - Our aim here is to change only the local services location (package name), the server location can't be changed due to backward compatibility. * Enhance GRPC Response model * Adopt enhanced GRPC response model - Adopted in a few endpoints * Enhance Connection failure type * Add simple fixture test * Refactor fetchTransaction() to work with Response - Refactored this server call to adopt our new Response mechanism - GrpsStatusResolver.resolveFailureFromStatus() now accepts Throwable input - Added Response.Failure.toThrowable() to satisfy subsequent server calls results processing - A few other minor refactoring changes * Remove commented out log * Unify return type of collection returning methods - Switched fetchUtxos() to return Sequence instead of List - Added a check on empty tAddress input * fetchUtxos returns flow - Switched fetchUtxos() to return Flow of Service.GetAddressUtxosReply - Internally it calls getAddressUtxosStream() instead of getAddressUtxos() from GRPC layer * Update unsafe suffix documentation * Address several minor change requests * Remove code parameter - Removed from the locally triggered failures with default codes. * Rename local variable * Switch from empty response to exception - Our server calls now rather throw IllegalArgumentException than return an empty response - Removed commented out log message - Updated javadocs * Update proto files - Plus related api changes adoption * Unify new clients instances name * AGP 7.4.0 changes - packagingOptions -> androidComponents in sdk-lib and lightwallet-client-lib modules * SDK version bump * Response resolver tests * Release build upload timeout increase * Release build upload timeout increase fix * Revert timeout - As Github has some infrastructure troubles and we need to wait * Add migrations documentation * Sort packaging filters * Remove private field from public documentation * Hide private variables * Remove package from Android Manifest * Throw exception instead of custom error - This step unify our approach to validation on client side across all server calls * Replace setAddresses index const with number * Fix indentation in proto file --------- Co-authored-by: Honza --- .gitignore | 1 + .run/_sdkLib_connectedCheck.run.xml | 11 +- CHANGELOG.md | 10 + MIGRATIONS.md | 10 + darkside-test-lib/build.gradle.kts | 1 + .../darkside/MultiRecipientIntegrationTest.kt | 4 +- .../sdk/darkside/reorgs/ReorgLargeTest.kt | 4 +- .../darkside/test/DarksideTestCoordinator.kt | 44 ++-- .../android/sdk/darkside/test/TestWallet.kt | 8 +- .../sdk/sample/demoapp/SampleCodeTest.kt | 50 ++-- .../android/sdk/demoapp/BaseDemoFragment.kt | 4 +- .../z/ecc/android/sdk/demoapp/MainActivity.kt | 17 +- .../android/sdk/demoapp/SharedViewModel.kt | 8 +- .../android/sdk/demoapp/WalletCoordinator.kt | 2 +- .../demos/getblock/GetBlockFragment.kt | 9 +- .../getblockrange/GetBlockRangeFragment.kt | 16 +- .../GetLatestHeightFragment.kt | 2 +- .../demos/listutxos/ListUtxosFragment.kt | 7 +- .../sdk/demoapp/util/BenchmarkTrace.kt | 2 +- .../z/ecc/android/sdk/demoapp/util/Ext.kt | 2 +- docs/Architecture.md | 49 +++- gradle.properties | 3 +- lightwallet-client-lib/build.gradle.kts | 240 ++++++++++++++++++ lightwallet-client-lib/lint-baseline.xml | 48 ++++ lightwallet-client-lib/lint.xml | 4 + lightwallet-client-lib/packages.md | 7 + lightwallet-client-lib/proguard-consumer.txt | 22 ++ lightwallet-client-lib/proguard-project.txt | 18 ++ .../src/androidTest/AndroidManifest.xml | 9 + .../client/ext/BenchmarkingExtTest.kt | 22 ++ .../client/fixture/BlockRangeFixtureTest.kt | 17 ++ .../client/fixture/StatusExceptionFixture.kt | 13 + .../client/internal/ChannelFactoryTest.kt | 19 ++ .../client/internal/GrpcStatusResolverTest.kt | 59 +++++ .../lightwallet/client/test/Global.kt | 12 + .../src/main/AndroidManifest.xml | 4 + .../client/BlockingLightWalletClient.kt | 103 ++++++++ .../client/CoroutineLightWalletClient.kt | 104 ++++++++ .../client}/ext/BenchmarkingExt.kt | 4 +- .../client/fixture/BlockRangeFixture.kt | 25 ++ .../client/internal/ApiStatusResolver.kt | 10 + .../internal/BlockingLightWalletClientImpl.kt | 192 ++++++++++++++ .../client/internal/ChannelFactory.kt | 30 +++ .../lightwallet/client/internal/Constants.kt | 6 + .../CoroutineLightWalletClientImpl.kt | 192 ++++++++++++++ .../client/internal}/DarksideApi.kt | 115 +++++---- .../client/internal/GrpcStatusResolver.kt | 67 +++++ .../client/model/BlockHeightUnsafe.kt | 18 ++ .../client}/model/LightWalletEndpoint.kt | 2 +- .../model/LightWalletEndpointInfoUnsafe.kt | 23 ++ .../client/model/RawTransactionUnsafe.kt | 17 ++ .../lightwallet/client/model/Response.kt | 103 ++++++++ .../client/model/SendResponseUnsafe.kt | 23 ++ .../src/main/proto/compact_formats.proto | 67 +++++ .../src/main/proto/darkside.proto | 25 +- .../src/main/proto/service.proto | 29 ++- sdk-lib/build.gradle.kts | 88 ++----- .../sdk/integration/TestnetIntegrationTest.kt | 19 +- .../integration/service/ChangeServiceTest.kt | 121 +-------- .../sdk/internal/SdkSynchronizerTest.kt | 2 +- .../PersistentTransactionManagerTest.kt | 4 +- .../android/sdk/util/BalancePrinterUtil.kt | 2 +- .../ecc/android/sdk/util/DataDbScannerUtil.kt | 2 +- .../cash/z/ecc/android/sdk/util/TestWallet.kt | 4 +- .../sdk/util/TransactionCounterUtil.kt | 35 ++- sdk-lib/src/main/AndroidManifest.xml | 4 +- .../cash/z/ecc/android/sdk/SdkSynchronizer.kt | 34 +-- .../cash/z/ecc/android/sdk/Synchronizer.kt | 10 +- .../sdk/block/CompactBlockProcessor.kt | 237 +++++++++-------- .../z/ecc/android/sdk/exception/Exceptions.kt | 6 +- .../android/sdk/fixture/BlockRangeFixture.kt | 24 -- .../internal/block/CompactBlockDownloader.kt | 117 +++------ .../db/block/DbCompactBlockRepository.kt | 2 +- .../android/sdk/internal/ext/WalletService.kt | 26 -- .../internal/model/BlockHeightUnsafeExt.kt | 11 + .../repository/CompactBlockRepository.kt | 2 +- .../service/LightWalletGrpcService.kt | 210 --------------- .../internal/service/LightWalletService.kt | 96 ------- .../PersistentTransactionManager.kt | 35 ++- .../sdk/model/LightWalletEndpointExt.kt | 2 + sdk-lib/src/main/proto/compact_formats.proto | 48 ---- .../sdk/model/LightWalletEndpointTest.kt | 1 + settings.gradle.kts | 31 ++- 83 files changed, 2070 insertions(+), 1016 deletions(-) create mode 100644 lightwallet-client-lib/build.gradle.kts create mode 100644 lightwallet-client-lib/lint-baseline.xml create mode 100644 lightwallet-client-lib/lint.xml create mode 100644 lightwallet-client-lib/packages.md create mode 100644 lightwallet-client-lib/proguard-consumer.txt create mode 100644 lightwallet-client-lib/proguard-project.txt create mode 100644 lightwallet-client-lib/src/androidTest/AndroidManifest.xml create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/ext/BenchmarkingExtTest.kt create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/fixture/BlockRangeFixtureTest.kt create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/fixture/StatusExceptionFixture.kt create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/internal/ChannelFactoryTest.kt create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/internal/GrpcStatusResolverTest.kt create mode 100644 lightwallet-client-lib/src/androidTest/java/co/electriccoin/lightwallet/client/test/Global.kt create mode 100644 lightwallet-client-lib/src/main/AndroidManifest.xml create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/BlockingLightWalletClient.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/CoroutineLightWalletClient.kt rename {sdk-lib/src/main/java/cash/z/ecc/android/sdk => lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client}/ext/BenchmarkingExt.kt (63%) create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/fixture/BlockRangeFixture.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/ApiStatusResolver.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/ChannelFactory.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/Constants.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt rename {darkside-test-lib/src/androidTest/java/cash/z/ecc/android/sdk/darkside/test => lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal}/DarksideApi.kt (53%) create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/GrpcStatusResolver.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/BlockHeightUnsafe.kt rename {sdk-lib/src/main/java/cash/z/ecc/android/sdk => lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client}/model/LightWalletEndpoint.kt (69%) create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/LightWalletEndpointInfoUnsafe.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/RawTransactionUnsafe.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/Response.kt create mode 100644 lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/SendResponseUnsafe.kt create mode 100644 lightwallet-client-lib/src/main/proto/compact_formats.proto rename {sdk-lib => lightwallet-client-lib}/src/main/proto/darkside.proto (86%) rename {sdk-lib => lightwallet-client-lib}/src/main/proto/service.proto (84%) delete mode 100644 sdk-lib/src/main/java/cash/z/ecc/android/sdk/fixture/BlockRangeFixture.kt create mode 100644 sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/BlockHeightUnsafeExt.kt delete mode 100644 sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/service/LightWalletGrpcService.kt delete mode 100644 sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/service/LightWalletService.kt delete mode 100644 sdk-lib/src/main/proto/compact_formats.proto diff --git a/.gitignore b/.gitignore index b0d34f04..117f0386 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ captures/ .idea/tasks.xml .idea/vcs.xml .idea/workspace.xml +.idea/protoeditor.xml *.iml # Keystore files diff --git a/.run/_sdkLib_connectedCheck.run.xml b/.run/_sdkLib_connectedCheck.run.xml index e922487e..44b8b56d 100644 --- a/.run/_sdkLib_connectedCheck.run.xml +++ b/.run/_sdkLib_connectedCheck.run.xml @@ -1,6 +1,6 @@ - +