This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
printf("Hello world\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { | |
int sum = 0; | |
int carrot = 0; | |
bool isHead = true; | |
ListNode* rhead; | |
ListNode* rbefore; | |
while(l1 || l2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CBlock::BuildMerkleTree() | |
{ | |
uint256 BuildMerkleTree() const | |
{ | |
vMerkleTree.clear(); | |
// 각 트랜잭션들의 해시값을 따로 저장하여 vMerkleTree 생성 | |
foreach(const CTransaction& tx, vtx) | |
vMerkleTree.push_back(tx.GetHash()); | |
int j = 0; | |
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// class CBlock in main.h | |
// header: 흔히 말하는 블록 헤더의 정체다. 풀노드가 아닌 경량 클라이언트(light client)들은 블록 헤더만 저장하게 된다. | |
int nVersion; | |
uint256 hashPrevBlock; | |
uint256 hashMerkleRoot; // BuildMerkleTree()로 생성되는 머클루트 | |
unsigned int nTime; | |
unsigned int nBits; | |
unsigned int nNonce; | |
// network and disk |