btcwallet

package
v0.0.0-...-6e04e41 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: ISC Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHANNEL_INTERNAL = 1
	CHANNEL_EXTERNAL = 0

	DEFAULT_ADDRESS = 3

	AMT_ALL = 100000000
)
View Source
const (
	BTC_ADDRESS_P2PKH             uint32 = 0 //  Legacy
	BTC_ADDRESS_P2SH              uint32 = 1 //  NestedSegwit
	BTC_ADDRESS_P2WKH             uint32 = 2 //  NativeSegwit
	BTC_ADDRESS_P2WSH             uint32 = 3 //  P2WSH
	BTC_ADDRESS_P2TR              uint32 = 4 //  Taproot
	BTC_ADDRESS_INSCRIPTIONCOMMIT uint32 = 5 //  Inscription Commit Tx address

	BTC_ADDRESS_UNKNOWN uint32 = 0xffffffff // Unknow type

	BTC_WalletInfo_Templete = "/%s/%s/%s/walletinfo" // /mtv/userid/btcaccountname/walletinfo
)
View Source
const (
	HOST_BTCCHAIN_RELEASE = "https://blockstream.info/api"
	HOST_BTCCHAIN_TEST    = "http://192.168.10.104:8019/testnet"

	URL_GETTXLIST  = "%s/address/%s/txs"
	URL_GETBALANCE = "%s/address/%s"
	URL_GETUTXOS   = "%s/allutxos/address/%s"
	URL_TRANSATION = "%s/tx"
)
View Source
const (
	FILENAME_LOCAL_WALLET = "localwallet.json"
)

Variables

View Source
var (
	// LeagacyAccountPath is the base path for BIP44 (m/44'/0'/0').
	LeagacyAccountPath = []uint32{
		44 + hdkeychain.HardenedKeyStart, hdkeychain.HardenedKeyStart,
		hdkeychain.HardenedKeyStart,
	}
	// NativeSegwitAccountPath is the base path for BIP84 (m/84'/0'/0').
	NativeSegwitAccountPath = []uint32{
		84 + hdkeychain.HardenedKeyStart, hdkeychain.HardenedKeyStart,
		hdkeychain.HardenedKeyStart,
	}
	// NestedSegwitAccountPath is the base path for BIP49 (m/49'/0'/0').
	NestedSegwitAccountPath = []uint32{
		49 + hdkeychain.HardenedKeyStart, hdkeychain.HardenedKeyStart,
		hdkeychain.HardenedKeyStart,
	}
	// TaprootAccountPath is the base path for BIP86 (m/86'/0'/0').
	TaprootAccountPath = []uint32{
		86 + hdkeychain.HardenedKeyStart, hdkeychain.HardenedKeyStart,
		hdkeychain.HardenedKeyStart,
	}
)

Functions

func AddChildAccount

func AddChildAccount(walletname string, mnemonic string, publicKey []byte, privateKey []byte) error

func AddrToPkScript

func AddrToPkScript(addr string) ([]byte, error)

func DelChildAccount

func DelChildAccount(walletname string) error

func GetAllWalletAccounts

func GetAllWalletAccounts() ([]string, error)

func GetBTCBalance

func GetBTCBalance(address string) (*big.Float, *big.Float, error)

func GetBTCBalance1

func GetBTCBalance1(address string) (*big.Float, *big.Float, error)

func GetDefaultWalletName

func GetDefaultWalletName() string

func GetPrikey

func GetPrikey(walletName string) ([]byte, error)

func GetRawTransaction

func GetRawTransaction(tx *wire.MsgTx, allowHighFees bool) (string, error)

func GetScriptType

func GetScriptType(pkScript []byte) (uint32, error)

func GetUserAccountID

func GetUserAccountID(walletName string) ([]byte, error)

func InitWalletManager

func InitWalletManager(workDir string)

func LoadLocalWallet

func LoadLocalWallet(workDir string) error

func LogAddressType

func LogAddressType(address string)

func LogMsgTx

func LogMsgTx(tx *wire.MsgTx)

func LogPsbt

func LogPsbt(pb *psbt.Packet)

func PathExists

func PathExists(path string) bool

PathExists 文件是否存在

func PkScriptToAddr

func PkScriptToAddr(pkScript []byte) (string, error)

func ResetInstance

func ResetInstance()

func SendTransaction

func SendTransaction(raw string) (string, error)

func SetWalletInfo

func SetWalletInfo(walletName string, WalletInfo *BTCWalletInfo) error

Types

type BTCAccountDetails

type BTCAccountDetails struct {
	// Address summary
	ExternalAddresses []*BTCAddressSummary `json:"ExternalAddresses,omitempty"`
	InternalAddresses []*BTCAddressSummary `json:"InternalAddresses,omitempty"`

	AddressCount       int    `json:"AddressCount,omitempty"`
	TotalAmount        string `json:"TotalAmount,omitempty"`
	TotalMempoolAmount string `json:"TotalMempoolAmount,omitempty"`

	ChangeAddress     string `json:"ChangeAddress,omitempty"`
	DefaultPayAddress string `json:"DefaultPayAddress,omitempty"`
}

type BTCAccountStatus

type BTCAccountStatus struct {
	Funded_TXO_Count int64 `json:"funded_txo_count"`
	Funded_TXO_Sum   int64 `json:"funded_txo_sum"`
	Spent_TXO_Count  int64 `json:"spent_txo_count"`
	Spent_TXO_Sum    int64 `json:"spent_txo_sum"`
	TX_Count         int64 `json:"tx_count"`
}

type BTCAddress

type BTCAddress struct {
	Address      string           `json:"address"`
	ChainStats   BTCAccountStatus `json:"chain_stats"`
	MempoolStats BTCAccountStatus `json:"mempool_stats"`
}

type BTCAddressDetails

type BTCAddressDetails struct {
	// Address meta
	BTCAddressInfo
	// contains filtered or unexported fields
}

type BTCAddressInfo

type BTCAddressInfo struct {
	Channel      uint32 `protobuf:"varint,1,opt,name=Channel,proto3" json:"Channel,omitempty"`
	Index        uint32 `protobuf:"varint,2,opt,name=Index,proto3" json:"Index,omitempty"`
	AddressType  uint32 `protobuf:"varint,3,opt,name=AddressType,proto3" json:"AddressType,omitempty"`
	AddressAlias string `protobuf:"bytes,4,opt,name=AddressAlias,proto3" json:"AddressAlias,omitempty"`
}

type BTCAddressSummary

type BTCAddressSummary struct {
	Address       string `json:"Address,omitempty"`
	Amount        string `json:"Amount,omitempty"`
	MempoolAmount string `json:"MempoolAmount,omitempty"`
	Channel       uint32 `json:"Channel,omitempty"`
	Index         uint32 `json:"Index,omitempty"`
	AddressType   uint32 `json:"AddressType,omitempty"`
	AddressAlias  string `json:"AddressAlias,omitempty"`
	Path          string `json:"Path,omitempty"`
}

type BTCInOutSummary

type BTCInOutSummary struct {
	Address string `json:"address"`
	Value   int64  `json:"value"`
}

type BTCTXStatus

type BTCTXStatus struct {
	Confirmed   bool   `json:"confirmed"`
	BlockHeight int64  `json:"block_height"`
	BlockHash   string `json:"block_hash"`
	BlockTime   int64  `json:"block_time"`
}

status

type BTCTXStruct

type BTCTXStruct struct {
	TX_ID    string      `json:"txid"`
	Version  int         `json:"version"`
	LockTime int64       `json:"locktime"`
	VIn      []BTCTXVIn  `json:"vin"`
	VOut     []BTCTXVOut `json:"vout"`
	Size     int64       `json:"size"`
	Weight   int64       `json:"weight"`
	Fee      int64       `json:"fee"`
	Status   BTCTXStatus `json:"status"`
}

BTC tx

func GetAllTxList

func GetAllTxList(address string, startPage int, offset int) ([]*BTCTXStruct, error)

Get all tx list

type BTCTXSummaryStruct

type BTCTXSummaryStruct struct {
	TX_ID     string            `json:"txid"`
	TxTime    int64             `json:"txtime"`
	In        []BTCInOutSummary `json:"in"`
	Out       []BTCInOutSummary `json:"out"`
	Value     int64             `json:"size"`
	Fee       int64             `json:"fee"`
	Confirmed bool              `json:"confirmed"`
}

func GetAllTxSummary

func GetAllTxSummary(address string) ([]*BTCTXSummaryStruct, error)

Get all tx list

type BTCTXVIn

type BTCTXVIn struct {
	TX_ID        string    `json:"txid"`
	Vout         int64     `json:"vout"`
	Prevout      BTCTXVOut `json:"prevout"`
	ScriptSig    string    `json:"scriptsig"`
	ScriptSigAsm string    `json:"scriptsig_asm"`
	Witness      []string  `json:"witness"`
	IsCoinBase   bool      `json:"is_coinbase"`
	Sequence     int64     `json:"sequence"`
}

vin

type BTCTXVOut

type BTCTXVOut struct {
	ScriptPubKey        string `json:"scriptpubkey"`
	SpriptPubkeyAsm     string `json:"scriptpubkey_asm"`
	SpriptPubkeyType    string `json:"scriptpubkey_type"`
	SpriptPubkeyAddress string `json:"scriptpubkey_address"`
	Value               int64  `json:"value"`
}

vout

type BTCTxRes

type BTCTxRes struct {
	TXID string `json:"txid"`
}

type BTCUtxo

type BTCUtxo struct {
	TXID  string `json:"txid"`
	VOut  int64  `json:"vout"`
	Value int64  `json:"value"`
}

func GetBTCUtoxs

func GetBTCUtoxs(address string) ([]*BTCUtxo, error)

type BTCUtxoResponse

type BTCUtxoResponse struct {
	Code  int       `json:"code"`
	Msg   string    `json:"msg"`
	Total int       `json:"total"`
	Utxos []BTCUtxo `json:"otherutxos"`
}

type BTCWallet

type BTCWallet struct {

	// Wallet info metadata, it will be stored in dkvs
	WalletInfo *BTCWalletInfo

	sync.RWMutex
	// contains filtered or unexported fields
}

func CreateBTCWallet

func CreateBTCWallet(walletname string) (*BTCWallet, error)

func Import

func Import(walletname string, mnemonic string) (*BTCWallet, error)

func ImportWithPrivateKey

func ImportWithPrivateKey(walletname string, privateKey string) (*BTCWallet, error)

func InitBTCWallet

func InitBTCWallet(walletname string, workDir string) (*BTCWallet, error)

func (*BTCWallet) AccountCollect

func (wallet *BTCWallet) AccountCollect(address string, feeRate uint32) (string, error)

func (*BTCWallet) CreateOrdxTransaction

func (wallet *BTCWallet) CreateOrdxTransaction(paymentAddress string, assetsUtxo string, outputs []*wire.TxOut,
	feeRate btcutil.Amount, change bool) (*wire.MsgTx, []*utxo, error)

func (*BTCWallet) CreateTransaction

func (wallet *BTCWallet) CreateTransaction(paymentAddresses []string, outputs []*wire.TxOut,
	feeRate btcutil.Amount, change bool, ticker string) (*wire.MsgTx, []*utxo, error)

func (*BTCWallet) DelAddress

func (wallet *BTCWallet) DelAddress(address string) error

func (*BTCWallet) GenerateAddress

func (wallet *BTCWallet) GenerateAddress(channel uint32, addresstype uint32, AddressAlias string) (string, error)

func (*BTCWallet) GetAccountDetails

func (wallet *BTCWallet) GetAccountDetails() (*BTCAccountDetails, error)

func (*BTCWallet) GetAddress

func (wallet *BTCWallet) GetAddress(addressKey *hdkeychain.ExtendedKey, addresstype uint32) (string, error)

func (*BTCWallet) GetAddressBalance

func (wallet *BTCWallet) GetAddressBalance(address string) (*big.Float, *big.Float, error)

func (*BTCWallet) GetAddressOrdxAssets

func (wallet *BTCWallet) GetAddressOrdxAssets(adddress string) ([]*OrdxAssetsInfo, error)

func (*BTCWallet) GetChangeAddress

func (wallet *BTCWallet) GetChangeAddress(paymentAddresses []string) (string, error)

func (*BTCWallet) GetDefaultAddress

func (wallet *BTCWallet) GetDefaultAddress() (string, error)

func (*BTCWallet) GetLegacyAddress

func (wallet *BTCWallet) GetLegacyAddress(addressKey *hdkeychain.ExtendedKey) (string, error)

func (*BTCWallet) GetNativeSegwitAddress

func (wallet *BTCWallet) GetNativeSegwitAddress(addressKey *hdkeychain.ExtendedKey) (string, error)

func (*BTCWallet) GetNestedSegwitAddress

func (wallet *BTCWallet) GetNestedSegwitAddress(addressKey *hdkeychain.ExtendedKey) (string, error)

func (*BTCWallet) GetP2WSHAddress

func (wallet *BTCWallet) GetP2WSHAddress(addressKey *hdkeychain.ExtendedKey) (string, error)

func (*BTCWallet) GetTaprootAddress

func (wallet *BTCWallet) GetTaprootAddress(addressKey *hdkeychain.ExtendedKey) (string, error)

func (*BTCWallet) GetUtxo

func (wallet *BTCWallet) GetUtxo(outPoint wire.OutPoint, paymentAddresses []string) (*utxo, string, error)

func (*BTCWallet) GetWalletMnemonic

func (wallet *BTCWallet) GetWalletMnemonic() (string, error)

func (*BTCWallet) RefreshAccountDetails

func (wallet *BTCWallet) RefreshAccountDetails() (*BTCAccountDetails, error)

func (*BTCWallet) SetAddressAlias

func (wallet *BTCWallet) SetAddressAlias(address string, alias string) error

func (*BTCWallet) SetChangeAddress

func (wallet *BTCWallet) SetChangeAddress(changeAddress string) error

func (*BTCWallet) SetDefaultAddress

func (wallet *BTCWallet) SetDefaultAddress(defaultAddress string) error

func (*BTCWallet) Transaction

func (wallet *BTCWallet) Transaction(paymentAddress string, address string, amount *big.Float, fee uint32, ticker string) (string, error)

func (*BTCWallet) TransactionOrdx

func (wallet *BTCWallet) TransactionOrdx(paymentAddress string, address string, utxo string, fee uint32) (string, error)

func (*BTCWallet) UnanchorTransaction

func (wallet *BTCWallet) UnanchorTransaction(paymentAddress string, unanchorScript []byte, amount *big.Float, fee uint32) (string, error)

func (*BTCWallet) UpdateWalletInfo

func (wallet *BTCWallet) UpdateWalletInfo() error

type BTCWalletInfo

type BTCWalletInfo struct {
	Entropy           []byte            `protobuf:"bytes,1,opt,name=Entropy,proto3" json:"Entropy,omitempty"`
	ChangeAddress     string            `protobuf:"bytes,2,opt,name=ChangeAddress,proto3" json:"ChangeAddress,omitempty"`
	AddressInfoList   []*BTCAddressInfo `protobuf:"bytes,3,rep,name=AddressInfoList,proto3" json:"AddressInfoList,omitempty"`
	CurrentIndex      uint32            `protobuf:"varint,4,opt,name=CurrentIndex,proto3" json:"CurrentIndex,omitempty"`
	DefaultPayAddress string            `protobuf:"bytes,5,opt,name=DefaultPayAddress,proto3" json:"DefaultPayAddress,omitempty"`
}

func GetWalletInfo

func GetWalletInfo(walletName string) (*BTCWalletInfo, error)

type BTCWalletManager

type BTCWalletManager struct {
	BTCWalletList map[string]*BTCWallet
}
var (
	BtcWalletMgr *BTCWalletManager
	NetParams    *chaincfg.Params
)

func GetWalletInst

func GetWalletInst() *BTCWalletManager

func (*BTCWalletManager) AddBTCWallet

func (walletMgr *BTCWalletManager) AddBTCWallet(wallet *BTCWallet) error

func (*BTCWalletManager) DeleteWallet

func (walletMgr *BTCWalletManager) DeleteWallet(walletname string) error

func (*BTCWalletManager) GetAllBTCWallets

func (walletMgr *BTCWalletManager) GetAllBTCWallets() map[string]*BTCWallet

func (*BTCWalletManager) GetDefaultAddress

func (walletMgr *BTCWalletManager) GetDefaultAddress() (string, error)

func (*BTCWalletManager) GetDefaultWallet

func (walletMgr *BTCWalletManager) GetDefaultWallet() (*BTCWallet, error)

func (*BTCWalletManager) GetWallet

func (walletMgr *BTCWalletManager) GetWallet(walletName string) (*BTCWallet, error)

func (*BTCWalletManager) InitBTCWalletList

func (walletMgr *BTCWalletManager) InitBTCWalletList(workDir string) error

type OrdxAssets

type OrdxAssets struct {
	Ticker string
	// contains filtered or unexported fields
}

type OrdxAssetsInfo

type OrdxAssetsInfo struct {
	Ticker  string
	Balance int64
}

type WalletAccount

type WalletAccount struct {
	WalletName string `json:"WalletName"`
	Mnemonic   string `json:"Mnemonic"`
	PublicKey  []byte `json:"PublicKey"`
	PrivateKey []byte `json:"PrivateKey"`
	WalletInfo *BTCWalletInfo
}

type WalletAccountManager

type WalletAccountManager struct {
	DefaultWallet     string
	WalletCount       int              `json:"WalletCount"`
	WalletAccountList []*WalletAccount `json:"WalletAccountList"`
}

Jump to

Keyboard shortcuts

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