Documentation
¶
Overview ¶
Package swap provides the management layer used by swapd for tracking current and past swaps.
Package swap is a generated GoMock package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
// CurInfoVersion is the latest supported version of a serialised Info struct
CurInfoVersion, _ = semver.NewVersion("0.3.0")
)
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface {
PutSwap(*Info) error
HasSwap(id types.Hash) (bool, error)
GetSwap(id types.Hash) (*Info, error)
GetAllSwaps() ([]*Info, error)
}
Database contains the db functions used by the swap manager.
type Info ¶
type Info struct {
Version *semver.Version `json:"version"`
PeerID peer.ID `json:"peerID" validate:"required"`
OfferID types.Hash `json:"offerID" validate:"required"`
Provides coins.ProvidesCoin `json:"provides" validate:"required"`
ProvidedAmount *apd.Decimal `json:"providedAmount" validate:"required"`
ExpectedAmount *apd.Decimal `json:"expectedAmount" validate:"required"`
ExchangeRate *coins.ExchangeRate `json:"exchangeRate" validate:"required"`
EthAsset types.EthAsset `json:"ethAsset"`
Status Status `json:"status" validate:"required"`
// LastStatusUpdateTime is the time at which the status was last updated.
LastStatusUpdateTime time.Time `json:"lastStatusUpdateTime" validate:"required"`
// MoneroStartHeight is the Monero block number when the swap begins.
MoneroStartHeight uint64 `json:"moneroStartHeight" validate:"required"`
// StartTime is the time at which the swap is initiated via
// key exchange.
// This may vary slightly between the maker/taker.
StartTime time.Time `json:"startTime" validate:"required"`
// EndTime is the time at which the swap completes; ie.
// when the node has claimed or refunded its funds.
EndTime *time.Time `json:"endTime,omitempty"`
// Timeout1 is the first swap timeout; before this timeout,
// the ETH-maker is able to refund the ETH (if `ready` has not
// been set to true in the contract). After this timeout,
// the ETH-taker is able to claim, and the ETH-maker can
// no longer refund.
Timeout1 *time.Time `json:"timeout1,omitempty"`
// Timeout2 is the second swap timeout; before this timeout
// (and after Timeout1), the ETH-taker is able to claim, but
// after this timeout, the ETH-taker can no longer claim, only
// the ETH-maker can refund.
Timeout2 *time.Time `json:"timeout2,omitempty"`
// contains filtered or unexported fields
}
Info contains the details of the swap as well as its status.
func NewInfo ¶
func NewInfo( peerID peer.ID, offerID types.Hash, provides coins.ProvidesCoin, providedAmount, expectedAmount *apd.Decimal, exchangeRate *coins.ExchangeRate, ethAsset types.EthAsset, status Status, moneroStartHeight uint64, statusCh chan types.Status, ) *Info
NewInfo creates a new *Info from the given parameters. Note that the swap ID is the same as the offer ID.
func UnmarshalInfo ¶
UnmarshalInfo deserializes a JSON Info struct, checking the version for compatibility before attempting to deserialize the whole blob.
type Manager ¶
type Manager interface {
AddSwap(info *Info) error
WriteSwapToDB(info *Info) error
GetPastIDs() ([]types.Hash, error)
GetPastSwap(types.Hash) (*Info, error)
GetOngoingSwap(types.Hash) (Info, error)
GetOngoingSwaps() ([]*Info, error)
CompleteOngoingSwap(info *Info) error
HasOngoingSwap(types.Hash) bool
}
Manager tracks current and past swaps.
func NewManager ¶
NewManager returns a new Manager that uses the given database. It loads all ongoing swaps into memory on construction. Completed swaps are not loaded into memory.
type MockDatabase ¶
type MockDatabase struct {
// contains filtered or unexported fields
}
MockDatabase is a mock of Database interface.
func NewMockDatabase ¶
func NewMockDatabase(ctrl *gomock.Controller) *MockDatabase
NewMockDatabase creates a new mock instance.
func (*MockDatabase) EXPECT ¶
func (m *MockDatabase) EXPECT() *MockDatabaseMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockDatabase) GetAllSwaps ¶
func (m *MockDatabase) GetAllSwaps() ([]*Info, error)
GetAllSwaps mocks base method.
func (*MockDatabase) GetSwap ¶
func (m *MockDatabase) GetSwap(arg0 common.Hash) (*Info, error)
GetSwap mocks base method.
func (*MockDatabase) HasSwap ¶
func (m *MockDatabase) HasSwap(arg0 common.Hash) (bool, error)
HasSwap mocks base method.
func (*MockDatabase) PutSwap ¶
func (m *MockDatabase) PutSwap(arg0 *Info) error
PutSwap mocks base method.
type MockDatabaseMockRecorder ¶
type MockDatabaseMockRecorder struct {
// contains filtered or unexported fields
}
MockDatabaseMockRecorder is the mock recorder for MockDatabase.
func (*MockDatabaseMockRecorder) GetAllSwaps ¶
func (mr *MockDatabaseMockRecorder) GetAllSwaps() *gomock.Call
GetAllSwaps indicates an expected call of GetAllSwaps.
func (*MockDatabaseMockRecorder) GetSwap ¶
func (mr *MockDatabaseMockRecorder) GetSwap(arg0 interface{}) *gomock.Call
GetSwap indicates an expected call of GetSwap.
func (*MockDatabaseMockRecorder) HasSwap ¶
func (mr *MockDatabaseMockRecorder) HasSwap(arg0 interface{}) *gomock.Call
HasSwap indicates an expected call of HasSwap.
func (*MockDatabaseMockRecorder) PutSwap ¶
func (mr *MockDatabaseMockRecorder) PutSwap(arg0 interface{}) *gomock.Call
PutSwap indicates an expected call of PutSwap.