Skip to content

Commit 562c1a4

Browse files
authored
Merge pull request #644 from code-payments/feat/proto-validation
2 parents 32fde20 + 5851569 commit 562c1a4

70 files changed

Lines changed: 2212 additions & 444 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/flipcash/features/currency-creator/src/main/kotlin/com/flipcash/app/currencycreator/internal/CurrencyCreatorViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.getcode.opencode.internal.solana.model.SwapId
4141
import com.getcode.opencode.model.core.errors.CheckTokenAvailabilityError
4242
import com.getcode.opencode.model.core.errors.GetMintsError
4343
import com.getcode.opencode.model.core.errors.LaunchTokenError
44+
import com.getcode.opencode.model.core.errors.ValidationException
4445
import com.getcode.opencode.model.financial.MintMetadata
4546
import com.getcode.opencode.model.financial.Token
4647
import com.getcode.opencode.model.financial.TokenCreateRequest
@@ -280,6 +281,7 @@ internal class CurrencyCreatorViewModel @Inject constructor(
280281
onError = { cause ->
281282
dispatchEvent(Event.UpdateProcessingState())
282283
when (cause) {
284+
is ValidationException,
283285
is TextModerationError.Flagged,
284286
is TextModerationError.Denied -> {
285287
BottomBarManager.showAlert(
@@ -330,6 +332,7 @@ internal class CurrencyCreatorViewModel @Inject constructor(
330332
dispatchEvent(Event.UpdateProcessingState())
331333
stateFlow.value.icon.dataOrNull?.let { contentReader.removeFromCache(it) }
332334
when (cause) {
335+
is ValidationException,
333336
is ImageModerationError.Flagged,
334337
is ImageModerationError.Denied -> {
335338
BottomBarManager.showAlert(
@@ -379,6 +382,7 @@ internal class CurrencyCreatorViewModel @Inject constructor(
379382
onError = { cause ->
380383
dispatchEvent(Event.UpdateProcessingState())
381384
when (cause) {
385+
is ValidationException,
382386
is TextModerationError.Flagged,
383387
is TextModerationError.Denied -> {
384388
BottomBarManager.showAlert(

apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class SwapViewModelErrorTest {
9898
fun `buy failure shows buySellFailed error`() = runTest(mainCoroutineRule.dispatcher) {
9999
dispatchers = TestDispatchers(testScheduler)
100100
transactionController.stub {
101-
onBlocking { buy(any(), any(), anyOrNull(), any(), any(), anyOrNull()) } doReturn
101+
onBlocking { buy(any(), any(), anyOrNull(), anyOrNull(), any(), anyOrNull(), anyOrNull()) } doReturn
102102
Result.failure(RuntimeException("buy failed"))
103103
}
104104

definitions/flipcash/models/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import dev.bmcreations.protovalidate.gradle.ProtoVariant
12
import org.apache.tools.ant.taskdefs.condition.Os
23

34
plugins {
45
alias(libs.plugins.flipcash.android.library)
5-
id("com.google.protobuf")
6+
alias(libs.plugins.protobuf)
7+
alias(libs.plugins.protobuf.validate)
68
}
79

810
val archSuffix = if (Os.isFamily(Os.FAMILY_MAC)) ":osx-x86_64" else ""
@@ -64,3 +66,7 @@ protobuf {
6466
}
6567
}
6668
}
69+
70+
protovalidate {
71+
variant.set(ProtoVariant.PGV)
72+
}
Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
syntax = "proto3";
2+
23
package flipcash.account.v1;
4+
35
option go_package = "github.com/code-payments/flipcash2-protobuf-api/generated/go/account/v1;acountpb";
46
option java_package = "com.codeinc.flipcash.gen.account.v1";
57
option objc_class_prefix = "FPBAccountV1";
8+
69
import "common/v1/common.proto";
710
import "google/protobuf/duration.proto";
811
import "google/protobuf/timestamp.proto";
12+
import "validate/validate.proto";
913

1014
service Account {
1115
// Register registers a new user, bound to the provided PublicKey.
1216
// If the PublicKey is already in use, the previous user account is returned.
1317
rpc Register(RegisterRequest) returns (RegisterResponse);
18+
1419
// Login retrieves the UserId (and in the future, potentially other information)
1520
// required for 'recovering' an account.
1621
rpc Login(LoginRequest) returns (LoginResponse);
22+
1723
// GetUserFlags gets user-specific flags.
1824
rpc GetUserFlags(GetUserFlagsRequest) returns (GetUserFlagsResponse);
25+
1926
// GetUserFlags gets user flags for unauthenticated users
2027
rpc GetUnauthenticatedUserFlags(GetUnauthenticatedUserFlagsRequest) returns (GetUnauthenticatedUserFlagsResponse);
2128
}
29+
2230
message RegisterRequest {
2331
// PublicKey the public key that is authorized to perform actions on the
2432
// registered users behalf.
25-
common.v1.PublicKey public_key = 1;
33+
common.v1.PublicKey public_key = 1 [(validate.rules).message.required = true];
34+
2635
// Signature of this message (without the signature), using the provided keypair.
27-
common.v1.Signature signature = 2;
36+
common.v1.Signature signature = 2 [(validate.rules).message.required = true];
2837
}
2938
message RegisterResponse {
3039
Result result = 1;
@@ -33,16 +42,19 @@ message RegisterResponse {
3342
INVALID_SIGNATURE = 1;
3443
DENIED = 2;
3544
}
45+
3646
// The UserId associated with the account.
3747
common.v1.UserId user_id = 2;
3848
}
49+
3950
message LoginRequest {
4051
// Timestamp is the timestamp the request was generated
4152
//
4253
// The server may reject the request if the timestamp is too far off
4354
// the current (server) time. This is to prevent replay attacks.
44-
google.protobuf.Timestamp timestamp = 1;
45-
common.v1.Auth auth = 2;
55+
google.protobuf.Timestamp timestamp = 1 [(validate.rules).timestamp.required = true];
56+
57+
common.v1.Auth auth = 2 [(validate.rules).message.required = true];
4658
}
4759
message LoginResponse {
4860
Result result = 1;
@@ -51,12 +63,17 @@ message LoginResponse {
5163
INVALID_TIMESTAMP = 1;
5264
DENIED = 2;
5365
}
66+
5467
common.v1.UserId user_id = 2;
5568
}
69+
5670
message GetUserFlagsRequest {
57-
common.v1.UserId user_id = 1;
58-
common.v1.Auth auth = 2;
71+
common.v1.UserId user_id = 1 [(validate.rules).message.required = true];
72+
73+
common.v1.Auth auth = 2 [(validate.rules).message.required = true];
74+
5975
common.v1.Platform platform = 3;
76+
6077
common.v1.CountryCode country_code = 4;
6178
}
6279
message GetUserFlagsResponse {
@@ -65,26 +82,34 @@ message GetUserFlagsResponse {
6582
OK = 0;
6683
DENIED = 1;
6784
}
85+
6886
UserFlags user_flags = 2;
6987
}
88+
7089
message GetUnauthenticatedUserFlagsRequest {
7190
common.v1.Platform platform = 1;
91+
7292
common.v1.CountryCode country_code = 2;
7393
}
7494
message GetUnauthenticatedUserFlagsResponse {
7595
Result result = 1;
7696
enum Result {
7797
OK = 0;
7898
}
99+
79100
UserFlags user_flags = 2;
80101
}
102+
81103
message UserFlags {
82104
// Is this a fully registered account using IAP for account creation?
83105
bool is_registered_account = 1;
106+
84107
// Is this user associated with a Flipcash staff member?
85108
bool is_staff = 2;
109+
86110
// Does this user require IAP for registration in the account creation flow?
87111
bool requires_iap_for_registration = 3;
112+
88113
enum OnRampProvider {
89114
UNKNOWN = 0;
90115
COINBASE_VIRTUAL = 1;
@@ -96,20 +121,28 @@ message UserFlags {
96121
BACKPACK = 7;
97122
BASE = 8;
98123
}
124+
99125
// The set of supported on ramp providers for the user, based on their platform
100126
// and locale if provided
101-
repeated OnRampProvider supported_on_ramp_providers = 4 ;
127+
repeated OnRampProvider supported_on_ramp_providers = 4 [(validate.rules).repeated = {
128+
min_items: 0
129+
max_items: 256
130+
}];
102131

103132
// The preferred on ramp provider for this user. If the value is UNKNOWN, client
104133
// should show the list of all supported providers.
105134
OnRampProvider preferred_on_ramp_provider = 5;
135+
106136
// The minumum build number for this user. If their build number is less than the
107137
// provided value, client should show a forced upgrade screen.
108138
uint32 min_build_number = 6;
139+
109140
// Exchange data timeout for sequential give/grabs for bills
110141
google.protobuf.Duration bill_exchange_data_timeout = 7;
142+
111143
// USDF amount, in quarks, that must be purchased when launching a new currency
112144
uint64 new_currency_purchase_amount = 8;
145+
113146
// USDF amount, in quarks, that must be paid in a fee when launching a new currency
114147
uint64 new_currency_fee_amount = 9;
115148
}
Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,88 @@
11
syntax = "proto3";
2+
23
package flipcash.activity.v1;
4+
35
option go_package = "github.com/code-payments/flipcash2-protobuf-api/generated/go/activity/v1;activitypb";
46
option java_package = "com.codeinc.flipcash.gen.activity.v1";
57
option objc_class_prefix = "FPBActivityV1";
8+
69
import "activity/v1/model.proto";
710
import "common/v1/common.proto";
11+
import "validate/validate.proto";
812

913
service ActivityFeed {
1014
// GetLatestNotifications gets the latest N notifications in a user's
1115
// activity feed. Results will be ordered by descending timestamp.
1216
rpc GetLatestNotifications(GetLatestNotificationsRequest) returns (GetLatestNotificationsResponse);
17+
1318
// GetPagedNotifications gets all notifications using a paging API.
1419
rpc GetPagedNotifications(GetPagedNotificationsRequest) returns (GetPagedNotificationsResponse);
20+
1521
// GetBatchNotifications gets a batch of notifications by ID.
1622
rpc GetBatchNotifications(GetBatchNotificationsRequest) returns (GetBatchNotificationsResponse);
1723
}
24+
1825
message GetLatestNotificationsRequest {
1926
// The activity feed to fetch notifications from
20-
ActivityFeedType type = 1;
27+
ActivityFeedType type = 1 [(validate.rules).enum.in = 1];
28+
2129
// Maximum number of notifications to return. If <= 0, the server default is used
22-
int32 max_items = 2;
23-
common.v1.Auth auth = 3;
30+
int32 max_items = 2 [(validate.rules).int32.lte = 1024];
31+
32+
common.v1.Auth auth = 3 [(validate.rules).message.required = true];
2433
}
34+
2535
message GetLatestNotificationsResponse {
2636
Result result = 1;
2737
enum Result {
2838
OK = 0;
2939
DENIED = 1;
3040
}
31-
repeated Notification notifications = 2 ;
41+
42+
repeated Notification notifications = 2 [(validate.rules).repeated = {
43+
max_items: 1024
44+
}];
3245
}
46+
3347
message GetPagedNotificationsRequest {
3448
// The activity feed to fetch notifications from
35-
ActivityFeedType type = 1;
36-
common.v1.QueryOptions query_options = 2;
37-
common.v1.Auth auth = 3;
49+
ActivityFeedType type = 1 [(validate.rules).enum.in = 1];
50+
51+
common.v1.QueryOptions query_options = 2 [(validate.rules).message.required = true];
52+
53+
common.v1.Auth auth = 3 [(validate.rules).message.required = true];
3854
}
55+
3956
message GetPagedNotificationsResponse {
4057
Result result = 1;
4158
enum Result {
4259
OK = 0;
4360
DENIED = 1;
4461
}
45-
repeated Notification notifications = 2 ;
62+
63+
repeated Notification notifications = 2 [(validate.rules).repeated = {
64+
max_items: 1024
65+
}];
4666
}
67+
4768
message GetBatchNotificationsRequest {
48-
repeated NotificationId ids = 1 ;
49-
common.v1.Auth auth = 2;
69+
repeated NotificationId ids = 1 [(validate.rules).repeated = {
70+
min_items: 1
71+
max_items: 1024
72+
}];
73+
74+
common.v1.Auth auth = 2 [(validate.rules).message.required = true];
5075
}
76+
5177
message GetBatchNotificationsResponse {
5278
Result result = 1;
5379
enum Result {
5480
OK = 0;
5581
DENIED = 1;
5682
NOT_FOUND = 2;
5783
}
58-
repeated Notification notifications = 2 ;
84+
85+
repeated Notification notifications = 2 [(validate.rules).repeated = {
86+
max_items: 1024
87+
}];
5988
}

0 commit comments

Comments
 (0)