bitcoincash

package
v1.89.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockCacheSize      = 144
	MaximumConfirmation = 99999999
	MaxAsgardAddresses  = 100
	// EstimateAverageTxSize for THORChain the estimate tx size is hard code to 250 here , as most of time it will spend 1 input, have 3 output
	EstimateAverageTxSize = 1500
	DefaultCoinbaseValue  = 6.25
	MaxMempoolScanPerTry  = 500
)

BlockCacheSize the number of block meta that get store in storage.

View Source
const (
	TransactionFeeKey = "transactionfee-"
	PrefixBlockMeta   = `blockmeta-`
	PrefixMempool     = "mempool-"
	PrefixObservedTx  = "observed-"
)

PrefixUTXOStorage declares prefix to use in leveldb to avoid conflicts

View Source
const (
	// SatsPervBytes it should be enough , this one will only be used if signer can't find any previous UTXO , and fee info from local storage.
	SatsPervBytes = 25
	// MinUTXOConfirmation UTXO that has less confirmation then this will not be spent , unless it is yggdrasil
	MinUTXOConfirmation = 1
)

Variables

This section is empty.

Functions

func GetBech32AccountPubKey

func GetBech32AccountPubKey(key *bchec.PrivateKey) (common.PubKey, error)

GetBech32AccountPubKey convert the given private key to

Types

type BlockMeta

type BlockMeta struct {
	PreviousHash         string   `json:"previous_hash"`
	Height               int64    `json:"height"`
	BlockHash            string   `json:"block_hash"`
	SelfTransactions     []string `json:"self_transactions,omitempty"`     // keep the transactions that broadcast by itself
	CustomerTransactions []string `json:"customer_transactions,omitempty"` // keep the transactions that from customer
}

BlockMeta is a structure to store the blocks bifrost scanned

func NewBlockMeta

func NewBlockMeta(previousHash string, height int64, blockHash string) *BlockMeta

NewBlockMeta create a new instance of BlockMeta

func (*BlockMeta) AddCustomerTransaction

func (b *BlockMeta) AddCustomerTransaction(txID string)

AddCustomerTransaction add the given Transaction into block meta

func (*BlockMeta) AddSelfTransaction

func (b *BlockMeta) AddSelfTransaction(txID string)

AddSelfTransaction add the given Transaction into block meta

func (*BlockMeta) RemoveCustomerTransaction

func (b *BlockMeta) RemoveCustomerTransaction(txID string)

RemoveCustomerTransaction remove the given transaction from the block

func (*BlockMeta) TransactionHashExist

func (b *BlockMeta) TransactionHashExist(hash string) bool

TransactionHashExist check whether the given traction hash exist in the block meta

type BlockMetaAccessor

type BlockMetaAccessor interface {
	GetBlockMetas() ([]*BlockMeta, error)
	GetBlockMeta(height int64) (*BlockMeta, error)
	SaveBlockMeta(height int64, blockMeta *BlockMeta) error
	PruneBlockMeta(height int64, callback PruneBlockMetaCallback) error
	UpsertTransactionFee(fee float64, vSize int32) error
	GetTransactionFee() (float64, int32, error)
	TryAddToMemPoolCache(hash string) (bool, error)
	RemoveFromMemPoolCache(hash string) error
	TryAddToObservedTxCache(hash string) (bool, error)
	RemoveObservedTxCache(hash string) error
}

BlockMetaAccessor define methods need to access block meta storage

type Client

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

Client observes bitcoin cash chain and allows to sign and broadcast tx

func NewClient

func NewClient(thorKeys *thorclient.Keys, cfg config.ChainConfiguration, server *tssp.TssServer, bridge *thorclient.ThorchainBridge, m *metrics.Metrics) (*Client, error)

NewClient generates a new Client

func (*Client) BroadcastTx

func (c *Client) BroadcastTx(txOut stypes.TxOutItem, payload []byte) (string, error)

BroadcastTx will broadcast the given payload to BCH chain

func (*Client) ConfirmationCountReady

func (c *Client) ConfirmationCountReady(txIn types.TxIn) bool

ConfirmationCountReady will be called by observer before send the txIn to thorchain confirmation counting is on block level , refer to https://medium.com/coinmonks/1confvalue-a-simple-pow-confirmation-rule-of-thumb-a8d9c6c483dd for detail

func (*Client) FetchMemPool

func (c *Client) FetchMemPool(height int64) (types.TxIn, error)

FetchMemPool retrieves txs from mempool

func (*Client) FetchTxs

func (c *Client) FetchTxs(height int64) (types.TxIn, error)

FetchTxs retrieves txs for a block height

func (*Client) GetAccount

func (c *Client) GetAccount(pkey common.PubKey, height *big.Int) (common.Account, error)

GetAccount returns account with balance for an address

func (*Client) GetAccountByAddress

func (c *Client) GetAccountByAddress(string, *big.Int) (common.Account, error)

func (*Client) GetAddress

func (c *Client) GetAddress(poolPubKey common.PubKey) string

GetAddress returns address from pubkey

func (*Client) GetChain

func (c *Client) GetChain() common.Chain

GetChain returns BCH Chain

func (*Client) GetConfig

func (c *Client) GetConfig() config.ChainConfiguration

GetConfig - get the chain configuration

func (*Client) GetConfirmationCount

func (c *Client) GetConfirmationCount(txIn types.TxIn) int64

func (*Client) GetHeight

func (c *Client) GetHeight() (int64, error)

GetHeight returns current block height

func (*Client) IsBlockScannerHealthy

func (c *Client) IsBlockScannerHealthy() bool

func (*Client) OnObservedTxIn

func (c *Client) OnObservedTxIn(txIn types.TxInItem, blockHeight int64)

OnObservedTxIn gets called from observer when we have a valid observation For bitcoin cash chain client we want to save the utxo we can spend later to sign

func (*Client) RegisterPublicKey

func (c *Client) RegisterPublicKey(pkey common.PubKey) error

RegisterPublicKey register the given pubkey to bitcoin cash wallet

func (*Client) ReportSolvency added in v0.79.0

func (c *Client) ReportSolvency(bchBlockHeight int64) error

func (*Client) ShouldReportSolvency added in v0.79.0

func (c *Client) ShouldReportSolvency(height int64) bool

ShouldReportSolvency based on the given block height , should the client report solvency to THORNode

func (*Client) SignTx

func (c *Client) SignTx(tx stypes.TxOutItem, thorchainHeight int64) ([]byte, error)

SignTx is going to generate the outbound transaction, and also sign it

func (*Client) Start

func (c *Client) Start(globalTxsQueue chan types.TxIn, globalErrataQueue chan types.ErrataBlock, globalSolvencyQueue chan types.Solvency)

Start starts the block scanner

func (*Client) Stop

func (c *Client) Stop()

Stop stops the block scanner

type KeySignWrapper

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

KeySignWrapper is a wrap of private key and also tss instance it also implement the txscript.Signable interface, and will decide which method to use based on the pubkey

func NewKeySignWrapper

func NewKeySignWrapper(privateKey *bchec.PrivateKey, tssKeyManager tss.ThorchainKeyManager) (*KeySignWrapper, error)

NewKeysignWrapper create a new instance of Keysign Wrapper

func (*KeySignWrapper) GetSignable

func (w *KeySignWrapper) GetSignable(poolPubKey common.PubKey) txscript.Signable

GetSignable based on the given poolPubKey

type LevelDBBlockMetaAccessor

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

LevelDBBlockMetaAccessor struct

func NewLevelDBBlockMetaAccessor

func NewLevelDBBlockMetaAccessor(db *leveldb.DB) (*LevelDBBlockMetaAccessor, error)

NewLevelDBBlockMetaAccessor creates a new level db backed BlockMeta accessor

func (*LevelDBBlockMetaAccessor) GetBlockMeta

func (t *LevelDBBlockMetaAccessor) GetBlockMeta(height int64) (*BlockMeta, error)

GetBlockMeta at given block height , when the requested block meta doesn't exist , it will return nil , thus caller need to double check it

func (*LevelDBBlockMetaAccessor) GetBlockMetas

func (t *LevelDBBlockMetaAccessor) GetBlockMetas() ([]*BlockMeta, error)

GetBlockMetas returns all the block metas in storage The chain client will Prune block metas every time it finished scan a block , so at maximum it will keep BlockCacheSize blocks thus it should not grow out of control

func (*LevelDBBlockMetaAccessor) GetTransactionFee

func (t *LevelDBBlockMetaAccessor) GetTransactionFee() (float64, int32, error)

GetTransactionFee from db

func (*LevelDBBlockMetaAccessor) PruneBlockMeta

func (t *LevelDBBlockMetaAccessor) PruneBlockMeta(height int64, callback PruneBlockMetaCallback) error

PruneBlockMeta remove all block meta that is older than the given block height with exception, if there are unspent transaction output in it , then the block meta will not be removed

func (*LevelDBBlockMetaAccessor) RemoveFromMemPoolCache

func (t *LevelDBBlockMetaAccessor) RemoveFromMemPoolCache(hash string) error

RemoveFromMemPoolCache remove the hash from cache

func (*LevelDBBlockMetaAccessor) RemoveObservedTxCache added in v0.54.0

func (t *LevelDBBlockMetaAccessor) RemoveObservedTxCache(hash string) error

RemoveObservedTxCache remove the hash from cache

func (*LevelDBBlockMetaAccessor) SaveBlockMeta

func (t *LevelDBBlockMetaAccessor) SaveBlockMeta(height int64, blockMeta *BlockMeta) error

SaveBlockMeta persistent the given BlockMeta into storage

func (*LevelDBBlockMetaAccessor) TryAddToMemPoolCache

func (t *LevelDBBlockMetaAccessor) TryAddToMemPoolCache(hash string) (bool, error)

TryAddToMemPoolCache trying to add the given hash to mempool hash return value bool indicated whether we added value to cache or not

func (*LevelDBBlockMetaAccessor) TryAddToObservedTxCache added in v0.54.0

func (t *LevelDBBlockMetaAccessor) TryAddToObservedTxCache(hash string) (bool, error)

TryAddToObservedTxCache store the transaction hash into local key value store so as bifrost will not report a tx twice, which will cause it to be slashed by thornode

func (*LevelDBBlockMetaAccessor) UpsertTransactionFee

func (t *LevelDBBlockMetaAccessor) UpsertTransactionFee(fee float64, vSize int32) error

UpsertTransactionFee update the transaction fee in storage

type PruneBlockMetaCallback added in v0.54.0

type PruneBlockMetaCallback func(meta *BlockMeta) bool

type TransactionFee

type TransactionFee struct {
	Fee   float64 `json:"fee"`
	VSize int32   `json:"v_size"`
}

TransactionFee on bitcoin

type TssSignable

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

TssSignable is a signable implementation backed by tss

func NewTssSignable

func NewTssSignable(pubKey common.PubKey, manager tss.ThorchainKeyManager) (*TssSignable, error)

NewTssSignable create a new instance of TssSignable

func (*TssSignable) GetPubKey

func (ts *TssSignable) GetPubKey() *bchec.PublicKey

func (*TssSignable) SignECDSA

func (ts *TssSignable) SignECDSA(payload []byte) (*bchec.Signature, error)

SignECDSA signs the given payload using ECDSA

func (*TssSignable) SignSchnorr

func (ts *TssSignable) SignSchnorr(payload []byte) (*bchec.Signature, error)

SignSchnorr signs the given payload using Schnorr

Jump to

Keyboard shortcuts

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