gostratum

package
v0.0.0-...-507f73e Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorDisconnected = fmt.Errorf("disconnecting")

Functions

func CleanWallet

func CleanWallet(in string) (string, error)

func DefaultLogger

func DefaultLogger() *zap.Logger

func HandleAuthorize

func HandleAuthorize(ctx *StratumContext, event JsonRpcEvent) error

func HandleSubmit

func HandleSubmit(ctx *StratumContext, event JsonRpcEvent) error

func HandleSubscribe

func HandleSubscribe(ctx *StratumContext, event JsonRpcEvent) error

func NewMockContext

func NewMockContext(ctx context.Context, logger *zap.Logger, state any) (*StratumContext, *MockConnection)

func SendExtranonce

func SendExtranonce(ctx *StratumContext)

Types

type ContextSummary

type ContextSummary struct {
	RemoteAddr string
	WalletAddr string
	WorkerName string
	RemoteApp  string
}

type DisconnectChannel

type DisconnectChannel chan *StratumContext

type EventHandler

type EventHandler func(ctx *StratumContext, event JsonRpcEvent) error

type JsonRpcEvent

type JsonRpcEvent struct {
	Id      any           `json:"id"` // id can be nil, a string, or an int 🙄
	Version string        `json:"jsonrpc"`
	Method  StratumMethod `json:"method"`
	Params  []any         `json:"params"`
}

func NewEvent

func NewEvent(id string, method string, params []any) JsonRpcEvent

func UnmarshalEvent

func UnmarshalEvent(in string) (JsonRpcEvent, error)

type JsonRpcResponse

type JsonRpcResponse struct {
	Id     any   `json:"id"`
	Result any   `json:"result"`
	Error  []any `json:"error"`
}

func NewResponse

func NewResponse(event JsonRpcEvent, results any, err []any) JsonRpcResponse

func UnmarshalResponse

func UnmarshalResponse(in string) (JsonRpcResponse, error)

type LineCallback

type LineCallback func(line string) error

type MockAddr

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

func (MockAddr) Network

func (ma MockAddr) Network() string

func (MockAddr) String

func (ma MockAddr) String() string

type MockConnection

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

func NewMockConnection

func NewMockConnection() *MockConnection

func (*MockConnection) AsyncReadTestDataFromBuffer

func (mc *MockConnection) AsyncReadTestDataFromBuffer(handler func([]byte))

func (*MockConnection) AsyncWriteTestDataToReadBuffer

func (mc *MockConnection) AsyncWriteTestDataToReadBuffer(s string)

func (*MockConnection) Close

func (mc *MockConnection) Close() error

func (*MockConnection) LocalAddr

func (mc *MockConnection) LocalAddr() net.Addr

func (*MockConnection) Read

func (mc *MockConnection) Read(b []byte) (int, error)

func (*MockConnection) ReadTestDataFromBuffer

func (mc *MockConnection) ReadTestDataFromBuffer(handler func([]byte))

func (*MockConnection) RemoteAddr

func (mc *MockConnection) RemoteAddr() net.Addr

func (*MockConnection) SetDeadline

func (mc *MockConnection) SetDeadline(t time.Time) error

func (*MockConnection) SetReadDeadline

func (mc *MockConnection) SetReadDeadline(t time.Time) error

func (*MockConnection) SetWriteDeadline

func (mc *MockConnection) SetWriteDeadline(t time.Time) error

func (*MockConnection) Write

func (mc *MockConnection) Write(b []byte) (int, error)

type StateGenerator

type StateGenerator func() any

type StratumClientListener

type StratumClientListener interface {
	OnConnect(ctx *StratumContext)
	OnDisconnect(ctx *StratumContext)
}

type StratumContext

type StratumContext struct {
	RemoteAddr string
	WalletAddr string
	WorkerName string
	Password   string
	RemoteApp  string
	Id         int32
	Logger     *zap.Logger

	State any // gross, but go generics aren't mature enough this can be typed 😭

	Extranonce string
	SesUid     string
	// contains filtered or unexported fields
}

func (*StratumContext) Connected

func (sc *StratumContext) Connected() bool

func (StratumContext) Deadline

func (StratumContext) Deadline() (time.Time, bool)

func (*StratumContext) Disconnect

func (sc *StratumContext) Disconnect()

func (StratumContext) Done

func (StratumContext) Done() <-chan struct{}

func (StratumContext) Err

func (StratumContext) Err() error

func (*StratumContext) Reply

func (sc *StratumContext) Reply(response JsonRpcResponse) error

func (*StratumContext) ReplyBadShare

func (sc *StratumContext) ReplyBadShare(id any) error

func (*StratumContext) ReplyDupeShare

func (sc *StratumContext) ReplyDupeShare(id any) error

func (*StratumContext) ReplyLowDiffShare

func (sc *StratumContext) ReplyLowDiffShare(id any) error

func (*StratumContext) ReplyStaleShare

func (sc *StratumContext) ReplyStaleShare(id any) error

func (*StratumContext) Send

func (sc *StratumContext) Send(event JsonRpcEvent) error

func (*StratumContext) String

func (sc *StratumContext) String() string

func (*StratumContext) Summary

func (sc *StratumContext) Summary() ContextSummary

func (StratumContext) Value

func (d StratumContext) Value(key any) any

type StratumHandlerMap

type StratumHandlerMap map[string]EventHandler

func DefaultHandlers

func DefaultHandlers() StratumHandlerMap

type StratumListener

type StratumListener struct {
	StratumListenerConfig
	// contains filtered or unexported fields
}

func NewListener

func NewListener(cfg StratumListenerConfig) *StratumListener

func (*StratumListener) HandleEvent

func (s *StratumListener) HandleEvent(ctx *StratumContext, event JsonRpcEvent) error

func (*StratumListener) Listen

func (s *StratumListener) Listen(ctx context.Context) error

type StratumListenerConfig

type StratumListenerConfig struct {
	Logger         *zap.Logger
	HandlerMap     StratumHandlerMap
	ClientListener StratumClientListener
	StateGenerator StateGenerator
	Port           string
}

func DefaultConfig

func DefaultConfig(logger *zap.Logger) StratumListenerConfig

type StratumMethod

type StratumMethod string
const (
	StratumMethodSubscribe StratumMethod = "mining.subscribe"
	StratumMethodAuthorize StratumMethod = "mining.authorize"
	StratumMethodSubmit    StratumMethod = "mining.submit"
)

type StratumStats

type StratumStats struct {
	Disconnects int64
}

Jump to

Keyboard shortcuts

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