@@ -49,6 +49,8 @@ type intentModel struct {
49
49
IsTip bool `db:"is_tip"`
50
50
TipPlatform sql.NullInt16 `db:"tip_platform"`
51
51
TippedUsername sql.NullString `db:"tipped_username"`
52
+ IsChat bool `db:"is_chat"`
53
+ ChatId sql.NullString `db:"chat_id"`
52
54
RelationshipTo sql.NullString `db:"relationship_to"`
53
55
InitiatorPhoneNumber sql.NullString `db:"phone_number"` // todo: rename the DB field to initiator_phone_number
54
56
State uint `db:"state"`
@@ -106,6 +108,7 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
106
108
m .IsRemoteSend = obj .SendPrivatePaymentMetadata .IsRemoteSend
107
109
m .IsMicroPayment = obj .SendPrivatePaymentMetadata .IsMicroPayment
108
110
m .IsTip = obj .SendPrivatePaymentMetadata .IsTip
111
+ m .IsChat = obj .SendPrivatePaymentMetadata .IsChat
109
112
110
113
if m .IsTip {
111
114
m .TipPlatform = sql.NullInt16 {
@@ -117,6 +120,13 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
117
120
String : obj .SendPrivatePaymentMetadata .TipMetadata .Username ,
118
121
}
119
122
}
123
+
124
+ if m .IsChat {
125
+ m .ChatId = sql.NullString {
126
+ Valid : true ,
127
+ String : obj .SendPrivatePaymentMetadata .ChatId ,
128
+ }
129
+ }
120
130
case intent .ReceivePaymentsPrivately :
121
131
m .Source = obj .ReceivePaymentsPrivatelyMetadata .Source
122
132
m .Quantity = obj .ReceivePaymentsPrivatelyMetadata .Quantity
@@ -224,6 +234,7 @@ func fromIntentModel(obj *intentModel) *intent.Record {
224
234
IsRemoteSend : obj .IsRemoteSend ,
225
235
IsMicroPayment : obj .IsMicroPayment ,
226
236
IsTip : obj .IsTip ,
237
+ IsChat : obj .IsChat ,
227
238
}
228
239
229
240
if record .SendPrivatePaymentMetadata .IsTip {
@@ -232,6 +243,11 @@ func fromIntentModel(obj *intentModel) *intent.Record {
232
243
Username : obj .TippedUsername .String ,
233
244
}
234
245
}
246
+
247
+ if record .SendPrivatePaymentMetadata .IsChat {
248
+ record .SendPrivatePaymentMetadata .ChatId = obj .ChatId .String
249
+ }
250
+
235
251
case intent .ReceivePaymentsPrivately :
236
252
record .ReceivePaymentsPrivatelyMetadata = & intent.ReceivePaymentsPrivatelyMetadata {
237
253
Source : obj .Source ,
@@ -300,16 +316,16 @@ func fromIntentModel(obj *intentModel) *intent.Record {
300
316
func (m * intentModel ) dbSave (ctx context.Context , db * sqlx.DB ) error {
301
317
return pgutil .ExecuteInTx (ctx , db , sql .LevelDefault , func (tx * sqlx.Tx ) error {
302
318
query := `INSERT INTO ` + intentTableName + `
303
- (intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at)
304
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
319
+ (intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at)
320
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28 )
305
321
306
322
ON CONFLICT (intent_id)
307
323
DO UPDATE
308
- SET state = $25
324
+ SET state = $27
309
325
WHERE ` + intentTableName + `.intent_id = $1
310
326
311
327
RETURNING
312
- id, intent_id, intent_type, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at`
328
+ id, intent_id, intent_type, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at`
313
329
314
330
err := tx .QueryRowxContext (
315
331
ctx ,
@@ -334,9 +350,11 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
334
350
m .IsIssuerVoidingGiftCard ,
335
351
m .IsMicroPayment ,
336
352
m .IsTip ,
353
+ m .IsChat ,
337
354
m .RelationshipTo ,
338
355
m .TipPlatform ,
339
356
m .TippedUsername ,
357
+ m .ChatId ,
340
358
m .InitiatorPhoneNumber ,
341
359
m .State ,
342
360
m .CreatedAt ,
@@ -349,7 +367,7 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
349
367
func dbGetIntent (ctx context.Context , db * sqlx.DB , intentID string ) (* intentModel , error ) {
350
368
res := & intentModel {}
351
369
352
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
370
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
353
371
FROM ` + intentTableName + `
354
372
WHERE intent_id = $1
355
373
LIMIT 1`
@@ -364,7 +382,7 @@ func dbGetIntent(ctx context.Context, db *sqlx.DB, intentID string) (*intentMode
364
382
func dbGetLatestByInitiatorAndType (ctx context.Context , db * sqlx.DB , intentType intent.Type , owner string ) (* intentModel , error ) {
365
383
res := & intentModel {}
366
384
367
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
385
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
368
386
FROM ` + intentTableName + `
369
387
WHERE owner = $1 AND intent_type = $2
370
388
ORDER BY created_at DESC
@@ -381,7 +399,7 @@ func dbGetLatestByInitiatorAndType(ctx context.Context, db *sqlx.DB, intentType
381
399
func dbGetAllByOwner (ctx context.Context , db * sqlx.DB , owner string , cursor q.Cursor , limit uint64 , direction q.Ordering ) ([]* intentModel , error ) {
382
400
res := []* intentModel {}
383
401
384
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
402
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
385
403
FROM ` + intentTableName + `
386
404
WHERE (owner = $1 OR destination_owner = $1) AND (intent_type != $2 AND intent_type != $3)
387
405
`
@@ -542,7 +560,7 @@ func dbGetNetBalanceFromPrePrivacy2022Intents(ctx context.Context, db *sqlx.DB,
542
560
func dbGetLatestSaveRecentRootIntentForTreasury (ctx context.Context , db * sqlx.DB , treasury string ) (* intentModel , error ) {
543
561
res := & intentModel {}
544
562
545
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
563
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
546
564
FROM ` + intentTableName + `
547
565
WHERE treasury_pool = $1 and intent_type = $2
548
566
ORDER BY id DESC
@@ -559,7 +577,7 @@ func dbGetLatestSaveRecentRootIntentForTreasury(ctx context.Context, db *sqlx.DB
559
577
func dbGetOriginalGiftCardIssuedIntent (ctx context.Context , db * sqlx.DB , giftCardVault string ) (* intentModel , error ) {
560
578
res := []* intentModel {}
561
579
562
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
580
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
563
581
FROM ` + intentTableName + `
564
582
WHERE destination = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
565
583
LIMIT 2
@@ -591,7 +609,7 @@ func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCar
591
609
func dbGetGiftCardClaimedIntent (ctx context.Context , db * sqlx.DB , giftCardVault string ) (* intentModel , error ) {
592
610
res := []* intentModel {}
593
611
594
- query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
612
+ query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id , phone_number, state, created_at
595
613
FROM ` + intentTableName + `
596
614
WHERE source = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
597
615
LIMIT 2
0 commit comments