Documentation
¶
Index ¶
- Constants
- Variables
- 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
- type ABIDAI
- type ABIInfo
- type AccountOwner
- type Address
- type AddressCreateResult
- type AddressDecoder
- type AddressDecoderV2
- type AddressDecoderV2Base
- func (dec *AddressDecoderV2Base) AddressDecode(addr string, opts ...interface{}) ([]byte, error)
- func (dec *AddressDecoderV2Base) AddressEncode(pub []byte, opts ...interface{}) (string, error)
- func (dec *AddressDecoderV2Base) AddressVerify(address string, opts ...interface{}) bool
- func (dec *AddressDecoderV2Base) CustomCreateAddress(account *AssetsAccount, newIndex uint64) (*Address, error)
- func (dec *AddressDecoderV2Base) PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)
- func (dec *AddressDecoderV2Base) PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)
- func (dec *AddressDecoderV2Base) RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)
- func (dec *AddressDecoderV2Base) SupportCustomCreateAddressFunction() bool
- func (dec *AddressDecoderV2Base) WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)
- type App
- type AssetsAccount
- type AssetsAdapter
- type AssetsAdapterBase
- func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder
- func (a *AssetsAdapterBase) GetAddressDecoderV2() AddressDecoderV2
- func (a *AssetsAdapterBase) GetAssetsLogger() *log.OWLogger
- func (a *AssetsAdapterBase) GetBlockScanner() BlockScanner
- func (a *AssetsAdapterBase) GetJsonRPCEndpoint() JsonRPCEndpoint
- func (a *AssetsAdapterBase) GetSmartContractDecoder() SmartContractDecoder
- func (a *AssetsAdapterBase) GetTransactionDecoder() TransactionDecoder
- func (a *AssetsAdapterBase) InitAssetsAdapter() error
- type AssetsConfig
- type AssetsConfigBase
- type Balance
- type BalanceModelType
- type BlockHeader
- type BlockScanAddressFunc
- type BlockScanNotificationObject
- type BlockScanNotify
- type BlockScanTargetFunc
- type BlockScanner
- type BlockScannerBase
- func (bs *BlockScannerBase) AddObserver(obj BlockScanNotificationObject) error
- func (bs *BlockScannerBase) CloseBlockScanner() error
- func (bs *BlockScannerBase) ExtractTransactionData(txid string, scanTargetFunc BlockScanTargetFunc) (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) SetBlockScanTargetFunc(scanTargetFunc BlockScanTargetFunc) error
- func (bs *BlockScannerBase) SetBlockScanWalletDAI(dai WalletDAI) error
- func (bs *BlockScannerBase) SetBlockchainDAI(dai BlockchainDAI) error
- func (bs *BlockScannerBase) SetRescanBlockHeight(height uint64) error
- func (bs *BlockScannerBase) SetTask(task func())
- func (bs *BlockScannerBase) Stop() error
- func (bs *BlockScannerBase) SupportBlockchainDAI() bool
- type Blockchain
- type BlockchainDAI
- type BlockchainDAIBase
- func (base *BlockchainDAIBase) DeleteUnscanRecordByHeight(height uint64, symbol string) error
- func (base *BlockchainDAIBase) DeleteUnscanRecordByID(id string, symbol string) error
- func (base *BlockchainDAIBase) GetCurrentBlockHead(symbol string) (*BlockHeader, error)
- func (base *BlockchainDAIBase) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)
- func (base *BlockchainDAIBase) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)
- func (base *BlockchainDAIBase) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)
- func (base *BlockchainDAIBase) SaveCurrentBlockHead(header *BlockHeader) error
- func (base *BlockchainDAIBase) SaveLocalBlockHead(header *BlockHeader) error
- func (base *BlockchainDAIBase) SaveUnscanRecord(record *UnscanRecord) error
- func (base *BlockchainDAIBase) SetMaxBlockCache(size uint64, symbol string) error
- type BlockchainLocal
- func (base *BlockchainLocal) DeleteUnscanRecordByHeight(height uint64, symbol string) error
- func (base *BlockchainLocal) DeleteUnscanRecordByID(id string, symbol string) error
- func (base *BlockchainLocal) GetCurrentBlockHead(symbol string) (*BlockHeader, error)
- func (base *BlockchainLocal) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)
- func (base *BlockchainLocal) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)
- func (base *BlockchainLocal) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)
- func (base *BlockchainLocal) SaveCurrentBlockHead(header *BlockHeader) error
- func (base *BlockchainLocal) SaveLocalBlockHead(header *BlockHeader) error
- func (base *BlockchainLocal) SaveUnscanRecord(record *UnscanRecord) error
- func (base *BlockchainLocal) SetMaxBlockCache(size uint64, symbol string) error
- type Bytes
- type CacheEntry
- type Coin
- type Error
- type FeesSupportAccount
- type ICacheManager
- type ImportAddress
- type JsonRPCEndpoint
- type JsonRPCEndpointBase
- type KeySignature
- type PublicKey
- type RawTransaction
- type RawTransactionWithError
- type Recharge
- type ScanTarget
- type SmartContract
- type SmartContractAction
- type SmartContractDecoder
- type SmartContractDecoderBase
- func (decoder *SmartContractDecoderBase) GetABIInfo(address string) (*ABIInfo, error)
- func (decoder *SmartContractDecoderBase) GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error)
- func (decoder *SmartContractDecoderBase) SetABIInfo(address string, abi ABIInfo) error
- type SmartContractRawTransaction
- type SmartContractTransaction
- 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) CreateSummaryRawTransactionWithError(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransactionWithError, error)
- func (decoder *TransactionDecoderBase) EstimateRawTransactionFee(wrapper WalletDAI, rawTx *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 TransactionSigner
- type TransactionSignerBase
- type TxExtractData
- type TxInput
- type TxOutPut
- type UnscanRecord
- 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
- 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) GetTransactionByTxID(txid, symbol string) ([]*Transaction, 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 WalletType
- type Withdraw
Constants ¶
const ( CurrentBlockHeaderKey = "current_block_header" CurrentBlockIncreaseIndexKey = "current_block_increase_index" BlockCacheIndexKey = "block_cache_index" )
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 //广播原始交易单失败 ErrInsufficientTokenBalanceOfAddress = 2009 //地址代币余额不足 /* 账户类别 */ ErrAccountNotFound = 3001 //账户不存在 ErrAddressNotFound = 3002 //地址不存在 ErrContractNotFound = 3003 //合约不存在 ErrAdressEncodeFailed = 3004 //地址编码失败 ErrAdressDecodeFailed = 3006 //地址解码失败 ErrNonceInvaild = 3007 //Nonce不正确 ErrAccountNotAddress = 3008 //账户没有地址 /* 网络类型 */ ErrCallFullNodeAPIFailed = 4001 //全节点API无法访问 ErrNetworkRequestFailed = 4002 //网络请求失败 /* 其他 */ ErrUnknownException = 9001 //未知异常情况 ErrSystemException = 9002 //系统程序异常情况 )
const ( // VERSION represent openw web framework version. VERSION = "1.0.0" // DEV is for develop DEV = "dev" // PROD is for production PROD = "prod" )
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 导出地址目录
Types ¶
type ABIDAI ¶ added in v1.4.1
type ABIDAI interface {
//@require
GetABIInfo(address string) (*ABIInfo, error)
//@require
SetABIInfo(address string, abi ABIInfo) error
}
ABIDAI abi data access interface
type ABIInfo ¶ added in v1.4.1
type ABIInfo struct {
Address string `json:"address"`
ABI interface{} `json:"abi"`
}
ABIInfo abi model
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, adapter AssetsAdapter, 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, adapter AssetsAdapter, 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 AddressDecoderV2 ¶ added in v1.4.1
type AddressDecoderV2 interface {
AddressDecoder
// AddressDecode 地址解析
AddressDecode(addr string, opts ...interface{}) ([]byte, error)
// AddressEncode 地址编码
AddressEncode(pub []byte, opts ...interface{}) (string, error)
// AddressVerify 地址校验
AddressVerify(address string, opts ...interface{}) bool
// CustomCreateAddress 自主实现创建账户地址
CustomCreateAddress(account *AssetsAccount, newIndex uint64) (*Address, error)
// SupportCustomCreateAddressFunction 支持创建地址实现
SupportCustomCreateAddressFunction() bool
}
AddressDecoderV2
type AddressDecoderV2Base ¶ added in v1.4.1
type AddressDecoderV2Base struct {
}
AddressDecoderV2
func (*AddressDecoderV2Base) AddressDecode ¶ added in v1.4.1
func (dec *AddressDecoderV2Base) AddressDecode(addr string, opts ...interface{}) ([]byte, error)
AddressDecode 地址解析
func (*AddressDecoderV2Base) AddressEncode ¶ added in v1.4.1
func (dec *AddressDecoderV2Base) AddressEncode(pub []byte, opts ...interface{}) (string, error)
AddressEncode 地址编码
func (*AddressDecoderV2Base) AddressVerify ¶ added in v1.4.12
func (dec *AddressDecoderV2Base) AddressVerify(address string, opts ...interface{}) bool
AddressVerify 地址校验
func (*AddressDecoderV2Base) CustomCreateAddress ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) CustomCreateAddress(account *AssetsAccount, newIndex uint64) (*Address, error)
CustomCreateAddress 创建账户地址
func (*AddressDecoderV2Base) PrivateKeyToWIF ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)
PrivateKeyToWIF 私钥转WIF
func (*AddressDecoderV2Base) PublicKeyToAddress ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)
PublicKeyToAddress 公钥转地址
func (*AddressDecoderV2Base) RedeemScriptToAddress ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)
RedeemScriptToAddress 多重签名赎回脚本转地址
func (*AddressDecoderV2Base) SupportCustomCreateAddressFunction ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) SupportCustomCreateAddressFunction() bool
SupportCustomCreateAddressFunction 支持创建地址实现
func (*AddressDecoderV2Base) WIFToPrivateKey ¶ added in v1.4.11
func (dec *AddressDecoderV2Base) WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)
WIFToPrivateKey WIF转私钥
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
//GetAddressDecodeV2 地址解析器V2
//如果实现了AddressDecoderV2,就无需实现AddressDecoder
//@required
GetAddressDecoderV2() AddressDecoderV2
//GetAddressDecode 地址解析器
//如果实现了AddressDecoderV2,就无需实现AddressDecoder
//@required
GetAddressDecode() AddressDecoder
//GetTransactionDecoder 交易单解析器
//@required
GetTransactionDecoder() TransactionDecoder
//GetBlockScanner 获取区块链扫描器
//@required
GetBlockScanner() BlockScanner
//GetSmartContractDecoder 获取智能合约解析器
//@optional
GetSmartContractDecoder() SmartContractDecoder
//GetAssetsLogger 获取资产日志工具
//@optional
GetAssetsLogger() *log.OWLogger
//GetJsonRPCEndpoint 获取全节点服务的JSON-RPC客户端
//@optional
GetJsonRPCEndpoint() JsonRPCEndpoint
}
AssetsAdapter 资产适配器接口 适配OpenWallet钱包体系的抽象接口
type AssetsAdapterBase ¶
type AssetsAdapterBase struct {
SymbolInfoBase
AssetsConfigBase
}
func (*AssetsAdapterBase) GetAddressDecode ¶
func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder
GetAddressDecode 地址解析器 如果实现了AddressDecoderV2,就无需实现AddressDecoder
func (*AssetsAdapterBase) GetAddressDecoderV2 ¶ added in v1.4.11
func (a *AssetsAdapterBase) GetAddressDecoderV2() AddressDecoderV2
GetAddressDecode 地址解析器 如果实现了AddressDecoderV2,就无需实现AddressDecoder
func (*AssetsAdapterBase) GetAssetsLogger ¶
func (a *AssetsAdapterBase) GetAssetsLogger() *log.OWLogger
GetAssetsLogger 获取资产账户日志工具
func (*AssetsAdapterBase) GetBlockScanner ¶
func (a *AssetsAdapterBase) GetBlockScanner() BlockScanner
GetBlockScanner 获取区块链扫描器
func (*AssetsAdapterBase) GetJsonRPCEndpoint ¶ added in v1.6.0
func (a *AssetsAdapterBase) GetJsonRPCEndpoint() JsonRPCEndpoint
GetJsonRPCEndpoint 获取全节点服务的JSON-RPC客户端 @optional
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 BalanceModelType ¶ added in v1.3.0
type BalanceModelType uint32
余额模型类别
const ( BalanceModelTypeAddress BalanceModelType = 0 //以地址记录余额 BalanceModelTypeAccount BalanceModelType = 1 //以账户记录余额 )
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" storm:"id"`
Version uint64 `json:"version"`
Time uint64 `json:"time"`
Fork bool `json:"fork"`
Symbol string `json:"symbol"`
}
BlockHeader 区块头
type BlockScanAddressFunc ¶
deprecated 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 BlockScanTargetFunc ¶ added in v1.3.0
type BlockScanTargetFunc func(target ScanTarget) (string, bool)
BlockScanTargetFunc 扫描对象是否存在算法 @return 对象所属源标识,是否存在
type BlockScanner ¶
type BlockScanner interface {
//deprecated
//Deprecated SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法
SetBlockScanAddressFunc(scanAddressFunc BlockScanAddressFunc) error
//SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法
//@required
SetBlockScanTargetFunc(scanTargetFunc BlockScanTargetFunc) error
//AddObserver 添加观测者
//@optional
AddObserver(obj BlockScanNotificationObject) error
//RemoveObserver 移除观测者
//@optional
RemoveObserver(obj BlockScanNotificationObject) error
//SetRescanBlockHeight 重置区块链扫描高度
//@required
SetRescanBlockHeight(height uint64) error
//Run 运行
//@optional
Run() error
//Stop 停止扫描
//@optional
Stop() error
//Pause 暂停扫描
//@optional
Pause() error
//Restart 继续扫描
//@optional
Restart() error
//InitBlockScanner 初始化扫描器
//@optional
InitBlockScanner() error
//CloseBlockScanner 关闭扫描器
//@optional
CloseBlockScanner() error
//ScanBlock 扫描指定高度的区块
//@required
ScanBlock(height uint64) error
//NewBlockNotify 新区块通知
//@optional
NewBlockNotify(header *BlockHeader) error
//GetCurrentBlockHeight 获取当前区块高度
//@required
GetCurrentBlockHeader() (*BlockHeader, error)
//GetGlobalMaxBlockHeight 获取区块链全网最大高度
//@optional
GetGlobalMaxBlockHeight() uint64
//GetScannedBlockHeight 获取已扫区块高度
//@required
GetScannedBlockHeight() uint64
//ExtractTransactionData 提取交易单数据
//@required
ExtractTransactionData(txid string, scanTargetFunc BlockScanTargetFunc) (map[string][]*TxExtractData, error)
//GetBalanceByAddress 查询地址余额
//@required
GetBalanceByAddress(address ...string) ([]*Balance, error)
//GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址
//返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算
//@optional
GetTransactionsByAddress(offset, limit int, coin Coin, address ...string) ([]*TxExtractData, error)
//SetBlockScanWalletDAI 设置区块扫描过程,上层提供一个钱包数据接口
//@optional
SetBlockScanWalletDAI(dai WalletDAI) error
//SetBlockchainDAI 设置区块链数据访问接口,读取持久化的区块数据
//@optional
SetBlockchainDAI(dai BlockchainDAI) error
//SupportBlockchainDAI 支持外部设置区块链数据访问接口
//@optional
SupportBlockchainDAI() bool
}
BlockScanner 区块扫描器 负责扫描新区块,给观察者推送订阅地址的新交易单。
type BlockScannerBase ¶
type BlockScannerBase struct {
AddressInScanning map[string]string //加入扫描的地址
Mu sync.RWMutex //读写锁
Observers map[BlockScanNotificationObject]bool //观察者
Scanning bool //是否扫描中
PeriodOfTask time.Duration
ScanAddressFunc BlockScanAddressFunc //区块扫描查询地址算法
ScanTargetFunc BlockScanTargetFunc //区块扫描查询地址算法
WalletDAI WalletDAI
BlockchainDAI BlockchainDAI
// 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, scanTargetFunc BlockScanTargetFunc) (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
deprecated SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法
func (*BlockScannerBase) SetBlockScanTargetFunc ¶ added in v1.3.0
func (bs *BlockScannerBase) SetBlockScanTargetFunc(scanTargetFunc BlockScanTargetFunc) error
SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法 @required
func (*BlockScannerBase) SetBlockScanWalletDAI ¶ added in v1.4.7
func (bs *BlockScannerBase) SetBlockScanWalletDAI(dai WalletDAI) error
SetBlockScanWalletDAI 设置区块扫描过程,上层提供一个钱包数据接口 @optional
func (*BlockScannerBase) SetBlockchainDAI ¶ added in v1.5.3
func (bs *BlockScannerBase) SetBlockchainDAI(dai BlockchainDAI) error
SetBlockchainDAI 设置区块链数据访问接口,读取持久化的区块数据 @optional
func (*BlockScannerBase) SetRescanBlockHeight ¶
func (bs *BlockScannerBase) SetRescanBlockHeight(height uint64) error
SetRescanBlockHeight 重置区块链扫描高度
func (*BlockScannerBase) SupportBlockchainDAI ¶ added in v1.5.3
func (bs *BlockScannerBase) SupportBlockchainDAI() bool
SupportBlockchainDAI 支持外部设置区块链数据访问接口 @optional
type Blockchain ¶
type BlockchainDAI ¶ added in v1.5.3
type BlockchainDAI interface {
SaveCurrentBlockHead(header *BlockHeader) error
GetCurrentBlockHead(symbol string) (*BlockHeader, error)
SaveLocalBlockHead(header *BlockHeader) error
GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)
SaveUnscanRecord(record *UnscanRecord) error
DeleteUnscanRecordByHeight(height uint64, symbol string) error
DeleteUnscanRecordByID(id string, symbol string) error
GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)
GetUnscanRecords(symbol string) ([]*UnscanRecord, error)
SetMaxBlockCache(max uint64, symbol string) error
}
BlockchainDAI 区块链数据访问接口
type BlockchainDAIBase ¶ added in v1.5.3
type BlockchainDAIBase int
BlockchainDAIBase 区块链数据访问接口基本实现
func (*BlockchainDAIBase) DeleteUnscanRecordByHeight ¶ added in v1.5.3
func (base *BlockchainDAIBase) DeleteUnscanRecordByHeight(height uint64, symbol string) error
func (*BlockchainDAIBase) DeleteUnscanRecordByID ¶ added in v1.5.3
func (base *BlockchainDAIBase) DeleteUnscanRecordByID(id string, symbol string) error
func (*BlockchainDAIBase) GetCurrentBlockHead ¶ added in v1.5.3
func (base *BlockchainDAIBase) GetCurrentBlockHead(symbol string) (*BlockHeader, error)
func (*BlockchainDAIBase) GetLocalBlockHeadByHeight ¶ added in v1.5.3
func (base *BlockchainDAIBase) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)
func (*BlockchainDAIBase) GetTransactionsByTxID ¶ added in v1.5.3
func (base *BlockchainDAIBase) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)
func (*BlockchainDAIBase) GetUnscanRecords ¶ added in v1.5.3
func (base *BlockchainDAIBase) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)
func (*BlockchainDAIBase) SaveCurrentBlockHead ¶ added in v1.5.3
func (base *BlockchainDAIBase) SaveCurrentBlockHead(header *BlockHeader) error
func (*BlockchainDAIBase) SaveLocalBlockHead ¶ added in v1.5.3
func (base *BlockchainDAIBase) SaveLocalBlockHead(header *BlockHeader) error
func (*BlockchainDAIBase) SaveUnscanRecord ¶ added in v1.5.3
func (base *BlockchainDAIBase) SaveUnscanRecord(record *UnscanRecord) error
func (*BlockchainDAIBase) SetMaxBlockCache ¶ added in v1.5.5
func (base *BlockchainDAIBase) SetMaxBlockCache(size uint64, symbol string) error
type BlockchainLocal ¶ added in v1.5.3
type BlockchainLocal struct {
// contains filtered or unexported fields
}
BlockchainLocal 区块链数据访问本地数据库实现
func NewBlockchainLocal ¶ added in v1.5.3
func NewBlockchainLocal(dbFile string, keepOpen bool) (*BlockchainLocal, error)
NewBlockchainLocal 加载区块链数据库
func (*BlockchainLocal) DeleteUnscanRecordByHeight ¶ added in v1.5.3
func (base *BlockchainLocal) DeleteUnscanRecordByHeight(height uint64, symbol string) error
func (*BlockchainLocal) DeleteUnscanRecordByID ¶ added in v1.5.3
func (base *BlockchainLocal) DeleteUnscanRecordByID(id string, symbol string) error
func (*BlockchainLocal) GetCurrentBlockHead ¶ added in v1.5.3
func (base *BlockchainLocal) GetCurrentBlockHead(symbol string) (*BlockHeader, error)
func (*BlockchainLocal) GetLocalBlockHeadByHeight ¶ added in v1.5.3
func (base *BlockchainLocal) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)
func (*BlockchainLocal) GetTransactionsByTxID ¶ added in v1.5.3
func (base *BlockchainLocal) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)
func (*BlockchainLocal) GetUnscanRecords ¶ added in v1.5.3
func (base *BlockchainLocal) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)
func (*BlockchainLocal) SaveCurrentBlockHead ¶ added in v1.5.3
func (base *BlockchainLocal) SaveCurrentBlockHead(header *BlockHeader) error
func (*BlockchainLocal) SaveLocalBlockHead ¶ added in v1.5.3
func (base *BlockchainLocal) SaveLocalBlockHead(header *BlockHeader) error
func (*BlockchainLocal) SaveUnscanRecord ¶ added in v1.5.3
func (base *BlockchainLocal) SaveUnscanRecord(record *UnscanRecord) error
func (*BlockchainLocal) SetMaxBlockCache ¶ added in v1.5.5
func (base *BlockchainLocal) SetMaxBlockCache(size uint64, symbol string) error
type CacheEntry ¶ added in v1.4.1
CacheEntry Cache Entry
type Coin ¶
type Coin struct {
Symbol string `json:"symbol"`
IsContract bool `json:"isContract"`
ContractID string `json:"contractID"`
Contract SmartContract `json:"contract"`
}
Coin 币种信息
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func (*Error) MarshalJSON ¶ added in v1.7.0
Json 错误信息JSON输出
func (*Error) UnmarshalJSON ¶ added in v1.7.0
type FeesSupportAccount ¶ added in v1.4.1
type ICacheManager ¶ added in v1.4.1
type ICacheManager interface {
Add(key string, value interface{}, duration time.Duration) error
Get(key string) (interface{}, bool)
GetCacheEntry(key string) (*CacheEntry, bool)
Remove(key string) (interface{}, bool)
Contains(key string) bool
Clear()
}
ICacheManager Cache Manager Interface
type JsonRPCEndpoint ¶ added in v1.6.0
type JsonRPCEndpoint interface {
//SendRPCRequest 发起JSON-RPC请求
//@optional
SendRPCRequest(method string, request interface{}) ([]byte, error)
//SupportJsonRPCEndpoint 是否开放客户端直接调用全节点的JSON-RPC方法
//@optional
SupportJsonRPCEndpoint() bool
}
JsonRPCEndpoint 全节点服务的JSON-RPC接口
type JsonRPCEndpointBase ¶ added in v1.6.0
type JsonRPCEndpointBase int
func (*JsonRPCEndpointBase) SendRPCRequest ¶ added in v1.6.0
func (base *JsonRPCEndpointBase) SendRPCRequest(method string, request interface{}) ([]byte, error)
SendRPCRequest 发起JSON-RPC请求 @optional
func (*JsonRPCEndpointBase) SupportJsonRPCEndpoint ¶ added in v1.6.0
func (base *JsonRPCEndpointBase) SupportJsonRPCEndpoint() bool
SupportJsonRPCEndpoint 是否开放客户端直接调用全节点的JSON-RPC方法 @optional
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"` //被签消息
RSV bool `json:"rsv"` //签名是否需要合并V
}
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
func (*RawTransaction) GetExtParam ¶ added in v1.4.3
func (rawtx *RawTransaction) GetExtParam() gjson.Result
GetExtParam
func (*RawTransaction) SetExtParam ¶ added in v1.4.3
func (rawtx *RawTransaction) SetExtParam(key string, value interface{}) error
SetExtParam
type RawTransactionWithError ¶ added in v1.4.1
type RawTransactionWithError struct {
RawTx *RawTransaction `json:"rawTx"`
Error *Error `json:"error"`
}
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 `json:"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"` //deprecated, 使用ExtParam扩展
Index uint64 `json:"index"` //@required
Received bool
CreateAt int64 `json:"createdAt"` //@required
Delete bool
TxType uint64 `json:"txType"` // @required 0:转账,1:合约调用(发生于主链)
}
type ScanTarget ¶ added in v1.3.0
type ScanTarget struct {
Address string //地址字符串
PublicKey string //地址公钥
Alias string //地址别名,可绑定用户别名
Symbol string //币种类别
BalanceModelType BalanceModelType //余额模型类别
}
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 SmartContractAction ¶ added in v1.6.0
type SmartContractDecoder ¶
type SmartContractDecoder interface {
ABIDAI
//GetTokenBalanceByAddress 查询地址token余额列表
GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error)
}
SmartContractDecoder 智能合约解析器
type SmartContractDecoderBase ¶
type SmartContractDecoderBase struct {
}
func (*SmartContractDecoderBase) GetABIInfo ¶ added in v1.4.1
func (decoder *SmartContractDecoderBase) GetABIInfo(address string) (*ABIInfo, error)
GetABIInfo get abi
func (*SmartContractDecoderBase) GetTokenBalanceByAddress ¶
func (decoder *SmartContractDecoderBase) GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error)
func (*SmartContractDecoderBase) SetABIInfo ¶ added in v1.4.1
func (decoder *SmartContractDecoderBase) SetABIInfo(address string, abi ABIInfo) error
SetABIInfo set abi
type SmartContractRawTransaction ¶
type SmartContractRawTransaction struct {
Symbol string `json:"symbol"` //@required 区块链类型标识
TxID string `json:"txID"` //交易单ID,广播后会生成
Sid string `json:"sid"` //@required 业务订单号,保证业务不重复交易而用
RawHex string `json:"rawHex"` //@required 区块链协议构造的交易原生数据
Account *AssetsAccount `json:"account"` //@required 创建交易单的账户
Signatures map[string][]*KeySignature `json:"signatures"` //拥有者accountID: []未花签名
IsBuilt bool `json:"isBuilt"` //是否完成构建建议单
IsCompleted bool `json:"isComplete"` //是否完成所有签名
IsSubmit bool `json:"isSubmit"` //是否已广播
CallParam string `json:"callParam"` //调用参数,用于调用智能合约,json结构
}
SmartContractRawTransaction 智能合约原始交易单
type SmartContractTransaction ¶ added in v1.6.0
type SmartContractTransaction struct {
WxID string `json:"wxid" storm:"id"` //@required 通过GenTransactionWxID计算
TxID string `json:"txid"` //@required
AccountID string `json:"accountID"` //@required 创建交易单的账户
Actions []*SmartContractAction `json:"actions"` //@required 执行事件, 例如:合约的Transfer事件
BlockHash string `json:"blockHash"` //@required
BlockHeight uint64 `json:"blockHeight"` //@required
SubmitTime int64 `json:"submitTime"` //@required
ConfirmTime int64 `json:"confirmTime"` //@required
Status string `json:"status"` //链上状态,0:失败,1:成功
Reason string `json:"reason"` //失败原因,失败状态码
CallParam string `json:"callParam"` //调用参数,用于调用智能合约,json结构
}
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"` //汇总的未花交易大于确认数
FeesSupportAccount *FeesSupportAccount `json:"feesSupportAccount"` //手续费支持账户
ExtParam string `json:"extParam"` //扩展参数,用于调用智能合约,json结构
}
SummaryRawTransaction 汇总交易
func (*SummaryRawTransaction) GetExtParam ¶ added in v1.4.3
func (sumRawtx *SummaryRawTransaction) GetExtParam() gjson.Result
GetExtParam
func (*SummaryRawTransaction) SetExtParam ¶ added in v1.4.3
func (sumRawtx *SummaryRawTransaction) SetExtParam(key string, value interface{}) error
SetExtParam
type SymbolInfo ¶
type SymbolInfo interface {
//CurveType 曲线类型
CurveType() uint32
//FullName 币种全名
FullName() string
//Symbol 币种标识
Symbol() string
//Decimal 小数位精度
Decimal() int32
//BalanceModelType 余额模型类别
BalanceModelType() BalanceModelType
}
type SymbolInfoBase ¶
type SymbolInfoBase struct {
}
func (*SymbolInfoBase) BalanceModelType ¶
func (s *SymbolInfoBase) BalanceModelType() BalanceModelType
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"` // @required 0:转账, 1:合约调用(发生于主链), >100: 自定义,可以在TxAction填说明
TxAction string `json:"txAction"` // 执行事件, 例如:合约的Transfer事件
Confirm int64 `json:"confirm"`
BlockHash string `json:"blockHash"` //@required
BlockHeight uint64 `json:"blockHeight"` //@required
IsMemo bool `json:"isMemo"`
Memo string `json:"memo"` //deprecated, 使用ExtParam扩展
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)
//EstimateRawTransactionFee 预估手续费
EstimateRawTransactionFee(wrapper WalletDAI, rawTx *RawTransaction) error
//CreateSummaryRawTransactionWithError 创建汇总交易,返回能原始交易单数组(包含带错误的原始交易单)
CreateSummaryRawTransactionWithError(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransactionWithError, 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) CreateSummaryRawTransactionWithError ¶ added in v1.4.1
func (decoder *TransactionDecoderBase) CreateSummaryRawTransactionWithError(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransactionWithError, error)
CreateSummaryRawTransactionWithError 创建汇总交易,返回能原始交易单数组(包含带错误的原始交易单)
func (*TransactionDecoderBase) EstimateRawTransactionFee ¶ added in v1.4.1
func (decoder *TransactionDecoderBase) EstimateRawTransactionFee(wrapper WalletDAI, rawTx *RawTransaction) error
EstimateRawTransactionFee 预估手续费
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 TransactionSigner ¶ added in v1.4.1
type TransactionSigner interface {
// SignTransactionHash 交易哈希签名算法
// required
SignTransactionHash(msg []byte, privateKey []byte, eccType uint32) ([]byte, error)
}
TransactionSigner 交易签署器
type TransactionSignerBase ¶ added in v1.4.1
type TransactionSignerBase struct {
}
func (*TransactionSignerBase) SignTransactionHash ¶ added in v1.4.1
func (singer *TransactionSignerBase) SignTransactionHash(msg []byte, privateKey []byte, eccType uint32) ([]byte, error)
SignTransactionHash 交易哈希签名算法 required
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 UnscanRecord ¶ added in v1.5.3
type UnscanRecord struct {
ID string `storm:"id"` // primary key
BlockHeight uint64 `json:"blockHeight"`
TxID string `json:"txid"`
Reason string `json:"reason"`
Symbol string `json:"symbol"`
}
UnscanRecord 扫描失败的区块及交易
func NewUnscanRecord ¶ added in v1.5.3
func NewUnscanRecord(height uint64, txID, reason, symbol string) *UnscanRecord
NewUnscanRecord new UnscanRecord
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 NewWatchOnlyWallet ¶
NewWatchOnlyWallet 只读钱包,用于观察冷钱包 Deprecated
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 把钱包作为一个单资产账户来使用
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)
//获取钱包所创建的交易单
GetTransactionByTxID(txid, symbol string) ([]*Transaction, 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) GetTransactionByTxID ¶ added in v1.4.7
func (base *WalletDAIBase) GetTransactionByTxID(txid, symbol string) ([]*Transaction, 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