hypercash

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2019 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//币种
	Symbol    = "HC"
	MasterKey = "hypercash seed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BTCBlockScanner

type BTCBlockScanner struct {
	CurrentBlockHeight uint64 //当前区块高度

	IsScanMemPool        bool   //是否扫描交易池
	RescanLastBlockCount uint64 //重扫上N个区块数量
	// contains filtered or unexported fields
}

BTCBlockScanner bitcoin的区块链扫描器

func NewBTCBlockScanner

func NewBTCBlockScanner(wm *WalletManager) *BTCBlockScanner

NewBTCBlockScanner 创建区块链扫描器

func (*BTCBlockScanner) AddAddress

func (bs *BTCBlockScanner) AddAddress(address, accountID string, wallet *openwallet.Wallet)

AddAddress 添加订阅地址

func (*BTCBlockScanner) AddObserver

AddObserver 添加观测者

func (*BTCBlockScanner) AddWallet

func (bs *BTCBlockScanner) AddWallet(accountID string, wallet *openwallet.Wallet)

AddWallet 添加扫描钱包

func (*BTCBlockScanner) BatchExtractTransaction

func (bs *BTCBlockScanner) BatchExtractTransaction(blockHeight uint64, blockHash string, txs []string) error

BatchExtractTransaction 批量提取交易单 bitcoin 1M的区块链可以容纳3000笔交易,批量多线程处理,速度更快

func (*BTCBlockScanner) Clear

func (bs *BTCBlockScanner) Clear()

Clear 清理订阅扫描的内容

func (*BTCBlockScanner) DeleteRechargesByHeight

func (bs *BTCBlockScanner) DeleteRechargesByHeight(height uint64) error

DeleteRechargesByHeight 删除某区块高度的充值记录

func (*BTCBlockScanner) DropRechargeRecords

func (bs *BTCBlockScanner) DropRechargeRecords(accountID string) error

DropRechargeRecords 清楚钱包的全部充值记录

func (*BTCBlockScanner) ExtractTransaction

func (bs *BTCBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, txid string) ExtractResult

ExtractTransaction 提取交易单

func (*BTCBlockScanner) GetCurrentBlockHeader

func (bs *BTCBlockScanner) GetCurrentBlockHeader() (*openwallet.BlockHeader, error)

GetCurrentBlockHeader 获取当前区块高度

func (*BTCBlockScanner) GetWalletByAddress

func (bs *BTCBlockScanner) GetWalletByAddress(address string) (*openwallet.Wallet, bool)

GetWalletByAddress 获取地址对应的钱包

func (*BTCBlockScanner) IsExistAddress

func (bs *BTCBlockScanner) IsExistAddress(address string) bool

IsExistAddress 指定地址是否已登记扫描

func (*BTCBlockScanner) IsExistWallet

func (bs *BTCBlockScanner) IsExistWallet(accountID string) bool

IsExistWallet 指定账户的钱包是否已登记扫描

func (*BTCBlockScanner) Pause

func (bs *BTCBlockScanner) Pause()

Pause 暂停扫描

func (*BTCBlockScanner) RemoveObserver

func (bs *BTCBlockScanner) RemoveObserver(obj openwallet.BlockScanNotificationObject)

RemoveObserver 移除观测者

func (*BTCBlockScanner) RescanFailedRecord

func (bs *BTCBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*BTCBlockScanner) RescanUnconfirmRechargeRecord

func (bs *BTCBlockScanner) RescanUnconfirmRechargeRecord()

RescanUnconfirmRechargeRecord

func (*BTCBlockScanner) Restart

func (bs *BTCBlockScanner) Restart()

Restart 继续扫描

func (*BTCBlockScanner) Run

func (bs *BTCBlockScanner) Run()

Run 运行

func (*BTCBlockScanner) SaveRechargeToWalletDB

func (bs *BTCBlockScanner) SaveRechargeToWalletDB(height uint64, list []*openwallet.Recharge) error

SaveRechargeToWalletDB 保存交易单内的充值记录到钱包数据库

func (*BTCBlockScanner) SaveUnscanRecord

func (bs *BTCBlockScanner) SaveUnscanRecord(record *UnscanRecord) error

SaveTxToWalletDB 保存交易记录到钱包数据库

func (*BTCBlockScanner) ScanBlock

func (bs *BTCBlockScanner) ScanBlock(height uint64) error

ScanBlock 扫描指定高度区块

func (*BTCBlockScanner) ScanTxMemPool

func (bs *BTCBlockScanner) ScanTxMemPool()

ScanTxMemPool 扫描交易内存池

func (*BTCBlockScanner) SetRescanBlockHeight

func (bs *BTCBlockScanner) SetRescanBlockHeight(height uint64) error

SetRescanBlockHeight 重置区块链扫描高度

func (*BTCBlockScanner) Stop

func (bs *BTCBlockScanner) Stop()

Stop 停止扫描

type Block

type Block struct {
	Hash          string
	Confirmations uint64
	Merkleroot    string

	Previousblockhash string
	Height            uint64 `storm:"id"`
	Version           uint64
	Time              uint64
	Fork              bool
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(json *gjson.Result) *Block

func (*Block) BlockHeader

func (b *Block) BlockHeader() *openwallet.BlockHeader

BlockHeader 区块链头

type BlockchainInfo

type BlockchainInfo struct {
	Chain                string `json:"chain"`
	Blocks               uint64 `json:"blocks"`
	Headers              uint64 `json:"headers"`
	Bestblockhash        string `json:"bestblockhash"`
	Difficulty           string `json:"difficulty"`
	Mediantime           uint64 `json:"mediantime"`
	Verificationprogress string `json:"verificationprogress"`
	Chainwork            string `json:"chainwork"`
	Pruned               bool   `json:"pruned"`
}

BlockchainInfo 本地节点区块链信息

func NewBlockchainInfo

func NewBlockchainInfo(json *gjson.Result) *BlockchainInfo

type Client

type Client struct {
	BaseURL     string
	AccessToken string
	Debug       bool
	// contains filtered or unexported fields
}

A Client is a Bitcoin RPC client. It performs RPCs over HTTP using JSON request and responses. A Client must be configured with a secret token to authenticate with other Cores on the network.

func NewClient

func NewClient(url, token string, debug bool) *Client

func (*Client) Call

func (c *Client) Call(path string, request []interface{}) (*gjson.Result, error)

Call calls a remote procedure on another node, specified by the path.

type ExtractResult

type ExtractResult struct {
	Recharges   []*openwallet.Recharge
	TxID        string
	BlockHeight uint64
	Success     bool
	Reason      string
}

ExtractResult 扫描完成的提取结果

type FloatStr

type FloatStr string

func (FloatStr) MarshalJSON

func (n FloatStr) MarshalJSON() ([]byte, error)

type Response

type Response struct {
	Code    int         `json:"code,omitempty"`
	Error   interface{} `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Message string      `json:"message,omitempty"`
	Id      string      `json:"id,omitempty"`
}

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult 保存结果

type UnscanRecord

type UnscanRecord struct {
	ID          string `storm:"id"` // primary key
	BlockHeight uint64
	TxID        string
	Reason      string
	RescanCount int
}

UnscanRecords 扫描失败的区块及交易

func NewUnscanRecord

func NewUnscanRecord(height uint64, txID, reason string) *UnscanRecord

type Unspent

type Unspent struct {

	/*
			{
		        "txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a",
		        "vout" : 1,
		        "address" : "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe",
		        "account" : "test label",
		        "scriptPubKey" : "76a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac",
		        "amount" : 0.00010000,
		        "confirmations" : 6210,
		        "spendable" : true,
		        "solvable" : true
		    }
	*/
	Key           string `storm:"id"`
	TxID          string `json:"txid"`
	Vout          uint64 `json:"vout"`
	Address       string `json:"address"`
	AccountID     string `json:"account" storm:"index"`
	ScriptPubKey  string `json:"scriptPubKey"`
	Amount        string `json:"amount"`
	Confirmations uint64 `json:"confirmations"`
	Spendable     bool   `json:"spendable"`
	Solvable      bool   `json:"solvable"`
	HDAddress     openwallet.Address
}

Unspent 未花记录

func NewUnspent

func NewUnspent(json *gjson.Result) *Unspent

type UnspentSort

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

func (UnspentSort) Len

func (s UnspentSort) Len() int

func (UnspentSort) Less

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

func (UnspentSort) Swap

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

type User

type User struct {
	UserKey string `storm:"id"`     // primary key
	Group   string `storm:"index"`  // this field will be indexed
	Email   string `storm:"unique"` // this field will be indexed with a unique constraint
	Name    string // this field will not be indexed
	Age     int    `storm:"index"`
}

type WalletConfig

type WalletConfig struct {

	// 核心钱包是否只做监听
	CoreWalletWatchOnly bool
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *WalletConfig

type WalletManager

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

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) AddMerchantObserverForBlockScan

func (wm *WalletManager) AddMerchantObserverForBlockScan(obj openwallet.BlockScanNotificationObject, wallet *openwallet.Wallet) error

AddMerchantObserverForBlockScan 添加区块链观察者,当扫描出新区块时进行通知

func (*WalletManager) AddWalletInSummary

func (wm *WalletManager) AddWalletInSummary(wid string, wallet *openwallet.Wallet)

AddWalletInSummary 添加汇总钱包账户

func (*WalletManager) BackupWallet

func (wm *WalletManager) BackupWallet(walletID string) (string, error)

BackupWallet 备份数据

func (*WalletManager) BackupWalletFlow

func (wm *WalletManager) BackupWalletFlow() error

备份钱包流程

func (*WalletManager) BuildTransaction

func (wm *WalletManager) BuildTransaction(utxos []*Unspent, to []string, change string, amount []decimal.Decimal, fees decimal.Decimal) (string, decimal.Decimal, error)

BuildTransaction 构建交易单

func (*WalletManager) ConfigMerchantWallet

func (wm *WalletManager) ConfigMerchantWallet(wallet *openwallet.Wallet) error

ConfigMerchantWallet 钱包工具配置接口

func (*WalletManager) CreateAddressFlow

func (wm *WalletManager) CreateAddressFlow() error

创建地址流程

func (*WalletManager) CreateBatchAddress

func (wm *WalletManager) CreateBatchAddress(name, password string, count uint64) (string, []*openwallet.Address, error)

CreateBatchAddress 批量创建地址

func (*WalletManager) CreateMerchantAddress

func (wm *WalletManager) CreateMerchantAddress(wallet *openwallet.Wallet, account *openwallet.AssetsAccount, count uint64) ([]*openwallet.Address, error)

CreateMerchantAddress 创建钱包地址

func (*WalletManager) CreateMerchantAssetsAccount

func (wm *WalletManager) CreateMerchantAssetsAccount(wallet *openwallet.Wallet) (*openwallet.AssetsAccount, error)

func (*WalletManager) CreateMerchantWallet

func (wm *WalletManager) CreateMerchantWallet(wallet *openwallet.Wallet) error

CreateMerchantWallet 创建钱包

func (*WalletManager) CreateNewAddress

func (wm *WalletManager) CreateNewAddress(key *hdkeystore.HDKey) (*openwallet.Address, error)

CreateNewAddress 给指定账户创建地址

func (*WalletManager) CreateNewChangeAddress

func (wm *WalletManager) CreateNewChangeAddress(walletID string) (*openwallet.Address, error)

CreateNewAddress 给指定账户创建地址

func (*WalletManager) CreateNewWallet

func (wm *WalletManager) CreateNewWallet(name, password string) (*openwallet.Wallet, string, error)

CreateNewWallet 创建钱包

func (*WalletManager) CreateWalletFlow

func (wm *WalletManager) CreateWalletFlow() error

创建钱包流程

func (*WalletManager) DeleteUnscanRecord

func (wm *WalletManager) DeleteUnscanRecord(height uint64) error

DeleteUnscanRecord 删除指定高度的未扫记录

func (*WalletManager) DeleteUnscanRecordByTxID

func (wm *WalletManager) DeleteUnscanRecordByTxID(height uint64, txid string) error

DeleteUnscanRecordByTxID 删除未扫记录

func (*WalletManager) DeleteUnscanRecordNotFindTX

func (wm *WalletManager) DeleteUnscanRecordNotFindTX() error

DeleteUnscanRecordNotFindTX 删除未没有找到交易记录的重扫记录

func (*WalletManager) EncryptWallet

func (wm *WalletManager) EncryptWallet(password string) error

EncryptWallet 通过密码加密钱包,只在第一次加密码时才有效

func (*WalletManager) EstimateFee

func (wm *WalletManager) EstimateFee(inputs, outputs int64, feeRate decimal.Decimal) (decimal.Decimal, error)

EstimateFee 预估手续费

func (*WalletManager) EstimateFeeRate

func (wm *WalletManager) EstimateFeeRate() (decimal.Decimal, error)

EstimateFeeRate 预估的没KB手续费率

func (*WalletManager) GetAddressBalance

func (wm *WalletManager) GetAddressBalance(walletID, address string) string

GetAddressBalance 获取地址余额

func (*WalletManager) GetAddressesByAccount

func (wm *WalletManager) GetAddressesByAccount(walletID string) ([]string, error)

func (*WalletManager) GetAddressesFromLocalDB

func (wm *WalletManager) GetAddressesFromLocalDB(walletID string, watchOnly bool, offset, limit int) ([]*openwallet.Address, error)

GetAddressesFromLocalDB 从本地数据库

func (*WalletManager) GetBlock

func (wm *WalletManager) GetBlock(hash string) (*Block, error)

GetBlock 获取区块数据

func (*WalletManager) GetBlockChainInfo

func (wm *WalletManager) GetBlockChainInfo() (*BlockchainInfo, error)

GetBlockChainInfo 获取钱包区块链信息

func (*WalletManager) GetBlockHash

func (wm *WalletManager) GetBlockHash(height uint64) (string, error)

GetBlockHash 根据区块高度获得区块hash

func (*WalletManager) GetBlockHeight

func (wm *WalletManager) GetBlockHeight() (uint64, error)

GetBlockHeight 获取区块链高度

func (*WalletManager) GetBlockchainInfo

func (wm *WalletManager) GetBlockchainInfo() (*openwallet.Blockchain, error)

GetBlockchainInfo 获取区块链信息

func (*WalletManager) GetLocalBlock

func (wm *WalletManager) GetLocalBlock(height uint64) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*WalletManager) GetLocalNewBlock

func (wm *WalletManager) GetLocalNewBlock() (uint64, string)

GetLocalNewBlock 获取本地记录的区块高度和hash

func (*WalletManager) GetMerchantAddressBalance

func (wm *WalletManager) GetMerchantAddressBalance(walletID, address string) (string, error)

GetMerchantAssetsAccount 获取地址资产

func (*WalletManager) GetMerchantAddressList

func (wm *WalletManager) GetMerchantAddressList(wallet *openwallet.Wallet, account *openwallet.AssetsAccount, watchOnly bool, offset uint64, limit uint64) ([]*openwallet.Address, error)

GetMerchantAddressList 获取钱包地址

func (*WalletManager) GetMerchantAssetsAccountList

func (wm *WalletManager) GetMerchantAssetsAccountList(wallet *openwallet.Wallet) ([]*openwallet.AssetsAccount, error)

func (*WalletManager) GetMerchantWalletBalance

func (wm *WalletManager) GetMerchantWalletBalance(walletID string) (string, error)

GetMerchantAssetsAccount 获取账户资产

func (*WalletManager) GetMerchantWalletList

func (wm *WalletManager) GetMerchantWalletList() ([]*openwallet.Wallet, error)

GetMerchantWalletList 获取钱包列表

func (*WalletManager) GetTransaction

func (wm *WalletManager) GetTransaction(txid string) (*gjson.Result, error)

GetTransaction 获取交易单

func (*WalletManager) GetTxIDsInMemPool

func (wm *WalletManager) GetTxIDsInMemPool() ([]string, error)

GetTxIDsInMemPool 获取待处理的交易池中的交易单IDs

func (*WalletManager) GetUnscanRecords

func (wm *WalletManager) GetUnscanRecords() ([]*UnscanRecord, error)

获取未扫记录

func (*WalletManager) GetWalletBalance

func (wm *WalletManager) GetWalletBalance(accountID string) string

GetWalletBalance 获取钱包余额

func (*WalletManager) GetWalletInfo

func (wm *WalletManager) GetWalletInfo(walletID string) (*openwallet.Wallet, error)

GetWalletInfo 获取钱包列表

func (*WalletManager) GetWalletList

func (wm *WalletManager) GetWalletList() error

GetWalletList 获取钱包列表

func (*WalletManager) GetWallets

func (wm *WalletManager) GetWallets() ([]*openwallet.Wallet, error)

GetWallets 获取钱包列表

func (*WalletManager) ImportMerchantAddress

func (wm *WalletManager) ImportMerchantAddress(wallet *openwallet.Wallet, account *openwallet.AssetsAccount, addresses []*openwallet.Address) error

ImportMerchantAddress 导入地址

func (*WalletManager) ImportMulti

func (wm *WalletManager) ImportMulti(addresses []*openwallet.Address, keys []string, walletID string, watchOnly bool) ([]int, error)

ImportMulti 批量导入地址和私钥

func (*WalletManager) InitConfigFlow

func (wm *WalletManager) InitConfigFlow() error

初始化配置流程

func (*WalletManager) ListUnspent

func (wm *WalletManager) ListUnspent(min uint64) ([]*Unspent, error)

ListUnspent 获取未花记录

func (*WalletManager) ListUnspentFromLocalDB

func (wm *WalletManager) ListUnspentFromLocalDB(walletID string) ([]*Unspent, error)

ListUnspentFromLocalDB 查询本地数据库的未花记录

func (*WalletManager) LockWallet

func (wm *WalletManager) LockWallet() error

LockWallet 锁钱包

func (*WalletManager) MerchantRescanBlockHeight

func (wm *WalletManager) MerchantRescanBlockHeight(startHeight uint64, endHeight uint64) error

MerchantRescanBlockHeight 商户重置区块链扫描高度范围

func (*WalletManager) RebuildWalletUnspent

func (wm *WalletManager) RebuildWalletUnspent(walletID string) error

RebuildWalletUnspent 批量插入未花记录到本地

func (*WalletManager) RemoveMerchantObserverForBlockScan

func (wm *WalletManager) RemoveMerchantObserverForBlockScan(obj openwallet.BlockScanNotificationObject)

RemoveMerchantObserverForBlockScan 移除区块链扫描的观测者

func (*WalletManager) RescanCorewallet

func (wm *WalletManager) RescanCorewallet(beginheight uint64) error

RescanCorewallet 重扫钱包

func (*WalletManager) RestoreWallet

func (wm *WalletManager) RestoreWallet(keyFile, dbFile, datFile, password string) error

RestoreWallet 恢复钱包

func (*WalletManager) RestoreWalletFlow

func (wm *WalletManager) RestoreWalletFlow() error

RestoreWalletFlow 恢复钱包流程

func (*WalletManager) SaveLocalBlock

func (wm *WalletManager) SaveLocalBlock(block *Block)

SaveLocalBlock 记录本地新区块

func (*WalletManager) SaveLocalNewBlock

func (wm *WalletManager) SaveLocalNewBlock(blockHeight uint64, blockHash string)

SaveLocalNewBlock 记录区块高度和hash到本地

func (*WalletManager) SaveTransaction

func (wm *WalletManager) SaveTransaction(blockHeight uint64)

SaveTransaction 记录高度到本地

func (*WalletManager) SendBatchTransaction

func (wm *WalletManager) SendBatchTransaction(walletID string, to []string, amounts []decimal.Decimal, password string) (string, error)

SendBatchTransaction 发送批量交易

func (*WalletManager) SendRawTransaction

func (wm *WalletManager) SendRawTransaction(txHex string) (string, error)

SendRawTransaction 广播交易

func (*WalletManager) SendTransaction

func (wm *WalletManager) SendTransaction(walletID, to string, amount decimal.Decimal, password string, feesInSender bool) ([]string, error)

SendTransaction 发送交易

func (*WalletManager) SetConfigFlow

func (wm *WalletManager) SetConfigFlow(subCmd string) error

SetConfigFlow 初始化配置流程

func (*WalletManager) SetMerchantRescanBlockHeight

func (wm *WalletManager) SetMerchantRescanBlockHeight(height uint64) error

SetMerchantRescanBlockHeight 商户重置区块链扫描高度

func (*WalletManager) ShowConfig

func (wm *WalletManager) ShowConfig() error

查看配置信息

func (*WalletManager) ShowConfigInfo

func (wm *WalletManager) ShowConfigInfo(subCmd string) error

ShowConfigInfo 查看配置信息

func (*WalletManager) SignRawTransaction

func (wm *WalletManager) SignRawTransaction(txHex, walletID string, key *hdkeystore.HDKey, utxos []*Unspent) (string, error)

SignRawTransaction 钱包交易单

func (*WalletManager) SubmitTransactions

func (wm *WalletManager) SubmitTransactions(wallet *openwallet.Wallet, account *openwallet.AssetsAccount, withdraws []*openwallet.Withdraw, surplus string) (*openwallet.Transaction, error)

SubmitTransaction 提交转账申请

func (*WalletManager) SummaryFollow

func (wm *WalletManager) SummaryFollow() error

SummaryFollow 汇总流程

func (*WalletManager) SummaryWallets

func (wm *WalletManager) SummaryWallets()

SummaryWallets 执行汇总流程

func (*WalletManager) TransferFlow

func (wm *WalletManager) TransferFlow() error

SendTXFlow 发送交易

func (*WalletManager) UnlockWallet

func (wm *WalletManager) UnlockWallet(passphrase string, seconds int) error

UnlockWallet 解锁钱包

func (*WalletManager) WalletFileName

func (wm *WalletManager) WalletFileName(w *openwallet.Wallet) string

FileName 该钱包定义的文件名规则

Jump to

Keyboard shortcuts

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