MCPcopy Create free account
hub / github.com/DNAProject/DNA / ReadNum

Method ReadNum

core/program/program.go:185–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

183}
184
185func (self *programParser) ReadNum() (uint16, error) {
186 code, err := self.PeekOpCode()
187 if err != nil {
188 return 0, err
189 }
190
191 if code == neovm.PUSH0 {
192 self.ReadOpCode()
193 return 0, nil
194 } else if num := int(code) - int(neovm.PUSH1) + 1; 1 <= num && num <= 16 {
195 self.ReadOpCode()
196 return uint16(num), nil
197 }
198
199 buff, err := self.ReadBytes()
200 if err != nil {
201 return 0, err
202 }
203 bint := common.BigIntFromNeoBytes(buff)
204 num := bint.Int64()
205 if num > math.MaxUint16 || num <= 16 {
206 return 0, fmt.Errorf("num not in range (16, MaxUint16]: %d", num)
207 }
208
209 return uint16(num), nil
210}
211
212func (self *programParser) ReadBytes() ([]byte, error) {
213 code, err := self.ReadOpCode()

Callers 2

GetProgramInfoFunction · 0.95

Calls 5

PeekOpCodeMethod · 0.95
ReadOpCodeMethod · 0.95
ReadBytesMethod · 0.95
BigIntFromNeoBytesFunction · 0.92
ErrorfMethod · 0.80

Tested by 1