bitshares

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: GPL-3.0 Imports: 34 Imported by: 3

Documentation

Index

Constants

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

Variables

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

Functions

func NewAddressDecoder

func NewAddressDecoder(wm *WalletManager) *addressDecoder

NewAddressDecoder 地址解析器

func NewTransaction

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

func NewWebsocketAPI

func NewWebsocketAPI(api string) bitshares.WebsocketAPI

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
	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 BtsBlockScanner

type BtsBlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

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

BtsBlockScanner BTS block scanner

func NewBlockScanner

func NewBlockScanner(wm *WalletManager) *BtsBlockScanner

NewBlockScanner create a block scanner

func (*BtsBlockScanner) BatchExtractTransactions

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

BatchExtractTransactions 批量提取交易单

func (*BtsBlockScanner) DeleteUnscanRecord

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

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

func (*BtsBlockScanner) ExtractTransaction

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

ExtractTransaction 提取交易单

func (*BtsBlockScanner) GetBalanceByAddress

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

GetBalanceByAddress 查询地址余额

func (*BtsBlockScanner) GetChainInfo

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

GetChainInfo GetChainInfo

func (*BtsBlockScanner) GetCurrentBlockHeader

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

func (*BtsBlockScanner) GetGlobalHeadBlock

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

GetGlobalHeadBlock GetGlobalHeadBlock

func (*BtsBlockScanner) GetGlobalMaxBlockHeight

func (bs *BtsBlockScanner) GetGlobalMaxBlockHeight() uint64

GetGlobalMaxBlockHeight GetGlobalMaxBlockHeight

func (*BtsBlockScanner) GetLocalBlock

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

GetLocalBlock 获取本地区块数据

func (*BtsBlockScanner) GetLocalBlockHead

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

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

func (*BtsBlockScanner) GetScannedBlockHeight

func (bs *BtsBlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*BtsBlockScanner) InitExtractResult

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

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

func (*BtsBlockScanner) RescanFailedRecord added in v1.0.8

func (bs *BtsBlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*BtsBlockScanner) SaveLocalBlock

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

SaveLocalBlock 记录本地新区块

func (*BtsBlockScanner) SaveLocalBlockHead

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

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

func (*BtsBlockScanner) SaveUnscanRecord

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

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

func (*BtsBlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*BtsBlockScanner) ScanBlockTask

func (bs *BtsBlockScanner) ScanBlockTask()

ScanBlockTask scan block task

func (*BtsBlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

type CacheManager

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

func NewCacheManager

func NewCacheManager() CacheManager

func (*CacheManager) Add

func (cm *CacheManager) Add(key string, value interface{}, duration time.Duration) error

func (*CacheManager) Clear

func (cm *CacheManager) Clear()

func (*CacheManager) Contains

func (cm *CacheManager) Contains(key string) bool

func (*CacheManager) Get

func (cm *CacheManager) Get(key string) (interface{}, bool)

func (*CacheManager) GetCacheEntry

func (cm *CacheManager) GetCacheEntry(key string) (*openwallet.CacheEntry, bool)

func (*CacheManager) Remove

func (cm *CacheManager) Remove(key string) (interface{}, bool)

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 UnscanRecord

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

UnscanRecord 扫描失败的区块及交易

func NewUnscanRecord

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

NewUnscanRecord new UnscanRecord

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 *types.Transaction) (*BroadcastResponse, error)

BroadcastTransaction broadcast a transaction

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

func (c *WalletClient) GetAssetsBalance(account types.ObjectID, asset types.ObjectID) (*Balance, error)

GetAssetsBalance 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) GetRequiredFee

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

func (*WalletClient) GetTransaction

func (c *WalletClient) GetTransaction(height uint32, trxInBlock int) (*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
	ServerWS  string
	WalletAPI string
	//默认配置内容
	DefaultConfig string
	//曲线类型
	CurveType uint32
	//数据目录
	DataDir        string
	MemoPrivateKey string
	// 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    *BtsBlockScanner                //区块扫描器
	CacheManager    openwallet.ICacheManager        //缓存管理器
	WebsocketAPI    bitshares.WebsocketAPI          //bitshares WebsocketAPI
}

func NewWalletManager

func NewWalletManager(cacheManager openwallet.ICacheManager) *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) DeleteUnscanRecordNotFindTX added in v1.0.8

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

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

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetTransactionDecoder

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

GetTransactionDecoder 交易单解析器

func (*WalletManager) GetUnscanRecords added in v1.0.8

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