MCPcopy
hub / github.com/bcoin-org/bcoin / findAndDelete

Method findAndDelete

lib/script/script.js:1307–1348  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 1

executeMethod · 0.80

Calls 5

compileMethod · 0.95
fromPushMethod · 0.80
getSizeMethod · 0.45
equalsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected