当前位置: 首页>>代码示例>>Golang>>正文


Golang MsgBlock.BlockSha方法代码示例

本文整理汇总了Golang中github.com/decred/dcrd/wire.MsgBlock.BlockSha方法的典型用法代码示例。如果您正苦于以下问题:Golang MsgBlock.BlockSha方法的具体用法?Golang MsgBlock.BlockSha怎么用?Golang MsgBlock.BlockSha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/decred/dcrd/wire.MsgBlock的用法示例。


在下文中一共展示了MsgBlock.BlockSha方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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.BlockSha()

	return bl
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:29,代码来源:block.go

示例2: 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.BlockSha()

	return bl
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:33,代码来源:block.go

示例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.BlockSha(),
		msgBlock:    msgBlock,
		blockHeight: BlockHeightUnknown,
	}
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:9,代码来源:block.go

示例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.BlockSha(),
		msgBlock:        msgBlock,
		serializedBlock: serializedBlock,
		blockHeight:     BlockHeightUnknown,
	}
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:10,代码来源:block.go

示例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.BlockSha(),
		msgBlock:    &msgBlock,
		blockHeight: BlockHeightUnknown,
	}
	return &b, nil
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:17,代码来源:block.go

示例6:

	Header: wire.BlockHeader{
		Version:    1,
		PrevBlock:  chainhash.Hash{},
		MerkleRoot: genesisMerkleRoot,
		StakeRoot:  chainhash.Hash{},
		Timestamp:  time.Unix(1454954400, 0), // Mon, 08 Feb 2016 18:00:00 GMT
		Bits:       0x1b01ffff,               // Difficulty 32767
		SBits:      2 * 1e8,                  // 2 Coin
		Nonce:      0x00000000,
	},
	Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
}

// genesisHash is the hash of the first block in the block chain for the main
// network (genesis block).
var genesisHash = genesisBlock.BlockSha()

// TestNet ------------------------------------------------------------------------

// genesisCoinbaseTxLegacy is the coinbase transaction for the genesis block for
// the test network.
var genesisCoinbaseTxLegacy = wire.MsgTx{
	Version: 1,
	TxIn: []*wire.TxIn{
		{
			PreviousOutPoint: wire.OutPoint{
				Hash:  chainhash.Hash{},
				Index: 0xffffffff,
			},
			SignatureScript: []byte{
				0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x45, /* |.......E| */
开发者ID:Kefkius,项目名称:dcrd,代码行数:31,代码来源:genesis.go


注:本文中的github.com/decred/dcrd/wire.MsgBlock.BlockSha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。