decred.org/dcrdex@v1.0.5/tatanka/tanka/swaps.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package tanka 5 6 import ( 7 "encoding/binary" 8 "encoding/hex" 9 "time" 10 11 "github.com/decred/dcrd/crypto/blake256" 12 ) 13 14 type Order struct { 15 From PeerID `json:"from"` 16 BaseID uint32 `json:"baseID"` 17 QuoteID uint32 `json:"quoteID"` 18 Sell bool `json:"sell"` 19 Qty uint64 `json:"qty"` 20 Rate uint64 `json:"rate"` 21 // LotSize: Tatankanet does not prescribe a lot size. Instead, users must 22 // select their own minimum minimum lot size. The user's UI should ignore 23 // orderbook orders that don't have the requisite lot size. The UI should 24 // show lot size selection in terms of a sliding scale of fee exposure. 25 // Lot sizes can only be powers of 2. 26 LotSize uint64 `json:"lotSize"` 27 // MinFeeRate: Tatankanet does not prescribe a fee rate on an order, but it 28 // does supply a suggested fee rate that is updated periodically. The user's 29 // UI should ignore an order from the order book if its MinFeeRate falls 30 // below the Tatnkanet suggested rate. 31 MinFeeRate uint64 `json:"minFeeRate"` 32 Stamp time.Time `json:"stamp"` 33 Expiration time.Time `json:"expiration"` 34 } 35 36 func (ord *Order) ID() [32]byte { 37 const msgLen = 32 + 4 + 4 + 1 + 8 + 8 + 8 + 8 + 8 + 8 38 b := make([]byte, msgLen) 39 copy(b[:32], ord.From[:]) 40 binary.BigEndian.PutUint32(b[32:36], ord.BaseID) 41 binary.BigEndian.PutUint32(b[36:40], ord.QuoteID) 42 if ord.Sell { 43 b[41] = 1 44 } 45 binary.BigEndian.PutUint64(b[41:49], ord.Qty) 46 binary.BigEndian.PutUint64(b[49:57], ord.Rate) 47 binary.BigEndian.PutUint64(b[57:65], ord.LotSize) 48 binary.BigEndian.PutUint64(b[65:73], ord.MinFeeRate) 49 binary.BigEndian.PutUint64(b[73:81], uint64(ord.Stamp.UnixMilli())) 50 binary.BigEndian.PutUint64(b[81:89], uint64(ord.Expiration.UnixMilli())) 51 return blake256.Sum256(b) 52 53 } 54 55 type ID32 [32]byte 56 57 func (i ID32) String() string { 58 return hex.EncodeToString(i[:]) 59 } 60 61 type Match struct { 62 From PeerID `json:"from"` 63 OrderID ID32 `json:"orderID"` 64 Qty uint64 `json:"qty"` 65 Stamp time.Time `json:"stamp"` 66 } 67 68 func (m *Match) ID() ID32 { 69 const msgLen = 32 + 32 + 8 + 8 70 b := make([]byte, msgLen) 71 copy(b[:32], m.From[:]) 72 copy(b[32:64], m.OrderID[:]) 73 binary.BigEndian.PutUint64(b[64:72], m.Qty) 74 binary.BigEndian.PutUint64(b[72:80], uint64(m.Stamp.UnixMilli())) 75 return blake256.Sum256(b) 76 } 77 78 type MatchAcceptance struct { 79 OrderID ID32 `json:"orderID"` 80 MatchID ID32 `json:"matchID"` 81 } 82 83 type MarketParameters struct { 84 BaseID uint32 `json:"baseID"` 85 QuoteID uint32 `json:"quoteID"` 86 }