block: allow cached seralized block to be overritten

This commit is contained in:
Roy Lee 2022-08-12 02:18:22 -07:00
parent c604c37b24
commit 6a93b80756

View file

@ -69,6 +69,13 @@ func (b *Block) Bytes() ([]byte, error) {
return serializedBlock, nil return serializedBlock, nil
} }
// Bytes sets the serialized bytes for the Block. This is equivalent to
// calling Serialize on the underlying wire.MsgBlock, however it caches the
// result so subsequent calls are more efficient.
func (b *Block) SetBytes(data []byte) {
b.serializedBlock = data
}
// BytesNoWitness returns the serialized bytes for the block with transactions // BytesNoWitness returns the serialized bytes for the block with transactions
// encoded without any witness data. // encoded without any witness data.
func (b *Block) BytesNoWitness() ([]byte, error) { func (b *Block) BytesNoWitness() ([]byte, error) {
@ -90,6 +97,12 @@ func (b *Block) BytesNoWitness() ([]byte, error) {
return serializedBlock, nil return serializedBlock, nil
} }
// SetBytesNoWitness sets the serialized bytes for the block with transactions
// encoded without any witness data.
func (b *Block) SetBytesNoWitness(data []byte) {
b.serializedBlockNoWitness = data
}
// Hash returns the block identifier hash for the Block. This is equivalent to // Hash returns the block identifier hash for the Block. This is equivalent to
// calling BlockHash on the underlying wire.MsgBlock, however it caches the // calling BlockHash on the underlying wire.MsgBlock, however it caches the
// result so subsequent calls are more efficient. // result so subsequent calls are more efficient.