diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 7927a651..3878b1e6 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1186,8 +1186,6 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "getblock" && n > 1) ConvertTo(params[1]); if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); - if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); - if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); if (strMethod == "gettxout" && n > 1) ConvertTo(params[1]); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 04b848e7..dfe05d2b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -33,7 +33,7 @@ public: nDefaultPort = 28333; nRPCPort = 28332; bnProofOfWorkLimit = CBigNum(~uint256(0) >> 1); - nTxBits = 0x207fffff; + nTxBits = 0x1e03ffff; nSubsidyHalvingInterval = 210000; // Build the genesis block. Note that the output of the genesis coinbase cannot diff --git a/src/main.cpp b/src/main.cpp index e72e38d7..e9168762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -477,6 +477,23 @@ bool CheckUsername(const std::string &userName, CValidationState &state) return true; } +bool DoTxProofOfWork(CTransaction& tx) +{ + CBigNum bnTarget; + bnTarget.SetCompact(Params().txBits()); + + if (bnTarget <= 0 || bnTarget > Params().ProofOfWorkLimit()) + return error("DoTxProofOfWork() : nBits below minimum work"); + + for(tx.nNonce = 0; tx.nNonce < std::numeric_limits::max(); tx.nNonce++ ) { + if( tx.GetHash() < bnTarget.getuint256() ) { + printf("DoTxProofOfWork completed: nonce=%u hash=%s\n", tx.nNonce, tx.GetHash().ToString().c_str()); + return true; + } + } + printf("DoTxProofOfWork error. nonce not found\n"); + return false; +} // [MF] check tx consistency and pow, not duplicated id. bool CheckTransaction(const CTransaction& tx, CValidationState &state) diff --git a/src/main.h b/src/main.h index b7f8724e..1ee9effb 100644 --- a/src/main.h +++ b/src/main.h @@ -272,6 +272,8 @@ inline bool AllowFree(double dPriority) bool CheckUsername(const std::string &userName, CValidationState &state); +bool DoTxProofOfWork(CTransaction& tx); + // Context-independent validity checks bool CheckTransaction(const CTransaction& tx, CValidationState& state); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index e6699bb4..f0a186f8 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -145,58 +145,28 @@ Value getrawtransaction(const Array& params, bool fHelp) Value createrawtransaction(const Array& params, bool fHelp) { - if (fHelp || params.size() != 2) + if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\n" - "Create a transaction spending given inputs\n" - "(array of objects containing transaction id and output number),\n" - "sending to given address(es).\n" + "createrawtransaction [pubKey=generate if omited]\n" + "Create a transaction registering a new user\n" "Returns hex-encoded raw transaction.\n" - "Note that the transaction's inputs are not signed, and\n" "it is not stored in the wallet or transmitted to the network."); - RPCTypeCheck(params, list_of(array_type)(obj_type)); - - Array inputs = params[0].get_array(); - Object sendTo = params[1].get_obj(); - CTransaction rawTx; - BOOST_FOREACH(const Value& input, inputs) - { - const Object& o = input.get_obj(); + if (params[0].type() != str_type) + throw JSONRPCError(RPC_INVALID_PARAMETER, "username must be string"); + string username = params[0].get_str(); + rawTx.userName = CScript() << vector((const unsigned char*)username.data(), (const unsigned char*)username.data() + username.size()); - uint256 txid = ParseHashO(o, "txid"); - - const Value& vout_v = find_value(o, "vout"); - if (vout_v.type() != int_type) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); - int nOutput = vout_v.get_int(); - if (nOutput < 0) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); - - CTxIn in(COutPoint(txid, nOutput)); - // [MF] rawTx.vin.push_back(in); + if (params.size() > 1) { + vector txData(ParseHexV(params[1], "pubkey")); + rawTx.pubKey << txData; + } else { + throw JSONRPCError(RPC_INTERNAL_ERROR, "pubkey generation not implemented"); } - set setAddress; - BOOST_FOREACH(const Pair& s, sendTo) - { - CBitcoinAddress address(s.name_); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+s.name_); - - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_); - setAddress.insert(address); - - CScript scriptPubKey; - scriptPubKey.SetDestination(address.Get()); - int64 nAmount = AmountFromValue(s.value_); - - CTxOut out(nAmount, scriptPubKey); - // [MF] rawTx.vout.push_back(out); - } + DoTxProofOfWork(rawTx); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << rawTx; @@ -386,8 +356,6 @@ Value signrawtransaction(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param"); } - bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE); - // Sign what we can: /* [MF] for (unsigned int i = 0; i < mergedTx.vin.size(); i++) diff --git a/src/script.h b/src/script.h index 8c6ba4e8..8ec8adb6 100644 --- a/src/script.h +++ b/src/script.h @@ -574,10 +574,10 @@ public: return std::string(); unsigned int opSize = this->at(0); - return std::string((const char*)&(this[1]), opSize); + return std::string((const char*)data()+1, opSize); } - std::string ExtractPushDataString(int n) const + std::string ExtractPushDataString(unsigned int n) const { std::vector< std::vector > vData; if( ExtractPushData(vData) && vData.size() >= n+1 ) {