* Remove all matched data elements from * a script's code (used to remove signatures * before verification). Note that this * compares and removes data on the _byte level_. * It also reserializes the data to a single * script with minimaldata encoding beforehand. * A signature will
(data)
| 1305 | */ |
| 1306 | |
| 1307 | findAndDelete(data) { |
| 1308 | const target = Opcode.fromPush(data); |
| 1309 | |
| 1310 | if (this.raw.length < target.getSize()) |
| 1311 | return 0; |
| 1312 | |
| 1313 | let found = false; |
| 1314 | |
| 1315 | for (const op of this.code) { |
| 1316 | if (op.value === -1) |
| 1317 | break; |
| 1318 | |
| 1319 | if (op.equals(target)) { |
| 1320 | found = true; |
| 1321 | break; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | if (!found) |
| 1326 | return 0; |
| 1327 | |
| 1328 | const code = []; |
| 1329 | |
| 1330 | let total = 0; |
| 1331 | |
| 1332 | for (const op of this.code) { |
| 1333 | if (op.value === -1) |
| 1334 | break; |
| 1335 | |
| 1336 | if (op.equals(target)) { |
| 1337 | total += 1; |
| 1338 | continue; |
| 1339 | } |
| 1340 | |
| 1341 | code.push(op); |
| 1342 | } |
| 1343 | |
| 1344 | this.code = code; |
| 1345 | this.compile(); |
| 1346 | |
| 1347 | return total; |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * Find a data element in a script. |