SwapN swaps the top N items on the stack with those below them. Stack transformation: SwapN(1): [... x1 x2] -> [... x2 x1] SwapN(2): [... x1 x2 x3 x4] -> [... x3 x4 x1 x2]
(n int32)
| 271 | // SwapN(1): [... x1 x2] -> [... x2 x1] |
| 272 | // SwapN(2): [... x1 x2 x3 x4] -> [... x3 x4 x1 x2] |
| 273 | func (s *stack) SwapN(n int32) error { |
| 274 | if n < 1 { |
| 275 | str := fmt.Sprintf("attempt to swap %d stack items", n) |
| 276 | return scriptError(ErrInvalidStackOperation, str) |
| 277 | } |
| 278 | |
| 279 | entry := 2*n - 1 |
| 280 | for i := n; i > 0; i-- { |
| 281 | // Swap 2n-1th entry to top. |
| 282 | so, err := s.nipN(entry) |
| 283 | if err != nil { |
| 284 | return err |
| 285 | } |
| 286 | |
| 287 | s.PushByteArray(so) |
| 288 | } |
| 289 | return nil |
| 290 | } |
| 291 | |
| 292 | // OverN copies N items N items back to the top of the stack. |
| 293 | // |