openwallet

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: GPL-3.0 Imports: 25 Imported by: 85

Documentation

Index

Constants

View Source
const (
	CurrentBlockHeaderKey        = "current_block_header"
	CurrentBlockIncreaseIndexKey = "current_block_increase_index"
	BlockCacheIndexKey           = "block_cache_index"
)
View Source
const (
	ScanTargetTypeAccountAddress  = 0
	ScanTargetTypeAccountAlias    = 1
	ScanTargetTypeContractAddress = 2
	ScanTargetTypeContractAlias   = 3
	ScanTargetTypeAddressPubKey   = 4
	ScanTargetTypeAddressMemo     = 5
)

扫描目标类型

View Source
const (
	WalletTypeSingle = 0
	WalletTypeMulti  = 1
)
View Source
const (

	/// 私钥字节长度
	PrivateKeyLength = 32

	/// 公钥字节长度(压缩)
	PublicKeyLengthCompressed = 33

	/// 公钥字节长度(未压缩)
	PublicKeyLengthUncompressed = 65
)
View Source
const (
	// 0:未知协议,1:ERC20协议,2:ERC721协议,3:ERC1155协议
	InterfaceTypeUnknown = ""
	InterfaceTypeERC20   = "erc20"
	InterfaceTypeERC721  = "erc721"
	InterfaceTypeERC1155 = "erc1155"
)
View Source
const (
	// 0:hex字符串,1:json字符串,2:base64字符串
	TxRawTypeHex    = 0
	TxRawTypeJSON   = 1
	TxRawTypeBase64 = 2
)
View Source
const (
	SmartContractCallResultStatusFail    = 0
	SmartContractCallResultStatusSuccess = 1
)
View Source
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 //网络请求失败

	/* 智能合约类 */
	ErrContractCallMsgInvalid                  = 5001 //合约调用参数无效
	ErrCreateRawSmartContractTransactionFailed = 5002 //创建原始合约交易单失败
	ErrSubmitRawSmartContractTransactionFailed = 5003 //广播原始合约交易单失败

	/* 其他 */
	ErrUnknownException = 9001 //未知异常情况
	ErrSystemException  = 9002 //系统程序异常情况
)
View Source
const (
	NFTEventTypeTransferred = 0 //转账
	NFTEventTypeMinted      = 1 //铸造
	NFTEventTypeBurned      = 2 //销毁
)

NFTEventType

View Source
const (
	// VERSION represent openw web framework version.
	VERSION = "1.0.0"
	// DEV is for develop
	DEV = "dev"
	// PROD is for production
	PROD = "prod"
)
View Source
const (
	TxStatusSuccess = "1" //成功
	TxStatusFail    = "0" //失败
)

交易单状态

Variables

View Source
var (
	//ID首字节的标识
	AccountIDVer = []byte{0x09}
)

Functions

func GenAccountID

func GenAccountID(publicKey string) string

GenAccountID 计算publicKey的AccountID publickey为OW编码后

func GenAccountIDByHex

func GenAccountIDByHex(publicKeyHex string) string

GenAccountIDByHex 计算publicKey的AccountID publickey为HEX传

func GenContractID

func GenContractID(symbol, address string) string

GenContractID 合约ID

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 GenTransactionWxID2(txid string, coinsymbol string, contractId string) string

func GenTxInputSID

func GenTxInputSID(txid string, coinsymbol string, contractId string, n uint64) string

func GenTxOutPutSID

func GenTxOutPutSID(txid string, coinsymbol string, contractId string, n uint64) string

func GetBackupDir

func GetBackupDir(symbol string) string

GetBackupDir 钱包备份目录

func GetDBDir

func GetDBDir(symbol string) string

GetDBDir 钱包数据库目录

func GetDataDir

func GetDataDir(symbol string) string

GetDataDir 钱包数据目录

func GetExportAddressDir

func GetExportAddressDir(symbol string) string

GetExportAddressDir 导出地址目录

func GetKeyDir

func GetKeyDir(symbol string) string

GetKeyDir 密钥目录

Types

type ABIDAI

type ABIDAI interface {
	//@require
	GetABIInfo(address string) (*ABIInfo, error)
	//@require
	SetABIInfo(address string, abi ABIInfo) error
}

ABIDAI abi data access interface

type ABIInfo

type ABIInfo struct {
	Address string      `json:"address"`
	ABI     interface{} `json:"abi"`
}

ABIInfo abi model

type AccountOwner

type AccountOwner interface {
}

AccountOwner 账户拥有者接口

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

func NewAddress(json gjson.Result) *Address

type AddressCreateResult

type AddressCreateResult struct {
	Success bool
	Err     error
	Address *Address
}

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

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

type AddressDecoderV2Base struct {
}

AddressDecoderV2

func (*AddressDecoderV2Base) AddressDecode

func (dec *AddressDecoderV2Base) AddressDecode(addr string, opts ...interface{}) ([]byte, error)

AddressDecode 地址解析

func (*AddressDecoderV2Base) AddressEncode

func (dec *AddressDecoderV2Base) AddressEncode(pub []byte, opts ...interface{}) (string, error)

AddressEncode 地址编码

func (*AddressDecoderV2Base) AddressVerify

func (dec *AddressDecoderV2Base) AddressVerify(address string, opts ...interface{}) bool

AddressVerify 地址校验

func (*AddressDecoderV2Base) CustomCreateAddress

func (dec *AddressDecoderV2Base) CustomCreateAddress(account *AssetsAccount, newIndex uint64) (*Address, error)

CustomCreateAddress 创建账户地址

func (*AddressDecoderV2Base) PrivateKeyToWIF

func (dec *AddressDecoderV2Base) PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)

PrivateKeyToWIF 私钥转WIF

func (*AddressDecoderV2Base) PublicKeyToAddress

func (dec *AddressDecoderV2Base) PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)

PublicKeyToAddress 公钥转地址

func (*AddressDecoderV2Base) RedeemScriptToAddress

func (dec *AddressDecoderV2Base) RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)

RedeemScriptToAddress 多重签名赎回脚本转地址

func (*AddressDecoderV2Base) SupportCustomCreateAddressFunction

func (dec *AddressDecoderV2Base) SupportCustomCreateAddressFunction() bool

SupportCustomCreateAddressFunction 支持创建地址实现

func (*AddressDecoderV2Base) WIFToPrivateKey

func (dec *AddressDecoderV2Base) WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)

WIFToPrivateKey WIF转私钥

type App

type App struct {
	AppID   string `json:"appID"`
	AppName string `json:"appID"`
}

App

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 NewUserAccount

func NewUserAccount() *AssetsAccount

NewUserAccount 创建账户

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

	//GetNFTContractDecoder 获取NFT智能合约解析器
	//@optional
	GetNFTContractDecoder() NFTContractDecoder
}

AssetsAdapter 资产适配器接口 适配OpenWallet钱包体系的抽象接口

type AssetsAdapterBase

type AssetsAdapterBase struct {
	SymbolInfoBase
	AssetsConfigBase
}

func (*AssetsAdapterBase) GetAddressDecode

func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder

GetAddressDecode 地址解析器 如果实现了AddressDecoderV2,就无需实现AddressDecoder

func (*AssetsAdapterBase) GetAddressDecoderV2

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

func (a *AssetsAdapterBase) GetJsonRPCEndpoint() JsonRPCEndpoint

GetJsonRPCEndpoint 获取全节点服务的JSON-RPC客户端 @optional

func (*AssetsAdapterBase) GetNFTContractDecoder added in v2.4.0

func (a *AssetsAdapterBase) GetNFTContractDecoder() NFTContractDecoder

GetNFTContractDecoder 获取NFT智能合约解析器 @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 Balance

type Balance struct {
	Symbol           string
	AccountID        string
	Address          string
	ConfirmBalance   string
	UnconfirmBalance string
	Balance          string
}

type BalanceModelType

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

type BlockScanAddressFunc func(address string) (string, bool)

deprecated BlockScanAddressFunc 扫描地址是否存在算法 @return 地址所属源标识,是否存在

type BlockScanNotificationObject

type BlockScanNotificationObject interface {

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

	//BlockExtractDataNotify 区块提取结果通知
	//@required
	BlockExtractDataNotify(sourceKey string, data *TxExtractData) error

	//BlockExtractSmartContractDataNotify 区块提取智能合约交易结果通知
	//@param sourceKey: 为contractID
	//@param data: 合约交易回执
	//@required
	BlockExtractSmartContractDataNotify(sourceKey string, data *SmartContractReceipt) error
}

BlockScanNotificationObject 扫描被通知对象

type BlockScanNotify

type BlockScanNotify func(header *BlockHeader)

BlockScanNotify 新区块扫描完成通知 @param txs 每扫完区块链,与地址相关的交易到

type BlockScanTargetFunc

type BlockScanTargetFunc func(target ScanTarget) (string, bool)

deprecated BlockScanTargetFunc 扫描对象是否存在算法 @return 对象所属源标识,是否存在

type BlockScanTargetFuncV2

type BlockScanTargetFuncV2 func(target ScanTargetParam) ScanTargetResult

BlockScanTargetFuncV2 扫描智能合约是否存在算法 @return 对象所属源标识,是否存在

type BlockScanner

type BlockScanner interface {

	//deprecated
	// SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法
	SetBlockScanAddressFunc(scanAddressFunc BlockScanAddressFunc) error

	//deprecated
	// SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法
	SetBlockScanTargetFunc(scanTargetFunc BlockScanTargetFunc) error

	//SetBlockScanTargetFuncV2 设置区块扫描过程,查找扫描对象过程方法
	//@required
	SetBlockScanTargetFuncV2(scanTargetFunc BlockScanTargetFuncV2) 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

	//ExtractTransactionAndReceiptData 提取交易单及交易回执数据
	//@required
	ExtractTransactionAndReceiptData(txid string, scanTargetFunc BlockScanTargetFuncV2) (map[string][]*TxExtractData, map[string]*SmartContractReceipt, error)

	//GetBlockchainSyncStatus 获取当前区块链同步状态
	//@optional
	GetBlockchainSyncStatus() (*BlockchainSyncStatus, 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  //区块扫描查询地址算法
	ScanTargetFunc   BlockScanTargetFunc   //区块扫描查询地址算法
	ScanTargetFuncV2 BlockScanTargetFuncV2 //区块扫描查询地址算法

	WalletDAI     WalletDAI
	BlockchainDAI BlockchainDAI
	// contains filtered or unexported fields
}

BlockScannerBase 区块链扫描器基本结构实现

func NewBlockScannerBase

func NewBlockScannerBase() *BlockScannerBase

NewBTCBlockScanner 创建区块链扫描器

func (*BlockScannerBase) AddObserver

func (bs *BlockScannerBase) AddObserver(obj BlockScanNotificationObject) error

AddObserver 添加观测者

func (*BlockScannerBase) CloseBlockScanner

func (bs *BlockScannerBase) CloseBlockScanner() error

CloseBlockScanner 关闭扫描器

func (*BlockScannerBase) ExtractTransactionAndReceiptData

func (bs *BlockScannerBase) ExtractTransactionAndReceiptData(txid string, scanTargetFunc BlockScanTargetFuncV2) (map[string][]*TxExtractData, map[string]*SmartContractReceipt, error)

ExtractTransactionAndReceiptData 提取交易单及交易回执数据 @required

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) GetBlockchainSyncStatus added in v2.5.0

func (bs *BlockScannerBase) GetBlockchainSyncStatus() (*BlockchainSyncStatus, error)

GetBlockchainSyncStatus 获取当前区块链同步状态 @optional

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

func (bs *BlockScannerBase) IsClose() bool

IsClose 是否已经关闭

func (*BlockScannerBase) NewBlockNotify

func (bs *BlockScannerBase) NewBlockNotify(block *BlockHeader) error

NewBlockNotify 获得新区块后,发送到通知通道

func (*BlockScannerBase) Pause

func (bs *BlockScannerBase) Pause() error

Pause 暂停扫描

func (*BlockScannerBase) RemoveObserver

func (bs *BlockScannerBase) RemoveObserver(obj BlockScanNotificationObject) error

RemoveObserver 移除观测者

func (*BlockScannerBase) Restart

func (bs *BlockScannerBase) Restart() error

Restart 继续扫描

func (*BlockScannerBase) Run

func (bs *BlockScannerBase) Run() error

Run 运行

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

func (bs *BlockScannerBase) SetBlockScanTargetFunc(scanTargetFunc BlockScanTargetFunc) error

deprecated SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法 @required

func (*BlockScannerBase) SetBlockScanTargetFuncV2

func (bs *BlockScannerBase) SetBlockScanTargetFuncV2(scanTargetFuncV2 BlockScanTargetFuncV2) error

SetBlockScanTargetFuncV2 设置区块扫描过程,查找扫描对象过程方法 @required

func (*BlockScannerBase) SetBlockScanWalletDAI

func (bs *BlockScannerBase) SetBlockScanWalletDAI(dai WalletDAI) error

SetBlockScanWalletDAI 设置区块扫描过程,上层提供一个钱包数据接口 @optional

func (*BlockScannerBase) SetBlockchainDAI

func (bs *BlockScannerBase) SetBlockchainDAI(dai BlockchainDAI) error

SetBlockchainDAI 设置区块链数据访问接口,读取持久化的区块数据 @optional

func (*BlockScannerBase) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*BlockScannerBase) SetTask

func (bs *BlockScannerBase) SetTask(task func())

SetTask

func (*BlockScannerBase) Stop

func (bs *BlockScannerBase) Stop() error

Stop 停止扫描

func (*BlockScannerBase) SupportBlockchainDAI

func (bs *BlockScannerBase) SupportBlockchainDAI() bool

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

type Blockchain

type Blockchain struct {
	Blocks     uint64
	Headers    uint64
	ScanHeight uint64
}

type BlockchainDAI

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
	SaveTransaction(tx *Transaction) error
}

BlockchainDAI 区块链数据访问接口

type BlockchainDAIBase

type BlockchainDAIBase int

BlockchainDAIBase 区块链数据访问接口基本实现

func (*BlockchainDAIBase) DeleteUnscanRecordByHeight

func (base *BlockchainDAIBase) DeleteUnscanRecordByHeight(height uint64, symbol string) error

func (*BlockchainDAIBase) DeleteUnscanRecordByID

func (base *BlockchainDAIBase) DeleteUnscanRecordByID(id string, symbol string) error

func (*BlockchainDAIBase) GetCurrentBlockHead

func (base *BlockchainDAIBase) GetCurrentBlockHead(symbol string) (*BlockHeader, error)

func (*BlockchainDAIBase) GetLocalBlockHeadByHeight

func (base *BlockchainDAIBase) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)

func (*BlockchainDAIBase) GetTransactionsByTxID

func (base *BlockchainDAIBase) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)

func (*BlockchainDAIBase) GetUnscanRecords

func (base *BlockchainDAIBase) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)

func (*BlockchainDAIBase) SaveCurrentBlockHead

func (base *BlockchainDAIBase) SaveCurrentBlockHead(header *BlockHeader) error

func (*BlockchainDAIBase) SaveLocalBlockHead

func (base *BlockchainDAIBase) SaveLocalBlockHead(header *BlockHeader) error

func (*BlockchainDAIBase) SaveTransaction added in v2.3.0

func (base *BlockchainDAIBase) SaveTransaction(tx *Transaction) error

func (*BlockchainDAIBase) SaveUnscanRecord

func (base *BlockchainDAIBase) SaveUnscanRecord(record *UnscanRecord) error

func (*BlockchainDAIBase) SetMaxBlockCache

func (base *BlockchainDAIBase) SetMaxBlockCache(size uint64, symbol string) error

type BlockchainLocal

type BlockchainLocal struct {
	BlockchainDAIBase
	// contains filtered or unexported fields
}

BlockchainLocal 区块链数据访问本地数据库实现

func NewBlockchainLocal

func NewBlockchainLocal(dbFile string, keepOpen bool) (*BlockchainLocal, error)

NewBlockchainLocal 加载区块链数据库

func (*BlockchainLocal) DeleteUnscanRecordByHeight

func (base *BlockchainLocal) DeleteUnscanRecordByHeight(height uint64, symbol string) error

func (*BlockchainLocal) DeleteUnscanRecordByID

func (base *BlockchainLocal) DeleteUnscanRecordByID(id string, symbol string) error

func (*BlockchainLocal) GetCurrentBlockHead

func (base *BlockchainLocal) GetCurrentBlockHead(symbol string) (*BlockHeader, error)

func (*BlockchainLocal) GetLocalBlockHeadByHeight

func (base *BlockchainLocal) GetLocalBlockHeadByHeight(height uint64, symbol string) (*BlockHeader, error)

func (*BlockchainLocal) GetTransactionsByTxID

func (base *BlockchainLocal) GetTransactionsByTxID(txid, symbol string) ([]*Transaction, error)

func (*BlockchainLocal) GetUnscanRecords

func (base *BlockchainLocal) GetUnscanRecords(symbol string) ([]*UnscanRecord, error)

func (*BlockchainLocal) SaveCurrentBlockHead

func (base *BlockchainLocal) SaveCurrentBlockHead(header *BlockHeader) error

func (*BlockchainLocal) SaveLocalBlockHead

func (base *BlockchainLocal) SaveLocalBlockHead(header *BlockHeader) error

func (*BlockchainLocal) SaveTransaction added in v2.3.0

func (base *BlockchainLocal) SaveTransaction(tx *Transaction) error

func (*BlockchainLocal) SaveUnscanRecord

func (base *BlockchainLocal) SaveUnscanRecord(record *UnscanRecord) error

func (*BlockchainLocal) SetMaxBlockCache

func (base *BlockchainLocal) SetMaxBlockCache(size uint64, symbol string) error

type BlockchainSyncStatus added in v2.5.0

type BlockchainSyncStatus struct {
	NetworkBlockHeight uint64
	CurrentBlockHeight uint64
	Syncing            bool
}

type Bytes

type Bytes []byte

字节流

type CacheEntry

type CacheEntry struct {
	Key        string
	Value      interface{}
	Expiration int64
}

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 ConvertError

func ConvertError(err error) *Error

ConvertError error转OWError

func Errorf

func Errorf(code uint64, format string, a ...interface{}) *Error

Errorf 生成OWError

func NewError

func NewError(code uint64, text string) *Error

NewError 生成OWError

func (*Error) Code

func (err *Error) Code() uint64

Code 错误编号

func (*Error) Error

func (err *Error) Error() string

Error 错误信息

func (*Error) MarshalJSON

func (err *Error) MarshalJSON() ([]byte, error)

Json 错误信息JSON输出

func (*Error) UnmarshalJSON

func (err *Error) UnmarshalJSON(b []byte) error

type FeesSupportAccount

type FeesSupportAccount struct {
	AccountID        string `json:"accountID"`        //提供手续费支持的账户
	FixSupportAmount string `json:"fixSupportAmount"` //每次转账固定数量
	FeesSupportScale string `json:"feesScale"`        //每次转账消耗手续费的倍率
}

type ICacheManager

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 ImportAddress

type ImportAddress struct {
	Address `storm:"inline"`
}

ImportAddress 待导入的地址记录

type JsonRPCEndpoint

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

type JsonRPCEndpointBase int

func (*JsonRPCEndpointBase) SendRPCRequest

func (base *JsonRPCEndpointBase) SendRPCRequest(method string, request interface{}) ([]byte, error)

SendRPCRequest 发起JSON-RPC请求 @optional

func (*JsonRPCEndpointBase) SupportJsonRPCEndpoint

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 NFT added in v2.4.0

type NFT struct {
	Symbol   string `json:"symbol"` //@required 主币的symbol
	Address  string `json:"address"`
	Token    string `json:"token"` //@required NFT的symbol
	Protocol string `json:"protocol"`
	Name     string `json:"name"`
	TokenID  string `json:"tokenID"`
}

type NFTApproval added in v2.4.0

type NFTApproval struct {
	Token    NFT    `json:"token"`    //@required nft
	Owner    string `json:"owner"`    //@required nft拥有者
	Operator string `json:"operator"` //required 被授权的操作者
	IsAll    bool   `json:"isAll"`    //@required 是否全部NFT,true:token = null,false,token = *NFT
}

type NFTBalance added in v2.4.0

type NFTBalance struct {
	NFT     *NFT
	Balance string
}

type NFTContractDecoder added in v2.4.0

type NFTContractDecoder interface {
	//GetNFTBalanceByAddress 查询地址NFT余额列表
	GetNFTBalanceByAddress(nft *NFT, owner string) (*NFTBalance, *Error)
	// GetNFTBalanceByAddressBatch 查询地址NFT余额列表
	GetNFTBalanceByAddressBatch(nft []*NFT, owner []string) ([]*NFTBalance, *Error)
	//GetNFTOwnerByTokenID 查询地址token的拥有者
	GetNFTOwnerByTokenID(nft *NFT) (*NFTOwner, *Error)
	//GetMetaDataOfNFT 查询NFT的MetaData
	GetMetaDataOfNFT(nft *NFT) (*NFTMetaData, *Error)
	//GetNFTTransfer 从event解析NFT转账信息
	GetNFTTransfer(event *SmartContractEvent) (*NFTTransfer, *Error)
}

NFTContractDecoder NFT智能合约解析器

type NFTContractDecoderBase added in v2.4.0

type NFTContractDecoderBase struct {
}

func (*NFTContractDecoderBase) GetMetaDataOfNFT added in v2.4.0

func (decoder *NFTContractDecoderBase) GetMetaDataOfNFT(nft *NFT) (*NFTMetaData, *Error)

GetMetaDataOfNFT 查询NFT的MetaData

func (*NFTContractDecoderBase) GetNFTBalanceByAddress added in v2.4.0

func (decoder *NFTContractDecoderBase) GetNFTBalanceByAddress(nft *NFT, owner string) (*NFTBalance, *Error)

GetNFTBalanceByAddress 查询地址NFT余额列表 NFT.TokenID为空则查询合约下拥有者所NFT数量。

func (*NFTContractDecoderBase) GetNFTBalanceByAddressBatch added in v2.4.0

func (decoder *NFTContractDecoderBase) GetNFTBalanceByAddressBatch(nft []*NFT, owner []string) ([]*NFTBalance, *Error)

GetNFTBalanceByAddressBatch 查询地址NFT余额列表

func (*NFTContractDecoderBase) GetNFTOwnerByTokenID added in v2.4.0

func (decoder *NFTContractDecoderBase) GetNFTOwnerByTokenID(nft *NFT) (*NFTOwner, *Error)

GetNFTOwnerByTokenID 查询地址token的拥有者

func (*NFTContractDecoderBase) GetNFTTransfer added in v2.4.0

func (decoder *NFTContractDecoderBase) GetNFTTransfer(event *SmartContractEvent) (*NFTTransfer, *Error)

GetNFTTransfer 从event解析NFT转账信息

type NFTMetaData added in v2.4.0

type NFTMetaData struct {
	NFT *NFT
	URI string
}

type NFTOwner added in v2.4.0

type NFTOwner struct {
	NFT   *NFT
	Owner string
}

type NFTTransfer added in v2.4.0

type NFTTransfer struct {
	Tokens    []NFT    `json:"tokens"`    //@required nft
	Operator  string   `json:"operator"`  //required 被授权转账的操作者
	From      string   `json:"from"`      //@required 发送者
	To        string   `json:"to"`        //@required 接受者
	Amounts   []string `json:"amounts"`   //@required erc1155 token有数量
	EventType uint64   `json:"eventType"` //@required
}

type PublicKey

type PublicKey []byte

公钥

func BytesToPublicKey

func BytesToPublicKey(b []byte) PublicKey

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

func (rawtx *RawTransaction) GetExtParam() gjson.Result

GetExtParam

func (*RawTransaction) SetExtParam

func (rawtx *RawTransaction) SetExtParam(key string, value interface{}) error

SetExtParam

type RawTransactionWithError

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

type ScanTarget struct {
	Address          string           //地址字符串
	PublicKey        string           //地址公钥
	Alias            string           //地址别名,可绑定用户别名
	Symbol           string           //币种类别
	BalanceModelType BalanceModelType //余额模型类别
}

type ScanTargetParam

type ScanTargetParam struct {
	ScanTarget     string //地址字符串
	Symbol         string //主链类别
	ScanTargetType uint64 // 0: 账户地址,1:账户别名,2:合约地址,3:合约别名,4:地址公钥,5:地址备注
}

ScanTargetParam 扫描目标参数

type ScanTargetResult

type ScanTargetResult struct {
	SourceKey string //关联键,地址关联的账户或ID等等
	Exist     bool   //是否存在

	//对象指针,对应ScanTargetType:
	//0:openwallet.Address
	//1:openwallet.Account
	//2: openwallet SmartContract
	//3: openwallet SmartContract
	//4: openwallet Address
	//5: openwallet Address
	TargetInfo interface{}
}

ScanTargetResult 扫描结果

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"`
	// contains filtered or unexported fields
}

func (*SmartContract) GetABI

func (contract *SmartContract) GetABI() string

GetABI

func (*SmartContract) SetABI

func (contract *SmartContract) SetABI(abiJson string)

SetABI

type SmartContractCallResult

type SmartContractCallResult struct {
	Method    string `json:"method"`    //调用方法
	Value     string `json:"value"`     //json结果
	RawHex    string `json:"rawHex"`    //16进制字符串结果
	Status    uint64 `json:"status"`    //0:成功,1:失败
	Exception string `json:"exception"` //异常错误
}

SmartContractCallResult 调用结果,不产生交易

type SmartContractDecoder

type SmartContractDecoder interface {
	ABIDAI

	//GetTokenBalanceByAddress 查询地址token余额列表
	GetTokenBalanceByAddress(contract SmartContract, address ...string) ([]*TokenBalance, error)
	//调用合约ABI方法
	CallSmartContractABI(wrapper WalletDAI, rawTx *SmartContractRawTransaction) (*SmartContractCallResult, *Error)
	//创建原始交易单
	CreateSmartContractRawTransaction(wrapper WalletDAI, rawTx *SmartContractRawTransaction) *Error
	//SubmitRawTransaction 广播交易单
	SubmitSmartContractRawTransaction(wrapper WalletDAI, rawTx *SmartContractRawTransaction) (*SmartContractReceipt, *Error)
	//GetTokenMetadata 根据合约地址查询token元数据
	GetTokenMetadata(contract string) (*SmartContract, error)
}

SmartContractDecoder 智能合约解析器

type SmartContractDecoderBase

type SmartContractDecoderBase struct {
}

func (*SmartContractDecoderBase) CallSmartContractABI

func (decoder *SmartContractDecoderBase) CallSmartContractABI(wrapper WalletDAI, rawTx *SmartContractRawTransaction) (*SmartContractCallResult, *Error)

调用合约ABI方法

func (*SmartContractDecoderBase) CreateSmartContractRawTransaction

func (decoder *SmartContractDecoderBase) CreateSmartContractRawTransaction(wrapper WalletDAI, rawTx *SmartContractRawTransaction) *Error

创建原始交易单

func (*SmartContractDecoderBase) GetABIInfo

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) GetTokenMetadata added in v2.6.0

func (decoder *SmartContractDecoderBase) GetTokenMetadata(contract string) (*SmartContract, error)

GetTokenMetadata 根据合约地址查询token元数据

func (*SmartContractDecoderBase) SetABIInfo

func (decoder *SmartContractDecoderBase) SetABIInfo(address string, abi ABIInfo) error

SetABIInfo set abi

func (*SmartContractDecoderBase) SubmitSmartContractRawTransaction

func (decoder *SmartContractDecoderBase) SubmitSmartContractRawTransaction(wrapper WalletDAI, rawTx *SmartContractRawTransaction) (*SmartContractReceipt, *Error)

SubmitRawTransaction 广播交易单

type SmartContractEvent

type SmartContractEvent struct {
	Contract *SmartContract `json:"contract"` //合约
	Event    string         `json:"event"`    //记录事件
	Value    string         `json:"value"`    //结果参数,json字符串
}

SmartContractEvent 事件记录

type SmartContractRawTransaction

type SmartContractRawTransaction struct {
	Coin         Coin                       `json:"coin"`         //@required 区块链类型标识
	TxID         string                     `json:"txID"`         //交易单ID,广播后会生成
	Sid          string                     `json:"sid"`          //@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"`     //是否已广播
	Raw          string                     `json:"raw"`          //交易单调用参数,根据RawType填充数据
	RawType      uint64                     `json:"rawType"`      // 0:hex字符串,1:json字符串,2:base64字符串
	ABIParam     []string                   `json:"abiParam"`     //abi调用参数,[method, arg1, arg2, args...]
	Value        string                     `json:"value"`        //主币数量
	FeeRate      string                     `json:"feeRate"`      //自定义费率
	Fees         string                     `json:"fees"`         //手续费
	TxFrom       string                     `json:"txFrom"`       //调用地址
	TxTo         string                     `json:"txTo"`         //调用地址,与合约地址一致
	AwaitResult  bool                       `json:"awaitResult"`  //是否广播后同时等待结果
	AwaitTimeout uint64                     `json:"awaitTimeout"` //广播后等待超时秒,0 = 默认超时90秒
}

SmartContractRawTransaction 智能合约原始交易单

type SmartContractReceipt

type SmartContractReceipt struct {
	Coin        Coin                  `json:"coin"`            //@required 区块链类型标识
	WxID        string                `json:"wxid" storm:"id"` //@required 通过GenTransactionWxID计算
	TxID        string                `json:"txid"`            //@required
	From        string                `json:"from"`            //@required 调用者
	To          string                `json:"to"`              //@required 调用地址,与合约地址一致
	Value       string                `json:"value"`           //主币数量
	Fees        string                `json:"fees"`            //手续费
	RawReceipt  string                `json:"rawReceipt"`      //@required 原始交易回执,一般为json
	Events      []*SmartContractEvent `json:"events"`          //@required 执行事件, 例如:event Transfer
	BlockHash   string                `json:"blockHash"`       //@required
	BlockHeight uint64                `json:"blockHeight"`     //@required
	ConfirmTime int64                 `json:"confirmTime"`     //@required
	Status      string                `json:"status"`          //@required 链上状态,0:失败,1:成功
	Reason      string                `json:"reason"`          //失败原因,失败状态码
	ExtParam    string                `json:"extParam"`        //扩展参数,用于调用智能合约,json结构
}

func (*SmartContractReceipt) GenWxID

func (tx *SmartContractReceipt) GenWxID()

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

func (sumRawtx *SummaryRawTransaction) GetExtParam() gjson.Result

GetExtParam

func (*SummaryRawTransaction) SetExtParam

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 余额模型类别

func (*SymbolInfoBase) CurveType

func (s *SymbolInfoBase) CurveType() uint32

CurveType 曲线类型

func (*SymbolInfoBase) Decimal

func (s *SymbolInfoBase) Decimal() int32

Decimal 小数位精度

func (*SymbolInfoBase) FullName

func (s *SymbolInfoBase) FullName() string

FullName 币种全名

func (*SymbolInfoBase) Symbol

func (s *SymbolInfoBase) Symbol() string

Symbol 币种标识

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

func (tx *Transaction) GetExtParam() gjson.Result

GetExtParam

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

func (decoder *TransactionDecoderBase) CreateSummaryRawTransactionWithError(wrapper WalletDAI, sumRawTx *SummaryRawTransaction) ([]*RawTransactionWithError, error)

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

func (*TransactionDecoderBase) EstimateRawTransactionFee

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

type TransactionSigner interface {

	// SignTransactionHash 交易哈希签名算法
	// required
	SignTransactionHash(msg []byte, privateKey []byte, eccType uint32) ([]byte, error)
}

TransactionSigner 交易签署器

type TransactionSignerBase

type TransactionSignerBase struct {
}

func (*TransactionSignerBase) SignTransactionHash

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 TxOutPut

type TxOutPut struct {
	Recharge `storm:"inline"`
	ExtParam string //扩展参数,用于记录utxo的解锁字段,json格式
}

TxOutPut 交易输出,则到账记录

func (*TxOutPut) GetExtParam

func (txOut *TxOutPut) GetExtParam() gjson.Result

GetExtParam

func (*TxOutPut) SetExtParam

func (txOut *TxOutPut) SetExtParam(key string, value interface{}) error

SetExtParam

type UnscanRecord

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

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

func GetWalletsByKeyDir(dir string) ([]*Wallet, error)

GetWalletsByKeyDir 通过给定的文件路径加载keystore文件得到钱包列表

func NewWallet

func NewWallet(walletID string, symbol string) *Wallet

Deprecated

func NewWatchOnlyWallet

func NewWatchOnlyWallet(walletID string, symbol string) *Wallet

NewWatchOnlyWallet 只读钱包,用于观察冷钱包 Deprecated

func ReadWalletByKey

func ReadWalletByKey(keyPath string) *Wallet

ReadWalletByKey 加载文件,实例化钱包

func (*Wallet) DropRecharge

func (w *Wallet) DropRecharge() error

DropRecharge 删除充值记录表

func (*Wallet) FileName

func (w *Wallet) FileName() string

FileName 钱包文件名

func (*Wallet) GetAddress

func (w *Wallet) GetAddress(address string) *Address

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

func (*Wallet) GetAddressesByAccount

func (w *Wallet) GetAddressesByAccount(accountID string) []*Address

GetAddressesByAccountID 通过账户ID获取地址列表

func (*Wallet) GetAssetsAccounts

func (w *Wallet) GetAssetsAccounts(symbol string) []*AssetsAccount

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

func (*Wallet) GetRecharges

func (w *Wallet) GetRecharges(received bool, height ...uint64) ([]*Recharge, error)

GetRecharges 获取钱包相关的充值记录

func (*Wallet) GetUnconfrimRecharges

func (w *Wallet) GetUnconfrimRecharges(limitTime int64) ([]*Recharge, error)

GetUnconfrimRecharges

func (*Wallet) HDKey

func (w *Wallet) HDKey(password ...string) (*hdkeystore.HDKey, error)

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

func (*Wallet) OpenDB

func (w *Wallet) OpenDB() (*storm.DB, error)

openDB 打开钱包数据库

func (*Wallet) SaveRecharge

func (w *Wallet) SaveRecharge(tx *Recharge) error

SaveRecharge 保存交易记录

func (*Wallet) SaveToDB

func (w *Wallet) SaveToDB() error

SaveToDB 保存到数据库

func (*Wallet) SaveUnreceivedRecharge

func (w *Wallet) SaveUnreceivedRecharge(tx *Recharge) error

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

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

type WalletType

type WalletType = uint

钱包类型

type Withdraw

type Withdraw struct {
	Symbol   string `json:"coin"`
	WalletID string `json:"walletID"`
	Sid      string `json:"sid"  storm:"id"`
	IsMemo   bool   `json:"isMemo"`
	Address  string `json:"address"`
	Amount   string `json:"amount"`
	Memo     string `json:"memo"`
	Password string `json:"password"`
	TxID     string `json:"txid"`
}

func NewWithdraw

func NewWithdraw(json gjson.Result) *Withdraw

NewWithdraw 创建提现单

Jump to

Keyboard shortcuts

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