本文整理汇总了C++中CBigNum::setvch方法的典型用法代码示例。如果您正苦于以下问题:C++ CBigNum::setvch方法的具体用法?C++ CBigNum::setvch怎么用?C++ CBigNum::setvch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBigNum
的用法示例。
在下文中一共展示了CBigNum::setvch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHeight
int Block::getHeight() const {
Script coinbase = getTransaction(0).getInput(0).signature();
Script::const_iterator cbi = coinbase.begin();
opcodetype opcode;
std::vector<unsigned char> data;
// We simply ignore the first opcode and data, however, it is the height...
coinbase.getOp(cbi, opcode, data);
if (opcode < OP_PUSHDATA1) {
CBigNum height;
height.setvch(data);
int h = height.getint();
return h;
}
return 0;
}
示例2: bignum_error
inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
{
CAutoBN_CTX pctx;
CBigNum bn58 = 58;
CBigNum bn0 = 0;
// Convert big endian data to little endian
// Extra zero at the end make sure bignum will interpret as a positive number
vector<unsigned char> vchTmp(pend-pbegin+1, 0);
reverse_copy(pbegin, pend, vchTmp.begin());
// Convert little endian data to bignum
CBigNum bn;
bn.setvch(vchTmp);
// Convert bignum to string
string str;
// Expected size increase from base58 conversion is approximately 137%
// use 138% to be safe
str.reserve((pend - pbegin) * 138 / 100 + 1);
CBigNum dv;
CBigNum rem;
while (bn > bn0)
{
if (!BN_div(&dv, &rem, &bn, &bn58, pctx))
throw bignum_error("EncodeBase58 : BN_div failed");
bn = dv;
unsigned int c = rem.getulong();
str += pszBase58[c];
}
// Leading zeroes encoded as base58 zeros
for (const unsigned char* p = pbegin; p < pend && *p == 0; p++)
str += pszBase58[0];
// Convert little endian string to big endian
reverse(str.begin(), str.end());
return str;
}