MCPcopy Create free account
hub / github.com/citp/BlockSci / getHash

Method getHash

tools/parser/preproccessed_block.cpp:276–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274};
275
276blocksci::uint256 RawTransaction::getHash(const InputView &info, const blocksci::CScriptView &scriptView, int hashType) const {
277
278 bool anyoneCanPay = !!(hashType & SIGHASH_ANYONECANPAY);
279 bool hashSingle = (hashType & 0x1f) == SIGHASH_SINGLE;
280 bool hashNone = (hashType & 0x1f) == SIGHASH_NONE;
281
282 Serializer s;
283 s.serialize(version);
284 size_t nInputs = anyoneCanPay ? 1 :inputs.size();
285 s.serializeCompact(nInputs);
286 for (unsigned int nInput = 0; nInput < nInputs; nInput++) {
287 if (anyoneCanPay) {
288 nInput = info.inputNum;
289 }
290 // Serialize the prevout
291 auto &outPointer = inputs[nInput].rawOutputPointer;
292 uint32_t outNum = outPointer.outputNum;
293 s.serialize(outPointer.hash);
294 s.serialize(outNum);
295 // Serialize the script
296 if (nInput != info.inputNum) {
297 // Blank out other inputs' signatures
298 s.serializeCompact(0);
299 } else {
300 blocksci::CScriptView::iterator it = scriptView.begin();
301 blocksci::CScriptView::iterator itBegin = it;
302 blocksci::opcodetype opcode;
303 unsigned int nCodeSeparators = 0;
304 while (scriptView.GetOp(it, opcode)) {
305 if (opcode == blocksci::OP_CODESEPARATOR) {
306 nCodeSeparators++;
307 }
308 }
309 s.serializeCompact(scriptView.size() - nCodeSeparators);
310 it = itBegin;
311 while (scriptView.GetOp(it, opcode)) {
312 if (opcode == blocksci::OP_CODESEPARATOR) {
313 s.serialize(&itBegin[0], static_cast<size_t>(it-itBegin-1));
314 itBegin = it;
315 }
316 }
317 if (itBegin != scriptView.end()) {
318 s.serialize(&itBegin[0], static_cast<size_t>(it-itBegin));
319 }
320 }
321 // Serialize the nSequence
322 if (nInput != info.inputNum && (hashSingle || hashNone)) {
323 // let the others update at will
324 s.serialize(int32_t{0});
325 } else {
326 s.serialize(inputs[nInput].sequenceNum);
327 }
328 }
329 size_t nOutputs = hashNone ? 0 : (hashSingle ? info.inputNum+1 : outputs.size());
330 s.serializeCompact(nOutputs);
331 for (unsigned int nOutput = 0; nOutput < nOutputs; nOutput++) {
332 auto value = static_cast<int64_t>(outputs[nOutput].value);
333 auto script = outputs[nOutput].getScriptView();

Callers

nothing calls this directly

Calls 8

serializeCompactMethod · 0.80
serializeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
GetOpMethod · 0.45
endMethod · 0.45
getScriptViewMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected