payments

package
v0.0.0-...-8a10f5f Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package payments provides the payment service

Index

Constants

This section is empty.

Variables

Transitions represents the valid forward-transitions for each given state

Functions

func GetAllValidTransitionSequences

func GetAllValidTransitionSequences() [][]QLDBPaymentTransitionState

GetAllValidTransitionSequences returns all valid transition sequences

func RevisionValidInTree

func RevisionValidInTree(
	ctx context.Context,
	client wrappedQldbSdkClient,
	transaction QLDBPaymentTransitionHistoryEntry,
) (bool, error)

RevisionValidInTree verifies a document revision in QLDB using a digest and the Merkle hashes to rederive the digest

func TransitionHistoryIsValid

func TransitionHistoryIsValid(transactionHistory []QLDBPaymentTransitionHistoryEntry) (bool, error)

TransitionHistoryIsValid returns whether a slice of entries representing the entire state history for a given id include exculsively valid transitions.

Types

type BitflyerMachine

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

BitflyerMachine is an implementation of TxStateMachine for Bitflyer's use-case

func (*BitflyerMachine) Authorized

func (bm *BitflyerMachine) Authorized() (QLDBPaymentTransitionState, error)

Authorized implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) Failed

Failed implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) Initialized

func (bm *BitflyerMachine) Initialized() (QLDBPaymentTransitionState, error)

Initialized implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) Paid

Paid implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) Pending

Pending implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) Prepared

Prepared implements TxStateMachine for the Bitflyer machine

func (*BitflyerMachine) SetVersion

func (bm *BitflyerMachine) SetVersion(version int)

SetVersion assigns the version field in the BitflyerMachine to the specified int

type GeminiMachine

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

GeminiMachine is an implementation of TxStateMachine for Gemini's use-case

func (*GeminiMachine) Authorized

func (gm *GeminiMachine) Authorized() (QLDBPaymentTransitionState, error)

Authorized implements TxStateMachine for the Gemini machine

func (*GeminiMachine) Failed

Failed implements TxStateMachine for the Gemini machine

func (*GeminiMachine) Initialized

func (gm *GeminiMachine) Initialized() (QLDBPaymentTransitionState, error)

Initialized implements TxStateMachine for the Gemini machine

func (*GeminiMachine) Paid

Paid implements TxStateMachine for the Gemini machine

func (*GeminiMachine) Pending

Pending implements TxStateMachine for the Gemini machine

func (*GeminiMachine) Prepared

Prepared implements TxStateMachine for the Gemini machine

func (*GeminiMachine) SetVersion

func (gm *GeminiMachine) SetVersion(version int)

SetVersion assigns the version field in the GeminiMachine to the specified int

type QLDBPaymentTransitionData

type QLDBPaymentTransitionData struct {
	Status QLDBPaymentTransitionState `ion:"status"`
}

QLDBPaymentTransitionData represents the data for a transaction. It is stored in QLDB in a serialized format and needs to be separately deserialized from the QLDB ion deserialization.

type QLDBPaymentTransitionHistoryEntry

type QLDBPaymentTransitionHistoryEntry struct {
	BlockAddress qldbPaymentTransitionHistoryEntryBlockAddress `ion:"blockAddress"`
	Hash         QLDBPaymentTransitionHistoryEntryHash         `ion:"hash"`
	Data         QLDBPaymentTransitionHistoryEntryData         `ion:"data"`
	Metadata     QLDBPaymentTransitionHistoryEntryMetadata     `ion:"metadata"`
}

QLDBPaymentTransitionHistoryEntry defines top level entry for a QLDB transaction

func GetQLDBObject

func GetQLDBObject(txn wrappedQldbTxnAPI, id string) (QLDBPaymentTransitionHistoryEntry, error)

GetQLDBObject returns the latests state of an entry for a given ID after validating its transition history.

func GetTransitionHistory

func GetTransitionHistory(txn wrappedQldbTxnAPI, id string) ([]QLDBPaymentTransitionHistoryEntry, error)

GetTransitionHistory returns a slice of entries representing the entire state history for a given id.

func (QLDBPaymentTransitionHistoryEntry) BuildSigningBytes

func (e QLDBPaymentTransitionHistoryEntry) BuildSigningBytes() ([]byte, error)

BuildSigningBytes returns the bytes that should be signed over when creating a signature for a QLDBPaymentTransitionHistoryEntry.

type QLDBPaymentTransitionHistoryEntryData

type QLDBPaymentTransitionHistoryEntryData struct {
	Signature []byte `ion:"signature"`
	Data      []byte `ion:"data"`
}

QLDBPaymentTransitionHistoryEntryData defines data for QLDBPaymentTransitionHistoryEntry

type QLDBPaymentTransitionHistoryEntryHash

type QLDBPaymentTransitionHistoryEntryHash string

QLDBPaymentTransitionHistoryEntryHash defines hash for QLDBPaymentTransitionHistoryEntry

type QLDBPaymentTransitionHistoryEntryMetadata

type QLDBPaymentTransitionHistoryEntryMetadata struct {
	ID      string    `ion:"id"`
	Version int64     `ion:"version"`
	TxTime  time.Time `ion:"txTime"`
	TxID    string    `ion:"txId"`
}

QLDBPaymentTransitionHistoryEntryMetadata defines metadata for QLDBPaymentTransitionHistoryEntry

type QLDBPaymentTransitionHistoryEntrySignature

type QLDBPaymentTransitionHistoryEntrySignature []byte

QLDBPaymentTransitionHistoryEntrySignature defines signature for QLDBPaymentTransitionHistoryEntry

func WriteQLDBObject

func WriteQLDBObject(
	driver wrappedQldbDriverAPI,
	key ed25519.PrivateKey,
	object QLDBPaymentTransitionHistoryEntry,
) (QLDBPaymentTransitionHistoryEntrySignature, error)

WriteQLDBObject persists an object in a transaction after verifying that its change represents a valid state transition.

type QLDBPaymentTransitionState

type QLDBPaymentTransitionState int64

QLDBPaymentTransitionState is an integer representing transaction status

const (
	// Initialized represents the first state that a transaction record
	Initialized QLDBPaymentTransitionState = iota
	// Prepared represents a record that has been prepared for authorization
	Prepared
	// Authorized represents a record that has been authorized
	Authorized
	// Pending represents a record that is being or has been submitted to a processor
	Pending
	Paid
	// Failed represents a record that has failed processing permanently
	Failed
)

func Drive

func Drive[T TxStateMachine](
	ctx context.Context,
	machine T,
	currentTransactionState QLDBPaymentTransitionState,
	currentTransactionVersion int,
) (QLDBPaymentTransitionState, error)

Drive switches on the provided currentTransactionState and executes the appropriate method from the provided TxStateMachine to attempt to progress the state.

func (QLDBPaymentTransitionState) GetValidTransitions

func (q QLDBPaymentTransitionState) GetValidTransitions() []QLDBPaymentTransitionState

GetValidTransitions returns valid transitions

type TxStateMachine

type TxStateMachine interface {
	SetVersion(int)
	Initialized() (QLDBPaymentTransitionState, error)
	Prepared() (QLDBPaymentTransitionState, error)
	Authorized() (QLDBPaymentTransitionState, error)
	Pending() (QLDBPaymentTransitionState, error)
	Paid() (QLDBPaymentTransitionState, error)
	Failed() (QLDBPaymentTransitionState, error)
}

TxStateMachine describes types with the appropriate methods to be Driven as a state machine

type UpholdMachine

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

UpholdMachine is an implementation of TxStateMachine for uphold's use-case

func (*UpholdMachine) Authorized

func (um *UpholdMachine) Authorized() (QLDBPaymentTransitionState, error)

Authorized implements TxStateMachine for uphold machine

func (*UpholdMachine) Failed

Failed implements TxStateMachine for uphold machine

func (*UpholdMachine) Initialized

func (um *UpholdMachine) Initialized() (QLDBPaymentTransitionState, error)

Initialized implements TxStateMachine for uphold machine

func (*UpholdMachine) Paid

Paid implements TxStateMachine for uphold machine

func (*UpholdMachine) Pending

Pending implements TxStateMachine for uphold machine

func (*UpholdMachine) Prepared

Prepared implements TxStateMachine for uphold machine

func (*UpholdMachine) SetVersion

func (um *UpholdMachine) SetVersion(version int)

SetVersion assigns the version field in the GeminiMachine to the specified int

Jump to

Keyboard shortcuts

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