MCPcopy Create free account
hub / github.com/copernet/copernicus / convertOPS

Method convertOPS

model/script/script.go:313–366  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

311}
312
313func (s *Script) convertOPS() (err error) {
314 s.ParsedOpCodes = make([]opcodes.ParsedOpCode, 0)
315 scriptLen := uint(len(s.data))
316 err = nil
317
318 var i uint
319 for i < scriptLen {
320 var nSize uint
321 opcode := s.data[i]
322 i++
323 if opcode < opcodes.OP_PUSHDATA1 {
324 nSize = uint(opcode)
325 } else if opcode == opcodes.OP_PUSHDATA1 {
326 if scriptLen-i < 1 {
327 log.Debug("OP_PUSHDATA1 has no enough data")
328 err = errors.New("OP_PUSHDATA1 has no enough data")
329 break
330 }
331 nSize = uint(s.data[i])
332 i++
333 } else if opcode == opcodes.OP_PUSHDATA2 {
334 if scriptLen-i < 2 {
335 log.Debug("OP_PUSHDATA2 has no enough data")
336 err = errors.New("OP_PUSHDATA2 has no enough data")
337 break
338 }
339 nSize = uint(binary.LittleEndian.Uint16(s.data[i : i+2]))
340 i += 2
341 } else if opcode == opcodes.OP_PUSHDATA4 {
342 if scriptLen-i < 4 {
343 log.Debug("OP_PUSHDATA4 has no enough data")
344 err = errors.New("OP_PUSHDATA4 has no enough data")
345 break
346
347 }
348 nSize = uint(binary.LittleEndian.Uint32(s.data[i : i+4]))
349 i += 4
350 }
351 if scriptLen-i < 0 || scriptLen-i < nSize {
352 log.Debug("ConvertOPS script data size is wrong")
353 err = errors.New("size is wrong")
354 break
355 }
356 parsedopCode := opcodes.NewParsedOpCode(opcode, int(nSize), s.data[i:i+nSize])
357 s.ParsedOpCodes = append(s.ParsedOpCodes, *parsedopCode)
358 i += nSize
359 }
360 if err != nil {
361 s.badOpCode = true
362 } else {
363 s.badOpCode = false
364 }
365 return
366}
367
368func (s *Script) RemoveOpcodeByData(data []byte) *Script {
369 parsedOpCodes := make([]opcodes.ParsedOpCode, 0, len(s.ParsedOpCodes))

Callers 7

DecodeMethod · 0.95
NewScriptRawFunction · 0.95
PushOpCodeMethod · 0.95
PushInt64Method · 0.95
PushDataMethod · 0.95
PushSingleDataMethod · 0.95
PushMultDataMethod · 0.95

Calls 2

Uint16Method · 0.80
Uint32Method · 0.80

Tested by

no test coverage detected