xdag

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//币种
	Symbol    = "XDAG"
	CurveType = owcrypt.ECC_CURVE_SECP256K1

	//交易单发送超时时限
	DefaultTxSendingTimeout = 5 * time.Minute
)
View Source
const (
	TxStatusPending     = 0
	TxStatusInProgress  = 1
	TxStatusCanceled    = 2
	TxStatusCompleted   = 3
	TxStatusFailed      = 4
	TxStatusRegistering = 5
)
View Source
const DKEY string = "xdagpp968"

Variables

This section is empty.

Functions

func D added in v1.0.7

func D(encryptData string, keys ...string) string

func Decrypt added in v1.0.7

func Decrypt(key string, val string) (string, error)

func E added in v1.0.7

func E(plainData string, keys ...string) string

func Encrypt added in v1.0.7

func Encrypt(key string, val string) (string, error)

func PKCS5Padding added in v1.0.7

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding added in v1.0.7

func PKCS5UnPadding(origData []byte) []byte

Types

type AddressCreateResult

type AddressCreateResult struct {
	Success bool
	Err     error
	Address string
}

type Block

type Block struct {
	Chainwork     string
	Hash          string
	Found         bool
	PrevBlockHash string
	Time          int64
	Height        uint64
}

func NewBlock

func NewBlock(result *gjson.Result) *Block

func (*Block) BlockHeader

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

BlockHeader 区块链头

type BlockchainInfo

type BlockchainInfo struct {
	Chainwork  string
	Hash       string
	Height     uint64
	LowHorizon uint64
	Timestamp  int64
}

func NewBlockchainInfo

func NewBlockchainInfo(result *gjson.Result) *BlockchainInfo

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(wm *WalletManager) (*Client, error)

func (*Client) CreateBatchAddress

func (c *Client) CreateBatchAddress(count, workerSize uint64) ([]string, error)

CreateBatchAddress

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(height uint64) (*Block, error)

GetBlockByHeight

func (*Client) GetTransaction

func (c *Client) GetTransaction(txid string) (*Transaction, error)

GetTransaction

func (*Client) GetTransactionsByHeight

func (c *Client) GetTransactionsByHeight(height uint64) ([]*Transaction, error)

GetTransactionsByHeight

func (*Client) GetWalletAddress

func (c *Client) GetWalletAddress() ([]string, error)

GetWalletAddress

func (*Client) GetWalletBalance

func (c *Client) GetWalletBalance() (*openwallet.Balance, error)

GetWalletBalance

func (*Client) GetWalletStatus

func (c *Client) GetWalletStatus() (*WalletStatus, error)

GetWalletStatus 获取钱包当前状态

func (*Client) SummaryToAddress

func (c *Client) SummaryToAddress(summaryAddress string) (string, string, string, error)

打币

func (*Client) TransFCoin

func (c *Client) TransFCoin(toAddress, toAmount, remark string) (string, error)

打币

func (*Client) ValidateAddress

func (c *Client) ValidateAddress(address string) (bool, error)

验证地址

type ExtractResult

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

ExtractResult 扫描完成的提取结果

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult result

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(wm *WalletManager) (*Server, error)

func (*Server) Close

func (server *Server) Close()

Close 关闭监听

func (*Server) GetWalletStatus

func (server *Server) GetWalletStatus(ctx *owtp.Context)

func (*Server) Listen

func (server *Server) Listen() error

Listen 启动监听

func (*Server) SetConnectHandler

func (server *Server) SetConnectHandler(h func(node *Server, nodeInfo *TrustNodeInfo))

SetConnectHandler 设置托管节点断开连接后的通知

func (*Server) SetDisconnectHandler

func (server *Server) SetDisconnectHandler(h func(node *Server, nodeID string))

SetDisconnectHandler 设置托管节点连接成功的通知

type Transaction

type Transaction struct {
	CreateTime    int64
	TxID          string
	TxAddress     string
	Value         string
	From          string
	To            string
	Remark        string
	Confirmations uint64
	BlockHeight   uint64
	BlockHash     string
}

func NewTransaction

func NewTransaction(result *gjson.Result) *Transaction

type TransactionDecoder

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

func NewTransactionDecoder

func NewTransactionDecoder(wm *WalletManager) *TransactionDecoder

NewTransactionDecoder 交易单解析器

func (*TransactionDecoder) GetRawTransactionFeeRate

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

GetRawTransactionFeeRate 获取交易单的费率

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

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

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

type TrustNodeInfo

type TrustNodeInfo struct {
	NodeID      string `json:"nodeID"` //@required 节点ID
	NodeName    string `json:"nodeName"`
	ConnectType string `json:"connectType"`
}

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 WalletClient

type WalletClient struct {
	WalletAPI, ExplorerAPI string
	Debug                  bool
	// contains filtered or unexported fields
}

A Client is a Bitcoin 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 NewWalletClient

func NewWalletClient(walletAPI, explorerAPI string, debug bool) *WalletClient

func (*WalletClient) GetBlockByHeight

func (c *WalletClient) GetBlockByHeight(walletAddress string, height uint64) (*WalletStatus, error)

GetBlockByHeight

func (*WalletClient) GetTransaction

func (c *WalletClient) GetTransaction(txid string) (*Transaction, error)

GetTransaction

func (*WalletClient) GetTransactionDetail

func (c *WalletClient) GetTransactionDetail(txAddress string) (string, string, error)

func (*WalletClient) GetTransactionHexTxid added in v1.0.7

func (c *WalletClient) GetTransactionHexTxid(txAddress string) (string, error)

converto txAddress to txhash

func (*WalletClient) GetTransactionsByStatus

func (c *WalletClient) GetTransactionsByStatus(status int) ([]*Transaction, error)

GetTransactionsByStatus

func (*WalletClient) GetTransactionsByWalletAddress added in v1.0.1

func (c *WalletClient) GetTransactionsByWalletAddress(walletAddress string, page uint64) ([]*Transaction, error)

GetTransactionsByHeight

func (*WalletClient) GetWalletStatus

func (c *WalletClient) GetWalletStatus(walletAddress string) (*WalletStatus, error)

GetWalletStatus

func (*WalletClient) SendTransaction

func (c *WalletClient) SendTransaction(from, to string, value, fee uint64, comment string) (string, error)

SendTransaction

func (*WalletClient) TransferCoin added in v1.0.7

func (c *WalletClient) TransferCoin(amount, address, remark string) (string, error)

transfer coin

func (*WalletClient) UnlockWallet added in v1.0.7

func (c *WalletClient) UnlockWallet(password string) error

unlockWallet

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol string

	//区块链数据文件
	BlockchainFile string

	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32

	//xdag 充值地址
	DepositAddress string

	//xdag 提币地址
	WithdrawAddress string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(symbol string) *WalletConfig

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase

	Config          *WalletConfig                   // 节点配置
	Decoder         openwallet.AddressDecoder       //地址编码器
	TxDecoder       openwallet.TransactionDecoder   //交易单编码器
	Log             *log.OWLogger                   //日志工具
	ContractDecoder openwallet.SmartContractDecoder //智能合约解析器
	Blockscanner    *XDAGBlockScanner               //区块扫描器
	// contains filtered or unexported fields
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) BalanceModelType

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

BalanceModelType 余额模型类别

func (WalletManager) CreateRemoteWalletAddress

func (wm WalletManager) CreateRemoteWalletAddress(count, workerSize uint64) ([]string, error)

func (*WalletManager) CurveType

func (wm *WalletManager) CurveType() uint32

CurveType 曲线类型

func (*WalletManager) Decimal

func (wm *WalletManager) Decimal() int32

Decimal 小数位精度

func (*WalletManager) DeleteUnscanRecord

func (wm *WalletManager) DeleteUnscanRecord(height uint64) error

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

func (*WalletManager) DeleteUnscanRecordNotFindTX

func (wm *WalletManager) DeleteUnscanRecordNotFindTX() error

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

func (*WalletManager) FullName

func (wm *WalletManager) FullName() string

FullName 币种全名

func (*WalletManager) GetAddressDecode

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

GetAddressDecode 地址解析器

func (*WalletManager) GetAssetsLogger

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

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlockScanner

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

GetBlockScanner 获取区块链

func (*WalletManager) GetLocalBlock

func (wm *WalletManager) GetLocalBlock(height uint64) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*WalletManager) GetLocalNewBlock

func (wm *WalletManager) GetLocalNewBlock() (uint64, string)

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

func (WalletManager) GetLocalWalletBalance

func (wm WalletManager) GetLocalWalletBalance() (*openwallet.Balance, error)

func (WalletManager) GetRemoteWalletAddress

func (wm WalletManager) GetRemoteWalletAddress() ([]string, error)

func (WalletManager) GetRemoteWalletBalance

func (wm WalletManager) GetRemoteWalletBalance() (*openwallet.Balance, error)

func (*WalletManager) GetSmartContractDecoder

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

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetTransaction

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

GetTransactionsByHeight

func (*WalletManager) GetTransactionDecoder

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

GetTransactionDecoder 交易单解析器

func (*WalletManager) GetTransactionsByHeight

func (wm *WalletManager) GetTransactionsByHeight(height uint64) ([]*Transaction, error)

GetTransactionsByHeight

func (*WalletManager) GetUnscanRecords

func (wm *WalletManager) GetUnscanRecords() ([]*UnscanRecord, error)

获取未扫记录

func (*WalletManager) InitAssetsConfig

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

InitAssetsConfig 初始化默认配置

func (*WalletManager) LoadAssetsConfig

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

LoadAssetsConfig 加载外部配置

func (*WalletManager) SaveLocalBlock

func (wm *WalletManager) SaveLocalBlock(block *Block)

SaveLocalBlock 记录本地新区块

func (*WalletManager) SaveLocalNewBlock

func (wm *WalletManager) SaveLocalNewBlock(blockHeight uint64, blockHash string)

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

func (*WalletManager) SetupLog

func (wm *WalletManager) SetupLog(logDir, logFile string, debug bool)

SetupLog 配置日志

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

func (*WalletManager) TransferCoinRemote

func (wm *WalletManager) TransferCoinRemote(toAddress, toAmount, remark string) (string, error)

打币 远程调用

func (*WalletManager) ValidateAddress

func (wm *WalletManager) ValidateAddress(address string) (bool, error)

验证地址格式

func (*WalletManager) ValidateAddressRemote

func (wm *WalletManager) ValidateAddressRemote(address string) (bool, error)

远程验证地址格式

type WalletStatus

type WalletStatus struct {
	CurrentHeight    uint64
	CurrentStateHash string
	PrevStateHash    string
	Available        uint64
	Receiving        uint64
	Sending          uint64
	Maturing         uint64
	Locked           uint64
}

func NewWalletStatus

func NewWalletStatus(result *gjson.Result) *WalletStatus

type XDAGBlockScanner

type XDAGBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

	RescanLastBlockCount uint64 //重扫上N个区块数量
	// contains filtered or unexported fields
}

XDAGBlockScanner XDAG block scanner

func NewXDAGBlockScanner

func NewXDAGBlockScanner(wm *WalletManager) *XDAGBlockScanner

NewEOSBlockScanner create a block scanner

func (*XDAGBlockScanner) BatchExtractTransaction

func (bs *XDAGBlockScanner) BatchExtractTransaction(blockHeight uint64, blockHash string) error

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

func (*XDAGBlockScanner) ExtractTransaction

func (bs *XDAGBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, trx *Transaction, scanTargetFunc openwallet.BlockScanTargetFunc) ExtractResult

提取交易单

func (*XDAGBlockScanner) ExtractTransactionData

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

ExtractTransactionData

func (*XDAGBlockScanner) GetBalanceByAddress

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

GetBalanceByAddress 查询地址余额

func (*XDAGBlockScanner) GetBlockByHeight

func (bs *XDAGBlockScanner) GetBlockByHeight(height uint64) (*Block, error)

func (*XDAGBlockScanner) GetBlockHeight

func (bs *XDAGBlockScanner) GetBlockHeight() (uint64, error)

GetBlockHeight 获取区块链高度

func (*XDAGBlockScanner) GetCurrentBlock

func (bs *XDAGBlockScanner) GetCurrentBlock() (*Block, error)

GetCurrentBlock 获取当前最新区块

func (*XDAGBlockScanner) GetCurrentBlockHeader

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

GetCurrentBlockHeader 获取当前区块高度

func (*XDAGBlockScanner) GetGlobalMaxBlockHeight

func (bs *XDAGBlockScanner) GetGlobalMaxBlockHeight() uint64

GetGlobalMaxBlockHeight 获取区块链全网最大高度

func (*XDAGBlockScanner) GetScannedBlockHeader

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

GetScannedBlockHeader 获取当前扫描的区块头

func (*XDAGBlockScanner) GetScannedBlockHeight

func (bs *XDAGBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*XDAGBlockScanner) GetTransaction

func (bs *XDAGBlockScanner) GetTransaction(hash string) (*Transaction, error)

GetTransaction

func (*XDAGBlockScanner) InitExtractResult

func (bs *XDAGBlockScanner) InitExtractResult(tx *Transaction, sourceKey string, result *ExtractResult, operate int64)

InitTronExtractResult operate = 0: 输入输出提取,1: 输入提取,2:输出提取

func (*XDAGBlockScanner) RescanFailedRecord

func (bs *XDAGBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*XDAGBlockScanner) SaveUnscanRecord

func (bs *XDAGBlockScanner) SaveUnscanRecord(record *UnscanRecord) error

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

func (*XDAGBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*XDAGBlockScanner) ScanBlockTask

func (bs *XDAGBlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*XDAGBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

Jump to

Keyboard shortcuts

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