Skip to content

Commit 436a5db

Browse files
committed
Added initial omni layer functions
1 parent 5181892 commit 436a5db

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

src/bitcoinapi/bitcoinapi.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,3 +1383,89 @@ utxosetinfo_t BitcoinAPI::gettxoutsetinfo() {
13831383

13841384
return ret;
13851385
}
1386+
1387+
#ifdef _OMNI_SUPPORT_
1388+
1389+
std::vector<omni_detailed_balance_t> BitcoinAPI::omni_getwalletbalances(bool includewatchonly)
1390+
{
1391+
string command = "omni_getwalletbalances";
1392+
Value params, result;
1393+
vector<omni_detailed_balance_t> ret;
1394+
1395+
params.append(includewatchonly);
1396+
result = sendcommand(command, params);
1397+
1398+
for(ValueIterator it = result.begin(); it != result.end(); it++){
1399+
omni_detailed_balance_t tmp;
1400+
Value val = (*it);
1401+
1402+
tmp.balance = val["balance"].asDouble();
1403+
tmp.reserved = val["reserved"].asDouble();
1404+
tmp.propertyid = val["propertyid"].asDouble();
1405+
tmp.name = val["name"].asString();
1406+
tmp.propertyid = val["propertyid"].asInt();
1407+
1408+
ret.push_back(tmp);
1409+
}
1410+
1411+
return ret;
1412+
}
1413+
1414+
omni_balance_t BitcoinAPI::omni_getbalance(const std::string& address, int propertyid)
1415+
{
1416+
string command = "omni_getbalance";
1417+
Value params, result;
1418+
omni_balance_t ret;
1419+
1420+
params.append(address);
1421+
params.append(propertyid);
1422+
1423+
result = sendcommand(command, params);
1424+
1425+
ret.balance = result["balance"].asDouble();
1426+
ret.reserved = result["reserved"].asDouble();
1427+
ret.frozen = result["frozen"].asDouble();
1428+
1429+
return ret;
1430+
}
1431+
1432+
std::vector<omni_transaction_t> BitcoinAPI::omni_listtransactions(const std::string& txid, int count, int skip, int startblock, int endblock)
1433+
{
1434+
string command = "omni_listtransactions";
1435+
Value params, result;
1436+
vector<omni_transaction_t> ret;
1437+
1438+
params.append(txid);
1439+
params.append(count);
1440+
params.append(skip);
1441+
params.append(startblock);
1442+
params.append(endblock);
1443+
result = sendcommand(command, params);
1444+
1445+
for(ValueIterator it = result.begin(); it != result.end(); it++){
1446+
omni_transaction_t tmp;
1447+
Value val = (*it);
1448+
tmp.txid = val["txid"].asString();
1449+
tmp.sendingaddress = val["sendingaddress"].asString();
1450+
tmp.referenceaddress = val["referenceaddress"].asString();
1451+
tmp.ismine = val["ismine"].asBool();
1452+
tmp.confirmations = val["confirmations"].asInt();
1453+
tmp.fee = val["fee"].asDouble();
1454+
tmp.blocktime = val["blocktime"].asUInt();
1455+
tmp.valid = val["valid"].asBool();
1456+
tmp.positioninblock = val["positioninblock"].asUInt();
1457+
tmp.version = val["version"].asInt();
1458+
tmp.type_int = val["type_int"].asInt();
1459+
tmp.type = val["type"].asString();
1460+
tmp.amount = val["amount"].asDouble();
1461+
tmp.blockhash = val["blockhash"].asString();
1462+
tmp.block = val["block"].asUInt();
1463+
1464+
ret.push_back(tmp);
1465+
}
1466+
1467+
return ret;
1468+
1469+
}
1470+
1471+
#endif

src/bitcoinapi/bitcoinapi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@ class BitcoinAPI
4242
virtual std::string sendmany(const std::string& fromaccount, const std::map<std::string, double>& amounts) = 0;
4343
4444
*/
45+
/*
4546
void omni_funded_send();
4647
void omni_funded_sendall();
4748
void omni_send();
49+
*/
50+
51+
void omni_funded_sendall();
52+
53+
std::vector<omni_detailed_balance_t> omni_getwalletbalances(bool includewatchonly);
54+
omni_balance_t omni_getbalance(const std::string& address, int propertyid);
55+
std::vector<omni_transaction_t> omni_listtransactions(const std::string& txid = "*", int count = 10, int skip = 0, int startblock = 0, int endblock = 999999999);
56+
4857
#endif
4958

5059
/* === Auxiliary functions === */

src/bitcoinapi/exception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BitcoinException: public std::exception
4040
/* Authentication error */
4141
}else if(errcode == Errors::ERROR_RPC_INTERNAL_ERROR && message.size() == 18){
4242
this->code = errcode;
43-
this->msg = "Failed to authenticate successfully";
43+
this->msg = "Failed to authenticate successfully. " + message;
4444
/* Miscellaneous error */
4545
}else{
4646
this->code = parseCode(message);

src/bitcoinapi/types.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,39 @@
242242
int confirmations;
243243
};
244244

245+
#ifdef _OMNI_SUPPORT_
246+
247+
struct omni_transaction_t {
248+
std::string txid;
249+
std::string sendingaddress;
250+
std::string referenceaddress;
251+
bool ismine;
252+
int confirmations;
253+
double amount;
254+
std::string blockhash;
255+
unsigned int block;
256+
double fee;
257+
unsigned int blocktime;
258+
bool valid;
259+
unsigned int positioninblock;
260+
int version;
261+
int type_int;
262+
std::string type;
263+
};
264+
265+
struct omni_balance_t {
266+
double balance;
267+
double reserved;
268+
double frozen;
269+
};
270+
271+
struct omni_detailed_balance_t: omni_balance_t{
272+
int propertyid;
273+
std::string name;
274+
};
275+
276+
#endif
277+
245278

246279
/* === Unused yet === */
247280
struct blockinfo_t{

0 commit comments

Comments
 (0)