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

Method DupN

txscript/stack.go:225–241  ·  view source on GitHub ↗

DupN duplicates the top N items on the stack. Stack transformation: DupN(1): [... x1 x2] -> [... x1 x2 x2] DupN(2): [... x1 x2] -> [... x1 x2 x1 x2]

(n int32)

Source from the content-addressed store, hash-verified

223// DupN(1): [... x1 x2] -> [... x1 x2 x2]
224// DupN(2): [... x1 x2] -> [... x1 x2 x1 x2]
225func (s *stack) DupN(n int32) error {
226 if n < 1 {
227 str := fmt.Sprintf("attempt to dup %d stack items", n)
228 return scriptError(ErrInvalidStackOperation, str)
229 }
230
231 // Iteratively duplicate the value n-1 down the stack n times.
232 // This leaves an in-order duplicate of the top n items on the stack.
233 for i := n; i > 0; i-- {
234 so, err := s.PeekByteArray(n - 1)
235 if err != nil {
236 return err
237 }
238 s.PushByteArray(so)
239 }
240 return nil
241}
242
243// RotN rotates the top 3N items on the stack to the left N times.
244//

Callers 4

TestStackFunction · 0.95
opcode2DupFunction · 0.80
opcode3DupFunction · 0.80
opcodeDupFunction · 0.80

Calls 3

PeekByteArrayMethod · 0.95
PushByteArrayMethod · 0.95
scriptErrorFunction · 0.85

Tested by 1

TestStackFunction · 0.76