Documentation
¶
Index ¶
- Variables
- func TokenHash(t []byte) []byte
- type BuyProposal
- type BuyProposalInfo
- type BuyProposalResponse
- type BuyerTrade
- type FundsData
- type Handler
- func (sh *Handler) HandleStage(s stages.Stage, t Trade) error
- func (sh *Handler) HandleTrade(t Trade) error
- func (sh *Handler) InstallStageHandler(s stages.Stage, h StageHandlerFunc)
- func (sh *Handler) InstallStageHandlers(hm StageHandlerMap)
- func (sh *Handler) Unhandled(s ...stages.Stage) []stages.Stage
- type Lock
- type LockData
- type OnChainTrade
- func (bt OnChainTrade) AcceptBuyProposal(prop *BuyProposal) error
- func (t *OnChainTrade) Buyer() (BuyerTrade, error)
- func (t *OnChainTrade) Duration() duration.Duration
- func (bt OnChainTrade) GenerateBuyProposal() (*BuyProposal, error)
- func (bt OnChainTrade) GenerateKeys() error
- func (bt OnChainTrade) GenerateToken() (types.Bytes, error)
- func (bt OnChainTrade) Locks() *BuyProposalResponse
- func (t *OnChainTrade) MarshalYAML() (interface{}, error)
- func (t *OnChainTrade) OwnInfo() *TraderInfo
- func (t *OnChainTrade) RecoverableFunds() FundsData
- func (t *OnChainTrade) RecoveryKey() key.Private
- func (bt OnChainTrade) RecoveryTx(lockScript []byte, feePerByte uint64) (tx.Tx, error)
- func (bt OnChainTrade) RecoveryTxFixedFee(lockScript []byte, fee uint64) (tx.Tx, error)
- func (t *OnChainTrade) RedeemKey() key.Private
- func (bt OnChainTrade) RedeemTx(lockScript []byte, feePerByte uint64) (tx.Tx, error)
- func (bt OnChainTrade) RedeemTxFixedFee(lockScript []byte, fee uint64) (tx.Tx, error)
- func (t *OnChainTrade) RedeemableFunds() FundsData
- func (t *OnChainTrade) Role() roles.Role
- func (t *OnChainTrade) Seller() (SellerTrade, error)
- func (bt OnChainTrade) SetLocks(locks *BuyProposalResponse) error
- func (bt OnChainTrade) SetToken(token types.Bytes)
- func (t *OnChainTrade) Stager() *stages.Stager
- func (t *OnChainTrade) Token() types.Bytes
- func (t *OnChainTrade) TokenHash() types.Bytes
- func (t *OnChainTrade) TraderInfo() *TraderInfo
- func (t *OnChainTrade) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Output
- type SellerTrade
- type StageHandlerFunc
- type StageHandlerMap
- type StagesNotHandledError
- type Trade
- type TraderInfo
Constants ¶
This section is empty.
Variables ¶
var ( // NoOpHandler no operation handler NoOpHandler = func(_ Trade) error { return nil } // InterruptHandler interrupt trade handler InterruptHandler = func(_ Trade) error { return ErrInterruptTrade } // DefaultStageHandlers default handlers DefaultStageHandlers = StageHandlerMap{ stages.Done: func(_ Trade) error { return nil }, stages.GenerateKeys: func(tr Trade) error { return tr.GenerateKeys() }, stages.GenerateToken: func(tr Trade) error { btr, err := tr.Buyer() if err != nil { return err } _, err = btr.GenerateToken() return err }, } // ErrInterruptTrade is returned when a trade interruption happens ErrInterruptTrade = errors.New("trade interrupted") )
var ( // ErrNotABuyerTrade is returned if the trade is not a buy ErrNotABuyerTrade = errors.New("not a buyer trade") // ErrNotASellerTrade is returned if the trade is not a sell ErrNotASellerTrade = errors.New("not a seller trade") )
var ( // ErrMismatchTokenHash is returned when there is a token hash mismatch ErrMismatchTokenHash = errors.New("mismatching token hash") // ErrInvalidLockInterval is returned when the time lock interval is invalid ErrInvalidLockInterval = errors.New("invalid lock interval") // ErrMismatchKeyData is returned when there is a mismatch in the key data ErrMismatchKeyData = errors.New("mismatching key data") )
var ErrInvalidLockScript = errors.New("invalid lock script")
ErrInvalidLockScript is returns when the lock script is invalid
var ErrNotEnoughBytes = errors.New("not enough bytes")
ErrNotEnoughBytes is returned the is not possible to read enough random bytes
var ErrNotUTXO = errors.New("not a utxo crypto")
ErrNotUTXO is returned in the case the crypto is not a utxo crypto
Functions ¶
Types ¶
type BuyProposal ¶
type BuyProposal struct { Buyer *BuyProposalInfo `yaml:"buyer"` Seller *BuyProposalInfo `yaml:"seller"` TokenHash types.Bytes `yaml:"token_hash"` RedeemKeyData key.KeyData `yaml:"redeem_key_data"` RecoveryKeyData key.KeyData `yaml:"recovery_key_data"` }
BuyProposal represents a buy proposal
func UnamrshalBuyProposal ¶
func UnamrshalBuyProposal(b []byte) (*BuyProposal, error)
UnamrshalBuyProposal unmarshals a buy proposal
type BuyProposalInfo ¶
type BuyProposalInfo struct { Crypto *cryptos.Crypto `yaml:"crypto"` Amount types.Amount `yaml:"amount"` LockDuration duration.Duration `yaml:"lock_duration"` }
BuyProposalInfo represents a buy proposal trader info
type BuyProposalResponse ¶
BuyProposalResponse is returned when a buy proposal is accepted
func UnamrshalBuyProposalResponse ¶
func UnamrshalBuyProposalResponse(buyer, seller *cryptos.Crypto, b []byte) (*BuyProposalResponse, error)
UnamrshalBuyProposalResponse unmarshals a buy proposal response
type BuyerTrade ¶
type BuyerTrade interface { // GenerateToken generates a new token GenerateToken() (types.Bytes, error) // GenerateBuyProposal generates a buy proposal GenerateBuyProposal() (*BuyProposal, error) // SetLocks sets the locks for the trade SetLocks(locks *BuyProposalResponse) error }
BuyerTrade represents a buyer trade
type FundsData ¶
type FundsData interface { // AddFunds adds funds to the manager AddFunds(funds interface{}) // Funds returns the fund on the manager Funds() interface{} // SetLock sets the lock for the funds SetLock(lock Lock) // Lock returns the lock for the funds Lock() Lock }
FundsData holds information about funds
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a trade handler
func NewHandlerDefaults ¶
func NewHandlerDefaults(hm StageHandlerMap) *Handler
NewHandlerDefaults returns a new *Handler with the default handlers installed
func (*Handler) HandleStage ¶
HandleStage handles a single trade stage
func (*Handler) HandleTrade ¶
HandleTrade handles a trade
func (*Handler) InstallStageHandler ¶
func (sh *Handler) InstallStageHandler(s stages.Stage, h StageHandlerFunc)
InstallStageHandler installs a stage handler
func (*Handler) InstallStageHandlers ¶
func (sh *Handler) InstallStageHandlers(hm StageHandlerMap)
InstallStageHandlers installs multiple handlers from a stage handler map
type Lock ¶
type Lock interface { // Bytes returns the lock bytes Bytes() types.Bytes // LockData returns the lock data LockData() (*LockData, error) // Address returns the address for the given chain Address(chain params.Chain) (string, error) }
Lock represents a cryptocurrency lock
type LockData ¶
type LockData struct { LockTime time.Time TokenHash types.Bytes RedeemKeyData key.KeyData RecoveryKeyData key.KeyData }
LockData represents a lock
type OnChainTrade ¶
type OnChainTrade struct {
// contains filtered or unexported fields
}
func (OnChainTrade) AcceptBuyProposal ¶
func (bt OnChainTrade) AcceptBuyProposal(prop *BuyProposal) error
AcceptBuyProposal implement SellerTrade
func (*OnChainTrade) Buyer ¶
func (t *OnChainTrade) Buyer() (BuyerTrade, error)
func (*OnChainTrade) Duration ¶
func (t *OnChainTrade) Duration() duration.Duration
func (OnChainTrade) GenerateBuyProposal ¶
func (bt OnChainTrade) GenerateBuyProposal() (*BuyProposal, error)
GenerateBuyProposal implement BuyerTrade
func (OnChainTrade) GenerateKeys ¶
func (bt OnChainTrade) GenerateKeys() error
GenerateKeys implement Trade
func (OnChainTrade) GenerateToken ¶
GenerateKeys implement BuyerTrade
func (OnChainTrade) Locks ¶
func (bt OnChainTrade) Locks() *BuyProposalResponse
Locks implement SellerTrade
func (*OnChainTrade) MarshalYAML ¶
func (t *OnChainTrade) MarshalYAML() (interface{}, error)
func (*OnChainTrade) OwnInfo ¶
func (t *OnChainTrade) OwnInfo() *TraderInfo
func (*OnChainTrade) RecoverableFunds ¶
func (t *OnChainTrade) RecoverableFunds() FundsData
func (*OnChainTrade) RecoveryKey ¶
func (t *OnChainTrade) RecoveryKey() key.Private
func (OnChainTrade) RecoveryTx ¶
RecoveryTx implement Trade
func (OnChainTrade) RecoveryTxFixedFee ¶
RecoveryTxFixedFee implement Trade
func (*OnChainTrade) RedeemKey ¶
func (t *OnChainTrade) RedeemKey() key.Private
func (OnChainTrade) RedeemTxFixedFee ¶
RedeemTxFixedFee implement Trade
func (*OnChainTrade) RedeemableFunds ¶
func (t *OnChainTrade) RedeemableFunds() FundsData
func (*OnChainTrade) Role ¶
func (t *OnChainTrade) Role() roles.Role
func (*OnChainTrade) Seller ¶
func (t *OnChainTrade) Seller() (SellerTrade, error)
func (OnChainTrade) SetLocks ¶
func (bt OnChainTrade) SetLocks(locks *BuyProposalResponse) error
SetLocks implement BuyerTrade
func (*OnChainTrade) Stager ¶
func (t *OnChainTrade) Stager() *stages.Stager
func (*OnChainTrade) Token ¶
func (t *OnChainTrade) Token() types.Bytes
func (*OnChainTrade) TokenHash ¶
func (t *OnChainTrade) TokenHash() types.Bytes
func (*OnChainTrade) TraderInfo ¶
func (t *OnChainTrade) TraderInfo() *TraderInfo
func (*OnChainTrade) UnmarshalYAML ¶
func (t *OnChainTrade) UnmarshalYAML(unmarshal func(interface{}) error) error
type Output ¶
type Output struct { TxID types.Bytes `yaml:"txid"` N uint32 `yaml:"n"` Amount uint64 `yaml:"amount"` }
Output represents an output
type SellerTrade ¶
type SellerTrade interface { // AcceptBuyProposal accepts a buy proposal AcceptBuyProposal(prop *BuyProposal) error // Locks returns the locks for the trade Locks() *BuyProposalResponse }
SellerTrade represents a seller trade
type StageHandlerFunc ¶
StageHandlerFunc is a trade stage handler function
type StageHandlerMap ¶
type StageHandlerMap = map[stages.Stage]StageHandlerFunc
StageHandlerMap is a map of stage handlers
type StagesNotHandledError ¶
StagesNotHandledError represents an error related to unhandled stages
func (StagesNotHandledError) Error ¶
func (e StagesNotHandledError) Error() string
Error implement error
type Trade ¶
type Trade interface { // Role returns the user role in the trade Role() roles.Role // Duration returns the trade duration Duration() duration.Duration // Token returns the token Token() types.Bytes // TokenHash returns the token hash TokenHash() types.Bytes // OwnInfo returns the trader info for the user OwnInfo() *TraderInfo // TraderInfo returns the trader info for the trader TraderInfo() *TraderInfo // RedeemKey returns the redeem key RedeemKey() key.Private // RecoveryKey returns the recovery key RecoveryKey() key.Private // RedeemableFunds returns the FundsData for the redeemable funds RedeemableFunds() FundsData // RecoverableFunds returns the FundsData for the recoverable funds RecoverableFunds() FundsData // Stager returns the trade *stages.Stager Stager() *stages.Stager // GenerateKeys generates both redeem and recovery keys GenerateKeys() error // SetToken sets the trade token (and token hash) SetToken(token types.Bytes) // RedeemTxFixedFee generates a redeem transaction with fixed fee RedeemTxFixedFee(lockScript []byte, fee uint64) (tx.Tx, error) // RedeemTx generates a redeem transaction with fee per byte RedeemTx(lockScript []byte, feePerByte uint64) (tx.Tx, error) // RecoveryTxFixedFee generates a recovery transaction with fixed fee RecoveryTxFixedFee(lockScript []byte, fee uint64) (tx.Tx, error) // RecoveryTx generates a recovery transaction with fee per byte RecoveryTx(lockScript []byte, feePerByte uint64) (tx.Tx, error) // Buyer returns a buyer trade Buyer() (BuyerTrade, error) // Seller returns a seller trade Seller() (SellerTrade, error) }
Trade represents a trade
func NewOnChainBuy ¶
func NewOnChainBuy( ownAmount types.Amount, ownCrypto *cryptos.Crypto, traderAmount types.Amount, traderCrypto *cryptos.Crypto, dur time.Duration, ) (Trade, error)
NewOnChainBuy returns a new buyer on-chain trade
func NewOnChainSell ¶
func NewOnChainSell() Trade
NewOnChainSell returns a new seller on-chain trade