openwallet

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2019 License: GPL-3.0 Imports: 25 Imported by: 84

Documentation

Index

Constants

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

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

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

	/// 公钥字节长度(未压缩)
	PublicKeyLengthUncompressed = 65
)
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无法访问

	/* 其他 */
	ErrUnknownException = 9001 //未知异常情况
)
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 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
	ABI     interface{}
}

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, decoder AddressDecoder, 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, decoder AddressDecoder, addrIndex int, addrIsChange int64) AddressCreateResult

type AddressDecoder

type AddressDecoder interface {

	//PrivateKeyToWIF 私钥转WIF
	PrivateKeyToWIF(priv []byte, isTestnet bool) (string, error)
	//PublicKeyToAddress 公钥转地址
	PublicKeyToAddress(pub []byte, isTestnet bool) (string, error)
	//WIFToPrivateKey WIF转私钥
	WIFToPrivateKey(wif string, isTestnet bool) ([]byte, error)
	//RedeemScriptToAddress 多重签名赎回脚本转地址
	RedeemScriptToAddress(pubs [][]byte, required uint64, isTestnet bool) (string, error)
}

type AddressDecoderV2 added in v1.4.1

type AddressDecoderV2 interface {
	//AddressDecode 地址解析
	AddressDecode(addr string, opts ...interface{}) ([]byte, error)
	//AddressEncode 地址编码
	AddressEncode(pub []byte, opts ...interface{}) (string, error)
}

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 地址编码

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

	//GetAddressDecode 地址解析器
	//@required
	GetAddressDecode() AddressDecoder

	//GetTransactionDecoder 交易单解析器
	//@required
	GetTransactionDecoder() TransactionDecoder

	//GetBlockScanner 获取区块链扫描器
	//@required
	GetBlockScanner() BlockScanner

	//GetSmartContractDecoder 获取智能合约解析器
	//@optional
	GetSmartContractDecoder() SmartContractDecoder

	//GetAssetsLogger 获取资产日志工具
	//@optional
	GetAssetsLogger() *log.OWLogger
}

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

type AssetsAdapterBase

type AssetsAdapterBase struct {
	SymbolInfoBase
	AssetsConfigBase
}

func (*AssetsAdapterBase) GetAddressDecode

func (a *AssetsAdapterBase) GetAddressDecode() AddressDecoder

GetAddressDecode 地址解析器

func (*AssetsAdapterBase) GetAssetsLogger

func (a *AssetsAdapterBase) GetAssetsLogger() *log.OWLogger

GetAssetsLogger 获取资产账户日志工具

func (*AssetsAdapterBase) GetBlockScanner

func (a *AssetsAdapterBase) GetBlockScanner() BlockScanner

GetBlockScanner 获取区块链扫描器

func (*AssetsAdapterBase) GetSmartContractDecoder

func (a *AssetsAdapterBase) GetSmartContractDecoder() SmartContractDecoder

GetBlockScanner 获取智能合约解析器

func (*AssetsAdapterBase) GetTransactionDecoder

func (a *AssetsAdapterBase) GetTransactionDecoder() TransactionDecoder

GetTransactionDecoder 交易单解析器

func (*AssetsAdapterBase) InitAssetsAdapter

func (a *AssetsAdapterBase) InitAssetsAdapter() error

GetAddressDecode 地址解析器

type AssetsConfig

type AssetsConfig interface {

	//LoadExternalConfig 加载外部配置
	LoadAssetsConfig(c config.Configer) error

	//InitDefaultConfig 初始化默认配置
	InitAssetsConfig() (config.Configer, error)
}

AssetsConfig 用于给AssetsAdapter调用者初始化、加载外部配置的接口

type AssetsConfigBase

type AssetsConfigBase struct{}

func (*AssetsConfigBase) InitAssetsConfig

func (as *AssetsConfigBase) InitAssetsConfig() (config.Configer, error)

InitAssetsConfig 初始化默认配置

func (*AssetsConfigBase) LoadAssetsConfig

func (as *AssetsConfigBase) LoadAssetsConfig(c config.Configer) error

LoadAssetsConfig 加载外部配置

type Balance

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

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"`
	Version           uint64 `json:"version"`
	Time              uint64 `json:"time"`
	Fork              bool   `json:"fork"`
	Symbol            string `json:"symbol"`
}

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
}

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 添加观测者
	AddObserver(obj BlockScanNotificationObject) error

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

	//SetRescanBlockHeight 重置区块链扫描高度
	//@required
	SetRescanBlockHeight(height uint64) error

	//Run 运行
	Run() error

	//Stop 停止扫描
	Stop() error

	//Pause 暂停扫描
	Pause() error

	//Restart 继续扫描
	Restart() error

	//InitBlockScanner 初始化扫描器
	InitBlockScanner() error

	//CloseBlockScanner 关闭扫描器
	CloseBlockScanner() error

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

	//NewBlockNotify 新区块通知
	NewBlockNotify(header *BlockHeader) error

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

	//GetGlobalMaxBlockHeight 获取区块链全网最大高度
	//@required
	GetGlobalMaxBlockHeight() uint64

	//GetScannedBlockHeight 获取已扫区块高度
	//@required
	GetScannedBlockHeight() uint64

	//ExtractTransactionData 提取交易单数据
	//@required
	ExtractTransactionData(txid string, scanTargetFunc BlockScanTargetFunc) (map[string][]*TxExtractData, error)

	//GetBalanceByAddress 查询地址余额
	GetBalanceByAddress(address ...string) ([]*Balance, error)

	//GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址
	//返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算
	GetTransactionsByAddress(offset, limit int, coin Coin, address ...string) ([]*TxExtractData, error)
}

BlockScanner 区块扫描器 负责扫描新区块,给观察者推送订阅地址的新交易单。

type BlockScannerBase

type BlockScannerBase struct {
	AddressInScanning map[string]string //加入扫描的地址

	Mu              sync.RWMutex                         //读写锁
	Observers       map[BlockScanNotificationObject]bool //观察者
	Scanning        bool                                 //是否扫描中
	PeriodOfTask    time.Duration
	ScanAddressFunc BlockScanAddressFunc //区块扫描查询地址算法
	ScanTargetFunc  BlockScanTargetFunc  //区块扫描查询地址算法
	// 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) 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) 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 added in v1.3.0

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

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

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 停止扫描

type Blockchain

type Blockchain struct {
	Blocks     uint64
	Headers    uint64
	ScanHeight uint64
}

type Bytes

type Bytes []byte

字节流

type CacheEntry added in v1.4.1

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

Error 错误信息

func (*Error) Error

func (err *Error) Error() string

Error 错误信息

type FeesSupportAccount added in v1.4.1

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

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 ImportAddress

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

ImportAddress 待导入的地址记录

type KeySignature

type KeySignature struct {
	EccType   uint32   `json:"eccType"` //曲线类型
	Nonce     string   `json:"nonce"`
	Address   *Address `json:"address"` //提供签名的地址
	Signature string   `json:"signed"`  //未花签名
	Message   string   `json:"msg"`     //被签消息
}

KeySignature 签名信息

type 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 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 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"`        //业务订单号,保证业务不重复交易而用
	RawHex      string          `json:"rawHex"`     //区块链协议构造的交易原生数据
	Account     *AssetsAccount  `json:"account"`    //@required 创建交易单的账户
	Fees        string          `json:"fees"`       //手续费
	Signatures  []*KeySignature `json:"signatures"` //拥有者accountID: []未花签名
	IsBuilt     bool            `json:"isBuilt"`    //是否完成构建建议单
	IsCompleted bool            `json:"isComplete"` //是否完成所有签名
	IsSubmit    bool            `json:"isSubmit"`   //是否已广播
	TxAmount    string          `json:"txAmount"`   //交易单实际对账户发生的数量变化
	ExtParam    string          `json:"extParam"`   //扩展参数,用于调用智能合约,json结构

}

SmartContractRawTransaction 智能合约原始交易单

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

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:合约调用(发生于主链)
	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 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 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 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)
}

WalletDAI 钱包数据访问接口

type WalletDAIBase

type WalletDAIBase struct {
}

TransactionDecoderBase 实现TransactionDecoder的基类

func (*WalletDAIBase) GetAddress

func (base *WalletDAIBase) GetAddress(address string) (*Address, error)

func (*WalletDAIBase) GetAddressExtParam

func (base *WalletDAIBase) GetAddressExtParam(address string, key string) (interface{}, error)

获取地址的扩展字段

func (*WalletDAIBase) GetAddressList

func (base *WalletDAIBase) GetAddressList(offset, limit int, cols ...interface{}) ([]*Address, error)

func (*WalletDAIBase) GetAssetsAccountByAddress

func (base *WalletDAIBase) GetAssetsAccountByAddress(address string) (*AssetsAccount, error)

func (*WalletDAIBase) GetAssetsAccountInfo

func (base *WalletDAIBase) GetAssetsAccountInfo(accountID string) (*AssetsAccount, error)

func (*WalletDAIBase) GetAssetsAccountList

func (base *WalletDAIBase) GetAssetsAccountList(offset, limit int, cols ...interface{}) ([]*AssetsAccount, error)

func (*WalletDAIBase) GetWallet

func (base *WalletDAIBase) GetWallet() *Wallet

func (*WalletDAIBase) GetWalletByID

func (base *WalletDAIBase) GetWalletByID(walletID string) (*Wallet, error)

func (*WalletDAIBase) HDKey

func (base *WalletDAIBase) HDKey(password ...string) (*hdkeystore.HDKey, error)

func (*WalletDAIBase) SetAddressExtParam

func (base *WalletDAIBase) SetAddressExtParam(address string, key string, val interface{}) error

设置地址的扩展字段

func (*WalletDAIBase) UnlockWallet

func (base *WalletDAIBase) UnlockWallet(password string, time time.Duration) error

type 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