is_spendable flag added

pull/2/head
moneroexamples 7 years ago
parent a0579f3263
commit ddb29ff242

@ -30,6 +30,7 @@ vector<transaction> CurrentBlockchainStatus::mempool_txs;
string CurrentBlockchainStatus::import_payment_address;
string CurrentBlockchainStatus::import_payment_viewkey;
uint64_t CurrentBlockchainStatus::import_fee {10000000000}; // 0.01 xmr
uint64_t CurrentBlockchainStatus::spendable_age {10}; // default number in monero
account_public_address CurrentBlockchainStatus::address;
secret_key CurrentBlockchainStatus::viewkey;
map<string, shared_ptr<TxSearch>> CurrentBlockchainStatus::searching_threads;
@ -122,6 +123,13 @@ CurrentBlockchainStatus::init_monero_blockchain()
return true;
}
bool
CurrentBlockchainStatus::is_tx_unlocked(uint64_t tx_blk_height)
{
return (tx_blk_height + spendable_age > get_current_blockchain_height());
}
bool
CurrentBlockchainStatus::get_block(uint64_t height, block &blk)
{

@ -52,6 +52,7 @@ struct CurrentBlockchainStatus
static string import_payment_address;
static string import_payment_viewkey;
static uint64_t import_fee;
static uint64_t spendable_age;
static account_public_address address;
static secret_key viewkey;
@ -87,6 +88,9 @@ struct CurrentBlockchainStatus
static bool
init_monero_blockchain();
static bool
is_tx_unlocked(uint64_t tx_blk_height);
static bool
get_block(uint64_t height, block &blk);

@ -417,6 +417,7 @@ MysqlTransactions::insert(const XmrTransaction& tx_data)
tx_data.unlock_time,
tx_data.height,
tx_data.coinbase,
tx_data.spendable,
tx_data.payment_id,
tx_data.mixin,
tx_data.timestamp);

@ -134,6 +134,10 @@ TxSearch::search()
searched_blk_no, pod_to_hex(get_block_hash(blk)));
}
// flag indicating whether the txs in the given block are spendable.
// this is true when block number is more than 10 blocks from current
// blockchain height.
bool is_spendable = CurrentBlockchainStatus::is_tx_unlocked(searched_blk_no);
DateTime blk_timestamp_mysql_format
= XmrTransaction::timestamp_to_DateTime(blk.timestamp);
@ -296,7 +300,6 @@ TxSearch::search()
continue;
}
tx_data.hash = tx_hash_str;
tx_data.prefix_hash = tx_prefix_hash_str;
tx_data.account_id = acc->id;
@ -306,6 +309,7 @@ TxSearch::search()
tx_data.unlock_time = 0;
tx_data.height = searched_blk_no;
tx_data.coinbase = is_coinbase_tx;
tx_data.spendable = is_spendable;
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
tx_data.mixin = get_mixin_no(tx) - 1;
tx_data.timestamp = blk_timestamp_mysql_format;

@ -44,6 +44,7 @@ XmrTransaction::to_json() const
{"height" , height},
{"payment_id" , payment_id},
{"coinbase" , bool {coinbase}},
{"spendable" , bool {spendable}},
{"mixin" , mixin},
{"timestamp" , timestamp}
};

@ -58,7 +58,7 @@ struct XmrAccount : public Accounts
};
sql_create_12(Transactions, 1, 2,
sql_create_13(Transactions, 1, 2,
sql_bigint_unsigned, id,
sql_varchar , hash,
sql_varchar , prefix_hash,
@ -68,6 +68,7 @@ sql_create_12(Transactions, 1, 2,
sql_bigint_unsigned, unlock_time,
sql_bigint_unsigned, height,
sql_bool , coinbase,
sql_bool , spendable,
sql_varchar , payment_id,
sql_bigint_unsigned, mixin,
sql_timestamp , timestamp);
@ -92,12 +93,12 @@ struct XmrTransaction : public Transactions
INSERT IGNORE INTO `Transactions` (`hash`, `prefix_hash` ,
`account_id`, `total_received`,
`total_sent`, `unlock_time`, `height`,
`coinbase`, `payment_id`, `mixin`,
`coinbase`, `spendable`, `payment_id`, `mixin`,
`timestamp`)
VALUES (%0q, %1q, %2q,
%3q, %4q, %5q,
%6q, %7q, %8q,
%9q, %10q);
%9q, %10q, , %11q);
)";
static constexpr const char* SUM_XMR_RECIEVED = R"(

Loading…
Cancel
Save