Skip to content

Commit

Permalink
Add blocktime to MetaDEx RPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Oct 4, 2022
1 parent 25969dc commit c4cdb5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/omnicore/dbtradelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include <omnicore/sp.h>

#include <amount.h>
#include <chain.h>
#include <chainparams.h>
#include <fs.h>
#include <uint256.h>
#include <util/strencodings.h>
#include <validation.h>
#include <tinyformat.h>

#include <univalue.h>
Expand Down Expand Up @@ -170,6 +173,10 @@ bool CMPTradeList::getMatchingTrades(const uint256& txid, uint32_t propertyId, U
UniValue trade(UniValue::VOBJ);
trade.pushKV("txid", matchTxid);
trade.pushKV("block", blockNum);
CBlockIndex* pBlockIndex = ::ChainActive()[blockNum];
if (pBlockIndex != nullptr) {
trade.pushKV("blocktime", pBlockIndex->GetBlockTime());
}
if (prop1 == propertyId) {
trade.pushKV("address", address1);
trade.pushKV("amountsold", strAmount1);
Expand Down Expand Up @@ -295,6 +302,10 @@ void CMPTradeList::getTradesForPair(uint32_t propertyIdSideA, uint32_t propertyI

UniValue trade(UniValue::VOBJ);
trade.pushKV("block", blockNum);
CBlockIndex* pBlockIndex = ::ChainActive()[blockNum];
if (pBlockIndex != nullptr) {
trade.pushKV("blocktime", pBlockIndex->GetBlockTime());
}
trade.pushKV("unitprice", unitPriceStr);
trade.pushKV("inverseprice", inversePriceStr);
trade.pushKV("sellertxid", sellerTxid.GetHex());
Expand Down
3 changes: 3 additions & 0 deletions src/omnicore/doc/rpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,7 @@ Get detailed information and trade matches for orders on the distributed token e
{
"txid" : "hash", // (string) the hash of the transaction that was matched against
"block" : nnnnnn, // (number) the index of the block that contains this transaction
"blocktime" : nnnnnnnnnn, // (number) the timestamp of the block that contains the match
"address" : "address", // (string) the Bitcoin address of the other trader
"amountsold" : "n.nnnnnnnn", // (string) the number of tokens sold in this trade
"amountreceived" : "n.nnnnnnnn" // (string) the number of tokens traded in exchange
Expand Down Expand Up @@ -1851,6 +1852,7 @@ Retrieves the history of trades on the distributed token exchange for the specif
[ // (array of JSON objects)
{
"block" : nnnnnn, // (number) the index of the block that contains the trade match
"blocktime" : nnnnnnnnnn, // (number) the timestamp of the block that contains the match
"unitprice" : "n.nnnnnnnnnnn..." , // (string) the unit price used to execute this trade (received/sold)
"inverseprice" : "n.nnnnnnnnnnn...", // (string) the inverse unit price (sold/received)
"sellertxid" : "hash", // (string) the hash of the transaction of the seller
Expand Down Expand Up @@ -1912,6 +1914,7 @@ Retrieves the history of orders on the distributed exchange for the supplied add
{
"txid" : "hash", // (string) the hash of the transaction that was matched against
"block" : nnnnnn, // (number) the index of the block that contains this transaction
"blocktime" : nnnnnnnnnn, // (number) the timestamp of the block that contains the match
"address" : "address", // (string) the Bitcoin address of the other trader
"amountsold" : "n.nnnnnnnn", // (string) the number of tokens sold in this trade
"amountreceived" : "n.nnnnnnnn" // (string) the number of tokens traded in exchange
Expand Down
3 changes: 3 additions & 0 deletions src/omnicore/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ static UniValue omni_gettradehistoryforaddress(const JSONRPCRequest& request)
{
{RPCResult::Type::STR_HEX, "txid", "the hash of the transaction that was matched against"},
{RPCResult::Type::NUM, "block", "the index of the block that contains this transaction"},
{RPCResult::Type::NUM, "blocktime", "the timestamp of the block that contains the match"},
{RPCResult::Type::STR, "address", "the Bitcoin address of the other trader"},
{RPCResult::Type::STR_AMOUNT, "amountsold", "the number of tokens sold in this trade"},
{RPCResult::Type::STR_AMOUNT, "amountreceived", "the number of tokens traded in exchange"},
Expand Down Expand Up @@ -2027,6 +2028,7 @@ static UniValue omni_gettradehistoryforpair(const JSONRPCRequest& request)
{RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::NUM, "block", "the index of the block that contains the trade match"},
{RPCResult::Type::NUM, "blocktime", "the timestamp of the block that contains the match"},
{RPCResult::Type::STR_AMOUNT, "unitprice", "the unit price used to execute this trade (received/sold)"},
{RPCResult::Type::STR_AMOUNT, "inverseprice", "the inverse unit price (sold/received)"},
{RPCResult::Type::STR_HEX, "sellertxid", "the hash of the transaction of the seller"},
Expand Down Expand Up @@ -2730,6 +2732,7 @@ static UniValue omni_gettrade(const JSONRPCRequest& request)
{
{RPCResult::Type::STR_HEX, "txid", "the hash of the transaction that was matched against"},
{RPCResult::Type::NUM, "block", "the index of the block that contains this transaction"},
{RPCResult::Type::NUM, "blocktime", "the timestamp of the block that contains the match"},
{RPCResult::Type::STR, "address", "the Bitcoin address of the other trader"},
{RPCResult::Type::STR_AMOUNT, "amountsold", "the number of tokens sold in this trade"},
{RPCResult::Type::STR_AMOUNT, "amountreceived", "the number of tokens traded in exchange"},
Expand Down

0 comments on commit c4cdb5a

Please sign in to comment.