@@ -358,12 +358,26 @@ static void parseInputs(
358358 const Block *block,
359359 const uint8_t *&p,
360360 const uint8_t *txHash
361+ #if defined(BITCOIN)
362+ , uint64_t * witnessNum
363+ #endif
361364) {
362365 if (!skip) {
363366 startInputs (p);
364367 }
365368
366369 LOAD_VARINT (nbInputs, p);
370+
371+ #if defined(BITCOIN) // segwit support
372+ *witnessNum = 0 ;
373+ if (nbInputs == 0 )
374+ {
375+ SKIP (unsigned char , flag, p); // flag is always 1 in current implementation
376+ LOAD_VARINT (nbRealInputs, p);
377+ nbInputs = nbRealInputs;
378+ *witnessNum = nbRealInputs;
379+ }
380+ #endif
367381 for (uint64_t inputIndex=0 ; inputIndex<nbInputs; ++inputIndex) {
368382 parseInput<skip>(
369383 block,
@@ -378,6 +392,28 @@ static void parseInputs(
378392 }
379393}
380394
395+ #if defined(BITCOIN)
396+ static void parseWitness (
397+ const uint8_t * &p
398+ ) {
399+ LOAD_VARINT (num, p);
400+ for (uint64_t i=0 ; i<num; ++i)
401+ {
402+ LOAD_VARINT (num2, p);
403+ p += num2; // just skip witness data for now
404+ }
405+ }
406+
407+
408+ static void parseWitnesses (
409+ const uint64_t witnessNum,
410+ const uint8_t * &p
411+ ) {
412+ for (uint64_t i=0 ; i<witnessNum; ++i)
413+ parseWitness (p);
414+ }
415+ #endif
416+
381417template <
382418 bool skip
383419>
@@ -409,7 +445,12 @@ static void parseTX(
409445 SKIP (uint32_t , nTime, p);
410446 #endif
411447
448+ #if defined(BITCOIN)
449+ uint64_t witnessNum = 0 ;
450+ parseInputs<skip>(block, p, txHash, &witnessNum);
451+ #else
412452 parseInputs<skip>(block, p, txHash);
453+ #endif
413454
414455 Chunk *txo = 0 ;
415456 size_t txoOffset = -1 ;
@@ -422,6 +463,11 @@ static void parseTX(
422463
423464 parseOutputs<skip, false >(p, txHash);
424465
466+ #if defined(BITCOIN)
467+ if (witnessNum)
468+ parseWitnesses (witnessNum, p);
469+ #endif
470+
425471 if (txo) {
426472 size_t txoSize = p - outputsStart;
427473 txo->init (
@@ -978,15 +1024,15 @@ static void findBlockFiles() {
9781024 }
9791025
9801026 auto fileSize = statBuf.st_size ;
981- #if !defined(_WIN64)
982- auto r1 = posix_fadvise (fd, 0 , fileSize, POSIX_FADV_NOREUSE );
983- if (r1<0 ) {
984- warning (
985- " failed to posix_fadvise on block chain file %s" ,
986- fileName.c_str ()
987- );
988- }
989- #endif
1027+ #if !defined(_WIN64)
1028+ auto r1 = posix_fadvise (fd, 0 , fileSize, POSIX_FADV_NOREUSE );
1029+ if (r1<0 ) {
1030+ warning (
1031+ " failed to posix_fadvise on block chain file %s" ,
1032+ fileName.c_str ()
1033+ );
1034+ }
1035+ #endif
9901036
9911037 BlockFile blockFile;
9921038 blockFile.fd = fd;
0 commit comments