RotN rotates the top 3N items on the stack to the left N times. Stack transformation: RotN(1): [... x1 x2 x3] -> [... x2 x3 x1] RotN(2): [... x1 x2 x3 x4 x5 x6] -> [... x3 x4 x5 x6 x1 x2]
(n int32)
| 246 | // RotN(1): [... x1 x2 x3] -> [... x2 x3 x1] |
| 247 | // RotN(2): [... x1 x2 x3 x4 x5 x6] -> [... x3 x4 x5 x6 x1 x2] |
| 248 | func (s *stack) RotN(n int32) error { |
| 249 | if n < 1 { |
| 250 | str := fmt.Sprintf("attempt to rotate %d stack items", n) |
| 251 | return scriptError(ErrInvalidStackOperation, str) |
| 252 | } |
| 253 | |
| 254 | // Nip the 3n-1th item from the stack to the top n times to rotate |
| 255 | // them up to the head of the stack. |
| 256 | entry := 3*n - 1 |
| 257 | for i := n; i > 0; i-- { |
| 258 | so, err := s.nipN(entry) |
| 259 | if err != nil { |
| 260 | return err |
| 261 | } |
| 262 | |
| 263 | s.PushByteArray(so) |
| 264 | } |
| 265 | return nil |
| 266 | } |
| 267 | |
| 268 | // SwapN swaps the top N items on the stack with those below them. |
| 269 | // |