Documentation ¶
Index ¶
- Constants
- func CheckMask(mask, hash []byte) bool
- func DefaultSha3() []byte
- func FindValidNonce(text, timestamp string, mask []byte) <-chan []byte
- func GetCancellationEpoch(maker, sender *types.Address, db *gorm.DB) *types.Uint256
- func GetDB(connectionString, passwordURI string) (*gorm.DB, error)
- func OnesCount(data []byte) int
- func PopulateAssetMetadata(orders []Order, db *gorm.DB)
- type AssetAttribute
- type AssetMetadata
- type Cancellation
- type CancellationConsumer
- type Exchange
- type ExchangeLookup
- type FillRecord
- type HashMask
- type IndexConsumer
- type Indexer
- func (indexer *Indexer) Index(order *types.Order) error
- func (indexer *Indexer) RecordCancellation(cancellation *Cancellation) error
- func (indexer *Indexer) RecordFill(fillRecord *FillRecord) error
- func (indexer *Indexer) RecordSpend(makerAddress, tokenAddress, zrxAddress *types.Address, ...) error
- func (indexer *Indexer) UpdateAndPublish(query *gorm.DB, key string, value interface{}, unfillable bool) error
- type Order
- type Pair
- type RecordFillConsumer
- type RecordSpendConsumer
- type SpendRecord
- type Terms
- type TermsManager
- func (tm *TermsManager) CheckAddress(address *types.Address) <-chan bool
- func (tm *TermsManager) CheckTerms(id uint, sig *types.Signature, address *types.Address, timestamp string, ...) (bool, error)
- func (tm *TermsManager) ClearExpiredHashMasks()
- func (tm *TermsManager) GetHashMaskById(id uint) ([]byte, error)
- func (tm *TermsManager) GetNewHashMask(terms *Terms) ([]byte, uint, error)
- func (tm *TermsManager) GetTerms(language string) (*Terms, error)
- func (tm *TermsManager) SaveSig(id uint, sig *types.Signature, address *types.Address, ...) error
- func (tm *TermsManager) UpdateTerms(lang, text string) error
- type TermsSig
Constants ¶
const ( StatusOpen = int64(0) StatusFilled = int64(1) StatusUnfunded = int64(2) StatusCancelled = int64(3) )
Variables ¶
This section is empty.
Functions ¶
func DefaultSha3 ¶
func DefaultSha3() []byte
func FindValidNonce ¶
FindValidNonce finds a valid hash for a given hash mask, Terms, and Timestamp, and returns the Nonce used to generate thas hashmask.
func GetCancellationEpoch ¶
func OnesCount ¶
OnesCount returns how many 1s appear in the binary representation of a string of bytes. Similar to math/bits.OnesCount, but works for arbitrarily sized byte slices.
func PopulateAssetMetadata ¶
Types ¶
type AssetAttribute ¶
type AssetMetadata ¶
type AssetMetadata struct { AssetData types.AssetData `gorm:"primary_key" json:"-"` RawMetadata string `sql:"type:text;" json:"raw_metadata,omitempty"` URI string `json:"token_uri"` Name string `json:"name,omitempty"` ExternalURL string `json:"external_url,omitempty"` Image string `json:"image,omitempty"` Description string `sql:"type:text;" json:"description,omitempty"` BackgroundColor string `json:"background_color,omitempty"` Attributes []AssetAttribute `json:"attributes,omitempty" gorm:"foreignkey:AssetData;association_foreigkey:AssetData" ` RawAttributes string `sql:"type:text;" json:"raw_attributes,omitempty"` }
func (*AssetMetadata) AfterFind ¶
func (meta *AssetMetadata) AfterFind(scope *gorm.Scope)
AfterFind populates Attribute Data upon querying for AssetMetadata. Gorm doesn't like our AssetData property as a primary key in Preload, as it tries to treat it as a collection of bytes instead of a key. This effectively implements preload implicitly, and accounts for Gorm's issues with byte slices and pointers.
func (*AssetMetadata) SetAssetData ¶
func (meta *AssetMetadata) SetAssetData(assetData types.AssetData)
func (*AssetMetadata) UnmarshalJSON ¶
func (meta *AssetMetadata) UnmarshalJSON(data []byte) error
type Cancellation ¶
type CancellationConsumer ¶
type CancellationConsumer struct {
// contains filtered or unexported fields
}
func (*CancellationConsumer) Consume ¶
func (consumer *CancellationConsumer) Consume(msg channels.Delivery)
type ExchangeLookup ¶
type ExchangeLookup struct {
// contains filtered or unexported fields
}
func NewExchangeLookup ¶
func NewExchangeLookup(db *gorm.DB) *ExchangeLookup
func (*ExchangeLookup) ExchangeIsKnown ¶
func (lookup *ExchangeLookup) ExchangeIsKnown(address *types.Address) <-chan uint
func (*ExchangeLookup) GetExchangesByNetwork ¶
func (lookup *ExchangeLookup) GetExchangesByNetwork(network int64) ([]*types.Address, error)
func (*ExchangeLookup) GetNetworkByExchange ¶
func (lookup *ExchangeLookup) GetNetworkByExchange(address *types.Address) (int64, error)
type FillRecord ¶
type HashMask ¶
HashMask is a string of bytes. When a user signs the terms-of-service, they must provide a Nonce that makes the hash of the terms (along with the timestamp) match the hash mask. Matching the hash mask means that any 1 bits in the HashMask must also be 1 in the hash. 0s in the HashMask can be 1 or 0 in the hash.
type IndexConsumer ¶
type IndexConsumer struct {
// contains filtered or unexported fields
}
func NewIndexConsumer ¶
func (*IndexConsumer) Consume ¶
func (consumer *IndexConsumer) Consume(msg channels.Delivery)
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
func (*Indexer) RecordCancellation ¶
func (indexer *Indexer) RecordCancellation(cancellation *Cancellation) error
func (*Indexer) RecordFill ¶
func (indexer *Indexer) RecordFill(fillRecord *FillRecord) error
RecordFill takes information about a filled order and updates the corresponding database record, if any exists.
func (*Indexer) RecordSpend ¶
func (indexer *Indexer) RecordSpend(makerAddress, tokenAddress, zrxAddress *types.Address, assetData types.AssetData, balance *types.Uint256) error
RecordSpend takes information about a token transfer, and updates any orders that might have become unfillable as a result of the transfer.
type Order ¶
type Order struct { types.Order CreatedAt time.Time UpdatedAt time.Time OrderHash []byte `gorm:"primary_key"` Status int64 `gorm:"index"` Price float64 `gorm:"index:price"` FeeRate float64 `gorm:"index:price"` MakerAssetRemaining *types.Uint256 MakerFeeRemaining *types.Uint256 MakerAssetMetadata *AssetMetadata TakerAssetMetadata *AssetMetadata }
func (*Order) Save ¶
Save records the order in the database, defaulting to the specified status. Status should either be db.StatusOpen, or db.StatusUnfunded. If the order is filled based on order.TakerAssetAmountFilled + order.TakerAssetAmountCancelled the status will be recorded as db.StatusFilled regardless of the specified status.
type Pair ¶
Pair tracks pairs of tokens TokenA and TokenB
func GetAllTokenPairs ¶
GetAllTokenPairs returns an unfilitered list of Pairs based on the trading pairs currently present in the database, limited by a count and offset.
func GetTokenABPairs ¶
func GetTokenABPairs(db *gorm.DB, tokenA, tokenB types.AssetData, networkID int) ([]Pair, int, error)
GetTokenABPairs returns a list of Pairs based on the trading pairs currrently present in the database, filtered to include only pairs that include both tokenA and tokenB. There should only be one distinct combination of both token pairs, so there is no offset or limit, but it still returns a list to provide the same return value as the other retrieval methods.
func GetTokenAPairs ¶
func GetTokenAPairs(db *gorm.DB, tokenA types.AssetData, offset, count, networkID int) ([]Pair, int, error)
GetTokenAPairs returns a list of Pairs based on the trading pairs currrently present in the database, filtered to include only pairs that include tokenA and limited by a count and offset.
func (*Pair) MarshalJSON ¶
type RecordFillConsumer ¶
type RecordFillConsumer struct {
// contains filtered or unexported fields
}
func NewRecordFillConsumer ¶
func (*RecordFillConsumer) Consume ¶
func (consumer *RecordFillConsumer) Consume(msg channels.Delivery)
type RecordSpendConsumer ¶
type RecordSpendConsumer struct {
// contains filtered or unexported fields
}
func NewRecordSpendConsumer ¶
func (*RecordSpendConsumer) Consume ¶
func (consumer *RecordSpendConsumer) Consume(msg channels.Delivery)
type SpendRecord ¶
type Terms ¶
type Terms struct { gorm.Model Current bool Lang string Text string `sql:"type:text;"` Valid bool Difficulty int }
Terms represents an instance of the terms of service. There should only be one Current version of the Terms for a given language at a given time, but older versions may remain Valid. The difficulty indicates how many 1 bits a HashMask must have when signing these terms.
type TermsManager ¶
type TermsManager struct {
// contains filtered or unexported fields
}
TermsManager keeps track of a database instance and a cache and provides several interfaces for interacting with the Terms of Service in the database.
func NewTermsManager ¶
func NewTermsManager(db *gorm.DB) *TermsManager
func NewTxTermsManager ¶
func NewTxTermsManager(db *gorm.DB) *TermsManager
func (*TermsManager) CheckAddress ¶
func (tm *TermsManager) CheckAddress(address *types.Address) <-chan bool
Check ensures that a given address has signed the terms
func (*TermsManager) CheckTerms ¶
func (tm *TermsManager) CheckTerms(id uint, sig *types.Signature, address *types.Address, timestamp string, nonce []byte, mask []byte) (bool, error)
CheckTerms verifies that a signature is valid for a given Terms of use, specified by ID.
func (*TermsManager) ClearExpiredHashMasks ¶
func (tm *TermsManager) ClearExpiredHashMasks()
ClearExpiredHashMasks deletes any expired hash masks. These can be deleted even if a corresponding signature has been created; they're only needed during the sign up process.
func (*TermsManager) GetHashMaskById ¶
func (tm *TermsManager) GetHashMaskById(id uint) ([]byte, error)
GetHashMaskById retrieves a HashMask from the database given its ID.
func (*TermsManager) GetNewHashMask ¶
func (tm *TermsManager) GetNewHashMask(terms *Terms) ([]byte, uint, error)
GetNewHashMask generates a HashMask for a Terms object, considering the difficulty for those Terms. It saves the HashMask in the database, and returns the Bytes along with the byte string.
func (*TermsManager) GetTerms ¶
func (tm *TermsManager) GetTerms(language string) (*Terms, error)
GetTerms returns the current Terms object for a given language.
func (*TermsManager) SaveSig ¶
func (tm *TermsManager) SaveSig(id uint, sig *types.Signature, address *types.Address, timestamp, host_ip string, nonce []byte, mask []byte) error
SaveSig verifies that a signature is valid for a given Terms, then saves it to the database
func (*TermsManager) UpdateTerms ¶
func (tm *TermsManager) UpdateTerms(lang, text string) error
UpdateTerms creates a new Terms object in the database, deprecating the old terms
type TermsSig ¶
type TermsSig struct { gorm.Model Signer *types.Address `gorm:"index"` Timestamp string IP string Nonce []byte Banned bool Signature *types.Signature TermsID uint }
TermsSig represent a user's signature of the terms of service. It tracks the address of the signer, when they signed it, the IP they submitted the signature from, the Nonce they used to make the HashMask match, the cryptographic signature, and a reference to the Terms object they signed.