Skip to content

Instantly share code, notes, and snippets.

@dlgusdn616
Created June 7, 2018 08:54
Show Gist options
  • Save dlgusdn616/f13d7fdb1d0bc630ae8aa884df887921 to your computer and use it in GitHub Desktop.
Save dlgusdn616/f13d7fdb1d0bc630ae8aa884df887921 to your computer and use it in GitHub Desktop.
CBlock::CheckMerkleBranch
static uint256 CheckMerkleBranch(uint256 hash, const vector<uint256>& vMerkleBranch, int nIndex)
{
if (nIndex == -1)
return 0;
foreach(const uint256& otherside, vMerkleBranch)
{ // 해시되는 순서를 지켜주기 위해 아래의 두 경우를 구분하여 처리
if (nIndex & 1) // 트랜잭션의 인덱스가 홀수일 경우
hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
else // 트랜잭션의 인덱스가 짝수일 경우
hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
nIndex >>= 1; // 해시되는 순서를 맞춰준다.
}
return hash; // it should be merkleRoot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment