Browse Source

Merge branch 'danger' into duke

p2p_privacy
Duke 12 months ago
parent
commit
c933771f85
  1. 97
      src/hush_gateway.h
  2. 1
      src/hush_globals.h
  3. 262
      src/hush_pax.h
  4. 1
      src/hush_utils.h
  5. 71
      src/rpc/blockchain.cpp
  6. 3
      src/rpc/client.cpp
  7. 3
      src/rpc/server.cpp
  8. 5
      src/rpc/server.h
  9. 82
      src/wallet/rpcwallet.cpp

97
src/hush_gateway.h

@ -18,40 +18,9 @@
// paxdeposit equivalent in reverse makes opreturn and HUSH does the same in reverse
#include "hush_defs.h"
/*#include "secp256k1/include/secp256k1.h"
#include "secp256k1/include/secp256k1_schnorrsig.h"
#include "secp256k1/include/secp256k1_musig.h"
int32_t dummy_linker_tricker()
{
secp256k1_context *ctx = 0; std::vector<uint8_t> musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk;
if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 )
return(1);
}*/
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base)
{
int32_t baseid; struct hush_state *sp; int64_t netliability,maxallowed,maxval;
*available = *deposited = *issued = *withdrawn = *approved = *redeemed = 0;
if ( (baseid= hush_baseid(base)) >= 0 )
{
if ( (sp= hush_stateptrget(base)) != 0 )
{
*deposited = sp->deposited;
*issued = sp->issued;
*withdrawn = sp->withdrawn;
*approved = sp->approved;
*redeemed = sp->redeemed;
maxval = sp->approved;
if ( sp->withdrawn > maxval )
maxval = sp->withdrawn;
netliability = (sp->issued - maxval) - sp->shorted;
maxallowed = hush_maxallowed(baseid);
if ( netliability < maxallowed )
*available = (maxallowed - netliability);
//printf("%llu - %llu %s %.8f %.8f %.8f %.8f %.8f\n",(long long)maxallowed,(long long)netliability,base,dstr(*deposited),dstr(*issued),dstr(*withdrawn),dstr(*approved),dstr(*redeemed));
return(0);
} else printf("pax_fiatstatus cant get basesp.%s\n",base);
} // else printf("pax_fiatstatus illegal base.%s\n",base);
return(-1);
}
@ -210,71 +179,7 @@ int32_t hush_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction
int32_t hush_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *hushheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo)
{
struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[HUSH_SMART_CHAIN_MAXLEN];
//if ( HUSH_PAX == 0 )
// return(0);
incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4));
//41e77b91cb68dc2aa02fa88550eae6b6d44db676a7e935337b6d1392d9718f03cb0200305c90660400000000fbcbeb1f000000bde801006201000058e7945ad08ddba1eac9c9b6c8e1e97e8016a2d152
// 41e94d736ec69d88c08b5d238abeeca609c02357a8317e0d56c328bcb1c259be5d0200485bc80200000000404b4c000000000059470200b80b000061f22ba7d19fe29ac3baebd839af8b7127d1f9075553440046bb4cc7a3b5cd39dffe7206507a3482a00780e617f68b273cce9817ed69298d02001069ca1b0000000080f0fa02000000005b470200b90b000061f22ba7d19fe29ac3baebd839af8b7127d1f90755
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretlen.%d (%s)\n",opretlen,base);
//printf(" opretlen.%d vs %d incr.%d (%d)\n",opretlen,(int32_t)(2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 2),incr,opretlen/incr);
//if ( SMART_CHAIN_SYMBOL[0] == 0 || strncmp(SMART_CHAIN_SYMBOL,base,strlen(base)) == 0 )
{
type = opretbuf[0];
opretbuf++, opretlen--;
for (n=0; n<opretlen/incr; n++)
{
if ( iskomodo != 0 )
{
memset(&p,0,sizeof(p));
len += hush_rwapproval(0,&opretbuf[len],&p);
if ( values != 0 && srcvalues != 0 && hushheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 )
{
txids[n] = p.txid;
vouts[n] = p.vout;
values[n] = (strcmp("HUSH3",base) == 0) ? p.puposhis : p.fiatoshis;
srcvalues[n] = (strcmp("HUSH3",base) == 0) ? p.fiatoshis : p.puposhis;
hushheights[n] = p.height;
otherheights[n] = p.otherheight;
memcpy(&rmd160s[n * 20],p.rmd160,20);
baseids[n] = hush_baseid(p.source);
if ( 0 )
{
char coinaddr[64];
bitcoin_address(coinaddr,60,&rmd160s[n * 20],20);
printf(">>>>>>> %s: (%s) fiat %.8f hushheight.%d other.%d -> %s %.8f\n",type=='A'?"approvedA":"issuedX",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),hushheights[n],otherheights[n],coinaddr,dstr(values[n]));
}
}
}
else
{
for (i=0; i<4; i++)
base[i] = opretbuf[opretlen-4+i];
for (j=0; j<32; j++)
{
((uint8_t *)&txids[n])[j] = opretbuf[len++];
//printf("%02x",((uint8_t *)&txids[n])[j]);
}
vouts[n] = opretbuf[len++];
vouts[n] = (opretbuf[len++] << 8) | vouts[n];
baseids[n] = hush_baseid(base);
if ( (pax= hush_paxfinds(txids[n],vouts[n])) != 0 )
{
values[n] = (strcmp("HUSH3",base) == 0) ? pax->puposhis : pax->fiatoshis;
srcvalues[n] = (strcmp("HUSH3",base) == 0) ? pax->fiatoshis : pax->puposhis;
hushheights[n] = pax->height;
otherheights[n] = pax->otherheight;
memcpy(&rmd160s[n * 20],pax->rmd160,20);
}
}
//printf(" hush_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen);
}
}
return(n);
return 0;
}
int32_t hush_paxcmp(char *symbol,int32_t hushheight,uint64_t value,uint64_t checkvalue,uint64_t seed)

1
src/hush_globals.h

@ -29,7 +29,6 @@ int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,ui
int32_t hush_isrealtime(int32_t *hushheightp);
uint64_t hush_paxtotal();
int32_t hush_longestchain();
uint64_t hush_maxallowed(int32_t baseid);
int32_t hush_checkvout(int32_t vout,int32_t k,int32_t indallvouts);
pthread_mutex_t hush_mutex;

262
src/hush_pax.h

@ -18,213 +18,13 @@
#include "hush_defs.h"
#define USD 0
#define EUR 1
#define JPY 2
#define GBP 3
#define AUD 4
#define CAD 5
#define CHF 6
#define NZD 7
#define CNY 8
#define RUB 9
#define MXN 10
#define BRL 11
#define INR 12
#define HKD 13
#define TRY 14
#define ZAR 15
#define PLN 16
#define NOK 17
#define SEK 18
#define DKK 19
#define CZK 20
#define HUF 21
#define ILS 22
#define KRW 23
#define MYR 24
#define PHP 25
#define RON 26
#define SGD 27
#define THB 28
#define BGN 29
#define IDR 30
#define HRK 31
#define MAX_CURRENCIES 32
extern char CURRENCIES[][8];
uint64_t M1SUPPLY[] = { 3317900000000, 6991604000000, 667780000000000, 1616854000000, 331000000000, 861909000000, 584629000000, 46530000000, // major currencies
45434000000000, 16827000000000, 3473357229000, 306435000000, 27139000000000, 2150641000000, 347724099000, 1469583000000, 749543000000, 1826110000000, 2400434000000, 1123925000000, 3125276000000, 13975000000000, 317657000000, 759706000000000, 354902000000, 2797061000000, 162189000000, 163745000000, 1712000000000, 39093000000, 1135490000000000, 80317000000,
100000000 };
#define MIND 1000
uint32_t MINDENOMS[] = { MIND, MIND, 100*MIND, MIND, MIND, MIND, MIND, MIND, // major currencies
10*MIND, 100*MIND, 10*MIND, MIND, 100*MIND, 10*MIND, MIND, 10*MIND, MIND, 10*MIND, 10*MIND, 10*MIND, 10*MIND, 100*MIND, MIND, 1000*MIND, MIND, 10*MIND, MIND, MIND, 10*MIND, MIND, 10000*MIND, 10*MIND, // end of currencies
10*MIND,
};
int32_t Peggy_inds[539] = {289, 404, 50, 490, 59, 208, 87, 508, 366, 288, 13, 38, 159, 440, 120, 480, 361, 104, 534, 195, 300, 362, 489, 108, 143, 220, 131, 244, 133, 473, 315, 439, 210, 456, 219, 352, 153, 444, 397, 491, 286, 479, 519, 384, 126, 369, 155, 427, 373, 360, 135, 297, 256, 506, 322, 425, 501, 251, 75, 18, 420, 537, 443, 438, 407, 145, 173, 78, 340, 240, 422, 160, 329, 32, 127, 128, 415, 495, 372, 522, 60, 238, 129, 364, 471, 140, 171, 215, 378, 292, 432, 526, 252, 389, 459, 350, 233, 408, 433, 51, 423, 19, 62, 115, 211, 22, 247, 197, 530, 7, 492, 5, 53, 318, 313, 283, 169, 464, 224, 282, 514, 385, 228, 175, 494, 237, 446, 105, 150, 338, 346, 510, 6, 348, 89, 63, 536, 442, 414, 209, 216, 227, 380, 72, 319, 259, 305, 334, 236, 103, 400, 176, 267, 355, 429, 134, 257, 527, 111, 287, 386, 15, 392, 535, 405, 23, 447, 399, 291, 112, 74, 36, 435, 434, 330, 520, 335, 201, 478, 17, 162, 483, 33, 130, 436, 395, 93, 298, 498, 511, 66, 487, 218, 65, 309, 419, 48, 214, 377, 409, 462, 139, 349, 4, 513, 497, 394, 170, 307, 241, 185, 454, 29, 367, 465, 194, 398, 301, 229, 212, 477, 303, 39, 524, 451, 116, 532, 30, 344, 85, 186, 202, 517, 531, 515, 230, 331, 466, 147, 426, 234, 304, 64, 100, 416, 336, 199, 383, 200, 166, 258, 95, 188, 246, 136, 90, 68, 45, 312, 354, 184, 314, 518, 326, 401, 269, 217, 512, 81, 88, 272, 14, 413, 328, 393, 198, 226, 381, 161, 474, 353, 337, 294, 295, 302, 505, 137, 207, 249, 46, 98, 27, 458, 482, 262, 253, 71, 25, 0, 40, 525, 122, 341, 107, 80, 165, 243, 168, 250, 375, 151, 503, 124, 52, 343, 371, 206, 178, 528, 232, 424, 163, 273, 191, 149, 493, 177, 144, 193, 388, 1, 412, 265, 457, 255, 475, 223, 41, 430, 76, 102, 132, 96, 97, 316, 472, 213, 263, 3, 317, 324, 274, 396, 486, 254, 205, 285, 101, 21, 279, 58, 467, 271, 92, 538, 516, 235, 332, 117, 500, 529, 113, 445, 390, 358, 79, 34, 488, 245, 83, 509, 203, 476, 496, 347, 280, 12, 84, 485, 323, 452, 10, 146, 391, 293, 86, 94, 523, 299, 91, 164, 363, 402, 110, 321, 181, 138, 192, 469, 351, 276, 308, 277, 428, 182, 260, 55, 152, 157, 382, 121, 507, 225, 61, 431, 31, 106, 327, 154, 16, 49, 499, 73, 70, 449, 460, 187, 24, 248, 311, 275, 158, 387, 125, 67, 284, 35, 463, 190, 179, 266, 376, 221, 42, 26, 290, 357, 268, 43, 167, 99, 374, 242, 156, 239, 403, 339, 183, 320, 180, 306, 379, 441, 20, 481, 141, 77, 484, 69, 410, 502, 172, 417, 118, 461, 261, 47, 333, 450, 296, 453, 368, 359, 437, 421, 264, 504, 281, 270, 114, 278, 56, 406, 448, 411, 521, 418, 470, 123, 455, 148, 356, 468, 109, 204, 533, 365, 8, 345, 174, 370, 28, 57, 11, 2, 231, 310, 196, 119, 82, 325, 44, 342, 37, 189, 142, 222, 9, 54, };
uint64_t peggy_smooth_coeffs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)] = // numprimes.13
{
962714545, 962506087, 962158759, 961672710, 961048151, 960285354, 959384649, 958346426, 957171134, // x.8
955859283, 954411438, 952828225, 951110328, 949258485, 947273493, 945156207, 942907532, 940528434, // x.17
938019929, 935383089, 932619036, 929728945, 926714044, 923575608, 920314964, 916933485, 913432593, // x.26
909813756, 906078486, 902228342, 898264923, 894189872, 890004874, 885711650, 881311964, 876807614, // x.35
872200436, 867492300, 862685110, 857780804, 852781347, 847688737, 842505000, 837232189, 831872382, // x.44
826427681, 820900212, 815292123, 809605581, 803842772, 798005901, 792097186, 786118864, 780073180, // x.53
773962395, 767788778, 761554609, 755262175, 748913768, 742511686, 736058231, 729555707, 723006417, // x.62
716412665, 709776755, 703100984, 696387648, 689639036, 682857428, 676045100, 669204315, 662337327, // x.71
655446378, 648533696, 641601496, 634651978, 627687325, 620709702, 613721256, 606724115, 599720386, // x.80
592712154, 585701482, 578690411, 571680955, 564675105, 557674825, 550682053, 543698699, 536726645, // x.89
529767743, 522823816, 515896658, 508988029, 502099660, 495233249, 488390461, 481572928, 474782249, // x.98
468019988, 461287675, 454586804, 447918836, 441285195, 434687268, 428126409, 421603932, 415121117, // x.107
408679208, 402279408, 395922888, 389610779, 383344175, 377124134, 370951677, 364827785, 358753406, // x.116
352729449, 346756785, 340836251, 334968645, 329154729, 323395230, 317690838, 312042206, 306449955, // x.125
300914667, 295436891, 290017141, 284655897, 279353604, 274110676, 268927490, 263804394, 258741701, // x.134
253739694, 248798623, 243918709, 239100140, 234343077, 229647649, 225013957, 220442073, 215932043, // x.143
211483883, 207097585, 202773112, 198510404, 194309373, 190169909, 186091877, 182075118, 178119452, // x.152
174224676, 170390565, 166616873, 162903335, 159249664, 155655556, 152120688, 148644718, 145227287, // x.161
141868021, 138566528, 135322401, 132135218, 129004542, 125929924, 122910901, 119946997, 117037723, // x.170
114182582, 111381062, 108632643, 105936795, 103292978, 100700645, 98159238, 95668194, 93226942, // x.179
90834903, 88491495, 86196126, 83948203, 81747126, 79592292, 77483092, 75418916, 73399150, // x.188
71423178, 69490383, 67600142, 65751837, 63944844, 62178541, 60452305, 58765515, 57117547, // x.197
55507781, 53935597, 52400377, 50901505, 49438366, 48010349, 46616844, 45257246, 43930951, // x.206
42637360, 41375878, 40145912, 38946876, 37778185, 36639262, 35529533, 34448428, 33395384, // x.215
32369842, 31371249, 30399057, 29452725, 28531717, 27635503, 26763558, 25915365, 25090413, // x.224
24288196, 23508216, 22749980, 22013003, 21296806, 20600917, 19924870, 19268206, 18630475, // x.233
18011231, 17410035, 16826458, 16260073, 15710466, 15177224, 14659944, 14158231, 13671694, // x.242
13199950, 12742625, 12299348, 11869759, 11453500, 11050225, 10659590, 10281262, 9914910, // x.251
9560213, 9216856, 8884529, 8562931, 8251764, 7950739, 7659571, 7377984, 7105706, // x.260
6842471, 6588020, 6342099, 6104460, 5874861, 5653066, 5438844, 5231969, 5032221, // x.269
4839386, 4653254, 4473620, 4300287, 4133059, 3971747, 3816167, 3666139, 3521488, // x.278
3382043, 3247640, 3118115, 2993313, 2873079, 2757266, 2645728, 2538325, 2434919, // x.287
2335380, 2239575, 2147382, 2058677, 1973342, 1891262, 1812325, 1736424, 1663453, // x.296
1593311, 1525898, 1461118, 1398879, 1339091, 1281666, 1226519, 1173569, 1122736, // x.305
1073944, 1027117, 982185, 939076, 897725, 858065, 820033, 783568, 748612, // x.314
715108, 682999, 652233, 622759, 594527, 567488, 541597, 516808, 493079, // x.323
470368, 448635, 427841, 407948, 388921, 370725, 353326, 336692, 320792, // x.332
305596, 291075, 277202, 263950, 251292, 239204, 227663, 216646, 206130, // x.341
196094, 186517, 177381, 168667, 160356, 152430, 144874, 137671, 130806, // x.350
124264, 118031, 112093, 106437, 101050, 95921, 91039, 86391, 81968, // x.359
77759, 73755, 69945, 66322, 62877, 59602, 56488, 53528, 50716, // x.368
48043, 45505, 43093, 40803, 38629, 36564, 34604, 32745, 30980, // x.377
29305, 27717, 26211, 24782, 23428, 22144, 20927, 19774, 18681, // x.386
17646, 16665, 15737, 14857, 14025, 13237, 12491, 11786, 11118, // x.395
10487, 9890, 9325, 8791, 8287, 7810, 7359, 6933, 6531, // x.404
6151, 5792, 5453, 5133, 4831, 4547, 4278, 4024, 3785, // x.413
3560, 3347, 3147, 2958, 2779, 2612, 2454, 2305, 2164, // x.422
2032, 1908, 1791, 1681, 1577, 1480, 1388, 1302, 1221, // x.431
1145, 1073, 1006, 942, 883, 827, 775, 725, 679, // x.440
636, 595, 557, 521, 487, 456, 426, 399, 373, // x.449
348, 325, 304, 284, 265, 248, 231, 216, 202, // x.458
188, 175, 164, 153, 142, 133, 124, 115, 107, // x.467
100, 93, 87, 81, 75, 70, 65, 61, 56, // x.476
53, 49, 45, 42, 39, 36, 34, 31, 29, // x.485
27, 25, 23, 22, 20, 19, 17, 16, 15, // x.494
14, 13, 12, 11, 10, 9, 9, 8, 7, // x.503
7, 6, 6, 5, 5, 5, 4, 4, 4, // x.512
3, 3, 3, 3, 2, 2, 2, 2, 2, // x.521
2, 2, 1, 1, 1, 1, 1, 1, 1, // x.530
1, 1, 1, 1, 1, 1, 0, 0, // isum 100000000000
};
uint64_t hush_maxallowed(int32_t baseid)
{
uint64_t mult,val = COIN * (uint64_t)10000;
if ( baseid < 0 || baseid >= 32 )
return(0);
if ( baseid < 10 )
val *= 4;
mult = MINDENOMS[baseid] / MIND;
return(mult * val);
}
uint64_t hush_paxvol(uint64_t volume,uint64_t price)
{
if ( volume < 10000000000 )
return((volume * price) / 1000000000);
else if ( volume < (uint64_t)10 * 10000000000 )
return((volume * (price / 10)) / 100000000);
else if ( volume < (uint64_t)100 * 10000000000 )
return(((volume / 10) * (price / 10)) / 10000000);
else if ( volume < (uint64_t)1000 * 10000000000 )
return(((volume / 10) * (price / 100)) / 1000000);
else if ( volume < (uint64_t)10000 * 10000000000 )
return(((volume / 100) * (price / 100)) / 100000);
else if ( volume < (uint64_t)100000 * 10000000000 )
return(((volume / 100) * (price / 1000)) / 10000);
else if ( volume < (uint64_t)1000000 * 10000000000 )
return(((volume / 1000) * (price / 1000)) / 1000);
else if ( volume < (uint64_t)10000000 * 10000000000 )
return(((volume / 1000) * (price / 10000)) / 100);
else return(((volume / 10000) * (price / 10000)) / 10);
}
void pax_rank(uint64_t *ranked,uint32_t *pvals)
{
int32_t i; uint64_t vals[32],sum = 0;
for (i=0; i<32; i++)
{
vals[i] = hush_paxvol(M1SUPPLY[i] / MINDENOMS[i],pvals[i]);
sum += vals[i];
}
for (i=0; i<32; i++)
{
ranked[i] = (vals[i] * 1000000000) / sum;
//printf("%.6f ",(double)ranked[i]/1000000000.);
}
//printf("sum %llu\n",(long long)sum);
};
#define BTCFACTOR_HEIGHT 466266
double PAX_BTCUSD(int32_t height,uint32_t btcusd)
{
double btcfactor,BTCUSD;
if ( height >= BTCFACTOR_HEIGHT )
btcfactor = 100000.;
else btcfactor = 1000.;
BTCUSD = ((double)btcusd / (1000000000. / btcfactor));
if ( height >= BTCFACTOR_HEIGHT && height < 500000 && BTCUSD > 20000 && btcfactor == 100000. )
BTCUSD /= 100;
return(BTCUSD);
}
int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t rmd160[20],char fiat[4],uint8_t *shortflagp,int64_t *fiatoshisp)
{
if ( rwflag != 0 )
{
memset(pubkey33,0,33);
pubkey33[0] = 0x02 | (*shortflagp != 0);
memcpy(&pubkey33[1],fiat,3);
dragon_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp);
pubkey33[12] = *addrtypep;
memcpy(&pubkey33[13],rmd160,20);
}
else
{
*shortflagp = (pubkey33[0] == 0x03);
memcpy(fiat,&pubkey33[1],3);
fiat[3] = 0;
dragon_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp);
if ( *shortflagp != 0 )
*fiatoshisp = -(*fiatoshisp);
*addrtypep = pubkey33[12];
memcpy(rmd160,&pubkey33[13],20);
}
return(33);
}
double PAX_val(uint32_t pval,int32_t baseid)
{
//printf("PAX_val baseid.%d pval.%u\n",baseid,pval);
if ( baseid >= 0 && baseid < MAX_CURRENCIES )
return(((double)pval / 1000000000.) / MINDENOMS[baseid]);
return(0.);
}
@ -232,68 +32,6 @@ void hush_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
{
}
uint64_t hush_paxcorrelation(uint64_t *votes,int32_t numvotes,uint64_t seed)
{
int32_t i,j,k,ind,zeroes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0;
for (sum=i=zeroes=nonz=0; i<numvotes; i++)
{
if ( votes[i] == 0 )
zeroes++;
else sum += votes[i], nonz++;
}
if ( nonz < (numvotes >> 2) )
return(0);
sum /= nonz;
lastprice = sum;
for (i=0; i<numvotes; i++)
{
if ( votes[i] == 0 )
votes[i] = lastprice;
else lastprice = votes[i];
}
tolerance = sum / 50;
for (k=0; k<numvotes; k++)
{
ind = Peggy_inds[(k + seed) % numvotes];
i = (int32_t)(ind % numvotes);
wt = 0;
if ( votes[i] != 0 )
{
for (j=0; j<numvotes; j++)
{
if ( votes[j] != 0 )
{
if ( (delta= (votes[i] - votes[j])) < 0 )
delta = -delta;
if ( delta <= tolerance )
{
wt++;
if ( wt > (numvotes >> 1) )
break;
}
}
}
}
if ( wt > (numvotes >> 1) )
{
ind = i;
for (densum=sum=j=0; j<numvotes; j++)
{
den = peggy_smooth_coeffs[j];
densum += den;
sum += (den * votes[(ind + j) % numvotes]);
//printf("(%llu/%llu %.8f) ",(long long)sum,(long long)densum,(double)sum/densum);
}
if ( densum != 0 )
sum /= densum;
//sum = (sum * basevolume);
//printf("paxprice seed.%llx sum %.8f densum %.8f\n",(long long)seed,dstr(sum),dstr(densum));
break;
}
}
return(sum);
}
uint64_t hush_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint64_t basevolume)
{
return 0;

1
src/hush_utils.h

@ -2335,7 +2335,6 @@ void hush_args(char *argv0)
if ( (baseid = hush_baseid(SMART_CHAIN_SYMBOL)) >= 0 && baseid < 32 )
{
//hush_maxallowed(baseid);
if(fDebug)
printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN);
}

71
src/rpc/blockchain.cpp

@ -1061,79 +1061,8 @@ UniValue notaries(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
int32_t hush_pending_withdraws(char *opretstr);
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
extern char CURRENCIES[][8];
UniValue paxpending(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); char opretbuf[10000*2]; int32_t opretlen,baseid; uint64_t available,deposited,issued,withdrawn,approved,redeemed;
if ( fHelp || params.size() != 0 )
throw runtime_error("paxpending needs no args\n");
LOCK(cs_main);
if ( (opretlen= hush_pending_withdraws(opretbuf)) > 0 )
ret.push_back(Pair("withdraws", opretbuf));
else ret.push_back(Pair("withdraws", (char *)""));
for (baseid=0; baseid<32; baseid++)
{
UniValue item(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,CURRENCIES[baseid]) == 0 )
{
if ( deposited != 0 || issued != 0 || withdrawn != 0 || approved != 0 || redeemed != 0 )
{
item.push_back(Pair("available", ValueFromAmount(available)));
item.push_back(Pair("deposited", ValueFromAmount(deposited)));
item.push_back(Pair("issued", ValueFromAmount(issued)));
item.push_back(Pair("withdrawn", ValueFromAmount(withdrawn)));
item.push_back(Pair("approved", ValueFromAmount(approved)));
item.push_back(Pair("redeemed", ValueFromAmount(redeemed)));
obj.push_back(Pair(CURRENCIES[baseid],item));
a.push_back(obj);
}
}
}
ret.push_back(Pair("fiatstatus", a));
return ret;
}
UniValue paxprice(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if ( fHelp || params.size() > 4 || params.size() < 2 )
throw runtime_error("paxprice \"base\" \"rel\" height\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ); uint64_t basevolume=0,relvolume,seed;
std::string base = params[0].get_str();
std::string rel = params[1].get_str();
int32_t height;
if ( params.size() == 2 )
height = chainActive.LastTip()->GetHeight();
else height = atoi(params[2].get_str().c_str());
//if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 )
basevolume = 100000;
relvolume = hush_paxprice(&seed,height,(char *)base.c_str(),(char *)rel.c_str(),basevolume);
ret.push_back(Pair("base", base));
ret.push_back(Pair("rel", rel));
ret.push_back(Pair("height", height));
char seedstr[32];
sprintf(seedstr,"%llu",(long long)seed);
ret.push_back(Pair("seed", seedstr));
if ( height < 0 || height > chainActive.Height() )
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
else
{
CBlockIndex *pblockindex = chainActive[height];
if ( pblockindex != 0 )
ret.push_back(Pair("timestamp", (int64_t)pblockindex->nTime));
if ( basevolume != 0 && relvolume != 0 )
{
ret.push_back(Pair("price",((double)relvolume / (double)basevolume)));
ret.push_back(Pair("invprice",((double)basevolume / (double)relvolume)));
ret.push_back(Pair("basevolume",ValueFromAmount(basevolume)));
ret.push_back(Pair("relvolume",ValueFromAmount(relvolume)));
} else ret.push_back(Pair("error", "overflow or error in one or more of parameters"));
}
return ret;
}
UniValue gettxout(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if (fHelp || params.size() < 2 || params.size() > 3)

3
src/rpc/client.cpp

@ -154,9 +154,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "z_shieldcoinbase", 3},
{ "z_getoperationstatus", 0},
{ "z_getoperationresult", 0},
{ "paxprice", 4 },
{ "paxprices", 3 },
{ "paxpending", 0 },
{ "notaries", 2 },
{ "minerids", 1 },
{ "kvsearch", 1 },

3
src/rpc/server.cpp

@ -332,9 +332,6 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
{ "blockchain", "verifychain", &verifychain, true },
{ "blockchain", "getspentinfo", &getspentinfo, false },
//{ "blockchain", "paxprice", &paxprice, true },
//{ "blockchain", "paxpending", &paxpending, true },
//{ "blockchain", "paxprices", &paxprices, true },
{ "blockchain", "notaries", &notaries, true },
//{ "blockchain", "height_MoM", &height_MoM, true },
//{ "blockchain", "txMoMproof", &txMoMproof, true },

5
src/rpc/server.h

@ -502,10 +502,5 @@ extern UniValue notaries(const UniValue& params, bool fHelp, const CPubKey& mypk
extern UniValue minerids(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue kvsearch(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue paxprice(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue paxpending(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue paxprices(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue paxdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue paxwithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk);
#endif // HUSH_RPCSERVER_H

82
src/wallet/rpcwallet.cpp

@ -606,13 +606,11 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
#define HUSH_KVBINARY 2
#define HUSH_KVDURATION 1440
#define DRAGON_MAXSCRIPTSIZE 10001
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis);
int32_t hush_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen);
extern int32_t HUSH_PAX;
int32_t hush_is_issuer();
int32_t dragon_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t hush_isrealtime(int32_t *hushheightp);
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
int32_t hush_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t hush_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
uint64_t hush_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen);
@ -763,86 +761,6 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
return ret;
}
UniValue paxdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,puposhis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33];
bool fSubtractFeeFromAmount = false;
if ( HUSH_PAX == 0 )
{
throw runtime_error("paxdeposit disabled without -pax");
}
if ( hush_is_issuer() != 0 )
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KYC");
if (!EnsureWalletIsAvailable(fHelp))
throw runtime_error("paxdeposit needs wallet"); //return Value::null;
if (fHelp || params.size() != 3)
throw runtime_error("paxdeposit address fiatoshis base");
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
std::string base = params[2].get_str();
std::string dest;
height = chainActive.LastTip()->GetHeight();
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis )
{
fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis);
throw runtime_error("paxdeposit not enough available inventory");
}
puposhis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis);
dest.append(destaddr);
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey37[i]);
fprintf(stderr," ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) puposhis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)puposhis,(long long)seed);
EnsureWalletIsUnlocked();
CWalletTx wtx;
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = puposhis / 1000;
if ( fee < 10000 )
fee = 10000;
dragon_rwnum(1,&pubkey37[33],sizeof(height),&height);
opretlen = hush_opreturnscript(opretbuf,'D',pubkey37,37);
SendMoney(address.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,puposhis);
return wtx.GetHash().GetHex();
}
UniValue paxwithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
CWalletTx wtx; std::string dest; int32_t hushheight; uint64_t seed,puposhis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false;
if ( SMART_CHAIN_SYMBOL[0] == 0 )
return(0);
if (!EnsureWalletIsAvailable(fHelp))
return 0;
throw runtime_error("paxwithdraw deprecated");
if (fHelp || params.size() != 2)
throw runtime_error("paxwithdraw address fiatamount");
if ( hush_isrealtime(&hushheight) == 0 )
return(0);
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
puposhis = PAX_fiatdest(&seed,1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),hushheight,SMART_CHAIN_SYMBOL,fiatoshis);
dest.append(destaddr);
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
for (i=0; i<33; i++)
printf("%02x",pubkey37[i]);
printf(" hushheight.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) puposhis.%llu seed.%llx\n",hushheight,(char *)params[0].get_str().c_str(),SMART_CHAIN_SYMBOL,(long long)fiatoshis,destaddr,(long long)puposhis,(long long)seed);
EnsureWalletIsUnlocked();
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = fiatoshis / 1000;
if ( fee < 10000 )
fee = 10000;
dragon_rwnum(1,&pubkey37[33],sizeof(hushheight),&hushheight);
opretlen = hush_opreturnscript(opretbuf,'W',pubkey37,37);
SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,fiatoshis);
return wtx.GetHash().GetHex();
}
UniValue listaddressgroupings(const UniValue& params, bool fHelp, const CPubKey& mypk)
{

Loading…
Cancel
Save