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

Method TransactionHeader

tools/parser/preproccessed_block.cpp:120–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120TransactionHeader::TransactionHeader(SafeMemReader &reader) {
121 auto startOffset = reader.offset();
122 auto curOffset = reader.offset();
123 version = reader.readNext<decltype(version)>();
124 baseSize = static_cast<uint32_t>(reader.offset() - curOffset);
125 curOffset = reader.offset();
126 auto inputCount = reader.readVariableLengthInteger();
127 bool containsSegwit = false;
128 if (inputCount == 0) {
129 reader.readNext<uint8_t>(); // flag
130 //assert(flag == 1);
131 containsSegwit = true;
132 curOffset = reader.offset();
133 inputCount = reader.readVariableLengthInteger();
134 }
135
136 for (decltype(inputCount) i = 0; i < inputCount; i++) {
137 reader.advance(sizeof(blocksci::uint256) + sizeof(uint32_t));
138 auto scriptLength = reader.readVariableLengthInteger();
139 reader.advance(scriptLength + sizeof(SequenceNum));
140 }
141
142 auto outputCount = reader.readVariableLengthInteger();
143 for (decltype(outputCount) i = 0; i < outputCount; i++) {
144 reader.advance(sizeof(Value));
145 auto scriptLength = reader.readVariableLengthInteger();
146 reader.advance(scriptLength);
147 }
148
149 baseSize += static_cast<uint32_t>(reader.offset() - curOffset);
150 if (containsSegwit) {
151 for (decltype(inputCount) i = 0; i < inputCount; i++) {
152 auto stackItemCount = reader.readVariableLengthInteger();
153 for (uint32_t j = 0; j < stackItemCount; j++) {
154 auto length = reader.readVariableLengthInteger();
155 reader.advance(length);
156 }
157 }
158 }
159 curOffset = reader.offset();
160 locktime = reader.readNext<Locktime>();
161 baseSize += static_cast<uint32_t>(reader.offset() - curOffset);
162 realSize = static_cast<uint32_t>(reader.offset() - startOffset);
163}
164
165void RawTransaction::calculateHash() {
166 if (hash.IsNull()) {

Callers

nothing calls this directly

Calls 3

offsetMethod · 0.80
advanceMethod · 0.80

Tested by

no test coverage detected