@@ -15,13 +15,13 @@ import (
15
15
messagingpb "github.com/code-payments/code-protobuf-api/generated/go/messaging/v1"
16
16
transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2"
17
17
18
+ "github.com/code-payments/code-server/pkg/code/common"
19
+ "github.com/code-payments/code-server/pkg/code/limit"
18
20
currency_lib "github.com/code-payments/code-server/pkg/currency"
19
21
"github.com/code-payments/code-server/pkg/kikcode"
20
22
"github.com/code-payments/code-server/pkg/kin"
21
23
"github.com/code-payments/code-server/pkg/netutil"
22
24
"github.com/code-payments/code-server/pkg/solana"
23
- "github.com/code-payments/code-server/pkg/code/common"
24
- "github.com/code-payments/code-server/pkg/code/limit"
25
25
)
26
26
27
27
type trustedPaymentRequest struct {
@@ -138,35 +138,23 @@ func (r *trustedPaymentRequest) GetPrivateRendezvousKey() *common.Account {
138
138
}
139
139
140
140
type trustlessPaymentRequest struct {
141
- currency currency_lib.Code
142
- nativeAmount float64
143
- destination * common.Account
144
-
145
- publicRendezvousKey * common.Account
146
- clientSignature solana.Signature // For a messagingpb.RequestToReceiveBill
147
-
148
- webhookUrl * string
141
+ originalProtoMessage * messagingpb.RequestToReceiveBill
142
+ publicRendezvousKey * common.Account
143
+ clientSignature solana.Signature // For a messagingpb.RequestToReceiveBill
144
+ webhookUrl * string
149
145
}
150
146
151
147
func newTrustlessPaymentRequest (
152
- currency currency_lib.Code ,
153
- nativeAmount float64 ,
154
- destination * common.Account ,
155
-
148
+ originalProtoMessage * messagingpb.RequestToReceiveBill ,
156
149
publicRendezvousKey * common.Account ,
157
150
clientSignature solana.Signature ,
158
-
159
151
webhookUrl * string ,
160
152
) (* trustlessPaymentRequest , error ) {
161
153
return & trustlessPaymentRequest {
162
- currency : currency ,
163
- nativeAmount : nativeAmount ,
164
- destination : destination ,
165
-
166
- publicRendezvousKey : publicRendezvousKey ,
167
- clientSignature : clientSignature ,
168
-
169
- webhookUrl : webhookUrl ,
154
+ originalProtoMessage : originalProtoMessage ,
155
+ publicRendezvousKey : publicRendezvousKey ,
156
+ clientSignature : clientSignature ,
157
+ webhookUrl : webhookUrl ,
170
158
}, nil
171
159
}
172
160
@@ -193,15 +181,15 @@ func newTrustlessPaymentRequestFromHttpContext(r *http.Request) (*trustlessPayme
193
181
return nil , errors .New ("intent is not a public key" )
194
182
}
195
183
196
- var messageProto messagingpb.RequestToReceiveBill
184
+ var protoMesage messagingpb.RequestToReceiveBill
197
185
messageBytes , err := base64 .RawURLEncoding .DecodeString (httpRequestBody .Message )
198
186
if err != nil {
199
187
return nil , errors .New ("message not valid base64" )
200
188
}
201
- err = proto .Unmarshal (messageBytes , & messageProto )
189
+ err = proto .Unmarshal (messageBytes , & protoMesage )
202
190
if err != nil {
203
191
return nil , errors .New ("message bytes is not a RequestToReceiveBill" )
204
- } else if err := messageProto .Validate (); err != nil {
192
+ } else if err := protoMesage .Validate (); err != nil {
205
193
return nil , errors .Wrap (err , "message failed proto validation" )
206
194
}
207
195
@@ -212,14 +200,14 @@ func newTrustlessPaymentRequestFromHttpContext(r *http.Request) (*trustlessPayme
212
200
}
213
201
copy (signature [:], decodedSignature )
214
202
215
- destination , err : = common .NewAccountFromProto (messageProto .RequestorAccount )
203
+ _ , err = common .NewAccountFromProto (protoMesage .RequestorAccount )
216
204
if err != nil {
217
205
return nil , errors .New ("destination is not a public key" )
218
206
}
219
207
220
208
var currency currency_lib.Code
221
209
var amount float64
222
- switch typed := messageProto .ExchangeData .(type ) {
210
+ switch typed := protoMesage .ExchangeData .(type ) {
223
211
case * messagingpb.RequestToReceiveBill_Exact :
224
212
currency = currency_lib .Code (strings .ToLower (typed .Exact .Currency ))
225
213
amount = float64 (kin .FromQuarks (typed .Exact .Quarks )) // Because of minimum bucket sizes
@@ -255,6 +243,9 @@ func newTrustlessPaymentRequestFromHttpContext(r *http.Request) (*trustlessPayme
255
243
return nil , errors .Errorf ("%s currency has a minimum amount of %.2f" , currency , limits .Min )
256
244
}
257
245
246
+ // todo: Validate domain fields with user-friendly error messaging. The
247
+ // messaging service will do this for now, and will be translated.
248
+
258
249
if httpRequestBody .Webhook != nil {
259
250
err = netutil .ValidateHttpUrl (* httpRequestBody .Webhook , true , false )
260
251
if err != nil {
@@ -263,13 +254,9 @@ func newTrustlessPaymentRequestFromHttpContext(r *http.Request) (*trustlessPayme
263
254
}
264
255
265
256
return newTrustlessPaymentRequest (
266
- currency ,
267
- amount ,
268
- destination ,
269
-
257
+ & protoMesage ,
270
258
rendezvousKey ,
271
259
signature ,
272
-
273
260
httpRequestBody .Webhook ,
274
261
)
275
262
}
@@ -283,11 +270,11 @@ func (r *trustlessPaymentRequest) GetClientSignature() solana.Signature {
283
270
}
284
271
285
272
func (r * trustlessPaymentRequest ) ToProtoMessage () * messagingpb.Message {
286
- return getRequestToReceiveBillMessage (
287
- r . currency ,
288
- r . nativeAmount ,
289
- r . destination ,
290
- )
273
+ return & messagingpb. Message {
274
+ Kind : & messagingpb. Message_RequestToReceiveBill {
275
+ RequestToReceiveBill : r . originalProtoMessage ,
276
+ } ,
277
+ }
291
278
}
292
279
293
280
func getRequestToReceiveBillMessage (
0 commit comments