Permalink
Browse files

Added ?raw=1 parameter to outpointSpend and outpointSpends APIs

  • Loading branch information...
gertjaap committed Dec 7, 2017
1 parent 1311a32 commit 13776009b732bbea99259ca3191ff6f9bb1b3fdb
Showing with 40 additions and 4 deletions.
  1. +39 −3 src/httpserver.cpp
  2. +1 −1 vertcoin-mainnet.yml
@@ -377,7 +377,9 @@ void VtcBlockIndexer::HttpServer::outpointSpend( const shared_ptr< Session > ses
json j;
j["error"] = false;
const auto request = session->get_request( );

int raw = stoi(request->get_query_parameter("raw","0"));
int unconfirmed = stoi(request->get_query_parameter("unconfirmed","0"));

long long vout = stoll(request->get_path_parameter( "vout", "0" ));
string txid = request->get_path_parameter("txid", "");
stringstream txBlockKey;
@@ -399,13 +401,28 @@ void VtcBlockIndexer::HttpServer::outpointSpend( const shared_ptr< Session > ses
j["spent"] = s.ok();
if(s.ok()) {
j["spender"] = spentTx.substr(65, 64);
} else {
} else if(unconfirmed != 0) {
string mempoolSpend = mempoolMonitor->outpointSpend(txid, vout);
if(mempoolSpend.compare("") != 0) {
j["spent"] = true;
j["spender"] = mempoolSpend;
}
}

if(raw != 0 && j["spender"].is_string()) {
try {
const Json::Value tx = vertcoind->getrawtransaction(j["spender"].get<string>(), false);
j["spenderRaw"] = tx.asString();
j["spender"] = nullptr;
} catch(const jsonrpc::JsonRpcException& e) {
const std::string message(e.what());
cout << "Not found " << message << endl;
}
}




}

string body = j.dump();
@@ -419,8 +436,16 @@ void VtcBlockIndexer::HttpServer::outpointSpends( const shared_ptr< Session > se
const auto request = session->get_request( );
size_t content_length = 0;
content_length = request->get_header( "Content-Length", 0);



session->fetch( content_length, [ request, this ]( const shared_ptr< Session > session, const Bytes & body )
{
const auto request = session->get_request( );
int raw = stoi(request->get_query_parameter("raw","0"));
int unconfirmed = stoi(request->get_query_parameter("unconfirmed","0"));


string content =string(body.begin(), body.end());
json output = json::array();
json input = json::parse(content);
@@ -450,7 +475,7 @@ void VtcBlockIndexer::HttpServer::outpointSpends( const shared_ptr< Session > se
if(s.ok()) {
j["spender"] = spentTx.substr(65, 64);
j["spent"] = true;
} else {
} else if(unconfirmed != 0) {
string mempoolSpend = mempoolMonitor->outpointSpend( txo["txid"].get<string>(), txo["vout"].get<int>());
if(mempoolSpend.compare("") != 0) {
json j;
@@ -462,6 +487,17 @@ void VtcBlockIndexer::HttpServer::outpointSpends( const shared_ptr< Session > se
}
}

if(raw != 0 && j["spender"].is_string()) {
try {
const Json::Value tx = vertcoind->getrawtransaction(j["spender"].get<string>(), false);
j["spenderRaw"] = tx.asString();
j["spender"] = nullptr;
} catch(const jsonrpc::JsonRpcException& e) {
const std::string message(e.what());
cout << "Not found " << message << endl;
}
}

output.push_back(j);

}
@@ -11,7 +11,7 @@ services:
- "5889:5889"
volumes:
- ./data/vtc/main/coind:/data
command: -rpcuser=middleware -rpcpassword=middleware -txindex
command: -rpcuser=middleware -rpcpassword=middleware -rpcallowip=0.0.0.0/0 -rpcport=8332 -txindex

vtc-middleware-cpp-main:
image: vtc-wallet-middleware

0 comments on commit 1377600

Please sign in to comment.