intent

package
v1.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TaskTypeSendContactDmPaymentMessage is the task that injects the cash
	// message into the sender and recipient's DM after a contact DM payment.
	TaskTypeSendContactDmPaymentMessage uint32 = 1

	// TaskTypeSendDmPaymentMessage is the task that injects the cash message
	// into the sender and recipient's DM after a DM payment.
	TaskTypeSendDmPaymentMessage uint32 = 2

	// TaskTypeSendGroupPaymentMessage is the task that injects the cash
	// message into the group after a group payment.
	TaskTypeSendGroupPaymentMessage uint32 = 3

	// TaskTypeRecordReactionBoost is the task that records a reaction boost
	// against the payer's reaction once its payment is made (see
	// messaging.Sender.RecordBoost).
	TaskTypeRecordReactionBoost uint32 = 4

	// TaskTypeRecordRequestedPayment is the task that marks a payment
	// request's share paid by a requested payment and injects its cash
	// message into the group.
	TaskTypeRecordRequestedPayment uint32 = 5

	// TaskTypeSendReturnPaymentMessage is the task that marks the returned
	// payment's offer returned (messaging.Store.MarkCashMessageReturned) and
	// injects the return's cash message into the DM.
	TaskTypeSendReturnPaymentMessage uint32 = 6
)

The OCP task system treats the type as an opaque app-owned namespace, so values must be globally unique across the app and stable forever — pending tasks in the DB reference them. Type 0 is reserved as invalid by the base system.

View Source
const MaxGroupPaymentReceivers = 10

MaxGroupPaymentReceivers is the most members one group payment may pay: the most receivers a cash message can list (messagingpb.CashContent_Payments). OCP caps a multi payment's destinations at the same number today; the check is Flipcash's own, so a payment that passed validation can always be posted.

Variables

View Source
var ErrNotDirectPayment = errors.New("intent is not a direct payment")

ErrNotDirectPayment is returned by GetDirectPayment for an intent that is not a direct payment.

Functions

func GetChatMetadata added in v1.15.0

func GetChatMetadata(appMetadata []byte) *intentpb.ChatMetadata

GetChatMetadata extracts the chat metadata from an intent's additional app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not chat metadata.

This and the accessors below take the blob rather than the intent it came from, because the intent is not the only thing that carries it: a transaction history record passes the same bytes through unmodified, and decodes to the same metadata the intent was submitted with.

func GetChatPaymentVerb added in v1.35.0

func GetChatPaymentVerb(appMetadata []byte, createdAt time.Time) messagingpb.CashContent_Verb

GetChatPaymentVerb reports how a chat payment created at createdAt should be rendered. A DM payment is a tip only when its action is TIP; SEND and the unset DEFAULT are plain sends, from either location, except for payments created before sendByDefaultCutoff. Everything else, contact DM, group, requested and return payments included, is a plain send: a group payment's TIP is denied at validation (see validateGroupAppMetadata), and a requested or return payment carries no action.

Both the cash message injected into the chat and the sender's activity feed entry render off this, so they cannot disagree about what a payment was. createdAt is the intent's creation time, which OCP sets before validation and copies onto the intent's history records, so every caller passes the same time for the same payment.

func GetContactDmPayment added in v1.15.0

func GetContactDmPayment(appMetadata []byte) *intentpb.ChatMetadata_ContactDmPayment

GetContactDmPayment extracts the contact DM payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a contact DM payment.

func GetDmPayment added in v1.33.0

func GetDmPayment(appMetadata []byte) *intentpb.ChatMetadata_DmPayment

GetDmPayment extracts the DM payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a DM payment.

func GetGroupPayment added in v1.35.0

func GetGroupPayment(appMetadata []byte) *intentpb.ChatMetadata_GroupPayment

GetGroupPayment extracts the group payment from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a group payment.

func GetReactionBoost added in v1.35.0

func GetReactionBoost(appMetadata []byte) *intentpb.ChatMetadata_ReactionBoost

GetReactionBoost extracts the reaction boost from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a reaction boost.

func GetRequestedPayment added in v1.36.0

func GetRequestedPayment(appMetadata []byte) *intentpb.ChatMetadata_RequestedPayment

GetRequestedPayment extracts the requested payment, a payment of the payer's share of a payment request, from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a requested payment.

func GetReturnPayment added in v1.38.0

func GetReturnPayment(appMetadata []byte) *intentpb.ChatMetadata_ReturnPayment

GetReturnPayment extracts the return payment, a payment returning one offered for returning in a DM's cash message, from app metadata, if present. It returns nil when there is no app metadata, the metadata fails to decode, or it is not a return payment.

func IsUserChatPayment added in v1.35.0

func IsUserChatPayment(appMetadata []byte) bool

IsUserChatPayment reports whether app metadata is a chat payment whose parties know each other by user ID: a DM payment, a group payment, whose cash message names the payer and every recipient in the group, a reaction boost, whose payer is shown on the reaction to the group and whose payees are the group's creator and the message's sender, a requested payment, whose activity entries name the payer and the request's creator, or a return payment, whose payer is the returned payment's receiver and whose payee is its sender, both members of the DM it was made in. A contact DM payment is not one, since its parties know each other by phone number; nor is a payment carrying no chat metadata, such as one handed off in person, where no identity was exchanged at all.

func NewIntegration

func NewIntegration(
	accounts account.Store,
	chats chat.Store,
	messages messaging.Store,
	profiles profile.Store,
	requests paymentrequest.Store,
	access *chat.Access,
	mintDataProvider *ocp_currency_util.MintDataProvider,
	teamUserID *commonpb.UserId,
) ocp_integration.SubmitIntent

NewIntegration constructs the intent integration. messages is the messaging store, read to validate reaction boosts, and requests the payment request store, read to validate a payment of a share. access is the one chat.Access the parent builds and shares with the chat and messaging servers. teamUserID is the Flipcash team account, which the parent resolves once at startup with flipcashteam.GetUserID and passes to the chat store, the chat RuleEvaluator, the chat server and the Sender too; nil names no one.

func NewRecordReactionBoostTask added in v1.35.0

func NewRecordReactionBoostTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewRecordReactionBoostTask creates the task that records a reaction boost after its payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewRecordRequestedPaymentTask added in v1.36.0

func NewRecordRequestedPaymentTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewRecordRequestedPaymentTask creates the task that marks a payment request's share paid after a requested payment, and injects its cash message into the group. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendContactDmPaymentMessageTask added in v1.15.0

func NewSendContactDmPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendContactDmPaymentMessageTask creates the task that injects the cash message into the sender and recipient's DM after a contact DM payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendDmPaymentMessageTask added in v1.33.0

func NewSendDmPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendDmPaymentMessageTask creates the task that injects the cash message into the sender and recipient's DM after a DM payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendGroupPaymentMessageTask added in v1.35.0

func NewSendGroupPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendGroupPaymentMessageTask creates the task that injects the cash message into the group after a group payment. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

func NewSendReturnPaymentMessageTask added in v1.38.0

func NewSendReturnPaymentMessageTask(intentRecord *ocp_intent.Record) *ocp_task.Record

NewSendReturnPaymentMessageTask creates the task that marks the returned payment's offer returned after a return payment, and injects the return's cash message into the DM. Only the intent ID is carried, via the reference ID; the executor reloads the authoritative intent record at execution time.

Types

type DirectDestination added in v1.36.0

type DirectDestination struct {
	Owner        *ocp_common.Account
	Quarks       uint64
	NativeAmount float64
}

DirectDestination is one destination of a direct payment: the owner account paid and how much, in quarks and in the payment's currency.

type DirectPayment added in v1.36.0

type DirectPayment struct {
	// Payer is the owner account that made the payment.
	Payer *ocp_common.Account

	// Destinations are the payment's destinations, one per payee, in the
	// payment's own order.
	Destinations []DirectDestination

	// Amount is the whole payment, every destination's part together.
	Amount *commonpb.CryptoPaymentAmount

	// UsdMarketValue is the whole payment's value in USD (for a boost, what
	// it grows the reaction's totals by).
	UsdMarketValue float64
}

DirectPayment is a direct payment from one user to one or more others, read off its intent record by GetDirectPayment: who paid, who it pays, and the whole payment. It is what group payment, boost and requested payment validation, and the tasks they schedule, read instead of the intent's own metadata, so that the one place that knows which intents are direct payments, and how each names its destinations, is GetDirectPayment.

func GetDirectPayment added in v1.36.0

func GetDirectPayment(intentRecord *ocp_intent.Record) (*DirectPayment, error)

GetDirectPayment reads a direct payment off its intent record. A payment to one person is a SendPublicPayment, with one destination; a payment to several at once is a SendPublicMultiPayment, one DirectDestination per destination. Which of the two a payment must be is judged by its validator (validateGroupAppMetadata, validateReactionBoostAppMetadata, validateRequestedPaymentAppMetadata), not here.

It reads nothing but the record and returns ErrNotDirectPayment (wrapped) for an intent that is neither, or a SendPublicPayment that is not direct.

type Integration

type Integration struct {
	// contains filtered or unexported fields
}

func (*Integration) AllowCreation

func (i *Integration) AllowCreation(ctx context.Context, intentRecord *ocp_intent.Record, metadata *ocp_transactionpb.Metadata, actions []*ocp_transactionpb.Action) error

func (*Integration) GetTasksToSchedule added in v1.15.0

func (i *Integration) GetTasksToSchedule(ctx context.Context, intentRecord *ocp_intent.Record) ([]*ocp_task.Record, error)

GetTasksToSchedule returns the guaranteed work derived from a submitted intent. A DM payment of either type (contact DM or DM) schedules the cash message injected into the DM between the sender and recipient, and a group payment, made as either payment intent, the one injected into the group; a reaction boost, made as either payment intent, schedules the task that records the boost; a requested payment, a SendPublicPayment alone, the task that marks its share paid; and a return payment, a SendPublicPayment alone, the task that marks the returned payment's offer returned and injects the return's cash message into the DM. Execution is handled by task.Executor.

func (*Integration) OnSuccess

func (i *Integration) OnSuccess(ctx context.Context, intentRecord *ocp_intent.Record) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL