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

Method OverN

txscript/stack.go:297–315  ·  view source on GitHub ↗

OverN copies N items N items back to the top of the stack. Stack transformation: OverN(1): [... x1 x2 x3] -> [... x1 x2 x3 x2] OverN(2): [... x1 x2 x3 x4] -> [... x1 x2 x3 x4 x1 x2]

(n int32)

Source from the content-addressed store, hash-verified

295// OverN(1): [... x1 x2 x3] -> [... x1 x2 x3 x2]
296// OverN(2): [... x1 x2 x3 x4] -> [... x1 x2 x3 x4 x1 x2]
297func (s *stack) OverN(n int32) error {
298 if n < 1 {
299 str := fmt.Sprintf("attempt to perform over on %d stack items",
300 n)
301 return scriptError(ErrInvalidStackOperation, str)
302 }
303
304 // Copy 2n-1th entry to top of the stack.
305 entry := 2*n - 1
306 for ; n > 0; n-- {
307 so, err := s.PeekByteArray(entry)
308 if err != nil {
309 return err
310 }
311 s.PushByteArray(so)
312 }
313
314 return nil
315}
316
317// PickN copies the item N items back in the stack to the top.
318//

Callers 3

TestStackFunction · 0.95
opcode2OverFunction · 0.80
opcodeOverFunction · 0.80

Calls 3

PeekByteArrayMethod · 0.95
PushByteArrayMethod · 0.95
scriptErrorFunction · 0.85

Tested by 1

TestStackFunction · 0.76