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

Method nipN

txscript/stack.go:146–167  ·  view source on GitHub ↗

nipN is an internal function that removes the nth item on the stack and returns it. Stack transformation: nipN(0): [... x1 x2 x3] -> [... x1 x2] nipN(1): [... x1 x2 x3] -> [... x1 x3] nipN(2): [... x1 x2 x3] -> [... x2 x3]

(idx int32)

Source from the content-addressed store, hash-verified

144// nipN(1): [... x1 x2 x3] -> [... x1 x3]
145// nipN(2): [... x1 x2 x3] -> [... x2 x3]
146func (s *stack) nipN(idx int32) ([]byte, error) {
147 sz := int32(len(s.stk))
148 if idx < 0 || idx > sz-1 {
149 str := fmt.Sprintf("index %d is invalid for stack size %d", idx,
150 sz)
151 return nil, scriptError(ErrInvalidStackOperation, str)
152 }
153
154 so := s.stk[sz-idx-1]
155 if idx == 0 {
156 s.stk = s.stk[:sz-1]
157 } else if idx == sz-1 {
158 s1 := make([][]byte, sz-1)
159 copy(s1, s.stk[1:])
160 s.stk = s1
161 } else {
162 s1 := s.stk[sz-idx : sz]
163 s.stk = s.stk[:sz-idx-1]
164 s.stk = append(s.stk, s1...)
165 }
166 return so, nil
167}
168
169// NipN removes the Nth object on the stack
170//

Callers 5

PopByteArrayMethod · 0.95
NipNMethod · 0.95
RotNMethod · 0.95
SwapNMethod · 0.95
RollNMethod · 0.95

Calls 1

scriptErrorFunction · 0.85

Tested by

no test coverage detected