bopo

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Symbol    = "BOPO" //币种
	MasterKey = "BopoPlat"
)

Variables

This section is empty.

Functions

func FilePathWalkDir

func FilePathWalkDir(root string) ([]string, error)

func GenBlockHash

func GenBlockHash(blockData []byte) (hash string, err error)

Types

type Block

type Block struct {
	/*
		{
		'consensusMetadata': 'CAI=',
		'nonHashData': {'chaincodeEvents': [{}],
		                'localLedgerCommitTimestamp': {'nanos': 94090909,
		                                               'seconds': 1518419369}},
		'previousBlockHash': '+SuQi13GO8bGYik2SQOIeRcRCiH21NUVH7uSRtMTtq/td0EaKTw/jTQdPvICWq2Gn+klrJ2Hs0DqRYukPVUyow==',
		'stateHash': 'ZUVvUvCScFUAWRk3E3gwIWnsOaFNDUXT2C4x6Wl3GTMsnWTk1gaFny4G582NTpzqWGR755zCQ5kDA8YyMl3R2w==',
		'transactions': [{'cert': 'MIICtDCCAlugAwIBAgIRAPn/PTSQLUT/gj6C34hBopQwCgYIKoZIzj0EAwMwMzELMAkGA1UEBhMCQ04xFjAUBgNVBAoTDUdhbWVwYWkgRnVuZC4xDDAKBgNVBAMTA3RjYTAeFw0xODAyMTIwNzA2MDhaFw0xODA1MTMwNzA2MDhaMEcxCzAJBgNVBAYTAkNOMRYwFAYDVQQKEw1HYW1lcGFpIEZ1bmQuMSAwHgYDVQQDExdUcmFuc2FjdGlvbiBDZXJ0aWZpY2F0ZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABPTKMJHudYvdS4B08CEwWTEF8Ll4SUjq93mq4x+8R2bMrdXGHwC6h85r4cwwcyNLJjEYYgqa9VanrQ/Kn9usCpijggE6MIIBNjAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADANBgNVHQ4EBgQEAQIDBDAPBgNVHSMECDAGgAQBAgMEMBIGBioDBAUGCgQIRGVsZWdhdGUwEwYGKgMEBQYLBAlBbGlFQ1NIQjEwTQYGKgMEBQYHAQH/BEBduQTYRCWuHIAIZoMgUMl90wPUkGP5bSF4MQTz/XNxsaYZ/Gsi5b1P2zOHJJNA8IQzw/TKwF11yXToaKm/oOImMEoGBioDBAUGCARA4nZ1FCdDLT8w2vnhPClfkIk13XCFBir60qDE3Ic//AMoHt8IFwmndtOaDIzPrPCKajDlt7OsTertkTO9dLQPBjAyBgYqAwQFBgkEKDAwSEVBRFBhaUFkbWluUm9sZS0+MSNQYWlBZG1pblJlZ2lvbi0+MiMwCgYIKoZIzj0EAwMDRwAwRAIgCkc8m2RBcl9dYbmyrdyceb5g51yGuRySD9cM+4Cc5s0CIEdR6HhgnM8RODTFUo4GGjY6/xk285MihBgL83Mtv1Lx',
		                  'chaincodeID': 'Eg9nYW1lcGFpY29yZV92MDE=',
		                  'nonce': '67ba1CKLYHSfQQ0KASPt4GV5j6YtmRQJ',
		                  'payload': 'CtsCCAESERIPZ2FtZXBhaWNvcmVfdjAxGqUCChFVU0VSX1JFR1BVQkxJQ0tFWQpIQ2lJMVdFWlZOVjlHZWtSVGFFRnplR0Z6TVZSNlVXMW5NV3hvVVROeVJUUlFXVnBuRWhEUkEwL3VWaUE2K0gxdXErZDZOblQ5CmRDa2dJQVJKRUNpQlZnR3o3d2NqTHNIbHpSdGhRREVOcWo0NUtsQUJBTTJSTHA4bm4raHUrN2hJZzB5U0pYVDdtdTJ4elFQa0wrQkwwN3pjTDdEQ2VQWDlpUjFVVDR0eStLZnc9CmBDa1FLSUJobGF3bzlnSWlFUXpzYXVjcXNYK3ZyM2ptdUl2VkpPcVgzcEg4TE5tUDVFaUNnUVBDaVNDeHpRdVRKNnJod3dqazRYNlFqWHFXQ1F6YWdydktzTk96bFJnPT1CDFBhaUFkbWluUm9sZUIOUGFpQWRtaW5SZWdpb24=',
		                  'signature': 'MEQCIHvGzTPfWbNLL0Ad+AbNY9/WTsgDNxzHeaUWw0BPFx8NAiB+QBfB6HXOQ+pJyX1bDpbJXX+qV2KZ1c1cIuYl+W99Ug==',
		                  'timestamp': {'nanos': 67157084,
		                                'seconds': 1518419357},
		                  'txid': 'effe5d08-346b-4689-b105-dfdcbdfe790f',
		                  'type': 2}]
		}
	*/
	Hash              string
	Previousblockhash string     `json:"previousBlockHash,omitempty"`
	Statehash         string     `json:"stateHash,omitempty"`
	Transactions      []*BlockTX `json:"transactions,omitempty"`
	Height            uint64     `storm:"id"`
}

Block Fabric区块结构

type BlockTX

type BlockTX struct {
	Cert        string `json:"cert,omitempty"`
	ChaincodeID string `json:"chaincodeID,omitempty"`
	Nonce       string `json:"nonce,omitempty"`
	Payload     []byte `json:"payload"`
	Signature   string `json:"signature,omitempty"`
	Timestrap   struct {
		// contains filtered or unexported fields
	}
	Txid string `json:"txid,omitempty"`
	Type string `json:"type,omitempty"`
}

BlockTX 区块交易记录 Struct

type BlockTxPayload

type BlockTxPayload struct {
	From    string `json:"from,omitempty"`
	To      string `json:"to,omitempty"`
	Comment string `json:"comment,omitempty"`
	Amount  uint64 `json:"amount,omitempty"`
}

PayloadSpec 每笔交易的具体数据

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 本地节点区块链信息

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 string, debug bool) *Client

func (*Client) Call

func (c *Client) Call(path, method string, request interface{}) ([]byte, error)

type ExtractResult

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

ExtractResult 扫描完成的提取结果

type FabricBlockScanner

type FabricBlockScanner struct {
	CurrentBlockHeight uint64 //当前区块高度
	// contains filtered or unexported fields
}

FabricBlockScanner bitcoin的区块链扫描器

func NewFabricBlockScanner

func NewFabricBlockScanner(wm *WalletManager) *FabricBlockScanner

NewFabricBlockScanner 创建区块链扫描器

func (*FabricBlockScanner) AddAddress

func (bs *FabricBlockScanner) AddAddress(address, accountID string, wallet *openwallet.Wallet)
Implements to Interface "openwallet.BlockScanner"

Prepare for Scanner:
	//AddAddress 添加扫描地址,账户ID,其钱包指针
	AddAddress(address, accountID string, wallet *Wallet)

	//AddWallet 添加扫描账户及其钱包指针
	AddWallet(accountID string, wallet *Wallet)

	//AddObserver 添加观测者
	AddObserver(obj BlockScanNotificationObject)

	//RemoveObserver 移除观测者
	RemoveObserver(obj BlockScanNotificationObject)

	//Clear 清理订阅扫描的内容
	Clear()

AddAddress 增加预期扫描的地址

func (*FabricBlockScanner) AddObserver

AddObserver 添加观测者

func (*FabricBlockScanner) AddWallet

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

AddWallet 添加扫描钱包

func (*FabricBlockScanner) BatchExtractTransaction

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

---------------------------------------------------------------------- BatchExtractTransaction 批量提取交易单 Fabric block can be set any size to include Txs, and that default value is less than 20 about BOPO net.

func (*FabricBlockScanner) Clear

func (bs *FabricBlockScanner) Clear()

Clear 清理订阅扫描的内容

func (*FabricBlockScanner) DeleteRechargesByHeight

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

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

func (*FabricBlockScanner) DeleteUnscanRecord

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

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

func (*FabricBlockScanner) DeleteUnscanRecordByTxID

func (bs *FabricBlockScanner) DeleteUnscanRecordByTxID(height uint64, txid string) error

DeleteUnscanRecordByTxID 通过 TxID 删除未扫记录

func (*FabricBlockScanner) DeleteUnscanRecordNotFindTX

func (bs *FabricBlockScanner) DeleteUnscanRecordNotFindTX() error

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

func (*FabricBlockScanner) ExtractTransaction

func (bs *FabricBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, mTx *BlockTX) ExtractResult

ExtractTransaction 提取交易单

func (*FabricBlockScanner) GetCurrentBlockHeader

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

GetCurrentBlockHeader 获取当前区块高度

func (*FabricBlockScanner) GetLocalBlock

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

GetLocalBlock 获取本地区块数据

func (*FabricBlockScanner) GetLocalNewBlock

func (bs *FabricBlockScanner) GetLocalNewBlock() (uint64, string)

GetLocalNewBlock 获取本地区块高度和hash

func (*FabricBlockScanner) GetUnscanRecords

func (bs *FabricBlockScanner) GetUnscanRecords() ([]*UnscanRecord, error)

GetUnsacnRecords 获取未扫记录

func (*FabricBlockScanner) GetWalletByAddress

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

GetWalletByAddress 获取地址对应的钱包

func (*FabricBlockScanner) IsExistAddress

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

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

func (*FabricBlockScanner) IsExistWallet

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

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

func (*FabricBlockScanner) Pause

func (bs *FabricBlockScanner) Pause()

Pause 暂停扫描

func (*FabricBlockScanner) RemoveObserver

RemoveObserver 移除观测者

func (*FabricBlockScanner) RescanFailedRecord

func (bs *FabricBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*FabricBlockScanner) Restart

func (bs *FabricBlockScanner) Restart()

Restart 继续扫描

func (*FabricBlockScanner) Run

func (bs *FabricBlockScanner) Run()
Implements to Interface "openwallet.BlockScanner"

Actions of Scanner's operations:
	Run()		//Run 运行
	Stop()		//Stop 停止扫描
	Pause()		//Pause 暂停扫描
	Restart()	//Restart 继续扫描

	//ScanBlock 扫描指定高度的区块
	ScanBlock(height uint64) error

	//rescanFailedRecord 重扫失败记录
	RescanFailedRecord()

Run 运行

func (*FabricBlockScanner) SaveLocalBlock

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

---------------------------------------------------------------------------- SaveLocalBlock 记录本地新区块

func (*FabricBlockScanner) SaveLocalNewBlock

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

SaveLocalNewBlock 写入本地区块高度和hash

func (*FabricBlockScanner) SaveRechargeToWalletDB

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

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

func (*FabricBlockScanner) SaveTransaction

func (bs *FabricBlockScanner) SaveTransaction(blockHeight uint64) error

SaveTransaction 记录高度到本地

func (*FabricBlockScanner) SaveUnscanRecord

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

---------------------------------------------------------------------------- SaveUnscanRecord 保存未扫描交易记录

func (*FabricBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*FabricBlockScanner) SetRescanBlockHeight

func (bs *FabricBlockScanner) SetRescanBlockHeight(height uint64) error
Implements to Interface "openwallet.BlockScanner"

Extra methods to make more controls:
	//SetRescanBlockHeight 重置区块链扫描高度
	SetRescanBlockHeight(height uint64) error

	//GetCurrentBlockHeight 获取当前区块高度
	GetCurrentBlockHeader() (*BlockHeader, error)

	//IsExistAddress 指定地址是否已登记扫描
	IsExistAddress(address string) bool

	//IsExistWallet 指定账户的钱包是否已登记扫描
	IsExistWallet(accountID string) bool

SetRescanBlockHeight 重置区块链扫描高度

func (*FabricBlockScanner) Stop

func (bs *FabricBlockScanner) Stop()

Stop 停止扫描

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"`
}

A struct of Response for BOPO RESTful response

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 Wallet

type Wallet struct {
	WalletID string `json:"rootid"`
	Addr     string `json:"addr"`
	Balance  string `json:"balance"`
	Alias    string `json:"alias"`
	Password string `json:"password"`
	RootPub  string `json:"rootpub"`
	KeyFile  string
}

Wallet 钱包模型

type WalletConfig

type WalletConfig struct {

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

Node setup 节点配置

func NewWalletConfig

func NewWalletConfig() *WalletConfig

type WalletManager

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

func (*WalletManager) AddWalletInSummary

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

AddWalletInSummary 添加汇总钱包账户

func (*WalletManager) BackupWalletFlow

func (w *WalletManager) BackupWalletFlow() error

func (*WalletManager) CreateAddressFlow

func (w *WalletManager) CreateAddressFlow() error

func (*WalletManager) CreateWalletFlow

func (w *WalletManager) CreateWalletFlow() error

func (*WalletManager) GetBlockChainInfo

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

GetBlockChainInfo 获取钱包区块链信息

Return:

&{Chain: Blocks:377379 Headers:0 Bestblockhash: Difficulty: Mediantime:0 Verificationprogress: Chainwork: Pruned:false}

func (*WalletManager) GetBlockContent

func (wm *WalletManager) GetBlockContent(height uint64) (block *Block, err error)

GetBlockContent 获取钱包区块链内容

func (*WalletManager) GetBlockHash

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

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

func (*WalletManager) GetBlockHeight

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

GetBlockHeight 获取区块链高度

func (*WalletManager) GetBlockPayload

func (wm *WalletManager) GetBlockPayload(payload string) (payloadSpec *BlockTxPayload, err error)

GetBlockTxPayload 获取区块中交易详情

func (*WalletManager) GetTransaction

func (wm *WalletManager) GetTransaction(txid string) (txr *BlockTX, err error)

Get detail of a transzation

func (*WalletManager) GetWalletList

func (w *WalletManager) GetWalletList() error

func (*WalletManager) InitConfigFlow

func (w *WalletManager) InitConfigFlow() error

func (*WalletManager) RestoreWalletFlow

func (w *WalletManager) RestoreWalletFlow() error

func (*WalletManager) ShowConfig

func (w *WalletManager) ShowConfig() error

func (*WalletManager) SummaryFollow

func (w *WalletManager) SummaryFollow() error

func (*WalletManager) SummaryWallets

func (wm *WalletManager) SummaryWallets()

SummaryWallets 执行汇总流程

func (*WalletManager) TransferFlow

func (w *WalletManager) TransferFlow() error

Jump to

Keyboard shortcuts

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