btc

package
v0.0.0-...-09e170c Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainSignet  = "signet"
	ChainMainnet = "mainnet"
	// ComingChat used, similar mainnet's alias.
	ChainBitcoin = "bitcoin"
)

Variables

View Source
var (
	ErrUnsupportedChain  = errors.New("Unsupported BTC chainnet")
	ErrHttpResponseParse = errors.New("Network data parsing error")

	ErrDecodeAddress = errors.New("Btc cannot support decode address to public key")
)

Functions

func EncodePublicDataToAddress

func EncodePublicDataToAddress(public []byte, chainnet string) (string, error)

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey, chainnet string) (string, error)

@param publicKey can start with 0x or not.

func FetchTransactionDetail deprecated

func FetchTransactionDetail(hashString, chainnet string) (*base.TransactionDetail, error)

Deprecated: FetchTransactionDetail is deprecated. Please Use Chain.FetchTransactionDetail() instead.

func FetchTransactionStatus deprecated

func FetchTransactionStatus(hashString string, chainnet string) base.TransactionStatus

Deprecated: FetchTransactionStatus is deprecated. Please Use Chain.FetchTransactionStatus() instead.

func IsValidAddress

func IsValidAddress(address, chainnet string) bool

@param chainnet chain name

func QueryBalance deprecated

func QueryBalance(address, chainnet string) (string, error)

Deprecated: QueryBalance is deprecated. Please Use Chain.QueryBalanceWithAddress() instead.

func QueryBalancePubkey deprecated

func QueryBalancePubkey(pubkey, chainnet string) (string, error)

Deprecated: QueryBalancePubkey is deprecated. Please Use Chain.QueryBalanceWithPublicKey() instead.

func SdkBatchTransactionStatus deprecated

func SdkBatchTransactionStatus(hashListString string, chainnet string) string

Deprecated: SdkBatchTransactionStatus is deprecated. Please Use Chain.BatchFetchTransactionStatus() instead.

func SendRawTransaction deprecated

func SendRawTransaction(signedTx string, chainnet string) (string, error)

Deprecated: SendRawTransaction is deprecated. Please Use Chain.SendRawTransaction() instead.

Types

type Account

type Account struct {
	Chainnet string
	// contains filtered or unexported fields
}

func AccountWithPrivateKey

func AccountWithPrivateKey(prikey string, chainnet string) (*Account, error)

func AsBitcoinAccount

func AsBitcoinAccount(account base.Account) *Account

func NewAccountWithMnemonic

func NewAccountWithMnemonic(mnemonic, chainnet string) (*Account, error)

func (*Account) Address

func (a *Account) Address() string

@return default is the mainnet address

func (*Account) DecodeAddressToPublicKey

func (a *Account) DecodeAddressToPublicKey(address string) (string, error)

@return publicKey that will start with 0x.

func (*Account) DeriveAccountAt

func (a *Account) DeriveAccountAt(chainnet string) (*Account, error)

func (*Account) EncodePublicKeyToAddress

func (a *Account) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Account) IsValidAddress

func (a *Account) IsValidAddress(address string) bool

func (*Account) PrivateKey

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

@return publicKey data

func (*Account) PublicKeyHex

func (a *Account) PublicKeyHex() string

@return publicKey string that will start with 0x.

func (*Account) Sign

func (a *Account) Sign(message []byte, password string) ([]byte, error)

TODO: function not implement yet.

func (*Account) SignHex

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

TODO: function not implement yet.

type Chain

type Chain struct {
	*Util
}

func NewChainWithChainnet

func NewChainWithChainnet(chainnet string) (*Chain, error)

func (*Chain) BalanceOfAccount

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)

func (*Chain) BalanceOfPublicKey

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Chain) BatchFetchTransactionStatus

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

func (*Chain) BuildTransfer

func (t *Chain) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)

func (*Chain) BuildTransferAll

func (t *Chain) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error)

func (*Chain) CanTransferAll

func (t *Chain) CanTransferAll() bool

func (*Chain) Chain

func (c *Chain) Chain() base.Chain

func (*Chain) EstimateTransactionFee

func (c *Chain) EstimateTransactionFee(transaction base.Transaction) (fee *base.OptionalString, err error)

func (*Chain) EstimateTransactionFeeUsePublicKey

func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction, pubkey string) (fee *base.OptionalString, err error)

func (*Chain) FetchTransactionDetail

func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)

Fetch transaction details through transaction hash Note: The input parsing of bitcoin is very complex and the network cost is relatively high, So only the status and timestamp can be queried.

func (*Chain) FetchTransactionStatus

func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus

func (*Chain) MainToken

func (c *Chain) MainToken() base.Token

func (*Chain) SendRawTransaction

func (c *Chain) SendRawTransaction(signedTx string) (string, error)

Send the raw transaction on-chain @return the hex hash string

func (*Chain) TokenInfo

func (c *Chain) TokenInfo() (*base.TokenInfo, error)

type FeeRate

type FeeRate struct {
	Low     int64
	Average int64
	High    int64
}

func SuggestFeeRate

func SuggestFeeRate() (*FeeRate, error)

type Util

type Util struct {
	Chainnet string
}

func NewUtilWithChainnet

func NewUtilWithChainnet(chainnet string) (*Util, error)

func (*Util) DecodeAddressToPublicKey

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

Warning: Btc cannot support decode address to public key

func (*Util) EncodePublicDataToAddress

func (u *Util) EncodePublicDataToAddress(public []byte) (string, error)

func (*Util) EncodePublicKeyToAddress

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Util) IsValidAddress

func (u *Util) IsValidAddress(address string) bool

Jump to

Keyboard shortcuts

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