transaction_v2

package
v0.0.0-...-c6effd4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DisableSubmitIntentConfigEnvName = envConfigPrefix + "DISABLE_SUBMIT_INTENT"

	DisableBlockchainChecksConfigEnvName = envConfigPrefix + "DISABLE_BLOCKCHAIN_CHECKS"

	SubmitIntentTimeoutConfigEnvName = envConfigPrefix + "SUBMIT_INTENT_TIMEOUT"

	ClientReceiveTimeoutConfigEnvName = envConfigPrefix + "CLIENT_RECEIVE_TIMEOUT"

	FeeCollectorTokenPublicKeyConfigEnvName = envConfigPrefix + "FEE_COLLECTOR_TOKEN_PUBLIC_KEY"

	EnableAirdropsConfigEnvName = envConfigPrefix + "ENABLE_AIRDROPS"

	AirdropperOwnerPublicKeyEnvName = envConfigPrefix + "AIRDROPPER_OWNER_PUBLIC_KEY"

	SwapSubsidizerOwnerPublicKeyEnvName = envConfigPrefix + "SWAP_SUBSIDIZER_OWNER_PUBLIC_KEY"

	SwapTimeoutConfigEnvName = envConfigPrefix + "SWAP_TIMEOUT"

	SwapPriorityFeeMultiple = envConfigPrefix + "SWAP_PRIORITY_FEE_MULTIPLE"
)

Variables

View Source
var (
	ErrInvalidAirdropTarget          = errors.New("invalid airdrop target owner account")
	ErrInsufficientAirdropperBalance = errors.New("insufficient airdropper balance")
	ErrIneligibleForAirdrop          = errors.New("user isn't eligible for airdrop")
)
View Source
var (
	ErrTimedOutReceivingRequest = errors.New("timed out receiving request")

	ErrTooManyPayments          = newIntentDeniedError("too many payments")
	ErrTransactionLimitExceeded = newIntentDeniedError("dollar value exceeds limit")
	ErrNotManagedByCode         = newIntentDeniedError("at least one account is no longer managed by code")

	ErrInvalidSignature  = errors.New("invalid signature provided")
	ErrMissingSignature  = errors.New("at least one signature is missing")
	ErrTooManySignatures = errors.New("too many signatures provided")

	ErrNotImplemented = errors.New("feature not implemented")
)

Functions

func GetNewAirdropIntentId

func GetNewAirdropIntentId(airdropType AirdropType, reference string) string

Consistent intent ID that maps to a 32 byte buffer

func GetOldAirdropIntentId

func GetOldAirdropIntentId(airdropType AirdropType, reference string) string

func NewTransactionServer

func NewTransactionServer(
	data code_data.Provider,
	airdropIntegration AirdropIntegration,
	antispamGuard *antispam.Guard,
	amlGuard *aml.Guard,
	configProvider ConfigProvider,
) transactionpb.TransactionServer

Types

type AirdropIntegration

type AirdropIntegration interface {
	// GetWelcomeBonusAmount returns the amount that should be paid for the
	// welcome bonus. Return 0 amount if the airdrop should not be sent.
	GetWelcomeBonusAmount(ctx context.Context, owner *common.Account) (float64, currency_lib.Code, error)
}

func NewDefaultAirdropIntegration

func NewDefaultAirdropIntegration() AirdropIntegration

NewDefaultAirdropIntegration retuns an AirdropIntegration that sends $1 USD to everyone

type AirdropType

type AirdropType uint8
const (
	AirdropTypeUnknown AirdropType = iota
	AirdropTypeGiveFirstCrypto
	AirdropTypeGetFirstCrypto
)

func (AirdropType) String

func (t AirdropType) String() string

type ConfigProvider

type ConfigProvider func() *conf

ConfigProvider defines how config values are pulled

func WithEnvConfigs

func WithEnvConfigs() ConfigProvider

WithEnvConfigs returns configuration pulled from environment variables

type CreateActionHandler

type CreateActionHandler interface {
	// FulfillmentCount returns the total number of fulfillments that
	// will be created for the action.
	FulfillmentCount() int

	// PopulateMetadata populates action metadata into the provided record
	PopulateMetadata(actionRecord *action.Record) error

	// GetServerParameter gets the server parameter for the action within the context
	// of the intent.
	GetServerParameter() *transactionpb.ServerParameter

	// RequiresNonce determines whether a nonce should be acquired for the
	// fulfillment being created. This should be true whenever a virtual
	// instruction needs to be signed by the client.
	RequiresNonce(fulfillmentIndex int) bool

	// GetFulfillmentMetadata gets metadata for the fulfillment being created
	GetFulfillmentMetadata(
		index int,
		nonce *common.Account,
		bh solana.Blockhash,
	) (*newFulfillmentMetadata, error)

	// OnSaveToDB is a callback when the action is being saved to the DB
	// within the scope of a DB transaction. Additional supporting DB records
	// (ie. not the action or fulfillment records) relevant to the action should
	// be saved here.
	OnSaveToDB(ctx context.Context) error
}

CreateActionHandler is an interface for creating new actions

func NewFeePaymentActionHandler

func NewFeePaymentActionHandler(protoAction *transactionpb.FeePaymentAction, feeCollector *common.Account) (CreateActionHandler, error)

func NewNoPrivacyTransferActionHandler

func NewNoPrivacyTransferActionHandler(protoAction *transactionpb.NoPrivacyTransferAction) (CreateActionHandler, error)

func NewNoPrivacyWithdrawActionHandler

func NewNoPrivacyWithdrawActionHandler(intentRecord *intent.Record, protoAction *transactionpb.NoPrivacyWithdrawAction) (CreateActionHandler, error)

func NewOpenAccountActionHandler

func NewOpenAccountActionHandler(data code_data.Provider, protoAction *transactionpb.OpenAccountAction, protoMetadata *transactionpb.Metadata) (CreateActionHandler, error)

type CreateIntentHandler

type CreateIntentHandler interface {
	// PopulateMetadata adds intent metadata to the provided intent record
	// using the client-provided protobuf variant. No other fields in the
	// intent should be modified.
	PopulateMetadata(ctx context.Context, intentRecord *intent.Record, protoMetadata *transactionpb.Metadata) error

	// IsNoop determines whether the intent is a no-op operation. SubmitIntent will
	// simply return OK and stop any further intent processing.
	//
	// Note: This occurs before validation, so if anything appears out-of-order, then
	// the recommendation is to return false and have the verification logic catch the
	// error.
	IsNoop(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) (bool, error)

	// GetAdditionalAccountsToLock gets additional accounts to apply distributed
	// locking on that are specific to an intent.
	//
	// Note: Assumes relevant information is contained in the intent record after
	// calling PopulateMetadata.
	GetAdditionalAccountsToLock(ctx context.Context, intentRecord *intent.Record) (*lockableAccounts, error)

	// AllowCreation determines whether the new intent creation should be allowed.
	AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error

	// OnSaveToDB is a callback when the intent is being saved to the DB
	// within the scope of a DB transaction. Additional supporting DB records
	// (ie. not the intent record) relevant to the intent should be saved here.
	OnSaveToDB(ctx context.Context, intentRecord *intent.Record) error

	// OnCommittedToDB is a callback when the intent has been committed to the
	// DB. Any instant side-effects should called here, and can be done async
	// in a new goroutine to not affect SubmitIntent latency.
	//
	// Note: Any errors generated here have no effect on rolling back the intent.
	//       This is all best-effort up to this point. Use a worker for things
	//       requiring retries!
	OnCommittedToDB(ctx context.Context, intentRecord *intent.Record) error
}

CreateIntentHandler is an interface for handling new intent creations

func NewOpenAccountsIntentHandler

func NewOpenAccountsIntentHandler(conf *conf, data code_data.Provider, antispamGuard *antispam.Guard) CreateIntentHandler

func NewReceivePaymentsPubliclyIntentHandler

func NewReceivePaymentsPubliclyIntentHandler(
	conf *conf,
	data code_data.Provider,
	antispamGuard *antispam.Guard,
	amlGuard *aml.Guard,
) CreateIntentHandler

func NewSendPublicPaymentIntentHandler

func NewSendPublicPaymentIntentHandler(
	conf *conf,
	data code_data.Provider,
	antispamGuard *antispam.Guard,
	amlGuard *aml.Guard,
) CreateIntentHandler

type IntentDeniedError

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

func (IntentDeniedError) Error

func (e IntentDeniedError) Error() string

type IntentValidationError

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

func (IntentValidationError) Error

func (e IntentValidationError) Error() string

type LocalSimulationResult

type LocalSimulationResult struct {
	SimulationsByAccount map[string]TokenAccountSimulation
}

func LocalSimulation

func LocalSimulation(ctx context.Context, data code_data.Provider, actions []*transactionpb.Action) (*LocalSimulationResult, error)

LocalSimulation simulates actions as if they were executed on the blockchain taking into account cached Code DB state.

func (LocalSimulationResult) CountFeePayments

func (s LocalSimulationResult) CountFeePayments() int

func (LocalSimulationResult) GetClosedAccounts

func (s LocalSimulationResult) GetClosedAccounts() []TokenAccountSimulation

func (LocalSimulationResult) GetFeePayments

func (s LocalSimulationResult) GetFeePayments() []TransferSimulation

func (LocalSimulationResult) GetOpenedAccounts

func (s LocalSimulationResult) GetOpenedAccounts() []TokenAccountSimulation

func (LocalSimulationResult) HasAnyFeePayments

func (s LocalSimulationResult) HasAnyFeePayments() bool

type NoPrivacyTransferActionHandler

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

func (*NoPrivacyTransferActionHandler) FulfillmentCount

func (h *NoPrivacyTransferActionHandler) FulfillmentCount() int

func (*NoPrivacyTransferActionHandler) GetFulfillmentMetadata

func (h *NoPrivacyTransferActionHandler) GetFulfillmentMetadata(
	index int,
	nonce *common.Account,
	bh solana.Blockhash,
) (*newFulfillmentMetadata, error)

func (*NoPrivacyTransferActionHandler) GetServerParameter

func (*NoPrivacyTransferActionHandler) OnSaveToDB

func (*NoPrivacyTransferActionHandler) PopulateMetadata

func (h *NoPrivacyTransferActionHandler) PopulateMetadata(actionRecord *action.Record) error

func (*NoPrivacyTransferActionHandler) RequiresNonce

func (h *NoPrivacyTransferActionHandler) RequiresNonce(index int) bool

type NoPrivacyWithdrawActionHandler

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

func (*NoPrivacyWithdrawActionHandler) FulfillmentCount

func (h *NoPrivacyWithdrawActionHandler) FulfillmentCount() int

func (*NoPrivacyWithdrawActionHandler) GetFulfillmentMetadata

func (h *NoPrivacyWithdrawActionHandler) GetFulfillmentMetadata(
	index int,
	nonce *common.Account,
	bh solana.Blockhash,
) (*newFulfillmentMetadata, error)

func (*NoPrivacyWithdrawActionHandler) GetServerParameter

func (*NoPrivacyWithdrawActionHandler) OnSaveToDB

func (*NoPrivacyWithdrawActionHandler) PopulateMetadata

func (h *NoPrivacyWithdrawActionHandler) PopulateMetadata(actionRecord *action.Record) error

func (*NoPrivacyWithdrawActionHandler) RequiresNonce

func (h *NoPrivacyWithdrawActionHandler) RequiresNonce(index int) bool

type OpenAccountActionHandler

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

func (*OpenAccountActionHandler) FulfillmentCount

func (h *OpenAccountActionHandler) FulfillmentCount() int

func (*OpenAccountActionHandler) GetFulfillmentMetadata

func (h *OpenAccountActionHandler) GetFulfillmentMetadata(
	index int,
	nonce *common.Account,
	bh solana.Blockhash,
) (*newFulfillmentMetadata, error)

func (*OpenAccountActionHandler) GetServerParameter

func (h *OpenAccountActionHandler) GetServerParameter() *transactionpb.ServerParameter

func (*OpenAccountActionHandler) OnSaveToDB

func (h *OpenAccountActionHandler) OnSaveToDB(ctx context.Context) error

func (*OpenAccountActionHandler) PopulateMetadata

func (h *OpenAccountActionHandler) PopulateMetadata(actionRecord *action.Record) error

func (*OpenAccountActionHandler) RequiresNonce

func (h *OpenAccountActionHandler) RequiresNonce(index int) bool

type OpenAccountsIntentHandler

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

func (*OpenAccountsIntentHandler) AllowCreation

func (h *OpenAccountsIntentHandler) AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error

func (*OpenAccountsIntentHandler) GetAdditionalAccountsToLock

func (h *OpenAccountsIntentHandler) GetAdditionalAccountsToLock(ctx context.Context, intentRecord *intent.Record) (*lockableAccounts, error)

func (*OpenAccountsIntentHandler) IsNoop

func (h *OpenAccountsIntentHandler) IsNoop(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) (bool, error)

func (*OpenAccountsIntentHandler) OnCommittedToDB

func (h *OpenAccountsIntentHandler) OnCommittedToDB(ctx context.Context, intentRecord *intent.Record) error

func (*OpenAccountsIntentHandler) OnSaveToDB

func (h *OpenAccountsIntentHandler) OnSaveToDB(ctx context.Context, intentRecord *intent.Record) error

func (*OpenAccountsIntentHandler) PopulateMetadata

func (h *OpenAccountsIntentHandler) PopulateMetadata(ctx context.Context, intentRecord *intent.Record, protoMetadata *transactionpb.Metadata) error

type ReceivePaymentsPubliclyIntentHandler

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

Generally needs a rewrite to send funds to the primary account

func (*ReceivePaymentsPubliclyIntentHandler) AllowCreation

func (h *ReceivePaymentsPubliclyIntentHandler) AllowCreation(ctx context.Context, intentRecord *intent.Record, untypedMetadata *transactionpb.Metadata, actions []*transactionpb.Action) error

func (*ReceivePaymentsPubliclyIntentHandler) GetAdditionalAccountsToLock

func (h *ReceivePaymentsPubliclyIntentHandler) GetAdditionalAccountsToLock(ctx context.Context, intentRecord *intent.Record) (*lockableAccounts, error)

func (*ReceivePaymentsPubliclyIntentHandler) IsNoop

func (h *ReceivePaymentsPubliclyIntentHandler) IsNoop(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) (bool, error)

func (*ReceivePaymentsPubliclyIntentHandler) OnCommittedToDB

func (h *ReceivePaymentsPubliclyIntentHandler) OnCommittedToDB(ctx context.Context, intentRecord *intent.Record) error

func (*ReceivePaymentsPubliclyIntentHandler) OnSaveToDB

func (h *ReceivePaymentsPubliclyIntentHandler) OnSaveToDB(ctx context.Context, intentRecord *intent.Record) error

func (*ReceivePaymentsPubliclyIntentHandler) PopulateMetadata

func (h *ReceivePaymentsPubliclyIntentHandler) PopulateMetadata(ctx context.Context, intentRecord *intent.Record, protoMetadata *transactionpb.Metadata) error

type SendPublicPaymentIntentHandler

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

func (*SendPublicPaymentIntentHandler) AllowCreation

func (h *SendPublicPaymentIntentHandler) AllowCreation(ctx context.Context, intentRecord *intent.Record, untypedMetadata *transactionpb.Metadata, actions []*transactionpb.Action) error

func (*SendPublicPaymentIntentHandler) GetAdditionalAccountsToLock

func (h *SendPublicPaymentIntentHandler) GetAdditionalAccountsToLock(ctx context.Context, intentRecord *intent.Record) (*lockableAccounts, error)

func (*SendPublicPaymentIntentHandler) IsNoop

func (h *SendPublicPaymentIntentHandler) IsNoop(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) (bool, error)

func (*SendPublicPaymentIntentHandler) OnCommittedToDB

func (h *SendPublicPaymentIntentHandler) OnCommittedToDB(ctx context.Context, intentRecord *intent.Record) error

func (*SendPublicPaymentIntentHandler) OnSaveToDB

func (h *SendPublicPaymentIntentHandler) OnSaveToDB(ctx context.Context, intentRecord *intent.Record) error

func (*SendPublicPaymentIntentHandler) PopulateMetadata

func (h *SendPublicPaymentIntentHandler) PopulateMetadata(ctx context.Context, intentRecord *intent.Record, protoMetadata *transactionpb.Metadata) error

type StaleStateError

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

func (StaleStateError) Error

func (e StaleStateError) Error() string

type SwapDeniedError

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

func (SwapDeniedError) Error

func (e SwapDeniedError) Error() string

type SwapValidationError

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

func (SwapValidationError) Error

func (e SwapValidationError) Error() string

type TokenAccountSimulation

type TokenAccountSimulation struct {
	TokenAccount *common.Account

	Transfers []TransferSimulation

	Opened     bool
	OpenAction *transactionpb.Action

	Closed         bool
	CloseAction    *transactionpb.Action
	IsAutoReturned bool
}

func FilterAutoReturnedAccounts

func FilterAutoReturnedAccounts(in []TokenAccountSimulation) []TokenAccountSimulation

func (TokenAccountSimulation) CountIncomingTransfers

func (s TokenAccountSimulation) CountIncomingTransfers() int

func (TokenAccountSimulation) CountOutgoingTransfers

func (s TokenAccountSimulation) CountOutgoingTransfers() int

func (TokenAccountSimulation) CountPrivateTransfers

func (s TokenAccountSimulation) CountPrivateTransfers() int

func (TokenAccountSimulation) CountPublicTransfers

func (s TokenAccountSimulation) CountPublicTransfers() int

func (TokenAccountSimulation) CountWithdrawals

func (s TokenAccountSimulation) CountWithdrawals() int

func (TokenAccountSimulation) EnforceBalances

func (s TokenAccountSimulation) EnforceBalances(ctx context.Context, data code_data.Provider, currentBalance uint64) error

func (TokenAccountSimulation) GetAutoReturns

func (s TokenAccountSimulation) GetAutoReturns() []TransferSimulation

func (TokenAccountSimulation) GetDeltaQuarks

func (s TokenAccountSimulation) GetDeltaQuarks(includeAutoReturns bool) int64

func (TokenAccountSimulation) GetIncomingTransfers

func (s TokenAccountSimulation) GetIncomingTransfers() []TransferSimulation

func (TokenAccountSimulation) GetOutgoingTransfers

func (s TokenAccountSimulation) GetOutgoingTransfers() []TransferSimulation

func (TokenAccountSimulation) GetPrivateTransfers

func (s TokenAccountSimulation) GetPrivateTransfers() []TransferSimulation

func (TokenAccountSimulation) GetPublicTransfers

func (s TokenAccountSimulation) GetPublicTransfers() []TransferSimulation

func (TokenAccountSimulation) GetWithdraws

func (s TokenAccountSimulation) GetWithdraws() []TransferSimulation

func (TokenAccountSimulation) HasAnyPrivateTransfers

func (s TokenAccountSimulation) HasAnyPrivateTransfers() bool

func (TokenAccountSimulation) HasAnyPublicTransfers

func (s TokenAccountSimulation) HasAnyPublicTransfers() bool

func (TokenAccountSimulation) HasAnyWithdraws

func (s TokenAccountSimulation) HasAnyWithdraws() bool

func (TokenAccountSimulation) HasIncomingTransfer

func (s TokenAccountSimulation) HasIncomingTransfer() bool

func (TokenAccountSimulation) HasOutgoingTransfer

func (s TokenAccountSimulation) HasOutgoingTransfer() bool

func (TokenAccountSimulation) RequiresBalanceCheck

func (s TokenAccountSimulation) RequiresBalanceCheck() bool

func (TokenAccountSimulation) RequiresBalanceFetch

func (s TokenAccountSimulation) RequiresBalanceFetch() bool

type TransferSimulation

type TransferSimulation struct {
	Action       *transactionpb.Action
	IsPrivate    bool
	IsWithdraw   bool
	IsFee        bool
	IsAutoReturn bool
	DeltaQuarks  int64
}

todo: Make it easier to extract accounts from a TransferSimulation (see some fee payment validation logic)

func FilterAutoReturnTransfers

func FilterAutoReturnTransfers(in []TransferSimulation) []TransferSimulation

Jump to

Keyboard shortcuts

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