casper

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//币种
	Symbol    = "CSPR"
	CurveType = owcrypt.ECC_CURVE_ED25519
	Decimals  = int32(9)
)
View Source
const (
	BlockIdentifierLastBlock = uint8(0)
	BlockIdentifierHeight    = uint8(1)
	BlockIdentifierHash      = uint8(2)
)
View Source
const (
	ED25519_TAG   = uint8(1)
	SECP256K1_TAG = uint8(2)
)
View Source
const (
	SignatureAlgorithmEd25519   = "ed25519"
	SignatureAlgorithmSecp256K1 = "secp256k1"
)
View Source
const (
	CLTypeBool      = uint8(0)
	CLTypeI32       = uint8(1)
	CLTypeI64       = uint8(2)
	CLTypeU8        = uint8(3)
	CLTypeU32       = uint8(4)
	CLTypeU64       = uint8(5)
	CLTypeU128      = uint8(6)
	CLTypeU256      = uint8(7)
	CLTypeU512      = uint8(8)
	CLTypeUnit      = uint8(9)
	CLTypeString    = uint8(10)
	CLTypeKey       = uint8(11)
	CLTypeURef      = uint8(12)
	CLTypePublicKey = uint8(22)
	CLTypeOption    = uint8(13)
	CLTypeList      = uint8(14)
	CLTypeByteArray = uint8(15)
	CLTypeResult    = uint8(16)
	CLTypeMap       = uint8(17)
	CLTypeTuple1    = uint8(18)
	CLTypeTuple2    = uint8(19)
	CLTypeTuple3    = uint8(20)
	CLTypeAny       = uint8(21)
)

Variables

This section is empty.

Functions

func PublicKeyToHash

func PublicKeyToHash(publicKey string, tag uint8) string

PublicKeyToHash 公钥转hash hex

func ToAccountHex

func ToAccountHex(publicKey string) string

Types

type AddressDecoderV2 added in v1.0.1

type AddressDecoderV2 struct {
	*openwallet.AddressDecoderV2Base
}

AddressDecoderV2

func (*AddressDecoderV2) AddressDecode added in v1.0.1

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

AddressDecode 地址解析

func (*AddressDecoderV2) AddressEncode added in v1.0.1

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

AddressEncode 地址编码

func (*AddressDecoderV2) AddressVerify added in v1.0.1

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

AddressVerify 地址校验

func (*AddressDecoderV2) CustomCreateAddress added in v1.0.1

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

CustomCreateAddress 创建账户地址

func (*AddressDecoderV2) SupportCustomCreateAddressFunction added in v1.0.1

func (dec *AddressDecoderV2) SupportCustomCreateAddressFunction() bool

SupportCustomCreateAddressFunction 支持创建地址实现

type Approval

type Approval struct {
	Signature string `json:"signature"`
	Signer    string `json:"signer"`
}

type Block

type Block struct {
	Hash              string
	StateRootHash     string
	Previousblockhash string
	Height            uint64
	Version           string
	Time              uint64
	Fork              bool
	TransferHashes    []string
}

func NewBlock

func NewBlock(json gjson.Result) *Block

func (*Block) BlockHeader

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

BlockHeader 区块链头

type BlockScanner

type BlockScanner struct {
	*openwallet.BlockScannerBase

	CurrentBlockHeight uint64 //当前区块高度

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

BlockScanner block scanner

func NewBlockScanner

func NewBlockScanner(wm *WalletManager) *BlockScanner

NewBlockScanner create a block scanner

func (*BlockScanner) BatchExtractTransactions

func (bs *BlockScanner) BatchExtractTransactions(blockHeight uint64, blockHash string, blockTime int64) error

BatchExtractTransactions 批量提取交易单

func (*BlockScanner) DeleteUnscanRecord

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

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

func (*BlockScanner) ExtractTransaction

func (bs *BlockScanner) ExtractTransaction(tx *Transfer, blockTime int64, scanTargetFunc openwallet.BlockScanTargetFuncV2) ExtractResult

ExtractTransaction 提取交易单

func (*BlockScanner) ExtractTransactionData

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

ExtractTransactionData 扫描一笔交易

func (*BlockScanner) GetBalanceByAddress

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

GetBalanceByAddress 查询地址余额

func (*BlockScanner) GetCurrentBlockHeader

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

func (*BlockScanner) GetGlobalMaxBlockHeight

func (bs *BlockScanner) GetGlobalMaxBlockHeight() uint64

GetGlobalMaxBlockHeight GetGlobalMaxBlockHeight

func (*BlockScanner) GetLocalBlock

func (bs *BlockScanner) GetLocalBlock(height uint64) (*Block, error)

GetLocalBlock 获取本地区块数据

func (*BlockScanner) GetLocalBlockHead

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

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

func (*BlockScanner) GetScannedBlockHeight

func (bs *BlockScanner) GetScannedBlockHeight() uint64

GetScannedBlockHeight 获取已扫区块高度

func (*BlockScanner) GetUnscanRecords

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

func (*BlockScanner) InitExtractResult

func (bs *BlockScanner) InitExtractResult(source1 *openwallet.ScanTargetResult, source2 *openwallet.ScanTargetResult, tx *Transfer, result *ExtractResult, optType int64)

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

func (*BlockScanner) RescanFailedRecord

func (bs *BlockScanner) RescanFailedRecord()

rescanFailedRecord 重扫失败记录

func (*BlockScanner) SaveLocalBlock

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

SaveLocalBlock 记录本地新区块

func (*BlockScanner) SaveLocalBlockHead

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

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

func (*BlockScanner) SaveUnscanRecord

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

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

func (*BlockScanner) ScanBlock

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

ScanBlock 扫描指定高度区块

func (*BlockScanner) ScanBlockTask

func (bs *BlockScanner) ScanBlockTask()

ScanBlockTask scan block task

func (*BlockScanner) SetRescanBlockHeight

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

SetRescanBlockHeight 重置区块链扫描高度

func (*BlockScanner) SupportBlockchainDAI

func (bs *BlockScanner) SupportBlockchainDAI() bool

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

type ByteArrayValue

type ByteArrayValue struct {
	RawBytes []byte
}

func (*ByteArrayValue) ClType

func (bav *ByteArrayValue) ClType() uint8

func (*ByteArrayValue) ClTypeToBytes

func (bav *ByteArrayValue) ClTypeToBytes() []byte

func (*ByteArrayValue) ClTypeToJson

func (bav *ByteArrayValue) ClTypeToJson() interface{}

func (*ByteArrayValue) ToBytes

func (bav *ByteArrayValue) ToBytes() []byte

type CLTypedAndToBytes

type CLTypedAndToBytes interface {
	ToBytes
	ClType() uint8
	ClTypeToBytes() []byte
	ClTypeToJson() interface{}
}

type CLValue

type CLValue struct {
	ClType uint8
	Parsed interface{}
	Value  CLTypedAndToBytes
	Bytes  string
}

func FromByteArray

func FromByteArray(bytes []byte) *CLValue

func FromOption

func FromOption(t CLTypedAndToBytes, innerType uint8) *CLValue

func FromU512

func FromU512(amount string) *CLValue

func NewCLValue

func NewCLValue(value CLTypedAndToBytes) *CLValue

func (*CLValue) MarshalJSON

func (clv *CLValue) MarshalJSON() ([]byte, error)

func (*CLValue) ToBytes

func (clv *CLValue) ToBytes() []byte

type Client

type Client struct {
	BaseURL 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 NewClient

func NewClient(url string, debug bool) *Client

func (*Client) Call

func (c *Client) Call(path string, request interface{}) (*gjson.Result, error)

Call calls a remote procedure on another node, specified by the path.

type ClientInterface

type ClientInterface interface {
	Call(path string, request []interface{}) (*gjson.Result, error)
}

type Deploy

type Deploy struct {
	Approvals []*Approval `json:"approvals"`
	Hash      string      `json:"hash"`
	Header    *Header     `json:"header"`
	Payment   *Payment
	Transfer  *Transfer `json:"session"`
}

func (*Deploy) MarshalJSON

func (deploy *Deploy) MarshalJSON() ([]byte, error)

type ExtractResult

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

ExtractResult extract result

type Header struct {
	Account      *PublicKey
	BodyHash     []byte
	ChainName    string
	Dependencies []ToBytes
	GasPrice     uint64
	Timestamp    int64
	Ttl          uint64
}

func (*Header) MarshalJSON

func (header *Header) MarshalJSON() ([]byte, error)

type NamedArg

type NamedArg struct {
	Name  string
	Value *CLValue
}

func (*NamedArg) ToBytes

func (arg *NamedArg) ToBytes() []byte

type NumberCoder

type NumberCoder struct {
	BitSize uint64
	Signed  bool
	Val     *big.Int
	Name    string
}

func (*NumberCoder) ToBytes

func (number *NumberCoder) ToBytes() []byte

type Option

type Option struct {
	Inner CLTypedAndToBytes
}

func (*Option) ClType

func (op *Option) ClType() uint8

func (*Option) ClTypeToBytes

func (op *Option) ClTypeToBytes() []byte

func (*Option) ClTypeToJson

func (op *Option) ClTypeToJson() interface{}

func (*Option) ToBytes

func (op *Option) ToBytes() []byte

type Payment

type Payment struct {
	Amount      string
	ModuleBytes []byte
	Args        *RuntimeArgs
}

func StandardPayment

func StandardPayment(amount string) *Payment

func (*Payment) MarshalJSON

func (p *Payment) MarshalJSON() ([]byte, error)

func (*Payment) Tag

func (p *Payment) Tag() uint8

func (*Payment) ToBytes

func (p *Payment) ToBytes() []byte

type PublicKey

type PublicKey struct {
	RawPublicKey []byte
	Tag          uint8
}

func (*PublicKey) ClType

func (pk *PublicKey) ClType() uint8

func (*PublicKey) ClTypeToBytes

func (pk *PublicKey) ClTypeToBytes() []byte

func (*PublicKey) ClTypeToJson

func (pk *PublicKey) ClTypeToJson() interface{}

func (*PublicKey) ToBytes

func (pk *PublicKey) ToBytes() []byte

type RuntimeArgs

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

func NewRuntimeArgs

func NewRuntimeArgs() *RuntimeArgs

func (*RuntimeArgs) Insert

func (ra *RuntimeArgs) Insert(name string, value *CLValue)

func (*RuntimeArgs) MarshalJSON

func (ra *RuntimeArgs) MarshalJSON() ([]byte, error)

func (*RuntimeArgs) ToBytes

func (ra *RuntimeArgs) ToBytes() []byte

type SaveResult

type SaveResult struct {
	TxID        string
	BlockHeight uint64
	Success     bool
}

SaveResult result

type ToBytes

type ToBytes interface {
	ToBytes() []byte
}

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 Transfer

type Transfer struct {
	Amount      string
	Target      string
	ID          string
	Args        *RuntimeArgs
	From        string
	To          string
	DeployHash  string
	Source      string
	Gas         string
	BlockHeight uint64
	BlockHash   string
}

func NewTransfer

func NewTransfer(amount string, target []byte, id string) *Transfer

func (*Transfer) MarshalJSON

func (t *Transfer) MarshalJSON() ([]byte, error)

func (*Transfer) Tag

func (t *Transfer) Tag() uint8

func (*Transfer) ToBytes

func (t *Transfer) ToBytes() []byte

type U512

type U512 struct {
	NumberCoder
}

func (*U512) ClType

func (u512 *U512) ClType() uint8

func (*U512) ClTypeToBytes

func (u512 *U512) ClTypeToBytes() []byte

func (*U512) ClTypeToJson

func (u512 *U512) ClTypeToJson() interface{}

type U64

type U64 struct {
	NumberCoder
}

func NewU64

func NewU64(amount string) *U64

func (*U64) ClType

func (u64 *U64) ClType() uint8

func (*U64) ClTypeToBytes

func (u64 *U64) ClTypeToBytes() []byte

func (*U64) ClTypeToJson

func (u64 *U64) ClTypeToJson() interface{}

type WalletConfig

type WalletConfig struct {

	//币种
	Symbol string
	//本地数据库文件路径
	DBPath string
	//钱包服务API
	ServerAPI string
	//最低手续费
	MinFees decimal.Decimal
	//最新转账金额
	TransferMinimumMotes decimal.Decimal
	//数据目录
	DataDir string
	//曲线类型
	CurveType uint32
	//网络名
	NetworkName string
}

func NewConfig

func NewConfig(symbol string) *WalletConfig

type WalletManager

type WalletManager struct {
	openwallet.AssetsAdapterBase
	WalletClient    *Client                         // 节点客户端
	Config          *WalletConfig                   //钱包管理配置
	Decoder         openwallet.AddressDecoder       //地址编码器
	DecoderV2       openwallet.AddressDecoderV2     //地址编码器
	TxDecoder       openwallet.TransactionDecoder   //交易单编码器
	Log             *log.OWLogger                   //日志工具
	Blockscanner    openwallet.BlockScanner         //区块扫描器
	ContractDecoder openwallet.SmartContractDecoder //智能合约解析器
	// contains filtered or unexported fields
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) AddSignatureToDeploy

func (wm *WalletManager) AddSignatureToDeploy(deploy *Deploy, keySig *openwallet.KeySignature)

func (*WalletManager) AddSignatureToDeployParam

func (wm *WalletManager) AddSignatureToDeployParam(deploy map[string]interface{}, keySig *openwallet.KeySignature) map[string]interface{}

func (*WalletManager) AddressToHash added in v1.0.1

func (wm *WalletManager) AddressToHash(address string) string

func (*WalletManager) BalanceModelType

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

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

func (wm *WalletManager) GetAccountBalance(stateRootHash, hash string) (decimal.Decimal, error)

func (*WalletManager) GetAddressDecode

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

AddressDecode 地址解析器

func (*WalletManager) GetAddressDecoderV2

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

AddressDecode 地址解析器

func (*WalletManager) GetAssetsLogger

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

GetAssetsLogger 获取资产账户日志工具

func (*WalletManager) GetBlockByHash

func (wm *WalletManager) GetBlockByHash(hash string) (*Block, error)

func (*WalletManager) GetBlockByHeight

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

func (*WalletManager) GetBlockInfo

func (wm *WalletManager) GetBlockInfo(value interface{}, identifier uint8) (*Block, error)

func (*WalletManager) GetBlockScanner

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

GetBlockScanner 获取区块链

func (*WalletManager) GetBlockTransfers

func (wm *WalletManager) GetBlockTransfers(height uint64) ([]*Transfer, error)

func (*WalletManager) GetDeployInfo

func (wm *WalletManager) GetDeployInfo(txid string) (*gjson.Result, error)

func (*WalletManager) GetLatestBlockInfo

func (wm *WalletManager) GetLatestBlockInfo() (*Block, error)

func (*WalletManager) GetPurseUref

func (wm *WalletManager) GetPurseUref(stateRootHash, hash string) (string, error)

func (*WalletManager) GetSmartContractDecoder

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

GetSmartContractDecoder 获取智能合约解析器

func (*WalletManager) GetStateRootHash

func (wm *WalletManager) GetStateRootHash() (string, error)

func (*WalletManager) GetTransactionDecoder

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

TransactionDecoder 交易单解析器

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

func (wm *WalletManager) MakeTransferDeploy(sender, to, amount, fee, id string, timestamp int64) (*Deploy, error)

func (*WalletManager) PutDeploy

func (wm *WalletManager) PutDeploy(deploy *Deploy) (string, error)

func (*WalletManager) PutDeployParam

func (wm *WalletManager) PutDeployParam(deploy map[string]interface{}) (string, error)

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