Skip to content

Commit da9697c

Browse files
committed
chore(flipcash): update user_flags to populate supported on ramp providers
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 2be6258 commit da9697c

13 files changed

Lines changed: 176 additions & 8 deletions

File tree

definitions/flipcash/protos/src/main/proto/account/v1/flipcash_account_service.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ message LoginResponse {
5353
message GetUserFlagsRequest {
5454
common.v1.UserId user_id = 1;
5555
common.v1.Auth auth = 2;
56+
common.v1.Platform platform = 3;
57+
common.v1.CountryCode country_code = 4;
5658
}
5759
message GetUserFlagsResponse {
5860
Result result = 1;
@@ -69,4 +71,11 @@ message UserFlags {
6971
bool is_staff = 2;
7072
// Does this user require IAP for registration in the account creation flow?
7173
bool requires_iap_for_registration = 3;
74+
// The set of supported on ramp providers for the user, based on their platform
75+
// and locale if provided
76+
repeated OnRampProvider supported_on_ramp_providers = 4 ;
77+
enum OnRampProvider {
78+
UNKNOWN = 0;
79+
COINBASE = 1;
80+
}
7281
}

definitions/flipcash/protos/src/main/proto/common/v1/common.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ message Response {
9494
ERROR = 1;
9595
}
9696
}
97+
message CountryCode {
98+
// ISO 3166-1 Alpha-2
99+
string value = 1 ;
100+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
syntax = "proto3";
2+
package flipcash.event.v1;
3+
option go_package = "github.com/code-payments/flipcash-protobuf-api/generated/go/event/v1;eventpb";
4+
option java_package = "com.codeinc.flipcash.gen.events.v1";
5+
option objc_class_prefix = "FPBEventV1";
6+
import "event/v1/model.proto";
7+
import "common/v1/common.proto";
8+
import "google/protobuf/timestamp.proto";
9+
10+
service EventStreaming {
11+
// StreamEvents streams events for the requesting user.
12+
rpc StreamEvents(stream StreamEventsRequest) returns (stream StreamEventsResponse);
13+
// ForwardEvents is an internal RPC for forwarding events to another server.
14+
rpc ForwardEvents(ForwardEventsRequest) returns (ForwardEventsResponse);
15+
}
16+
message StreamEventsRequest {
17+
oneof type {
18+
Params params = 1;
19+
ClientPong pong = 2;
20+
}
21+
message Params {
22+
common.v1.Auth auth = 1;
23+
// ts contains the time for stream open.
24+
//
25+
// It is used primarily as a nonce for auth. Server may reject
26+
// timestamps that are too far in the future or past.
27+
google.protobuf.Timestamp ts = 2;
28+
}
29+
}
30+
message StreamEventsResponse {
31+
oneof type {
32+
ServerPing ping = 1;
33+
StreamError error = 2;
34+
EventBatch events = 3;
35+
}
36+
message StreamError {
37+
Code code = 1;
38+
enum Code {
39+
DENIED = 0;
40+
INVALID_TIMESTAMP = 1;
41+
}
42+
}
43+
}
44+
message ForwardEventsRequest {
45+
UserEventBatch user_events = 1;
46+
}
47+
message ForwardEventsResponse {
48+
Result result = 1;
49+
enum Result {
50+
OK = 0;
51+
DENIED = 1;
52+
}
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
syntax = "proto3";
2+
package flipcash.event.v1;
3+
option go_package = "github.com/code-payments/flipcash-protobuf-api/generated/go/event/v1;eventpb";
4+
option java_package = "com.codeinc.flipcash.gen.events.v1";
5+
option objc_class_prefix = "FPBEventV1";
6+
import "common/v1/common.proto";
7+
import "pool/v1/model.proto";
8+
import "google/protobuf/duration.proto";
9+
import "google/protobuf/timestamp.proto";
10+
11+
message EventId {
12+
bytes id = 1 ;
13+
}
14+
// todo: define additional events
15+
message Event {
16+
EventId id = 1;
17+
google.protobuf.Timestamp ts = 2;
18+
oneof type {
19+
TestEvent test = 3;
20+
//
21+
// Section: Betting pools
22+
//
23+
PoolResolvedEvent pool_resolved = 100;
24+
PoolBetUpdateEvent pool_bet_update = 101;
25+
}
26+
}
27+
message EventBatch {
28+
repeated Event events = 1 ;
29+
}
30+
message UserEvent {
31+
common.v1.UserId user_id = 1;
32+
Event event = 2;
33+
}
34+
message UserEventBatch {
35+
repeated UserEvent events = 1 ;
36+
}
37+
message TestEvent {
38+
repeated string hops = 1;
39+
uint64 nonce = 2;
40+
}
41+
// Event sent when a pool has been resolved
42+
message PoolResolvedEvent {
43+
// The latest signed pool metadata, which is guaranteed to contain a resolution
44+
pool.v1.SignedPoolMetadata pool = 1;
45+
// The final bet summary for the pool
46+
pool.v1.BetSummary bet_summary = 2;
47+
// The user's outcome for the pool
48+
pool.v1.UserPoolSummary user_summary = 3;
49+
}
50+
// Event sent when a bet is made against a pool
51+
message PoolBetUpdateEvent {
52+
// The pool ID the bet update is for
53+
pool.v1.PoolId pool_id = 1;
54+
// The latest bet summary for the pool
55+
pool.v1.BetSummary bet_summary = 2;
56+
}
57+
message ServerPing {
58+
// Timestamp the ping was sent on the stream, for client to get a sense
59+
// of potential network latency
60+
google.protobuf.Timestamp timestamp = 1;
61+
// The delay server will apply before sending the next ping
62+
google.protobuf.Duration ping_delay = 2;
63+
}
64+
message ClientPong {
65+
// Timestamp the Pong was sent on the stream, for server to get a sense
66+
// of potential network latency
67+
google.protobuf.Timestamp timestamp = 1;
68+
}

services/flipcash/src/main/kotlin/com/flipcash/services/controllers/AccountController.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import com.flipcash.services.internal.model.account.UserFlags
44
import com.flipcash.services.repository.AccountRepository
55
import com.flipcash.services.user.UserManager
66
import com.getcode.opencode.model.core.ID
7+
import com.getcode.util.locale.LocaleHelper
78
import javax.inject.Inject
89

910
class AccountController @Inject constructor(
1011
private val repository: AccountRepository,
1112
private val userManager: UserManager,
13+
private val localeHelper: LocaleHelper,
1214
) {
1315
suspend fun createAccount(): Result<ID> {
1416
val owner = userManager.accountCluster?.authority?.keyPair
@@ -29,9 +31,12 @@ class AccountController @Inject constructor(
2931
val userId = userManager.accountId
3032
?: return Result.failure(Throwable("No user ID in UserManager"))
3133

34+
val countryCode = localeHelper.getDefaultCountry()
35+
3236
return repository.getUserFlags(
3337
owner = owner,
34-
userId = userId
38+
userId = userId,
39+
countryCode = countryCode
3540
)
3641
}
3742
}

services/flipcash/src/main/kotlin/com/flipcash/services/internal/domain/UserFlagsMapper.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flipcash.services.internal.domain
22

33
import com.codeinc.flipcash.gen.account.v1.FlipcashAccountService
44
import com.flipcash.services.internal.model.account.UserFlags
5+
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
56
import com.getcode.opencode.mapper.Mapper
67
import javax.inject.Inject
78

@@ -11,7 +12,13 @@ internal class UserFlagsMapper @Inject constructor():
1112
return UserFlags(
1213
isRegistered = from.isRegisteredAccount,
1314
isStaff = from.isStaff,
14-
requiresIapForRegistration = from.requiresIapForRegistration
15+
requiresIapForRegistration = from.requiresIapForRegistration,
16+
supportedOnRampProviders = from.supportedOnRampProvidersList.map {
17+
when (it) {
18+
FlipcashAccountService.UserFlags.OnRampProvider.COINBASE -> OnRampProvider.Coinbase
19+
else -> OnRampProvider.Unknown
20+
}
21+
}
1522
)
1623
}
1724
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.flipcash.services.internal.model.account
22

3+
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
4+
35
data class UserFlags(
46
val isStaff: Boolean,
57
val isRegistered: Boolean,
6-
val requiresIapForRegistration: Boolean
8+
val requiresIapForRegistration: Boolean,
9+
val supportedOnRampProviders: List<OnRampProvider>,
710
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.flipcash.services.internal.model.thirdparty
2+
3+
enum class OnRampProvider {
4+
Unknown,
5+
Coinbase;
6+
}

services/flipcash/src/main/kotlin/com/flipcash/services/internal/network/api/AccountApi.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.flipcash.services.internal.network.api
22

33
import com.codeinc.flipcash.gen.account.v1.AccountGrpcKt
4+
import com.codeinc.flipcash.gen.common.v1.Common
45
import com.flipcash.services.internal.annotations.FlipcashManagedChannel
6+
import com.flipcash.services.internal.network.extensions.asCountryCode
57
import com.flipcash.services.internal.network.extensions.asPublicKey
68
import com.flipcash.services.internal.network.extensions.asUserId
79
import com.flipcash.services.internal.network.extensions.authenticate
@@ -61,9 +63,12 @@ internal class AccountApi @Inject constructor(
6163
suspend fun getUserFlags(
6264
userId: ID,
6365
owner: KeyPair,
66+
countryCode: String,
6467
): RpcAccountService.GetUserFlagsResponse {
6568
val request = RpcAccountService.GetUserFlagsRequest.newBuilder()
6669
.setUserId(userId.asUserId())
70+
.setPlatform(Common.Platform.GOOGLE)
71+
.setCountryCode(countryCode.asCountryCode())
6772
.apply { setAuth(authenticate(owner)) }
6873
.build()
6974

services/flipcash/src/main/kotlin/com/flipcash/services/internal/network/extensions/LocalToProtobuf.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,8 @@ internal fun Pair<ApiProvider, String>.asApiKey(): ThirdPartyModels.ApiKey {
138138
)
139139
.setValue(second)
140140
.build()
141+
}
142+
143+
internal fun String.asCountryCode(): Common.CountryCode {
144+
return Common.CountryCode.newBuilder().setValue(this).build()
141145
}

0 commit comments

Comments
 (0)