@@ -49,6 +49,8 @@ type intentModel struct {
4949 IsTip bool `db:"is_tip"`
5050 TipPlatform sql.NullInt16 `db:"tip_platform"`
5151 TippedUsername sql.NullString `db:"tipped_username"`
52+ IsChat bool `db:"is_chat"`
53+ ChatId sql.NullString `db:"chat_id"`
5254 RelationshipTo sql.NullString `db:"relationship_to"`
5355 InitiatorPhoneNumber sql.NullString `db:"phone_number"` // todo: rename the DB field to initiator_phone_number
5456 State uint `db:"state"`
@@ -106,6 +108,7 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
106108 m .IsRemoteSend = obj .SendPrivatePaymentMetadata .IsRemoteSend
107109 m .IsMicroPayment = obj .SendPrivatePaymentMetadata .IsMicroPayment
108110 m .IsTip = obj .SendPrivatePaymentMetadata .IsTip
111+ m .IsChat = obj .SendPrivatePaymentMetadata .IsChat
109112
110113 if m .IsTip {
111114 m .TipPlatform = sql.NullInt16 {
@@ -117,6 +120,13 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
117120 String : obj .SendPrivatePaymentMetadata .TipMetadata .Username ,
118121 }
119122 }
123+
124+ if m .IsChat {
125+ m .ChatId = sql.NullString {
126+ Valid : true ,
127+ String : obj .SendPrivatePaymentMetadata .ChatId ,
128+ }
129+ }
120130 case intent .ReceivePaymentsPrivately :
121131 m .Source = obj .ReceivePaymentsPrivatelyMetadata .Source
122132 m .Quantity = obj .ReceivePaymentsPrivatelyMetadata .Quantity
@@ -224,6 +234,7 @@ func fromIntentModel(obj *intentModel) *intent.Record {
224234 IsRemoteSend : obj .IsRemoteSend ,
225235 IsMicroPayment : obj .IsMicroPayment ,
226236 IsTip : obj .IsTip ,
237+ IsChat : obj .IsChat ,
227238 }
228239
229240 if record .SendPrivatePaymentMetadata .IsTip {
@@ -232,6 +243,11 @@ func fromIntentModel(obj *intentModel) *intent.Record {
232243 Username : obj .TippedUsername .String ,
233244 }
234245 }
246+
247+ if record .SendPrivatePaymentMetadata .IsChat {
248+ record .SendPrivatePaymentMetadata .ChatId = obj .ChatId .String
249+ }
250+
235251 case intent .ReceivePaymentsPrivately :
236252 record .ReceivePaymentsPrivatelyMetadata = & intent.ReceivePaymentsPrivatelyMetadata {
237253 Source : obj .Source ,
@@ -300,16 +316,16 @@ func fromIntentModel(obj *intentModel) *intent.Record {
300316func (m * intentModel ) dbSave (ctx context.Context , db * sqlx.DB ) error {
301317 return pgutil .ExecuteInTx (ctx , db , sql .LevelDefault , func (tx * sqlx.Tx ) error {
302318 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 )
305321
306322 ON CONFLICT (intent_id)
307323 DO UPDATE
308- SET state = $25
324+ SET state = $27
309325 WHERE ` + intentTableName + `.intent_id = $1
310326
311327 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`
313329
314330 err := tx .QueryRowxContext (
315331 ctx ,
@@ -334,9 +350,11 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
334350 m .IsIssuerVoidingGiftCard ,
335351 m .IsMicroPayment ,
336352 m .IsTip ,
353+ m .IsChat ,
337354 m .RelationshipTo ,
338355 m .TipPlatform ,
339356 m .TippedUsername ,
357+ m .ChatId ,
340358 m .InitiatorPhoneNumber ,
341359 m .State ,
342360 m .CreatedAt ,
@@ -349,7 +367,7 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
349367func dbGetIntent (ctx context.Context , db * sqlx.DB , intentID string ) (* intentModel , error ) {
350368 res := & intentModel {}
351369
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
353371 FROM ` + intentTableName + `
354372 WHERE intent_id = $1
355373 LIMIT 1`
@@ -364,7 +382,7 @@ func dbGetIntent(ctx context.Context, db *sqlx.DB, intentID string) (*intentMode
364382func dbGetLatestByInitiatorAndType (ctx context.Context , db * sqlx.DB , intentType intent.Type , owner string ) (* intentModel , error ) {
365383 res := & intentModel {}
366384
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
368386 FROM ` + intentTableName + `
369387 WHERE owner = $1 AND intent_type = $2
370388 ORDER BY created_at DESC
@@ -381,7 +399,7 @@ func dbGetLatestByInitiatorAndType(ctx context.Context, db *sqlx.DB, intentType
381399func dbGetAllByOwner (ctx context.Context , db * sqlx.DB , owner string , cursor q.Cursor , limit uint64 , direction q.Ordering ) ([]* intentModel , error ) {
382400 res := []* intentModel {}
383401
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
385403 FROM ` + intentTableName + `
386404 WHERE (owner = $1 OR destination_owner = $1) AND (intent_type != $2 AND intent_type != $3)
387405 `
@@ -542,7 +560,7 @@ func dbGetNetBalanceFromPrePrivacy2022Intents(ctx context.Context, db *sqlx.DB,
542560func dbGetLatestSaveRecentRootIntentForTreasury (ctx context.Context , db * sqlx.DB , treasury string ) (* intentModel , error ) {
543561 res := & intentModel {}
544562
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
546564 FROM ` + intentTableName + `
547565 WHERE treasury_pool = $1 and intent_type = $2
548566 ORDER BY id DESC
@@ -559,7 +577,7 @@ func dbGetLatestSaveRecentRootIntentForTreasury(ctx context.Context, db *sqlx.DB
559577func dbGetOriginalGiftCardIssuedIntent (ctx context.Context , db * sqlx.DB , giftCardVault string ) (* intentModel , error ) {
560578 res := []* intentModel {}
561579
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
563581 FROM ` + intentTableName + `
564582 WHERE destination = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
565583 LIMIT 2
@@ -591,7 +609,7 @@ func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCar
591609func dbGetGiftCardClaimedIntent (ctx context.Context , db * sqlx.DB , giftCardVault string ) (* intentModel , error ) {
592610 res := []* intentModel {}
593611
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
595613 FROM ` + intentTableName + `
596614 WHERE source = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
597615 LIMIT 2
0 commit comments