Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segwit support: parse transactions #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,26 @@ static void parseInputs(
const Block *block,
const uint8_t *&p,
const uint8_t *txHash
#if defined(BITCOIN)
, uint64_t* witnessNum
#endif
) {
if(!skip) {
startInputs(p);
}

LOAD_VARINT(nbInputs, p);

#if defined(BITCOIN) // segwit support
*witnessNum = 0;
if(nbInputs == 0)
{
SKIP(unsigned char, flag, p); // flag is always 1 in current implementation
LOAD_VARINT(nbRealInputs, p);
nbInputs = nbRealInputs;
*witnessNum = nbRealInputs;
}
#endif
for(uint64_t inputIndex=0; inputIndex<nbInputs; ++inputIndex) {
parseInput<skip>(
block,
Expand All @@ -378,6 +392,28 @@ static void parseInputs(
}
}

#if defined(BITCOIN)
static void parseWitness(
const uint8_t* &p
) {
LOAD_VARINT(num, p);
for(uint64_t i=0; i<num; ++i)
{
LOAD_VARINT(num2, p);
p += num2; // just skip witness data for now
}
}


static void parseWitnesses(
const uint64_t witnessNum,
const uint8_t* &p
) {
for(uint64_t i=0; i<witnessNum; ++i)
parseWitness(p);
}
#endif

template<
bool skip
>
Expand Down Expand Up @@ -409,7 +445,12 @@ static void parseTX(
SKIP(uint32_t, nTime, p);
#endif

#if defined(BITCOIN)
uint64_t witnessNum = 0;
parseInputs<skip>(block, p, txHash, &witnessNum);
#else
parseInputs<skip>(block, p, txHash);
#endif

Chunk *txo = 0;
size_t txoOffset = -1;
Expand All @@ -422,6 +463,11 @@ static void parseTX(

parseOutputs<skip, false>(p, txHash);

#if defined(BITCOIN)
if(witnessNum)
parseWitnesses(witnessNum, p);
#endif

if(txo) {
size_t txoSize = p - outputsStart;
txo->init(
Expand Down