elastos

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//币种
	Symbol    = "ELA"
	MasterKey = "Elastos seed"
	CurveType = owcrypt.ECC_CURVE_SECP256R1
	Decimals  = int32(8)
)

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) string

See 2 (end of page 4) http://www.ietf.org/rfc/rfc2617.txt "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials." It is not meant to be urlencoded.

func NewAddressDecoder

func NewAddressDecoder(wm *WalletManager) *addressDecoder

NewAddressDecoder 地址解析器

Types

type AddressDecoder

type AddressDecoder interface {
	openwallet.AddressDecoder
}

type Block

type Block struct {
	Hash          string
	Confirmations uint64
	Merkleroot    string

	Previousblockhash string
	Height            uint64 `storm:"id"`
	Version           uint64
	Time              uint64
	Fork              bool
	// contains filtered or unexported fields
}

func (*Block) BlockHeader

func (b *Block) BlockHeader(symbol string) *openwallet.BlockHeader

BlockHeader 区块链头

type BlockchainInfo

type BlockchainInfo struct {
	Chain                string `json:"chain"`
	Blocks               uint64 `json:"blocks"`
	Headers              uint64 `json:"headers"`
	Bestblockhash        string `json:"bestblockhash"`
	Difficulty           string `json:"difficulty"`
	Mediantime           uint64 `json:"mediantime"`
	Verificationprogress string `json:"verificationprogress"`
	Chainwork            string `json:"chainwork"`
	Pruned               bool   `json:"pruned"`
}

BlockchainInfo 本地节点区块链信息

func NewBlockchainInfo

func NewBlockchainInfo(json *gjson.Result) *BlockchainInfo

type Client

type Client struct {
	BaseURL string
	// AccessToken string
	Debug bool
	// contains filtered or unexported fields
}

A Client is a Elastos RPC client. It performs RPCs over HTTP using JSON request and responses. A Client must be configured with a secret token to authenticate with other Cores on the network.

func NewClient

func NewClient(url string, debug bool) *Client

func (*Client) Call

func (c *Client) Call(path string, request []interface{}) (*gjson.Result, error)

Call calls a remote procedure on another node, specified by the path.

func (*Client) NewBlock

func (c *Client) NewBlock(json *gjson.Result) *Block

type ClientInterface

type ClientInterface interface {
	Call(path string, request []interface{}) (*gjson.Result, error)
}

type ContractDecoder

type ContractDecoder struct {
	*openwallet.SmartContractDecoderBase
	// contains filtered or unexported fields
}

func NewContractDecoder

func NewContractDecoder(wm *WalletManager) *ContractDecoder

NewContractDecoder 智能合约解析器

type ELABlockScanner

type ELABlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

	IsScanMemPool        bool   //是否扫描交易池
	RescanLastBlockCount uint64 //重扫上N个区块数量

	//用于实现浏览器
	IsSkipFailedBlock bool //是否跳过失败区块
	// contains filtered or unexported fields
}

ELABlockScanner bitcoin的区块链扫描器

func NewELABlockScanner

func NewELABlockScanner(wm *WalletManager) *ELABlockScanner

NewELABlockScanner 创建区块链扫描器

func (*ELABlockScanner) BatchExtractTransaction

func (bs *ELABlockScanner) BatchExtractTransaction(blockHeight uint64, blockHash string, txs []string) error

BatchExtractTransaction 批量提取交易单 bitcoin 1M的区块链可以容纳3000笔交易,批量多线程处理,速度更快

func (*ELABlockScanner) DeleteUnscanRecord added in v1.1.0

func (bs *ELABlockScanner) DeleteUnscanRecord(height uint32) error

DeleteUnscanRecord 删除指定高度的未扫记录

func (*ELABlockScanner) DeleteUnscanRecordNotFindTX added in v1.1.1

func (bs *ELABlockScanner) DeleteUnscanRecordNotFindTX() error

DeleteUnscanRecordNotFindTX 删除未没有找到交易记录的重扫记录

func (*ELABlockScanner) ExtractTransaction

func (bs *ELABlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, txid string, scanAddressFunc openwallet.BlockScanAddressFunc) ExtractResult

ExtractTransaction 提取交易单

func (*ELABlockScanner) ExtractTransactionData

func (bs *ELABlockScanner) ExtractTransactionData(txid string, scanTargetFunc openwallet.BlockScanTargetFunc) (map[string][]*openwallet.TxExtractData, error)

func (*ELABlockScanner) GetBalanceByAddress

func (bs *ELABlockScanner) GetBalanceByAddress(address ...string) ([]*openwallet.Balance, error)

GetAssetsAccountBalanceByAddress 查询账户相关地址的交易记录

func (*ELABlockScanner) GetCurrentBlockHeader

func (bs *ELABlockScanner) GetCurrentBlockHeader() (*openwallet.BlockHeader, error)

GetCurrentBlockHeader 获取当前区块高度

func (*ELABlockScanner) GetGlobalMaxBlockHeight

func (bs *ELABlockScanner) GetGlobalMaxBlockHeight() uint64

func (*ELABlockScanner) GetLocalBlock added in v1.1.0

func (bs *ELABlockScanner) GetLocalBlock(height uint32) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*ELABlockScanner) GetLocalBlockHead added in v1.1.0

func (bs *ELABlockScanner) GetLocalBlockHead() (uint32, string, error)

GetLocalBlockHead 获取本地记录的区块高度和hash

func (*ELABlockScanner) GetLocalNewBlock added in v1.1.1

func (bs *ELABlockScanner) GetLocalNewBlock() (uint64, string, error)

GetLocalNewBlock 获取本地记录的区块高度和hash

func (*ELABlockScanner) GetScannedBlockHeader

func (bs *ELABlockScanner) GetScannedBlockHeader() (*openwallet.BlockHeader, error)

GetScannedBlockHeader 获取当前扫描的区块头

func (*ELABlockScanner) GetScannedBlockHeight

func (bs *ELABlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*ELABlockScanner) GetTransactionsByAddress

func (bs *ELABlockScanner) GetTransactionsByAddress(offset, limit int, coin openwallet.Coin, address ...string) ([]*openwallet.TxExtractData, error)

GetAssetsAccountTransactionsByAddress 查询账户相关地址的交易记录

func (*ELABlockScanner) GetUnscanRecords added in v1.1.0

func (bs *ELABlockScanner) GetUnscanRecords() ([]*openwallet.UnscanRecord, error)

func (*ELABlockScanner) RescanFailedRecord

func (bs *ELABlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*ELABlockScanner) Run

func (bs *ELABlockScanner) Run() error

Run 运行

func (*ELABlockScanner) SaveLocalBlock added in v1.1.0

func (bs *ELABlockScanner) SaveLocalBlock(blockHeader *Block) error

SaveLocalBlock 记录本地新区块

func (*ELABlockScanner) SaveLocalBlockHead added in v1.1.0

func (bs *ELABlockScanner) SaveLocalBlockHead(blockHeight uint32, blockHash string) error

SaveLocalBlockHead 记录区块高度和hash到本地

func (*ELABlockScanner) SaveLocalNewBlock added in v1.1.1

func (bs *ELABlockScanner) SaveLocalNewBlock(blockHeight uint64, blockHash string) error

SaveLocalNewBlock 记录区块高度和hash到本地

func (*ELABlockScanner) SaveUnscanRecord

func (bs *ELABlockScanner) SaveUnscanRecord(record *openwallet.UnscanRecord) error

SaveUnscanRecord 保存交易记录到钱包数据库

func (*ELABlockScanner) ScanBlock

func (bs *ELABlockScanner) ScanBlock(height uint64) error

ScanBlock 扫描指定高度区块

func (*ELABlockScanner) ScanBlockTask

func (bs *ELABlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*ELABlockScanner) ScanTxMemPool

func (bs *ELABlockScanner) ScanTxMemPool()

ScanTxMemPool 扫描交易内存池

func (*ELABlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*ELABlockScanner) Stop

func (bs *ELABlockScanner) Stop() error

//Stop 停止扫描

func (*ELABlockScanner) SupportBlockchainDAI added in v1.1.0

func (bs *ELABlockScanner) SupportBlockchainDAI() bool

type ExtractResult

type ExtractResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
	// contains filtered or unexported fields
}

ExtractResult 扫描完成的提取结果

type Response

type Response struct {
	Code    int         `json:"code,omitempty"`
	Error   interface{} `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Message string      `json:"message,omitempty"`
	Id      string      `json:"id,omitempty"`
}

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult 保存结果

type Transaction

type Transaction struct {
	TxID          string
	Size          uint64
	Version       uint64
	LockTime      int64
	Hex           string
	BlockHash     string
	BlockHeight   uint64
	Confirmations uint64
	Blocktime     int64
	IsCoinBase    bool
	Fees          string
	Decimals      int32
	Type          int32
	Vins          []*Vin
	Vouts         []*Vout
}

type TransactionDecoder

type TransactionDecoder struct {
	openwallet.TransactionDecoderBase
	// contains filtered or unexported fields
}

func NewTransactionDecoder

func NewTransactionDecoder(wm *WalletManager) *TransactionDecoder

NewTransactionDecoder 交易单解析器

func (*TransactionDecoder) CreateELARawTransaction

func (decoder *TransactionDecoder) CreateELARawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateRawTransaction 创建交易单

func (*TransactionDecoder) CreateELASummaryRawTransaction

func (decoder *TransactionDecoder) CreateELASummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

CreateELASummaryRawTransaction 创建ELA汇总交易

func (*TransactionDecoder) CreateRawTransaction

func (decoder *TransactionDecoder) CreateRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

CreateRawTransaction 创建交易单

func (*TransactionDecoder) CreateSummaryRawTransaction

func (decoder *TransactionDecoder) CreateSummaryRawTransaction(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransaction, error)

CreateSummaryRawTransaction 创建汇总交易,返回原始交易单数组

func (*TransactionDecoder) CreateSummaryRawTransactionWithError

func (decoder *TransactionDecoder) CreateSummaryRawTransactionWithError(wrapper openwallet.WalletDAI, sumRawTx *openwallet.SummaryRawTransaction) ([]*openwallet.RawTransactionWithError, error)

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

func (*TransactionDecoder) GetRawTransactionFeeRate

func (decoder *TransactionDecoder) GetRawTransactionFeeRate() (feeRate string, unit string, err error)

GetRawTransactionFeeRate 获取交易单的费率

func (*TransactionDecoder) SignELARawTransaction

func (decoder *TransactionDecoder) SignELARawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

SignRawTransaction 签名交易单

func (*TransactionDecoder) SignRawTransaction

func (decoder *TransactionDecoder) SignRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

SignRawTransaction 签名交易单

func (*TransactionDecoder) SubmitRawTransaction

func (decoder *TransactionDecoder) SubmitRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) (*openwallet.Transaction, error)

SendRawTransaction 广播交易单

func (*TransactionDecoder) VerifyELARawTransaction

func (decoder *TransactionDecoder) VerifyELARawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单

func (*TransactionDecoder) VerifyRawTransaction

func (decoder *TransactionDecoder) VerifyRawTransaction(wrapper openwallet.WalletDAI, rawTx *openwallet.RawTransaction) error

VerifyRawTransaction 验证交易单,验证交易单并返回加入签名后的交易单

type UnscanRecord

type UnscanRecord struct {
	ID          string `storm:"id"` // primary key
	BlockHeight uint64
	TxID        string
	Reason      string
}

UnscanRecords 扫描失败的区块及交易

func NewUnscanRecord

func NewUnscanRecord(height uint64, txID, reason string) *UnscanRecord

type Unspent

type Unspent struct {

	/*
			{
		        "txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a",
		        "vout" : 1,
		        "address" : "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe",
		        "account" : "test label",
		        "scriptPubKey" : "76a9140dfc8bafc8419853b34d5e072ad37d1a5159f58488ac",
		        "amount" : 0.00010000,
		        "confirmations" : 6210,
		        "spendable" : true,
		        "solvable" : true
		    }
	*/
	Key     string `storm:"id"`
	TxID    string `json:"txid"`
	Vout    uint64 `json:"vout"`
	Address string `json:"address"`
	//	AccountID string `json:"account" storm:"index"`
	// ScriptPubKey  string `json:"scriptPubKey"`
	Amount        string `json:"amount"`
	Confirmations uint64 `json:"confirmations"`
	Spendable     bool   `json:"spendable"`
	Solvable      bool   `json:"solvable"`
	HDAddress     openwallet.Address
}

Unspent 未花记录

func NewUnspent

func NewUnspent(json *gjson.Result) *Unspent

type UnspentSort

type UnspentSort struct {
	Values     []*Unspent
	Comparator func(a, b *Unspent) int
}

func (UnspentSort) Len

func (s UnspentSort) Len() int

func (UnspentSort) Less

func (s UnspentSort) Less(i, j int) bool

func (UnspentSort) Swap

func (s UnspentSort) Swap(i, j int)

type User

type User struct {
	UserKey string `storm:"id"`     // primary key
	Group   string `storm:"index"`  // this field will be indexed
	Email   string `storm:"unique"` // this field will be indexed with a unique constraint
	Name    string // this field will not be indexed
	Age     int    `storm:"index"`
}

type Vin

type Vin struct {
	Coinbase string
	TxID     string
	Vout     uint64
	N        uint64
	Addr     string
	Value    string
}

type Vout

type Vout struct {
	AssetID string
	N       uint64
	Addr    string
	Value   string
	Type    string
	Lock    uint64
}

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol    string
	MasterKey string

	//RPC认证账户名
	RpcUser string
	//RPC认证账户密码
	RpcPassword string
	//证书目录
	CertsDir string

	//rpc证书
	CertFileName string
	//区块链数据文件
	//BlockchainFile string
	// 核心钱包是否只做监听
	CoreWalletWatchOnly bool
	//最大的输入数量
	MaxTxInputs int

	//钱包服务API
	ServerAPI string
	//钱包安装的路径
	NodeInstallPath string
	//钱包数据文件目录
	WalletDataPath string
	//汇总阈值
	Threshold decimal.Decimal
	//汇总地址
	SumAddress string
	//汇总执行间隔时间
	CycleSeconds time.Duration
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//核心钱包密码,配置有值用于自动解锁钱包
	WalletPassword string
	//使用固定手续费
	UseFixedFee bool
	//固定手续费
	FixedFee string
	//小数位精度
	Decimals int32
	// data directory
	DataDir string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(symbol string, curveType uint32, decimals int32) *WalletConfig

func (*WalletConfig) InitConfig

func (wc *WalletConfig) InitConfig()

initConfig 初始化配置文件

func (*WalletConfig) PrintConfig

func (wc *WalletConfig) PrintConfig() error

printConfig Print config information

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase

	Storage         *hdkeystore.HDKeystore        //秘钥存取
	WalletClient    *Client                       // 节点客户端
	Config          *WalletConfig                 //钱包管理配置
	WalletsInSum    map[string]*openwallet.Wallet //参与汇总的钱包
	Blockscanner    *ELABlockScanner              //区块扫描器
	Decoder         AddressDecoder                //地址编码器
	TxDecoder       openwallet.TransactionDecoder //交易单编码器
	Log             *log.OWLogger                 //日志工具
	ContractDecoder openwallet.SmartContractDecoder
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) BalanceModelType

func (wm *WalletManager) BalanceModelType() openwallet.BalanceModelType

func (*WalletManager) CurveType

func (wm *WalletManager) CurveType() uint32

CurveType 曲线类型

func (*WalletManager) Decimal

func (wm *WalletManager) Decimal() int32

小数位精度

func (*WalletManager) EstimateFee

func (wm *WalletManager) EstimateFee(inputs, outputs, sigs int64, feeRate decimal.Decimal) (decimal.Decimal, error)

EstimateFee 预估手续费

func (*WalletManager) EstimateFeeRate

func (wm *WalletManager) EstimateFeeRate() (decimal.Decimal, error)

EstimateFeeRate 预估的没KB手续费率

func (*WalletManager) FullName

func (wm *WalletManager) FullName() string

FullName 币种全名

func (*WalletManager) GetAddressDecode

func (wm *WalletManager) GetAddressDecode() openwallet.AddressDecoder

AddressDecode 地址解析器

func (*WalletManager) GetAssetsLogger

func (wm *WalletManager) GetAssetsLogger() *log.OWLogger

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlock

func (wm *WalletManager) GetBlock(hash string) (*Block, error)

GetBlock 获取区块数据

func (*WalletManager) GetBlockHash

func (wm *WalletManager) GetBlockHash(height uint64) (string, error)

GetBlockHash 根据区块高度获得区块hash

func (*WalletManager) GetBlockHeight

func (wm *WalletManager) GetBlockHeight() (uint64, error)

GetBlockHeight 获取区块链高度

func (*WalletManager) GetBlockScanner

func (wm *WalletManager) GetBlockScanner() openwallet.BlockScanner

GetBlockScanner 获取区块链

func (*WalletManager) GetSmartContractDecoder

func (wm *WalletManager) GetSmartContractDecoder() openwallet.SmartContractDecoder

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetTransaction

func (wm *WalletManager) GetTransaction(txid string) (*Transaction, error)

GetTransaction 获取交易单

func (*WalletManager) GetTransactionDecoder

func (wm *WalletManager) GetTransactionDecoder() openwallet.TransactionDecoder

TransactionDecoder 交易单解析器

func (*WalletManager) GetTxIDsInMemPool

func (wm *WalletManager) GetTxIDsInMemPool() ([]string, error)

GetTxIDsInMemPool 获取待处理的交易池中的交易单IDs

func (*WalletManager) GetTxOut

func (wm *WalletManager) GetTxOut(txid string, vout uint64) (*Vout, error)

GetTxOut 获取交易单输出信息,用于追溯交易单输入源头

func (*WalletManager) InitAssetsConfig

func (wm *WalletManager) InitAssetsConfig() (config.Configer, error)

InitAssetsConfig 初始化默认配置

func (*WalletManager) ListUnspent

func (wm *WalletManager) ListUnspent(min uint64, addresses ...string) ([]*Unspent, error)

ListUnspent 获取未花记录

func (*WalletManager) LoadAssetsConfig

func (wm *WalletManager) LoadAssetsConfig(c config.Configer) error

LoadAssetsConfig 加载外部配置

func (*WalletManager) SendRawTransaction

func (wm *WalletManager) SendRawTransaction(txHex string) (string, error)

SendRawTransaction 广播交易

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

Jump to

Keyboard shortcuts

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