ninjacoin

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//币种
	Symbol    = "NINJA"
	Decimal   = 5
	CurveType = owcrypt.ECC_CURVE_ED25519

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

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressCreateResult

type AddressCreateResult struct {
	Success bool
	Err     error
	Address string
}

type ApiClient

type ApiClient struct {
	WalletAPI, BlockAPI string
	Debug               bool
	BlockClient         *req.Req
	WalletClient        *walletapi.WalletAPI
}

A Client is a Bitcoin RPC BlockClient. 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(blockAPIUrl, walletIpAddr, walletIpPort, walletRpcPassword string, walletObj walletapi.Wallet, debug bool) *ApiClient

func (*ApiClient) CreateAddress

func (c *ApiClient) CreateAddress() (string, error)

CreateAddress

func (*ApiClient) CreateBatchAddress

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

CreateBatchAddress 批量创建地址 @count 连续创建数量 @workerSize 并行线程数。建议20条。

func (*ApiClient) GetAddressBalance

func (c *ApiClient) GetAddressBalance(address string) (string, error)

获取地址余额

func (*ApiClient) GetAddressList

func (c *ApiClient) GetAddressList() ([]string, error)

GetAddressList

func (*ApiClient) GetBlockByHash

func (c *ApiClient) GetBlockByHash(hash string) (*Block, error)

GetBlockByHash

func (*ApiClient) GetBlockByHeight

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

GetBlockByHeight

func (*ApiClient) GetTransaction

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

GetTransaction

func (*ApiClient) GetTransactionsByHeight

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

GetTransactionsByHeight

func (*ApiClient) GetWalletStatus

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

GetWalletStatus

func (*ApiClient) SendTransaction

func (c *ApiClient) SendTransaction(to, amount, paymentId string) (string, error)

SendTransaction

func (*ApiClient) ValidateAddress

func (c *ApiClient) ValidateAddress(address string) bool

验证地址

type Block

type Block struct {
	Hash          string
	PrevBlockHash string
	Height        uint64
	Txs           []walletapi.Transaction
}

func NewBlock

func NewBlock(result *gjson.Result) *Block

func (*Block) BlockHeader

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

BlockHeader 区块链头

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

func (c *Client) GetAddressBalance(address string) (string, error)

验证地址

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, paymentId 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 NinjaBlockScanner

type NinjaBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

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

func NewNinjaBlockScanner

func NewNinjaBlockScanner(wm *WalletManager) *NinjaBlockScanner

// NewEOSBlockScanner create a block scanner

func (*NinjaBlockScanner) BatchExtractTransaction

func (bs *NinjaBlockScanner) BatchExtractTransaction(blockHeight uint64, blockHash string, txs []walletapi.Transaction, blockTime int64) error

BatchExtractTransaction 批量提取交易单 直接获取区块 Payment 操作

func (*NinjaBlockScanner) DeleteUnscanRecord

func (bs *NinjaBlockScanner) DeleteUnscanRecord(height uint64) error

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

func (*NinjaBlockScanner) DeleteUnscanRecordNotFindTX

func (bs *NinjaBlockScanner) DeleteUnscanRecordNotFindTX() error

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

func (*NinjaBlockScanner) ExtractTransaction

func (bs *NinjaBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, tx walletapi.Transaction, scanTargetFunc openwallet.BlockScanTargetFunc) ExtractResult

提取交易单

func (*NinjaBlockScanner) ExtractTransactionData

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

ExtractTransactionData

func (*NinjaBlockScanner) GetBalanceByAddress

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

GetBalanceByAddress 查询地址余额

func (*NinjaBlockScanner) GetBlockByHeight

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

func (*NinjaBlockScanner) GetCurrentBlock

func (bs *NinjaBlockScanner) GetCurrentBlock() (*WalletStatus, error)

GetBlockHeight 获取区块链高度

func (*NinjaBlockScanner) GetCurrentBlockHeader

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

GetCurrentBlockHeader 获取当前区块高度

func (*NinjaBlockScanner) GetGlobalMaxBlockHeight

func (bs *NinjaBlockScanner) GetGlobalMaxBlockHeight() uint64

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

func (*NinjaBlockScanner) GetLocalBlock

func (bs *NinjaBlockScanner) GetLocalBlock(height uint64) (*openwallet.BlockHeader, error)

GetLocalBlock 获取本地区块数据

func (*NinjaBlockScanner) GetLocalBlockHead

func (bs *NinjaBlockScanner) GetLocalBlockHead() (uint64, string, error)

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

func (*NinjaBlockScanner) GetLocalNewBlock

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

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

func (*NinjaBlockScanner) GetScannedBlockHeader

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

GetScannedBlockHeader 获取已扫高度区块头

func (*NinjaBlockScanner) GetScannedBlockHeight

func (bs *NinjaBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*NinjaBlockScanner) GetUnscanRecords

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

func (*NinjaBlockScanner) InitExtractResult

func (bs *NinjaBlockScanner) InitExtractResult(tx walletapi.Transaction, feePayed string, blockHeight uint64, blockHash string,
	sourceKey string, result *ExtractResult, scanTargetFunc openwallet.BlockScanTargetFunc, operate int64)

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

func (*NinjaBlockScanner) Pause

func (bs *NinjaBlockScanner) Pause() error

Pause 暂停扫描

func (*NinjaBlockScanner) RescanFailedRecord

func (bs *NinjaBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*NinjaBlockScanner) Restart

func (bs *NinjaBlockScanner) Restart() error

Restart 继续扫描

func (*NinjaBlockScanner) Run

func (bs *NinjaBlockScanner) Run() error

Run 运行

func (*NinjaBlockScanner) SaveLocalBlock

func (bs *NinjaBlockScanner) SaveLocalBlock(blockHeader *openwallet.BlockHeader) error

SaveLocalBlock 记录本地新区块

func (*NinjaBlockScanner) SaveLocalBlockHead

func (bs *NinjaBlockScanner) SaveLocalBlockHead(blockHeight uint64, blockHash string) error

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

func (*NinjaBlockScanner) SaveLocalNewBlock

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

GetTransaction

func (bs *NinjaBlockScanner) GetTransaction(hash string) (*Transaction, error) {
	r, err := bs.wm.client.TransactionByID(hash)
	if err != nil {
		return nil, err
	}
	return NewTransaction(r), nil
}

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

func (*NinjaBlockScanner) SaveUnscanRecord

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

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

func (*NinjaBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*NinjaBlockScanner) ScanBlockTask

func (bs *NinjaBlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*NinjaBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*NinjaBlockScanner) Stop

func (bs *NinjaBlockScanner) Stop() error

//Stop 停止扫描

func (*NinjaBlockScanner) SupportBlockchainDAI

func (bs *NinjaBlockScanner) SupportBlockchainDAI() bool

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

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

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

获取地址余额

func (*Server) GetWalletStatus

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

func (*Server) Listen

func (server *Server) Listen()

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 {
	Comment       string
	CreateTime    int64
	Fee           uint64
	TxID          string
	Value         uint64
	Kernel        string
	Receiver      string
	Sender        string
	Income        bool
	Status        int64
	StatusString  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) 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) 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 WalletConfig

type WalletConfig struct {

	//币种
	Symbol string

	//区块链数据文件
	BlockchainFile string

	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	// 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    *NinjaBlockScanner              //区块扫描器
	// contains filtered or unexported fields
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) BackupWalletData

func (wm *WalletManager) BackupWalletData() error

BackupWalletData

func (*WalletManager) BalanceModelType

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

BalanceModelType 余额模型类别

func (WalletManager) CreateLocalWalletAddress

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

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

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

func (WalletManager) GetLocalWalletBalance

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

func (WalletManager) GetRemoteBlockByHeight

func (wm WalletManager) GetRemoteBlockByHeight(height uint64) (*Block, 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) InitAssetsConfig

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

InitAssetsConfig 初始化默认配置

func (*WalletManager) LoadAssetsConfig

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

LoadAssetsConfig 加载外部配置

func (*WalletManager) SetupLog

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

SetupLog 配置日志

func (*WalletManager) StartSummaryWallet

func (wm *WalletManager) StartSummaryWallet() error

func (*WalletManager) SummaryWalletProcess

func (wm *WalletManager) SummaryWalletProcess(summaryToAddress string) (string, string, string, error)

汇总到目标地址 return txId,summaryAmount,feeAmount,err

func (*WalletManager) SummaryWalletProcessRemote

func (wm *WalletManager) SummaryWalletProcessRemote(summaryToAddress string) (string, string, string, error)

汇总 远程调用

func (*WalletManager) SummaryWallets

func (wm *WalletManager) SummaryWallets()

SummaryWallets 执行汇总流程

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

func (*WalletManager) TransferCoinRemote

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

打币 远程调用

func (*WalletManager) ValidateAddress

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

验证地址格式

func (*WalletManager) ValidateAddressRemote

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

远程验证地址格式

type WalletStatus

type WalletStatus struct {
	CurrentHeight uint64
	CurrentHash   string
}

func NewWalletStatus

func NewWalletStatus(result *gjson.Result) *WalletStatus

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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