From 6f3c17e4cb144b840208a023cad40d864d67e3f2 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Tue, 9 Jun 2026 12:24:52 -0400 Subject: [PATCH 1/2] Support additional app metadata in SubmitIntent --- go.mod | 2 +- go.sum | 4 ++-- ocp/data/intent/intent.go | 13 +++++++++++++ ocp/data/intent/postgres/model.go | 24 ++++++++++++++---------- ocp/data/intent/postgres/store_test.go | 2 ++ ocp/data/intent/tests/tests.go | 6 ++++-- ocp/rpc/transaction/intent.go | 9 +++++++++ 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 6e6f5ae..1750327 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25 github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2 github.com/code-payments/code-vm-indexer v1.2.0 - github.com/code-payments/ocp-protobuf-api v1.12.0 + github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8 github.com/emirpasic/gods v1.12.0 github.com/envoyproxy/protoc-gen-validate v1.2.1 github.com/golang/protobuf v1.5.4 diff --git a/go.sum b/go.sum index 692cb97..eaa2a22 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0= github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8= -github.com/code-payments/ocp-protobuf-api v1.12.0 h1:Gm+DMGJXvV4PIdM609BfcxoRrAwJHDAC12mRc6SL+Jc= -github.com/code-payments/ocp-protobuf-api v1.12.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= +github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8 h1:MsWTKtfagmT/rJn4+dMmBKFA7R5X0Un9bCK3ta0Ykto= +github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= diff --git a/ocp/data/intent/intent.go b/ocp/data/intent/intent.go index 9d0af4d..582cdbf 100644 --- a/ocp/data/intent/intent.go +++ b/ocp/data/intent/intent.go @@ -44,6 +44,9 @@ type Record struct { ReceivePaymentsPubliclyMetadata *ReceivePaymentsPubliclyMetadata PublicDistributionMetadata *PublicDistributionMetadata + // AppMetadata is optional app-level metadata provided with the intent + AppMetadata []byte + State State Version uint64 @@ -146,6 +149,12 @@ func (r *Record) Clone() Record { publicDistributionMetadata = &cloned } + var appMetadata []byte + if r.AppMetadata != nil { + appMetadata = make([]byte, len(r.AppMetadata)) + copy(appMetadata, r.AppMetadata) + } + return Record{ Id: r.Id, @@ -162,6 +171,8 @@ func (r *Record) Clone() Record { ReceivePaymentsPubliclyMetadata: receivePaymentsPubliclyMetadata, PublicDistributionMetadata: publicDistributionMetadata, + AppMetadata: appMetadata, + State: r.State, Version: r.Version, @@ -186,6 +197,8 @@ func (r *Record) CopyTo(dst *Record) { dst.ReceivePaymentsPubliclyMetadata = r.ReceivePaymentsPubliclyMetadata dst.PublicDistributionMetadata = r.PublicDistributionMetadata + dst.AppMetadata = r.AppMetadata + dst.State = r.State dst.Version = r.Version diff --git a/ocp/data/intent/postgres/model.go b/ocp/data/intent/postgres/model.go index 6774ef7..d53ff3c 100644 --- a/ocp/data/intent/postgres/model.go +++ b/ocp/data/intent/postgres/model.go @@ -44,6 +44,7 @@ type intentModel struct { IsReturned bool `db:"is_returned"` IsIssuerVoidingGiftCard bool `db:"is_issuer_voiding_gift_card"` IsSwap bool `db:"is_swap"` + AppMetadata []byte `db:"app_metadata"` State uint `db:"state"` Version int64 `db:"version"` CreatedAt time.Time `db:"created_at"` @@ -73,6 +74,7 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) { IntentType: uint(obj.IntentType), Mint: mint, InitiatorOwner: obj.InitiatorOwnerAccount, + AppMetadata: obj.AppMetadata, State: uint(obj.State), CreatedAt: obj.CreatedAt, Version: int64(obj.Version), @@ -142,6 +144,7 @@ func fromIntentModel(obj *intentModel) *intent.Record { IntentId: obj.IntentId, IntentType: intent.Type(obj.IntentType), InitiatorOwnerAccount: obj.InitiatorOwner, + AppMetadata: obj.AppMetadata, State: intent.State(obj.State), Version: uint64(obj.Version), CreatedAt: obj.CreatedAt.UTC(), @@ -225,16 +228,16 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error { return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error { query := `INSERT INTO ` + intentTableName + ` - (intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20 + 1, $21) + (intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21 + 1, $22) ON CONFLICT (intent_id) DO UPDATE - SET usd_market_value = $12, state = $19, version = ` + intentTableName + `.version + 1 - WHERE ` + intentTableName + `.intent_id = $1 AND ` + intentTableName + `.version = $20 + SET usd_market_value = $12, state = $20, version = ` + intentTableName + `.version + 1 + WHERE ` + intentTableName + `.intent_id = $1 AND ` + intentTableName + `.version = $21 RETURNING - id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at` + id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at` err := tx.QueryRowxContext( ctx, @@ -257,6 +260,7 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error { m.IsReturned, m.IsIssuerVoidingGiftCard, m.IsSwap, + m.AppMetadata, m.State, m.Version, m.CreatedAt, @@ -382,7 +386,7 @@ func dbGetAccounts(ctx context.Context, db *sqlx.DB, intentType intent.Type, pag func dbGetIntentByIntentID(ctx context.Context, db *sqlx.DB, intentID string) (*intentModel, error) { res := &intentModel{} - query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at + query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at FROM ` + intentTableName + ` WHERE intent_id = $1 LIMIT 1` @@ -402,7 +406,7 @@ func dbGetIntentByIntentID(ctx context.Context, db *sqlx.DB, intentID string) (* func dbGetIntentByID(ctx context.Context, db *sqlx.DB, id int64) (*intentModel, error) { res := &intentModel{} - query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at + query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at FROM ` + intentTableName + ` WHERE id = $1 LIMIT 1` @@ -425,7 +429,7 @@ func dbGetAllByOwner(ctx context.Context, db *sqlx.DB, owner string, cursor q.Cu models := []*intentModel{} opts := []any{owner} - query1 := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at + query1 := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at FROM ` + intentTableName + ` WHERE (owner = $1 OR destination_owner = $1) ` @@ -494,7 +498,7 @@ func dbGetAllByOwner(ctx context.Context, db *sqlx.DB, owner string, cursor q.Cu func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCardVault string) (*intentModel, error) { res := []*intentModel{} - query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at + query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at FROM ` + intentTableName + ` WHERE destination = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE LIMIT 2 @@ -526,7 +530,7 @@ func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCar func dbGetGiftCardClaimedIntent(ctx context.Context, db *sqlx.DB, giftCardVault string) (*intentModel, error) { res := []*intentModel{} - query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, state, version, created_at + query := `SELECT id, intent_id, intent_type, mint, owner, source, destination_owner, destination, quantity, exchange_currency, exchange_rate, native_amount, usd_market_value, original_usd_market_value, is_withdraw, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_swap, app_metadata, state, version, created_at FROM ` + intentTableName + ` WHERE source = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE LIMIT 2 diff --git a/ocp/data/intent/postgres/store_test.go b/ocp/data/intent/postgres/store_test.go index affff7f..85efedd 100644 --- a/ocp/data/intent/postgres/store_test.go +++ b/ocp/data/intent/postgres/store_test.go @@ -46,6 +46,8 @@ const ( is_issuer_voiding_gift_card BOOL NOT NULL, is_swap BOOL NOT NULL, + app_metadata BYTEA NULL, + state INTEGER NOT NULL, version INTEGER NOT NULL, diff --git a/ocp/data/intent/tests/tests.go b/ocp/data/intent/tests/tests.go index a0df3dd..4bd135b 100644 --- a/ocp/data/intent/tests/tests.go +++ b/ocp/data/intent/tests/tests.go @@ -155,8 +155,9 @@ func testSendPublicPaymentRoundTrip(t *testing.T, s intent.Store) { IsRemoteSend: true, IsSwapSell: true, }, - State: intent.StateUnknown, - CreatedAt: time.Now(), + AppMetadata: []byte("test_app_metadata"), + State: intent.StateUnknown, + CreatedAt: time.Now(), } cloned := expected.Clone() err = s.Save(ctx, &expected) @@ -181,6 +182,7 @@ func testSendPublicPaymentRoundTrip(t *testing.T, s intent.Store) { assert.Equal(t, cloned.SendPublicPaymentMetadata.IsWithdrawal, actual.SendPublicPaymentMetadata.IsWithdrawal) assert.Equal(t, cloned.SendPublicPaymentMetadata.IsRemoteSend, actual.SendPublicPaymentMetadata.IsRemoteSend) assert.Equal(t, cloned.SendPublicPaymentMetadata.IsSwapSell, actual.SendPublicPaymentMetadata.IsSwapSell) + assert.Equal(t, cloned.AppMetadata, actual.AppMetadata) assert.Equal(t, cloned.State, actual.State) assert.Equal(t, cloned.CreatedAt.Unix(), actual.CreatedAt.Unix()) assert.EqualValues(t, 1, actual.Id) diff --git a/ocp/rpc/transaction/intent.go b/ocp/rpc/transaction/intent.go index e4f0c51..3d1b9b4 100644 --- a/ocp/rpc/transaction/intent.go +++ b/ocp/rpc/transaction/intent.go @@ -271,6 +271,11 @@ func (s *transactionServer) SubmitIntent(streamer transactionpb.Transaction_Subm return handleSubmitIntentError(ctx, streamer, intentRecord, err) } + // Store any optional app-level metadata provided alongside the intent + if appMetadata := submitActionsReq.Metadata.GetAppMetadata(); appMetadata != nil { + intentRecord.AppMetadata = appMetadata.Value + } + // Check whether the intent is a no-op isNoop, err := intentHandler.IsNoop(ctx, intentRecord, submitActionsReq.Metadata, submitActionsReq.Actions) if err != nil { @@ -890,6 +895,10 @@ func (s *transactionServer) GetIntentMetadata(ctx context.Context, req *transact }, nil } + if len(intentRecord.AppMetadata) > 0 { + metadata.AppMetadata = &transactionpb.AppMetadata{Value: intentRecord.AppMetadata} + } + return &transactionpb.GetIntentMetadataResponse{ Result: transactionpb.GetIntentMetadataResponse_OK, Metadata: metadata, From 254d85dc82831f5aa13df751156007db9f190ff4 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Wed, 10 Jun 2026 08:58:00 -0400 Subject: [PATCH 2/2] Pull ocp-protobuf-api v1.13.0 --- go.mod | 2 +- go.sum | 4 ++-- ocp/data/intent/intent.go | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2cb3483..c2624a8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25 github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2 github.com/code-payments/code-vm-indexer v1.2.0 - github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8 + github.com/code-payments/ocp-protobuf-api v1.13.0 github.com/emirpasic/gods v1.12.0 github.com/envoyproxy/protoc-gen-validate v1.2.1 github.com/golang/protobuf v1.5.4 diff --git a/go.sum b/go.sum index 055094a..73ae0de 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0= github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8= -github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8 h1:MsWTKtfagmT/rJn4+dMmBKFA7R5X0Un9bCK3ta0Ykto= -github.com/code-payments/ocp-protobuf-api v1.12.1-0.20260609161103-06495ea0a0d8/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= +github.com/code-payments/ocp-protobuf-api v1.13.0 h1:Skzi+h0wqAu1e8zMNN7jCeQoJB3t1BVAVpnv0JuRDIU= +github.com/code-payments/ocp-protobuf-api v1.13.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= diff --git a/ocp/data/intent/intent.go b/ocp/data/intent/intent.go index 582cdbf..95342f4 100644 --- a/ocp/data/intent/intent.go +++ b/ocp/data/intent/intent.go @@ -44,7 +44,6 @@ type Record struct { ReceivePaymentsPubliclyMetadata *ReceivePaymentsPubliclyMetadata PublicDistributionMetadata *PublicDistributionMetadata - // AppMetadata is optional app-level metadata provided with the intent AppMetadata []byte State State