block

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

Package block implements the bridge interfaces for block blockchain.

Index

Constants

This section is empty.

Variables

View Source
var BridgeInstance btc.BridgeInterface

BridgeInstance btc bridge instance

View Source
var MainNetParams = chaincfg.Params{
	Name: "mainnet",
	Net:  wire.MainNet,

	PowLimit:                 new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne),
	PowLimitBits:             0x00000fff,
	BIP0034Height:            1,
	BIP0065Height:            1,
	BIP0066Height:            1,
	CoinbaseMaturity:         100,
	SubsidyReductionInterval: 210000,
	TargetTimespan:           time.Minute * 1,
	TargetTimePerBlock:       time.Minute * 1,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        false,

	Checkpoints: []chaincfg.Checkpoint{},

	RuleChangeActivationThreshold: 1368,
	MinerConfirmationWindow:       1440,
	Deployments: [chaincfg.DefinedDeployments]chaincfg.ConsensusDeployment{
		chaincfg.DeploymentTestDummy: {
			BitNumber:  28,
			StartTime:  1199145601,
			ExpireTime: 1230767999,
		},
		chaincfg.DeploymentCSV: {
			BitNumber:  0,
			StartTime:  0,
			ExpireTime: math.MaxInt64,
		},
		chaincfg.DeploymentSegwit: {
			BitNumber:  1,
			StartTime:  1584295200,
			ExpireTime: 1589565600,
		},
	},

	RelayNonStdTxs: false,

	Bech32HRPSegwit: "block",

	PubKeyHashAddrID:        0x1a,
	ScriptHashAddrID:        0x1c,
	PrivateKeyID:            0x9a,
	WitnessPubKeyHashAddrID: 0x06,
	WitnessScriptHashAddrID: 0x0A,

	HDPrivateKeyID: [4]byte{0x04, 0x88, 0xAD, 0xE4},
	HDPublicKeyID:  [4]byte{0x04, 0x88, 0xB2, 0x1E},

	HDCoinType: 0,
}

MainNetParams is blocknet mainnet cfg

View Source
var PairID = "block"

PairID unique btc pair ID

Functions

func ConvertBlock added in v0.3.1

func ConvertBlock(blk *btcjson.GetBlockVerboseResult) *electrs.ElectBlock

ConvertBlock converts btcjson block verbose result to elect block

func ConvertTx added in v0.3.1

func ConvertTx(tx *btcjson.TxRawResult) *electrs.ElectTx

ConvertTx converts btcjson raw tx result to elect tx

func ConvertVin added in v0.3.1

func ConvertVin(vin *btcjson.Vin) *electrs.ElectTxin

ConvertVin converts btcjson vin to elect vin

func ConvertVout added in v0.3.1

func ConvertVout(vout *btcjson.Vout) *electrs.ElectTxOut

ConvertVout converts btcjson vout to elect vout

func DecodeTxHex added in v0.3.1

func DecodeTxHex(txHex string, protocolversion uint32, isWitness bool) *wire.MsgTx

DecodeTxHex decode tx hex to msgTx

func DecodeWIF added in v0.3.1

func DecodeWIF(wif string) (*btcutil.WIF, error)

DecodeWIF decode wif

func GetBindAddressFromMemoScipt added in v0.3.1

func GetBindAddressFromMemoScipt(memoScript string) (bind string, ok bool)

GetBindAddressFromMemoScipt get bind address

func Init added in v0.3.1

func Init(btcExtra *tokens.BtcExtraConfig)

Init init btc extra

func TxOutspend added in v0.3.1

func TxOutspend(txout *btcjson.GetTxOutResult) *electrs.ElectOutspend

TxOutspend make elect outspend from btcjson tx raw result

func TxStatus added in v0.3.1

TxStatus make elect tx status from btcjson tx raw result

Types

type Bridge

type Bridge struct {
	*tokens.CrossChainBridgeBase
}

Bridge block bridge inherit from btc bridge

func NewCrossChainBridge

func NewCrossChainBridge(isSrc bool) *Bridge

NewCrossChainBridge new fsn bridge

func (*Bridge) AggregateUtxos added in v0.3.1

func (b *Bridge) AggregateUtxos(addrs []string, utxos []*electrs.ElectUtxo) (string, error)

AggregateUtxos aggregate uxtos

func (*Bridge) BuildAggregateTransaction added in v0.3.1

func (b *Bridge) BuildAggregateTransaction(relayFeePerKb int64, addrs []string, utxos []*electrs.ElectUtxo) (rawTx *txauthor.AuthoredTx, err error)

BuildAggregateTransaction build aggregate tx (spend p2sh utxo)

func (*Bridge) BuildRawTransaction added in v0.3.1

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) BuildTransaction added in v0.3.1

func (b *Bridge) BuildTransaction(from string, receivers []string, amounts []int64, memo string, relayFeePerKb int64) (rawTx interface{}, err error)

BuildTransaction build tx

func (*Bridge) CalcSignatureHash

func (b *Bridge) CalcSignatureHash(sigScript []byte, tx *wire.MsgTx, i int) (sigHash []byte, err error)

CalcSignatureHash calc sig hash

func (*Bridge) CheckSwapinTxType added in v0.3.1

func (b *Bridge) CheckSwapinTxType(tx *electrs.ElectTx) (p2shBindAddrs []string, err error)

CheckSwapinTxType check swapin type

func (*Bridge) DcrmSignMsgHash added in v0.3.1

func (b *Bridge) DcrmSignMsgHash(msgHash []string, args *tokens.BuildTxArgs) (rsv []string, err error)

DcrmSignMsgHash dcrm sign msg hash

func (*Bridge) DcrmSignTransaction added in v0.3.1

func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signedTx interface{}, txHash string, err error)

DcrmSignTransaction dcrm sign raw tx

func (*Bridge) DecodeAddress added in v0.3.1

func (b *Bridge) DecodeAddress(addr string) (address btcutil.Address, err error)

DecodeAddress decode address

func (*Bridge) EstimateFeePerKb added in v0.3.1

func (b *Bridge) EstimateFeePerKb(blocks int) (fee int64, err error)

EstimateFeePerKb impl

func (*Bridge) FindUtxos added in v0.3.1

func (b *Bridge) FindUtxos(addr string) (utxos []*electrs.ElectUtxo, err error)

FindUtxos impl

func (*Bridge) GetBalance added in v0.3.1

func (b *Bridge) GetBalance(account string) (*big.Int, error)

GetBalance impl

func (*Bridge) GetBlock added in v0.3.1

func (b *Bridge) GetBlock(blockHash string) (eblock *electrs.ElectBlock, err error)

GetBlock impl

func (*Bridge) GetBlockHash added in v0.3.1

func (b *Bridge) GetBlockHash(height uint64) (hash string, err error)

GetBlockHash impl

func (*Bridge) GetBlockTransactions added in v0.3.1

func (b *Bridge) GetBlockTransactions(blockHash string, startIndex uint32) (etxs []*electrs.ElectTx, err error)

GetBlockTransactions impl

func (*Bridge) GetBlockTxids added in v0.3.1

func (b *Bridge) GetBlockTxids(blockHash string) (txids []string, err error)

GetBlockTxids impl

func (*Bridge) GetChainParams

func (b *Bridge) GetChainParams() *chaincfg.Params

GetChainParams get chain config (net params)

func (*Bridge) GetClient added in v0.3.1

func (b *Bridge) GetClient() *Client

GetClient returns new Client

func (*Bridge) GetCompressedPublicKey added in v0.3.1

func (b *Bridge) GetCompressedPublicKey(fromPublicKey string, needVerify bool) (cPkData []byte, err error)

GetCompressedPublicKey get compressed public key

func (*Bridge) GetElectTransactionStatus added in v0.3.1

func (b *Bridge) GetElectTransactionStatus(txHash string) (txstatus *electrs.ElectTxStatus, err error)

GetElectTransactionStatus impl

func (*Bridge) GetLatestBlockNumber added in v0.3.1

func (b *Bridge) GetLatestBlockNumber() (blocknumber uint64, err error)

GetLatestBlockNumber impl

func (*Bridge) GetLatestBlockNumberOf added in v0.3.1

func (b *Bridge) GetLatestBlockNumberOf(apiAddress string) (uint64, error)

GetLatestBlockNumberOf impl

func (*Bridge) GetOutspend added in v0.3.1

func (b *Bridge) GetOutspend(txHash string, vout uint32) (evout *electrs.ElectOutspend, err error)

GetOutspend impl Only to find out if txout is spent, does not tell in which transactions it is spent.

func (*Bridge) GetP2shAddress added in v0.3.1

func (b *Bridge) GetP2shAddress(bindAddr string) (p2shAddress string, redeemScript []byte, err error)

GetP2shAddress get p2sh address from bind address

func (*Bridge) GetP2shAddressByRedeemScript added in v0.3.1

func (b *Bridge) GetP2shAddressByRedeemScript(redeemScript []byte) (string, error)

GetP2shAddressByRedeemScript get p2sh address by redeem script

func (*Bridge) GetP2shRedeemScript

func (b *Bridge) GetP2shRedeemScript(memo, pubKeyHash []byte) (redeemScript []byte, err error)

GetP2shRedeemScript get p2sh redeem script

func (*Bridge) GetP2shSigScript added in v0.3.1

func (b *Bridge) GetP2shSigScript(redeemScript []byte) ([]byte, error)

GetP2shSigScript get p2sh signature script

func (*Bridge) GetPayToAddrScript

func (b *Bridge) GetPayToAddrScript(address string) ([]byte, error)

GetPayToAddrScript get pay to address script

func (*Bridge) GetPoolTransactions added in v0.3.1

func (b *Bridge) GetPoolTransactions(addr string) (txs []*electrs.ElectTx, err error)

GetPoolTransactions impl

func (*Bridge) GetPoolTxidList added in v0.3.1

func (b *Bridge) GetPoolTxidList() (txids []string, err error)

GetPoolTxidList impl

func (*Bridge) GetPublicKeyFromECDSA

func (b *Bridge) GetPublicKeyFromECDSA(privKey *ecdsa.PrivateKey, compressed bool) []byte

GetPublicKeyFromECDSA get public key from ecdsa private key

func (*Bridge) GetReceivedValue added in v0.3.1

func (b *Bridge) GetReceivedValue(vout []*electrs.ElectTxOut, receiver, pubkeyType string) (value uint64, memoScript string, rightReceiver bool)

GetReceivedValue get received value

func (*Bridge) GetSigScript

func (b *Bridge) GetSigScript(sigScripts [][]byte, prevScript, signData, cPkData []byte, i int) (sigScript []byte, err error)

GetSigScript get script

func (*Bridge) GetTokenBalance added in v0.3.1

func (b *Bridge) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error)

GetTokenBalance impl

func (*Bridge) GetTokenSupply added in v0.3.1

func (b *Bridge) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error)

GetTokenSupply impl

func (*Bridge) GetTransaction added in v0.3.1

func (b *Bridge) GetTransaction(txHash string) (interface{}, error)

GetTransaction impl

func (*Bridge) GetTransactionByHash added in v0.3.1

func (b *Bridge) GetTransactionByHash(txHash string) (etx *electrs.ElectTx, err error)

GetTransactionByHash impl

func (*Bridge) GetTransactionHistory added in v0.3.1

func (b *Bridge) GetTransactionHistory(addr, lastSeenTxid string) (etxs []*electrs.ElectTx, err error)

GetTransactionHistory impl lastSeenTxis 以后所有的交易

func (*Bridge) GetTransactionStatus added in v0.3.1

func (b *Bridge) GetTransactionStatus(txHash string) (*tokens.TxStatus, error)

GetTransactionStatus impl

func (*Bridge) InitLatestBlockNumber added in v0.3.1

func (b *Bridge) InitLatestBlockNumber()

InitLatestBlockNumber init latest block number

func (*Bridge) IsP2pkhAddress added in v0.3.1

func (b *Bridge) IsP2pkhAddress(addr string) bool

IsP2pkhAddress check p2pkh addrss

func (*Bridge) IsP2shAddress added in v0.3.1

func (b *Bridge) IsP2shAddress(addr string) bool

IsP2shAddress check p2sh addrss

func (*Bridge) IsPayToScriptHash

func (b *Bridge) IsPayToScriptHash(sigScript []byte) bool

IsPayToScriptHash is p2sh

func (*Bridge) IsValidAddress added in v0.3.1

func (b *Bridge) IsValidAddress(addr string) bool

IsValidAddress check address

func (*Bridge) MakeSignedTransaction added in v0.3.1

func (b *Bridge) MakeSignedTransaction(authoredTx *txauthor.AuthoredTx, msgHash, rsv []string, sigScripts [][]byte, cPkData []byte) (signedTx interface{}, txHash string, err error)

MakeSignedTransaction make signed tx

func (*Bridge) NewAddressPubKeyHash added in v0.3.1

func (b *Bridge) NewAddressPubKeyHash(pkData []byte) (*btcutil.AddressPubKeyHash, error)

NewAddressPubKeyHash encap

func (*Bridge) NewAddressScriptHash added in v0.3.1

func (b *Bridge) NewAddressScriptHash(redeemScript []byte) (*btcutil.AddressScriptHash, error)

NewAddressScriptHash encap

func (*Bridge) NewMsgTx added in v0.3.1

func (b *Bridge) NewMsgTx(inputs []*wire.TxIn, outputs []*wire.TxOut, locktime uint32) *wire.MsgTx

NewMsgTx new msg tx

func (*Bridge) NewTxIn

func (b *Bridge) NewTxIn(txid string, vout uint32, pkScript []byte) (*wire.TxIn, error)

NewTxIn new txin

func (*Bridge) NewTxOut

func (b *Bridge) NewTxOut(amount int64, pkScript []byte) *wire.TxOut

NewTxOut new txout

func (*Bridge) NewUnsignedTransaction added in v0.3.1

func (b *Bridge) NewUnsignedTransaction(outputs []*wireTxOutType, relayFeePerKb btcAmountType, fetchInputs txauthor.InputSource, fetchChange txauthor.ChangeSource, isAggregate bool) (*txauthor.AuthoredTx, error)

NewUnsignedTransaction ref btcwallet ref. https://github.com/btcsuite/btcwallet/blob/b07494fc2d662fdda2b8a9db2a3eacde3e1ef347/wallet/txauthor/author.go we only modify it to support P2PKH change script (the origin only support P2WPKH change script) and update estimate size because we are not use P2WKH

func (*Bridge) NullDataScript

func (b *Bridge) NullDataScript(memo string) ([]byte, error)

NullDataScript encap

func (*Bridge) ParsePkScript

func (b *Bridge) ParsePkScript(pkScript []byte) (txscript.PkScript, error)

ParsePkScript parse pkScript

func (*Bridge) PostTransaction added in v0.3.1

func (b *Bridge) PostTransaction(txHex string) (txHash string, err error)

PostTransaction impl

func (*Bridge) SendTransaction added in v0.3.1

func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)

SendTransaction send signed tx

func (*Bridge) SerializePublicKey

func (b *Bridge) SerializePublicKey(ecPub *ecdsa.PublicKey, compressed bool) []byte

SerializePublicKey serialize ecdsa public key

func (*Bridge) SerializeSignature

func (b *Bridge) SerializeSignature(r, s *big.Int) []byte

SerializeSignature serialize signature

func (*Bridge) SetChainAndGateway added in v0.3.1

func (b *Bridge) SetChainAndGateway(chainCfg *tokens.ChainConfig, gatewayCfg *tokens.GatewayConfig)

SetChainAndGateway set chain and gateway config

func (*Bridge) ShouldAggregate added in v0.3.1

func (b *Bridge) ShouldAggregate(aggUtxoCount int, aggSumVal uint64) bool

ShouldAggregate should aggregate

func (*Bridge) SignTransaction added in v0.3.1

func (b *Bridge) SignTransaction(rawTx interface{}, pairID string) (signedTx interface{}, txHash string, err error)

SignTransaction sign tx with pairID

func (*Bridge) SignTransactionWithPrivateKey added in v0.3.1

func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, privKey *ecdsa.PrivateKey) (signTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) SignTransactionWithWIF added in v0.3.1

func (b *Bridge) SignTransactionWithWIF(rawTx interface{}, wif string) (signedTx interface{}, txHash string, err error)

SignTransactionWithWIF sign tx with WIF

func (*Bridge) SignWithECDSA

func (b *Bridge) SignWithECDSA(privKey *ecdsa.PrivateKey, msgHash []byte) (rsv string, err error)

SignWithECDSA sign with ecdsa private key

func (*Bridge) StartChainTransactionScanJob added in v0.3.1

func (b *Bridge) StartChainTransactionScanJob()

StartChainTransactionScanJob scan job

func (*Bridge) StartPoolTransactionScanJob added in v0.3.1

func (b *Bridge) StartPoolTransactionScanJob()

StartPoolTransactionScanJob scan job

func (*Bridge) StartSwapHistoryScanJob added in v0.3.1

func (b *Bridge) StartSwapHistoryScanJob()

StartSwapHistoryScanJob scan job

func (*Bridge) ToCompressedPublicKey

func (b *Bridge) ToCompressedPublicKey(pkData []byte) ([]byte, error)

ToCompressedPublicKey convert to compressed public key if not

func (*Bridge) VerifyAggregateMsgHash added in v0.3.1

func (b *Bridge) VerifyAggregateMsgHash(msgHash []string, args *tokens.BuildTxArgs) error

VerifyAggregateMsgHash verify aggregate msgHash

func (*Bridge) VerifyChainConfig added in v0.3.1

func (b *Bridge) VerifyChainConfig()

VerifyChainConfig verify chain config nolint:goconst // use string literal

func (*Bridge) VerifyMsgHash added in v0.3.1

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHash []string) (err error)

VerifyMsgHash verify msg hash

func (*Bridge) VerifyP2shTransaction added in v0.3.1

func (b *Bridge) VerifyP2shTransaction(pairID, txHash, bindAddress string, allowUnstable bool) (*tokens.TxSwapInfo, error)

VerifyP2shTransaction verify p2sh tx

func (*Bridge) VerifyRedeemScript added in v0.3.1

func (b *Bridge) VerifyRedeemScript(prevScript, redeemScript []byte) error

VerifyRedeemScript verify redeem script

func (*Bridge) VerifyTokenConfig added in v0.3.1

func (b *Bridge) VerifyTokenConfig(tokenCfg *tokens.TokenConfig) error

VerifyTokenConfig verify token config

func (*Bridge) VerifyTransaction added in v0.3.1

func (b *Bridge) VerifyTransaction(pairID, txHash string, allowUnstable bool) (*tokens.TxSwapInfo, error)

VerifyTransaction impl

type Client added in v0.3.1

type Client struct {
	CClients         []CoreClient
	UTXOAPIAddresses []string
	// contains filtered or unexported fields
}

Client struct

func (*Client) Closer added in v0.3.4

func (c *Client) Closer()

Closer close all rpc clients

func (*Client) NextID added in v0.3.1

func (c *Client) NextID() int

NextID returns next id for FindUtxo request

type CloudchainUtxo added in v0.3.1

type CloudchainUtxo struct {
	Address     string  `json:"address"`
	Txhash      string  `json:"Txhash"`
	Vout        uint32  `json:"Vout"`
	BlockNumber uint64  `json:"block_number"`
	Value       float64 `json:"value"`
}

CloudchainUtxo struct

type CoreClient added in v0.3.1

type CoreClient struct {
	*rpcclient.Client
	Address string
	Closer  func()
}

CoreClient extends btcd rpcclient

Jump to

Keyboard shortcuts

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