MCPcopy Create free account
hub / github.com/ElementsProject/elements / IsConfirmedBitcoinBlock

Function IsConfirmedBitcoinBlock

src/mainchainrpc.cpp:154–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDepth, const int nbTxs)
155{
156 LogPrintf("Checking for confirmed bitcoin block with hash %s, mindepth %d, nbtxs %d\n", hash.ToString().c_str(), nMinConfirmationDepth, nbTxs);
157 try {
158 UniValue params(UniValue::VARR);
159 params.push_back(hash.GetHex());
160 UniValue reply = CallMainChainRPC("getblockheader", params);
161 UniValue errval = find_value(reply, "error");
162 if (!errval.isNull()) {
163 LogPrintf("WARNING: Got error reply from bitcoind getblockheader: %s\n", errval.write());
164 return false;
165 }
166 UniValue result = find_value(reply, "result");
167 if (!result.isObject()) {
168 LogPrintf("ERROR: bitcoind getblockheader result was malformed (not object): %s\n", result.write());
169 return false;
170 }
171
172 UniValue confirmations = find_value(result.get_obj(), "confirmations");
173 if (!confirmations.isNum() || confirmations.get_int64() < nMinConfirmationDepth) {
174 LogPrintf("Insufficient confirmations (got %s, need at least %d).\n", confirmations.write(), nMinConfirmationDepth);
175 return false;
176 }
177
178 // Only perform extra test if nbTxs has been provided (non-zero).
179 if (nbTxs != 0) {
180 UniValue nTx = find_value(result.get_obj(), "nTx");
181 if (!nTx.isNum() || nTx.get_int64() != nbTxs) {
182 LogPrintf("ERROR: Invalid number of transactions in merkle block for %s (got %s, need exactly %d)\n",
183 hash.GetHex(), nTx.write(), nbTxs);
184 return false;
185 }
186 }
187 } catch (CConnectionFailed&) {
188 LogPrintf("WARNING: Lost connection to mainchain daemon RPC; will retry.\n");
189 return false;
190 } catch (...) {
191 LogPrintf("WARNING: Failure connecting to mainchain daemon RPC; will retry.\n");
192 return false;
193 }
194 return true;
195}

Callers 2

IsValidPeginWitnessFunction · 0.85
createrawpeginFunction · 0.85

Calls 9

CallMainChainRPCFunction · 0.85
isObjectMethod · 0.80
isNumMethod · 0.80
get_int64Method · 0.80
ToStringMethod · 0.45
push_backMethod · 0.45
GetHexMethod · 0.45
isNullMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected