CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.
(h *Header)
| 334 | // CopyHeader creates a deep copy of a block header to prevent side effects from |
| 335 | // modifying a header variable. |
| 336 | func CopyHeader(h *Header) *Header { |
| 337 | cpy := *h |
| 338 | if cpy.Time = new(big.Int); h.Time != nil { |
| 339 | cpy.Time.Set(h.Time) |
| 340 | } |
| 341 | if cpy.Number = new(big.Int); h.Number != nil { |
| 342 | cpy.Number.Set(h.Number) |
| 343 | } |
| 344 | if len(h.Extra) > 0 { |
| 345 | cpy.Extra = make([]byte, len(h.Extra)) |
| 346 | copy(cpy.Extra, h.Extra) |
| 347 | } |
| 348 | cpy.Dpor = *CopyDporSnap(&h.Dpor) |
| 349 | return &cpy |
| 350 | } |
| 351 | |
| 352 | func CopyDporSnap(d *DporSnap) *DporSnap { |
| 353 | // copy DporSnap |
no test coverage detected