whitecoin

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: GPL-3.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CurveType = owcrypt.ECC_CURVE_SECP256K1
)
View Source
const DECIMAL_COUNT = 8
View Source
const TimeLayout = `2006-01-02T15:04:05`

Variables

View Source
var (
	//币种
	Symbol = "XWC"
)

Functions

func ConvertAmountToFloat added in v1.2.2

func ConvertAmountToFloat(amount string, decimals int) (decimal.Decimal, error)

func ConvertFloatStringToBigInt added in v1.2.2

func ConvertFloatStringToBigInt(amount string, decimals int) (*big.Int, error)

func ConvertToDecimal added in v1.2.2

func ConvertToDecimal(amount string) (*big.Int, error)

从系统内的小数值转换为区块链中的整数值

func ConvertToFloat added in v1.2.2

func ConvertToFloat(amount string) (decimal.Decimal, error)

从区块链中的值转换为系统内显示的小数值

func NewAddressDecoder

func NewAddressDecoder(wm *WalletManager) *addressDecoder

NewAddressDecoder 地址解析器

func NewTransaction

func NewTransaction(result *gjson.Result, transactionID string) (*types.Transaction, error)

func ParseHeader

func ParseHeader(b *Block) *openwallet.BlockHeader

ParseHeader 区块链头

Types

type Asset

type Asset struct {
	ID                 types.ObjectID `json:"id"`
	Symbol             string         `json:"symbol"`
	Precision          uint8          `json:"precision"`
	Issuer             string         `json:"issuer"`
	DynamicAssetDataID string         `json:"dynamic_asset_data_id"`
}

type Balance

type Balance struct {
	AssetID types.ObjectID `json:"asset_id"`
	Amount  string         `json:"amount"`
}

func NewBalance

func NewBalance(result gjson.Result) *Balance

type Block

type Block struct {
	Height                uint64               `json:"number"`
	BlockID               string               `json:"block_id"`
	TransactionMerkleRoot string               `json:"transaction_merkle_root"`
	Previous              string               `json:"previous"`
	Timestamp             types.Time           `json:"timestamp"`
	Witness               string               `json:"witness"`
	Extensions            []json.RawMessage    `json:"extensions"`
	WitnessSignature      string               `json:"witness_signature"`
	Transactions          []*types.Transaction `json:"transactions"`
	TransactionIDs        []string             `json:"transaction_ids"`
}

func NewBlock

func NewBlock(height uint32, result *gjson.Result) *Block

func (*Block) CalculateID

func (block *Block) CalculateID() error

type BlockHeader

type BlockHeader struct {
	TransactionMerkleRoot string            `json:"transaction_merkle_root"`
	Previous              string            `json:"previous"`
	Timestamp             types.Time        `json:"timestamp"`
	Witness               string            `json:"witness"`
	Extensions            []json.RawMessage `json:"extensions"`
	WitnessSignature      string            `json:"witness_signature"`
}

func NewBlockHeader

func NewBlockHeader(result *gjson.Result) *BlockHeader

func (*BlockHeader) CalculateID

func (block *BlockHeader) CalculateID() (string, error)

func (*BlockHeader) Marshal

func (block *BlockHeader) Marshal(encoder *encoding.Encoder) error

MarshalBlockHeader implements encoding.Marshaller interface.

func (*BlockHeader) Serialize

func (block *BlockHeader) Serialize() ([]byte, error)

type BlockchainInfo

type BlockchainInfo struct {
	HeadBlockNum             uint64    `json:"head_block_number"`
	HeadBlockID              string    `json:"head_block_id"`
	LastIrreversibleBlockNum uint64    `json:"last_irreversible_block_num"`
	Timestamp                time.Time `json:"time"`
}

func NewBlockchainInfo

func NewBlockchainInfo(result *gjson.Result) *BlockchainInfo

type BroadcastResponse

type BroadcastResponse struct {
	ID string `json:"id"`
}

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)

GetTokenBalanceByAddress return the balance by account alias, queried by rpc

type ExtractResult

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

ExtractResult extract result

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult result

type TransactionDecoder

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

TransactionDecoder 交易单解析器

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)

SubmitRawTransaction 广播交易单

func (*TransactionDecoder) VerifyRawTransaction

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

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

type WalletClient

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

WalletClient is a Bitshares 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(serverAPI, walletAPI string, debug bool) *WalletClient

NewWalletClient init a rpc client

func (*WalletClient) BroadcastTransaction

func (c *WalletClient) BroadcastTransaction(tx *bt.SignedTransaction) (string, error)

BroadcastTransaction broadcast a transaction

func (*WalletClient) GetAccountByAddr

func (c *WalletClient) GetAccountByAddr(address string) (*types.Account, error)

func (*WalletClient) GetAccountID

func (c *WalletClient) GetAccountID(name string) (*types.ObjectID, error)

GetAssetsBalance Returns information about the given account.

func (*WalletClient) GetAccounts

func (c *WalletClient) GetAccounts(names_or_ids ...string) ([]*types.Account, error)

GetAssetsBalance Returns information about the given account.

func (*WalletClient) GetAddrBalance

func (c *WalletClient) GetAddrBalance(addr string, asset types.ObjectID) (*Balance, error)

GetAddrBalance Returns information about the given account.

func (*WalletClient) GetBlockByHeight

func (c *WalletClient) GetBlockByHeight(height uint32) (*Block, error)

GetBlockByHeight returns a certain block

func (*WalletClient) GetBlockchainInfo

func (c *WalletClient) GetBlockchainInfo() (*BlockchainInfo, error)

GetBlockchainInfo returns current blockchain data

func (*WalletClient) GetObjects

func (c *WalletClient) GetObjects(assets ...types.ObjectID) (*gjson.Result, error)

GetObjects return a block by the given block number

func (*WalletClient) GetTransaction

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

GetTransaction returns the TX

func (*WalletClient) GetTransactionID

func (c *WalletClient) GetTransactionID(tx *types.Transaction) (string, error)

GetTransactionID return the TX ID

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol string

	//区块链数据文件
	BlockchainFile string

	//钱包服务API
	ServerAPI string
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//数据目录
	DataDir string
	//chain id
	ChainID string
	//Fix XWC Required Fee
	FixFees int64
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(symbol string) *WalletConfig

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase

	Api             *WalletClient                   // 节点客户端
	Config          *WalletConfig                   // 节点配置
	Decoder         openwallet.AddressDecoder       //地址编码器
	DecoderV2       openwallet.AddressDecoderV2     //地址编码器V2
	TxDecoder       openwallet.TransactionDecoder   //交易单编码器
	Log             *log.OWLogger                   //日志工具
	ContractDecoder openwallet.SmartContractDecoder //智能合约解析器
	Blockscanner    openwallet.BlockScanner         //区块扫描器
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) BalanceModelType

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

BalanceModelType 余额模型类型

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

func (wm *WalletManager) GetAddressDecoderV2() openwallet.AddressDecoderV2

GetAddressDecode 地址解析器 如果实现了AddressDecoderV2,就无需实现AddressDecoder

func (*WalletManager) GetAssetsLogger

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

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlockScanner

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

GetBlockScanner 获取区块链

func (*WalletManager) GetRequiredFee

func (wm *WalletManager) GetRequiredFee(ops []bt.Operation, assetID string) ([]bt.AssetAmount, error)

func (*WalletManager) GetSmartContractDecoder

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

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetTransactionDecoder

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

GetTransactionDecoder 交易单解析器

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

func (wm *WalletManager) Symbol() string

Symbol 币种标识

type XWCBlockScanner

type XWCBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

	IsScanMemPool        bool   //是否扫描交易池
	RescanLastBlockCount uint64 //重扫上N个区块数量
	// contains filtered or unexported fields
}

XWCBlockScanner BTS block scanner

func NewBlockScanner

func NewBlockScanner(wm *WalletManager) *XWCBlockScanner

NewBlockScanner create a block scanner

func (*XWCBlockScanner) BatchExtractTransactions

func (bs *XWCBlockScanner) BatchExtractTransactions(blockHeight uint64, blockHash string, blockTime int64, transactions []*types.Transaction, txIDs []string) error

BatchExtractTransactions 批量提取交易单

func (*XWCBlockScanner) DeleteUnscanRecord

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

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

func (*XWCBlockScanner) ExtractTransaction

func (bs *XWCBlockScanner) ExtractTransaction(blockHeight uint64, blockHash string, blockTime int64, transaction *types.Transaction, scanTargetFunc openwallet.BlockScanTargetFunc) ExtractResult

ExtractTransaction 提取交易单

func (*XWCBlockScanner) ExtractTransactionData

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

ExtractTransactionData 扫描一笔交易

func (*XWCBlockScanner) GetBalanceByAddress

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

GetBalanceByAddress 查询地址余额

func (*XWCBlockScanner) GetChainInfo

func (bs *XWCBlockScanner) GetChainInfo() (infoResp *BlockchainInfo, err error)

GetChainInfo GetChainInfo

func (*XWCBlockScanner) GetCurrentBlockHeader

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

func (*XWCBlockScanner) GetGlobalHeadBlock

func (bs *XWCBlockScanner) GetGlobalHeadBlock() (block *Block, err error)

GetGlobalHeadBlock GetGlobalHeadBlock

func (*XWCBlockScanner) GetGlobalMaxBlockHeight

func (bs *XWCBlockScanner) GetGlobalMaxBlockHeight() uint64

GetGlobalMaxBlockHeight GetGlobalMaxBlockHeight

func (*XWCBlockScanner) GetLocalBlock

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

GetLocalBlock 获取本地区块数据

func (*XWCBlockScanner) GetLocalBlockHead

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

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

func (*XWCBlockScanner) GetScannedBlockHeight

func (bs *XWCBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*XWCBlockScanner) GetUnscanRecords

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

func (*XWCBlockScanner) InitExtractResult

func (bs *XWCBlockScanner) InitExtractResult(sourceKey string, operation *types.TransferOperation, result *ExtractResult, optType int64)

InitExtractResult optType = 0: 输入输出提取,1: 输入提取,2:输出提取

func (*XWCBlockScanner) RescanFailedRecord

func (bs *XWCBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*XWCBlockScanner) SaveLocalBlock

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

SaveLocalBlock 记录本地新区块

func (*XWCBlockScanner) SaveLocalBlockHead

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

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

func (*XWCBlockScanner) SaveUnscanRecord

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

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

func (*XWCBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*XWCBlockScanner) ScanBlockTask

func (bs *XWCBlockScanner) ScanBlockTask()

ScanBlockTask scan block task

func (*XWCBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*XWCBlockScanner) SupportBlockchainDAI

func (bs *XWCBlockScanner) SupportBlockchainDAI() bool

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

Jump to

Keyboard shortcuts

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