cxcblock

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2019 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RPCServerCore     = 0 //RPC服务,核心钱包
	RPCServerExplorer = 1 //RPC服务,insight-API
)
View Source
const (
	//币种
	Symbol    = "CXC"
	CurveType = owcrypt.ECC_CURVE_SECP256K1
	Decimals  = int32(6)
)

Variables

View Source
var (
	MainNetAddressPrefix = cxcTransaction.BTCMainnetAddressPrefix
	TestNetAddressPrefix = cxcTransaction.BTCTestnetAddressPrefix
)

Functions

func BasicAuth

func BasicAuth(username, password string) string

See 2 (end of page 4) http://www.ietf.org/rfc/rfc2617.txt "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials." It is not meant to be urlencoded.

func DecodeScript

func DecodeScript(script string) ([]byte, error)

func NewAddressDecoder

func NewAddressDecoder(wm *WalletManager) *addressDecoder

NewAddressDecoder 地址解析器

Types

type Address added in v1.0.5

type Address struct {
	Address      string `json:"address"`
	Ismine       bool   `json:"ismine"`
	Iswatchonly  bool   `json:"iswatchonly"`
	Isscript     bool   `json:"isscript"`
	Synchronized bool   `json:"synchronized"`
}

type Assets added in v1.0.5

type Assets struct {
	Name     string          `json:"name"`
	Selltxid string          `json:"selltxid"`
	Assetref string          `json:"assetref"`
	Multiple uint64          `json:"multiple"`
	Unit     decimal.Decimal `json:"units"`
	Decimals int32
}

func NewAssets added in v1.0.5

func NewAssets(json gjson.Result) *Assets

type AssetsUnspent added in v1.1.0

type AssetsUnspent struct {
	Name     string `json:"name"`
	Assetref string `json:"assetref"`
	Qty      string `json:"qty"`
	Raw      string `json:"raw"`
	Type     string `json:"type"`
}

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 (*Block) BlockHeader

func (b *Block) BlockHeader(symbol string) *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 CXCBlockScanner

type CXCBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

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

CXCBlockScanner

func NewCXCBlockScanner

func NewCXCBlockScanner(wm *WalletManager) *CXCBlockScanner

NewCXCBlockScanner 创建区块链扫描器

func (*CXCBlockScanner) BatchExtractTransaction

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

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

func (*CXCBlockScanner) DeleteUnscanRecord added in v1.2.0

func (bs *CXCBlockScanner) DeleteUnscanRecord(height uint64) error

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

func (*CXCBlockScanner) DeleteUnscanRecordNotFindTX added in v1.2.0

func (bs *CXCBlockScanner) DeleteUnscanRecordNotFindTX() error

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

func (*CXCBlockScanner) ExtractTransaction

func (bs *CXCBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, txid string, scanTargetFunc openwallet.BlockScanTargetFunc) ExtractResult

ExtractTransaction 提取交易单

func (*CXCBlockScanner) ExtractTransactionData

func (bs *CXCBlockScanner) ExtractTransactionData(txid string, scanTargetFunc openwallet.BlockScanTargetFunc) (map[string][]*openwallet.TxExtractData, error)

func (*CXCBlockScanner) GetBalanceByAddress

func (bs *CXCBlockScanner) GetBalanceByAddress(address ...string) ([]*openwallet.Balance, error)

GetAssetsAccountBalanceByAddress 查询账户相关地址的交易记录

func (*CXCBlockScanner) GetCurrentBlockHeader

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

GetCurrentBlockHeader 获取当前区块高度

func (*CXCBlockScanner) GetGlobalMaxBlockHeight

func (bs *CXCBlockScanner) GetGlobalMaxBlockHeight() uint64

func (*CXCBlockScanner) GetLocalBlock added in v1.2.0

func (bs *CXCBlockScanner) GetLocalBlock(height uint64) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*CXCBlockScanner) GetLocalNewBlock added in v1.2.0

func (bs *CXCBlockScanner) GetLocalNewBlock() (uint64, string, error)

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

func (*CXCBlockScanner) GetScannedBlockHeader

func (bs *CXCBlockScanner) GetScannedBlockHeader() (*openwallet.BlockHeader, error)

GetScannedBlockHeader 获取当前扫描的区块头

func (*CXCBlockScanner) GetScannedBlockHeight

func (bs *CXCBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*CXCBlockScanner) GetUnscanRecords added in v1.2.0

func (bs *CXCBlockScanner) GetUnscanRecords() ([]*openwallet.UnscanRecord, error)

获取未扫记录

func (*CXCBlockScanner) RescanFailedRecord

func (bs *CXCBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*CXCBlockScanner) SaveLocalBlock added in v1.2.0

func (bs *CXCBlockScanner) SaveLocalBlock(block *Block) error

SaveLocalBlock 记录本地新区块

func (*CXCBlockScanner) SaveLocalNewBlock added in v1.2.0

func (bs *CXCBlockScanner) SaveLocalNewBlock(blockHeight uint64, blockHash string) error

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

func (*CXCBlockScanner) SaveUnscanRecord

func (bs *CXCBlockScanner) SaveUnscanRecord(record *openwallet.UnscanRecord) error

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

func (*CXCBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*CXCBlockScanner) ScanBlockTask

func (bs *CXCBlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*CXCBlockScanner) ScanTxMemPool

func (bs *CXCBlockScanner) ScanTxMemPool()

ScanTxMemPool 扫描交易内存池

func (*CXCBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*CXCBlockScanner) SupportBlockchainDAI added in v1.2.0

func (bs *CXCBlockScanner) SupportBlockchainDAI() bool

SupportBlockchainDAI 支持外部设置区块链数据访问接口 @optional

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 ClientInterface

type ClientInterface interface {
	Call(path string, request []interface{}) (*gjson.Result, error)
}

type ContractDecoder added in v1.0.5

type ContractDecoder struct {
	*openwallet.SmartContractDecoderBase
	// contains filtered or unexported fields
}

func NewContractDecoder added in v1.0.5

func NewContractDecoder(wm *WalletManager) *ContractDecoder

NewContractDecoder 智能合约解析器

func (*ContractDecoder) GetTokenBalanceByAddress added in v1.0.5

func (decoder *ContractDecoder) GetTokenBalanceByAddress(contract openwallet.SmartContract, address ...string) ([]*openwallet.TokenBalance, error)

type ExtractData added in v1.1.0

type ExtractData map[string]*openwallet.TxExtractData

type ExtractInput added in v1.1.0

type ExtractInput map[string][]*openwallet.TxInput

type ExtractOutput added in v1.1.0

type ExtractOutput map[string][]*openwallet.TxOutPut

type ExtractResult

type ExtractResult struct {

	//extractData     map[string]*openwallet.TxExtractData
	//extractOmniData map[string]*openwallet.TxExtractData //代币交易
	TxID        string
	BlockHeight uint64
	Success     bool
	// contains filtered or unexported fields
}

ExtractResult 扫描完成的提取结果

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 Transaction

type Transaction struct {
	TxID          string
	Size          uint64
	Version       uint64
	LockTime      int64
	Hex           string
	BlockHash     string
	BlockHeight   uint64
	Confirmations uint64
	Blocktime     int64
	IsCoinBase    bool
	Fees          string
	Decimals      int32

	Vins  []*Vin
	Vouts []*Vout
}

type TransactionDecoder

type TransactionDecoder struct {
	openwallet.TransactionDecoderBase
	// contains filtered or unexported fields
}

func NewTransactionDecoder

func NewTransactionDecoder(wm *WalletManager) *TransactionDecoder

NewTransactionDecoder 交易单解析器

func (*TransactionDecoder) CreateBTCSummaryRawTransaction

func (decoder *TransactionDecoder) CreateBTCSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateBTCSummaryRawTransaction 创建BTC汇总交易

func (*TransactionDecoder) CreateCXCRawTransaction added in v1.1.0

func (decoder *TransactionDecoder) CreateCXCRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateRawTransaction 创建交易单

func (*TransactionDecoder) CreateRawTransaction

func (decoder *TransactionDecoder) CreateRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateRawTransaction 创建交易单

func (*TransactionDecoder) CreateSummaryRawTransaction

func (decoder *TransactionDecoder) CreateSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransaction, error)

CreateSummaryRawTransaction 创建汇总交易,返回原始交易单数组

func (*TransactionDecoder) CreateSummaryRawTransactionWithError

func (decoder *TransactionDecoder) CreateSummaryRawTransactionWithError(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateSummaryRawTransactionWithError 创建汇总交易,返回能原始交易单数组(包含带错误的原始交易单)

func (*TransactionDecoder) CreateTokenRawTransaction added in v1.0.5

func (decoder *TransactionDecoder) CreateTokenRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateTokenRawTransaction 创建Token交易单

func (*TransactionDecoder) CreateTokenSummaryRawTransaction added in v1.1.0

func (decoder *TransactionDecoder) CreateTokenSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateTokenSummaryRawTransaction 创建Token汇总交易

func (*TransactionDecoder) GetRawTransactionFeeRate

func (decoder *TransactionDecoder) GetRawTransactionFeeRate() (feeRate string, unit string, err error)

GetRawTransactionFeeRate 获取交易单的费率

func (*TransactionDecoder) SignCXCRawTransaction added in v1.1.0

func (decoder *TransactionDecoder) SignCXCRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

SignRawTransaction 签名交易单

func (*TransactionDecoder) SignRawTransaction

func (decoder *TransactionDecoder) SignRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

SignRawTransaction 签名交易单

func (*TransactionDecoder) SubmitRawTransaction

func (decoder *TransactionDecoder) SubmitRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) (*openwallet.Transaction, error)

SendRawTransaction 广播交易单

func (*TransactionDecoder) VerifyCXCRawTransaction added in v1.1.0

func (decoder *TransactionDecoder) VerifyCXCRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单

func (*TransactionDecoder) VerifyRawTransaction

func (decoder *TransactionDecoder) VerifyRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单

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
	Assets        []*AssetsUnspent `json:"assets"`
}

Unspent 未花记录

func NewUnspent

func NewUnspent(json *gjson.Result) *Unspent

type UnspentSort

type UnspentSort struct {
	Values     []*Unspent
	Comparator func(a, b *Unspent) int
}

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 Vin

type Vin struct {
	Coinbase string
	TxID     string
	Vout     uint64
	N        uint64
	Addr     string
	Value    string
	Assets   []*AssetsUnspent
	IsToken  bool
}

type Vout

type Vout struct {
	N            uint64
	Addr         string
	Value        string
	ScriptPubKey string
	Type         string
	Assets       []*AssetsUnspent
	IsToken      bool
}

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol    string
	MasterKey string

	//RPC认证账户名
	RpcUser string
	//RPC认证账户密码
	RpcPassword string
	//证书目录
	CertsDir string

	//rpc证书
	CertFileName string
	//区块链数据文件
	BlockchainFile string
	//是否测试网络
	IsTestNet bool
	// 核心钱包是否只做监听
	CoreWalletWatchOnly bool
	//最大的输入数量
	MaxTxInputs int
	//本地数据库文件路径
	DBPath string

	//钱包服务API
	ServerAPI string
	//钱包安装的路径
	NodeInstallPath string
	//钱包数据文件目录
	WalletDataPath string
	//汇总阀值
	Threshold decimal.Decimal
	//汇总地址
	SumAddress string
	//汇总执行间隔时间
	CycleSeconds time.Duration
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//核心钱包密码,配置有值用于自动解锁钱包
	WalletPassword string
	//后台数据源类型
	RPCServerType int
	//s是否支持隔离验证
	SupportSegWit bool
	//Omni代币转账最低成本
	OmniTransferCost string
	//OmniCore API
	OmniCoreAPI string
	//Omni rpc user
	OmniRPCUser string
	//Omni rpc password
	OmniRPCPassword string
	//是否支持omni
	OmniSupport bool
	//主网地址前缀
	MainNetAddressPrefix cxcTransaction.AddressPrefix
	//测试网地址前缀
	TestNetAddressPrefix cxcTransaction.AddressPrefix
	//小数位精度
	Decimals int32
	//最低手续费
	MinFees decimal.Decimal
	//数据目录
	DataDir string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(symbol string, curveType uint32, decimals int32) *WalletConfig

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase

	Storage         *hdkeystore.HDKeystore        //秘钥存取
	WalletClient    *Client                       // 节点客户端
	Config          *WalletConfig                 //钱包管理配置
	Decoder         openwallet.AddressDecoder     //地址编码器
	TxDecoder       openwallet.TransactionDecoder //交易单编码器
	Log             *log.OWLogger                 //日志工具
	Blockscanner    *CXCBlockScanner              //区块扫描器
	ContractDecoder *ContractDecoder              //智能合约解析器
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) Addnewaddr added in v1.0.5

func (wm *WalletManager) Addnewaddr() (*gjson.Result, error)

func (*WalletManager) CurveType

func (wm *WalletManager) CurveType() uint32

CurveType 曲线类型

func (*WalletManager) Decimal

func (wm *WalletManager) Decimal() int32

小数位精度

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

func (wm *WalletManager) FullName() string

FullName 币种全名

func (*WalletManager) GetAddressDecode

func (wm *WalletManager) GetAddressDecode() openwallet.AddressDecoder

AddressDecode 地址解析器

func (*WalletManager) GetAssetsBalance added in v1.0.5

func (wm *WalletManager) GetAssetsBalance(propertyId, address string) (decimal.Decimal, error)

func (*WalletManager) GetAssetsLogger

func (wm *WalletManager) GetAssetsLogger() *log.OWLogger

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlock

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

GetBlock 获取区块数据

func (*WalletManager) GetBlockByHeight

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

GetBlockByHeight 获取区块数据

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

func (wm *WalletManager) GetBlockScanner() openwallet.BlockScanner

GetBlockScanner 获取区块链

func (*WalletManager) GetSmartContractDecoder added in v1.0.5

func (wm *WalletManager) GetSmartContractDecoder() openwallet.SmartContractDecoder

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetTransaction

func (wm *WalletManager) GetTransaction(txid string) (*Transaction, error)

GetTransaction 获取交易单

func (*WalletManager) GetTransactionDecoder

func (wm *WalletManager) GetTransactionDecoder() openwallet.TransactionDecoder

TransactionDecoder 交易单解析器

func (*WalletManager) GetTxIDsInMemPool

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

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

func (*WalletManager) GetTxOut

func (wm *WalletManager) GetTxOut(txid string, vout uint64) (*Vout, error)

GetTxOut 获取交易单输出信息,用于追溯交易单输入源头

func (*WalletManager) ImportAddress

func (wm *WalletManager) ImportAddress(address, account string) error

ImportAddress 导入地址核心钱包

func (*WalletManager) InitAssetsConfig

func (wm *WalletManager) InitAssetsConfig() (config.Configer, error)

InitAssetsConfig 初始化默认配置

func (*WalletManager) ListUnspent

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

ListUnspent 获取未花记录

func (*WalletManager) LoadAssetsConfig

func (wm *WalletManager) LoadAssetsConfig(c config.Configer) error

LoadAssetsConfig 加载外部配置

func (*WalletManager) NewBlock

func (wm *WalletManager) NewBlock(json *gjson.Result) *Block

func (*WalletManager) SendRawTransaction

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

SendRawTransaction 广播交易

func (*WalletManager) ShowAssets added in v1.0.5

func (wm *WalletManager) ShowAssets(propertyId string) (*Assets, error)

GetOmniProperty 获取Omni资产信息

func (*WalletManager) Showaddrs added in v1.0.5

func (wm *WalletManager) Showaddrs() ([]*Address, error)

func (*WalletManager) Showchain added in v1.0.5

func (wm *WalletManager) Showchain() (*gjson.Result, error)

func (*WalletManager) Shownet

func (wm *WalletManager) Shownet() (*gjson.Result, error)

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

Jump to

Keyboard shortcuts

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