本文整理匯總了Golang中github.com/decred/dcrd/wire.MsgBlock.BlockHash方法的典型用法代碼示例。如果您正苦於以下問題:Golang MsgBlock.BlockHash方法的具體用法?Golang MsgBlock.BlockHash怎麽用?Golang MsgBlock.BlockHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/decred/dcrd/wire.MsgBlock
的用法示例。
在下文中一共展示了MsgBlock.BlockHash方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewBlockDeepCopyCoinbase
// 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 NewBlockDeepCopyCoinbase(msgBlock *wire.MsgBlock) *Block {
// Copy the msgBlock and the pointers to all the transactions.
msgBlockCopy := new(wire.MsgBlock)
lenTxs := len(msgBlock.Transactions)
mtxsCopy := make([]*wire.MsgTx, lenTxs)
for i, mtx := range msgBlock.Transactions {
mtxsCopy[i] = mtx
}
msgBlockCopy.Transactions = mtxsCopy
lenStxs := len(msgBlock.STransactions)
smtxsCopy := make([]*wire.MsgTx, lenStxs)
for i, smtx := range msgBlock.STransactions {
smtxsCopy[i] = smtx
}
msgBlockCopy.STransactions = smtxsCopy
msgBlockCopy.Header = msgBlock.Header
// Deep copy the first transaction. Also change the coinbase pointer.
msgBlockCopy.Transactions[0] =
NewTxDeep(msgBlockCopy.Transactions[0]).MsgTx()
bl := &Block{
blockHeight: int64(msgBlockCopy.Header.Height),
msgBlock: msgBlockCopy,
}
bl.hash = msgBlock.BlockHash()
return bl
}
示例2: NewBlockDeepCopy
// NewBlockDeepCopy deep copies an entire block down to the wire components and
// returns the new block based off of this copy.
func NewBlockDeepCopy(msgBlock *wire.MsgBlock) *Block {
// Deep copy the header and all the transactions.
msgBlockCopy := new(wire.MsgBlock)
lenTxs := len(msgBlock.Transactions)
mtxsCopy := make([]*wire.MsgTx, lenTxs)
for i, mtx := range msgBlock.Transactions {
txd := NewTxDeep(mtx)
mtxsCopy[i] = txd.MsgTx()
}
msgBlockCopy.Transactions = mtxsCopy
lenStxs := len(msgBlock.STransactions)
smtxsCopy := make([]*wire.MsgTx, lenStxs)
for i, smtx := range msgBlock.STransactions {
stxd := NewTxDeep(smtx)
smtxsCopy[i] = stxd.MsgTx()
}
msgBlockCopy.STransactions = smtxsCopy
msgBlockCopy.Header = msgBlock.Header
bl := &Block{
blockHeight: int64(msgBlockCopy.Header.Height),
msgBlock: msgBlockCopy,
}
bl.hash = msgBlock.BlockHash()
return bl
}
示例3: NewBlock
// NewBlock returns a new instance of a block given an underlying
// wire.MsgBlock. See Block.
func NewBlock(msgBlock *wire.MsgBlock) *Block {
return &Block{
hash: msgBlock.BlockHash(),
msgBlock: msgBlock,
blockHeight: int64(msgBlock.Header.Height),
}
}
示例4: NewBlockFromBlockAndBytes
// NewBlockFromBlockAndBytes returns a new instance of a block given
// an underlying wire.MsgBlock and the serialized bytes for it. See Block.
func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block {
return &Block{
hash: msgBlock.BlockHash(),
msgBlock: msgBlock,
serializedBlock: serializedBlock,
blockHeight: int64(msgBlock.Header.Height),
}
}
示例5: NewBlockFromReader
// NewBlockFromReader returns a new instance of a block given a
// Reader to deserialize the block. See Block.
func NewBlockFromReader(r io.Reader) (*Block, error) {
// Deserialize the bytes into a MsgBlock.
var msgBlock wire.MsgBlock
err := msgBlock.Deserialize(r)
if err != nil {
return nil, err
}
b := Block{
hash: msgBlock.BlockHash(),
msgBlock: &msgBlock,
blockHeight: int64(msgBlock.Header.Height),
}
return &b, nil
}