From d1d5d09ec5d86543243b9c9aecd24b7e9c48486a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 1 Dec 2014 13:16:01 -0800 Subject: [PATCH] update bitcoind.js for latest bitcoin upstream. --- binding.gyp | 2 + src/bitcoindjs.cc | 114 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/binding.gyp b/binding.gyp index 7530eeb6..c77b6cf1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -38,6 +38,8 @@ '-lboost_program_options', '-lboost_thread', '-lboost_chrono', + # XXX NEW + '-lsecp256k1', '<(LIBBITCOIND)', ] }] diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 58746600..836d671c 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -23,6 +23,13 @@ #include #include +/** + * secp256k1 + */ + +// XXX NEW +#include + /** * Bitcoin headers */ @@ -45,7 +52,14 @@ #include "coincontrol.h" #include "coins.h" #include "compat.h" -#include "core.h" + +// XXX OLD +// #include "core.h" + +// XXX NEW +#include "core/block.h" +#include "core/transaction.h" + #include "core_io.h" #include "crypter.h" #include "db.h" @@ -68,12 +82,19 @@ #include "rpcprotocol.h" #include "rpcserver.h" #include "rpcwallet.h" -#include "script/compressor.h" + +// XXX OLD +// #include "script/compressor.h" + #include "script/interpreter.h" #include "script/script.h" #include "script/sigcache.h" #include "script/sign.h" #include "script/standard.h" + +// XXX NEW +#include "script/script_error.h" + #include "serialize.h" #include "sync.h" #include "threadsafety.h" @@ -103,9 +124,18 @@ #include "json/json_spirit_writer.h" #include "json/json_spirit_writer_template.h" +// XXX OLD +// #include "crypto/common.h" +// #include "crypto/sha2.h" +// #include "crypto/sha1.h" +// #include "crypto/ripemd160.h" + +// XXX NEW #include "crypto/common.h" -#include "crypto/sha2.h" +#include "crypto/hmac_sha512.h" #include "crypto/sha1.h" +#include "crypto/sha256.h" +#include "crypto/sha512.h" #include "crypto/ripemd160.h" #include "univalue/univalue_escapes.h" @@ -1608,7 +1638,13 @@ NAN_METHOD(GetInfo) { obj->Set(NanNew("connections"), NanNew((int)vNodes.size())->ToInt32()); obj->Set(NanNew("proxy"), NanNew(proxy.IsValid() ? proxy.ToStringIPPort() : std::string(""))); obj->Set(NanNew("difficulty"), NanNew((double)GetDifficulty())); - obj->Set(NanNew("testnet"), NanNew(Params().NetworkID() == CBaseChainParams::TESTNET)); + + // XXX OLD + // obj->Set(NanNew("testnet"), NanNew(Params().NetworkID() == CBaseChainParams::TESTNET)); + + // XXX NEW + obj->Set(NanNew("testnet"), NanNew(Params().NetworkIDString() == "test")); + #ifdef ENABLE_WALLET if (pwalletMain) { obj->Set(NanNew("keypoololdest"), NanNew(pwalletMain->GetOldestKeyPoolTime())); @@ -1679,8 +1715,22 @@ NAN_METHOD(GetPeerInfo) { if (fStateStats) { obj->Set(NanNew("banscore"), NanNew(statestats.nMisbehavior)); obj->Set(NanNew("syncheight"), NanNew(statestats.nSyncHeight)->ToInt32()); + + // XXX NEW + obj->Set(NanNew("synced_headers"), NanNew(statestats.nSyncHeight)->ToInt32()); + obj->Set(NanNew("synced_blocks"), NanNew(statestats.nCommonHeight)->ToInt32()); + Local heights = NanNew(); + int hi = 0; + BOOST_FOREACH(int height, statestats.vHeightInFlight) { + heights->Set(hi, NanNew(height)); + hi++; + } + obj->Set(NanNew("inflight"), heights); } - obj->Set(NanNew("syncnode"), NanNew(stats.fSyncNode)); + + // XXX OLD + // obj->Set(NanNew("syncnode"), NanNew(stats.fSyncNode)); + obj->Set(NanNew("whitelisted"), NanNew(stats.fWhitelisted)); // obj->Set(NanNew("relaytxes"), NanNew(stats.fRelayTxes)); @@ -1968,7 +2018,13 @@ NAN_METHOD(GetMiningInfo) { obj->Set(NanNew("networkhashps"), NanNew( (int64_t)getnetworkhashps(empty_params, false).get_int64())); obj->Set(NanNew("pooledtx"), NanNew((uint64_t)mempool.size())); - obj->Set(NanNew("testnet"), NanNew(Params().NetworkID() == CBaseChainParams::TESTNET)); + + // XXX OLD + // obj->Set(NanNew("testnet"), NanNew(Params().NetworkID() == CBaseChainParams::TESTNET)); + + // XXX NEW + obj->Set(NanNew("testnet"), NanNew(Params().NetworkIDString() == "test")); + obj->Set(NanNew("chain"), NanNew(Params().NetworkIDString())); #ifdef ENABLE_WALLET obj->Set(NanNew("generate"), NanNew( @@ -3792,10 +3848,32 @@ NAN_METHOD(WalletCreateMultiSigAddress) { NanReturnValue(Undefined()); } - CScript inner = _createmultisig_redeemScript(nRequired, keys); + // XXX NEW + std::string strAccount = ""; + if (options->Get(NanNew("account"))->IsString()) { + String::Utf8Value account_(options->Get(NanNew("account"))->ToString()); + strAccount = std::string(*account_); + } + if (options->Get(NanNew("label"))->IsString()) { + String::Utf8Value account_(options->Get(NanNew("label"))->ToString()); + strAccount = std::string(*account_); + } + if (options->Get(NanNew("name"))->IsString()) { + String::Utf8Value account_(options->Get(NanNew("name"))->ToString()); + strAccount = std::string(*account_); + } // Construct using pay-to-script-hash: - CScriptID innerID = inner.GetID(); + CScript inner = _createmultisig_redeemScript(nRequired, keys); + + // XXX OLD + // CScriptID innerID = inner.GetID(); + + // XXX NEW + CScriptID innerID(inner); + pwalletMain->AddCScript(inner); + pwalletMain->SetAddressBook(innerID, strAccount, "send"); + CBitcoinAddress address(innerID); Local result = NanNew(); @@ -5841,8 +5919,14 @@ jstx_to_ctx(const Local jstx, CTransaction& ctx_) { Local script_obj = Local::Cast(in->Get(NanNew("scriptSig"))); String::AsciiValue shash__(script_obj->Get(NanNew("hex"))->ToString()); shash_ = *shash__; - uint256 shash(shash_); - CScript scriptSig(shash); + + // XXX OLD + // uint256 shash(shash_); + // CScript scriptSig(shash); + + // XXX NEW + std::vector shash(shash_.begin(), shash_.end()); + CScript scriptSig(shash.begin(), shash.end()); txin.scriptSig = scriptSig; txin.nSequence = (unsigned int)in->Get(NanNew("sequence"))->Uint32Value(); @@ -5862,8 +5946,14 @@ jstx_to_ctx(const Local jstx, CTransaction& ctx_) { Local script_obj = Local::Cast(out->Get(NanNew("scriptPubKey"))); String::AsciiValue phash__(script_obj->Get(NanNew("hex"))); std::string phash_ = *phash__; - uint256 phash(phash_); - CScript scriptPubKey(phash); + + // XXX OLD + // uint256 phash(phash_); + // CScript scriptPubKey(phash); + + // XXX NEW + std::vector phash(phash_.begin(), phash_.end()); + CScript scriptPubKey(phash.begin(), phash.end()); txout.scriptPubKey = scriptPubKey;