mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Infrastructure for "tx" RPC command to track transactions.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include "json/writer.h"
|
#include "json/writer.h"
|
||||||
|
|
||||||
#include "LocalTransaction.h"
|
#include "LocalTransaction.h"
|
||||||
@@ -36,3 +38,19 @@ void LocalTransaction::performTransaction()
|
|||||||
{
|
{
|
||||||
mTransaction=theApp->getOPs().processTransaction(mTransaction);
|
mTransaction=theApp->getOPs().processTransaction(mTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json::Value LocalTransaction::getJson() const
|
||||||
|
{
|
||||||
|
if(!mTransaction)
|
||||||
|
{ // has no corresponding transaction
|
||||||
|
Json::Value ret(Json::objectValue);
|
||||||
|
ret["Status"]="unfunded";
|
||||||
|
ret["Amount"]=boost::lexical_cast<std::string>(mAmount);
|
||||||
|
Json::Value destination(Json::objectValue);
|
||||||
|
destination["AccountID"]=NewcoinAddress(mDestAcctID).GetString();
|
||||||
|
ret["Destination"]=destination;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mTransaction->getJson(true, isPaid(), isCredited());
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include "json/value.h"
|
||||||
|
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
|
|
||||||
@@ -49,6 +51,8 @@ public:
|
|||||||
|
|
||||||
void performTransaction(); // perform this transaction as if we received it from the network
|
void performTransaction(); // perform this transaction as if we received it from the network
|
||||||
bool makeTransaction(); // create a transaction object according to these rules
|
bool makeTransaction(); // create a transaction object according to these rules
|
||||||
|
|
||||||
|
Json::Value getJson() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -383,6 +383,31 @@ Json::Value RPCServer::doSendTo(Json::Value& params)
|
|||||||
return lt->getTransaction()->getJson(true);
|
return lt->getTransaction()->getJson(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json::Value RPCServer::doTx(Json::Value& params)
|
||||||
|
{
|
||||||
|
// tx
|
||||||
|
// tx <txID>
|
||||||
|
// tx <family> <seq>
|
||||||
|
// tx <account>
|
||||||
|
|
||||||
|
std::string param1, param2;
|
||||||
|
if(!extractString(param1, params, 0))
|
||||||
|
{ // all local transactions
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Transaction::isHexTxID(param1))
|
||||||
|
{ // transaction by ID
|
||||||
|
}
|
||||||
|
|
||||||
|
if(extractString(param2, params, 1))
|
||||||
|
{ // family seq
|
||||||
|
}
|
||||||
|
|
||||||
|
// account
|
||||||
|
|
||||||
|
return "not implemented";
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
|
Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params)
|
||||||
{
|
{
|
||||||
std::cerr << "RPC:" << command << std::endl;
|
std::cerr << "RPC:" << command << std::endl;
|
||||||
@@ -416,6 +441,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
|
|||||||
if(command=="unlock") return doUnlock(params);
|
if(command=="unlock") return doUnlock(params);
|
||||||
if(command=="sendto") return doSendTo(params);
|
if(command=="sendto") return doSendTo(params);
|
||||||
if(command=="connect") return doConnect(params);
|
if(command=="connect") return doConnect(params);
|
||||||
|
if(command=="tx") return doTx(params);
|
||||||
|
|
||||||
return "unknown command";
|
return "unknown command";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class RPCServer : public boost::enable_shared_from_this<RPCServer>
|
|||||||
Json::Value doUnlock(Json::Value& params);
|
Json::Value doUnlock(Json::Value& params);
|
||||||
Json::Value doSendTo(Json::Value& params);
|
Json::Value doSendTo(Json::Value& params);
|
||||||
Json::Value doConnect(Json::Value& params);
|
Json::Value doConnect(Json::Value& params);
|
||||||
|
Json::Value doTx(Json::Value& params);
|
||||||
|
|
||||||
// parses a string account name into a uint160
|
// parses a string account name into a uint160
|
||||||
// can be local or remote
|
// can be local or remote
|
||||||
|
|||||||
@@ -318,7 +318,23 @@ bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedg
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value Transaction::getJson(bool decorate) const
|
static bool isHex(char j)
|
||||||
|
{
|
||||||
|
if((j>='0') && (j<='9')) return true;
|
||||||
|
if((j>='A') && (j<='F')) return true;
|
||||||
|
if((j>='a') && (j<='f')) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Transaction::isHexTxID(const std::string& txid)
|
||||||
|
{
|
||||||
|
if(txid.size()!=64) return false;
|
||||||
|
for(int i=0; i<64; i++)
|
||||||
|
if(!isHex(txid[i])) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
||||||
{
|
{
|
||||||
Json::Value ret(Json::objectValue);
|
Json::Value ret(Json::objectValue);
|
||||||
ret["TransactionID"]=mTransactionID.GetHex();
|
ret["TransactionID"]=mTransactionID.GetHex();
|
||||||
@@ -356,7 +372,10 @@ Json::Value Transaction::getJson(bool decorate) const
|
|||||||
lac=theApp->getWallet().getLocalAccount(mAccountTo);
|
lac=theApp->getWallet().getLocalAccount(mAccountTo);
|
||||||
if(!!lac) destination=lac->getJson();
|
if(!!lac) destination=lac->getJson();
|
||||||
}
|
}
|
||||||
|
if(paid) source["Paid"]=true;
|
||||||
|
if(credited) destination["Credited"]=true;
|
||||||
ret["Source"]=source;
|
ret["Source"]=source;
|
||||||
ret["Destination"]=destination;
|
ret["Destination"]=destination;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ public:
|
|||||||
bool operator<=(const Transaction&) const;
|
bool operator<=(const Transaction&) const;
|
||||||
bool operator>=(const Transaction&) const;
|
bool operator>=(const Transaction&) const;
|
||||||
|
|
||||||
Json::Value getJson(bool decorate) const;
|
Json::Value getJson(bool decorate, bool paid_local=false, bool credited_local=false) const;
|
||||||
|
|
||||||
|
static bool isHexTxID(const std::string&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Transaction::pointer transactionFromSQL(const std::string& statement);
|
static Transaction::pointer transactionFromSQL(const std::string& statement);
|
||||||
|
|||||||
Reference in New Issue
Block a user