openw

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: GPL-3.0 Imports: 22 Imported by: 77

README

openw

openw包实现了一个单机版的钱包管理模型。目前用于给实现AssetsAapter协议的区块链资产适配器做功能测试。 后续会做一个可视化的钱包管理系统,专门用于区块链资产适配器的测试。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PeriodOfTask = 5 * time.Second
)

Functions

func GetAssets

func GetAssets(symbol string) interface{}

GetAssets 根据币种类型获取已注册的管理者

func GetAssetsAdapter

func GetAssetsAdapter(symbol string) (openwallet.AssetsAdapter, error)

GetAssetsAdapter 获取资产控制器

func GetSymbolInfo

func GetSymbolInfo(symbol string) (openwallet.SymbolInfo, error)

GetSymbolInfo 获取资产的币种信息

func RegAssets

func RegAssets(name string, manager interface{}, config ...config.Configer)

RegAssets 注册资产 @param name 资产别名 @param manager 资产适配器或管理器 @param config 加载配置 资产适配器实现了openwallet.AssetsConfig,可以传入配置接口完成预加载配置 usage: RegAssets(cardano.Symbol, &cardano.WalletManager{}, c) RegAssets(bytom.Symbol, &bytom.WalletManager{}, c)

Types

type AppID added in v1.3.0

type AppID string

type AppWrapper added in v1.3.0

type AppWrapper struct {
	*Wrapper
	// contains filtered or unexported fields
}

AppWrapper 应用装器,扩展应用功能

func NewAppWrapper added in v1.3.0

func NewAppWrapper(args ...interface{}) *AppWrapper

func (*AppWrapper) GetWalletInfo added in v1.3.0

func (wrapper *AppWrapper) GetWalletInfo(walletID string) (*openwallet.Wallet, error)

GetWalletInfo

func (*AppWrapper) GetWalletList added in v1.3.0

func (wrapper *AppWrapper) GetWalletList(offset, limit int) ([]*openwallet.Wallet, error)

GetWalletList

type Config

type Config struct {
	KeyDir          string   //钥匙备份路径
	DBPath          string   //本地数据库文件路径
	BackupDir       string   //备份路径
	SupportAssets   []string //支持的资产类型
	EnableBlockScan bool
	ConfigDir       string
}

func NewConfig

func NewConfig() *Config

type NotificationObject

type NotificationObject interface {

	//BlockScanNotify 新区块扫描完成通知
	BlockScanNotify(header *openwallet.BlockHeader) error

	//BlockTxExtractDataNotify 区块提取结果通知
	BlockTxExtractDataNotify(account *openwallet.AssetsAccount, data *openwallet.TxExtractData) error
}

type StormDB added in v1.3.0

type StormDB struct {
	*storm.DB
	FileName string
	Opened   bool
}

func OpenStormDB added in v1.3.0

func OpenStormDB(filename string, stormOptions ...func(*storm.Options) error) (*StormDB, error)

OpenStormDB

func (*StormDB) Close added in v1.3.0

func (db *StormDB) Close() error

Close closes the database.

type TransactionWrapper added in v1.3.0

type TransactionWrapper struct {
	*WalletWrapper
}

TransactionWrapper 交易包装器,扩展钱包交易单相关功能

func NewTransactionWrapper added in v1.3.0

func NewTransactionWrapper(args ...interface{}) *TransactionWrapper

func (*TransactionWrapper) DeleteBlockDataByHeight added in v1.3.0

func (wrapper *TransactionWrapper) DeleteBlockDataByHeight(height uint64) error

DeleteBlockDataByHeight 删除钱包中指定区块高度相关的交易记录

func (*TransactionWrapper) SaveBlockExtractData added in v1.3.0

func (wrapper *TransactionWrapper) SaveBlockExtractData(accountID string, data *openwallet.TxExtractData) error

SaveBlockExtractData 保存区块提取数据

type WalletDBFile added in v1.3.0

type WalletDBFile WrapperSourceFile

type WalletKeyFile added in v1.3.0

type WalletKeyFile string

type WalletManager

type WalletManager struct {
	AddressInScanning map[string]string //加入扫描的地址
	// contains filtered or unexported fields
}

WalletManager OpenWallet钱包管理器

func NewWalletManager

func NewWalletManager(config *Config) *WalletManager

NewWalletManager

func (*WalletManager) AddAddressForBlockScan

func (wm *WalletManager) AddAddressForBlockScan(address, sourceKey string) error

AddAddressForBlockScan 添加订阅地址

func (*WalletManager) AddObserver

func (wm *WalletManager) AddObserver(obj NotificationObject)

AddObserver 添加观测者

func (*WalletManager) BlockExtractDataNotify

func (wm *WalletManager) BlockExtractDataNotify(sourceKey string, data *openwallet.TxExtractData) error

BlockExtractDataNotify 区块提取结果通知

func (*WalletManager) BlockScanNotify

func (wm *WalletManager) BlockScanNotify(header *openwallet.BlockHeader) error

blockScanNotify 区块扫描结果通知

func (*WalletManager) ClearAddressForBlockScan

func (wm *WalletManager) ClearAddressForBlockScan() error

ClearAddressForBlockScan 清理订阅扫描的内容

func (*WalletManager) CloseDB

func (wm *WalletManager) CloseDB(appID string) error

CloseDB 关闭应用数据库文件

func (*WalletManager) CreateAddress

func (wm *WalletManager) CreateAddress(appID, walletID string, accountID string, count uint64) ([]*openwallet.Address, error)

CreateAddress

func (*WalletManager) CreateAssetsAccount

func (wm *WalletManager) CreateAssetsAccount(appID, walletID, password string, account *openwallet.AssetsAccount, otherOwnerKeys []string) (*openwallet.AssetsAccount, *openwallet.Address, error)

CreateAssetsAccount

func (*WalletManager) CreateErc20TokenTransaction

func (wm *WalletManager) CreateErc20TokenTransaction(appID, walletID, accountID, amount, address, feeRate, memo,
	contractAddr, tokenName, tokenSymbol string, tokenDecimal uint64) (*openwallet.RawTransaction, error)

func (*WalletManager) CreateQrc20TokenTransaction

func (wm *WalletManager) CreateQrc20TokenTransaction(appID, walletID, accountID, sendAmount, toAddress, feeRate, memo,
	contractAddr, tokenName, tokenSymbol string, tokenDecimal uint64) (*openwallet.RawTransaction, error)

func (*WalletManager) CreateSummaryRawTransactionWithError added in v1.4.1

func (wm *WalletManager) CreateSummaryRawTransactionWithError(
	appID, walletID, accountID, summaryAddress, minTransfer, retainedBalance, feeRate string,
	start, limit int,
	contract *openwallet.SmartContract,
	feeSupportAccount *openwallet.FeesSupportAccount,
) ([]*openwallet.RawTransactionWithError, error)

CreateSummaryTransaction

func (*WalletManager) CreateSummaryTransaction

func (wm *WalletManager) CreateSummaryTransaction(
	appID, walletID, accountID, summaryAddress, minTransfer, retainedBalance, feeRate string,
	start, limit int,
	contract *openwallet.SmartContract) ([]*openwallet.RawTransaction, error)

CreateSummaryTransaction

func (*WalletManager) CreateTransaction

func (wm *WalletManager) CreateTransaction(appID, walletID, accountID, amount, address, feeRate, memo string, contract *openwallet.SmartContract) (*openwallet.RawTransaction, error)

CreateTransaction

func (*WalletManager) CreateWallet

func (wm *WalletManager) CreateWallet(appID string, wallet *openwallet.Wallet) (*openwallet.Wallet, *hdkeystore.HDKey, error)

CreateWallet 创建钱包

func (*WalletManager) DBFile

func (wm *WalletManager) DBFile(appID string) string

DBFile 应用数据库文件

func (*WalletManager) DeleteRechargesByHeight

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

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

func (*WalletManager) GetAddress

func (wm *WalletManager) GetAddress(appID, walletID, accountID, address string) (*openwallet.Address, error)

GetAddress 获取单个地址信息

func (*WalletManager) GetAddressList

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

GetAddressList

func (*WalletManager) GetAssetsAccountBalance

func (wm *WalletManager) GetAssetsAccountBalance(appID, walletID, accountID string) (*openwallet.Balance, error)

GetAssetsAccountBalance 获取账户余额

func (*WalletManager) GetAssetsAccountInfo

func (wm *WalletManager) GetAssetsAccountInfo(appID, walletID, accountID string) (*openwallet.AssetsAccount, error)

GetAssetsAccountInfo

func (*WalletManager) GetAssetsAccountList

func (wm *WalletManager) GetAssetsAccountList(appID, walletID string, offset, limit int) ([]*openwallet.AssetsAccount, error)

GetAssetsAccountList

func (*WalletManager) GetAssetsAccountTokenBalance

func (wm *WalletManager) GetAssetsAccountTokenBalance(appID, walletID, accountID string, contract openwallet.SmartContract) (*openwallet.TokenBalance, error)

GetAssetsAccountTokenBalance 获取账户Token余额

func (*WalletManager) GetEstimateFeeRate

func (wm *WalletManager) GetEstimateFeeRate(coin openwallet.Coin) (feeRate string, unit string, err error)

GetEstimateFeeRate 获取币种推荐手续费

func (*WalletManager) GetNewBlockHeight

func (wm *WalletManager) GetNewBlockHeight(symbol string) (uint64, uint64, error)

GetNewBlockHeight 获取区块高度,(最新高度,已扫描高度)

func (*WalletManager) GetSourceKeyByAddressForBlockScan

func (wm *WalletManager) GetSourceKeyByAddressForBlockScan(address string) (string, bool)

GetSourceKeyByAddressForBlockScan 获取地址对应的数据源标识

func (*WalletManager) GetTransactionByWxID

func (wm *WalletManager) GetTransactionByWxID(appID, wxID string) (*openwallet.Transaction, error)

GetTransactionByWxID 通过WxID获取交易单

func (*WalletManager) GetTransactions

func (wm *WalletManager) GetTransactions(appID string, offset, limit int, cols ...interface{}) ([]*openwallet.Transaction, error)

GetTransactions

func (*WalletManager) GetTxSpent

func (wm *WalletManager) GetTxSpent(appID string, offset, limit int, cols ...interface{}) ([]*openwallet.TxInput, error)

GetTxSpent

func (*WalletManager) GetTxUnspent

func (wm *WalletManager) GetTxUnspent(appID string, offset, limit int, cols ...interface{}) ([]*openwallet.TxOutPut, error)

GetTxUnspent

func (*WalletManager) GetWalletInfo

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

GetWalletInfo

func (*WalletManager) GetWalletList

func (wm *WalletManager) GetWalletList(appID string, offset, limit int) ([]*openwallet.Wallet, error)

GetWalletList

func (*WalletManager) ImportWatchOnlyAddress

func (wm *WalletManager) ImportWatchOnlyAddress(appID, walletID, accountID string, addresses []*openwallet.Address) error

ImportWatchOnlyAddress

func (*WalletManager) Init

func (wm *WalletManager) Init()

Init 初始化

func (*WalletManager) IsExistAddressForBlockScan

func (wm *WalletManager) IsExistAddressForBlockScan(address string) bool

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

func (*WalletManager) NewWalletWrapper added in v1.4.11

func (wm *WalletManager) NewWalletWrapper(appID, walletID string) (*WalletWrapper, error)

NewWalletWrapper 创建App专用的包装器

func (*WalletManager) OpenDB

func (wm *WalletManager) OpenDB(appID string) (*StormDB, error)

OpenDB 打开应用数据库文件

func (*WalletManager) RemoveObserver

func (wm *WalletManager) RemoveObserver(obj NotificationObject)

RemoveObserver 移除观测者

func (*WalletManager) RescanBlockHeight

func (wm *WalletManager) RescanBlockHeight(symbol string, startHeight uint64, endHeight uint64) error

func (*WalletManager) SetRescanBlockHeight

func (wm *WalletManager) SetRescanBlockHeight(symbol string, height uint64) error

SetRescanBlockHeight 重置区块高度起扫描

func (*WalletManager) SignTransaction

func (wm *WalletManager) SignTransaction(appID, walletID, accountID, password string, rawTx *openwallet.RawTransaction) (*openwallet.RawTransaction, error)

SignTransaction

func (*WalletManager) SubmitTransaction

func (wm *WalletManager) SubmitTransaction(appID, walletID, accountID string, rawTx *openwallet.RawTransaction) (*openwallet.Transaction, error)

SubmitTransaction

func (*WalletManager) VerifyTransaction

func (wm *WalletManager) VerifyTransaction(appID, walletID, accountID string, rawTx *openwallet.RawTransaction) (*openwallet.RawTransaction, error)

VerifyTransaction

type WalletWrapper added in v1.3.0

type WalletWrapper struct {
	*AppWrapper
	// contains filtered or unexported fields
}

WalletWrapper 钱包包装器,扩展钱包功能

func NewWalletWrapper added in v1.3.0

func NewWalletWrapper(args ...interface{}) *WalletWrapper

func (*WalletWrapper) CreateAddress added in v1.3.0

func (wrapper *WalletWrapper) CreateAddress(accountID string, count uint64, decoder openwallet.AddressDecoder, isChange bool, isTestNet bool) ([]*openwallet.Address, error)

CreateAddress 创建地址 @param accountID 指定账户 @param count 创建数量 @param decoder 地址解释器 @param isChange 是否找零地址 @param isTestNet 是否测试网

func (*WalletWrapper) GetAddress added in v1.3.0

func (wrapper *WalletWrapper) GetAddress(address string) (*openwallet.Address, error)

GetAddress 通过地址字符串获取地址对象

func (*WalletWrapper) GetAddressExtParam added in v1.3.0

func (wrapper *WalletWrapper) GetAddressExtParam(address string, key string) (interface{}, error)

获取地址的扩展字段

func (*WalletWrapper) GetAddressList added in v1.3.0

func (wrapper *WalletWrapper) GetAddressList(offset, limit int, cols ...interface{}) ([]*openwallet.Address, error)

GetAddresses 获取资产账户地址列表

func (*WalletWrapper) GetAssetsAccountByAddress added in v1.3.0

func (wrapper *WalletWrapper) GetAssetsAccountByAddress(address string) (*openwallet.AssetsAccount, error)

GetAssetsAccountByAddress 通过地址获取资产账户对象

func (*WalletWrapper) GetAssetsAccountInfo added in v1.3.0

func (wrapper *WalletWrapper) GetAssetsAccountInfo(accountID string) (*openwallet.AssetsAccount, error)

GetAssetsAccountInfo 获取指定账户

func (*WalletWrapper) GetAssetsAccountList added in v1.3.0

func (wrapper *WalletWrapper) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*openwallet.AssetsAccount, error)

GetAssetsAccounts 获取某种区块链的全部资产账户

func (*WalletWrapper) GetImportAddressList added in v1.3.0

func (wrapper *WalletWrapper) GetImportAddressList(offset, limit int, cols ...interface{}) ([]*openwallet.ImportAddress, error)

GetImportAddressList 获取待导入

func (*WalletWrapper) GetTransactions added in v1.3.0

func (wrapper *WalletWrapper) GetTransactions(offset, limit int, cols ...interface{}) ([]*openwallet.Transaction, error)

GetTransactions 获取钱包的交易记录

func (*WalletWrapper) GetTxInputs added in v1.3.0

func (wrapper *WalletWrapper) GetTxInputs(offset, limit int, cols ...interface{}) ([]*openwallet.TxInput, error)

GetTxInputs 获取钱包的出账记录

func (*WalletWrapper) GetTxOutputs added in v1.3.0

func (wrapper *WalletWrapper) GetTxOutputs(offset, limit int, cols ...interface{}) ([]*openwallet.TxOutPut, error)

GetTxOutputs 获取钱包的入账记录

func (*WalletWrapper) GetWallet added in v1.3.0

func (wrapper *WalletWrapper) GetWallet() *openwallet.Wallet

GetWallet 获取钱包

func (*WalletWrapper) GetWalletByID added in v1.3.0

func (wrapper *WalletWrapper) GetWalletByID(walletID string) (*openwallet.Wallet, error)

GetWalletByID 通过钱包ID获取

func (*WalletWrapper) HDKey added in v1.3.0

func (wrapper *WalletWrapper) HDKey(password ...string) (*hdkeystore.HDKey, error)

HDKey 获取钱包密钥,需要密码

func (*WalletWrapper) ImportWatchOnlyAddress added in v1.3.0

func (wrapper *WalletWrapper) ImportWatchOnlyAddress(address ...*openwallet.Address) error

ImportWatchOnlyAddress 导入观测地址

func (*WalletWrapper) SaveAssetsAccount added in v1.3.0

func (wrapper *WalletWrapper) SaveAssetsAccount(account *openwallet.AssetsAccount) error

SaveAssetsAccount 更新账户信息

func (*WalletWrapper) SetAddressExtParam added in v1.3.0

func (wrapper *WalletWrapper) SetAddressExtParam(address string, key string, val interface{}) error

设置地址的扩展字段

func (*WalletWrapper) UnlockWallet added in v1.3.0

func (wrapper *WalletWrapper) UnlockWallet(password string, time time.Duration) error

type Wrapper added in v1.3.0

type Wrapper struct {
	openwallet.WalletDAIBase
	// contains filtered or unexported fields
}

Wrapper 基于OpenWallet钱包体系模型,专门处理钱包的持久化问题,关系数据查询

func NewWrapper added in v1.3.0

func NewWrapper(args ...interface{}) *Wrapper

func (*Wrapper) CloseDB added in v1.3.0

func (wrapper *Wrapper) CloseDB()

CloseDB 关闭数据库

func (*Wrapper) OpenStormDB added in v1.3.0

func (wrapper *Wrapper) OpenStormDB() (*StormDB, error)

OpenStormDB 打开数据库

func (*Wrapper) SetExternalDB added in v1.3.0

func (wrapper *Wrapper) SetExternalDB(db *StormDB) error

SetStormDB 设置钱包的应用数据库

type WrapperSourceFile added in v1.3.0

type WrapperSourceFile string

Jump to

Keyboard shortcuts

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