Documentation ¶
Overview ¶
Package swap is a generated GoMock package.
Package swap provides the management layer used by swapd for tracking current and past swaps.
Index ¶
- Variables
- type Database
- type Info
- func (i *Info) DeepCopy() (*Info, error)
- func (i *Info) IsTaker() bool
- func (i *Info) MarkSwapComplete()
- func (i *Info) SetRelayerFee(relayerFee *apd.Decimal)
- func (i *Info) SetStatus(s Status)
- func (i *Info) SetTimeouts(t1 *time.Time, t2 *time.Time)
- func (i *Info) UnmarshalJSON(jsonData []byte) error
- type Manager
- type MockDatabase
- type MockDatabaseMockRecorder
- type Status
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"` RelayerFee *apd.Decimal `json:"relayerFee,omitempty"` 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, ) *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 unmarshalls the passed JSON into a freshly created Info object.
func (*Info) IsTaker ¶ added in v0.2.1
IsTaker returns true if the node is the xmr-taker in the swap.
func (*Info) MarkSwapComplete ¶ added in v0.3.0
func (i *Info) MarkSwapComplete()
MarkSwapComplete sets the EndTime field to the current wall time, grabbing the needed lock before modifying fields.
func (*Info) SetRelayerFee ¶ added in v0.3.0
func (i *Info) SetRelayerFee(relayerFee *apd.Decimal)
SetRelayerFee updates the RelayerFee field
func (*Info) SetTimeouts ¶ added in v0.3.0
SetTimeouts sets the 2 timeout fields, , grabbing the needed lock before modifying fields.
func (*Info) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON deserializes a JSON Info struct, checking the version for compatibility.
type Manager ¶
type Manager interface { AddSwap(info *Info) error WriteSwapToDB(info *Info) error GetPastIDs() ([]types.Hash, error) GetPastSwap(types.Hash) (*Info, error) GetOngoingSwap(hash types.Hash) (*Info, error) GetOngoingSwapSnapshot(types.Hash) (*Info, error) GetOngoingSwapOfferIDs() ([]*types.Hash, error) GetOngoingSwapsSnapshot() ([]*Info, error) CompleteOngoingSwap(info *Info) error HasOngoingSwap(types.Hash) bool GetStatusChan(offerID types.Hash) <-chan types.Status DeleteStatusChan(offerID types.Hash) PushNewStatus(offerID types.Hash, status types.Status) }
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.