mirror of
https://github.com/jwinterm/myriadcoin.git
synced 2026-10-24 06:48:35 +02:00
add support for address index
This commit is contained in:
@@ -106,6 +106,65 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
|
||||
}
|
||||
}
|
||||
|
||||
Value searchrawtransactions(const Array ¶ms, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 4)
|
||||
throw runtime_error("searchrawtransactions <address> [verbose=1] [skip=0] [count=100]\n");
|
||||
|
||||
if (!fAddrIndex)
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Address index not enabled");
|
||||
|
||||
CBitcoinAddress address(params[0].get_str());
|
||||
if (!address.IsValid())
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||||
CTxDestination dest = address.Get();
|
||||
|
||||
std::set<CExtDiskTxPos> setpos;
|
||||
if (!FindTransactionsByDestination(dest, setpos))
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Cannot search for address");
|
||||
|
||||
int nSkip = 0;
|
||||
int nCount = 100;
|
||||
bool fVerbose = true;
|
||||
if (params.size() > 1)
|
||||
fVerbose = (params[1].get_int() != 0);
|
||||
if (params.size() > 2)
|
||||
nSkip = params[2].get_int();
|
||||
if (params.size() > 3)
|
||||
nCount = params[3].get_int();
|
||||
|
||||
if (nSkip < 0)
|
||||
nSkip += setpos.size();
|
||||
if (nSkip < 0)
|
||||
nSkip = 0;
|
||||
if (nCount < 0)
|
||||
nCount = 0;
|
||||
|
||||
std::set<CExtDiskTxPos>::const_iterator it = setpos.begin();
|
||||
while (it != setpos.end() && nSkip--) it++;
|
||||
|
||||
Array result;
|
||||
while (it != setpos.end() && nCount--) {
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
if (!ReadTransaction(tx, *it, hashBlock))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Cannot read transaction from disk");
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssTx << tx;
|
||||
string strHex = HexStr(ssTx.begin(), ssTx.end());
|
||||
if (fVerbose) {
|
||||
Object object;
|
||||
TxToJSON(tx, hashBlock, object);
|
||||
object.push_back(Pair("hex", strHex));
|
||||
result.push_back(object);
|
||||
} else {
|
||||
result.push_back(strHex);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Value getrawtransaction(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
|
||||
Reference in New Issue
Block a user