Documentation
¶
Index ¶
- type Block
- type Chain
- func (c *Chain) AppendBlock(b *Block) error
- func (c *Chain) GetBlock(hash []byte) *Block
- func (c *Chain) GetTransaction(txId []byte) (Transaction, error)
- func (c *Chain) MineBlock(address string, txs []*Transaction)
- func (c *Chain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
- func (c *Chain) VerifyTransaction(tx *Transaction) bool
- type Merkle
- type MerkleNode
- type TXInput
- type TXOutput
- type TXOutputs
- type Transaction
- func (tx *Transaction) Hash() []byte
- func (tx Transaction) IsCoinbase() bool
- func (tx Transaction) Serialize() []byte
- func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTXs map[string]Transaction)
- func (tx Transaction) String() string
- func (tx *Transaction) TrimmedCopy() Transaction
- func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool
- type UTXOSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { PrevHash []byte // 上一个区块的哈希值 Timestamp time.Time // 区块创建时间 Hash []byte // 区块哈希 Nonce int // 当前计数器(挖矿使用) Height int // 当前区块高度 Transactions []*Transaction // 区块中的交易记录 }
区块
func (*Block) Mining ¶
func (b *Block) Mining(txs []*Transaction)
type Chain ¶
func (*Chain) GetTransaction ¶
func (c *Chain) GetTransaction(txId []byte) (Transaction, error)
通过交易TxID获取交易
func (*Chain) SignTransaction ¶
func (c *Chain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
交易签名
type MerkleNode ¶
type MerkleNode struct { Left *MerkleNode Right *MerkleNode Hash []byte //节点的哈希值 }
默克林树的节点
type TXOutput ¶
func (*TXOutput) IsLockedWithKey ¶
检测输出是否是某签名签名过的
type Transaction ¶
type Transaction struct { Id []byte // 交易的hash值 Inputs []TXInput // 交易的所有输入(指明引用了哪个输出) TXOutputs // 交易的所有输出 }
func NewTransaction ¶
func NewTransaction(w *wallet.Wallet, to string, amount int) *Transaction
创建交易
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() []byte
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTXs map[string]Transaction)
对交易进行私钥签名(要取输出的公钥一起加密)
func (*Transaction) Verify ¶
func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool
Click to show internal directories.
Click to hide internal directories.