Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2011-12-16 "next" #705

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e9a0e4d
Execute command specified by -coinbaser when creating a new block, wh…
luke-jr May 27, 2011
b3fb0d0
coinbaser: replace %d in command line with available funds
luke-jr May 27, 2011
4e6e221
Support for TCP server coinbasers
luke-jr Jul 5, 2011
d6cc5ef
Save coinbase, not just extraNonce
luke-jr Jul 25, 2011
29b3245
Replace nBits in coinbase scriptSig with arbitrary data set by setwor…
luke-jr Aug 3, 2011
9c65143
Bugfix/safeguard: never create a coinbase scriptSig over 100 bytes long
luke-jr Aug 5, 2011
96f9693
Check for parse or overflow errors in setworkaux
luke-jr Aug 5, 2011
3c54a7b
Merge commit '96f9693' into coinbaser
luke-jr Oct 3, 2011
a1efc8c
Document -coinbaser option in --help
luke-jr Oct 3, 2011
5980642
Port coinbaser code to Windows
luke-jr Oct 5, 2011
80828e6
Merge branch 'coinbaser'
luke-jr Oct 8, 2011
6b18ab4
Added QRCode generation functions via libqrencode
sje397 Nov 10, 2011
5c3b3bd
Merge branch 'master' of https://github.com/bitcoin/bitcoin
sje397 Nov 16, 2011
6e15fce
Merge with addressbook changes
sje397 Nov 16, 2011
97641d8
Collapse no-op ExtractAddress/ExtractAddressInner
gavinandresen Sep 29, 2011
a3f397a
Rework unit tests so test_bitcoin.cpp does not #include them all
gavinandresen Oct 11, 2011
1b714b5
Support 3 new multisignature IsStandard transactions
gavinandresen Sep 28, 2011
c4a533a
Global fixture to send output to console instead of debug.log
gavinandresen Oct 3, 2011
f4cfa27
OP_EVAL implementation
gavinandresen Oct 3, 2011
9db95d3
Put OP_EVAL string in coinbase of generated blocks
gavinandresen Oct 13, 2011
dad3142
Disable addmultisigaddress if not testnet
gavinandresen Oct 19, 2011
309e722
Interpret OP_EVAL as OP_NOP until Feb 1, 2012
gavinandresen Oct 21, 2011
186b01d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
gavinandresen Nov 8, 2011
b6084f1
Fix logic for IsChange() for send-to-self transactions.
gavinandresen Dec 5, 2011
a880b29
Bugfix: fForRelay should be false when deciding required fee to inclu…
luke-jr Dec 14, 2011
dbbf1d4
GetMinFee takes a mode parameter (GMF_{BLOCK,RELAY,SEND}) instead of …
luke-jr Oct 3, 2011
f654eef
Merge branch 'minfee_modes' into next
luke-jr Dec 14, 2011
3765dbf
Bitcoin-Qt signmessage GUI
luke-jr Oct 11, 2011
791cdec
Merge branch 'coinbaser' into next
luke-jr Dec 14, 2011
dd24b28
Merge remote branch 'gavin/op_eval' into next
luke-jr Dec 14, 2011
6746621
Merge 'QR Code generation via libqrencode' into next
luke-jr Dec 14, 2011
84417ec
Merge branch 'signmessage_gui' into next
luke-jr Dec 14, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ OBJECTS_DIR = build
MOC_DIR = build
UI_DIR = build

# use: qmake "USE_QRCODE=1"
# libqrencode (http://fukuchi.org/works/qrencode/index.en.html) must be installed for support
contains(USE_QRCODE, 1) {
message(Building with QRCode support)
DEFINES += USE_QRCODE
LIBS += -lqrencode
}

# use: qmake "RELEASE=1"
contains(RELEASE, 1) {
# Mac: compile for maximum compatibility (10.5, 32-bit)
Expand Down Expand Up @@ -83,6 +91,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/optionsdialog.h \
src/qt/sendcoinsdialog.h \
src/qt/addressbookpage.h \
src/qt/messagepage.h \
src/qt/aboutdialog.h \
src/qt/editaddressdialog.h \
src/qt/bitcoinaddressvalidator.h \
Expand Down Expand Up @@ -144,6 +153,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/optionsdialog.cpp \
src/qt/sendcoinsdialog.cpp \
src/qt/addressbookpage.cpp \
src/qt/messagepage.cpp \
src/qt/aboutdialog.cpp \
src/qt/editaddressdialog.cpp \
src/qt/bitcoinaddressvalidator.cpp \
Expand Down Expand Up @@ -190,13 +200,20 @@ RESOURCES += \
FORMS += \
src/qt/forms/sendcoinsdialog.ui \
src/qt/forms/addressbookpage.ui \
src/qt/forms/messagepage.ui \
src/qt/forms/aboutdialog.ui \
src/qt/forms/editaddressdialog.ui \
src/qt/forms/transactiondescdialog.ui \
src/qt/forms/overviewpage.ui \
src/qt/forms/sendcoinsentry.ui \
src/qt/forms/askpassphrasedialog.ui

contains(USE_QRCODE, 1) {
HEADERS += src/qt/qrcodedialog.h
SOURCES += src/qt/qrcodedialog.cpp
FORMS += src/qt/forms/qrcodedialog.ui
}

CODECFORTR = UTF-8

# for lrelease/lupdate
Expand Down
25 changes: 25 additions & 0 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,33 @@ class CBitcoinAddress : public CBase58Data
return SetHash160(Hash160(vchPubKey));
}

bool SetScriptHash160(const uint160& hash160)
{
SetData(fTestNet ? 111^2 : 2, &hash160, 20);
return true;
}

bool IsValid() const
{
int nExpectedSize = 20;
bool fExpectTestNet = false;
switch(nVersion)
{
case 0:
nExpectedSize = 20; // Hash of public key
fExpectTestNet = false;
break;
case 2:
nExpectedSize = 20; // OP_EVAL, hash of CScript
fExpectTestNet = false;
break;

case 111:
nExpectedSize = 20;
fExpectTestNet = true;
break;
case 111^2:
nExpectedSize = 20;
fExpectTestNet = true;
break;

Expand All @@ -286,6 +303,14 @@ class CBitcoinAddress : public CBase58Data
}
return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize;
}
bool IsScript() const
{
if (!IsValid())
return false;
if (fTestNet)
return nVersion == 111^2;
return nVersion == 2;
}

CBitcoinAddress()
{
Expand Down
139 changes: 133 additions & 6 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static std::string strRPCUserColonPass;
static int64 nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;


Object JSONRPCError(int code, const string& message)
{
Object error;
Expand Down Expand Up @@ -532,8 +531,6 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}

static const string strMessageMagic = "Bitcoin Signed Message:\n";

Value signmessage(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
Expand Down Expand Up @@ -662,7 +659,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
if (params.size() > 1)
nMinDepth = params[1].get_int();

// Get the set of pub keys that have the label
// Get the set of pub keys assigned to account
string strAccount = AccountFromValue(params[0]);
set<CBitcoinAddress> setAddress;
GetAccountAddresses(strAccount, setAddress);
Expand Down Expand Up @@ -931,6 +928,68 @@ Value sendmany(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}

Value addmultisigaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)
{
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
"each key is a bitcoin address, hex or base58 public key\n"
"If [account] is specified, assign address to [account].";
throw runtime_error(msg);
}
if (!fTestNet)
throw runtime_error("addmultisigaddress available only when running -testnet\n");

int nRequired = params[0].get_int();
const Array& keys = params[1].get_array();
string strAccount;
if (params.size() > 2)
strAccount = AccountFromValue(params[2]);

// Gather public keys
if (keys.size() < nRequired)
throw runtime_error(
strprintf("addmultisigaddress: wrong number of keys (got %d, need at least %d)", keys.size(), nRequired));
std::vector<CKey> pubkeys;
pubkeys.resize(keys.size());
for (int i = 0; i < keys.size(); i++)
{
const std::string& ks = keys[i].get_str();
if (ks.size() == 130) // hex public key
pubkeys[i].SetPubKey(ParseHex(ks));
else if (ks.size() > 34) // base58-encoded
{
std::vector<unsigned char> vchPubKey;
if (DecodeBase58(ks, vchPubKey))
pubkeys[i].SetPubKey(vchPubKey);
else
throw runtime_error("Error base58 decoding key: "+ks);
}
else // bitcoin address for key in this wallet
{
CBitcoinAddress address(ks);
if (!pwalletMain->GetKey(address, pubkeys[i]))
throw runtime_error(
strprintf("addmultisigaddress: unknown address: %s",ks.c_str()));
}
}

// Construct using OP_EVAL
CScript inner;
inner.SetMultisig(nRequired, pubkeys);

uint160 scriptHash = Hash160(inner);
CScript scriptPubKey;
scriptPubKey.SetEval(inner);
pwalletMain->AddCScript(scriptHash, inner);
CBitcoinAddress address;
address.SetScriptHash160(scriptHash);

pwalletMain->SetAddressBookName(address, strAccount);
return address.ToString();
}


struct tallyitem
{
Expand Down Expand Up @@ -1591,14 +1650,71 @@ Value validateaddress(const Array& params, bool fHelp)
// version of the address:
string currentAddress = address.ToString();
ret.push_back(Pair("address", currentAddress));
ret.push_back(Pair("ismine", (pwalletMain->HaveKey(address) > 0)));
if (pwalletMain->HaveKey(address))
{
ret.push_back(Pair("ismine", true));
std::vector<unsigned char> vchPubKey;
pwalletMain->GetPubKey(address, vchPubKey);
ret.push_back(Pair("pubkey", HexStr(vchPubKey)));
std::string strPubKey(vchPubKey.begin(), vchPubKey.end());
ret.push_back(Pair("pubkey58", EncodeBase58(vchPubKey)));
}
else if (pwalletMain->HaveCScript(address.GetHash160()))
{
ret.push_back(Pair("isscript", true));
CScript subscript;
pwalletMain->GetCScript(address.GetHash160(), subscript);
ret.push_back(Pair("ismine", ::IsMine(*pwalletMain, subscript)));
std::vector<CBitcoinAddress> addresses;
txnouttype whichType;
int nRequired;
ExtractAddresses(subscript, pwalletMain, whichType, addresses, nRequired);
ret.push_back(Pair("script", GetTxnOutputType(whichType)));
Array a;
BOOST_FOREACH(const CBitcoinAddress& addr, addresses)
a.push_back(addr.ToString());
ret.push_back(Pair("addresses", a));
if (whichType == TX_MULTISIG)
ret.push_back(Pair("sigsrequired", nRequired));
}
else
ret.push_back(Pair("ismine", false));
if (pwalletMain->mapAddressBook.count(address))
ret.push_back(Pair("account", pwalletMain->mapAddressBook[address]));
}
return ret;
}


Value setworkaux(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"setworkaux <id> [data]\n"
"If [data] is not specified, deletes aux.\n"
);

std::string strId = params[0].get_str();
if (params.size() > 1)
{
std::string strData = params[1].get_str();
std::vector<unsigned char> vchData = ParseHex(strData);
if (vchData.size() * 2 != strData.size())
throw JSONRPCError(-8, "Failed to parse data as hexadecimal");
CScript scriptBackup = mapAuxCoinbases[strId];
mapAuxCoinbases[strId] = CScript(vchData);
bool fOverflow;
BuildCoinbaseScriptSig(0, UINT_MAX, &fOverflow);
if (fOverflow)
throw JSONRPCError(-7, "Change would overflow coinbase script");
}
else
mapAuxCoinbases.erase(strId);

return true;
}


Value getwork(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
Expand Down Expand Up @@ -1743,7 +1859,7 @@ Value getmemorypool(const Array& params, bool fHelp)
// Create new block
if(pblock)
delete pblock;
pblock = CreateNewBlock(reservekey);
pblock = CreateNewBlock(reservekey, false);
if (!pblock)
throw JSONRPCError(-7, "Out of memory");
}
Expand Down Expand Up @@ -1837,10 +1953,12 @@ pair<string, rpcfn_type> pCallTable[] =
make_pair("move", &movecmd),
make_pair("sendfrom", &sendfrom),
make_pair("sendmany", &sendmany),
make_pair("addmultisigaddress", &addmultisigaddress),
make_pair("gettransaction", &gettransaction),
make_pair("listtransactions", &listtransactions),
make_pair("signmessage", &signmessage),
make_pair("verifymessage", &verifymessage),
make_pair("setworkaux", &setworkaux),
make_pair("getwork", &getwork),
make_pair("listaccounts", &listaccounts),
make_pair("settxfee", &settxfee),
Expand Down Expand Up @@ -2478,6 +2596,15 @@ int CommandLineRPC(int argc, char *argv[])
params[1] = v.get_obj();
}
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "addmultisigaddress" && n > 1)
{
string s = params[1].get_str();
Value v;
if (!read_string(s, v) || v.type() != array_type)
throw runtime_error("addmultisigaddress: type mismatch "+s);
params[1] = v.get_array();
}

// Execute
Object reply = CallRPC(strMethod, params);
Expand Down
9 changes: 9 additions & 0 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,15 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
if (nMinVersion > VERSION)
return DB_TOO_NEW;
}
else if (strType == "cscript")
{
uint160 hash;
ssKey >> hash;
CScript script;
ssValue >> script;
if (!pwallet->LoadCScript(hash, script))
return DB_CORRUPT;
}
}
pcursor->close();
}
Expand Down
27 changes: 20 additions & 7 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

#include <db_cxx.h>

class CTxIndex;
class CAccount;
class CAccountingEntry;
class CAddress;
class CBlockLocator;
class CDiskBlockIndex;
class CDiskTxPos;
class CMasterKey;
class COutPoint;
class CAddress;
class CWalletTx;
class CTxIndex;
class CWallet;
class CAccount;
class CAccountingEntry;
class CBlockLocator;

class CWalletTx;

extern unsigned int nWalletDBUpdated;
extern DbEnv dbenv;
Expand Down Expand Up @@ -420,6 +420,19 @@ class CWalletDB : public CDB
return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
}

// Support for BIP 0013 : see https://en.bitcoin.it/wiki/BIP_0013
bool ReadCScript(const uint160 &hash, CScript& redeemScript)
{
redeemScript.clear();
return Read(std::make_pair(std::string("cscript"), hash), redeemScript);
}

bool WriteCScript(const uint160& hash, const CScript& redeemScript)
{
nWalletDBUpdated++;
return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
}

bool WriteBestBlock(const CBlockLocator& locator)
{
nWalletDBUpdated++;
Expand Down
9 changes: 9 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ bool AppInit2(int argc, char* argv[])
" -rpcport=<port> \t\t " + _("Listen for JSON-RPC connections on <port> (default: 8332)\n") +
" -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address\n") +
" -rpcconnect=<ip> \t " + _("Send commands to node running on <ip> (default: 127.0.0.1)\n") +
" -coinbaser=<cmd> \t " + _("Execute <cmd> to calculate coinbase payees\n") +
" -keypool=<n> \t " + _("Set key pool size to <n> (default: 100)\n") +
" -rescan \t " + _("Rescan the block chain for missing wallet transactions\n");

Expand Down Expand Up @@ -517,6 +518,14 @@ bool AppInit2(int argc, char* argv[])

RandAddSeedPerfmon();

{
// Put "OP_EVAL" in the coinbase so everybody can tell when
// a majority of miners support it
const char* pOpEvalName = GetOpName(OP_EVAL);
std::vector<unsigned char> vchData(pOpEvalName, pOpEvalName+strlen(pOpEvalName));
mapAuxCoinbases[pOpEvalName] = CScript(vchData);
}

if (!CreateThread(StartNode, NULL))
wxMessageBox(_("Error: CreateThread(StartNode) failed"), "Bitcoin");

Expand Down
Loading