MCPcopy Index your code
hub / github.com/btcsuite/btcd / RotN

Method RotN

txscript/stack.go:248–266  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

246// RotN(1): [... x1 x2 x3] -> [... x2 x3 x1]
247// RotN(2): [... x1 x2 x3 x4 x5 x6] -> [... x3 x4 x5 x6 x1 x2]
248func (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//

Callers 3

TestStackFunction · 0.95
opcode2RotFunction · 0.80
opcodeRotFunction · 0.80

Calls 3

nipNMethod · 0.95
PushByteArrayMethod · 0.95
scriptErrorFunction · 0.85

Tested by 1

TestStackFunction · 0.76