Skip to content

Commit 819aa10

Browse files
committed
chore: update ocp protos to support new multi-mint give request
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 27376cf commit 819aa10

File tree

7 files changed

+63
-46
lines changed

7 files changed

+63
-46
lines changed

definitions/opencode/protos/src/main/proto/messaging/v1/messaging_service.proto

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ service Messaging {
1515
// and are eligible for deletion from the service. Clients should, however, handle
1616
// duplicate delivery of messages.
1717
//
18-
// For grabbing a bill, the expected flow is as follows:
19-
// 1. The payment sender creates a cash scan code
20-
// 2. The payment sender calls OpenMessageStream on the rendezvous public key, which is
21-
// derived by using sha256(scan payload) as the keypair seed.
22-
// 3. The payment recipient scans the code and uses SendMessage to send their account ID
23-
// back to the sender via the rendezvous public key.
24-
// 4. The payment sender receives the message, submits the intent, and closes the stream.
18+
// For giving/grabbing a bill, the expected flow is as follows:
19+
// 1. The payment sender creates a multi-mint cash scan code.
20+
// 2. The payment sender calls OpenMessageStream on the rendezvous public key.
21+
// 3. The payment sender uses SendMessage to send the mint in a RequestToGiveBill message.
22+
// 4. The payment sender shows the bill with the scan code containing the rendezvous public key.
23+
// 5. The payment recipient scans the code.
24+
// 6. The payment recipient uses PollMessages to get the RequestToGiveBill message from part 3.
25+
// 7. The payment recipient sends the destination address in a RequestToGrabBill message.
26+
// 8. The payment sender receives the RequestToGrabBill message in real time, submits the intent
27+
// for the payment to the provided destination, and then closes the stream.
2528
rpc OpenMessageStream(OpenMessageStreamRequest) returns (stream OpenMessageStreamResponse);
2629
// OpenMessageStreamWithKeepAlive is like OpenMessageStream, but enables a ping/pong
2730
// keepalive to determine the health of the stream at both the client and server.
@@ -134,10 +137,17 @@ message MessageId {
134137
//
135138
// This message type is only initiated by clients.
136139
message RequestToGrabBill {
137-
// Requestor is the virtual core mint token account on the VM to which a
138-
// payment should be sent.
140+
// Requestor is the virtual token account on the VM to which a payment
141+
// should be sent.
139142
common.v1.SolanaAccountId requestor_account = 1;
140143
}
144+
// Request that a bill be given in the desired mint
145+
//
146+
// This message type is only initiated by clients.
147+
message RequestToGiveBill {
148+
// The mint that the bill will be received in
149+
common.v1.SolanaAccountId mint = 1;
150+
}
141151
message Message {
142152
// MessageId is the Id of the message. This ID is generated by the
143153
// server, and will _always_ be set when receiving a message.
@@ -155,7 +165,8 @@ message Message {
155165
//
156166
// Section: Cash
157167
//
158-
RequestToGrabBill request_to_grab_bill = 2;
168+
RequestToGrabBill request_to_grab_bill = 2;
169+
RequestToGiveBill request_to_give_bill = 13;
159170
}
160171
reserved 4; // Deprecated AirdropReceived field
161172
reserved 5; // Deprecated RequestToReceiveBill field

definitions/opencode/protos/src/main/proto/transaction/v2/transaction_service.proto

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ message CanWithdrawToAccountResponse {
209209
//
210210
// This will be set when requires_initialization = true
211211
//
212-
// Note: The fee is always paid in the core mint.
212+
// Note: The fee is always paid in the target mint.
213213
ExchangeDataWithoutRate fee_amount = 4;
214214
}
215215
message AirdropRequest {
@@ -345,7 +345,7 @@ message SendPublicPaymentMetadata {
345345
message ReceivePaymentsPubliclyMetadata {
346346
// The remote send gift card to receive funds from
347347
common.v1.SolanaAccountId source = 1;
348-
// The exact amount of core mint quarks being received
348+
// The exact amount of quarks being received
349349
uint64 quarks = 2;
350350
// Is the receipt of funds from a remote send gift card? Currently, this is
351351
// the only use case for this intent and validation enforces the flag to true.
@@ -443,7 +443,7 @@ message NoPrivacyTransferAction {
443443
common.v1.SolanaAccountId source = 2;
444444
// The destination account where funds are transferred to
445445
common.v1.SolanaAccountId destination = 3;
446-
// The core mint quark amount to transfer
446+
// The quark amount to transfer
447447
uint64 amount = 4;
448448
// The mint that this action will be operating against. For backwards
449449
// compatibility, if no mint is set, then it is assumed to be the core
@@ -458,7 +458,7 @@ message NoPrivacyWithdrawAction {
458458
common.v1.SolanaAccountId source = 2;
459459
// The destination account where funds are transferred to
460460
common.v1.SolanaAccountId destination = 3;
461-
// The intended core mint quark amount to withdraw
461+
// The quark amount to withdraw
462462
uint64 amount = 4;
463463
// Whether the account is closed afterwards. This is always true, since there
464464
// are no current se cases to leave it open.
@@ -484,7 +484,7 @@ message FeePaymentAction {
484484
common.v1.SolanaAccountId authority = 2;
485485
// The source account where funds are transferred from
486486
common.v1.SolanaAccountId source = 3;
487-
// The core mint quark amount to transfer
487+
// The quark amount to transfer
488488
uint64 amount = 4;
489489
// The mint that this action will be operating against. For backwards
490490
// compatibility, if no mint is set, then it is assumed to be the core

services/opencode/src/main/kotlin/com/getcode/opencode/internal/domain/mapping/MessageMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal class MessageMapper @Inject constructor():
2121
signature = signature,
2222
kind = when(from.kindCase) {
2323
MessagingService.Message.KindCase.REQUEST_TO_GRAB_BILL -> from.requestToGrabBill.toMessageKind()
24+
MessagingService.Message.KindCase.REQUEST_TO_GIVE_BILL -> from.requestToGiveBill.toMessageKind()
2425
MessagingService.Message.KindCase.KIND_NOT_SET -> MessageKind.Unknown
2526
else -> MessageKind.Unknown
2627
}

services/opencode/src/main/kotlin/com/getcode/opencode/internal/network/api/MessagingApi.kt

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,16 @@ internal class MessagingApi @Inject constructor(
3838
*
3939
* <p>
4040
*
41-
* For grabbing a bill, the expected flow is as follows:
42-
*
43-
* 1. The payment sender creates a cash scan code
44-
* 2. The payment sender calls OpenMessageStream on the rendezvous public key, which is
45-
* derived by using sha256(scan payload) as the keypair seed.
46-
* 3. The payment recipient scans the code and uses SendMessage to send their account ID
47-
* back to the sender via the rendezvous public key.
48-
* 4. The payment sender receives the message, submits the intent, and closes the stream.
49-
*
50-
* <p>
51-
*
52-
* For receiving a bill of requested value, the expected flow is as follows:
53-
*
54-
* 1. The payment recipient uses SendMessage to send their account ID and payment amount to
55-
* the sender via the rendezvous public key, which is derived by using sha256(scan payload)
56-
* as the keypair seed.
57-
* 2. The payment recipient calls OpenMessageStream on the rendezvous public key to listen
58-
* for status messages generated by client/server. It must ignore the original message it sent
59-
* as part of step 1.
60-
* 3. The payment recipient creates a payment request scan code
61-
* 4. The payment sender calls PollMessages on the rendezvous public key. This is ok because
62-
* we know the message exists per step 1, and doesn't actually incur a long poll. This is a
63-
* required hack because we don't have the infrastructure in place to allow multiple listens
64-
* on the same stream, and the recipient needs real-time status updates.
65-
* 5. The payment sender receives the message (any status messages are ignored), and submits the
66-
* intent.
67-
* 6. The payment recipient observes status message (eg. IntentSubmitted, ClientRejectedPayment,
68-
* WebhookCalled) for payment state.
69-
* 7. The payment recipient closes the stream once the payment hits a terminal state, or times out.
41+
* For giving/grabbing a bill, the expected flow is as follows:
42+
* 1. The payment sender creates a multi-mint cash scan code.
43+
* 2. The payment sender calls OpenMessageStream on the rendezvous public key.
44+
* 3. The payment sender uses SendMessage to send the mint in a RequestToGiveBill message.
45+
* 4. The payment sender shows the bill with the scan code containing the rendezvous public key.
46+
* 5. The payment recipient scans the code.
47+
* 6. The payment recipient uses PollMessages to get the RequestToGiveBill message from part 3.
48+
* 7. The payment recipient sends the destination address in a RequestToGrabBill message.
49+
* 8. The payment sender receives the RequestToGrabBill message in real time, submits the intent
50+
* for the payment to the provided destination, and then closes the stream.
7051
*
7152
*/
7253
fun openMessageStream(

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.getcode.opencode.internal.network.extensions
22

33
import com.codeinc.opencode.gen.common.v1.Model
44
import com.codeinc.opencode.gen.messaging.v1.MessagingService
5+
import com.codeinc.opencode.gen.messaging.v1.requestToGiveBill
56
import com.codeinc.opencode.gen.messaging.v1.requestToGrabBill
67
import com.codeinc.opencode.gen.transaction.v2.TransactionService
78
import com.codeinc.opencode.gen.transaction.v2.TransactionService.OpenAccountsMetadata.AccountSet
@@ -185,6 +186,12 @@ internal fun Message.asProtobufMessage(): MessagingService.Message {
185186
}
186187
}
187188

189+
is MessageKind.RequestToGiveBill -> {
190+
builder.requestToGiveBill = requestToGiveBill {
191+
mint = kind.mint.asSolanaAccountId()
192+
}
193+
}
194+
188195
MessageKind.Unknown -> Unit
189196
}
190197

services/opencode/src/main/kotlin/com/getcode/opencode/internal/network/extensions/ProtobufToLocal.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ internal fun MessagingService.RequestToGrabBill.toMessageKind(): MessageKind.Req
5252
)
5353
}
5454

55+
internal fun MessagingService.RequestToGiveBill.toMessageKind(): MessageKind.RequestToGiveBill {
56+
return MessageKind.RequestToGiveBill(
57+
mint = mint.toPublicKey()
58+
)
59+
}
60+
5561
internal fun TransactionService.Metadata.toMetadata(): TransactionMetadata {
5662
return when (val case = typeCase) {
5763
TransactionService.Metadata.TypeCase.OPEN_ACCOUNTS -> TransactionMetadata.OpenAccount(openAccounts.accountSet.toAccountType())

services/opencode/src/main/kotlin/com/getcode/opencode/model/messaging/Message.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,26 @@ sealed interface MessageKind {
3232

3333
// region Cash
3434
/**
35-
* Represents a request to send a pulled out bill to the specified address.
35+
* Represents a request that a pulled out bill be sent to the requested address.
3636
* <p>
3737
* This message type can only be initiated by clients.
3838
*
39-
* @param requestor is the Kin token account on Solana to which a payment should be sent.
39+
* @param requestor is the virtual token account on the VM to which a payment
4040
*/
4141
data class RequestToGrabBill(
4242
val requestor: PublicKey
4343
): MessageKind
44+
45+
/**
46+
* Represents a request that a bill be given in the desired mint
47+
* <p>
48+
* This message type can only be initiated by clients.
49+
*
50+
* @param mint is the mint that the bill will be received in
51+
*/
52+
data class RequestToGiveBill(
53+
val mint: PublicKey
54+
): MessageKind
4455
// endregion
4556

4657
data object Unknown: MessageKind

0 commit comments

Comments
 (0)