ontology

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

* Copyright 2018 The openwallet Authors * This file is part of the openwallet library. * * The openwallet library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The openwallet library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details.

Index

Constants

View Source
const (
	RPCServerRest        = 0 //RPC服务,Restful 测试 API
	RPCServerMainnetNode = 1 // RPC服务,主网节点 API
)
View Source
const (
	//币种
	Symbol    = "ONT"
	MasterKey = "Ontology seed"
	CurveType = owcrypt.ECC_CURVE_SECP256R1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrBalance

type AddrBalance struct {
	Address    string
	ONTBalance *big.Int
	ONGBalance *big.Int
	ONGUnbound *big.Int
	// contains filtered or unexported fields
}

type AddressDecoderV2 added in v1.1.3

type AddressDecoderV2 struct {
	openwallet.AddressDecoderV2Base
}

func NewAddressDecoderV2 added in v1.1.3

func NewAddressDecoderV2(wm *WalletManager) *AddressDecoderV2

NewAddressDecoder 地址解析器

func (*AddressDecoderV2) AddressDecode added in v1.1.3

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

AddressDecode 地址解析

func (*AddressDecoderV2) AddressEncode added in v1.1.3

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

AddressEncode 地址编码

func (*AddressDecoderV2) AddressVerify added in v1.1.3

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

AddressVerify 地址校验

func (*AddressDecoderV2) CustomCreateAddress added in v1.1.3

func (dec *AddressDecoderV2) CustomCreateAddress(account *openwallet.AssetsAccount, newIndex uint64) (*openwallet.Address, error)

CustomCreateAddress 创建账户地址

func (*AddressDecoderV2) PrivateKeyToWIF added in v1.1.3

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

PrivateKeyToWIF 私钥转WIF

func (*AddressDecoderV2) PublicKeyToAddress added in v1.1.3

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

PublicKeyToAddress 公钥转地址

func (*AddressDecoderV2) RedeemScriptToAddress added in v1.1.3

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

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

func (*AddressDecoderV2) SupportCustomCreateAddressFunction added in v1.1.3

func (dec *AddressDecoderV2) SupportCustomCreateAddressFunction() bool

SupportCustomCreateAddressFunction 支持创建地址实现

func (*AddressDecoderV2) WIFToPrivateKey added in v1.1.3

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

WIFToPrivateKey WIF转私钥

type Block

type Block struct {
	Hash             string
	Size             uint64
	Version          byte
	PrevBlockHash    string
	TransactionsRoot string
	BlockRoot        string
	Timestamp        uint64
	Height           uint64
	ConsensusData    string
	ConsensusPayload string
	NextBookkeeper   string
	Bookkeepers      []string
	SigData          []string
	Transactions     []string
}

func NewBlock

func NewBlock(json *gjson.Result) *Block

func (*Block) BlockHeader

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

BlockHeader 区块链头

type ContractDecoder

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

func NewContractDecoder

func NewContractDecoder(wm *WalletManager) *ContractDecoder

NewContractDecoder 智能合约解析器

func (*ContractDecoder) GetTokenBalanceByAddress

func (decoder *ContractDecoder) GetTokenBalanceByAddress(contract openwallet.SmartContract, address ...string) ([]*openwallet.TokenBalance, error)

type ExtractResult

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

ExtractResult 扫描完成的提取结果

type JsonRpcRequest

type JsonRpcRequest struct {
	Version string        `json:"jsonrpc"`
	Id      string        `json:"id"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
}

type JsonRpcResponse

type JsonRpcResponse struct {
	Id     string          `json:"id"`
	Error  int64           `json:"error"`
	Desc   string          `json:"desc"`
	Result json.RawMessage `json:"result"`
}

type Notify added in v1.0.1

type Notify struct {
	ContractAddress string
	IsFee           bool
	Method          string
	From            string
	To              string
	Amount          string
}

type ONTBlockScanner

type ONTBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

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

	RPCServer int
	// contains filtered or unexported fields
}

ONTBlockScanner ontology的区块链扫描器

func NewONTBlockScanner

func NewONTBlockScanner(wm *WalletManager) *ONTBlockScanner

NewONTBlockScanner 创建区块链扫描器

func (*ONTBlockScanner) BatchExtractTransaction

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

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

func (*ONTBlockScanner) DeleteUnscanRecord added in v1.1.0

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

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

func (*ONTBlockScanner) DeleteUnscanRecordNotFindTX added in v1.1.1

func (bs *ONTBlockScanner) DeleteUnscanRecordNotFindTX() error

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

func (*ONTBlockScanner) ExtractTransaction

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

ExtractTransaction 提取交易单

func (*ONTBlockScanner) ExtractTransactionData

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

func (*ONTBlockScanner) GetBalanceByAddress

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

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

func (*ONTBlockScanner) GetBalanceByAddressAndContract

func (bs *ONTBlockScanner) GetBalanceByAddressAndContract(fee *big.Int, contractAddress string, address ...string) ([]*openwallet.Balance, []bool, error)

func (*ONTBlockScanner) GetCurrentBlockHeader

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

GetCurrentBlockHeader 获取当前区块高度

func (*ONTBlockScanner) GetLocalBlock added in v1.1.0

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

GetLocalBlock 获取本地区块数据

func (*ONTBlockScanner) GetLocalBlockHead added in v1.1.0

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

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

func (*ONTBlockScanner) GetLocalNewBlock added in v1.1.1

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

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

func (*ONTBlockScanner) GetScannedBlockHeader

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

GetScannedBlockHeader 获取当前已扫区块高度

func (*ONTBlockScanner) GetScannedBlockHeight

func (bs *ONTBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*ONTBlockScanner) GetSourceKeyByAddress

func (bs *ONTBlockScanner) GetSourceKeyByAddress(address string) (string, bool)

GetSourceKeyByAddress 获取地址对应的数据源标识

func (*ONTBlockScanner) GetTransactionsByAddress

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

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

func (*ONTBlockScanner) GetUnscanRecords added in v1.1.0

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

func (*ONTBlockScanner) Pause

func (bs *ONTBlockScanner) Pause() error

Pause 暂停扫描

func (*ONTBlockScanner) RescanFailedRecord

func (bs *ONTBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*ONTBlockScanner) Restart

func (bs *ONTBlockScanner) Restart() error

Restart 继续扫描

func (*ONTBlockScanner) Run

func (bs *ONTBlockScanner) Run() error

Run 运行

func (*ONTBlockScanner) SaveLocalBlock added in v1.1.0

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

SaveLocalBlock 记录本地新区块

func (*ONTBlockScanner) SaveLocalBlockHead added in v1.1.0

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

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

func (*ONTBlockScanner) SaveLocalNewBlock added in v1.1.1

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

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

func (*ONTBlockScanner) SaveUnscanRecord

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

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

func (*ONTBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*ONTBlockScanner) ScanBlockTask

func (bs *ONTBlockScanner) ScanBlockTask()

ScanBlockTask 扫描任务

func (*ONTBlockScanner) ScanTxMemPool

func (bs *ONTBlockScanner) ScanTxMemPool()

ScanTxMemPool 扫描交易内存池

func (*ONTBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*ONTBlockScanner) Stop

func (bs *ONTBlockScanner) Stop() error

//Stop 停止扫描

func (*ONTBlockScanner) SupportBlockchainDAI added in v1.1.0

func (bs *ONTBlockScanner) SupportBlockchainDAI() bool

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

type RpcClient

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

func NewRpcClient

func NewRpcClient(addr string) *RpcClient

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult 保存结果

type Transaction

type Transaction struct {
	TxID        string `json:"txid"`
	Version     uint64 `json:"version"`
	Nonce       uint64 `json:"nonce"`
	GasPrice    uint64 `json:"gasprice"`
	GasLimit    uint64 `json:"gaslimit"`
	Payer       string `json:"payer"`
	TxType      uint64 `json:"txtype"`
	Notifys     []Notify
	BlockHeight uint64 `json:"blockheight"`
	BlockHash   string `json:"blockhash"`
}

type TransactionDecoder

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

func NewTransactionDecoder

func NewTransactionDecoder(wm *WalletManager) *TransactionDecoder

NewTransactionDecoder 交易单解析器

func (*TransactionDecoder) CreateONTRawTransaction

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

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)

func (*TransactionDecoder) CreateSummaryRawTransactionWithError added in v1.0.2

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

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

func (*TransactionDecoder) GetRawTransactionFeeRate added in v1.0.3

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

func (*TransactionDecoder) SignONTRawTransaction

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

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)

func (*TransactionDecoder) VerifyONTRawTransaction

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

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 WalletConfig

type WalletConfig struct {

	//币种
	Symbol    string
	MasterKey string

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

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

	//钱包服务API
	ServerAPI string
	//Restful API
	RestfulServerAPI string
	//Mainnet node API
	MainnetNodeAPI string
	//钱包安装的路径
	NodeInstallPath string
	//钱包数据文件目录
	WalletDataPath string
	//汇总阀值
	Threshold decimal.Decimal
	//汇总地址
	SumAddress string
	//汇总执行间隔时间
	CycleSeconds time.Duration
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//小数位长度
	CoinDecimal decimal.Decimal
	//核心钱包密码,配置有值用于自动解锁钱包
	WalletPassword string
	//s是否支持隔离验证
	SupportSegWit bool
	//GasLimit
	GasLimit      uint64
	GasPriceFixed uint64
	GasPriceType  uint64
	// data directory
	DataDir string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(symbol string, masterKey string) *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        //秘钥存取
	RPCClient       *RpcClient                    // RPC API
	Config          *WalletConfig                 //钱包管理配置
	WalletsInSum    map[string]*openwallet.Wallet //参与汇总的钱包
	Blockscanner    *ONTBlockScanner              //区块扫描器
	Decoder         openwallet.AddressDecoder     //地址编码器
	TxDecoder       openwallet.TransactionDecoder //交易单编码器
	Log             *log.OWLogger                 //日志工具
	ContractDecoder *ContractDecoder              //智能合约解析器
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) BackupWalletFlow

func (wm *WalletManager) BackupWalletFlow() error

备份钱包流程

func (*WalletManager) CreateAddressFlow

func (wm *WalletManager) CreateAddressFlow() error

创建地址流程

func (*WalletManager) CreateWalletFlow

func (wm *WalletManager) CreateWalletFlow() error

创建钱包流程

func (*WalletManager) CurveType

func (wm *WalletManager) CurveType() uint32

CurveType 曲线类型

func (*WalletManager) Decimal

func (wm *WalletManager) Decimal() int32

小数位精度

func (*WalletManager) FullName

func (wm *WalletManager) FullName() string

FullName 币种全名

func (*WalletManager) GetAddressDecode

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

AddressDecode 地址解析器

func (*WalletManager) GetAddressWithBalance

func (wm *WalletManager) GetAddressWithBalance(address ...*openwallet.Address) error

GetAddressWithBalance

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

func (wm *WalletManager) GetWalletInfo(walletID string) (*openwallet.Wallet, error)

GetWalletInfo 获取钱包列表

func (*WalletManager) GetWalletList

func (wm *WalletManager) GetWalletList() error

GetWalletList 获取钱包列表

func (*WalletManager) GetWallets

func (wm *WalletManager) GetWallets() ([]*openwallet.Wallet, error)

GetWallets 获取钱包列表

func (*WalletManager) ImportWatchOnlyAddress

func (wm *WalletManager) ImportWatchOnlyAddress(address ...*openwallet.Address) error

ImportWatchOnlyAddress 导入观测地址

func (*WalletManager) InitAssetsConfig

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

InitAssetsConfig 初始化默认配置

func (*WalletManager) InitConfigFlow

func (wm *WalletManager) InitConfigFlow() error

初始化配置流程

func (*WalletManager) InitNodeConfigFlow

func (wm *WalletManager) InitNodeConfigFlow() error

InitNodeConfig 初始化节点配置文件

func (*WalletManager) InstallNodeFlow

func (wm *WalletManager) InstallNodeFlow() error

InstallNode 安装节点

func (*WalletManager) LoadAssetsConfig

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

LoadAssetsConfig 加载外部配置

func (*WalletManager) RestartNodeFlow

func (wm *WalletManager) RestartNodeFlow() error

RestartNodeFlow 重启节点

func (*WalletManager) RestoreWalletFlow

func (wm *WalletManager) RestoreWalletFlow() error

RestoreWalletFlow 恢复钱包流程

func (*WalletManager) SendRawTransaction

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

SendRawTransaction 广播交易

func (*WalletManager) SetConfigFlow

func (wm *WalletManager) SetConfigFlow(subCmd string) error

SetConfigFlow 初始化配置流程

func (*WalletManager) ShowConfig

func (wm *WalletManager) ShowConfig() error

查看配置信息

func (*WalletManager) ShowConfigInfo

func (wm *WalletManager) ShowConfigInfo(subCmd string) error

ShowConfigInfo 查看配置信息

func (*WalletManager) ShowNodeInfo

func (wm *WalletManager) ShowNodeInfo() error

ShowNodeInfo 显示节点信息

func (*WalletManager) StartNodeFlow

func (wm *WalletManager) StartNodeFlow() error

StartNodeFlow 开启节点

func (*WalletManager) StopNodeFlow

func (wm *WalletManager) StopNodeFlow() error

StopNodeFlow 关闭节点

func (*WalletManager) SummaryFollow

func (wm *WalletManager) SummaryFollow() error

SummaryFollow 汇总流程

func (*WalletManager) Symbol

func (wm *WalletManager) Symbol() string

Symbol 币种标识

func (*WalletManager) TransferFlow

func (wm *WalletManager) TransferFlow() error

SendTXFlow 发送交易

Jump to

Keyboard shortcuts

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