Bitcoin Forum
May 01, 2024, 02:16:18 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Satoshi's sendalert.cpp  (Read 263 times)
theymos (OP)
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12900


View Profile
July 03, 2018, 06:32:21 AM
Merited by TheBeardedBaby (1)
 #1

Now that the alert key has been disclosed, 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);
}

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
1714529778
Hero Member
*
Offline Offline

Posts: 1714529778

View Profile Personal Message (Offline)

Ignore
1714529778
Reply with quote  #2

1714529778
Report to moderator
1714529778
Hero Member
*
Offline Offline

Posts: 1714529778

View Profile Personal Message (Offline)

Ignore
1714529778
Reply with quote  #2

1714529778
Report to moderator
The block chain is the main innovation of Bitcoin. It is the first distributed timestamping system.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714529778
Hero Member
*
Offline Offline

Posts: 1714529778

View Profile Personal Message (Offline)

Ignore
1714529778
Reply with quote  #2

1714529778
Report to moderator
1714529778
Hero Member
*
Offline Offline

Posts: 1714529778

View Profile Personal Message (Offline)

Ignore
1714529778
Reply with quote  #2

1714529778
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6566


Just writing some code


View Profile WWW
July 03, 2018, 07:43:17 AM
 #2

Wladimir has actually had a version of this code on his github gists for several years now: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44

btj
Member
**
Offline Offline

Activity: 115
Merit: 16


View Profile
July 03, 2018, 08:52:20 PM
Merited by DarkStar_ (2), malevolent (1)
 #3

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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!