winminer

package module
v0.0.0-...-aa374aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2018 License: MIT Imports: 15 Imported by: 0

README

winminer

Build Status Go Report Card GoDoc Lines of Code

API wrapper for the winminer API

Status

This is an ongoing effort to reverse-engineer the winminer API, particularly the live dashboard.

Things to know

It seems like Winminer invalidates API tokens and websocket tokens after some time. For this reason, it's recommended to update these tokens periodically.

Stability

Is it stable? Probably not. Winminer doesn't guarantee anything for the API, so I don't guarantee anything for the wrapper :)

License

MIT, see LICENSE.

Documentation

Index

Constants

View Source
const (
	MethodSetSystemInfo   = "SetSystemInfo"   // A: Client ID, Machine SID, Machine Info
	MethodStatusChanged   = "StatusChanged"   // A: Machine SID, Device ID, Device Status
	MethodStateChanged    = "StateChanged"    // A: Machine SID, Device ID, Enabled (bool)
	MethodAppClosed       = "AppClosed"       // A: Machine SID, Client ID?
	MethodClientConnected = "ClientConnected" // A: Client ID?
	MethodRemoveMessage   = "RemoveMessage"   // A: Machine SID, Message
	MethodAddMessage      = "AddMessage"      // A: Machine SID, Message
	MethodMiningStarted   = "MiningStarted"   // A: Client ID?
	MethodMiningStopped   = "MiningStopped"   // A: Client ID?
)

Websocket method constants.

View Source
const (
	StatusMining      = 8
	StatusStoppingToo = 10
	StatusStopping    = 0 // maybe
	StatusStarting1   = 2
	StatusStarting2   = 1
	StatusStarting3   = 5
	StatusStarting4   = 6
)

Mining status constants.

Variables

This section is empty.

Functions

func ParseDate

func ParseDate(date string) (time.Time, error)

ParseDate parses a date from the winminer string-encoding to a time.Time.

Types

type APIClient

type APIClient struct {
	// contains filtered or unexported fields
}

An APIClient is a client for the WinMiner API.

func NewAPIClient

func NewAPIClient(email, password string, debug bool) (*APIClient, error)

NewAPIClient constructs a new API client and attempts to log in.

func (*APIClient) CloseWebsocket

func (c *APIClient) CloseWebsocket() error

CloseWebsocket closes the websocket connection.

func (*APIClient) ConnectWebsocket

func (c *APIClient) ConnectWebsocket() (*WebsocketClient, error)

ConnectWebsocket connects a websocket connection for the Live API. Note that, if there is already a connection established, that connection will be returned instead. Close the connection with CloseWebsocket.

func (*APIClient) GetMachines

func (c *APIClient) GetMachines() (*MachinesResponse, error)

GetMachines gets information about current machines. Please note that the live information contained in this can not be trusted, e.g. the Enabled field will always be set to true, even if a device is not actually enabled.

func (*APIClient) GetStats

func (c *APIClient) GetStats() (*StatsResponse, error)

GetStats returns historical statistics.

func (*APIClient) GetWithdrawData

func (c *APIClient) GetWithdrawData() (*WithdrawDataResponse, error)

GetWithdrawData retrieves information about current withdraw options.

func (*APIClient) GetWithdrawHistory

func (c *APIClient) GetWithdrawHistory() (*WithdrawHistoryResponse, error)

GetWithdrawHistory retrieves the withdraw history.

func (*APIClient) ReconnectWebsocket

func (c *APIClient) ReconnectWebsocket() (*WebsocketClient, error)

ReconnectWebsocket closes and re-opens the websocket connection. Use this in case of any errors with the websocket connection.

func (*APIClient) UpdateLoginToken

func (c *APIClient) UpdateLoginToken() error

UpdateLoginToken performs another login request to update the token returned. You should call this periodically, it looks like winminer invalidates tokens after some time.

type AppClosedMessage

type AppClosedMessage struct {
	MachineSID string
	ClientID   string
}

An AppClosedMessage holds the arguments of a MethodAppClosed call.

func ParseAppClosedMessage

func ParseAppClosedMessage(message RawMessage) (*AppClosedMessage, error)

ParseAppClosedMessage parses a given RawMessage as an AppClosedMessage.

type Auth2Request

type Auth2Request struct {
	ClientType int    `json:"clientType"`
	LoginToken string `json:"loginToken"`
}

An Auth2Request is used to authenticate for the Websocket API.

type Auth2Response

type Auth2Response struct {
	Host  string `json:"host"`
	Token string `json:"token"`
}

An Auth2Response is the response to an Auth2Request.

type ClientConnectedMessage

type ClientConnectedMessage struct {
	ClientID string
}

func ParseClientConnectedMessage

func ParseClientConnectedMessage(message RawMessage) (*ClientConnectedMessage, error)

type DeviceEntry

type DeviceEntry struct {
	ID      string       `json:"id"` // probably string
	Enabled bool         `json:"enabled"`
	Name    string       `json:"name"`
	Type    string       `json:"type"`
	Status  DeviceStatus `json:"status"`
}

A DeviceEntry holds information about one device. This is used for both the HTTP and the Websocket API.

type DeviceStatus

type DeviceStatus struct {
	Status    int               `json:"status"`
	Tags      []string          `json:"tags"`
	Hashrates []decimal.Decimal `json:"hashrates"`
	Profits   []decimal.Decimal `json:"profits"`
	Currency  string            `json:"currency"`
	ExtraData string            `json:"extraData"` // never seen, no idea what type
}

DeviceStatus is the status of one device. This is used for both the HTTP and the Websocket API.

type ExchangeRates

type ExchangeRates struct {
	BTC decimal.Decimal `json:"btc"`
	ETH decimal.Decimal `json:"eth"`
	LTC decimal.Decimal `json:"ltc"`
}

ExchangeRates holds information about exchange rates to crypto currencies.

type ExchangeRequest

type ExchangeRequest struct {
	MiningToken  string `json:"MiningToken"`
	BalanceToken string `json:"BalanceToken"`
}

An ExchangeRequest holds the data necessary to get coin exchange information. Note that this is only used by the miner, not the website.

type ExchangeResponse

type ExchangeResponse struct {
	UserBalance decimal.Decimal `json:"userBalance"`
}

An ExchangeResponse is the response to an ExchangeRequest.

type FeeEntry

type FeeEntry struct {
	Type             int             `json:"type"`
	ProviderLowFee   decimal.Decimal `json:"providerLowFee"`
	ProviderFee      decimal.Decimal `json:"providerFee"`
	ProviderHighFee  decimal.Decimal `json:"providerHighFee"`
	ProviderFixedFee bool            `json:"providerFixedFee"`
	WithholdingTax   decimal.Decimal `json:"withholdingTax"`
	WinMinerFee      decimal.Decimal `json:"winMinerFee"`
}

A FeeEntry holds information about fees applied on withdrawal.

type GenericSignalrResponse

type GenericSignalrResponse struct {
	Response string `json:"Response"`
}

A GenericSignalrResponse is used for both the /start and /ping endpoint of the live API "signalr" endpoint.

type GiftCardEntry

type GiftCardEntry struct {
	ID          int    `json:"id"`
	Country     string `json:"country"`
	LocalAmount int    `json:"localAmount"`
	Amount      int    `json:"amount"`
	Symbol      string `json:"symbol"`
}

A GiftCardEntry holds information about withdrawal to gift cards.

type JWTEntry

type JWTEntry struct {
	Data                string          `json:"data"` // never seen, no idea what type
	BaseCurrency        string          `json:"baseCurrency"`
	BaseAmount          decimal.Decimal `json:"baseAmount"`
	WithholdingTax      decimal.Decimal `json:"withholdingTax"`
	WinminerFee         decimal.Decimal `json:"winminerFee"`
	ProviderFee         decimal.Decimal `json:"providerFee"`
	NetAmount           decimal.Decimal `json:"netAmount"`
	Exchange            decimal.Decimal `json:"exchange"`
	ProviderName        string          `json:"providerName"`
	FriendlyAmount      string          `json:"fAmount"`
	FriendlyWinminerFee string          `json:"fWinminerFee"`
	FriendlyProviderFee string          `json:"fProviderFee"`
	FriendlyNetAmount   string          `json:"fNetAmount"`
	// JWT stuff
	ExpirationTime float64 `json:"exp"`
	JWTID          string  `json:"jti"`
	IssuedAt       float64 `json:"iat"`
	Issuer         string  `json:"iss"`
}

A JWTEntry holds signed(?) information about litecoin(?) transaction specifics.

type LitecoinTransaction

type LitecoinTransaction struct {
	WalletAddress string   `json:"WalletAddress"`
	WithdrawType  int      `json:"WithdrawType"`
	JWT           JWTEntry `json:"jwt"`
}

A LitecoinTransaction holds information about a litecoin transaction.

type LiveState

type LiveState struct {
	Machines           []MachineEntry
	DevicesLastUpdated map[string]time.Time
	sync.Mutex
}

LiveState is a helper struct to keep track of Live API updates. Access must be protected with the embedded mutex.

func NewLiveState

func NewLiveState() *LiveState

NewLiveState returns a new LiveState.

func (*LiveState) AddMachine

func (s *LiveState) AddMachine(entry MachineEntry)

AddMachine adds a machine entry if it's not present already. If it is, the entry is overwritten.

func (*LiveState) SetSystemInfo

func (s *LiveState) SetSystemInfo(entries []MachineEntry)

SetSystemInfo clears the current state and sets it to the state received. The machine entries are kept as a reference, do not modify them later on.

func (*LiveState) UpdateState

func (s *LiveState) UpdateState(msg StateChangedMessage) error

UpdateState updates the LiveState with the given StateChangedMessage. This usually sets the enabled flag of one device to false, when mining on that device is stopped.

func (*LiveState) UpdateStatus

func (s *LiveState) UpdateStatus(container StatusChangedMessage) error

UpdateStatus updates the state with the given status change. Returns an error if the device or machine was not found. If that happens, the state got out of sync somehow. Best close and re-open the websocket connection and rebuild the state.

type LoginRequest

type LoginRequest struct {
	Email         string `json:"email"`
	Password      string `json:"password"`
	HubClientType int    `json:"hubClientType"`
}

A LoginRequest holds the data used to log in.

type LoginResponse

type LoginResponse struct {
	UserToken string `json:"userToken"`
	HubToken  string `json:"hubToken"`
	HubHost   string `json:"hubHost"`
}

A LoginResponse is the response to a login request.

type MachineEntry

type MachineEntry struct {
	MachineName   string        `json:"machineName"`
	SID           string        `json:"sid"`
	ClientVersion string        `json:"clientVersion"`
	IsAdmin       bool          `json:"isAdmin"`
	IsPortable    bool          `json:"isPortable"`
	Devices       []DeviceEntry `json:"devices"`
	Key           string        `json:"key"`
}

A MachineEntry holds information about one machine. This is used by both the HTTP and Websocket API.

func ParseSystemInfoMessage

func ParseSystemInfoMessage(message RawMessage) ([]MachineEntry, error)

ParseSystemInfoMessage parses a SystemInfo message.

type MachinesResponse

type MachinesResponse []MachineEntry

A MachinesResponse holds a bunch of MachineEntries.

type NegotiateResponse

type NegotiateResponse struct {
	URL                        string          `json:"Url"`
	ConnectionToken            string          `json:"ConnectionToken"`
	ConnectionID               string          `json:"ConnectionId"`
	KeepAliveTimeout           decimal.Decimal `json:"KeepAliveTimeout"`
	DisconnectTimeout          decimal.Decimal `json:"DisconnectTimeout"`
	ConnectionTimeout          decimal.Decimal `json:"ConnectionTimeout"`
	TryWebSockets              bool            `json:"TryWebSockets"`
	ProtocolVersion            string          `json:"ProtocolVersion"`
	TransportConnectionTimeout decimal.Decimal `json:"TransportConnectionTimeout"`
	LongPollDelay              decimal.Decimal `json:"LongPollDelay"`
}

A NegotiateResponse is the response to a negotiate request for a websocket connection.

type RawMessage

type RawMessage struct {
	Host      string            `json:"H"`
	Method    string            `json:"M"`
	Arguments []json.RawMessage `json:"A"`
}

A RawMessage is an unparsed message from the Live API. Use the Method field to determine the type of the message and the parse it with ParseStatusChangedMessage or ParseSystemInfoMessage.

type RawMessageContainer

type RawMessageContainer struct {
	Channel  string       `json:"C"`
	Messages []RawMessage `json:"M"`
}

A RawMessageContainer contains RawMessages from the Live API.

type StatEntry

type StatEntry struct {
	ClientID  int             `json:"clientId"`
	Date      string          `json:"date"`
	Currency  string          `json:"currency"`
	MachineID string          `json:"machineId"`
	RewardUSD decimal.Decimal `json:"rewardUSD"`
	HashSec   int             `json:"hashSec"`
}

A StatEntry is one entry with stats.

type StateChangedMessage

type StateChangedMessage struct {
	MachineSID string
	DeviceID   string
	Enabled    bool
}

A StateChangedMessage holds the arguments of a MethodStateChanged call.

func ParseStateChangedMessage

func ParseStateChangedMessage(message RawMessage) (*StateChangedMessage, error)

ParseStateChangedMessage parses a given RawMessage as a StateChangedMessage.

type StatsResponse

type StatsResponse struct {
	Stats   []StatEntry     `json:"stats"`
	Balance decimal.Decimal `json:"balance"`
	Cache   decimal.Decimal `json:"cache"`
}

A StatsResponse is the response to a stats query.

type StatusChangedMessage

type StatusChangedMessage struct {
	MachineSID string
	DeviceID   string
	Status     DeviceStatus
}

A StatusChangedMessage holds the arguments of a MethodStatusChanged call.

func ParseStatusChangedMessage

func ParseStatusChangedMessage(message RawMessage) (*StatusChangedMessage, error)

ParseStatusChangedMessage parses a StatusChanged message.

type TransactionEntry

type TransactionEntry struct {
	TransactionID           string `json:"transactionId"`
	IsCompleted             bool   `json:"isCompleted"`
	CompletedDate           string `json:"completedDate"` // never seen, but probably string
	RequestDate             string `json:"requestDate"`
	TransactionType         int    `json:"transactionType"`
	Status                  int    `json:"status"`
	TransactionData         string `json:"transactionData"`
	FriendlyStatus          string `json:"friendlyStatus"`
	FriendlyTransactionType string `json:"friendlyTransactionType"`
	Data                    string `json:"data"`
	FriendlyTotalAmount     string `json:"friendlyTotalAmount"`
	FriendlyNetAmount       string `json:"friendlyNetAmount"`
	FriendlyWinMinerFees    string `json:"friendlyWinMinerFees"`
	FriendlyProviderFees    string `json:"friendlyProviderFees"`
	ProviderName            string `json:"providerName"`
	ExternalTransactionID   string `json:"externalTransactionId"`
	IP                      string `json:"ip"`
}

A TransactionEntry holds information about one withdrawal. After determining the type of the transaction, parse the TransactionData using e.g. ParseAsLitecoinTransaction.

func (TransactionEntry) ParseDataAsLitecoinTransaction

func (e TransactionEntry) ParseDataAsLitecoinTransaction() (*LitecoinTransaction, error)

ParseDataAsLitecoinTransaction parses the TransactionData as a LitcoinTransaction.

type WebsocketClient

type WebsocketClient struct {
	// contains filtered or unexported fields
}

A WebsocketClient is a client for the Winminer Live API.

func (*WebsocketClient) Read

func (c *WebsocketClient) Read() (messageType int, b []byte, err error)

Read reads a message off the websocket. Use ReadNextInterestingMessage instead.

This method returns all kinds of errors that concurrently occurred since the last call to Read. If it does return an error, close and re-open the websocket connection.

func (*WebsocketClient) ReadNextInterestingMessages

func (c *WebsocketClient) ReadNextInterestingMessages() (*RawMessageContainer, error)

ReadNextInterestingMessages reads messages off the websocket until an interesting message comes by.

type WithdrawDataResponse

type WithdrawDataResponse struct {
	AppleGiftCards  []GiftCardEntry `json:"appleGiftCards"`
	AmazonGiftCards []GiftCardEntry `json:"amazonGiftCards"`
	Fees            []FeeEntry      `json:"fees"`
	Exchange        ExchangeRates   `json:"exchange"`
	Balance         decimal.Decimal `json:"balance"`
}

A WithdrawDataResponse is the response to a WithdrawData request.

type WithdrawHistoryResponse

type WithdrawHistoryResponse struct {
	Balance      decimal.Decimal    `json:"balance"`
	Transactions []TransactionEntry `json:"transactions"`
}

A WithdrawHistoryResponse is the resopnse to a withdraw history request.

type WithdrawOption

type WithdrawOption struct {
	Description                      string          `json:"description"`
	DescriptionAdd                   string          `json:"descriptionAdd"`
	TemplateURL                      string          `json:"templateUrl"`
	Height                           int             `json:"height"`
	TypeID                           int             `json:"typeId"`
	Path                             string          `json:"path"`
	MinimumToWithdraw                decimal.Decimal `json:"minimumToWithdraw"`
	MaximumToWithdraw                decimal.Decimal `json:"maximumToWithdraw"`
	NoCheckout                       bool            `json:"noCheckout"`
	ConfirmMessage                   []string        `json:"confirmMessage"`
	ConfirmMessageTokenValueProperty string          `json:"confirmMessageTokenValueProperty"`
	Disabled                         bool            `json:"disabled"`
	Message                          string          `json:"message"` // never seen, no idea what type
	AllowHighFee                     bool            `json:"allowHighFee"`
}

A WithdrawOption describes one withdraw option. Lots of the fields are just required for rendering, but kept here for completeness.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL