Documentation ¶
Index ¶
- Constants
- Variables
- func NewAssetResource(ctx context.Context, asset *Asset) mint.AssetResource
- func NewBalanceResource(ctx context.Context, balance *Balance) mint.BalanceResource
- func NewCrossingResource(ctx context.Context, crossing *Crossing) mint.CrossingResource
- func NewOfferResource(ctx context.Context, offer *Offer) mint.OfferResource
- func NewOperationResource(ctx context.Context, operation *Operation) mint.OperationResource
- func NewTransactionResource(ctx context.Context, transaction *Transaction, operations []*Operation, ...) mint.TransactionResource
- type Amount
- type Asset
- func CreateCanonicalAsset(ctx context.Context, owner string, code string, scale int8) (*Asset, error)
- func LoadAssetListByOwner(ctx context.Context, createdBefore time.Time, limit uint, owner string) ([]Asset, error)
- func LoadCanonicalAssetByName(ctx context.Context, name string) (*Asset, error)
- func LoadCanonicalAssetByOwnerCodeScale(ctx context.Context, owner string, code string, scale int8) (*Asset, error)
- type Balance
- func CreateCanonicalBalance(ctx context.Context, owner string, asset string, holder string, value Amount) (*Balance, error)
- func CreatePropagatedBalance(ctx context.Context, owner string, token string, created time.Time, ...) (*Balance, error)
- func LoadBalanceListByAsset(ctx context.Context, createdBefore time.Time, limit uint, asset string) ([]Balance, error)
- func LoadBalanceListByHolder(ctx context.Context, createdBefore time.Time, limit uint, holder string) ([]Balance, error)
- func LoadCanonicalBalanceByAssetHolder(ctx context.Context, asset string, holder string) (*Balance, error)
- func LoadCanonicalBalanceByID(ctx context.Context, id string) (*Balance, error)
- func LoadCanonicalBalanceByOwnerToken(ctx context.Context, owner string, token string) (*Balance, error)
- func LoadOrCreateCanonicalBalanceByAssetHolder(ctx context.Context, owner string, asset string, holder string) (*Balance, error)
- func LoadPropagatedBalanceByOwnerToken(ctx context.Context, owner string, token string) (*Balance, error)
- type Crossing
- func CreateCanonicalCrossing(ctx context.Context, owner string, offer string, amount Amount, ...) (*Crossing, error)
- func LoadCanonicalCrossingByTransactionHop(ctx context.Context, transaction string, hop int8) (*Crossing, error)
- func LoadCanonicalCrossingsByTransaction(ctx context.Context, transaction string) ([]*Crossing, error)
- type ErrUniqueConstraintViolation
- type OfPath
- type Offer
- func CreateCanonicalOffer(ctx context.Context, owner string, baseAsset string, quoteAsset string, ...) (*Offer, error)
- func CreatePropagatedOffer(ctx context.Context, owner string, token string, created time.Time, ...) (*Offer, error)
- func LoadCanonicalOfferByID(ctx context.Context, id string) (*Offer, error)
- func LoadCanonicalOfferByOwnerToken(ctx context.Context, owner string, token string) (*Offer, error)
- func LoadOfferListByBaseAsset(ctx context.Context, createdBefore time.Time, limit uint, asset string) ([]Offer, error)
- func LoadOfferListByQuoteAsset(ctx context.Context, createdBefore time.Time, limit uint, asset string) ([]Offer, error)
- func LoadPropagatedOfferByID(ctx context.Context, id string) (*Offer, error)
- func LoadPropagatedOfferByOwnerToken(ctx context.Context, owner string, token string) (*Offer, error)
- type Operation
- func CreateCanonicalOperation(ctx context.Context, owner string, asset string, source string, ...) (*Operation, error)
- func CreatePropagatedOperation(ctx context.Context, owner string, token string, created time.Time, ...) (*Operation, error)
- func LoadCanonicalOperationByID(ctx context.Context, id string) (*Operation, error)
- func LoadCanonicalOperationByOwnerToken(ctx context.Context, owner string, token string) (*Operation, error)
- func LoadCanonicalOperationByTransactionHop(ctx context.Context, transaction string, hop int8) (*Operation, error)
- func LoadCanonicalOperationsByTransaction(ctx context.Context, transaction string) ([]*Operation, error)
- func LoadPropagatedOperationByOwnerToken(ctx context.Context, owner string, token string) (*Operation, error)
- type Task
- type Transaction
- func CreateCanonicalTransaction(ctx context.Context, owner string, baseAsset string, quoteAsset string, ...) (*Transaction, error)
- func CreatePropagatedTransaction(ctx context.Context, token string, created time.Time, owner string, ...) (*Transaction, error)
- func LoadCanonicalTransactionByOwnerToken(ctx context.Context, owner string, token string) (*Transaction, error)
- func LoadPropagatedTransactionByOwnerToken(ctx context.Context, owner string, token string) (*Transaction, error)
- func LoadTransactionByID(ctx context.Context, id string) (*Transaction, error)
- type User
Constants ¶
const ( // AssetMinScale is the minimal value for an asset scale. AssetMinScale int8 = 0 // AssetMaxScale is the minimal value for an asset scale. AssetMaxScale int8 = 24 )
Variables ¶
var AssetCodeRegexp = regexp.MustCompile("^[A-Z0-9\\-]{1,64}$")
AssetCodeRegexp is used to validate asset codes at creation.
var MaxAssetAmount = new(big.Int).Exp( new(big.Int).SetInt64(2), new(big.Int).SetInt64(128), nil)
MaxAssetAmount is the maximum amount for an asset (2^128).
Functions ¶
func NewAssetResource ¶
func NewAssetResource( ctx context.Context, asset *Asset, ) mint.AssetResource
NewAssetResource generates a new resource.
func NewBalanceResource ¶
func NewBalanceResource( ctx context.Context, balance *Balance, ) mint.BalanceResource
NewBalanceResource generates a new resource.
func NewCrossingResource ¶
func NewCrossingResource( ctx context.Context, crossing *Crossing, ) mint.CrossingResource
NewCrossingResource generates a new resource.
func NewOfferResource ¶
func NewOfferResource( ctx context.Context, offer *Offer, ) mint.OfferResource
NewOfferResource generates a new resource.
func NewOperationResource ¶
func NewOperationResource( ctx context.Context, operation *Operation, ) mint.OperationResource
NewOperationResource generates a new resource.
func NewTransactionResource ¶
func NewTransactionResource( ctx context.Context, transaction *Transaction, operations []*Operation, crossings []*Crossing, ) mint.TransactionResource
NewTransactionResource generates a new resource.
Types ¶
type Asset ¶
type Asset struct { Owner string Token string Created time.Time Propagation mint.PgType Code string // Asset code. Scale int8 // Asset scale. }
Asset represents an asset object. Asset are created by users (issuer).
func CreateCanonicalAsset ¶
func CreateCanonicalAsset( ctx context.Context, owner string, code string, scale int8, ) (*Asset, error)
CreateCanonicalAsset creates and stores a new Asset object.
func LoadAssetListByOwner ¶
func LoadAssetListByOwner( ctx context.Context, createdBefore time.Time, limit uint, owner string, ) ([]Asset, error)
LoadAssetListByOwner loads an asset list by owner.
func LoadCanonicalAssetByName ¶
LoadCanonicalAssetByName attempts to load an asset by its name.
type Balance ¶
type Balance struct { Owner string Token string Created time.Time Propagation mint.PgType Asset string // Asset name. Holder string // Holder address. Value Amount }
Balance represents a user balance for a given asset. Balances are updated as operations are created and then propagated.
- Canonical balances are stored on the mint of the balance's asset owner (which acts as source of truth on its state).
- Propagated balances are indicatively stored on the mints of the balances's holders.
func CreateCanonicalBalance ¶
func CreateCanonicalBalance( ctx context.Context, owner string, asset string, holder string, value Amount, ) (*Balance, error)
CreateCanonicalBalance creates and store a new Balance object. Only one balance can exist for an asset, holder pair.
func CreatePropagatedBalance ¶
func CreatePropagatedBalance( ctx context.Context, owner string, token string, created time.Time, asset string, holder string, value Amount, ) (*Balance, error)
CreatePropagatedBalance creates and store a new propagated Balance object.
func LoadBalanceListByAsset ¶
func LoadBalanceListByAsset( ctx context.Context, createdBefore time.Time, limit uint, asset string, ) ([]Balance, error)
LoadBalanceListByAsset loads a balance list by asset.
func LoadBalanceListByHolder ¶
func LoadBalanceListByHolder( ctx context.Context, createdBefore time.Time, limit uint, holder string, ) ([]Balance, error)
LoadBalanceListByHolder loads a balance list by holder.
func LoadCanonicalBalanceByAssetHolder ¶
func LoadCanonicalBalanceByAssetHolder( ctx context.Context, asset string, holder string, ) (*Balance, error)
LoadCanonicalBalanceByAssetHolder attempts to load a balance for the given holder address and asset name.
func LoadCanonicalBalanceByID ¶
LoadCanonicalBalanceByID attempts to load the canonical balanceffer for the given id.
func LoadCanonicalBalanceByOwnerToken ¶
func LoadCanonicalBalanceByOwnerToken( ctx context.Context, owner string, token string, ) (*Balance, error)
LoadCanonicalBalanceByOwnerToken attempts to load a canonical balance for the given owner and token.
func LoadOrCreateCanonicalBalanceByAssetHolder ¶
func LoadOrCreateCanonicalBalanceByAssetHolder( ctx context.Context, owner string, asset string, holder string, ) (*Balance, error)
LoadOrCreateCanonicalBalanceByAssetHolder loads an existing balance for the specified asset and holder or creates one (with a 0 value) if it does not exist.
type Crossing ¶
type Crossing struct { Owner string Token string Created time.Time Propagation mint.PgType Offer string Amount Amount Status mint.TxStatus Transaction string `db:"txn"` Hop int8 `db:"hop"` }
Crossing represents a transaction crossing an offer and consuming some of its amount. Crossings are not propagated.
func CreateCanonicalCrossing ¶
func CreateCanonicalCrossing( ctx context.Context, owner string, offer string, amount Amount, status mint.TxStatus, transaction string, hop int8, ) (*Crossing, error)
CreateCanonicalCrossing creates and stores a new Crossing object.
func LoadCanonicalCrossingByTransactionHop ¶
func LoadCanonicalCrossingByTransactionHop( ctx context.Context, transaction string, hop int8, ) (*Crossing, error)
LoadCanonicalCrossingByTransactionHop attempts to load the crossing for the given transaction and hop.
type ErrUniqueConstraintViolation ¶
type ErrUniqueConstraintViolation struct {
Err error
}
ErrUniqueConstraintViolation is returned when a object insertion violates a unique constraint.
func (ErrUniqueConstraintViolation) Error ¶
func (e ErrUniqueConstraintViolation) Error() string
type OfPath ¶
type OfPath []string
OfPath is an offer path and implemets sql.Scanner and dirver.Valuer for easy serialization.
type Offer ¶
type Offer struct { Owner string Token string Created time.Time Propagation mint.PgType BaseAsset string `db:"base_asset"` // BaseAsset name. QuoteAsset string `db:"quote_asset"` // QuoteAsset name. BasePrice Amount `db:"base_price"` QuotePrice Amount `db:"quote_price"` Amount Amount Status mint.OfStatus Remainder Amount }
Offer represents an offer for an asset pair.
- Offers are always represented as asks (ask on pair A/B offer to sell A (base asset) for B (quote asset)). Amounts are expressed in quote asset.
- Canonical offers are stored on the mint of the offer's owner (which acts as source of truth on its state).
- Propagated offers are indicatively stored on the mints of the offers's assets, to compute order books.
func CreateCanonicalOffer ¶
func CreateCanonicalOffer( ctx context.Context, owner string, baseAsset string, quoteAsset string, basePrice Amount, quotePrice Amount, amount Amount, status mint.OfStatus, remainder Amount, ) (*Offer, error)
CreateCanonicalOffer creates and stores a new canonical Offer object.
func CreatePropagatedOffer ¶
func CreatePropagatedOffer( ctx context.Context, owner string, token string, created time.Time, baseAsset string, quoteAsset string, basePrice Amount, quotePrice Amount, amount Amount, status mint.OfStatus, remainder Amount, ) (*Offer, error)
CreatePropagatedOffer creates and stores a new propagated Offer object.
func LoadCanonicalOfferByID ¶
LoadCanonicalOfferByID attempts to load the canonical offer for the given id.
func LoadCanonicalOfferByOwnerToken ¶
func LoadCanonicalOfferByOwnerToken( ctx context.Context, owner string, token string, ) (*Offer, error)
LoadCanonicalOfferByOwnerToken attempts to load the canonical offer for the given owner and token.
func LoadOfferListByBaseAsset ¶
func LoadOfferListByBaseAsset( ctx context.Context, createdBefore time.Time, limit uint, asset string, ) ([]Offer, error)
LoadOfferListByBaseAsset loads a balance list by base asset.
func LoadOfferListByQuoteAsset ¶
func LoadOfferListByQuoteAsset( ctx context.Context, createdBefore time.Time, limit uint, asset string, ) ([]Offer, error)
LoadOfferListByQuoteAsset loads a balance list by quote asset.
func LoadPropagatedOfferByID ¶
LoadPropagatedOfferByID attempts to load the propagated offer for the given id.
type Operation ¶
type Operation struct { Owner string // Owner address. Token string Created time.Time Propagation mint.PgType Asset string // Asset name. Source string // Source address (if owner, issuance). Destination string // Destination addres (if owner, annihilation). Amount Amount Status mint.TxStatus Transaction *string `db:"txn"` Hop *int8 `db:"hop"` }
Operation represents a movement of an asset. Asset owners cannot hold a balance in their own assets so operations referring to the asset owner are either issuing or annihilating the asset.
- Canonical operations are stored on the mint of the operation's owner (which acts as source of truth on its state).
- Propagated operations are stored on the mints of the operation's source or destination, for retrieval by impacted users (only settled operations are reserved).
- When part of a transaction, an operation refers the transaction and hop.
func CreateCanonicalOperation ¶
func CreateCanonicalOperation( ctx context.Context, owner string, asset string, source string, destination string, amount Amount, status mint.TxStatus, transaction *string, hop *int8, ) (*Operation, error)
CreateCanonicalOperation creates and stores a new Operation.
func CreatePropagatedOperation ¶
func CreatePropagatedOperation( ctx context.Context, owner string, token string, created time.Time, asset string, source string, destination string, amount Amount, status mint.TxStatus, transaction *string, hop *int8, ) (*Operation, error)
CreatePropagatedOperation creates and stores a new Operation.
func LoadCanonicalOperationByID ¶
LoadCanonicalOperationByID attempts to load the canonical operation for the given id.
func LoadCanonicalOperationByOwnerToken ¶
func LoadCanonicalOperationByOwnerToken( ctx context.Context, owner string, token string, ) (*Operation, error)
LoadCanonicalOperationByOwnerToken attempts to load the canonical operation for the given owner and token.
func LoadCanonicalOperationByTransactionHop ¶
func LoadCanonicalOperationByTransactionHop( ctx context.Context, transaction string, hop int8, ) (*Operation, error)
LoadCanonicalOperationByTransactionHop attempts to load the canonical operation for the given transaction and hop.
func LoadCanonicalOperationsByTransaction ¶
func LoadCanonicalOperationsByTransaction( ctx context.Context, transaction string, ) ([]*Operation, error)
LoadCanonicalOperationsByTransaction loads all operations that are associated with the specified transaction.
type Task ¶
type Task struct { Token string Created time.Time Name mint.TkName Subject string Status mint.TkStatus Retry uint }
Task represents a task object.
func CreateTask ¶
func CreateTask( ctx context.Context, created time.Time, name mint.TkName, subject string, status mint.TkStatus, retry uint, ) (*Task, error)
CreateTask creates and stores a new Task.
func LoadPendingTasks ¶
LoadPendingTasks loads all tasks that are marked as pending.
type Transaction ¶
type Transaction struct { Owner string Token string Created time.Time Propagation mint.PgType BaseAsset string `db:"base_asset"` // BaseAsset name. QuoteAsset string `db:"quote_asset"` // QuoteAsset name. Amount Amount Destination string Path OfPath Status mint.TxStatus Lock string Secret *string }
Transaction represents a transaction across a chain of offers.
func CreateCanonicalTransaction ¶
func CreateCanonicalTransaction( ctx context.Context, owner string, baseAsset string, quoteAsset string, amount Amount, destination string, path []string, status mint.TxStatus, ) (*Transaction, error)
CreateCanonicalTransaction creates and stores a new canonical Transaction object.
func CreatePropagatedTransaction ¶
func CreatePropagatedTransaction( ctx context.Context, token string, created time.Time, owner string, baseAsset string, quoteAsset string, amount Amount, destination string, path []string, status mint.TxStatus, lock string, ) (*Transaction, error)
CreatePropagatedTransaction creates and stores a new propagated Transaction object.
func LoadCanonicalTransactionByOwnerToken ¶
func LoadCanonicalTransactionByOwnerToken( ctx context.Context, owner string, token string, ) (*Transaction, error)
LoadCanonicalTransactionByOwnerToken attempts to load the canonical transaction for the given owner and token.
func LoadPropagatedTransactionByOwnerToken ¶
func LoadPropagatedTransactionByOwnerToken( ctx context.Context, owner string, token string, ) (*Transaction, error)
LoadPropagatedTransactionByOwnerToken attempts to load the propagated transaction for the given owner and token.
func LoadTransactionByID ¶
func LoadTransactionByID( ctx context.Context, id string, ) (*Transaction, error)
LoadTransactionByID attempts to load the transaction (canonical or propagated) for the given owner and token.
type User ¶
type User struct { Token string Created time.Time Username string PasswordHash string `db:"password_hash"` }
User represents a user object. User objects are not managed by the mint and solely accesed in read-only mode, leaving user management to an external system with access to the same underlying mintDB.
func CreateUser ¶
CreateUser creates and stores a new User object.
func LoadUserByToken ¶
LoadUserByToken attempts to load a user with the given user token.
func LoadUserByUsername ¶
LoadUserByUsername attempts to load a user with the given username.
func (*User) CheckPassword ¶
CheckPassword checks if the provided password matches the password hash associated with that user.