Documentation ¶
Overview ¶
Package bc provides the fundamental blockchain data structures used in the Chain Protocol.
Index ¶
- Constants
- func DurationMillis(d time.Duration) uint64
- func Millis(t time.Time) uint64
- type AssetAmount
- type AssetID
- type Block
- type BlockHeader
- func (bh *BlockHeader) Hash() Hash
- func (bh *BlockHeader) HashForSig() Hash
- func (bh *BlockHeader) Scan(val interface{}) error
- func (bh *BlockHeader) Time() time.Time
- func (bh *BlockHeader) Value() (driver.Value, error)
- func (bh *BlockHeader) WriteForSigTo(w io.Writer) (int64, error)
- func (bh *BlockHeader) WriteTo(w io.Writer) (int64, error)
- type Hash
- type IssuanceInput
- type Outpoint
- type OutputCommitment
- type SigHasher
- type SpendInput
- type Tx
- type TxData
- func (tx *TxData) HasIssuance() bool
- func (tx *TxData) Hash() Hash
- func (tx *TxData) HashForSig(idx int) Hash
- func (tx *TxData) IssuanceHash(n int) (h Hash, err error)
- func (tx *TxData) MarshalText() ([]byte, error)
- func (tx *TxData) Scan(val interface{}) error
- func (tx *TxData) UnmarshalText(p []byte) error
- func (tx *TxData) Value() (driver.Value, error)
- func (tx *TxData) WitnessHash() Hash
- func (tx *TxData) WriteTo(w io.Writer) (int64, error)
- type TxInput
- func (t TxInput) Amount() uint64
- func (t TxInput) Arguments() [][]byte
- func (t TxInput) AssetAmount() AssetAmount
- func (t TxInput) AssetID() AssetID
- func (t TxInput) ControlProgram() []byte
- func (t TxInput) InputCommitmentBytes() []byte
- func (t TxInput) IssuanceProgram() []byte
- func (t TxInput) Outpoint() (o Outpoint)
- func (t *TxInput) SetArguments(args [][]byte)
- func (t TxInput) WitnessHash() Hash
- type TxOutput
- type TypedInput
Constants ¶
const ( SerBlockWitness = 1 SerBlockTransactions = 2 SerBlockSigHash = 0 SerBlockHeader = SerBlockWitness SerBlockFull = SerBlockWitness | SerBlockTransactions )
const ( SerWitness uint8 = 1 << iota SerPrevout SerMetadata // Bit mask for accepted serialization flags. // All other flag bits must be 0. SerValid = 0x7 )
These flags are part of the wire protocol; they must not change.
const CurrentTransactionVersion = 1
CurrentTransactionVersion is the current latest supported transaction version.
const NewBlockVersion = 1
NewBlockVersion is the version to use when creating new blocks.
Variables ¶
This section is empty.
Functions ¶
func DurationMillis ¶
DurationMillis converts a time.Duration to a number of milliseconds.
Types ¶
type AssetAmount ¶
type AssetID ¶
type AssetID [32]byte
AssetID is the Hash256 of the issuance script for the asset and the initial block of the chain where it appears.
func ComputeAssetID ¶
func ComputeAssetID(issuanceProgram []byte, initialHash [32]byte, vmVersion uint64) (assetID AssetID)
ComputeAssetID computes the asset ID of the asset defined by the given issuance program and initial block hash.
func (AssetID) MarshalText ¶
func (*AssetID) UnmarshalJSON ¶
func (*AssetID) UnmarshalText ¶
type Block ¶
type Block struct { BlockHeader Transactions []*Tx }
Block describes a complete block, including its header and the transactions it contains.
func (*Block) MarshalText ¶
MarshalText fulfills the json.Marshaler interface. This guarantees that blocks will get deserialized correctly when being parsed from HTTP requests.
func (*Block) UnmarshalText ¶
UnmarshalText fulfills the encoding.TextUnmarshaler interface.
type BlockHeader ¶
type BlockHeader struct { // Version of the block. Version uint64 // Height of the block in the block chain. // Initial block has height 1. Height uint64 // Hash of the previous block in the block chain. PreviousBlockHash Hash // Time of the block in milliseconds. // Must grow monotonically and can be equal // to the time in the previous block. TimestampMS uint64 // TransactionsMerkleRoot is the root hash of the Merkle binary hash // tree formed by the transaction witness hashes of all transactions // included in the block. TransactionsMerkleRoot Hash // AssetsMerkleRoot is the root hash of the Merkle Patricia Tree of // the set of unspent outputs with asset version 1 after applying // the block. AssetsMerkleRoot Hash // ConsensusProgram is the predicate for validating the next block. ConsensusProgram []byte // Witness is a vector of arguments to the previous block's // ConsensusProgram for validating this block. Witness [][]byte }
BlockHeader describes necessary data of the block.
func (*BlockHeader) Hash ¶
func (bh *BlockHeader) Hash() Hash
Hash returns complete hash of the block header.
func (*BlockHeader) HashForSig ¶
func (bh *BlockHeader) HashForSig() Hash
HashForSig returns a hash of the block header without witness. This hash is used for signing the block and verifying the signature.
func (*BlockHeader) Scan ¶
func (bh *BlockHeader) Scan(val interface{}) error
func (*BlockHeader) Time ¶
func (bh *BlockHeader) Time() time.Time
Time returns the time represented by the Timestamp in bh.
func (*BlockHeader) WriteForSigTo ¶
func (bh *BlockHeader) WriteForSigTo(w io.Writer) (int64, error)
WriteForSigTo writes bh to w in a format suitable for signing.
type Hash ¶
type Hash [32]byte
Hash represents a 256-bit hash. By convention, Hash objects are typically passed as values, not as pointers.
func (Hash) MarshalText ¶
MarshalText satisfies the TextMarshaler interface. It returns the bytes of h encoded in hex, for formats that can't hold arbitrary binary data. It never returns an error.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface. If b is a JSON-encoded null, it copies the zero-value into h. Othwerwise, it decodes hex data from b into h.
func (*Hash) UnmarshalText ¶
UnmarshalText satisfies the TextUnmarshaler interface. It decodes hex data from b into h.
type IssuanceInput ¶
type IssuanceInput struct { // Commitment Nonce []byte Amount uint64 // Witness InitialBlock Hash VMVersion uint64 IssuanceProgram []byte Arguments [][]byte }
func (IssuanceInput) AssetID ¶
func (ii IssuanceInput) AssetID() AssetID
func (IssuanceInput) IsIssuance ¶
func (ii IssuanceInput) IsIssuance() bool
type Outpoint ¶
Outpoint defines a bitcoin data type that is used to track previous transaction outputs.
type OutputCommitment ¶
type OutputCommitment struct { AssetAmount VMVersion uint64 ControlProgram []byte }
type SigHasher ¶
type SigHasher struct {
// contains filtered or unexported fields
}
SigHasher caches a txhash for reuse with multiple inputs.
func NewSigHasher ¶
type SpendInput ¶
type SpendInput struct { // Commitment Outpoint OutputCommitment // Witness Arguments [][]byte }
func (SpendInput) IsIssuance ¶
func (si SpendInput) IsIssuance() bool
type Tx ¶
Tx holds a transaction along with its hash.
func NewTx ¶
NewTx returns a new Tx containing data and its hash. If you have already computed the hash, use struct literal notation to make a Tx object directly.
func (*Tx) UnmarshalText ¶
type TxData ¶
type TxData struct { Version uint64 Inputs []*TxInput Outputs []*TxOutput MinTime uint64 MaxTime uint64 ReferenceData []byte }
TxData encodes a transaction in the blockchain. Most users will want to use Tx instead; it includes the hash.
func (*TxData) HasIssuance ¶
HasIssuance returns true if this transaction has an issuance input.
func (*TxData) Hash ¶
Hash computes the hash of the transaction with reference data fields replaced by their hashes, and stores the result in Hash.
func (*TxData) HashForSig ¶
HashForSig generates the hash required for the specified input's signature.
func (*TxData) MarshalText ¶
func (*TxData) UnmarshalText ¶
func (*TxData) WitnessHash ¶
WitnessHash is the combined hash of the transactions hash and signature data hash. It is used to compute the TxRoot of a block.
type TxInput ¶
type TxInput struct { AssetVersion uint64 ReferenceData []byte TypedInput }
func NewIssuanceInput ¶
func NewSpendInput ¶
func (TxInput) AssetAmount ¶
func (t TxInput) AssetAmount() AssetAmount
func (TxInput) ControlProgram ¶
func (TxInput) InputCommitmentBytes ¶
func (TxInput) IssuanceProgram ¶
func (*TxInput) SetArguments ¶
func (TxInput) WitnessHash ¶
type TxOutput ¶
type TxOutput struct { AssetVersion uint64 OutputCommitment ReferenceData []byte }
func NewTxOutput ¶
func (TxOutput) Commitment ¶
func (TxOutput) WitnessHash ¶
type TypedInput ¶
type TypedInput interface {
IsIssuance() bool
}