btc

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 29 Imported by: 0

README

btc router specials

btc token config ContractAddress item

ContractAddress is BTC or format of Currency

btc stands for native

btc chain and token config RouterContract item

RouterContract is the mpc address

btc public key to btc address

go run tokens/btc/tools/pubKeyToAddress/main.go -pubKey 0409373c48ead4253c79f0f2063139170c9a3f47d3aa9dc1fb99a2f6edff0703ff55742d2475ea2703c2b8d479221c6df53bf50c9832c94501597a65c40858b4f6
# output
address: mwjkhU9ZdoShS7wPKgj7dE8DnKgdRypoYh

router mechanism

  1. Swapout from btc to other chain

user send asset to mpc address with memo of the following format

bindAddress:toChainID

example:

0x1111111111111111111111111111111111111111:4

to specify route asset to which address (bindAddress) and to which destination blockchain (toChainID)

  1. Swapin from other chain to btc
function anySwapOut(address token, string memory to, uint amount, uint toChainID)

to is the destination on btc, it can be an btc address

btc tools

use -h option to get help info for each tool

example:

go run tokens/btc/tools/pubKeyToAddress/main.go -h
pubKeyToAddress
	convert ec public key to btc address

wifToEcPrivKey
	convert wif to ec privKey

config example: tokenConfig: [ { chainID: "1000004346948", tokenAddr: "btc", decimals: 8, version: 6, routerContract: "mwjkhU9ZdoShS7wPKgj7dE8DnKgdRypoYh", extra: "" } ] chainConfigs: [ { chainID: 1000004346948, blockChain: "btc", routerContract: "mwjkhU9ZdoShS7wPKgj7dE8DnKgdRypoYh", confirmations: "1", initialHeight: "5", extra: "" }, { chainID: 4, blockChain: "rinkeby", routerContract: "0x585DEa293B5c9dfe3E44976FD1A724e11CD7Cc21", confirmations: "15", initialHeight: "10781362", extra: "" }, ]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnlockMemoPrefix = "SWAPTX:"
)

Functions

func DecodeWIF

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

DecodeWIF decode wif

func EstimateFeePerKb

func EstimateFeePerKb(url string, blocks int) (fee int64, err error)

func GetBindAddressFromMemoScipt

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

GetBindAddressFromMemoScipt get bind address

func GetLatestBlockNumber

func GetLatestBlockNumber(url string) (result uint64, err error)

func GetP2shBindAddress

func GetP2shBindAddress(p2shAddress string) (bindAddress string)

GetP2shBindAddress get p2sh bind address

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID

func PostTransaction

func PostTransaction(url, txHex string) (txHash string, err error)

PostTransaction call post to /tx

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

Types

type Bridge

type Bridge struct {
	*tokens.CrossChainBridgeBase
}

Bridge near bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BroadcastTxCommit

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

PostTransaction impl

func (*Bridge) BuildRawTransaction

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

BuildRawTransaction build raw 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) DcrmSignMsgHash

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

DcrmSignMsgHash dcrm sign msg hash

func (*Bridge) DcrmSignTransaction

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

DcrmSignTransaction dcrm sign raw tx

func (*Bridge) DecodeAddress

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

DecodeAddress decode address

func (*Bridge) EstimateFeePerKb

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

EstimateFeePerKb impl

func (*Bridge) FindUtxos

func (b *Bridge) FindUtxos(addr string) (result []*ElectUtxo, err error)

func (*Bridge) GetChainParams

func (b *Bridge) GetChainParams(chainID *big.Int) *chaincfg.Params

GetChainParams get chain config (net params)

func (*Bridge) GetCompressedPublicKey

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

GetCompressedPublicKey get compressed public key

func (*Bridge) GetElectTransactionStatus

func (b *Bridge) GetElectTransactionStatus(txHash string) (result *ElectTxStatus, err error)

GetElectTransactionStatus impl

func (*Bridge) GetLatestBlockNumber

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

GetLatestBlockNumber gets latest block number

func (*Bridge) GetLatestBlockNumberOf

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

GetLatestBlockNumberOf gets latest block number from single api

func (*Bridge) GetP2shAddress

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

func (*Bridge) GetP2shAddressByRedeemScript

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)

func (*Bridge) GetP2shSigScript

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) GetPublicKeyFromECDSA

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

GetPublicKeyFromECDSA get public key from ecdsa private key

func (*Bridge) GetReceivedValue

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

func (*Bridge) GetSigScript

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

GetSigScript get script

func (*Bridge) GetTransaction

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

GetTransaction impl

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (result *ElectTx, err error)

GetTransactionByHash get tx response by hash

func (*Bridge) GetTransactionStatus

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

GetTransactionStatus impl

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*Bridge) InitRouterInfo

func (b *Bridge) InitRouterInfo(routerContract, routerVersion string) (err error)

InitRouterInfo init router info

func (*Bridge) IsPayToScriptHash

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

IsPayToScriptHash is p2sh

func (*Bridge) IsValidAddress

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

IsValidAddress check address

func (*Bridge) MPCSignTransaction

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

MPCSignTransaction mpc sign raw tx

func (*Bridge) MakeSignedTransaction

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

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

NewAddressPubKeyHash encap

func (*Bridge) NewAddressScriptHash

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

NewAddressScriptHash encap

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

func (b *Bridge) NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount,
	fetchInputs txauthor.InputSource, fetchChange txauthor.ChangeSource) (*txauthor.AuthoredTx, error)

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) PublicKeyToAddress

func (b *Bridge) PublicKeyToAddress(pubKey string) (string, error)

PublicKeyToAddress impl

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendTransaction

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

func (*Bridge) SetTokenConfig

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set and verify token config

func (*Bridge) SignTransactionWithPrivateKey

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

SignTransactionWithPrivateKey sign tx with ECDSA private key string

func (*Bridge) SignWithECDSA

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

SignWithECDSA sign with ecdsa private key

func (*Bridge) ToCompressedPublicKey

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

ToCompressedPublicKey convert to compressed public key if not

func (*Bridge) VerifyMsgHash

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

VerifyMsgHash verify msg hash

func (*Bridge) VerifyPubKey

func (b *Bridge) VerifyPubKey(address, pubKey string) error

todo: read from config

func (*Bridge) VerifyRedeemScript

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

VerifyRedeemScript verify redeem script

func (*Bridge) VerifyTokenConfig

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

VerifyTokenConfig verify token config

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction impl

type ElectBlock

type ElectBlock struct {
	Hash         *string `json:"id"`
	Height       *uint32 `json:"height"`
	Version      *uint32 `json:"version"`
	Timestamp    *uint32 `json:"timestamp"`
	TxCount      *uint32 `json:"tx_count"`
	Size         *uint32 `json:"size"`
	Weight       *uint32 `json:"weight"`
	MerkleRoot   *string `json:"merkle_root"`
	PreviousHash *string `json:"previousblockhash"`
	Nonce        *uint32 `json:"nonce"`
	Bits         *uint32 `json:"bits"`
	Difficulty   *uint64 `json:"difficulty"`
}

ElectBlock struct

type ElectOutspend

type ElectOutspend struct {
	Spent  *bool          `json:"spent"`
	Txid   *string        `json:"txid"`
	Vin    *uint32        `json:"vin"`
	Status *ElectTxStatus `json:"status,omitempty"`
}

ElectOutspend struct

func (*ElectOutspend) String

func (outspend *ElectOutspend) String() string

type ElectTx

type ElectTx struct {
	Txid     *string        `json:"txid"`
	Version  *uint32        `json:"version"`
	Locktime *uint32        `json:"locktime"`
	Size     *uint32        `json:"size"`
	Weight   *uint32        `json:"weight"`
	Fee      *uint64        `json:"fee"`
	Vin      []*ElectTxin   `json:"vin"`
	Vout     []*ElectTxOut  `json:"vout"`
	Status   *ElectTxStatus `json:"status,omitempty"`
}

ElectTx struct

func GetTransactionByHash

func GetTransactionByHash(url, txHash string) (*ElectTx, error)

GetTransactionByHash get tx by hash

type ElectTxOut

type ElectTxOut struct {
	Scriptpubkey        *string `json:"scriptpubkey"`
	ScriptpubkeyAsm     *string `json:"scriptpubkey_asm"`
	ScriptpubkeyType    *string `json:"scriptpubkey_type"`
	ScriptpubkeyAddress *string `json:"scriptpubkey_address"`
	Value               *uint64 `json:"value"`
}

ElectTxOut struct

type ElectTxStatus

type ElectTxStatus struct {
	Confirmed   *bool   `json:"confirmed"`
	BlockHeight *uint64 `json:"block_height"`
	BlockHash   *string `json:"block_hash"`
	BlockTime   *uint64 `json:"block_time"`
}

ElectTxStatus struct

func GetElectTransactionStatus

func GetElectTransactionStatus(url, txHash string) (result *ElectTxStatus, err error)

GetElectTransactionStatus call /tx/{txHash}/status

func (*ElectTxStatus) String

func (status *ElectTxStatus) String() string

type ElectTxin

type ElectTxin struct {
	Txid                 *string     `json:"txid"`
	Vout                 *uint32     `json:"vout"`
	Scriptsig            *string     `json:"scriptsig"`
	ScriptsigAsm         *string     `json:"scriptsig_asm"`
	IsCoinbase           *bool       `json:"is_coinbase"`
	Sequence             *uint32     `json:"sequence"`
	InnerRedeemscriptAsm *string     `json:"inner_redeemscript_asm"`
	Prevout              *ElectTxOut `json:"prevout"`
}

ElectTxin struct

type ElectUtxo

type ElectUtxo struct {
	Txid   *string        `json:"txid"`
	Vout   *uint32        `json:"vout"`
	Value  *uint64        `json:"value"`
	Status *ElectTxStatus `json:"status"`
}

ElectUtxo struct

func FindUtxos

func FindUtxos(url string, addr string) (result []*ElectUtxo, err error)

func (*ElectUtxo) String

func (utxo *ElectUtxo) String() string

type SortableElectUtxoSlice

type SortableElectUtxoSlice []*ElectUtxo

SortableElectUtxoSlice sortable

func (SortableElectUtxoSlice) Len

func (s SortableElectUtxoSlice) Len() int

Len impl Sortable

func (SortableElectUtxoSlice) Less

func (s SortableElectUtxoSlice) Less(i, j int) bool

Less impl Sortable sort utxos 1. confirmed fisrt 2. value first

func (SortableElectUtxoSlice) Swap

func (s SortableElectUtxoSlice) Swap(i, j int)

Swap impl Sortable

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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