Skip to content

Instantly share code, notes, and snippets.

@dlgusdn616
Last active June 7, 2018 08:53
Show Gist options
  • Save dlgusdn616/a16f2bb9e785d307220804581227364a to your computer and use it in GitHub Desktop.
Save dlgusdn616/a16f2bb9e785d307220804581227364a to your computer and use it in GitHub Desktop.
CBlock::GetMerkleBranch
// nIndex로 위변조 여부를 검사할 특정 트랜잭션을 선택하고 머클 트리내의 트랜잭션 해시값과 연관된
// 트랜잭션의 해시들만 따로 추출하여 MerkleBranch를 생성한다.
vector<uint256> GetMerkleBranch(int nIndex) const
{ // nIndex에 해당하는 트랜잭션 증명에 사용되는 노드들을 vMerkleBranch에 담는 작업을 진행
if (vMerkleTree.empty())
BuildMerkleTree();
vector<uint256> vMerkleBranch;
int j = 0;
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
{
int i = min(nIndex^1, nSize-1); // nIndex^1의 값은 0 또는 1(반복)
vMerkleBranch.push_back(vMerkleTree[j+i]);
nIndex >>= 1;
j += nSize;
}
return vMerkleBranch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment