Browse Source

tx accepted!

miguelfreitas
Miguel Freitas 12 years ago
parent
commit
6e1c42e963
  1. 2
      src/bitcoinrpc.cpp
  2. 2
      src/chainparams.cpp
  3. 17
      src/main.cpp
  4. 2
      src/main.h
  5. 58
      src/rpcrawtransaction.cpp
  6. 4
      src/script.h

2
src/bitcoinrpc.cpp

@ -1186,8 +1186,6 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]); if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "getrawtransaction" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getrawtransaction" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]);
if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true); if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
if (strMethod == "gettxout" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "gettxout" && n > 1) ConvertTo<boost::int64_t>(params[1]);

2
src/chainparams.cpp

@ -33,7 +33,7 @@ public:
nDefaultPort = 28333; nDefaultPort = 28333;
nRPCPort = 28332; nRPCPort = 28332;
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 1); bnProofOfWorkLimit = CBigNum(~uint256(0) >> 1);
nTxBits = 0x207fffff; nTxBits = 0x1e03ffff;
nSubsidyHalvingInterval = 210000; nSubsidyHalvingInterval = 210000;
// Build the genesis block. Note that the output of the genesis coinbase cannot // Build the genesis block. Note that the output of the genesis coinbase cannot

17
src/main.cpp

@ -477,6 +477,23 @@ bool CheckUsername(const std::string &userName, CValidationState &state)
return true; 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<unsigned int>::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. // [MF] check tx consistency and pow, not duplicated id.
bool CheckTransaction(const CTransaction& tx, CValidationState &state) bool CheckTransaction(const CTransaction& tx, CValidationState &state)

2
src/main.h

@ -272,6 +272,8 @@ inline bool AllowFree(double dPriority)
bool CheckUsername(const std::string &userName, CValidationState &state); bool CheckUsername(const std::string &userName, CValidationState &state);
bool DoTxProofOfWork(CTransaction& tx);
// Context-independent validity checks // Context-independent validity checks
bool CheckTransaction(const CTransaction& tx, CValidationState& state); bool CheckTransaction(const CTransaction& tx, CValidationState& state);

58
src/rpcrawtransaction.cpp

@ -145,58 +145,28 @@ Value getrawtransaction(const Array& params, bool fHelp)
Value createrawtransaction(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( throw runtime_error(
"createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\n" "createrawtransaction <username> [pubKey=generate if omited]\n"
"Create a transaction spending given inputs\n" "Create a transaction registering a new user\n"
"(array of objects containing transaction id and output number),\n"
"sending to given address(es).\n"
"Returns hex-encoded raw transaction.\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."); "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; CTransaction rawTx;
BOOST_FOREACH(const Value& input, inputs) if (params[0].type() != str_type)
{ throw JSONRPCError(RPC_INVALID_PARAMETER, "username must be string");
const Object& o = input.get_obj(); string username = params[0].get_str();
rawTx.userName = CScript() << vector<unsigned char>((const unsigned char*)username.data(), (const unsigned char*)username.data() + username.size());
uint256 txid = ParseHashO(o, "txid"); if (params.size() > 1) {
vector<unsigned char> txData(ParseHexV(params[1], "pubkey"));
const Value& vout_v = find_value(o, "vout"); rawTx.pubKey << txData;
if (vout_v.type() != int_type) } else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); throw JSONRPCError(RPC_INTERNAL_ERROR, "pubkey generation not implemented");
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);
} }
set<CBitcoinAddress> setAddress; DoTxProofOfWork(rawTx);
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);
}
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << rawTx; ss << rawTx;
@ -386,8 +356,6 @@ Value signrawtransaction(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
} }
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
// Sign what we can: // Sign what we can:
/* [MF] /* [MF]
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) for (unsigned int i = 0; i < mergedTx.vin.size(); i++)

4
src/script.h

@ -574,10 +574,10 @@ public:
return std::string(); return std::string();
unsigned int opSize = this->at(0); 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<unsigned char> > vData; std::vector< std::vector<unsigned char> > vData;
if( ExtractPushData(vData) && vData.size() >= n+1 ) { if( ExtractPushData(vData) && vData.size() >= n+1 ) {

Loading…
Cancel
Save