Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#include "leveldb/status.h"7#include <stdio.h>9#include "port/port.h"11namespace leveldb {13const char* Status::CopyState(const char* state) {14uint32_t size;15memcpy(&size, state, sizeof(size));16char* result = new char[size + 5];17memcpy(result, state, size + 5);18return result;19}21Status::Status(Code code, const Slice& msg, const Slice& msg2) {22assert(code != kOk);23const uint32_t len1 = static_cast<uint32_t>(msg.size());24const uint32_t len2 = static_cast<uint32_t>(msg2.size());25const uint32_t size = len1 + (len2 ? (2 + len2) : 0);26char* result = new char[size + 5];27memcpy(result, &size, sizeof(size));28result[4] = static_cast<char>(code);29memcpy(result + 5, msg.data(), len1);30if (len2) {31result[5 + len1] = ':';32result[6 + len1] = ' ';33memcpy(result + 7 + len1, msg2.data(), len2);34}35state_ = result;36}38std::string Status::ToString() const {39if (state_ == nullptr) {40return "OK";41} else {42char tmp[30];43const char* type;44switch (code()) {45case kOk:46type = "OK";47break;48case kNotFound:49type = "NotFound: ";50break;51case kCorruption:52type = "Corruption: ";53break;54case kNotSupported:55type = "Not implemented: ";56break;57case kInvalidArgument:58type = "Invalid argument: ";59break;60case kIOError:61type = "IO error: ";62break;63default:64snprintf(tmp, sizeof(tmp),65"Unknown code(%d): ", static_cast<int>(code()));66type = tmp;67break;68}69std::string result(type);70uint32_t length;71memcpy(&length, state_, sizeof(length));72result.append(state_ + 5, length);73return result;74}75}77} // namespace leveldb
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.