bitcoinpay

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Copyright (c) 2019 The bitcoinpay developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2019 The bitcoinpay developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

* Bitcoinpay james

Copyright (c) 2019 The bitcoinpay developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2019 The bitcoinpay developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2019 The bitcoinpay developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	//every mode position
	POWTYPE_START = 112
	POWTYPE_END   = 113
	TIMESTART     = 104
	TIMEEND       = 108
	NONCESTART    = 108
	NONCEEND      = 112
	HEIGHTSTART   = 104
	HEIGHTEND     = 112
	NBITSTART     = 100
	NBITEND       = 104
	STATESTART    = 68
	STATEEND      = 100
	MERKLESTART   = 36
	MERKLEEND     = 68
	PRESTART      = 4
	PREEND        = 36
	TXEND         = 68
	VERSIONSTART  = 0
	VERSIONEND    = 4
)
View Source
const (
	POW_CUCKROO   = "cuckaroo"
	POW_CUCKROOM  = "cuckaroom"
	POW_CUCKROO29 = "cuckaroo29"
)

Variables

View Source
var ErrSameWork = fmt.Errorf("Same work, Had Submitted!")
View Source
var ErrStratumStaleWork = fmt.Errorf("Stale work, throwing away")

ErrStratumStaleWork indicates that the work to send to the pool was stale.

Functions

func BlockComputePoolData

func BlockComputePoolData(b []byte) []byte

Header structure of assembly pool

func BlockDataWithProof

func BlockDataWithProof(h *types.BlockHeader) []byte

bitcoinpay block header

func BuildMerkleTreeStoreWithness

func BuildMerkleTreeStoreWithness(transactions []*types.Tx, witness bool) []*hash.Hash

buildMerkleTreeStore creates a merkle tree from a slice of transactions, stores it using a linear array, and returns a slice of the backing array. A linear array was chosen as opposed to an actual tree structure since it uses about half as much memory. The following describes a merkle tree and how it is stored in a linear array.

A merkle tree is a tree in which every non-leaf node is the hash of its children nodes. A diagram depicting how this works for transactions where h(x) is a blake256 hash follows:

         root = h1234 = h(h12 + h34)
        /                           \
  h12 = h(h1 + h2)            h34 = h(h3 + h4)
   /            \              /            \
h1 = h(tx1)  h2 = h(tx2)    h3 = h(tx3)  h4 = h(tx4)

The above stored as a linear array is as follows:

[h1 h2 h3 h4 h12 h34 root]

As the above shows, the merkle root is always the last element in the array.

The number of inputs is not always a power of two which results in a balanced tree structure as above. In that case, parent nodes with no children are also zero and parent nodes with only a single left node are calculated by concatenating the left node with itself before hashing. Since this function uses nodes that are pointers to the hashes, empty nodes will be nil.

func CuckarooGraphWeight

func CuckarooGraphWeight(mheight, targetHeight int64, edge_bits uint) uint64

func CuckatooGraphWeight

func CuckatooGraphWeight(mheight, targetHeight int64, edge_bits uint) uint64

func HashToBig

func HashToBig(hash *hash.Hash) *big.Int

func ReadBlockHeader

func ReadBlockHeader(b []byte, bh *types.BlockHeader) error

readBlockHeader reads a block header from io reader. See Deserialize for decoding block headers stored to disk, such as in a database, as opposed to decoding from the type. TODO, redefine the protocol version and storage

Types

type BasicReply

type BasicReply struct {
	ID     interface{} `json:"id"`
	Error  interface{} `json:"error,omitempty"`
	Result bool        `json:"result"`
}

Basic reply is a reply type for any of the simple messages.

type BitcoinpayRobot

type BitcoinpayRobot struct {
	core.MinerRobot
	Work                 BitcoinpayWork
	Devices              []core.BaseDevice
	Stratu               *BitcoinpayStratum
	AllTransactionsCount int64
}

func (*BitcoinpayRobot) GetPow

func (this *BitcoinpayRobot) GetPow(i int, device *cl.Device) core.BaseDevice

func (*BitcoinpayRobot) InitDevice

func (this *BitcoinpayRobot) InitDevice()

func (*BitcoinpayRobot) ListenWork

func (this *BitcoinpayRobot) ListenWork()

ListenWork

func (*BitcoinpayRobot) Run

func (this *BitcoinpayRobot) Run()

runing

func (*BitcoinpayRobot) Status

func (this *BitcoinpayRobot) Status()

stats the submit result

func (*BitcoinpayRobot) SubmitWork

func (this *BitcoinpayRobot) SubmitWork()

ListenWork

type BitcoinpayStratum

type BitcoinpayStratum struct {
	core.Stratum
	Target   *big.Int
	Diff     float64
	PoolWork NotifyWork
}

func (*BitcoinpayStratum) CalcBasePowLimit

func (s *BitcoinpayStratum) CalcBasePowLimit() *big.Int

func (*BitcoinpayStratum) HandleReply

func (this *BitcoinpayStratum) HandleReply()

func (*BitcoinpayStratum) HandleSubmitReply

func (s *BitcoinpayStratum) HandleSubmitReply(resp interface{})

func (*BitcoinpayStratum) PrepSubmit

func (s *BitcoinpayStratum) PrepSubmit(data []byte, jobID string, ExtraNonce2 string) (Submit, error)

func (*BitcoinpayStratum) Unmarshal

func (s *BitcoinpayStratum) Unmarshal(blob []byte) (interface{}, error)

Unmarshal provides a json unmarshaler for the commands. I'm sure a lot of this can be generalized but the json we deal with is pretty yucky.

type BitcoinpayWork

type BitcoinpayWork struct {
	core.Work
	Block    *BlockHeader
	PoolWork NotifyWork

	StartWork   bool
	ForceUpdate bool
	// contains filtered or unexported fields
}

func (*BitcoinpayWork) CopyNew

func (this *BitcoinpayWork) CopyNew() BitcoinpayWork

func (*BitcoinpayWork) Get

func (this *BitcoinpayWork) Get() bool

GetBlockTemplate

func (*BitcoinpayWork) PoolGet

func (this *BitcoinpayWork) PoolGet() bool

pool get work

func (*BitcoinpayWork) PoolSubmit

func (this *BitcoinpayWork) PoolSubmit(subm string) error

pool submit work

func (*BitcoinpayWork) Submit

func (this *BitcoinpayWork) Submit(subm string) error

Submit

type BlockHeader

type BlockHeader struct {
	sync.Mutex
	// block version
	Version uint32 `json:"version"`
	// The merkle root of the previous parent blocks (the dag layer)
	ParentRoot hash.Hash `json:"previousblockhash"`
	// The merkle root of the tx tree  (tx of the block)
	// included Witness here instead of the separated witness commitment
	TxRoot hash.Hash `json:"tx_root"`
	// The Multiset hash of UTXO set or(?) merkle range/path or(?) tire tree root
	// can all of the state data (stake, receipt, utxo) in state root?
	StateRoot hash.Hash `json:"stateroot"`

	Transactions []Transactions `json:"transactions"`
	Parents      []ParentItems  `json:"parents"`

	// block number
	Height     uint64 `json:"height"`
	Difficulty uint64 `json:"difficulty"`

	// TimeStamp
	Curtime uint32 `json:"curtime"`

	Pow pow.IPow

	// Nonce
	Target string `json:"target"`

	PowDiffReference json.PowDiffReference `json:"pow_diff_reference"`

	Coinbasevalue   int64 `json:"coinbasevalue"`
	HasCoinbasePack bool
	TotalFee        uint64
	// contains filtered or unexported fields
}

bitcoinpay block header

func (*BlockHeader) AddCoinbaseTx

func (h *BlockHeader) AddCoinbaseTx(coinbaseTx *types.Tx)

func (*BlockHeader) BuildMerkleTreeStore

func (h *BlockHeader) BuildMerkleTreeStore(index int) hash.Hash

func (*BlockHeader) CalcCoinBase

func (h *BlockHeader) CalcCoinBase(cfg *common.GlobalConfig, coinbaseStr string, extraNonce uint64, payAddressS string) (*hash.Hash, []Transactions)

calc coinbase

func (*BlockHeader) SetTxs

func (h *BlockHeader) SetTxs(transactions []*types.Tx)

type Cuckaroo

type Cuckaroo struct {
	core.Device
	ClearBytes                 []byte
	EdgesObj                   *cl.MemObject
	EdgesBytes                 []byte
	DestinationEdgesCountObj   *cl.MemObject
	DestinationEdgesCountBytes []byte
	EdgesIndexObj              *cl.MemObject
	EdgesIndex1Obj             *cl.MemObject
	EdgesIndexBytes            []byte
	DestinationEdgesObj        *cl.MemObject
	DestinationEdgesBytes      []byte
	NoncesObj                  *cl.MemObject
	NoncesBytes                []byte
	Nonces                     []uint32
	NodesObj                   *cl.MemObject
	NodesBytes                 []byte
	Edges                      []uint32
	CreateEdgeKernel           *cl.Kernel
	Trimmer01Kernel            *cl.Kernel
	Trimmer02Kernel            *cl.Kernel
	RecoveryKernel             *cl.Kernel
	Work                       *BitcoinpayWork

	EdgeBits      int
	Step          int
	WorkGroupSize int
	LocalSize     int
	Nedge         int
	Edgemask      uint64
	// contains filtered or unexported fields
}

func (*Cuckaroo) InitDevice

func (this *Cuckaroo) InitDevice()

func (*Cuckaroo) InitKernelAndParam

func (this *Cuckaroo) InitKernelAndParam()

func (*Cuckaroo) InitParamData

func (this *Cuckaroo) InitParamData()

func (*Cuckaroo) Mine

func (this *Cuckaroo) Mine(wg *sync.WaitGroup)

func (*Cuckaroo) Release

func (this *Cuckaroo) Release()

func (*Cuckaroo) SubmitShare

func (this *Cuckaroo) SubmitShare(substr chan string)

func (*Cuckaroo) Update

func (this *Cuckaroo) Update()

type MinerBlockData

type MinerBlockData struct {
	Transactions []Transactions
	Parents      []ParentItems
	HeaderData   []byte
	TargetDiff   *big.Int
	Target2      []byte
	Exnonce2     string
	JobID        string
	HeaderBlock  *types.BlockHeader
	Height       uint64
}

func (*MinerBlockData) PackagePoolHeader

func (this *MinerBlockData) PackagePoolHeader(work *BitcoinpayWork, powType pow.PowType)

the pool work submit structure

func (*MinerBlockData) PackagePoolHeaderByNonce

func (this *MinerBlockData) PackagePoolHeaderByNonce(work *BitcoinpayWork, nonce uint64)

the pool work submit structure

func (*MinerBlockData) PackageRpcHeader

func (this *MinerBlockData) PackageRpcHeader(work *BitcoinpayWork, txs []Transactions)

the solo work submit structure

type NotifyRes

type NotifyRes struct {
	JobID          string
	Hash           string
	GenTX1         string
	GenTX2         string
	MerkleBranches []string
	BlockVersion   string
	Nbits          string
	Ntime          string
	CleanJobs      bool
	StateRoot      string
	Height         int64
	CB3            string
	CB4            string
}

NotifyRes models the json from a mining.notify message.

type NotifyWork

type NotifyWork struct {
	Clean             bool
	Target            *big.Int
	ExtraNonce1       string
	ExtraNonce2       string
	ExtraNonce2Length float64
	Nonce2            uint32
	CB1               string
	CB2               string
	CB3               string
	CB4               string
	Height            int64
	NtimeDelta        int64
	JobID             string
	Hash              string
	Nbits             string
	Ntime             string
	Version           string
	NewWork           bool
	StateRoot         string
	MerkleBranches    []string
	WorkData          []byte
	LatestJobTime     uint64
	PowType           pow.PowType
	CuckooProof       [169]byte
}

NotifyWork holds all the info recieved from a mining.notify message along with the Work data generate from it.

func (*NotifyWork) PrepBitcoinpayWork

func (s *NotifyWork) PrepBitcoinpayWork() []byte

func (*NotifyWork) PrepWork

func (s *NotifyWork) PrepWork() error

PrepWork converts the stratum notify to getwork style data for mining.

type ParentItems

type ParentItems struct {
	Hash hash.Hash `json:"hash"`
	Data string    `json:"data"`
}

type StratErr

type StratErr struct {
	ErrNum uint64
	ErrStr string
	Result *json.RawMessage `json:"result,omitempty"`
}

StratErr is the basic error type (a number and a string) sent by the stratum server.

type StratumMsg

type StratumMsg struct {
	Method string `json:"method"`
	// Need to make generic.
	Params []string    `json:"params"`
	ID     interface{} `json:"id"`
}

StratumMsg is the basic message object from stratum.

type StratumRsp

type StratumRsp struct {
	Method string `json:"method"`
	// Need to make generic.
	ID     interface{}      `json:"id"`
	Error  StratErr         `json:"error,omitempty"`
	Result *json.RawMessage `json:"result,omitempty"`
}

StratumRsp is the basic response type from stratum.

type Submit

type Submit struct {
	Params []string    `json:"params"`
	ID     interface{} `json:"id"`
	Method string      `json:"method"`
}

Submit models a submission message.

type SubscribeReply

type SubscribeReply struct {
	SubscribeID       string
	ExtraNonce1       string
	ExtraNonce2Length float64
}

SubscribeReply models the server response to a subscribe message.

type Transactions

type Transactions struct {
	Hash hash.Hash `json:"hash"`
	Data string    `json:"data"`
	Fee  uint64    `json:"fee"`
}

func (*Transactions) EncodeTx

func (this *Transactions) EncodeTx() *types.Tx

func (*Transactions) GetSigCount

func (this *Transactions) GetSigCount() int

type Transactionses

type Transactionses []Transactions

func (Transactionses) Len

func (p Transactionses) Len() int

func (Transactionses) Less

func (p Transactionses) Less(i, j int) bool

fee sort desc

func (Transactionses) Swap

func (p Transactionses) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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