intent

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIntentNotFound       = errors.New("no records could be found")
	ErrInvalidIntent        = errors.New("invalid intent")
	ErrMultilpeIntentsFound = errors.New("multiple records found")
)

Functions

This section is empty.

Types

type AccountManagementMetadata

type AccountManagementMetadata struct {
	TokenAccount string
}

func (*AccountManagementMetadata) Clone

func (*AccountManagementMetadata) CopyTo

func (*AccountManagementMetadata) Validate

func (m *AccountManagementMetadata) Validate() error

type EstablishRelationshipMetadata

type EstablishRelationshipMetadata struct {
	RelationshipTo string
}

func (*EstablishRelationshipMetadata) Clone

func (*EstablishRelationshipMetadata) CopyTo

func (*EstablishRelationshipMetadata) Validate

func (m *EstablishRelationshipMetadata) Validate() error

type ExternalDepositMetadata

type ExternalDepositMetadata struct {
	DestinationOwnerAccount string
	DestinationTokenAccount string
	Quantity                uint64
	UsdMarketValue          float64
}

func (*ExternalDepositMetadata) Clone

func (*ExternalDepositMetadata) CopyTo

func (*ExternalDepositMetadata) Validate

func (m *ExternalDepositMetadata) Validate() error

type LoginMetadata added in v1.2.0

type LoginMetadata struct {
	App    string
	UserId string
}

func (*LoginMetadata) Clone added in v1.2.0

func (m *LoginMetadata) Clone() LoginMetadata

func (*LoginMetadata) CopyTo added in v1.2.0

func (m *LoginMetadata) CopyTo(dst *LoginMetadata)

func (*LoginMetadata) Validate added in v1.2.0

func (m *LoginMetadata) Validate() error

type MigrateToPrivacy2022Metadata

type MigrateToPrivacy2022Metadata struct {
	Quantity uint64
}

func (*MigrateToPrivacy2022Metadata) Clone

func (*MigrateToPrivacy2022Metadata) CopyTo

func (*MigrateToPrivacy2022Metadata) Validate

func (m *MigrateToPrivacy2022Metadata) Validate() error

type MoneyTransferMetadata

type MoneyTransferMetadata struct {
	Source      string
	Destination string

	Quantity uint64

	ExchangeCurrency currency.Code
	ExchangeRate     float64
	UsdMarketValue   float64

	IsWithdrawal bool
}

func (*MoneyTransferMetadata) Clone

func (*MoneyTransferMetadata) CopyTo

func (*MoneyTransferMetadata) Validate

func (m *MoneyTransferMetadata) Validate() error

type OpenAccountsMetadata

type OpenAccountsMetadata struct {
}

func (*OpenAccountsMetadata) Clone

func (*OpenAccountsMetadata) CopyTo

func (*OpenAccountsMetadata) Validate

func (m *OpenAccountsMetadata) Validate() error

type ReceivePaymentsPrivatelyMetadata

type ReceivePaymentsPrivatelyMetadata struct {
	Source    string
	Quantity  uint64
	IsDeposit bool

	UsdMarketValue float64
}

func (*ReceivePaymentsPrivatelyMetadata) Clone

func (*ReceivePaymentsPrivatelyMetadata) CopyTo

func (*ReceivePaymentsPrivatelyMetadata) Validate

type ReceivePaymentsPubliclyMetadata

type ReceivePaymentsPubliclyMetadata struct {
	Source                  string
	Quantity                uint64
	IsRemoteSend            bool
	IsReturned              bool
	IsIssuerVoidingGiftCard bool

	// Because remote send history isn't directly linked to the send. It's ok, because
	// we'd expect a single payment per gift card ok (unlike temporary incoming that
	// can receive many times and this metadata would be much more harder for the private
	// receive).
	//
	// todo: A better approach?
	OriginalExchangeCurrency currency.Code
	OriginalExchangeRate     float64
	OriginalNativeAmount     float64

	UsdMarketValue float64
}

func (*ReceivePaymentsPubliclyMetadata) Clone

func (*ReceivePaymentsPubliclyMetadata) CopyTo

func (*ReceivePaymentsPubliclyMetadata) Validate

func (m *ReceivePaymentsPubliclyMetadata) Validate() error

type Record

type Record struct {
	Id uint64

	IntentId   string
	IntentType Type

	InitiatorOwnerAccount string
	InitiatorPhoneNumber  *string

	// Intents v2 metadatum
	OpenAccountsMetadata             *OpenAccountsMetadata
	SendPrivatePaymentMetadata       *SendPrivatePaymentMetadata
	ReceivePaymentsPrivatelyMetadata *ReceivePaymentsPrivatelyMetadata
	SaveRecentRootMetadata           *SaveRecentRootMetadata
	MigrateToPrivacy2022Metadata     *MigrateToPrivacy2022Metadata
	ExternalDepositMetadata          *ExternalDepositMetadata
	SendPublicPaymentMetadata        *SendPublicPaymentMetadata
	ReceivePaymentsPubliclyMetadata  *ReceivePaymentsPubliclyMetadata
	EstablishRelationshipMetadata    *EstablishRelationshipMetadata
	LoginMetadata                    *LoginMetadata

	// Deprecated intents v1 metadatum
	MoneyTransferMetadata     *MoneyTransferMetadata
	AccountManagementMetadata *AccountManagementMetadata

	State State

	CreatedAt time.Time
}

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) IsCompleted

func (r *Record) IsCompleted() bool

func (*Record) Validate

func (r *Record) Validate() error

type SaveRecentRootMetadata

type SaveRecentRootMetadata struct {
	TreasuryPool           string
	PreviousMostRecentRoot string
}

func (*SaveRecentRootMetadata) Clone

func (*SaveRecentRootMetadata) CopyTo

func (*SaveRecentRootMetadata) Validate

func (m *SaveRecentRootMetadata) Validate() error

type SendPrivatePaymentMetadata

type SendPrivatePaymentMetadata struct {
	DestinationOwnerAccount string
	DestinationTokenAccount string
	Quantity                uint64

	ExchangeCurrency currency.Code
	ExchangeRate     float64
	NativeAmount     float64
	UsdMarketValue   float64

	IsWithdrawal   bool
	IsRemoteSend   bool
	IsMicroPayment bool
}

func (*SendPrivatePaymentMetadata) Clone

func (*SendPrivatePaymentMetadata) CopyTo

func (*SendPrivatePaymentMetadata) Validate

func (m *SendPrivatePaymentMetadata) Validate() error

type SendPublicPaymentMetadata

type SendPublicPaymentMetadata struct {
	DestinationOwnerAccount string
	DestinationTokenAccount string
	Quantity                uint64

	ExchangeCurrency currency.Code
	ExchangeRate     float64
	NativeAmount     float64
	UsdMarketValue   float64

	IsWithdrawal bool
}

func (*SendPublicPaymentMetadata) Clone

func (*SendPublicPaymentMetadata) CopyTo

func (*SendPublicPaymentMetadata) Validate

func (m *SendPublicPaymentMetadata) Validate() error

type State

type State uint8
const (
	StateUnknown State = iota
	StatePending
	StateConfirmed
	StateFailed
	StateRevoked
)

func (State) IsTerminal

func (s State) IsTerminal() bool

func (State) String

func (s State) String() string

type Store

type Store interface {
	// Save creates or updates an intent on the store.
	Save(ctx context.Context, record *Record) error

	// Get finds the intent record for a given intent ID.
	//
	// Returns ErrNotFound if no record is found.
	Get(ctx context.Context, intentID string) (*Record, error)

	// GetAllByOwner returns all records for a given owner (as both a source and destination).
	//
	// Returns ErrNotFound if no records are found.
	GetAllByOwner(ctx context.Context, owner string, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// GetLatestByInitiatorAndType gets the latest record by initiating owner and intent type
	//
	// Returns ErrNotFound if no records are found.
	GetLatestByInitiatorAndType(ctx context.Context, intentType Type, owner string) (*Record, error)

	// CountForAntispam gets a count of intents for antispam purposes. It calculates the
	// number of intents by type and state for a phone number since a timestamp.
	CountForAntispam(ctx context.Context, intentType Type, phoneNumber string, states []State, since time.Time) (uint64, error)

	// CountOwnerInteractionsForAntispam gets a count of intents for antispam purposes. It
	// calculates the number of times a source owner is involved in an intent with the
	// destination owner since a timestamp.
	CountOwnerInteractionsForAntispam(ctx context.Context, sourceOwner, destinationOwner string, states []State, since time.Time) (uint64, error)

	// GetTransactedAmountForAntiMoneyLaundering gets the total transacted Kin in quarks and the
	// corresponding USD market value for a phone number since a timestamp.
	GetTransactedAmountForAntiMoneyLaundering(ctx context.Context, phoneNumber string, since time.Time) (uint64, float64, error)

	// GetDepositedAmountForAntiMoneyLaundering gets the total deposited Kin in quarks and the
	// corresponding USD market value for a phone number since a timestamp.
	GetDepositedAmountForAntiMoneyLaundering(ctx context.Context, phoneNumber string, since time.Time) (uint64, float64, error)

	// GetNetBalanceFromPrePrivacy2022Intents gets the net balance of Kin in quarks after appying
	// pre-privacy legacy payment intents when intents detailed the entirety of the payment.
	GetNetBalanceFromPrePrivacy2022Intents(ctx context.Context, account string) (int64, error)

	// GetLatestSaveRecentRootIntentForTreasury gets the latest SaveRecentRoot intent for a treasury
	GetLatestSaveRecentRootIntentForTreasury(ctx context.Context, treasury string) (*Record, error)

	// GetOriginalGiftCardIssuedIntent gets the original intent where a gift card
	// was issued by its vault address.
	GetOriginalGiftCardIssuedIntent(ctx context.Context, giftCardVault string) (*Record, error)

	// GetGiftCardClaimedIntent gets the intent where a gift card was claimed by its
	// vault address.
	GetGiftCardClaimedIntent(ctx context.Context, giftCardVault string) (*Record, error)
}

type Type

type Type uint8
const (
	UnknownType Type = iota
	LegacyPayment
	LegacyCreateAccount
	OpenAccounts
	SendPrivatePayment
	ReceivePaymentsPrivately
	SaveRecentRoot
	MigrateToPrivacy2022
	ExternalDeposit
	SendPublicPayment
	ReceivePaymentsPublicly
	EstablishRelationship
	Login
)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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