Documentation ¶
Overview ¶
Copyright (c) 2020-2021 The bitcoinpay developers
Index ¶
- Constants
- Variables
- func GetBlockWeight(blk *Block) int
- func GetParentsRoot(parents []*hash.Hash) hash.Hash
- func MaxNetAddressPayload(pver uint32) uint32
- func MaxTxPerTxTree(pver uint32) uint64
- func ReadNetAddress(r io.Reader, pver uint32, na *NetAddress, ts bool) error
- func ReadOutPoint(r io.Reader, version uint32, op *TxOutPoint) error
- func WriteNetAddress(w io.Writer, pver uint32, na *NetAddress, ts bool) error
- func WriteOutPoint(w io.Writer, pver uint32, version uint32, op *TxOutPoint) error
- type Account
- type Address
- type AddressType
- type Amount
- type AmountSorter
- type AmountUnit
- type AuthorityId
- type Block
- func (b *Block) AddParent(h *hash.Hash) error
- func (b *Block) AddTransaction(tx *Transaction) error
- func (block *Block) BlockHash() hash.Hash
- func (b *Block) Decode(r io.Reader, pver uint32) error
- func (b *Block) Deserialize(r io.Reader) error
- func (b *Block) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error)
- func (block *Block) Encode(w io.Writer, pver uint32) error
- func (block *Block) Serialize(w io.Writer) error
- func (block *Block) SerializeSize() int
- type BlockHeader
- type BlockReceipt
- type BlockTemplate
- type Bytes
- type CBlock
- type CBlockHeader
- type Config
- type ContractTransaction
- type Event
- type Genesis
- type Input
- type Key
- type NetAddress
- func NewNetAddress(addr net.Addr, services protocol.ServiceFlag) (*NetAddress, error)
- func NewNetAddressFailBack(addr net.Addr, services protocol.ServiceFlag) (*NetAddress, error)
- func NewNetAddressIPPort(ip net.IP, port uint16, services protocol.ServiceFlag) *NetAddress
- func NewNetAddressTimestamp(timestamp time.Time, services protocol.ServiceFlag, ip net.IP, port uint16) *NetAddress
- type Output
- type PowDiffStandard
- type ScriptTx
- type ScriptTxType
- type SerializedBlock
- func NewBlock(block *Block) *SerializedBlock
- func NewBlockDeepCopyCoinbase(msgBlock *Block) *SerializedBlock
- func NewBlockFromBlockAndBytes(block *Block, serializedBytes []byte) *SerializedBlock
- func NewBlockFromBytes(serializedBytes []byte) (*SerializedBlock, error)
- func NewBlockFromReader(r io.Reader) (*SerializedBlock, error)
- func (sb *SerializedBlock) Block() *Block
- func (sb *SerializedBlock) Bytes() ([]byte, error)
- func (sb *SerializedBlock) Hash() *hash.Hash
- func (sb *SerializedBlock) Height() uint
- func (sb *SerializedBlock) Order() uint64
- func (sb *SerializedBlock) SetHeight(height uint)
- func (sb *SerializedBlock) SetOrder(order uint64)
- func (sb *SerializedBlock) Transactions() []*Tx
- func (sb *SerializedBlock) TxLoc() ([]TxLoc, error)
- type Transaction
- func (t *Transaction) AddTxIn(ti *TxInput)
- func (t *Transaction) AddTxOut(to *TxOutput)
- func (t *Transaction) CachedTxHash() *hash.Hash
- func (tx *Transaction) Decode(r io.Reader, pver uint32) error
- func (tx *Transaction) Deserialize(r io.Reader) error
- func (tx *Transaction) Encode(w io.Writer, pver uint32, serType TxSerializeType) error
- func (t *Transaction) GetInput() []Input
- func (t *Transaction) GetLockTime() uint32
- func (t *Transaction) GetOutput() []Output
- func (t *Transaction) GetType() ScriptTxType
- func (t *Transaction) GetVersion() uint32
- func (tx *Transaction) IsCoinBase() bool
- func (t *Transaction) RecacheTxHash() *hash.Hash
- func (tx *Transaction) Serialize() ([]byte, error)
- func (tx *Transaction) SerializeNoWitness() ([]byte, error)
- func (tx *Transaction) SerializeSize() int
- func (tx *Transaction) SerializeSizeNoWitness() int
- func (tx *Transaction) TxHash() hash.Hash
- func (tx *Transaction) TxHashFull() hash.Hash
- type Tx
- type TxDesc
- type TxInput
- type TxLoc
- type TxOutPoint
- type TxOutput
- type TxSerializeType
- type TxType
- type UInt128
- type UInt256
- type UInt64
- type Uint
Constants ¶
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 )
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 )
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 )
const MaxBlockHeaderPayload = 4 + (hash.HashSize * 3) + 4 + 4 + 4 + 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 4 bytes + powType 1 byte + edges_bits 1 byte + 42circles 42*4 bytes total 113 + 169 = 282 blake2bd only need 113 bytes cuckoo need 282 bytes
const MaxBlockPayload = 1048576 // 1024*1024 (1MB)
MaxBlockPayload is the maximum bytes a block message can be in bytes.
const MaxBlockVersionValue = 65535
max version value . because only has 2 bytes
const MaxBlocksPerMsg = 500
MaxBlocksPerMsg is the maximum number of blocks allowed per message.
const MaxParentsPerBlock = 50
Limited parents quantity
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 ¶
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.
Functions ¶
func GetBlockWeight ¶
GetBlockWeight computes the value of the weight metric for a given block.
func GetParentsRoot ¶
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 MaxNetAddressPayload ¶
MaxNetAddressPayload returns the max payload size for the NetAddress based on the protocol version.
func MaxTxPerTxTree ¶
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 ¶
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 ¶
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 ¶
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 ScriptAddress() []byte }
type AddressType ¶
type AddressType byte
const ( LegerAddress AddressType = 0x01 ContractAddress AddressType = 0x02 )
type Amount ¶
type Amount int64
Amount represents the base coin monetary unit (colloquially referred to as an `Atom'). A single Amount is equal to 1e-8 of a coin.
func NewAmount ¶
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 bitcoinpay 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 (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 ¶
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 bitcoinpay (for example, calculating a fee by multiplying by a percentage).
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 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 BTP" 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) AddTransaction ¶
func (b *Block) AddTransaction(tx *Transaction) error
AddTransaction adds a transaction to the message.
func (*Block) Decode ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SerializeSize returns the number of bytes it would take to serialize the the block.
type BlockHeader ¶
type BlockHeader struct { // block version // first 2 bytes, so this value can't more than 65535 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 113 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) GetVersion ¶
func (bh *BlockHeader) GetVersion() uint32
To maintain version use the first 2 bytes for version last 2 bytes use for rand nonce
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 standard PowDiffData PowDiffStandard }
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 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 Config ¶
func (Config) MarshalJSON ¶
MarshalJSON marshals as JSON
func (*Config) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON
type ContractTransaction ¶
type Genesis ¶
type Genesis struct { Config *Config `json:"config" required:"true"` Nonce uint64 `json:"nonce" required:"true" min:"1"` }
func (Genesis) MarshalJSON ¶
MarshalJSON marshals as JSON
func (*Genesis) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON
type Key ¶
type Key struct { Address Address PrivateKey *ecc.PrivateKey }
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 PowDiffStandard ¶
type PowDiffStandard struct { //blake2b diff hash target Blake2bDTarget uint32 X16rv3DTarget uint32 X8r16DTarget uint32 BitcoinpayKeccak256Target uint32 //cuckoo base difficultuy CuckarooBaseDiff uint64 CuckatooBaseDiff uint64 CuckaroomBaseDiff uint64 //cuckoo hash convert diff scale CuckarooDiffScale uint64 CuckatooDiffScale uint64 CuckaroomDiffScale uint64 }
this standard target use for miner to verify Their work for different pow work diff blake2bd on hash compare hash <= target cuckoo diff formula :scale * 2^64 / hash(front 8bytes) >= base diff
type ScriptTx ¶
type ScriptTx interface { GetInput() []Input GetOutput() []Output GetVersion() uint32 GetLockTime() uint32 GetType() ScriptTxType }
type ScriptTxType ¶
type ScriptTxType int
const ( BitcoinpayScriptTx 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) 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) 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
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 (*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.
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 (*Tx) 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) RefreshHash ¶
func (t *Tx) RefreshHash()
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 BTP 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) }
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 (*TxInput) SerializeSize ¶
SerializeSizeWitness returns the number of bytes it would take to serialize the transaction input for a witness.
func (*TxInput) SerializeSizePrefix ¶
SerializeSizePrefix returns the number of bytes it would take to serialize the transaction input for a prefix.
func (*TxInput) SerializeSizeWitness ¶
SerializeSizeWitness returns the number of bytes it would take to serialize the transaction input for a witness.
type TxLoc ¶
TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.
type TxOutPoint ¶
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 ¶
func NewTxOutput ¶
NewTxOutput returns a new bitcoin transaction output with the provided transaction value and public key script.
func (*TxOutput) GetPkScript ¶
func (*TxOutput) SerializeSize ¶
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 byte
func DetermineTxType ¶
func DetermineTxType(tx *Transaction) TxType
DetermineTxType determines the type of stake transaction a transaction is; if none, it returns that it is an assumed regular tx.