|
Title: Satoshi's sendalert.cpp Post by: theymos on July 03, 2018, 06:32:21 AM Now that the alert key has been disclosed (https://bitcointalk.org/index.php?topic=4587836.0), I thought that a few people might be interested in this small bit of code, perhaps the last piece of Satoshi's code that will be released. It's intended for 0.3.x.
Code: Compile Bitcoin with sendalert.cpp to make a CAlert broadcaster and run with -sendalert. sendalert.cpp: // *** CONFIDENTIAL - NOT FOR RELEASE *** #include "headers.h" static const int64 DAYS = 24 * 60 * 60; void ThreadSendAlert(); class CSendAlert { public: CSendAlert() { boost::thread(bind(ThreadSendAlert)); } ~CSendAlert() { } } instance_of_csendalert; void ThreadSendAlert() { Sleep(2000); if (!mapArgs.count("-sendalert") && !mapArgs.count("-printalert")) return; // Create alert -- set your parameters here CAlert alert; alert.nRelayUntil = GetTime() + 15 * 60; alert.nExpiration = GetTime() + 1 * DAY; alert.nID = 1001; alert.nCancel = 0; // cancels previous messages up to this ID number alert.nMinVer = 31600; alert.nMaxVer = 31600; alert.nPriority = 5000; alert.strComment = ""; alert.strStatusBar = "a new version is available"; // Sign const char* pszPrivKey = "30820113020101042053cdc1e0cfac07f7e1c312768886f4635f6bceebec0887f63a9d37a26a92e6b6a081a53081a2020101302c06072a8648ce3d0101022100fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f300604010004010704410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8022100fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141020101a14403420004fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"; vector<unsigned char> vchTmp(ParseHex(pszPrivKey)); CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); CDataStream sMsg; sMsg << *(CUnsignedAlert*)&alert; alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end()); CKey key; if (!key.SetPrivKey(vchPrivKey)) { printf("ThreadSendAlert() : key.SetPrivKey failed\n"); return; } if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) { printf("ThreadSendAlert() : key.Sign failed\n"); return; } // Test CDataStream sBuffer; sBuffer << alert; CAlert alert2; sBuffer >> alert2; if (!alert2.CheckSignature()) { printf("ThreadSendAlert() : CheckSignature failed\n"); return; } assert(alert2.vchMsg == alert.vchMsg); assert(alert2.vchSig == alert.vchSig); alert.SetNull(); printf("\nThreadSendAlert:\n"); printf("hash=%s\n", alert2.GetHash().ToString().c_str()); alert2.print(); printf("vchMsg.size()=%d, vchSig.size()=%d\n", alert2.vchMsg.size(), alert2.vchSig.size()); printf("vchMsg=%s\n", HexStr(alert2.vchMsg).c_str()); printf("vchSig=%s\n", HexStr(alert2.vchSig).c_str()); // Confirm if (!mapArgs.count("-sendalert")) return; while (vNodes.size() < 1 && !fShutdown) Sleep(500); if (fShutdown) return; if (ThreadSafeMessageBox("Send alert?", "ThreadSendAlert", wxYES_NO | wxNO_DEFAULT) != wxYES) return; if (ThreadSafeMessageBox("Send alert, are you sure?", "ThreadSendAlert", wxYES_NO | wxNO_DEFAULT) != wxYES) { ThreadSafeMessageBox("Nothing sent", "ThreadSendAlert", wxOK); return; } // Send printf("ThreadSendAlert() : Sending alert\n"); int nSent = 0; CRITICAL_BLOCK(cs_vNodes) { foreach(CNode* pnode, vNodes) { if (alert2.RelayTo(pnode)) { printf("ThreadSendAlert() : Sent alert to %s\n", pnode->addr.ToString().c_str()); nSent++; } } } printf("ThreadSendAlert() : Alert sent to %d nodes\n", nSent); ThreadSafeMessageBox(strprintf("Alert sent to %d nodes", nSent), "ThreadSendAlert", wxOK); } Title: Re: Satoshi's sendalert.cpp Post by: achow101 on July 03, 2018, 07:43:17 AM Wladimir has actually had a version of this code on his github gists for several years now: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44
Title: Re: Satoshi's sendalert.cpp Post by: btj on July 03, 2018, 08:52:20 PM Wladimir has actually had a version of this code on his github gists for several years now: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44 From the gist, it appear that "Created 19 days ago". More infos about sendalert.cpp (For tests and Patch it): https://gist.github.com/jimmysong/4c72d098255b217b4c8c |