types

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: ISC Imports: 21 Imported by: 10

Documentation

Overview

Copyright 2017-2018 The qitmeer developers

Index

Constants

View Source
const (
	// Greater than or equal to
	FloorFeeType = 0

	// Strict equality
	EqualFeeType = 1
)
View Source
const (
	// AtomsPerCent is the number of atomic units in one coin cent.
	// TODO, relocate the coin related item to chain's params
	AtomsPerCent = 1e6

	// AtomsPerCoin is the number of atomic units in one coin.
	// TODO, relocate the coin related item to chain's params
	AtomsPerCoin = 1e8

	// MaxAmount is the maximum transaction amount allowed in atoms.
	// TODO, relocate the coin related item to chain's params
	MaxAmount = 21e6 * AtomsPerCoin
)
View Source
const (

	// TxVersion is the current latest supported transaction version.
	TxVersion uint32 = 1

	// NullValueIn is a null value for an input witness.
	NullValueIn uint64 = 0

	// NullBlockHeight is the null value for an input witness. It references
	// the genesis block.
	NullBlockOrder uint32 = 0x00000000

	// NullTxIndex is the null transaction index in a block for an input
	// witness.
	NullTxIndex uint32 = 0xffffffff

	// MaxTxInSequenceNum is the maximum sequence number the sequence field
	// of a transaction input can be.
	MaxTxInSequenceNum uint32 = 0xffffffff

	// MaxPrevOutIndex is the maximum index the index field of a previous
	// outpoint can be.
	MaxPrevOutIndex uint32 = 0xffffffff

	// SequenceLockTimeDisabled is a flag that if set on a transaction
	// input's sequence number, the sequence number will not be interpreted
	// as a relative locktime.
	SequenceLockTimeDisabled = 1 << 31

	// SequenceLockTimeIsSeconds is a flag that if set on a transaction
	// input's sequence number, the relative locktime has units of 512
	// seconds.
	SequenceLockTimeIsSeconds = 1 << 22

	// SequenceLockTimeMask is a mask that extracts the relative locktime
	// when masked against the transaction input sequence number.
	SequenceLockTimeMask = 0x0000ffff

	// TODO, revisit lock time define
	// SequenceLockTimeGranularity is the defined time based granularity
	// for seconds-based relative time locks.  When converting from seconds
	// to a sequence number, the value is right shifted by this amount,
	// therefore the granularity of relative time locks in 512 or 2^9
	// seconds.  Enforced relative lock times are multiples of 512 seconds.
	SequenceLockTimeGranularity = 9

	// MaxMessagePayload is the maximum bytes a message can be regardless of other
	// individual limits imposed by messages themselves.
	MaxMessagePayload = (1024 * 1024 * 32) // 32MB

	// NoExpiryValue is the value of expiry that indicates the transaction
	// has no expiry.
	NoExpiryValue uint32 = 0

	// SupperPrevOutIndex is the supper index field of a previous
	// outpoint can be.
	SupperPrevOutIndex uint32 = 0xfffffffe

	// TokenInSequence is the maximum tx type the sequence field
	// of a transaction input can be.
	TxTypeInSequence uint32 = 0x400
)
View Source
const (
	// MaxBlockWeight defines the maximum block weight
	MaxBlockWeight = 4000000

	// MaxBlockSigOpsCost is the maximum number of signature operations
	// allowed for a block. It is calculated via a weighted algorithm which
	// weights segregated witness sig ops lower than regular sig ops.
	MaxBlockSigOpsCost = 80000
)
View Source
const MaxBlockHeaderPayload = 4 + (hash.HashSize * 3) + 4 + 4 + 8 + 1 + 1 + 42*4

MaxBlockHeaderPayload is the maximum number of bytes a block header can be. Version 4 bytes + ParentRoot 32 bytes + TxRoot 32 bytes + StateRoot 32 bytes + Difficulty 4 bytes + Timestamp 4 bytes + nonce 8 bytes + powType 1 byte + edges_bits 1 byte + 42circles 42*4 bytes total 117 + 169 = 286 hash pow only need 117 bytes cuckoo need 286 bytes

View Source
const MaxBlockPayload = 1048576 // 1024*1024 (1MB)

MaxBlockPayload is the maximum bytes a block message can be in bytes.

View Source
const MaxBlocksPerMsg = 500

MaxBlocksPerMsg is the maximum number of blocks allowed per message.

View Source
const MaxParentsPerBlock = 50

Limited parents quantity

View Source
const MaxTxPerBlock = (MaxBlockPayload / minTxPayload) + 1

MaxTxPerBlock is the maximum number of transactions that could possibly fit into a block.

View Source
const (
	// crosschain export tx fork for genesis locked utxo
	MeerEVMForkInput = math.MaxInt64
)
View Source
const TxIndexUnknown = -1

TxIndexUnknown is the value returned for a transaction index that is unknown. This is typically because the transaction has not been inserted into a block yet.

Variables

View Source
var CoinIDList = []CoinID{MEERA, MEERB}
View Source
var CoinNameMap = map[CoinID]string{}
View Source
var ErrInvalidNetAddr = errors.New("provided net.Addr is not a net.TCPAddr")

ErrInvalidNetAddr describes an error that indicates the caller didn't specify a TCP address as required.

Standard transaction type

Functions

func CheckCoinID

func CheckCoinID(id CoinID) error

Check if a valid coinId, current only check if the coinId is known.

func CheckGenesisLock

func CheckGenesisLock(tx *Transaction) error

CheckGenesisLock returns an error if a transaction is not a genesis_lock transaction. It makes sure the number of inputs/outputs, and related scripts are valid.

genesis_lock transactions are specified as below:

1.) Inputs: genesis output 1 [index 0] genesis output 2 [index 1] ...

2.) Outputs: OP_STAKE_LOCK tagged output [index 0] OP_RETURN push of input 1's stake reward receiving address [index 1] OP_STAKE_LOCK tagged output [index 2] OP_RETURN push of input 2's stake reward receiving address [index 3] ... Note: The output OP_RETURN pushes should be of size 20 bytes (standard address).

3.) NO changes are allowed for the tx && NO fee are allowed for this tx. inputs amount == output amount

func GetBlockWeight

func GetBlockWeight(blk *Block) int

GetBlockWeight computes the value of the weight metric for a given block.

func GetParentsRoot

func GetParentsRoot(parents []*hash.Hash) hash.Hash

This function get the simple hash use each parents string, so it can't use to check for block body .At present we use the merkles tree.

func GetSupportCoinsForCrossChain

func GetSupportCoinsForCrossChain() map[CoinID]bool

cross chain

func GetTransactionWeight

func GetTransactionWeight(tx *Tx) int64

func IsCoinBaseTx

func IsCoinBaseTx(tx *Transaction) bool

IsCoinBaseTx determines whether or not a transaction is a coinbase. A coinbase is a special transaction created by miners that has no inputs. This is represented in the block chain by a transaction with a single input that has a previous output transaction index set to the maximum value along with a zero hash.

This function only differs from IsCoinBase in that it works with a raw wire transaction as opposed to a higher level util transaction.

func IsCrossChainExportTx

func IsCrossChainExportTx(tx *Transaction) bool

func IsCrossChainImportTx

func IsCrossChainImportTx(tx *Transaction) bool

func IsCrossChainTx

func IsCrossChainTx(tx *Transaction) bool

func IsCrossChainVMTx

func IsCrossChainVMTx(tx *Transaction) bool

func IsGenesisLockTx

func IsGenesisLockTx(tx *Transaction) bool

IsGenesisLockTx returns whether or not a transaction is a genesis_lock transaction.

func IsKnownCoinID

func IsKnownCoinID(id CoinID) bool

func IsMeerEVMForkInput

func IsMeerEVMForkInput(ip *TxInput) bool

func IsSequenceLockTimeDisabled

func IsSequenceLockTimeDisabled(sequence uint32) bool

func IsTokenInvalidateTx

func IsTokenInvalidateTx(tx *Transaction) bool

func IsTokenMintTx

func IsTokenMintTx(tx *Transaction) bool

func IsTokenNewTx

func IsTokenNewTx(tx *Transaction) bool

func IsTokenRenewTx

func IsTokenRenewTx(tx *Transaction) bool

func IsTokenTx

func IsTokenTx(tx *Transaction) bool

func IsTokenUnmintTx

func IsTokenUnmintTx(tx *Transaction) bool

func IsTokenValidateTx

func IsTokenValidateTx(tx *Transaction) bool

func MaxNetAddressPayload

func MaxNetAddressPayload(pver uint32) uint32

MaxNetAddressPayload returns the max payload size for the NetAddress based on the protocol version.

func MaxTxPerTxTree

func MaxTxPerTxTree(pver uint32) uint64

MaxTxPerTxTree returns the maximum number of transactions that could possibly fit into a block per ekach merkle root for the given protocol version.

func ReadNetAddress

func ReadNetAddress(r io.Reader, pver uint32, na *NetAddress, ts bool) error

readNetAddress reads an encoded NetAddress from r depending on the protocol version and whether or not the timestamp is included per ts. Some messages like version do not include the timestamp.

func ReadOutPoint

func ReadOutPoint(r io.Reader, version uint32, op *TxOutPoint) error

ReadOutPoint reads the next sequence of bytes from r as an OutPoint.

func WriteNetAddress

func WriteNetAddress(w io.Writer, pver uint32, na *NetAddress, ts bool) error

writeNetAddress serializes a NetAddress to w depending on the protocol version and whether or not the timestamp is included per ts. Some messages like version do not include the timestamp.

func WriteOutPoint

func WriteOutPoint(w io.Writer, pver uint32, version uint32, op *TxOutPoint) error

WriteOutPoint encodes for an OutPoint to w.

Types

type Account

type Account Address

An identifier for an account of the system, which stand for a address

type Address

type Address interface {
	// String returns the string encoding of the transaction output
	// destination.
	//
	// Please note that String differs subtly from EncodeAddress: String
	// will return the value as a string without any conversion, while
	// EncodeAddress may convert destination types (for example,
	// converting pubkeys to P2PKH addresses) before encoding as a
	// payment address string.
	String() string

	// with encode
	Encode() string

	// Hash160 returns the Hash160(data) where data is the data normally
	// hashed to 160 bits from the respective address type.
	Hash160() *[20]byte

	EcType() ecc.EcType

	// raw byte in script, aka the hash in the most case
	Script() []byte

	// IsForNetwork returns whether or not the address is associated with the
	// passed network.
	IsForNetwork(net protocol.Network) bool
}

type AddressType

type AddressType byte
const (
	LegerAddress    AddressType = 0x01
	ContractAddress AddressType = 0x02
)

type Amount

type Amount struct {
	Value int64
	Id    CoinID
}

Amount represents the base coin monetary unit (colloquially referred to as an `Atom'). A single Amount is equal to 1e-8 of a coin. size is 10 bytes ( value -> 8 byte , coinId -> 2 byte)

func NewAmount

func NewAmount(f float64) (*Amount, error)

NewAmount creates an Amount from a floating point value representing some value in the currency. NewAmount errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of coins producible as f may not refer to an amount at a single moment in time.

NewAmount is for specifically for converting qitmeer to Atoms (atomic units). For creating a new Amount with an int64 value which denotes a quantity of Atoms, do a simple type conversion from type int64 to Amount.

func NewMeer

func NewMeer(a uint64) (*Amount, error)

func (*Amount) Add

func (z *Amount) Add(x, y *Amount) (*Amount, error)

func (*Amount) Format

func (a *Amount) Format(u AmountUnit) string

Format formats a monetary amount counted in coin base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "atom" for the base unit.

func (*Amount) MulF64

func (a *Amount) MulF64(f float64) *Amount

MulF64 multiplies an Amount by a floating point value. While this is not an operation that must typically be done by a full node or wallet, it is useful for services that build on top of qitmeer (for example, calculating a fee by multiplying by a percentage).

func (*Amount) String

func (a *Amount) String() string

String is the equivalent of calling Format with AmountCoin.

func (*Amount) ToCoin

func (a *Amount) ToCoin() float64

ToCoin is the equivalent of calling ToUnit with AmountCoin.

func (*Amount) ToUnit

func (a *Amount) ToUnit(u AmountUnit) float64

ToUnit converts a monetary amount counted in coin base units to a floating point value representing an amount of coins.

type AmountGroup

type AmountGroup []Amount

AmountGroup represents a group of multiple Amount,

type AmountMap

type AmountMap map[CoinID]int64

AmountMap represents a map of multiple Amount,

func (AmountMap) Add

func (am AmountMap) Add(other AmountMap)

type AmountSorter

type AmountSorter []Amount

AmountSorter implements sort.Interface to allow a slice of Amounts to be sorted.

func (AmountSorter) Len

func (s AmountSorter) Len() int

Len returns the number of Amounts in the slice. It is part of the sort.Interface implementation.

func (AmountSorter) Less

func (s AmountSorter) Less(i, j int) bool

Less returns whether the Amount with index i should sort before the Amount with index j. It is part of the sort.Interface implementation.

func (AmountSorter) Swap

func (s AmountSorter) Swap(i, j int)

Swap swaps the Amounts at the passed indices. It is part of the sort.Interface implementation.

type AmountUnit

type AmountUnit int

AmountUnit describes a method of converting an Amount to something other than the base unit of a coin. The value of the AmountUnit is the exponent component of the decadic multiple to convert from an amount in coins to an amount counted in atomic units.

const (
	AmountMegaCoin  AmountUnit = 6
	AmountKiloCoin  AmountUnit = 3
	AmountCoin      AmountUnit = 0
	AmountMilliCoin AmountUnit = -3
	AmountMicroCoin AmountUnit = -6
	AmountAtom      AmountUnit = -8
)

These constants define various units used when describing a coin monetary amount.

func (AmountUnit) String

func (u AmountUnit) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Atom" for the base unit. For all unrecognized units, "1eN MEER" is returned, where N is the AmountUnit.

type AuthorityId

type AuthorityId Address

/ An identifier for an authority in the consensus algorithm.

type Block

type Block struct {
	Header       BlockHeader
	Parents      []*hash.Hash
	Transactions []*Transaction //tx  6

}

func (*Block) AddParent

func (b *Block) AddParent(h *hash.Hash) error

AddTransaction adds a transaction to the message.

func (*Block) AddTransaction

func (b *Block) AddTransaction(tx *Transaction) error

AddTransaction adds a transaction to the message.

func (*Block) BlockHash

func (block *Block) BlockHash() hash.Hash

BlockHash computes the block identifier hash for this block.

func (*Block) Decode

func (b *Block) Decode(r io.Reader, pver uint32) error

decodes r into the receiver. See Deserialize for decoding blocks stored to disk, such as in a database, as opposed to decoding blocks .

func (*Block) Deserialize

func (b *Block) Deserialize(r io.Reader) error

Deserialize decodes a block from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field in the block.

func (*Block) DeserializeTxLoc

func (b *Block) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error)

DeserializeTxLoc decodes r in the same manner Deserialize does, but it takes a byte buffer instead of a generic reader and returns a slice containing the start and length of each transaction within the raw data that is being deserialized.

func (*Block) Encode

func (block *Block) Encode(w io.Writer, pver uint32) error

Encode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation. See Serialize for encoding blocks to be stored to disk, such as in a database, as opposed to encoding blocks for the wire.

func (*Block) Serialize

func (block *Block) Serialize(w io.Writer) error

Serialize encodes the block to w using a format that suitable for long-term storage such as a database while respecting the Version field in the block.

func (*Block) SerializeSize

func (block *Block) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the block.

type BlockHeader

type BlockHeader struct {

	// block version
	Version uint32

	// The merkle root of the previous parent blocks (the dag layer)
	ParentRoot hash.Hash

	// The merkle root of the tx tree  (tx of the block)
	// included Witness here instead of the separated witness commitment
	TxRoot hash.Hash

	// The merkle root of state tire (the app data layer)
	// can all of the state data (stake, receipt, utxo) in state root?
	StateRoot hash.Hash

	// Difficulty target for tx
	Difficulty uint32

	// TimeStamp
	Timestamp time.Time

	// pow blake2bd | cuckaroo | cuckatoo
	Pow pow.IPow
}

func (*BlockHeader) BlockData

func (bh *BlockHeader) BlockData() []byte

BlockData computes the block data for block hash. Block data has the dynamic length.

  • blake2bd data is 117 bytes .
  • cuckoo data is 282 bytes .

func (*BlockHeader) BlockHash

func (h *BlockHeader) BlockHash() hash.Hash

BlockHash computes the block identifier hash for the given block header.

func (*BlockHeader) Deserialize

func (h *BlockHeader) Deserialize(r io.Reader) error

Deserialize decodes a block header from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field.

func (*BlockHeader) Serialize

func (h *BlockHeader) Serialize(w io.Writer) error

Serialize encodes a block header from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field.

type BlockReceipt

type BlockReceipt struct {
	BlockNumber uint64

	// The merkle root of storage trie (for kv)
	StorageRoot hash.Hash

	// The merkle root for change logs trie
	// 1.) ordered storage keys that changed the storage, k also map to tx(one or many) (how them changed)
	// 2.) a parent MT also linked, which representing changes happened over the last change range of blocks.
	//     which refer to block(s) that caused the change rather than the tx included from the current block
	//     which provide proof that any group of change range blocks either don't change a storage item
	//     or can find out which tx exactly did.
	ChangeRoot hash.Hash

	// The event digest of a block, which is chain-specific, useful for light-clients.
	// Events are an array of data fragments that runtime encode events for light-client
	// for example authority set changes (ex. validator set changes)
	// fast warp sync by tracking validator set changes trustlessly
	Events []Event
}

type BlockTemplate

type BlockTemplate struct {
	// Block is a block that is ready to be solved by miners.  Thus, it is
	// completely valid with the exception of satisfying the proof-of-work
	// requirement.
	Block *Block

	// Fees contains the amount of fees each transaction in the generated
	// template pays in base units.  Since the first transaction is the
	// coinbase, the first entry (offset 0) will contain the negative of the
	// sum of the fees of all other transactions.
	Fees []int64

	// SigOpCounts contains the number of signature operations each
	// transaction in the generated template performs.
	SigOpCounts []int64

	// Height is the height at which the block template connects to the main
	// chain.
	Height uint64

	// Blues is the count of the blue set in the block past set to
	// the DAG
	Blues int64

	// ValidPayAddress indicates whether or not the template coinbase pays
	// to an address or is redeemable by anyone.  See the documentation on
	// NewBlockTemplate for details on which this can be useful to generate
	// templates without a coinbase payment address.
	ValidPayAddress bool

	//pow diff
	Difficulty uint32

	BlockFeesMap AmountMap

	TxMerklePath  []*hash.Hash
	TxWitnessRoot *hash.Hash
}

BlockTemplate houses a block that has yet to be solved along with additional details about the fees and the number of signature operations for each transaction in the block.

type BloomUpdateType

type BloomUpdateType uint8

BloomUpdateType specifies how the filter is updated when a match is found

const (
	// BloomUpdateNone indicates the filter is not adjusted when a match is
	// found.
	BloomUpdateNone BloomUpdateType = 0

	// BloomUpdateAll indicates if the filter matches any data element in a
	// public key script, the outpoint is serialized and inserted into the
	// filter.
	BloomUpdateAll BloomUpdateType = 1

	// BloomUpdateP2PubkeyOnly indicates if the filter matches a data
	// element in a public key script and the script is of the standard
	// pay-to-pubkey or multisig, the outpoint is serialized and inserted
	// into the filter.
	BloomUpdateP2PubkeyOnly BloomUpdateType = 2

	// MaxFilterLoadHashFuncs is the maximum number of hash functions to
	// load into the Bloom filter.
	MaxFilterLoadHashFuncs = 50

	// MaxFilterLoadFilterSize is the maximum size in bytes a filter may be.
	MaxFilterLoadFilterSize = 36000
)

type Bytes

type Bytes []byte

type CBlock

type CBlock struct {
	Header        CBlockHeader
	CTransactions []*ContractTransaction //ctx
}

type CBlockHeader

type CBlockHeader struct {

	//Contract block number
	CBlockNum *big.Int

	//Parent block hash
	CBlockParent hash.Hash

	// The merkle root of contract storage
	ContractRoot hash.Hash

	// The merkle root the ctx receipt trie  (proof of changes)
	// receipt generated after ctx processed (aka. post-tx info)
	ReceiptRoot hash.Hash

	// bloom filter for log entry of ctx receipt
	// can we remove/combine with cbf ?
	LogBloom hash.Hash

	// Difficulty target for ctx
	CDifficulty uint32
	// Nonce for ctx
	CNonce uint64
}

Contract block header

type CoinID

type CoinID uint16

from 0 ~ 65535 0 ~ 255 : Qitmeer reserved

const (
	MEERA CoinID = 0
	MEERB CoinID = 1

	QitmeerReservedID CoinID = 255
)

func NewCoinID

func NewCoinID(name string) CoinID

func (CoinID) Bytes

func (c CoinID) Bytes() []byte

func (CoinID) IsBase

func (c CoinID) IsBase() bool

Is it the main coin ?

func (CoinID) Name

func (c CoinID) Name() string

type Config

type Config struct {
	Id *big.Int `json:"Id"  required:"true" min:"0"`
}

func (Config) MarshalJSON

func (c Config) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON

type ContractTransaction

type ContractTransaction struct {
	From      Account
	To        Account
	Value     uint64
	GasPrice  uint64
	GasLimit  uint64
	Nonce     uint64
	Input     []byte
	Signature []byte
}

type Event

type Event []byte

block execution event, ex. validator change event

type FeeType

type FeeType byte

type Genesis

type Genesis struct {
	Config *Config `json:"config" required:"true"`
	Nonce  uint64  `json:"nonce"  required:"true" min:"1"`
}

func (Genesis) MarshalJSON

func (g Genesis) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON

func (*Genesis) UnmarshalJSON

func (g *Genesis) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON

type Input

type Input interface {
	GetSignScript() []byte
}

type Key

type Key struct {
	Address    Address
	PrivateKey *ecc.PrivateKey
}

type MessageEncoding

type MessageEncoding uint32

MessageEncoding represents the wire message encoding format to be used.

const (
	// BaseEncoding encodes all messages in the default format specified
	// for the Bitcoin wire protocol.
	BaseEncoding MessageEncoding = 1 << iota
)

type MessageError

type MessageError struct {
	Func        string // Function name
	Description string // Human readable description of the issue
}

MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.

This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.

func (*MessageError) Error

func (e *MessageError) Error() string

Error satisfies the error interface and prints human-readable errors.

type MsgFilterAdd

type MsgFilterAdd struct {
	Data []byte
}

MsgFilterAdd implements the Message interface and represents a qitmeer filteradd message. It is used to add a data element to an existing Bloom filter.

This message was not added until protocol version BIP0037Version.

type MsgFilterClear

type MsgFilterClear struct{}

MsgFilterClear implements the Message interface and represents a qitmeer filterclear message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version and has no payload.

type MsgFilterLoad

type MsgFilterLoad struct {
	Filter    []byte
	HashFuncs uint32
	Tweak     uint32
	Flags     BloomUpdateType
}

MsgFilterLoad implements the Message interface and represents a bitcoin filterload message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgFilterLoad

func NewMsgFilterLoad(filter []byte, hashFuncs uint32, tweak uint32, flags BloomUpdateType) *MsgFilterLoad

NewMsgFilterLoad returns a new bitcoin filterload message that conforms to the Message interface. See MsgFilterLoad for details.

func (*MsgFilterLoad) QitmeerDecode

func (msg *MsgFilterLoad) QitmeerDecode(r io.Reader, pver uint32, enc MessageEncoding) error

QitmeerDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFilterLoad) QitmeerEncode

func (msg *MsgFilterLoad) QitmeerEncode(w io.Writer, pver uint32, enc MessageEncoding) error

QitmeerEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

type MsgMerkleBlock

type MsgMerkleBlock struct {
	Header       BlockHeader
	Transactions uint32
	Hashes       []*chainhash.Hash
	Flags        []byte
}

MsgMerkleBlock implements the Message interface and represents a bitcoin merkleblock message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func (*MsgMerkleBlock) AddTxHash

func (msg *MsgMerkleBlock) AddTxHash(hash *chainhash.Hash) error

AddTxHash adds a new transaction hash to the message.

func (*MsgMerkleBlock) MaxPayloadLength

func (msg *MsgMerkleBlock) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type NetAddress

type NetAddress struct {
	// Last time the address was seen.  This is, unfortunately, encoded as a
	// uint32 on the wire and therefore is limited to 2106.  This field is
	// not present in the version message (MsgVersion) nor was it
	// added until protocol version >= NetAddressTimeVersion.
	Timestamp time.Time

	// Bitfield which identifies the services supported by the address.
	Services protocol.ServiceFlag

	// IP address of the peer.
	IP net.IP

	// Port the peer is using.  This is encoded in big endian on the wire
	// which differs from most everything else.
	Port uint16
}

NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.

func NewNetAddress

func NewNetAddress(addr net.Addr, services protocol.ServiceFlag) (*NetAddress, error)

NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.

Note that addr must be a net.TCPAddr. An ErrInvalidNetAddr is returned if it is not.

func NewNetAddressFailBack

func NewNetAddressFailBack(addr net.Addr, services protocol.ServiceFlag) (*NetAddress, error)

NewNetAddressFailBack add more attempts to extract the IP address and port from the passed net.Addr interface and create a NetAddress structure using that information.

func NewNetAddressIPPort

func NewNetAddressIPPort(ip net.IP, port uint16, services protocol.ServiceFlag) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.

func NewNetAddressTimestamp

func NewNetAddressTimestamp(
	timestamp time.Time, services protocol.ServiceFlag, ip net.IP, port uint16) *NetAddress

NewNetAddressTimestamp returns a new NetAddress using the provided timestamp, IP, port, and supported services. The timestamp is rounded to single second precision.

func (*NetAddress) AddService

func (na *NetAddress) AddService(service protocol.ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*NetAddress) HasService

func (na *NetAddress) HasService(service protocol.ServiceFlag) bool

HasService returns whether the specified service is supported by the address.

type Output

type Output interface {
	GetPkScript() []byte
}

type ScriptTx

type ScriptTx interface {
	GetInput() []Input
	GetOutput() []Output
	GetVersion() uint32
	GetLockTime() uint32
	GetType() ScriptTxType
}

type ScriptTxType

type ScriptTxType int
const (
	QitmeerScriptTx ScriptTxType = iota
	BtcScriptTx
)

type SerializedBlock

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

SerializedBlock provides easier and more efficient manipulation of raw blocks. It also memorizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func NewBlock

func NewBlock(block *Block) *SerializedBlock

NewBlock returns a new instance of the serialized block given an underlying Block. the block hash has been calculated and cached

func NewBlockDeepCopyCoinbase

func NewBlockDeepCopyCoinbase(msgBlock *Block) *SerializedBlock

NewBlockDeepCopyCoinbase returns a new instance of a block given an underlying wire.MsgBlock, but makes a deep copy of the coinbase transaction since it's sometimes mutable.

func NewBlockFromBlockAndBytes

func NewBlockFromBlockAndBytes(block *Block, serializedBytes []byte) *SerializedBlock

NewBlockFromBlockAndBytes returns a new instance of a block given an underlying Block and the serialized bytes for it.

func NewBlockFromBytes

func NewBlockFromBytes(serializedBytes []byte) (*SerializedBlock, error)

NewBlockFromBytes returns a new instance of a block given the serialized bytes. See Block.

func NewBlockFromReader

func NewBlockFromReader(r io.Reader) (*SerializedBlock, error)

NewBlockFromReader returns a new instance of a block given a Reader to deserialize the block. See Block.

func (*SerializedBlock) Block

func (sb *SerializedBlock) Block() *Block

func (*SerializedBlock) Bytes

func (sb *SerializedBlock) Bytes() ([]byte, error)

Bytes returns the serialized bytes for the Block. This is equivalent to calling Serialize on the underlying Block, however it caches the result so subsequent calls are more efficient.

func (*SerializedBlock) Hash

func (sb *SerializedBlock) Hash() *hash.Hash

Hash returns the block identifier hash for the Block. This is equivalent to calling BlockHash on the underlying Block, however it caches the result so subsequent calls are more efficient.

func (*SerializedBlock) Height

func (sb *SerializedBlock) Height() uint

func (*SerializedBlock) Order

func (sb *SerializedBlock) Order() uint64

Order returns a casted int64 order from the block header.

This function should not be used for new code and will be removed in the future.

func (*SerializedBlock) SetHeight

func (sb *SerializedBlock) SetHeight(height uint)

func (*SerializedBlock) SetOrder

func (sb *SerializedBlock) SetOrder(order uint64)

func (*SerializedBlock) String

func (sb *SerializedBlock) String() string

The stringer method makes SerializedBlock satisfy the Stringer interface. It simplifies the message printing in the trace logs.

func (*SerializedBlock) Transactions

func (sb *SerializedBlock) Transactions() []*Tx

Transactions returns a slice of wrapped transactions for all transactions in the Block. This is nearly equivalent to accessing the raw transactions (types.Transaction) in the underlying types.Block, however it instead provides easy access to wrapped versions of them.

func (*SerializedBlock) TxLoc

func (sb *SerializedBlock) TxLoc() ([]TxLoc, error)

TxLoc returns the offsets and lengths of each transaction in a raw block. It is used to allow fast indexing into transactions within the raw byte stream.

type Transaction

type Transaction struct {
	Version   uint32
	TxIn      []*TxInput
	TxOut     []*TxOutput
	LockTime  uint32
	Expire    uint32
	Timestamp time.Time // When the transaction was created for extensibility

	Message    []byte //a unencrypted/encrypted message if user pay additional fee & limit the max length
	CachedHash *hash.Hash
}

func NewTransaction

func NewTransaction() *Transaction

NewMsgTx returns a new tx message that conforms to the Message interface. The return instance has a default version of TxVersion and there are no transaction inputs or outputs. Also, the lock time is set to zero to indicate the transaction is valid immediately as opposed to some time in future.

func (*Transaction) AddTxIn

func (t *Transaction) AddTxIn(ti *TxInput)

AddTxIn adds a transaction input to the message.

func (*Transaction) AddTxOut

func (t *Transaction) AddTxOut(to *TxOutput)

AddTxOut adds a transaction output to the message.

func (*Transaction) CachedTxHash

func (t *Transaction) CachedTxHash() *hash.Hash

CachedTxHash is equivalent to calling TxHash, however it caches the result so subsequent calls do not have to recalculate the hash. It can be recalculated later with RecacheTxHash.

func (*Transaction) Decode

func (tx *Transaction) Decode(r io.Reader, pver uint32) error

func (*Transaction) Deserialize

func (tx *Transaction) Deserialize(r io.Reader) error

Deserialize decodes a transaction from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field in the transaction.

func (*Transaction) Encode

func (tx *Transaction) Encode(w io.Writer, pver uint32, serType TxSerializeType) error

func (*Transaction) GetInput

func (t *Transaction) GetInput() []Input

func (*Transaction) GetLockTime

func (t *Transaction) GetLockTime() uint32

func (*Transaction) GetOutput

func (t *Transaction) GetOutput() []Output

func (*Transaction) GetType

func (t *Transaction) GetType() ScriptTxType

func (*Transaction) GetVersion

func (t *Transaction) GetVersion() uint32

func (*Transaction) IsCoinBase

func (tx *Transaction) IsCoinBase() bool

func (*Transaction) RecacheTxHash

func (t *Transaction) RecacheTxHash() *hash.Hash

RecacheTxHash is equivalent to calling TxHash, however it replaces the cached result so future calls to CachedTxHash will return this newly calculated hash.

func (*Transaction) Serialize

func (tx *Transaction) Serialize() ([]byte, error)

serialize returns the serialization of the transaction for the provided serialization type without modifying the original transaction.

func (*Transaction) SerializeNoWitness

func (tx *Transaction) SerializeNoWitness() ([]byte, error)

func (*Transaction) SerializeSize

func (tx *Transaction) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction. (full size)

func (*Transaction) SerializeSizeNoWitness

func (tx *Transaction) SerializeSizeNoWitness() int

func (*Transaction) TxHash

func (tx *Transaction) TxHash() hash.Hash

TxHash generates the hash for the transaction prefix. Since it does not contain any witness data, it is not malleable and therefore is stable for use in unconfirmed transaction chains.

func (*Transaction) TxHashFull

func (tx *Transaction) TxHashFull() hash.Hash

TxHashFull generates the hash for the transaction prefix || witness. It first obtains the hashes for both the transaction prefix and witness, then concatenates them and hashes the result.

func (*Transaction) ValidTime

func (t *Transaction) ValidTime(allowScope int64) bool

type Tx

type Tx struct {
	Tx *Transaction // Underlying Transaction

	IsDuplicate bool // Whether duplicate tx.
	// contains filtered or unexported fields
}

Tx defines a transaction that provides easier and more efficient manipulation of raw transactions. It also memorizes the hash for the transaction on its first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func NewTx

func NewTx(t *Transaction) *Tx

NewTx returns a new instance of a transaction given an underlying wire.MsgTx. See Tx.

func NewTxDeep

func NewTxDeep(msgTx *Transaction) *Tx

NewTxDeep returns a new instance of a transaction given an underlying wire.MsgTx. Until NewTx, it completely copies the data in the msgTx so that there are new memory allocations, in case you were to somewhere else modify the data assigned to these pointers.

func NewTxDeepTxIns

func NewTxDeepTxIns(msgTx *Transaction) *Tx

NewTxDeepTxIns is used to deep copy a transaction, maintaining the old pointers to the TxOuts while replacing the old pointers to the TxIns with deep copies. This is to prevent races when the fraud proofs for the transactions are set by the miner.

func NewTxFromBytes

func NewTxFromBytes(serializedTx []byte) (*Tx, error)

NewTxFromBytes returns a new instance of a bitcoin transaction given the serialized bytes. See Tx.

func NewTxFromReader

func NewTxFromReader(r io.Reader) (*Tx, error)

NewTxFromReader returns a new instance of a bitcoin transaction given a Reader to deserialize the transaction. See Tx.

func (*Tx) Hash

func (t *Tx) Hash() *hash.Hash

Hash returns the hash of the transaction. This is equivalent to calling TxHash on the underlying wire.MsgTx, however it caches the result so subsequent calls are more efficient.

func (*Tx) Index

func (t *Tx) Index() int

func (*Tx) RefreshHash

func (t *Tx) RefreshHash()

func (*Tx) SetIndex

func (t *Tx) SetIndex(index int)

SetIndex sets the index of the transaction in within a block.

func (*Tx) Transaction

func (t *Tx) Transaction() *Transaction

Transaction() returns the underlying Tx for the transaction.

type TxDesc

type TxDesc struct {
	// Tx is the transaction associated with the entry.
	Tx *Tx

	// Added is the time when the entry was added to the source pool.
	Added time.Time

	// Height is the block height when the entry was added to the the source
	// pool.
	Height int64

	// Fee is the total fee the transaction associated with the entry pays.
	Fee int64

	// FeePerKB is the fee the transaction pays in meer per 1000 bytes.
	FeePerKB int64
}

TxDesc is a descriptor about a transaction in a transaction source along with additional metadata.

type TxInput

type TxInput struct {
	PreviousOut TxOutPoint
	//the signature script (or witness script? or redeem script?)
	SignScript []byte
	// This number has more historical significance than relevant usage;
	// however, its most relevant purpose is to enable “locking” of payments
	// so that they cannot be redeemed until a certain time.
	Sequence uint32 //work with LockTime (disable use 0xffffffff, bitcoin historical)
	AmountIn Amount
}

func NewTxInput

func NewTxInput(prevOut *TxOutPoint, signScript []byte) *TxInput

NewTxIn returns a new transaction input with the provided previous outpoint point and signature script with a default sequence of MaxTxInSequenceNum.

func (*TxInput) GetSignScript

func (ti *TxInput) GetSignScript() []byte

func (*TxInput) SerializeSize

func (ti *TxInput) SerializeSize() int

SerializeSizeWitness returns the number of bytes it would take to serialize the transaction input for a witness.

func (*TxInput) SerializeSizePrefix

func (ti *TxInput) SerializeSizePrefix() int

SerializeSizePrefix returns the number of bytes it would take to serialize the transaction input for a prefix.

func (*TxInput) SerializeSizeWitness

func (ti *TxInput) SerializeSizeWitness() int

SerializeSizeWitness returns the number of bytes it would take to serialize the transaction input for a witness.

type TxLoc

type TxLoc struct {
	TxStart int
	TxLen   int
}

TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.

type TxOutPoint

type TxOutPoint struct {
	Hash     hash.Hash //txid
	OutIndex uint32    //vout
}

func NewOutPoint

func NewOutPoint(hash *hash.Hash, index uint32) *TxOutPoint

NewOutPoint returns a new transaction outpoint point with the provided hash and index.

type TxOutput

type TxOutput struct {
	Amount   Amount
	PkScript []byte //Here, asm/type -> OP_XXX OP_RETURN
}

func NewTxOutput

func NewTxOutput(amount Amount, pkScript []byte) *TxOutput

NewTxOutput returns a new bitcoin transaction output with the provided transaction value and public key script.

func (*TxOutput) GetPkScript

func (to *TxOutput) GetPkScript() []byte

func (*TxOutput) SerializeSize

func (to *TxOutput) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction output.

type TxSerializeType

type TxSerializeType uint16

TxSerializeType represents the serialized type of a transaction.

const (
	// TxSerializeFull indicates a transaction be serialized with the prefix
	// and all witness data.
	TxSerializeFull TxSerializeType = iota
	// TxSerializeNoWitness indicates a transaction be serialized with only
	// the prefix.
	TxSerializeNoWitness
)

type TxType

type TxType int

TxType indicates the type of transactions such as regular or other tx type (coinbase, stake or token).

const (
	TxTypeRegular     TxType = iota
	TxTypeCoinbase    TxType = 0x1
	TxTypeGenesisLock TxType = 0x2 // the tx try to lock the genesis output to the stake pool

	TxTypeStakebase     TxType = 0x10 // the special tx which vote for stake_purchase and reward stake holder from the stake_reserve
	TyTypeStakeReserve  TxType = 0x11 // the tx reserve consensus-based value to a special stake_reserve address
	TxTypeStakePurchase TxType = 0x12 // the tx of stake holder who lock value into stake pool
	TxTypeStakeDispose  TxType = 0x13 // the opposite tx of stake_purchase

	TxTypeTokenRegulation TxType = 0x80 // token-regulation is reserved, not for using.
	TxTypeTokenNew        TxType = 0x81 // new coin-id, owners, up-limit etc. the token is disabled after token-new.
	TxTypeTokenRenew      TxType = 0x82 // update owners, up-limits etc. can't change coin-id. renew works only when the token is disabled.
	TxTypeTokenValidate   TxType = 0x83 // enable the token.
	TxTypeTokenInvalidate TxType = 0x84 // disable the token.
	TxTypeTokenRevoke     TxType = 0x8f // revoke the coin-id. token-revoke is reserved, not used at current stage.

	TxTypeTokenbase   TxType = 0x90 // token-base is reserved, not used at current stage.
	TxTypeTokenMint   TxType = 0x91 // token owner mint token amount by locking MEER. (must validated token)
	TxTypeTokenUnmint TxType = 0x92 // token owner unmint token amount by releasing MEER. (must validated token)

	TxTypeCrossChainExport TxType = 0x0101 // Cross chain by export tx
	TxTypeCrossChainImport TxType = 0x0102 // Cross chain by import tx
	TxTypeCrossChainVM     TxType = 0x0103 // Cross chain by vm tx
)

func DetermineTxType

func DetermineTxType(tx *Transaction) TxType

DetermineTxType determines the type of transaction

func GetTxType

func GetTxType(txtype string) TxType

func (TxType) String

func (tt TxType) String() string

type UInt128

type UInt128 big.Int

func NewUInt128

func NewUInt128(x int64) *UInt128

func (*UInt128) UnmarshalJSON

func (i *UInt128) UnmarshalJSON(input []byte) error

type UInt256

type UInt256 big.Int

func NewUInt256

func NewUInt256(x int64) *UInt256

func (*UInt256) MarshalJSON

func (i *UInt256) MarshalJSON() ([]byte, error)

func (*UInt256) UnmarshalJSON

func (i *UInt256) UnmarshalJSON(input []byte) error

type UInt64

type UInt64 uint64

func (*UInt64) UnmarshalJSON

func (i *UInt64) UnmarshalJSON(input []byte) error

type Uint

type Uint uint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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