Documentation ¶
Index ¶
- Constants
- Variables
- func Errorf(code int64, format string, a ...interface{}) error
- func GenAccountID(publicKey string) string
- func GenAccountIDByHex(publicKeyHex string) string
- func GenContractID(symbol, address string) string
- func GenRechargeSID(txid string, coinsymbol string, contractId string, n uint64, prefix string) string
- func GenTransactionWxID(tx *Transaction) string
- func GenTransactionWxID2(txid string, coinsymbol string, contractId string) string
- func GenTxInputSID(txid string, coinsymbol string, contractId string, n uint64) string
- func GenTxOutPutSID(txid string, coinsymbol string, contractId string, n uint64) string
- func GetBackupDir(symbol string) string
- func GetDBDir(symbol string) string
- func GetDataDir(symbol string) string
- func GetExportAddressDir(symbol string) string
- func GetKeyDir(symbol string) string
- func NewError(code int64, text string) error
- func NewWalletID() uuid.UUID
- type AccountOwner
- type Address
- type AddressCreateResult
- type AddressDecoder
- type App
- type AppID
- type AppWrapper
- type AssetsAccount
- type AssetsAdapter
- type AssetsAdapterBase
- func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder
- func (a *AssetsAdapterBase) GetAssetsLogger() *log.OWLogger
- func (a *AssetsAdapterBase) GetBlockScanner() BlockScanner
- func (a *AssetsAdapterBase) GetSmartContractDecoder() SmartContractDecoder
- func (a *AssetsAdapterBase) GetTransactionDecoder() TransactionDecoder
- func (a *AssetsAdapterBase) InitAssetsAdapter() error
- type AssetsConfig
- type AssetsConfigBase
- type Balance
- type BlockHeader
- type BlockScanAddressFunc
- type BlockScanNotificationObject
- type BlockScanNotify
- type BlockScanner
- type BlockScannerBase
- func (bs *BlockScannerBase) AddObserver(obj BlockScanNotificationObject) error
- func (bs *BlockScannerBase) CloseBlockScanner() error
- func (bs *BlockScannerBase) ExtractTransactionData(txid string, scanAddressFunc BlockScanAddressFunc) (map[string][]*TxExtractData, error)
- func (bs *BlockScannerBase) GetBalanceByAddress(address ...string) ([]*Balance, error)
- func (bs *BlockScannerBase) GetCurrentBlockHeader() (*BlockHeader, error)
- func (bs *BlockScannerBase) GetGlobalMaxBlockHeight() uint64
- func (bs *BlockScannerBase) GetScannedBlockHeight() uint64
- func (bs *BlockScannerBase) GetTransactionsByAddress(offset, limit int, coin Coin, address ...string) ([]*TxExtractData, error)
- func (bs *BlockScannerBase) InitBlockScanner() error
- func (bs *BlockScannerBase) IsClose() bool
- func (bs *BlockScannerBase) NewBlockNotify(block *BlockHeader) error
- func (bs *BlockScannerBase) Pause() error
- func (bs *BlockScannerBase) RemoveObserver(obj BlockScanNotificationObject) error
- func (bs *BlockScannerBase) Restart() error
- func (bs *BlockScannerBase) Run() error
- func (bs *BlockScannerBase) ScanBlock(height uint64) error
- func (bs *BlockScannerBase) SetBlockScanAddressFunc(scanAddressFunc BlockScanAddressFunc) error
- func (bs *BlockScannerBase) SetRescanBlockHeight(height uint64) error
- func (bs *BlockScannerBase) SetTask(task func())
- func (bs *BlockScannerBase) Stop() error
- type Blockchain
- type Bytes
- type Coin
- type Error
- type ImportAddress
- type KeySignature
- type PublicKey
- type RawTransaction
- type Recharge
- type SmartContract
- type SmartContractDecoder
- type SmartContractDecoderBase
- type SmartContractRawTransaction
- type StormDB
- type SummaryRawTransaction
- type SymbolInfo
- type SymbolInfoBase
- type TokenBalance
- type Transaction
- type TransactionDecoder
- type TransactionDecoderBase
- func (decoder *TransactionDecoderBase) CreateRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
- func (decoder *TransactionDecoderBase) CreateSummaryRawTransaction(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransaction, error)
- func (decoder *TransactionDecoderBase) GetRawTransactionFeeRate() (feeRate string, unit string, err error)
- func (decoder *TransactionDecoderBase) SignRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
- func (decoder *TransactionDecoderBase) SubmitRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) (*Transaction, error)
- func (decoder *TransactionDecoderBase) VerifyRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
- type TransactionWrapper
- type TxExtractData
- type TxInput
- type TxOutPut
- type Wallet
- func (w *Wallet) DropRecharge() error
- func (w *Wallet) FileName() string
- func (w *Wallet) GetAddress(address string) *Address
- func (w *Wallet) GetAddressesByAccount(accountID string) []*Address
- func (w *Wallet) GetAssetsAccounts(symbol string) []*AssetsAccount
- func (w *Wallet) GetRecharges(received bool, height ...uint64) ([]*Recharge, error)
- func (w *Wallet) GetUnconfrimRecharges(limitTime int64) ([]*Recharge, error)
- func (w *Wallet) HDKey(password ...string) (*hdkeystore.HDKey, error)
- func (w *Wallet) OpenDB() (*storm.DB, error)
- func (w *Wallet) SaveRecharge(tx *Recharge) error
- func (w *Wallet) SaveToDB() error
- func (w *Wallet) SaveUnreceivedRecharge(tx *Recharge) error
- func (w *Wallet) SingleAssetsAccount(symbol string) *AssetsAccount
- func (w *Wallet) WalletWrapper() *WalletWrapper
- type WalletConfig
- type WalletDAI
- type WalletDAIBase
- func (base *WalletDAIBase) GetAddress(address string) (*Address, error)
- func (base *WalletDAIBase) GetAddressExtParam(address string, key string) (interface{}, error)
- func (base *WalletDAIBase) GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error)
- func (base *WalletDAIBase) GetAssetsAccountByAddress(address string) (*AssetsAccount, error)
- func (base *WalletDAIBase) GetAssetsAccountInfo(accountID string) (*AssetsAccount, error)
- func (base *WalletDAIBase) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error)
- func (base *WalletDAIBase) GetWallet() *Wallet
- func (base *WalletDAIBase) GetWalletByID(walletID string) (*Wallet, error)
- func (base *WalletDAIBase) HDKey(password ...string) (*hdkeystore.HDKey, error)
- func (base *WalletDAIBase) SetAddressExtParam(address string, key string, val interface{}) error
- func (base *WalletDAIBase) UnlockWallet(password string, time time.Duration) error
- type WalletDBFile
- type WalletKeyFile
- type WalletType
- type WalletWrapper
- func (wrapper *WalletWrapper) CreateAddress(accountID string, count uint64, decoder AddressDecoder, isChange bool, ...) ([]*Address, error)
- func (wrapper *WalletWrapper) GetAddress(address string) (*Address, error)
- func (wrapper *WalletWrapper) GetAddressExtParam(address string, key string) (interface{}, error)
- func (wrapper *WalletWrapper) GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error)
- func (wrapper *WalletWrapper) GetAssetsAccountByAddress(address string) (*AssetsAccount, error)
- func (wrapper *WalletWrapper) GetAssetsAccountInfo(accountID string) (*AssetsAccount, error)
- func (wrapper *WalletWrapper) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error)
- func (wrapper *WalletWrapper) GetImportAddressList(offset, limit int, cols ...interface{}) ([]*ImportAddress, error)
- func (wrapper *WalletWrapper) GetTransactions(offset, limit int, cols ...interface{}) ([]*Transaction, error)
- func (wrapper *WalletWrapper) GetTxInputs(offset, limit int, cols ...interface{}) ([]*TxInput, error)
- func (wrapper *WalletWrapper) GetTxOutputs(offset, limit int, cols ...interface{}) ([]*TxOutPut, error)
- func (wrapper *WalletWrapper) GetWallet() *Wallet
- func (wrapper *WalletWrapper) GetWalletByID(walletID string) (*Wallet, error)
- func (wrapper *WalletWrapper) HDKey(password ...string) (*hdkeystore.HDKey, error)
- func (wrapper *WalletWrapper) ImportWatchOnlyAddress(address ...*Address) error
- func (wrapper *WalletWrapper) SaveAssetsAccount(account *AssetsAccount) error
- func (wrapper *WalletWrapper) SetAddressExtParam(address string, key string, val interface{}) error
- func (wrapper *WalletWrapper) UnlockWallet(password string, time time.Duration) error
- type Withdraw
- type Wrapper
- type WrapperSourceFile
Constants ¶
const ( WalletTypeSingle = 0 WalletTypeMulti = 1 )
const ( /// 私钥字节长度 PrivateKeyLength = 32 /// 公钥字节长度(压缩) PublicKeyLengthCompressed = 33 /// 公钥字节长度(未压缩) PublicKeyLengthUncompressed = 65 )
const ( /* 交易类别 */ ErrInsufficientBalanceOfAccount = 2001 //账户余额不足 ErrInsufficientBalanceOfAddress = 2002 //地址余额不足 ErrInsufficientFees = 2003 //手续费不足 ErrDustLimit = 2004 //限制粉尘攻击 ErrCreateRawTransactionFailed = 2005 //创建原始交易单失败 ErrSignRawTransactionFailed = 2006 //签名原始交易单失败 ErrVerifyRawTransactionFailed = 2007 //验证原始交易单失败 ErrSubmitRawTransactionFailed = 2008 //广播原始交易单失败 /* 账户类别 */ ErrAccountNotFound = 3001 //账户不存在 ErrAddressNotFound = 3002 //地址不存在 ErrContractNotFound = 3003 //合约不存在 ErrAdressEncodeFailed = 3004 //地址编码失败 ErrAdressDecodeFailed = 3006 //地址解码失败 ErrNonceInvaild = 3007 //Nonce不正确 ErrAccountNotAddress = 3008 //账户没有地址 /* 网络类型 */ ErrCallFullNodeAPIFailed = 4001 //全节点API无法访问 /* 其他 */ ErrUnknownException = 9001 //未知异常情况 )
const ( // VERSION represent openw web framework version. VERSION = "1.0.0" // DEV is for develop DEV = "dev" // PROD is for production PROD = "prod" )
const ( BalanceModelTypeAddress = 0 //以地址记录余额 BalanceModelTypeAccount = 1 //以账户记录余额 )
余额模型类别
const ( TxStatusSuccess = "1" //成功 TxStatusFail = "0" //失败 )
交易单状态
Variables ¶
var ( //ID首字节的标识 AccountIDVer = []byte{0x09} )
Functions ¶
func GenAccountID ¶
GenAccountID 计算publicKey的AccountID publickey为OW编码后
func GenAccountIDByHex ¶
GenAccountIDByHex 计算publicKey的AccountID publickey为HEX传
func GenRechargeSID ¶
func GenRechargeSID(txid string, coinsymbol string, contractId string, n uint64, prefix string) string
GenRechargeSID
func GenTransactionWxID ¶
func GenTransactionWxID(tx *Transaction) string
func GenTransactionWxID2 ¶
func GenTxInputSID ¶
func GenTxOutPutSID ¶
func GetExportAddressDir ¶
GetExportAddressDir 导出地址目录
func NewWalletID ¶
Types ¶
type Address ¶
type Address struct { AccountID string `json:"accountID" storm:"index"` //钱包ID Address string `json:"address" storm:"id"` //地址字符串 PublicKey string `json:"publicKey"` //地址公钥/赎回脚本 Alias string `json:"alias"` //地址别名,可绑定用户 Tag string `json:"tag"` //标签 Index uint64 `json:"index"` //账户ID,索引位 HDPath string `json:"hdPath"` //地址公钥根路径 WatchOnly bool `json:"watchOnly"` //是否观察地址,true的时候,Index,RootPath,Alias都没有。 Symbol string `json:"symbol"` //币种类别 Balance string `json:"balance"` //余额 IsMemo bool `json:"isMemo"` //是否备注 Memo string `json:"memo"` //备注 //CreateAt time.Time `json:"createdAt"`//创建时间 CreatedTime int64 `json:"createdTime"` //创建时间 IsChange bool `json:"isChange"` //是否找零地址 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 //核心地址指针 Core interface{} }
Address OpenWallet地址
func BatchCreateAddressByAccount ¶
func BatchCreateAddressByAccount(account *AssetsAccount, decoder AddressDecoder, count int64, workerSize int) ([]*Address, error)
BatchCreateAddressByAccount 批量创建地址 @account 账户 @decoder 地址编码器 @conf 环境配置 @count 连续创建数量 @workerSize 并行线程数。建议20条,并行执行5000条大约8.22秒。
func NewAddress ¶
type AddressCreateResult ¶
func CreateAddressByAccountWithIndex ¶
func CreateAddressByAccountWithIndex(account *AssetsAccount, decoder AddressDecoder, addrIndex int, addrIsChange int64) AddressCreateResult
type AddressDecoder ¶
type AddressDecoder interface { //PrivateKeyToWIF 私钥转WIF PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error) //PublicKeyToAddress 公钥转地址 PublicKeyToAddress(pub []byte, isTestnet bool) (string, error) //WIFToPrivateKey WIF转私钥 WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error) //RedeemScriptToAddress 多重签名赎回脚本转地址 RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error) }
type AppWrapper ¶
type AppWrapper struct { *Wrapper // contains filtered or unexported fields }
AppWrapper 应用装器,扩展应用功能
func NewAppWrapper ¶
func NewAppWrapper(args ...interface{}) *AppWrapper
func (*AppWrapper) GetWalletInfo ¶
func (wrapper *AppWrapper) GetWalletInfo(walletID string) (*Wallet, error)
GetWalletInfo
func (*AppWrapper) GetWalletList ¶
func (wrapper *AppWrapper) GetWalletList(offset, limit int) ([]*Wallet, error)
GetWalletList
type AssetsAccount ¶
type AssetsAccount struct { WalletID string `json:"walletID"` //钱包ID Alias string `json:"alias"` //别名 AccountID string `json:"accountID" storm:"id"` //账户ID,合成地址 Index uint64 `json:"index"` //账户ID,索引位 HDPath string `json:"hdPath"` //衍生路径 PublicKey string `json:"publicKey"` //主公钥 OwnerKeys []string `json:"ownerKeys"` //公钥数组,大于1为多签 //Owners map[string]AccountOwner //拥有者列表, 账户公钥: 拥有者 ContractAddress string `json:"contractAddress"` //多签合约地址 Required uint64 `json:"required"` //必要签名数 Symbol string `json:"symbol"` //资产币种类别 AddressIndex int `json:"addressIndex"` Balance string `json:"balance"` IsTrust bool `json:"isTrust"` //是否托管密钥 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 ModelType uint64 `json:"modelType"` //模型类别, 1: utxo模型(BTC), 2: account模型(ETH),3: 账户别名模型(EOS) // contains filtered or unexported fields }
AssetsAccount 千张包资产账户
func NewMultiSigAccount ¶
func NewMultiSigAccount(wallets []*Wallet, required uint, creator *Wallet) (*AssetsAccount, error)
func (*AssetsAccount) GetAccountID ¶
func (a *AssetsAccount) GetAccountID() string
GetAccountID 计算AccountID
func (*AssetsAccount) GetOwners ¶
func (a *AssetsAccount) GetOwners() []AccountOwner
type AssetsAdapter ¶
type AssetsAdapter interface { //币种信息 //@required SymbolInfo //配置 //@required AssetsConfig //GetAddressDecode 地址解析器 //@required GetAddressDecode() AddressDecoder //GetTransactionDecoder 交易单解析器 //@required GetTransactionDecoder() TransactionDecoder //GetBlockScanner 获取区块链扫描器 //@required GetBlockScanner() BlockScanner //GetSmartContractDecoder 获取智能合约解析器 //@optional GetSmartContractDecoder() SmartContractDecoder //GetAssetsLogger 获取资产日志工具 //@optional GetAssetsLogger() *log.OWLogger }
AssetsAdapter 资产适配器接口 适配OpenWallet钱包体系的抽象接口
type AssetsAdapterBase ¶
type AssetsAdapterBase struct { SymbolInfoBase AssetsConfigBase }
func (*AssetsAdapterBase) GetAddressDecode ¶
func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder
GetAddressDecode 地址解析器
func (*AssetsAdapterBase) GetAssetsLogger ¶
func (a *AssetsAdapterBase) GetAssetsLogger() *log.OWLogger
GetAssetsLogger 获取资产账户日志工具
func (*AssetsAdapterBase) GetBlockScanner ¶
func (a *AssetsAdapterBase) GetBlockScanner() BlockScanner
GetBlockScanner 获取区块链扫描器
func (*AssetsAdapterBase) GetSmartContractDecoder ¶
func (a *AssetsAdapterBase) GetSmartContractDecoder() SmartContractDecoder
GetBlockScanner 获取智能合约解析器
func (*AssetsAdapterBase) GetTransactionDecoder ¶
func (a *AssetsAdapterBase) GetTransactionDecoder() TransactionDecoder
GetTransactionDecoder 交易单解析器
func (*AssetsAdapterBase) InitAssetsAdapter ¶
func (a *AssetsAdapterBase) InitAssetsAdapter() error
GetAddressDecode 地址解析器
type AssetsConfig ¶
type AssetsConfig interface { //LoadExternalConfig 加载外部配置 LoadAssetsConfig(c config.Configer) error //InitDefaultConfig 初始化默认配置 InitAssetsConfig() (config.Configer, error) }
AssetsConfig 用于给AssetsAdapter调用者初始化、加载外部配置的接口
type AssetsConfigBase ¶
type AssetsConfigBase struct{}
func (*AssetsConfigBase) InitAssetsConfig ¶
func (as *AssetsConfigBase) InitAssetsConfig() (config.Configer, error)
InitAssetsConfig 初始化默认配置
func (*AssetsConfigBase) LoadAssetsConfig ¶
func (as *AssetsConfigBase) LoadAssetsConfig(c config.Configer) error
LoadAssetsConfig 加载外部配置
type BlockHeader ¶
type BlockHeader struct { Hash string `json:"hash"` Confirmations uint64 `json:"confirmations"` Merkleroot string `json:"merkleroot"` Previousblockhash string `json:"previousblockhash"` Height uint64 `json:"height"` Version uint64 `json:"version"` Time uint64 `json:"time"` Fork bool `json:"fork"` Symbol string `json:"symbol"` }
type BlockScanAddressFunc ¶
BlockScanAddressFunc 扫描地址是否存在算法 @return 地址所属源标识,是否存在
type BlockScanNotificationObject ¶
type BlockScanNotificationObject interface { //BlockScanNotify 新区块扫描完成通知 //@required BlockScanNotify(header *BlockHeader) error //BlockExtractDataNotify 区块提取结果通知 //@required BlockExtractDataNotify(sourceKey string, data *TxExtractData) error }
BlockScanNotificationObject 扫描被通知对象
type BlockScanNotify ¶
type BlockScanNotify func(header *BlockHeader)
BlockScanNotify 新区块扫描完成通知 @param txs 每扫完区块链,与地址相关的交易到
type BlockScanner ¶
type BlockScanner interface { //SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法 //@required SetBlockScanAddressFunc(scanAddressFunc BlockScanAddressFunc) error //AddObserver 添加观测者 AddObserver(obj BlockScanNotificationObject) error //RemoveObserver 移除观测者 RemoveObserver(obj BlockScanNotificationObject) error //SetRescanBlockHeight 重置区块链扫描高度 //@required SetRescanBlockHeight(height uint64) error //Run 运行 Run() error //Stop 停止扫描 Stop() error //Pause 暂停扫描 Pause() error //Restart 继续扫描 Restart() error //InitBlockScanner 初始化扫描器 InitBlockScanner() error //CloseBlockScanner 关闭扫描器 CloseBlockScanner() error //ScanBlock 扫描指定高度的区块 //@required ScanBlock(height uint64) error //NewBlockNotify 新区块通知 NewBlockNotify(header *BlockHeader) error //GetCurrentBlockHeight 获取当前区块高度 //@required GetCurrentBlockHeader() (*BlockHeader, error) //GetGlobalMaxBlockHeight 获取区块链全网最大高度 //@required GetGlobalMaxBlockHeight() uint64 //GetScannedBlockHeight 获取已扫区块高度 //@required GetScannedBlockHeight() uint64 //ExtractTransactionData 提取交易单数据 //@required ExtractTransactionData(txid string, scanAddressFunc BlockScanAddressFunc) (map[string][]*TxExtractData, error) //GetBalanceByAddress 查询地址余额 GetBalanceByAddress(address ...string) ([]*Balance, error) //GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址 //返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算 GetTransactionsByAddress(offset, limit int, coin Coin, address ...string) ([]*TxExtractData, error) }
BlockScanner 区块扫描器 负责扫描新区块,给观察者推送订阅地址的新交易单。
type BlockScannerBase ¶
type BlockScannerBase struct { AddressInScanning map[string]string //加入扫描的地址 Mu sync.RWMutex //读写锁 Observers map[BlockScanNotificationObject]bool //观察者 Scanning bool //是否扫描中 PeriodOfTask time.Duration ScanAddressFunc BlockScanAddressFunc //区块扫描查询地址算法 // contains filtered or unexported fields }
BlockScannerBase 区块链扫描器基本结构实现
func (*BlockScannerBase) AddObserver ¶
func (bs *BlockScannerBase) AddObserver(obj BlockScanNotificationObject) error
AddObserver 添加观测者
func (*BlockScannerBase) CloseBlockScanner ¶
func (bs *BlockScannerBase) CloseBlockScanner() error
CloseBlockScanner 关闭扫描器
func (*BlockScannerBase) ExtractTransactionData ¶
func (bs *BlockScannerBase) ExtractTransactionData(txid string, scanAddressFunc BlockScanAddressFunc) (map[string][]*TxExtractData, error)
func (*BlockScannerBase) GetBalanceByAddress ¶
func (bs *BlockScannerBase) GetBalanceByAddress(address ...string) ([]*Balance, error)
GetBalanceByAddress 查询地址余额
func (*BlockScannerBase) GetCurrentBlockHeader ¶
func (bs *BlockScannerBase) GetCurrentBlockHeader() (*BlockHeader, error)
GetCurrentBlockHeight 获取当前区块高度
func (*BlockScannerBase) GetGlobalMaxBlockHeight ¶
func (bs *BlockScannerBase) GetGlobalMaxBlockHeight() uint64
GetGlobalMaxBlockHeight 获取区块链全网最大高度 @required
func (*BlockScannerBase) GetScannedBlockHeight ¶
func (bs *BlockScannerBase) GetScannedBlockHeight() uint64
GetScannedBlockHeight 获取已扫区块高度
func (*BlockScannerBase) GetTransactionsByAddress ¶
func (bs *BlockScannerBase) GetTransactionsByAddress(offset, limit int, coin Coin, address ...string) ([]*TxExtractData, error)
GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址 返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算
func (*BlockScannerBase) InitBlockScanner ¶
func (bs *BlockScannerBase) InitBlockScanner() error
InitBlockScanner
func (*BlockScannerBase) NewBlockNotify ¶
func (bs *BlockScannerBase) NewBlockNotify(block *BlockHeader) error
NewBlockNotify 获得新区块后,发送到通知通道
func (*BlockScannerBase) RemoveObserver ¶
func (bs *BlockScannerBase) RemoveObserver(obj BlockScanNotificationObject) error
RemoveObserver 移除观测者
func (*BlockScannerBase) ScanBlock ¶
func (bs *BlockScannerBase) ScanBlock(height uint64) error
ScanBlock 扫描指定高度区块
func (*BlockScannerBase) SetBlockScanAddressFunc ¶
func (bs *BlockScannerBase) SetBlockScanAddressFunc(scanAddressFunc BlockScanAddressFunc) error
SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法 @required
func (*BlockScannerBase) SetRescanBlockHeight ¶
func (bs *BlockScannerBase) SetRescanBlockHeight(height uint64) error
SetRescanBlockHeight 重置区块链扫描高度
type Blockchain ¶
type Coin ¶
type Coin struct { Symbol string `json:"symbol"` IsContract bool `json:"isContract"` ContractID string `json:"contractID"` Contract SmartContract `json:"contract"` }
Coin 币种信息
type KeySignature ¶
type KeySignature struct { EccType uint32 `json:"eccType"` //曲线类型 Nonce string `json:"nonce"` Address *Address `json:"address"` //提供签名的地址 Signature string `json:"signed"` //未花签名 Message string `json:"msg"` //被签消息 }
KeySignature 签名信息
type RawTransaction ¶
type RawTransaction struct { Coin Coin `json:"coin"` //@required 区块链类型标识 TxID string `json:"txID"` //交易单ID,广播后会生成 Sid string `json:"sid"` //业务订单号,保证业务不重复交易而用 RawHex string `json:"rawHex"` //区块链协议构造的交易原生数据 FeeRate string `json:"feeRate"` //自定义费率 To map[string]string `json:"to"` //@required 目的地址:转账数量 Account *AssetsAccount `json:"account"` //@required 创建交易单的账户 Signatures map[string][]*KeySignature `json:"sigParts"` //拥有者accountID: []未花签名 Required uint64 `json:"reqSigs"` //必要签名 IsBuilt bool `json:"isBuilt"` //是否完成构建建议单 IsCompleted bool `json:"isComplete"` //是否完成所有签名 IsSubmit bool `json:"isSubmit"` //是否已广播 Change *Address `json:"change"` //找零地址 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 Fees string `json:"fees"` //手续费 TxAmount string `json:"txAmount"` //交易单实际对账户发生的数量变化 TxFrom []string `json:"txFrom"` //格式:"地址":"数量",备注订单使用 TxTo []string `json:"txTo"` //格式:"地址":"数量",备注订单使用 }
RawTransaction 原始交易单
Workflow:
首先:App(openw-server)中,提供 Coin/To/Account 参数 其次:APP 调用 tx_decoder 需处理: 1. 第一步调用交易单构建:计算手续费/构建签名结构,给 RawHex,Fees,FeeRate,Signatures,IsBuilt = true 赋值 2. 第二步调用交易单签名:获取到 RawHex 完成签名,完成参数 Signatures 3. 第三步调用交易单广播:解析rawHex,合并签名,验证签名,广播交易, 设置参数 TxID,IsSubmit = true
type Recharge ¶
type Recharge struct { Sid string `json:"sid" storm:"id"` //@required base64(sha1(txid+n+addr)),对于账户模型,只有一个输入输出,n = 0。 TxID string `json:"txid"` //@required AccountID string `json:"accountID"` Address string `json:"address"` //@required Symbol string `json:"symbol"` //Deprecated: use Coin Coin Coin //@required 区块链类型标识 Amount string `json:"amount"` //@required Confirm int64 `json:"confirm"` BlockHash string `json:"blockHash"` //@required BlockHeight uint64 `json:"blockHeight" storm:"index"` //@required IsMemo bool `json:"isMemo"` Memo string `json:"memo"` Index uint64 `json:"index"` //@required Received bool CreateAt int64 `json:"createdAt"` //@required Delete bool }
type SmartContract ¶
type SmartContract struct { ContractID string `json:"contractID" storm:"id"` //计算ID:base64(sha256({symbol}_{address})) 主链symbol Symbol string `json:"symbol"` //主币的symbol Address string `json:"address"` Token string `json:"token"` //合约的symbol Protocol string `json:"protocol"` Name string `json:"name"` Decimals uint64 `json:"decimals"` }
type SmartContractDecoder ¶
type SmartContractDecoder interface { //GetTokenBalanceByAddress 查询地址token余额列表 GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error) }
SmartContractDecoder 智能合约解析器
type SmartContractDecoderBase ¶
type SmartContractDecoderBase struct { }
func (*SmartContractDecoderBase) GetTokenBalanceByAddress ¶
func (decoder *SmartContractDecoderBase) GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error)
type SmartContractRawTransaction ¶
type SmartContractRawTransaction struct { Symbol string `json:"symbol"` //@required 区块链类型标识 TxID string `json:"txID"` //交易单ID,广播后会生成 Sid string `json:"sid"` //业务订单号,保证业务不重复交易而用 RawHex string `json:"rawHex"` //区块链协议构造的交易原生数据 Account *AssetsAccount `json:"account"` //@required 创建交易单的账户 Fees string `json:"fees"` //手续费 Signatures []*KeySignature `json:"signatures"` //拥有者accountID: []未花签名 IsBuilt bool `json:"isBuilt"` //是否完成构建建议单 IsCompleted bool `json:"isComplete"` //是否完成所有签名 IsSubmit bool `json:"isSubmit"` //是否已广播 TxAmount string `json:"txAmount"` //交易单实际对账户发生的数量变化 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 }
SmartContractRawTransaction 智能合约原始交易单
type StormDB ¶
func OpenStormDB ¶
OpenStormDB
type SummaryRawTransaction ¶
type SummaryRawTransaction struct { Coin Coin `json:"coin"` //@required 区块链类型标识 FeeRate string `json:"feeRate"` //自定义费率 SummaryAddress string `json:"summaryAddress"` //@required 目的地址:转账数量 MinTransfer string `json:"minTransfer"` //最低转账额,默认0 RetainedBalance string `json:"retainedBalance"` //账户的地址保留余额,默认0 Account *AssetsAccount `json:"account"` //@required 创建交易单的账户 AddressStartIndex int `json:"addressStartIndex"` //汇总账户地址开始位置 AddressLimit int `json:"addressLimit"` //汇总账户地址控制数量 Confirms uint64 `json:"confirms"` //汇总的未花交易大于确认数 }
SummaryRawTransaction 汇总交易
type SymbolInfo ¶
type SymbolInfoBase ¶
type SymbolInfoBase struct { }
func (*SymbolInfoBase) BalanceModelType ¶
func (s *SymbolInfoBase) BalanceModelType() uint32
BalanceModelType 余额模型类别
type TokenBalance ¶
type TokenBalance struct { Contract *SmartContract Balance *Balance }
type Transaction ¶
type Transaction struct { //openwallet自定义的ID,在不同链可能存在重复的txid, // 所以我们要生成一个全局不重复的 WxID string `json:"wxid" storm:"id"` //@required 通过GenTransactionWxID计算 TxID string `json:"txid"` //@required AccountID string `json:"accountID"` Coin Coin `json:"coin"` //@required 区块链类型标识 From []string `json:"from"` //@required 格式:"地址":"数量" To []string `json:"to"` //@required 格式:"地址":"数量" Amount string `json:"amount"` Decimal int32 `json:"decimal"` //@required TxType uint64 `json:"txType"` // 0:未知,1:主币转账,2:合约调用 Confirm int64 `json:"confirm"` BlockHash string `json:"blockHash"` //@required BlockHeight uint64 `json:"blockHeight"` //@required IsMemo bool `json:"isMemo"` Memo string `json:"memo"` Fees string `json:"fees"` //@required Received bool `json:"received"` SubmitTime int64 `json:"submitTime"` //@required ConfirmTime int64 `json:"confirmTime"` //@required Status string `json:"status"` //链上状态,0:失败,1:成功 Reason string `json:"reason"` //失败原因,失败状态码 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 }
func (*Transaction) SetExtParam ¶
func (tx *Transaction) SetExtParam(key string, value interface{}) error
SetExtParam
type TransactionDecoder ¶
type TransactionDecoder interface { //SendRawTransaction 广播交易单 //SendTransaction func(amount, feeRate string, to []string, wallet *Wallet, account *AssetsAccount) (*RawTransaction, error) //CreateRawTransaction 创建交易单 CreateRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error //SignRawTransaction 签名交易单 SignRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error //SubmitRawTransaction 广播交易单 SubmitRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) (*Transaction, error) //VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单 VerifyRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error //GetRawTransactionFeeRate 获取交易单的费率 GetRawTransactionFeeRate() (feeRate string, unit string, err error) //CreateSummaryRawTransaction 创建汇总交易,返回原始交易单数组 CreateSummaryRawTransaction(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransaction, error) }
TransactionDecoder 交易单解析器
type TransactionDecoderBase ¶
type TransactionDecoderBase struct { }
TransactionDecoderBase 实现TransactionDecoder的基类
func (*TransactionDecoderBase) CreateRawTransaction ¶
func (decoder *TransactionDecoderBase) CreateRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
CreateRawTransaction 创建交易单
func (*TransactionDecoderBase) CreateSummaryRawTransaction ¶
func (decoder *TransactionDecoderBase) CreateSummaryRawTransaction(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransaction, error)
CreateSummaryRawTransaction 创建汇总交易
func (*TransactionDecoderBase) GetRawTransactionFeeRate ¶
func (decoder *TransactionDecoderBase) GetRawTransactionFeeRate() (feeRate string, unit string, err error)
GetRawTransactionFeeRate 获取交易单的费率
func (*TransactionDecoderBase) SignRawTransaction ¶
func (decoder *TransactionDecoderBase) SignRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
SignRawTransaction 签名交易单
func (*TransactionDecoderBase) SubmitRawTransaction ¶
func (decoder *TransactionDecoderBase) SubmitRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) (*Transaction, error)
SendRawTransaction 广播交易单
func (*TransactionDecoderBase) VerifyRawTransaction ¶
func (decoder *TransactionDecoderBase) VerifyRawTransaction(wrapper WalletDAI, rawTx *RawTransaction) error
VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单
type TransactionWrapper ¶
type TransactionWrapper struct {
*WalletWrapper
}
TransactionWrapper 交易包装器,扩展钱包交易单相关功能
func NewTransactionWrapper ¶
func NewTransactionWrapper(args ...interface{}) *TransactionWrapper
func (*TransactionWrapper) DeleteBlockDataByHeight ¶
func (wrapper *TransactionWrapper) DeleteBlockDataByHeight(height uint64) error
DeleteBlockDataByHeight 删除钱包中指定区块高度相关的交易记录
func (*TransactionWrapper) SaveBlockExtractData ¶
func (wrapper *TransactionWrapper) SaveBlockExtractData(accountID string, data *TxExtractData) error
SaveBlockExtractData 保存区块提取数据
type TxExtractData ¶
type TxExtractData struct { //消费记录,交易单输入部分 TxInputs []*TxInput //充值记录,交易单输出部分 TxOutputs []*TxOutPut //交易记录 Transaction *Transaction }
TxExtractData 区块扫描后的交易单提取结果,每笔交易单
func NewBlockExtractData ¶
func NewBlockExtractData() *TxExtractData
type TxInput ¶
type TxInput struct { //SourceTxID和SourceIndex是utxo模型上的上一个交易输入源,account模型不需要填 SourceTxID string //源交易单ID SourceIndex uint64 //源交易单输出所因为 Recharge `storm:"inline"` }
TxInput 交易输入,则出账记录
type Wallet ¶
type Wallet struct { AppID string `json:"appID"` WalletID string `json:"walletID" storm:"id"` Alias string `json:"alias"` Password string `json:"password"` RootPub string `json:"rootpub"` //弃用 RootPath string `json:"rootPath"` KeyFile string `json:"keyFile"` //钱包的密钥文件 DBFile string `json:"dbFile"` //钱包的数据库文件 WatchOnly bool `json:"watchOnly"` //创建watchonly的钱包,没有私钥文件,只有db文件 IsTrust bool `json:"isTrust"` //是否托管密钥 AccountIndex int `json:"accountIndex"` //账户索引数,-1代表未创建账户 ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构 // contains filtered or unexported fields }
func GetWalletsByKeyDir ¶
GetWalletsByKeyDir 通过给定的文件路径加载keystore文件得到钱包列表
func NewHDWallet ¶
func NewHDWallet(key *hdkeystore.HDKey) (*Wallet, error)
func NewWatchOnlyWallet ¶
NewWatchOnlyWallet 只读钱包,用于观察冷钱包
func (*Wallet) GetAddress ¶
GetAddress 通过地址字符串获取地址对象
func (*Wallet) GetAddressesByAccount ¶
GetAddressesByAccountID 通过账户ID获取地址列表
func (*Wallet) GetAssetsAccounts ¶
func (w *Wallet) GetAssetsAccounts(symbol string) []*AssetsAccount
GetAssetsAccounts 获取某种区块链的全部资产账户
func (*Wallet) GetRecharges ¶
GetRecharges 获取钱包相关的充值记录
func (*Wallet) GetUnconfrimRecharges ¶
GetUnconfrimRecharges
func (*Wallet) HDKey ¶
func (w *Wallet) HDKey(password ...string) (*hdkeystore.HDKey, error)
HDKey 获取钱包密钥,需要密码
func (*Wallet) SaveUnreceivedRecharge ¶
SaveUnreceivedRecharge 保存未提交的充值记录
func (*Wallet) SingleAssetsAccount ¶
func (w *Wallet) SingleAssetsAccount(symbol string) *AssetsAccount
SingleAssetsAccount 把钱包作为一个单资产账户来使用
func (*Wallet) WalletWrapper ¶
func (w *Wallet) WalletWrapper() *WalletWrapper
WalletWrapper 返回一个钱包包装器
type WalletConfig ¶
type WalletConfig struct { /* | 参数名称 | 类型 | 是否可空 | 描述 | |----------|--------|----------|----------------------------------------------------------------| | coin | string | 否 | 币种 | | walletID | string | 否 | 钱包ID | | surplus | string | 否 | 剩余额,设置后,【余额—剩余额】低于第一笔提币金额则不提币(默认为0) | | fee | string | 否 | 提币矿工费 | | confirm | int | 否 | 确认次数(达到该确认次数后不再推送确认,默认30) | */ Key string `storm:"id"` Coin string `json:"coin"` WalletID string `json:"walletID" storm:"id"` Surplus string `json:"surplus"` Fee string `json:"fee"` Confirm uint64 `json:"confirm"` }
func NewWalletConfig ¶
func NewWalletConfig(json gjson.Result) *WalletConfig
type WalletDAI ¶
type WalletDAI interface { //获取当前钱包 GetWallet() *Wallet //根据walletID查询钱包 GetWalletByID(walletID string) (*Wallet, error) //获取单个资产账户 GetAssetsAccountInfo(accountID string) (*AssetsAccount, error) //查询资产账户列表 GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error) //根据地址查询资产账户 GetAssetsAccountByAddress(address string) (*AssetsAccount, error) //获取单个地址 GetAddress(address string) (*Address, error) //查询地址列表 GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error) //设置地址的扩展字段 SetAddressExtParam(address string, key string, val interface{}) error //获取地址的扩展字段 GetAddressExtParam(address string, key string) (interface{}, error) //解锁钱包,指定时间内免密 UnlockWallet(password string, time time.Duration) error //获取钱包HDKey HDKey(password ...string) (*hdkeystore.HDKey, error) }
WalletDAI 钱包数据访问接口
type WalletDAIBase ¶
type WalletDAIBase struct { }
TransactionDecoderBase 实现TransactionDecoder的基类
func (*WalletDAIBase) GetAddress ¶
func (base *WalletDAIBase) GetAddress(address string) (*Address, error)
func (*WalletDAIBase) GetAddressExtParam ¶
func (base *WalletDAIBase) GetAddressExtParam(address string, key string) (interface{}, error)
获取地址的扩展字段
func (*WalletDAIBase) GetAddressList ¶
func (base *WalletDAIBase) GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error)
func (*WalletDAIBase) GetAssetsAccountByAddress ¶
func (base *WalletDAIBase) GetAssetsAccountByAddress(address string) (*AssetsAccount, error)
func (*WalletDAIBase) GetAssetsAccountInfo ¶
func (base *WalletDAIBase) GetAssetsAccountInfo(accountID string) (*AssetsAccount, error)
func (*WalletDAIBase) GetAssetsAccountList ¶
func (base *WalletDAIBase) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error)
func (*WalletDAIBase) GetWallet ¶
func (base *WalletDAIBase) GetWallet() *Wallet
func (*WalletDAIBase) GetWalletByID ¶
func (base *WalletDAIBase) GetWalletByID(walletID string) (*Wallet, error)
func (*WalletDAIBase) HDKey ¶
func (base *WalletDAIBase) HDKey(password ...string) (*hdkeystore.HDKey, error)
func (*WalletDAIBase) SetAddressExtParam ¶
func (base *WalletDAIBase) SetAddressExtParam(address string, key string, val interface{}) error
设置地址的扩展字段
func (*WalletDAIBase) UnlockWallet ¶
func (base *WalletDAIBase) UnlockWallet(password string, time time.Duration) error
type WalletDBFile ¶
type WalletDBFile WrapperSourceFile
type WalletKeyFile ¶
type WalletKeyFile string
type WalletWrapper ¶
type WalletWrapper struct { *AppWrapper // contains filtered or unexported fields }
WalletWrapper 钱包包装器,扩展钱包功能
func NewWalletWrapper ¶
func NewWalletWrapper(args ...interface{}) *WalletWrapper
func (*WalletWrapper) CreateAddress ¶
func (wrapper *WalletWrapper) CreateAddress(accountID string, count uint64, decoder AddressDecoder, isChange bool, isTestNet bool) ([]*Address, error)
CreateAddress 创建地址 @param accountID 指定账户 @param count 创建数量 @param decoder 地址解释器 @param isChange 是否找零地址 @param isTestNet 是否测试网
func (*WalletWrapper) GetAddress ¶
func (wrapper *WalletWrapper) GetAddress(address string) (*Address, error)
GetAddress 通过地址字符串获取地址对象
func (*WalletWrapper) GetAddressExtParam ¶
func (wrapper *WalletWrapper) GetAddressExtParam(address string, key string) (interface{}, error)
获取地址的扩展字段
func (*WalletWrapper) GetAddressList ¶
func (wrapper *WalletWrapper) GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error)
GetAddresses 获取资产账户地址列表
func (*WalletWrapper) GetAssetsAccountByAddress ¶
func (wrapper *WalletWrapper) GetAssetsAccountByAddress(address string) (*AssetsAccount, error)
GetAssetsAccountByAddress 通过地址获取资产账户对象
func (*WalletWrapper) GetAssetsAccountInfo ¶
func (wrapper *WalletWrapper) GetAssetsAccountInfo(accountID string) (*AssetsAccount, error)
GetAssetsAccountInfo 获取指定账户
func (*WalletWrapper) GetAssetsAccountList ¶
func (wrapper *WalletWrapper) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error)
GetAssetsAccounts 获取某种区块链的全部资产账户
func (*WalletWrapper) GetImportAddressList ¶
func (wrapper *WalletWrapper) GetImportAddressList(offset, limit int, cols ...interface{}) ([]*ImportAddress, error)
GetImportAddressList 获取待导入
func (*WalletWrapper) GetTransactions ¶
func (wrapper *WalletWrapper) GetTransactions(offset, limit int, cols ...interface{}) ([]*Transaction, error)
GetTransactions 获取钱包的交易记录
func (*WalletWrapper) GetTxInputs ¶
func (wrapper *WalletWrapper) GetTxInputs(offset, limit int, cols ...interface{}) ([]*TxInput, error)
GetTxInputs 获取钱包的出账记录
func (*WalletWrapper) GetTxOutputs ¶
func (wrapper *WalletWrapper) GetTxOutputs(offset, limit int, cols ...interface{}) ([]*TxOutPut, error)
GetTxOutputs 获取钱包的入账记录
func (*WalletWrapper) GetWalletByID ¶
func (wrapper *WalletWrapper) GetWalletByID(walletID string) (*Wallet, error)
GetWalletByID 通过钱包ID获取
func (*WalletWrapper) HDKey ¶
func (wrapper *WalletWrapper) HDKey(password ...string) (*hdkeystore.HDKey, error)
HDKey 获取钱包密钥,需要密码
func (*WalletWrapper) ImportWatchOnlyAddress ¶
func (wrapper *WalletWrapper) ImportWatchOnlyAddress(address ...*Address) error
ImportWatchOnlyAddress 导入观测地址
func (*WalletWrapper) SaveAssetsAccount ¶
func (wrapper *WalletWrapper) SaveAssetsAccount(account *AssetsAccount) error
SaveAssetsAccount 更新账户信息
func (*WalletWrapper) SetAddressExtParam ¶
func (wrapper *WalletWrapper) SetAddressExtParam(address string, key string, val interface{}) error
设置地址的扩展字段
func (*WalletWrapper) UnlockWallet ¶
func (wrapper *WalletWrapper) UnlockWallet(password string, time time.Duration) error
type Withdraw ¶
type Wrapper ¶
type Wrapper struct { WalletDAIBase // contains filtered or unexported fields }
Wrapper 基于OpenWallet钱包体系模型,专门处理钱包的持久化问题,关系数据查询
func NewWrapper ¶
func NewWrapper(args ...interface{}) *Wrapper
func (*Wrapper) OpenStormDB ¶
OpenStormDB 打开数据库
func (*Wrapper) SetExternalDB ¶
SetStormDB 设置钱包的应用数据库
type WrapperSourceFile ¶
type WrapperSourceFile string