Skip to content

Commit

Permalink
wire: add Copy method to MsgBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Jan 21, 2024
1 parent e8a5a55 commit 9cda0f7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wire/msgblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ type MsgBlock struct {
Transactions []*MsgTx
}

// Copy creates a deep copy of MsgBlock.
func (msg *MsgBlock) Copy() *MsgBlock {
block := &MsgBlock{
Header: msg.Header,
Transactions: make([]*MsgTx, len(msg.Transactions)),
}

for i, tx := range msg.Transactions {
block.Transactions[i] = tx.Copy()
}

return block
}

// AddTransaction adds a transaction to the message.
func (msg *MsgBlock) AddTransaction(tx *MsgTx) error {
msg.Transactions = append(msg.Transactions, tx)
Expand Down

0 comments on commit 9cda0f7

Please sign in to comment.