From 1b3f15fef3c42379cd3955d1ea1216167cc5e38d Mon Sep 17 00:00:00 2001 From: exmac Date: Mon, 19 Mar 2018 19:27:31 +0100 Subject: [PATCH 001/115] Add yescryptR32 (#247) YescryptR32 for coin WAVI https://bitcointalk.org/index.php?topic=3146751.0 Tested on : https://lpool.name/pool/WAVI --- stratum/algos/yescrypt-opt.c | 3 +++ stratum/algos/yescrypt.c | 5 +++++ stratum/algos/yescrypt.h | 1 + stratum/config.sample/yescryptR32.conf | 15 +++++++++++++++ stratum/stratum.cpp | 1 + web/yaamp/core/functions/yaamp.php | 4 ++++ 6 files changed, 29 insertions(+) create mode 100644 stratum/config.sample/yescryptR32.conf diff --git a/stratum/algos/yescrypt-opt.c b/stratum/algos/yescrypt-opt.c index b65cdd2d0..c96190bab 100644 --- a/stratum/algos/yescrypt-opt.c +++ b/stratum/algos/yescrypt-opt.c @@ -942,6 +942,9 @@ yescrypt_kdf(const yescrypt_shared_t * shared, yescrypt_local_t * local, { HMAC_SHA256_CTX_Y ctx; HMAC_SHA256_Init_Y(&ctx, buf, buflen); + if (r == 32) { // yescryptR32 + HMAC_SHA256_Update_Y(&ctx, "WaviBanana", 10); + } else if (r == 16) { // yescryptR16 HMAC_SHA256_Update_Y(&ctx, "Client Key", 10); } diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index 9fac019ca..150174539 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -368,3 +368,8 @@ void yescryptR16_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32); } + +void yescryptR32_hash(const char *input, char *output, uint32_t len) +{ + yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 32, 1, (uint8_t*)output, 32); +} diff --git a/stratum/algos/yescrypt.h b/stratum/algos/yescrypt.h index f7dac4865..8e87c7bee 100644 --- a/stratum/algos/yescrypt.h +++ b/stratum/algos/yescrypt.h @@ -40,6 +40,7 @@ extern "C" { void yescrypt_hash(const char* input, char* output, uint32_t len); void yescryptR16_hash(const char* input, char* output, uint32_t len); +void yescryptR32_hash(const char* input, char* output, uint32_t len); /** * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): diff --git a/stratum/config.sample/yescryptR32.conf b/stratum/config.sample/yescryptR32.conf new file mode 100644 index 000000000..7494625ea --- /dev/null +++ b/stratum/config.sample/yescryptR32.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 6343 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = yescryptR32 +difficulty = 1 +max_ttf = 400000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 382a16515..0e8e5ba72 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -165,6 +165,7 @@ YAAMP_ALGO g_algos[] = {"skein2", skein2_hash, 1, 0, 0}, {"yescrypt", yescrypt_hash, 0x10000, 0, 0}, {"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 }, + {"yescryptR32", yescryptR32_hash, 0x10000, 0, 0 }, {"zr5", zr5_hash, 1, 0, 0}, {"a5a", a5a_hash, 0x10000, 0, 0}, diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 98e63cdc1..95d3e3257 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -58,6 +58,7 @@ function yaamp_get_algos() 'velvet', 'yescrypt', 'yescryptR16', + 'yescryptR32', 'whirlpool', 'zr5', ); @@ -113,6 +114,7 @@ function yaamp_get_algo_norm($algo) 'whirlpool' => 1.0, 'yescrypt' => 1.0, 'yescryptR16' => 1.0, + 'yescryptR32' => 1.0, 'zr5' => 1.0, ); @@ -178,6 +180,7 @@ function getAlgoColors($algo) 'whirlpool' => '#d0e0e0', 'yescrypt' => '#e0d0e0', 'yescryptR16' => '#e2d0e2', + 'yescryptR32' => '#e2d0d2', 'zr5' => '#d0b0d0', 'MN' => '#ffffff', // MasterNode Earnings @@ -244,6 +247,7 @@ function getAlgoPort($algo) 'velvet' => 6133, 'yescrypt' => 6233, 'yescryptR16' => 6333, + 'yescryptR32' => 6343, 'bastion' => 6433, 'hsr' => 7433, 'phi' => 8333, From e5dd766dd5de57044f1db11e6f1b8d334b235600 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Mar 2018 07:59:52 +0100 Subject: [PATCH 002/115] backend: avoid to clear earnings during payouts (#249) + simplify payment code based on RavenMinerPool commit --- web/yaamp/core/backend/payment.php | 6 ++++-- web/yaamp/modules/thread/CronjobController.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/backend/payment.php b/web/yaamp/core/backend/payment.php index 7a5eaa5cb..b3704ea95 100644 --- a/web/yaamp/core/backend/payment.php +++ b/web/yaamp/core/backend/payment.php @@ -171,17 +171,19 @@ function BackendCoinPayments($coin) if(!$user) continue; if(!isset($addresses[$user->username])) continue; + $payment_amount = bitcoinvaluetoa($addresses[$user->username]); + $payout = new db_payouts; $payout->account_id = $user->id; $payout->time = time(); - $payout->amount = bitcoinvaluetoa($user->balance*$coef); + $payout->amount = $payment_amount; $payout->fee = 0; $payout->idcoin = $coin->id; if ($payout->save()) { $payouts[$payout->id] = $user->id; - $user->balance = bitcoinvaluetoa(floatval($user->balance) - (floatval($user->balance)*$coef)); + $user->balance = bitcoinvaluetoa(floatval($user->balance) - $payment_amount); $user->save(); } } diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 4af398266..fc8a2a33d 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -57,8 +57,10 @@ public function actionRunBlocks() dborun("update jobs set active=false"); BackendBlockFind1(); - BackendClearEarnings(); - BackendRentingUpdate(); + if(!memcache_get($this->memcache->memcache, 'balances_locked')) { + BackendClearEarnings(); + BackendRentingUpdate(); + } BackendProcessList(); BackendBlocksUpdate(); @@ -209,10 +211,13 @@ public function actionRun() sleep(10); BackendDoBackup(); - memcache_set($this->memcache->memcache, 'apache_locked', false); + // prevent user balances changes during payments (blocks thread) + memcache_set($this->memcache->memcache, 'balances_locked', true); BackendPayments(); + memcache_set($this->memcache->memcache, 'balances_locked', false); + BackendCleanDatabase(); // BackendOptimizeTables(); From 9c438eeb946dc5a3f5ac60490458e76337d9be2f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Mar 2018 22:01:10 +0100 Subject: [PATCH 003/115] backend: protect also balances from renting clear + set an expiration to memcache lock, payment unlikely fails, but... --- web/yaamp/modules/thread/CronjobController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index fc8a2a33d..a05ebcdfe 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -59,8 +59,8 @@ public function actionRunBlocks() BackendBlockFind1(); if(!memcache_get($this->memcache->memcache, 'balances_locked')) { BackendClearEarnings(); - BackendRentingUpdate(); } + BackendRentingUpdate(); BackendProcessList(); BackendBlocksUpdate(); @@ -85,7 +85,7 @@ public function actionRunLoop2() MonitorBTC(); $last = memcache_get($this->memcache->memcache, 'last_renting_payout2'); - if($last + 5*60 < time()) + if($last + 5*60 < time() && !memcache_get($this->memcache->memcache, 'balances_locked')) { memcache_set($this->memcache->memcache, 'last_renting_payout2', time()); BackendRentingPayout(); @@ -214,7 +214,7 @@ public function actionRun() memcache_set($this->memcache->memcache, 'apache_locked', false); // prevent user balances changes during payments (blocks thread) - memcache_set($this->memcache->memcache, 'balances_locked', true); + memcache_set($this->memcache->memcache, 'balances_locked', true, 0, 300); BackendPayments(); memcache_set($this->memcache->memcache, 'balances_locked', false); From 2d0a2df4807bef32d42fcf45841a43941f98396e Mon Sep 17 00:00:00 2001 From: Tanariel Date: Sun, 25 Mar 2018 13:09:26 +0300 Subject: [PATCH 004/115] emulate getinfo for wallets who copy bitcoin mistakes (#250) like vertcoin 0.12... for sure its more efficient sigh --- .gitignore | 2 ++ web/yaamp/core/rpc/wallet-rpc.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 29a8aeb20..ee8ea0277 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ web/serverconfig.php web/assets/ *.rej *.orig +.idea/* +web/yaamp/.idea/ \ No newline at end of file diff --git a/web/yaamp/core/rpc/wallet-rpc.php b/web/yaamp/core/rpc/wallet-rpc.php index f5b77c4b8..70104fbc6 100644 --- a/web/yaamp/core/rpc/wallet-rpc.php +++ b/web/yaamp/core/rpc/wallet-rpc.php @@ -7,6 +7,7 @@ class WalletRPC { public $type = 'Bitcoin'; protected $rpc; protected $rpc_wallet; + protected $hasGetInfo = false; // cache protected $account; @@ -42,6 +43,7 @@ function __construct($userOrCoin, $pw='', $host='localhost', $port=8332, $url=nu default: $this->type = 'Bitcoin'; $this->rpc = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport, $url); + $this->hasGetInfo = $coin->hasgetinfo; } } else { @@ -377,7 +379,34 @@ function __call($method, $params) } // Bitcoin RPC - $res = $this->rpc->__call($method,$params); + switch ($method) { + case 'getinfo': + if ($this->hasGetInfo) { + $res = $this->rpc->__call($method,$params); + } else { + $miningInfo = $this->rpc->getmininginfo(); + $res["blocks"] = arraySafeVal($miningInfo,"blocks"); + $res["difficulty"] = arraySafeVal($miningInfo,"difficulty"); + $res["testnet"] = "main" != arraySafeVal($miningInfo,"chain"); + $walletInfo = $this->rpc->getwalletinfo(); + $res["walletversion"] = arraySafeVal($walletInfo,"walletversion"); + $res["balance"] = arraySafeVal($walletInfo,"balance"); + $res["keypoololdest"] = arraySafeVal($walletInfo,"keypoololdest"); + $res["keypoolsize"] = arraySafeVal($walletInfo,"keypoolsize"); + $res["paytxfee"] = arraySafeVal($walletInfo,"paytxfee"); + $networkInfo = $this->rpc->getnetworkinfo(); + $res["version"] = arraySafeVal($networkInfo,"version"); + $res["protocolversion"] = arraySafeVal($networkInfo,"protocolversion"); + $res["timeoffset"] = arraySafeVal($networkInfo,"timeoffset"); + $res["connections"] = arraySafeVal($networkInfo,"connections"); +// $res["proxy"] = arraySafeVal($networkInfo,"networks")[0]["proxy"]; + $res["relayfee"] = arraySafeVal($networkInfo,"relayfee"); + } + break; + default: + $res = $this->rpc->__call($method,$params); + } + $this->error = $this->rpc->error; return $res; } From 2ad138591e12e5ea8d95bd325e5b4af1afd7e3bf Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 26 Mar 2018 05:55:06 +0200 Subject: [PATCH 005/115] x12 algo + GCH multi-algos definition --- stratum/algos/makefile | 2 +- stratum/algos/x12.c | 85 +++++++++++++++++++++++++++++ stratum/algos/x12.h | 16 ++++++ stratum/config.sample/x12.conf | 16 ++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + web/yaamp/modules/explorer/util.php | 5 ++ 8 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/x12.c create mode 100644 stratum/algos/x12.h create mode 100644 stratum/config.sample/x12.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index b684b8716..e61b7dac7 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -9,7 +9,7 @@ CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ - blake.c scrypt.c c11.c x11.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ + blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ bitcore.c timetravel.c x16r.c xevan.c bastion.c hmq17.c \ diff --git a/stratum/algos/x12.c b/stratum/algos/x12.c new file mode 100644 index 000000000..07346a1a7 --- /dev/null +++ b/stratum/algos/x12.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void x12_hash(const char* input, char* output, uint32_t len) +{ + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_hamsi512_context ctx_hamsi; + + uint32_t hash[16]; + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, input, len); + sph_blake512_close(&ctx_blake, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, hash, 64); + sph_luffa512_close(&ctx_luffa, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, hash, 64); + sph_groestl512_close(&ctx_groestl, hash); + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, hash, 64); + sph_skein512_close(&ctx_skein, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, hash, 64); + sph_keccak512_close(&ctx_keccak, hash); + + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, hash, 64); + sph_hamsi512_close(&ctx_hamsi, hash); + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/x12.h b/stratum/algos/x12.h new file mode 100644 index 000000000..1b7ee985f --- /dev/null +++ b/stratum/algos/x12.h @@ -0,0 +1,16 @@ +#ifndef X12_H +#define X12_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void x12_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/x12.conf b/stratum/config.sample/x12.conf new file mode 100644 index 000000000..6bce44ac8 --- /dev/null +++ b/stratum/config.sample/x12.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3233 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = x12 +difficulty = 0.008 +max_ttf = 50000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 0e8e5ba72..f9757c07a 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -115,6 +115,7 @@ YAAMP_ALGO g_algos[] = {"c11", c11_hash, 1, 0, 0}, {"x11", x11_hash, 1, 0, 0}, + {"x12", x12_hash, 1, 0, 0}, {"x13", x13_hash, 1, 0, 0}, {"x14", x14_hash, 1, 0, 0}, {"x15", x15_hash, 1, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index cb9f9dd34..d24494848 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -150,6 +150,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/c11.h" #include "algos/x11.h" #include "algos/x11evo.h" +#include "algos/x12.h" #include "algos/x13.h" #include "algos/x14.h" #include "algos/x15.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 95d3e3257..b1f23f9d5 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -35,6 +35,7 @@ function yaamp_get_algos() 'c11', 'x11', 'x11evo', + 'x12', 'x13', 'x14', 'x15', @@ -137,6 +138,7 @@ function getAlgoColors($algo) 'deep' => '#e0ffff', 'x11' => '#f0f0a0', 'x11evo' => '#c0f0c0', + 'x12' => '#ffe090', 'x13' => '#ffd880', 'x14' => '#f0c080', 'x15' => '#f0b080', @@ -206,6 +208,7 @@ function getAlgoPort($algo) 'deep' => 3535, 'x11' => 3533, 'x11evo' => 3553, + 'x12' => 3233, 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index fb66eaf27..172a7e4dc 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -165,6 +165,9 @@ function versionToAlgo($coin, $version) 7 =>'nist5', 8 =>'myr-gr', 9=>'penta', 10=>'whirlpool', 11=>'luffa', 12=>'keccak', 13=>'quark', 15=>'bastion' ); + $algos['GCH'] = array( + 0=>'x12', 1=>'x11', 2=>'x13', 3=>'sha256', 4=>'blake2s' + ); $algos['RICHX'] = array( 0=>'sha256', 1=>'scrypt', 2=>'myr-gr', 3=>'skein', 4=>'qubit' ); @@ -182,6 +185,8 @@ function versionToAlgo($coin, $version) if ($symbol == 'J') return arraySafeVal($algos[$symbol], $version, ''); + else if($symbol == 'GCH') + return arraySafeVal($algos[$symbol], ($version - 9), ''); else if($symbol == 'XVG') return arraySafeVal($algos[$symbol], ($version >> 11), 'scrypt'); else if (isset($algos[$symbol])) From 20de9ab7747a89d2ff0f258990829cb3b918296f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 26 Mar 2018 10:27:07 +0200 Subject: [PATCH 006/115] markets: handle cryptohub api, but only manually their api is not complete enough to auto create the markets... --- web/yaamp/core/backend/markets.php | 43 +++++++++++++++++ web/yaamp/core/exchange/cryptohub.php | 68 +++++++++++++++++++++++++++ web/yaamp/core/exchange/exchange.php | 3 ++ 3 files changed, 114 insertions(+) create mode 100644 web/yaamp/core/exchange/cryptohub.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 2db5e0549..e044c7694 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -23,6 +23,7 @@ function BackendPricesUpdate() updateAlcurexMarkets(); updateBinanceMarkets(); updateBterMarkets(); + updateCryptohubMarkets(); //updateEmpoexMarkets(); updateJubiMarkets(); updateLiveCoinMarkets(); @@ -1165,6 +1166,48 @@ function updateBterMarkets() } } +function updateCryptohubMarkets() +{ + $exchange = 'cryptohub'; + if (exchange_get($exchange, 'disabled')) return; + + $markets = cryptohub_api_query('market/ticker'); + if(!is_array($markets)) return; + + $list = getdbolist('db_markets', "name='$exchange'"); + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $dbpair = 'BTC'.'_'.$symbol; + foreach ($markets as $pair => $ticker) { + if ($pair != $dbpair) continue; + $price2 = ($ticker['highestBid']+$ticker['lowestAsk'])/2; + $market->price = AverageIncrement($market->price, $ticker['highestBid']); + $market->price2 = AverageIncrement($market->price2, $price2); + $market->pricetime = time(); + //if ($market->disabled < 9) $market->disabled = (floatval($ticker['baseVolume']) < 0.01); + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->market = $exchange; + $coin->save(); + } + } + } +} + function updateEmpoexMarkets() { $exchange = 'empoex'; diff --git a/web/yaamp/core/exchange/cryptohub.php b/web/yaamp/core/exchange/cryptohub.php new file mode 100644 index 000000000..611172474 --- /dev/null +++ b/web/yaamp/core/exchange/cryptohub.php @@ -0,0 +1,68 @@ +$symbol)); + if(!$coin) return false; + $pair = $symbol; + $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'"); + if(!$market) return false; + + } else if (is_object($market)) { + + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) return false; + $symbol = $coin->getOfficialSymbol(); + $pair = $symbol; + if (!empty($market->base_coin)) $pair = $market->base_coin.'_'.$symbol; + } + + $t1 = microtime(true); + $ticker = cryptohub_api_query("market/ticker",$pair); + if(!$ticker || empty($ticker)) return false; + $ticker = array_pop($ticker); + if(arraySafeVal($ticker,'highestBid') === NULL) { + debuglog("$exchange: invalid data received for $pair ticker"); + return false; + } + + $price2 = ((double) $ticker['highestBid'] + $ticker['lowestAsk']) / 2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, (double) $ticker['highestBid']); + if ($ticker['lowestAsk'] < $market->price) $market->price = $ticker['lowestAsk']; + $market->pricetime = time(); + $market->save(); + + $apims = round((microtime(true) - $t1)*1000,3); + user()->setFlash('message', "$exchange $symbol price updated in $apims ms"); + + return true; +} diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index fc2a983dc..d9b67dcc1 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -19,6 +19,7 @@ function strip_data($data) require_once("ccexapi.php"); require_once("cexio.php"); require_once("cryptobridge.php"); +require_once("cryptohub.php"); require_once("kraken.php"); require_once("poloniex.php"); require_once("yobit.php"); @@ -93,6 +94,8 @@ function getMarketUrl($coin, $marketName) $url = "https://coinsmarkets.com/trade-{$base}-{$symbol}.htm"; else if($market == 'cryptobridge') $url = "https://wallet.crypto-bridge.org/market/BRIDGE.{$symbol}_BRIDGE.{$base}"; + else if($market == 'cryptohub') + $url = "https://cryptohub.online/market/{$symbol}/{$base}"; else if($market == 'cryptopia') $url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_{$base}"; else if($market == 'cryptowatch') From afa2e929a2e6bd59047131717a177babed128416 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 27 Mar 2018 01:46:57 +0200 Subject: [PATCH 007/115] markets: avoid useless api queries if exchange is not used --- web/yaamp/core/backend/markets.php | 74 ++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index e044c7694..64adb5d82 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -221,6 +221,9 @@ function updateBleutradeMarkets() $exchange = 'bleutrade'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = bleutrade_api_query('public/getcurrencies'); if(!is_object($list)) return; @@ -288,6 +291,10 @@ function updateBleutradeMarkets() function updateCryptoBridgeMarkets($force = false) { $exchange = 'cryptobridge'; + if (exchange_get($exchange, 'disabled')) return; + + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; $result = cryptobridge_api_query('ticker'); if(!is_array($result)) return; @@ -330,6 +337,9 @@ function updateKrakenMarkets($force = false) $exchange = 'kraken'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $result = kraken_api_query('AssetPairs'); if(!is_array($result)) return; @@ -394,6 +404,9 @@ function updateBittrexMarkets($force = false) $exchange = 'bittrex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = bittrex_api_query('public/getcurrencies'); if(!is_object($list)) return; foreach($list->result as $currency) @@ -474,6 +487,9 @@ function updateCCexMarkets() $exchange = 'c-cex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $ccex = new CcexAPI; $list = $ccex->getMarketSummaries(); if (!is_array($list)) return; @@ -561,6 +577,9 @@ function updatePoloniexMarkets() $exchange = 'poloniex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $poloniex = new poloniex; $tickers = $poloniex->get_ticker(); @@ -646,6 +665,9 @@ function updateYobitMarkets() $exchange = 'yobit'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $res = yobit_api_query('info'); if(!is_object($res)) return; @@ -731,10 +753,12 @@ function updateJubiMarkets() $exchange = 'jubi'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $btc = jubi_api_query('ticker', "?coin=btc"); if(!is_object($btc)) return; - $list = getdbolist('db_markets', "name='jubi'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -776,10 +800,12 @@ function updateAlcurexMarkets() $exchange = 'alcurex'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $data = alcurex_api_query('market', "?info=on"); if(!is_object($data)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -828,10 +854,12 @@ function updateCryptopiaMarkets() $exchange = 'cryptopia'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $data = cryptopia_api_query('GetMarkets', 24); if(!is_object($data)) return; - $list = getdbolist('db_markets', "name LIKE('$exchange%')"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1088,10 +1116,12 @@ function updateBinanceMarkets() $exchange = 'binance'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $tickers = binance_api_query('ticker/allBookTickers'); if(!is_array($tickers)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1130,10 +1160,12 @@ function updateBterMarkets() $exchange = 'bter'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = bter_api_query('tickers'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1171,10 +1203,12 @@ function updateCryptohubMarkets() $exchange = 'cryptohub'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = cryptohub_api_query('market/ticker'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1213,10 +1247,12 @@ function updateEmpoexMarkets() $exchange = 'empoex'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = empoex_api_query('marketinfo'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1257,6 +1293,9 @@ function updateKuCoinMarkets() $exchange = 'kucoin'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = kucoin_api_query('open/symbols','market=BTC'); if(!kucoin_result_valid($markets) || empty($markets->data)) return; @@ -1265,7 +1304,6 @@ function updateKuCoinMarkets() $coininfo = NULL; } - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1314,10 +1352,12 @@ function updateLiveCoinMarkets() $exchange = 'livecoin'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = livecoin_api_query('exchange/ticker'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1383,6 +1423,9 @@ function updateCoinExchangeMarkets() $exchange = 'coinexchange'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = coinexchange_api_query('getmarkets'); if(!is_object($list)) return; $markets = coinexchange_api_query('getmarketsummaries'); @@ -1454,6 +1497,9 @@ function updateCoinsMarketsMarkets() $exchange = 'coinsmarkets'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = coinsmarkets_api_query('apicoin'); if(empty($list) || !is_array($list)) return; foreach($list as $pair=>$data) @@ -1511,6 +1557,9 @@ function updateStocksExchangeMarkets() $exchange = 'stocksexchange'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = stocksexchange_api_query('ticker'); if(empty($list) || !is_array($list)) return; foreach($list as $m) @@ -1558,6 +1607,9 @@ function updateTradeSatoshiMarkets() $exchange = 'tradesatoshi'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $data = tradesatoshi_api_query('getmarketsummaries'); if(!is_object($data) || !$data->success || !is_array($data->result)) return; foreach($data->result as $m) @@ -1605,10 +1657,12 @@ function updateShapeShiftMarkets() $exchange = 'shapeshift'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = shapeshift_api_query('marketinfo'); if(!is_array($markets) || empty($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); From a954c13b36a85b642274e7de62e020cea884ebb6 Mon Sep 17 00:00:00 2001 From: opensourcerulez Date: Thu, 29 Mar 2018 03:49:37 +0300 Subject: [PATCH 008/115] x16s algo, shuffle variant (#251) see https://bitcointalk.org/?topic=3208091.0 for more explanations --- stratum/algos/makefile | 2 +- stratum/algos/x16s.c | 180 +++++++++++++++++++++++++++++ stratum/algos/x16s.h | 16 +++ stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 5 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/x16s.c create mode 100644 stratum/algos/x16s.h diff --git a/stratum/algos/makefile b/stratum/algos/makefile index e61b7dac7..815c7eb1e 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -12,7 +12,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ - bitcore.c timetravel.c x16r.c xevan.c bastion.c hmq17.c \ + bitcore.c timetravel.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ blake2.c \ yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ diff --git a/stratum/algos/x16s.c b/stratum/algos/x16s.c new file mode 100644 index 000000000..6247b6981 --- /dev/null +++ b/stratum/algos/x16s.c @@ -0,0 +1,180 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +enum Algo { + BLAKE = 0, + BMW, + GROESTL, + JH, + KECCAK, + SKEIN, + LUFFA, + CUBEHASH, + SHAVITE, + SIMD, + ECHO, + HAMSI, + FUGUE, + SHABAL, + WHIRLPOOL, + SHA512, + HASH_FUNC_COUNT +}; + +static void getAlgoString(const uint8_t* prevblock, char *output) +{ + strcpy(output, "0123456789ABCDEF"); + + for(int i = 0; i < 16; i++){ + uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed + uint8_t algoDigit = (i & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; + + int offset = algoDigit; + // insert the nth character at the front + char oldVal = output[offset]; + for(int j=offset; j-->0;) { + output[j+1] = output[j]; + } + output[0] = oldVal; + } +} + +void x16s_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hash[64/4]; + char hashOrder[HASH_FUNC_COUNT + 1] = { 0 }; + + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_hamsi512_context ctx_hamsi; + sph_fugue512_context ctx_fugue; + sph_shabal512_context ctx_shabal; + sph_whirlpool_context ctx_whirlpool; + sph_sha512_context ctx_sha512; + + void *in = (void*) input; + int size = len; + + getAlgoString(&input[4], hashOrder); + + for (int i = 0; i < 16; i++) + { + const char elem = hashOrder[i]; + const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; + + switch (algo) { + case BLAKE: + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, in, size); + sph_blake512_close(&ctx_blake, hash); + break; + case BMW: + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, in, size); + sph_bmw512_close(&ctx_bmw, hash); + break; + case GROESTL: + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, in, size); + sph_groestl512_close(&ctx_groestl, hash); + break; + case SKEIN: + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, in, size); + sph_skein512_close(&ctx_skein, hash); + break; + case JH: + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, in, size); + sph_jh512_close(&ctx_jh, hash); + break; + case KECCAK: + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, in, size); + sph_keccak512_close(&ctx_keccak, hash); + break; + case LUFFA: + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, in, size); + sph_luffa512_close(&ctx_luffa, hash); + break; + case CUBEHASH: + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, in, size); + sph_cubehash512_close(&ctx_cubehash, hash); + break; + case SHAVITE: + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, in, size); + sph_shavite512_close(&ctx_shavite, hash); + break; + case SIMD: + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, in, size); + sph_simd512_close(&ctx_simd, hash); + break; + case ECHO: + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, in, size); + sph_echo512_close(&ctx_echo, hash); + break; + case HAMSI: + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, in, size); + sph_hamsi512_close(&ctx_hamsi, hash); + break; + case FUGUE: + sph_fugue512_init(&ctx_fugue); + sph_fugue512(&ctx_fugue, in, size); + sph_fugue512_close(&ctx_fugue, hash); + break; + case SHABAL: + sph_shabal512_init(&ctx_shabal); + sph_shabal512(&ctx_shabal, in, size); + sph_shabal512_close(&ctx_shabal, hash); + break; + case WHIRLPOOL: + sph_whirlpool_init(&ctx_whirlpool); + sph_whirlpool(&ctx_whirlpool, in, size); + sph_whirlpool_close(&ctx_whirlpool, hash); + break; + case SHA512: + sph_sha512_init(&ctx_sha512); + sph_sha512(&ctx_sha512,(const void*) in, size); + sph_sha512_close(&ctx_sha512,(void*) hash); + break; + } + in = (void*) hash; + size = 64; + } + memcpy(output, hash, 32); +} diff --git a/stratum/algos/x16s.h b/stratum/algos/x16s.h new file mode 100644 index 000000000..ec9201c57 --- /dev/null +++ b/stratum/algos/x16s.h @@ -0,0 +1,16 @@ +#ifndef X16S_H +#define X16S_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void x16s_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/stratum.h b/stratum/stratum.h index d24494848..d8638fb70 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -155,6 +155,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/x14.h" #include "algos/x15.h" #include "algos/x16r.h" +#include "algos/x16s.h" #include "algos/x17.h" #include "algos/xevan.h" #include "algos/hmq17.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index b1f23f9d5..f2e855f28 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -40,6 +40,7 @@ function yaamp_get_algos() 'x14', 'x15', 'x16r', + 'x16s', 'x17', 'xevan', 'groestl', // dmd-gr -m 256 (deprecated) @@ -143,6 +144,7 @@ function getAlgoColors($algo) 'x14' => '#f0c080', 'x15' => '#f0b080', 'x16r' => '#f0b080', + 'x16s' => '#f0b080', 'x17' => '#f0b0a0', 'xevan' => '#f0b0a0', 'argon2' => '#e0d0e0', @@ -212,6 +214,7 @@ function getAlgoPort($algo) 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, + 'x16s' => 3666, 'x17' => 3737, 'xevan' => 3739, 'hmq1725' => 3747, From 5bb898f651939a6c8a4fff8fc589ef7ca2f8846e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 29 Mar 2018 02:53:55 +0200 Subject: [PATCH 009/115] small x16s fixes, and stratum sample --- stratum/algos/x16s.c | 2 +- stratum/config.sample/x16s.conf | 16 ++++++++++++++++ stratum/stratum.cpp | 1 + web/yaamp/core/functions/yaamp.php | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 stratum/config.sample/x16s.conf diff --git a/stratum/algos/x16s.c b/stratum/algos/x16s.c index 6247b6981..d3f329136 100644 --- a/stratum/algos/x16s.c +++ b/stratum/algos/x16s.c @@ -43,7 +43,7 @@ enum Algo { static void getAlgoString(const uint8_t* prevblock, char *output) { - strcpy(output, "0123456789ABCDEF"); + strcpy(output, "0123456789ABCDEF"); for(int i = 0; i < 16; i++){ uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed diff --git a/stratum/config.sample/x16s.conf b/stratum/config.sample/x16s.conf new file mode 100644 index 000000000..d71d25ec7 --- /dev/null +++ b/stratum/config.sample/x16s.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3663 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = x16s +difficulty = 0.25 +max_ttf = 50000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index f9757c07a..65a14deb4 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -125,6 +125,7 @@ YAAMP_ALGO g_algos[] = {"xevan", xevan_hash, 0x100, 0, 0}, {"x16r", x16r_hash, 0x100, 0, 0}, + {"x16s", x16s_hash, 0x100, 0, 0}, {"timetravel", timetravel_hash, 0x100, 0, 0}, {"bitcore", timetravel10_hash, 0x100, 0, 0}, {"hsr", hsr_hash, 1, 0, 0}, diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index f2e855f28..896ea767a 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -214,7 +214,7 @@ function getAlgoPort($algo) 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, - 'x16s' => 3666, + 'x16s' => 3663, 'x17' => 3737, 'xevan' => 3739, 'hmq1725' => 3747, From 31441a6c98889574bbb6260909c18af22f9d6100 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Sat, 31 Mar 2018 23:01:17 -0400 Subject: [PATCH 010/115] markets: handle graviex ticker (#252) manual only, so market row need to be created manually if really required. --- web/yaamp/core/backend/markets.php | 47 ++++++++++++++++++++++++++++ web/yaamp/core/exchange/exchange.php | 3 ++ web/yaamp/core/exchange/graviex.php | 23 ++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 web/yaamp/core/exchange/graviex.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 64adb5d82..b88227292 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -14,6 +14,7 @@ function BackendPricesUpdate() updatePoloniexMarkets(); updateBleutradeMarkets(); updateCryptoBridgeMarkets(); + updateGraviexMarkets(); updateKrakenMarkets(); updateKuCoinMarkets(); updateCCexMarkets(); @@ -332,6 +333,52 @@ function updateCryptoBridgeMarkets($force = false) ///////////////////////////////////////////////////////////////////////////////////////////// +function updateGraviexMarkets($force = false) +{ + $exchange = 'graviex'; + if (exchange_get($exchange, 'disabled')) return; + + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + + $markets = graviex_api_query('tickers'); + if(!is_array($markets)) return; + + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $symbol = strtolower($symbol); + $dbpair = $symbol.'btc'; + foreach ($markets as $pair => $ticker) { + if ($pair != $dbpair) continue; + $price2 = ($ticker['ticker']['high']+$ticker['ticker']['low'])/2; + $market->price = AverageIncrement($market->price, $ticker['ticker']['high']); + $market->price2 = AverageIncrement($market->price2, $price2); + $market->pricetime = time(); + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->market = $exchange; + $coin->save(); + } + } + } +} + +///////////////////////////////////////////////////////////////////////////////////////////// + function updateKrakenMarkets($force = false) { $exchange = 'kraken'; diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index d9b67dcc1..1684cfcef 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -19,6 +19,7 @@ function strip_data($data) require_once("ccexapi.php"); require_once("cexio.php"); require_once("cryptobridge.php"); +require_once("graviex.php"); require_once("cryptohub.php"); require_once("kraken.php"); require_once("poloniex.php"); @@ -104,6 +105,8 @@ function getMarketUrl($coin, $marketName) $url = "https://c-cex.com/?p={$lowsymbol}-{$lowbase}"; else if($market == 'empoex') $url = "http://www.empoex.com/trade/{$symbol}-{$base}"; + else if($market == 'graviex') + $url = "https://graviex.net/api/v2/tickers/{$symbol}{$base}"; else if($market == 'jubi') $url = "http://jubi.com/coin/{$lowsymbol}"; else if($market == 'hitbtc') diff --git a/web/yaamp/core/exchange/graviex.php b/web/yaamp/core/exchange/graviex.php new file mode 100644 index 000000000..befffda19 --- /dev/null +++ b/web/yaamp/core/exchange/graviex.php @@ -0,0 +1,23 @@ + Date: Tue, 3 Apr 2018 11:49:30 +0200 Subject: [PATCH 011/115] trading: auto set bittrex and bleutrade withdraw tx fee --- web/yaamp/core/backend/rawcoins.php | 18 ++++++++++++++---- web/yaamp/core/trading/bittrex_trading.php | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 067d0defc..1f6c5faf5 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -22,21 +22,31 @@ function updateRawcoins() if (!exchange_get('bittrex', 'disabled')) { $list = bittrex_api_query('public/getcurrencies'); - if(isset($list->result)) + if(isset($list->result) && !empty($list->result)) { dborun("UPDATE markets SET deleted=true WHERE name='bittrex'"); - foreach($list->result as $currency) + foreach($list->result as $currency) { + if ($currency->Currency == 'BTC') { + exchange_set('bittrex', 'withdraw_fee_btc', $currency->TxFee); + continue; + } updateRawCoin('bittrex', $currency->Currency, $currency->CurrencyLong); + } } } if (!exchange_get('bleutrade', 'disabled')) { $list = bleutrade_api_query('public/getcurrencies'); - if(isset($list->result)) + if(isset($list->result) && !empty($list->result)) { dborun("UPDATE markets SET deleted=true WHERE name='bleutrade'"); - foreach($list->result as $currency) + foreach($list->result as $currency) { + if ($currency->Currency == 'BTC') { + exchange_set('bleutrade', 'withdraw_fee_btc', $currency->TxFee); + continue; + } updateRawCoin('bleutrade', $currency->Currency, $currency->CurrencyLong); + } } } diff --git a/web/yaamp/core/trading/bittrex_trading.php b/web/yaamp/core/trading/bittrex_trading.php index 8f67ceca3..2ce73f223 100644 --- a/web/yaamp/core/trading/bittrex_trading.php +++ b/web/yaamp/core/trading/bittrex_trading.php @@ -236,7 +236,7 @@ function doBittrexTrading($quick=false) } $withdraw_min = exchange_get($exchange, 'withdraw_min_btc', EXCH_AUTO_WITHDRAW); - $withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.001); + $withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.0005); if($withdraw_min > 0 && $savebalance->balance >= ($withdraw_min + $withdraw_fee)) { // $btcaddr = exchange_get($exchange, 'withdraw_btc_address', YAAMP_BTCADDRESS); From 580801f3991b35fd533d988bb73ec34e29e434f7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 10:05:53 +0200 Subject: [PATCH 012/115] benchs: unique function to format devices labels + some new devices chips rules --- web/yaamp/core/backend/bench.php | 9 +++++++++ web/yaamp/modules/bench/devices.php | 6 +----- web/yaamp/modules/bench/functions.php | 16 ++++++++++++++++ web/yaamp/modules/bench/index.php | 12 +++++------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/web/yaamp/core/backend/bench.php b/web/yaamp/core/backend/bench.php index dce1e7cad..54e4627c6 100644 --- a/web/yaamp/core/backend/bench.php +++ b/web/yaamp/core/backend/bench.php @@ -17,6 +17,8 @@ function BenchUpdateChips() // bug in nvml 378.x and 381.x (linux + win) fixed in 382.05 dborun("UPDATE benchmarks SET realfreq=NULL WHERE realfreq<=200 AND driver LIKE '% 378.%'"); dborun("UPDATE benchmarks SET realfreq=NULL WHERE realfreq<=200 AND driver LIKE '% 381.%'"); + // sanity check on long fields (no html wanted) + dborun("DELETE FROM benchmarks WHERE device LIKE '%<%' OR client LIKE '%<%'"); $benchs = getdbolist('db_benchmarks', "IFNULL(chip,'')=''"); foreach ($benchs as $bench) { @@ -27,6 +29,13 @@ function BenchUpdateChips() continue; } + $rawdata = json_encode($bench->attributes); + if (strpos($rawdata,"script")) { + debuglog("bench record deleted : $rawdata"); + $bench->delete(); + continue; + } + $dups = getdbocount('db_benchmarks', "vendorid=:vid AND client=:client AND os=:os AND driver=:drv AND throughput=:thr AND userid=:uid", array(':vid'=>$bench->vendorid, ':client'=>$bench->client, ':os'=>$bench->os, ':drv'=>$bench->driver,':thr'=>$bench->throughput,':uid'=>$bench->userid) ); diff --git a/web/yaamp/modules/bench/devices.php b/web/yaamp/modules/bench/devices.php index 5bc76d3f8..68174eee1 100644 --- a/web/yaamp/modules/bench/devices.php +++ b/web/yaamp/modules/bench/devices.php @@ -105,11 +105,7 @@ $chip = CHtml::link($chip, '/bench?chip='.$row['idchip'].'&algo=all'); } echo ''.$chip.''; - - if ($row['type'] == 'gpu') - echo ''.$row['device'].getProductIdSuffix($row).''; - else - echo ''.formatCPU($row).''; + echo ''.formatDevice($row).''; if (substr($vendorid,0,4) == '10de') echo ''.$vendorid.''; diff --git a/web/yaamp/modules/bench/functions.php b/web/yaamp/modules/bench/functions.php index 9e67a9583..84b3e45ea 100644 --- a/web/yaamp/modules/bench/functions.php +++ b/web/yaamp/modules/bench/functions.php @@ -140,6 +140,20 @@ function formatCPU($row) return trim($device); } +function formatGPU($row) +{ + $label = $row['device'].getProductIdSuffix($row); + return strip_tags($label); +} + +function formatDevice($row) +{ + if ($row['type'] == 'gpu') + return formatGPU($row); + else + return formatCPU($row); +} + function getChipName($row) { if ($row['type'] == 'cpu') { @@ -179,6 +193,8 @@ function getChipName($row) $chip = str_replace('650 Ti BOOST','650 Ti', $chip); $chip = str_replace('760 Ti OEM','760 Ti', $chip); $chip = str_replace(' (Pascal)',' Pascal', $chip); + $chip = str_replace('Quadro M6000 24GB','Quadro M6000', $chip); + $chip = str_replace('Tesla P100 (PCIe)','Tesla P100', $chip); $chip = str_replace('Tesla P100-SXM2-16GB','Tesla P100', $chip); $chip = str_replace('Tesla P100-PCIE-16GB','Tesla P100', $chip); $chip = str_replace('Tesla V100-SXM2-16GB','Tesla V100', $chip); diff --git a/web/yaamp/modules/bench/index.php b/web/yaamp/modules/bench/index.php index f45cd6e92..1546dfce7 100644 --- a/web/yaamp/modules/bench/index.php +++ b/web/yaamp/modules/bench/index.php @@ -144,14 +144,12 @@ echo ''.CHtml::link($row['algo'],'/bench?algo='.$row['algo']).''; echo ''.$age.''; echo ''.($row['idchip'] ? CHtml::link($row['chip'],'/bench?chip='.$row['idchip']) : $row['chip']).''; - if ($row['type'] == 'cpu') { - echo ''.formatCPU($row).''; - echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; - echo ''.$row['arch'].''; - } else { - echo ''.$row['device'].getProductIdSuffix($row).''; - echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; + echo ''.formatDevice($row).''; + echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; + if ($row['type'] == 'gpu') { echo ''.formatCudaArch($row['arch']).''; + } else { + echo ''.$row['arch'].''; } echo ''.$hashrate.''; From 60fb627ad909fbef7ede75613567099c622108b3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 11:03:01 +0200 Subject: [PATCH 013/115] security: be more strict with algo param --- web/yaamp/core/common/util.php | 6 ++++++ web/yaamp/modules/site/SiteController.php | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/yaamp/core/common/util.php b/web/yaamp/core/common/util.php index d49403531..6bc646274 100644 --- a/web/yaamp/core/common/util.php +++ b/web/yaamp/core/common/util.php @@ -54,6 +54,12 @@ function getiparam($p,$default=0) return isset($_REQUEST[$p]) ? intval($_REQUEST[$p]) : $default; } +function getalgoparam() +{ + $algo = strip_tags(substr(getparam('algo'), 0, 32)); + return $algo; +} + ////////////////////////////////////////////////////// function downloadFile($url, &$size) diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index e4c265d30..80cf6a54c 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -1077,7 +1077,7 @@ public function actionClearorder() $this->goback(); } - public function actionCancelorder() + public function actionCancelorder() { if(!$this->admin) return; $order = getdbo('db_orders', getiparam('id')); @@ -1091,7 +1091,7 @@ public function actionCancelorder() public function actionAlgo() { - $algo = substr(getparam('algo'), 0, 32); + $algo = getalgoparam(); $a = getdbosql('db_algos', "name=:name", array(':name'=>$algo)); if($a) @@ -1108,7 +1108,7 @@ public function actionAlgo() public function actionGomining() { - $algo = substr(getparam('algo'), 0, 32); + $algo = getalgoparam(); if ($algo == 'all') { return; } From e97ea63c61755d0823d80f8ca6802d81f0577a6e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 11:22:14 +0200 Subject: [PATCH 014/115] security: protect XSS seekers from their own hacks --- web/yaamp/modules/renting/login.php | 3 +++ web/yaamp/modules/site/wallet.php | 4 ++++ web/yaamp/modules/trading/index.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/web/yaamp/modules/renting/login.php b/web/yaamp/modules/renting/login.php index 5f4cc6d86..e7ad453a4 100644 --- a/web/yaamp/modules/renting/login.php +++ b/web/yaamp/modules/renting/login.php @@ -13,6 +13,9 @@ $address = getparam('address'); if($address == 0) $address = ''; +if (!empty($address) && preg_match('/[^A-Za-z0-9]/', $address)) { + die; +} echo <<getState('yaamp-wallet'); +if (!empty($wallet) && preg_match('/[^A-Za-z0-9]/', $wallet)) { + die; +} $user = getuserparam($wallet); $algo_unit = 'Mh'; From 5b91a559f9d14e2e7218a7a1121f2c90442dac30 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 15:47:48 +0200 Subject: [PATCH 015/115] stratum: do more checks on stats device names --- stratum/db.cpp | 15 ++++++++++++++- web/yaamp/core/functions/yaamp.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index 3b3441542..f8c513cd8 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -55,6 +55,19 @@ char *db_clean_string(YAAMP_DB *db, char *string) return string; } +// allow more chars without the most hurting ones (bench device names) +static void clean_html(char* string) +{ + char *c = string; + size_t i, len = strlen(string) & 0x1FF; + for (i = 0; i < len; i++) { + if (c[i] == '<' || c[i] == '>' || c[i] == '%' || c[i] == '\\' || c[i] == '"' || c[i] == '\'') { + c[i] = '\0'; break; + } + } + if (strstr(string, "script")) strcpy(string, ""); +} + void db_query(YAAMP_DB *db, const char *format, ...) { va_list arglist; @@ -536,7 +549,7 @@ static void _json_str_safe(YAAMP_DB *db, json_value *json, const char *key, size char escaped[256] = { 0 }; snprintf(str, sizeof(str)-1, "%s", json_string_value(val)); str[maxlen-1] = '\0'; // truncate to dest len - //db_clean_string(db, str); + clean_html(str); mysql_real_escape_string(&db->mysql, escaped, str, strlen(str)); snprintf(out, maxlen, "%s", escaped); out[maxlen-1] = '\0'; diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 896ea767a..0a9d6911f 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -278,7 +278,7 @@ function getAlgoPort($algo) function yaamp_fee($algo) { $fee = controller()->memcache->get("yaamp_fee-$algo"); - if($fee) return $fee; + if($fee && is_numeric($fee)) return (float) $fee; /* $norm = yaamp_get_algo_norm($algo); if($norm == 0) $norm = 1; From e6a731cf19fd74fef76f9f44577eb7e161f003e2 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 11 Apr 2018 10:52:57 -0300 Subject: [PATCH 016/115] explorer: add multi-algo support for ARG explorer (#254) --- web/yaamp/modules/explorer/util.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index 172a7e4dc..39ce81fb0 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -180,6 +180,9 @@ function versionToAlgo($coin, $version) $algos['XVG'] = array( 0=>'scrypt', 1=>'scrypt', 2=>'myr-gr', 3=>'x17', 4=>'blake2s', 10=>'lyra2v2', ); + $algos['ARG'] = array( + 0=>'sha256', 1=>'scrypt', 2=>'lyra2v2', 3=>'myr-gr', 4=>'argon2d', 5=>'yescrypt', + ); $symbol = $coin->symbol; if (!empty($coin->symbol2)) $symbol = $coin->symbol2; From ea59f8a53b926f234b7c0f78d9dcb4b8a89d4fcc Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Thu, 19 Apr 2018 04:20:20 -0400 Subject: [PATCH 017/115] Fix graviex market url (#257) --- web/yaamp/core/exchange/exchange.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index 1684cfcef..6dd88c50f 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -106,7 +106,7 @@ function getMarketUrl($coin, $marketName) else if($market == 'empoex') $url = "http://www.empoex.com/trade/{$symbol}-{$base}"; else if($market == 'graviex') - $url = "https://graviex.net/api/v2/tickers/{$symbol}{$base}"; + $url = "https://graviex.net/markets/{$lowsymbol}{$lowbase}"; else if($market == 'jubi') $url = "http://jubi.com/coin/{$lowsymbol}"; else if($market == 'hitbtc') From 99f1fa9ac05e37bc5139a8f4ac47943c87489d3c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 20 Apr 2018 08:48:02 +0200 Subject: [PATCH 018/115] graviex: use the right ticker bid/ask fields --- web/yaamp/core/backend/markets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index b88227292..7541bcea4 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -361,8 +361,8 @@ function updateGraviexMarkets($force = false) $dbpair = $symbol.'btc'; foreach ($markets as $pair => $ticker) { if ($pair != $dbpair) continue; - $price2 = ($ticker['ticker']['high']+$ticker['ticker']['low'])/2; - $market->price = AverageIncrement($market->price, $ticker['ticker']['high']); + $price2 = ($ticker['ticker']['buy']+$ticker['ticker']['sell'])/2; + $market->price = AverageIncrement($market->price, $ticker['ticker']['buy']); $market->price2 = AverageIncrement($market->price2, $price2); $market->pricetime = time(); $market->save(); From dd9b467ecb91d6c98280140b4eeeeef495c3b6d7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 20 Apr 2018 17:34:55 +0200 Subject: [PATCH 019/115] config: new server var to disable autocreation of coins --- web/serverconfig.sample.php | 3 ++- web/yaamp/core/backend/rawcoins.php | 6 +++++- web/yaamp/defaultconfig.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/serverconfig.sample.php b/web/serverconfig.sample.php index 59b4a7f99..0a8d2e068 100644 --- a/web/serverconfig.sample.php +++ b/web/serverconfig.sample.php @@ -36,7 +36,8 @@ define('YAAMP_ADMIN_EMAIL', 'yiimp@spam.la'); define('YAAMP_ADMIN_IP', ''); // samples: "80.236.118.26,90.234.221.11" or "10.0.0.1/8" define('YAAMP_ADMIN_WEBCONSOLE', true); -define('YAAMP_NOTIFY_NEW_COINS', true); +define('YAAMP_CREATE_NEW_COINS', true); +define('YAAMP_NOTIFY_NEW_COINS', false); define('YAAMP_DEFAULT_ALGO', 'x11'); define('YAAMP_USE_NGINX', false); diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 1f6c5faf5..fbd96a668 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -382,7 +382,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') if($symbol == 'BTC') return; $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol)); - if(!$coin && $marketname != 'yobit') + if(!$coin && YAAMP_CREATE_NEW_COINS) { $algo = ''; if ($marketname == 'cryptopia') { @@ -405,6 +405,10 @@ function updateRawCoin($marketname, $symbol, $name='unknown') return; } + // some other to ignore... + if (in_array($marketname, array('yobit','kucoin'))) + return; + if (market_get($marketname, $symbol, "disabled")) { return; } diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 195eb2118..589c11ee2 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -55,7 +55,8 @@ if (!defined('YAAMP_ADMIN_IP')) define('YAAMP_ADMIN_IP', '127.0.0.1'); if (!defined('YAAMP_ADMIN_WEBCONSOLE')) define('YAAMP_ADMIN_WEBCONSOLE', true); -if (!defined('YAAMP_NOTIFY_NEW_COINS')) define('YAAMP_NOTIFY_NEW_COINS', true); +if (!defined('YAAMP_CREATE_NEW_COINS')) define('YAAMP_CREATE_NEW_COINS', true); +if (!defined('YAAMP_NOTIFY_NEW_COINS')) define('YAAMP_NOTIFY_NEW_COINS', false); if (!defined('YAAMP_LIMIT_ESTIMATE')) define('YAAMP_LIMIT_ESTIMATE', false); if (!defined('YAAMP_RENTAL')) define('YAAMP_RENTAL', false); From 10be25ee8287eea02f5f0ff9ccdb308235bd143d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Nov=C3=BD?= Date: Sun, 22 Apr 2018 04:25:40 +0200 Subject: [PATCH 020/115] stratum: correctly create blocks with 253-255 transactions (#260) According to [1], varints of 0xfd to 0xff are prefixed with 0xfd too. [1]: http://learnmeabitcoin.com/glossary/varint --- stratum/client_submit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 47dfd0fe0..78fc94cb0 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -215,7 +215,7 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL if(hash_int <= coin_target) { char count_hex[8] = { 0 }; - if (templ->txcount <= 255) + if (templ->txcount <= 252) sprintf(count_hex, "%02x", templ->txcount & 0xFF); else sprintf(count_hex, "fd%02x%02x", templ->txcount & 0xFF, templ->txcount >> 8); From b22b599b3e826e30299cf4170897bd963a893cad Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 23 Apr 2018 15:52:24 +0200 Subject: [PATCH 021/115] explorer: only allow hexa chars in query params --- web/yaamp/core/common/util.php | 7 +++++++ .../modules/explorer/ExplorerController.php | 20 +++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/web/yaamp/core/common/util.php b/web/yaamp/core/common/util.php index 6bc646274..999d89748 100644 --- a/web/yaamp/core/common/util.php +++ b/web/yaamp/core/common/util.php @@ -40,6 +40,13 @@ function getparam($p,$default='') return isset($_REQUEST[$p]) ? $_REQUEST[$p] : $default; } +function gethexparam($p,$default='') +{ + $str = getparam($p, NULL); + $hex = (is_string($str) && ctype_xdigit($str)) ? $str : $default; + return $hex; +} + function getiparam($p,$default=0) { // workaround for yii default /route/ .... diff --git a/web/yaamp/modules/explorer/ExplorerController.php b/web/yaamp/modules/explorer/ExplorerController.php index c1650075b..cfa192539 100644 --- a/web/yaamp/modules/explorer/ExplorerController.php +++ b/web/yaamp/modules/explorer/ExplorerController.php @@ -59,8 +59,8 @@ public function actionIndex() $coin = getdbo('db_coins', $id); if($coin && $coin->no_explorer) { $link = $coin->link_explorer; - //$txid = getparam('txid'); - //$hash = getparam('hash'); + //$txid = gethexparam('txid'); + //$hash = gethexparam('hash'); //if (!empty($txid)) $link .= 'tx/'.$txid; //elseif (!empty($hash)) $link .= 'block/'.$hash; die("Block explorer disabled, please use $link"); @@ -71,11 +71,11 @@ public function actionIndex() $remote = new WalletRPC($coin); $hash = $remote->getblockhash(intval($height)); } else { - $hash = getparam('hash'); + $hash = gethexparam('hash'); } - $txid = getparam('txid'); - $q = getparam('q'); + $txid = gethexparam('txid'); + $q = gethexparam('q'); if (strlen($q) >= 32 && ctype_xdigit($q)) { $remote = new WalletRPC($coin); $block = $remote->getblock($q); @@ -87,7 +87,7 @@ public function actionIndex() } } - if($coin && !empty($txid) && ctype_xdigit($txid)) + if($coin && !empty($txid)) { $remote = new WalletRPC($coin); $tx = $remote->getrawtransaction($txid, 1); @@ -96,7 +96,7 @@ public function actionIndex() $hash = arraySafeVal($tx,'blockhash'); } - if($coin && !empty($hash) && ctype_xdigit($hash)) + if($coin && !empty($hash)) $this->render('block', array('coin'=>$coin, 'hash'=>$hash)); else if($coin) @@ -116,9 +116,9 @@ public function actionId() public function actionSearch() { $height = getiparam('height'); - $txid = arraySafeVal($_REQUEST,'txid'); - $hash = arraySafeVal($_REQUEST,'hash'); - $q = arraySafeVal($_REQUEST,'q'); + $txid = gethexparam('txid'); + $hash = gethexparam('hash'); + $q = gethexparam('q'); if (isset($_GET['SYM'])) { // only for visible coins $url = "/explorer/".$_GET['SYM']."?"; From b517afb571033c7c912901ff5aa4785a222abbab Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 29 Apr 2018 18:41:12 +0200 Subject: [PATCH 022/115] dashboard: some cleanup, remove unused state --- web/yaamp/modules/site/common_results.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index fb88841e2..88abe8b11 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -507,20 +507,13 @@ function cronstate2text($state) } } -//$state_block = $this->memcache->get('cronjob_block_state'); -$state_main = $this->memcache->get('cronjob_main_state'); +$state_main = (int) $this->memcache->get('cronjob_main_state'); $btc = getdbosql('db_coins', "symbol='BTC'"); if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}'); echo ''; for($i=0; $i<10; $i++) { -// if($i != $state_block-1 && $state_block>0) -// { -// $state = $this->memcache->get("cronjob_block_state_$i"); -// if($state) echo "block $i "; -// } - if($i != $state_main-1 && $state_main>0) { $state = $this->memcache->get("cronjob_main_state_$i"); From 1bfec2be32acdeb5119875d59f8ad8d88570e782 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 1 May 2018 15:03:59 +0200 Subject: [PATCH 023/115] stratum: precheck addresses are valid base58 --- stratum/base58.cpp | 16 ++++++++++++++++ stratum/client.cpp | 6 +++++- stratum/util.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/stratum/base58.cpp b/stratum/base58.cpp index 856683ebe..631fde043 100644 --- a/stratum/base58.cpp +++ b/stratum/base58.cpp @@ -96,3 +96,19 @@ bool base58_decode(const char *input, char *output) return true; } + +bool is_base58(char *input) +{ + // All alphanumeric characters except "0", "O", "I" and "l" + size_t i=0, len = strlen(input); + char *c = input; + while (i < len) { + bool isdigit = (c[i] >= '1' && c[i] <= '9'); + bool isalpha = (c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'); + if (!isdigit && !isalpha) return false; + if (c[i] == 'I' || c[i] == 'O' || c[i] == 'l') return false; + i++; + } + return true; +} + diff --git a/stratum/client.cpp b/stratum/client.cpp index bdc6bb2b6..60a0d9bfe 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -256,8 +256,12 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) CommonUnlock(&g_db_mutex); } + bool is_bad_address = !is_base58(client->username); // when auto exchange is disabled, only authorize good wallet address... - if (!g_autoexchange && !client_validate_user_address(client)) { + if (!g_autoexchange && !client_validate_user_address(client)) + is_bad_address = true; + + if (is_bad_address) { clientlog(client, "bad mining address %s", client->username); client_send_result(client, "false"); diff --git a/stratum/util.h b/stratum/util.h index 7afdd1bed..bf57bfd27 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -74,6 +74,7 @@ string merkle_with_first(vector steps, string f); ////////////////////////////////////////////////////////////////////////// bool base58_decode(const char *input, char *output); +bool is_base58(char *input); void base64_encode(char *base64, const char *normal); void base64_decode(char *normal, const char *base64); From 138b0079bb2c78930aad106ce691d3a733dca6f3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 1 May 2018 15:34:01 +0200 Subject: [PATCH 024/115] stratum: pre-check bad usernames before db add --- stratum/client.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 60a0d9bfe..6f0c9d5b1 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -229,6 +229,11 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) } } + if (!is_base58(client->username)) { + clientlog(client, "bad mining address %s", client->username); + return false; + } + bool reset = client_initialize_multialgo(client); if(reset) return false; @@ -256,12 +261,8 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) CommonUnlock(&g_db_mutex); } - bool is_bad_address = !is_base58(client->username); // when auto exchange is disabled, only authorize good wallet address... - if (!g_autoexchange && !client_validate_user_address(client)) - is_bad_address = true; - - if (is_bad_address) { + if (!g_autoexchange && !client_validate_user_address(client)) { clientlog(client, "bad mining address %s", client->username); client_send_result(client, "false"); From 078ace3a6503cd80d638492dcb0922363476c4fa Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 2 May 2018 09:10:39 -0300 Subject: [PATCH 025/115] stratum: log ip of new clients (#262) --- stratum/user.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/user.cpp b/stratum/user.cpp index 29bf045f5..1e2ec6ce0 100644 --- a/stratum/user.cpp +++ b/stratum/user.cpp @@ -108,8 +108,8 @@ void db_add_user(YAAMP_DB *db, YAAMP_CLIENT *client) else if(client->userid == 0 && strlen(client->username) >= MIN_ADDRESS_LEN) { - db_query(db, "INSERT INTO accounts (username, coinsymbol, balance, donation) values ('%s', '%s', 0, %d)", - client->username, symbol, gift); + db_query(db, "INSERT INTO accounts (username, coinsymbol, balance, donation, hostaddr) values ('%s', '%s', 0, %d, '%s')", + client->username, symbol, gift, client->sock->ip); client->userid = (int)mysql_insert_id(&db->mysql); } From 6fe2208e2ea69392863f45590767fa691065f253 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 2 May 2018 09:11:02 -0300 Subject: [PATCH 026/115] yiimp: log ip in debug message for unknown address (#263) --- web/yaamp/core/backend/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/users.php b/web/yaamp/core/backend/users.php index 35bc8bb36..443443d10 100644 --- a/web/yaamp/core/backend/users.php +++ b/web/yaamp/core/backend/users.php @@ -70,7 +70,7 @@ function BackendUsersUpdate() } if (empty($user->coinid)) { - debuglog("{$user->username} is an unknown address!"); + debuglog("{$user->hostaddr} - {$user->username} is an unknown address!"); } $user->save(); From 8fb9a74164ca2f706af4e8712fe2360f563f48f0 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Wed, 2 May 2018 08:27:39 -0400 Subject: [PATCH 027/115] stratum: add vitalium algo (#261) note: beware of the masterscams --- stratum/algos/makefile | 2 +- stratum/algos/vitalium.c | 87 +++++++++++++++++++++++++++++ stratum/algos/vitalium.h | 16 ++++++ stratum/config.sample/vitalium.conf | 16 ++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 5 +- 7 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 stratum/algos/vitalium.c create mode 100644 stratum/algos/vitalium.h create mode 100644 stratum/config.sample/vitalium.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 815c7eb1e..c6e5200da 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -20,7 +20,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ a5a.c a5amath.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c + phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c vitalium.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/algos/vitalium.c b/stratum/algos/vitalium.c new file mode 100644 index 000000000..2a3b27cbb --- /dev/null +++ b/stratum/algos/vitalium.c @@ -0,0 +1,87 @@ +#include "vitalium.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include "gost.h" + +#include "common.h" + +void vitalium_hash(const char* input, char* output, uint32_t len) +{ + sph_skein512_context ctx_skein; + sph_cubehash512_context ctx_cubehash; + sph_fugue512_context ctx_fugue; + sph_gost512_context ctx_gost; + sph_echo512_context ctx_echo; + sph_shavite512_context ctx_shavite; + sph_luffa512_context ctx_luffa; + + //these uint512 in the c++ source of the client are backed by an array of uint32 + uint32_t hashA[16], hashB[16]; + + sph_skein512_init(&ctx_skein); + sph_skein512 (&ctx_skein, input, len); + sph_skein512_close (&ctx_skein, hashA); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, hashA, 64); + sph_cubehash512_close(&ctx_cubehash, hashB); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512 (&ctx_fugue, hashB, 64); + sph_fugue512_close(&ctx_fugue, hashA); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashA, 64); + sph_gost512_close (&ctx_gost, hashB); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, hashB, 64); + sph_echo512_close(&ctx_echo, hashA); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512 (&ctx_shavite, hashA, 64); + sph_shavite512_close(&ctx_shavite, hashB); + + sph_luffa512_init (&ctx_luffa); + sph_luffa512 (&ctx_luffa, hashB, 64); + sph_luffa512_close (&ctx_luffa, hashA); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashA, 64); + sph_gost512_close (&ctx_gost, hashB); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, hashB, 64); + sph_cubehash512_close(&ctx_cubehash, hashA); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512 (&ctx_fugue, hashA, 64); + sph_fugue512_close(&ctx_fugue, hashB); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashB, 64); + sph_gost512_close (&ctx_gost, hashA); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, hashA, 64); + sph_echo512_close(&ctx_echo, hashB); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512 (&ctx_shavite, hashB, 64); + sph_shavite512_close(&ctx_shavite, hashA); + + sph_luffa512_init (&ctx_luffa); + sph_luffa512 (&ctx_luffa, hashA, 64); + sph_luffa512_close (&ctx_luffa, hashB); + + memcpy(output, hashB, 32); +} diff --git a/stratum/algos/vitalium.h b/stratum/algos/vitalium.h new file mode 100644 index 000000000..e29b3bcb4 --- /dev/null +++ b/stratum/algos/vitalium.h @@ -0,0 +1,16 @@ +#ifndef VITALITY_H +#define VITALITY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void vitalium_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/vitalium.conf b/stratum/config.sample/vitalium.conf new file mode 100644 index 000000000..ff522cbb1 --- /dev/null +++ b/stratum/config.sample/vitalium.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3233 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = vitalium +difficulty = 0.001 +max_ttf = 400000000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 65a14deb4..8f6f09ed9 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -176,6 +176,7 @@ YAAMP_ALGO g_algos[] = {"veltor", veltor_hash, 1, 0, 0}, {"velvet", velvet_hash, 0x10000, 0, 0}, {"argon2", argon2_hash, 0x10000, 0, sha256_hash_hex }, + {"vitalium", vitalium_hash, 1, 0, 0}, {"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x diff --git a/stratum/stratum.h b/stratum/stratum.h index d8638fb70..6604d1a72 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -200,4 +200,5 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/veltor.h" #include "algos/velvet.h" #include "algos/argon2a.h" +#include "algos/vitalium.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0a9d6911f..0167c941b 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -58,6 +58,7 @@ function yaamp_get_algos() 'vanilla', 'veltor', 'velvet', + 'vitalium', 'yescrypt', 'yescryptR16', 'yescryptR32', @@ -178,9 +179,10 @@ function getAlgoColors($algo) 'bitcore' => '#f790c0', 'skunk' => '#dedefe', 'tribus' => '#c0d0d0', - 'a5a' => '#f0f0f0', + 'a5a' => '#f0f0f0', 'vanilla' => '#f0f0f0', 'velvet' => '#aac0cc', + 'vitalium' => '#f0b0a0', 'whirlpool' => '#d0e0e0', 'yescrypt' => '#e0d0e0', 'yescryptR16' => '#e2d0e2', @@ -251,6 +253,7 @@ function getAlgoPort($algo) 'm7m' => 6033, 'veltor' => 5034, 'velvet' => 6133, + 'vitalium' => 3233, 'yescrypt' => 6233, 'yescryptR16' => 6333, 'yescryptR32' => 6343, From adbdad424e795dad9433f8d2ee2b9a573902ee50 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 2 May 2018 16:32:44 +0200 Subject: [PATCH 028/115] backend: prevent php bug on empty masternode payee field (LUX) --- web/yaamp/core/backend/coins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/coins.php b/web/yaamp/core/backend/coins.php index 51c0e80e8..34a1c32b7 100644 --- a/web/yaamp/core/backend/coins.php +++ b/web/yaamp/core/backend/coins.php @@ -140,7 +140,7 @@ function BackendCoinsUpdate() $coin->charity_amount = $template['_V2']/100000000; if(isset($template['payee_amount']) && $coin->symbol != 'LIMX') { - $coin->charity_amount = $template['payee_amount']/100000000; + $coin->charity_amount = doubleval($template['payee_amount'])/100000000; $coin->reward -= $coin->charity_amount; } From a78ec34d37545a21a33aaa41f427ed9f2d90da66 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 4 May 2018 19:52:44 +0200 Subject: [PATCH 029/115] stratum: support for Machinecoin 0.16 mn+segwit (#265) --- stratum/coinbase.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 4b99ef289..280008c6c 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -204,6 +204,71 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * coind->reward = (double)available / 100000000 * coind->reward_mul; return; } + else if(strcmp(coind->symbol, "MAC") == 0) { + char script_payee[1024] = { 0 }; + char payees[4]; + int npayees = (templ->has_segwit_txs) ? 2 : 1; + bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); + bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); + json_value* superblock = json_get_array(json_result, "superblock"); + json_value* masternode = json_get_object(json_result, "masternode"); + + if (masternode_enabled && masternode) { + const char *payee = json_get_string(masternode, "payee"); + json_int_t amount = json_get_int(masternode, "amount"); + if (payee && amount) + ++npayees; + } + if(superblocks_enabled && superblock) { + for(int i = 0; i < superblock->u.array.length; i++) { + const char *payee = json_get_string(superblock->u.array.values[i], "payee"); + json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); + if (payee && amount) { + ++npayees; + } + } + } + sprintf(payees, "%02x", npayees); + strcat(templ->coinb2, payees); + if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); + if(superblocks_enabled && superblock) { + for(int i = 0; i < superblock->u.array.length; i++) { + const char *payee = json_get_string(superblock->u.array.values[i], "payee"); + json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); + if (payee && amount) { + npayees++; + available -= amount; + // superblock payments are going to use P2SH addresses / segwit transactions + base58_decode(payee, script_payee); + char eamount[32]; + encode_tx_value(eamount, amount); + strcat(templ->coinb2, eamount); + char coinb2_part[1024] = { 0 }; + char coinb2_len[3] = { 0 }; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + strcat(templ->coinb2, coinb2_len); + strcat(templ->coinb2, coinb2_part); + debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); + } + } + } + if (masternode_enabled && masternode) { + const char *payee = json_get_string(masternode, "payee"); + json_int_t amount = json_get_int(masternode, "amount"); + if (payee && amount) { + npayees++; + available -= amount; + base58_decode(payee, script_payee); + job_pack_tx(coind, templ->coinb2, amount, script_payee); + } + } + job_pack_tx(coind, templ->coinb2, available, NULL); + strcat(templ->coinb2, "00000000"); // locktime + + coind->reward = (double)available / 100000000 * coind->reward_mul; + return; + } // 2 txs are required on these coins, one for foundation (dev fees) if(coind->charity_percent) From fe47cca831555c60edfd70a32ad756b08dcdf08a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 19:53:31 +0200 Subject: [PATCH 030/115] stratum: also prepare normal optional mn+segwit --- stratum/coinbase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 280008c6c..49afbf69a 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -343,7 +343,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * char script_dests[2048] = { 0 }; char script_payee[128] = { 0 }; char payees[4]; // addresses count - int npayees = 1; + int npayees = (templ->has_segwit_txs) ? 2 : 1; bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); json_value* superblock = json_get_array(json_result, "superblock"); @@ -378,6 +378,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } sprintf(payees, "%02x", npayees); strcat(templ->coinb2, payees); + if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); strcat(templ->coinb2, script_dests); job_pack_tx(coind, templ->coinb2, available, NULL); strcat(templ->coinb2, "00000000"); // locktime From d4b00a8b0b850cab606501b1d5c401563cc9f0f4 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 21:41:06 +0200 Subject: [PATCH 031/115] Revert "stratum: support for Machinecoin 0.16 mn+segwit (#265)" This reverts commit a78ec34d37545a21a33aaa41f427ed9f2d90da66. --- stratum/coinbase.cpp | 65 -------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 49afbf69a..be21ad1c0 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -204,71 +204,6 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * coind->reward = (double)available / 100000000 * coind->reward_mul; return; } - else if(strcmp(coind->symbol, "MAC") == 0) { - char script_payee[1024] = { 0 }; - char payees[4]; - int npayees = (templ->has_segwit_txs) ? 2 : 1; - bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); - bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); - json_value* superblock = json_get_array(json_result, "superblock"); - json_value* masternode = json_get_object(json_result, "masternode"); - - if (masternode_enabled && masternode) { - const char *payee = json_get_string(masternode, "payee"); - json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) - ++npayees; - } - if(superblocks_enabled && superblock) { - for(int i = 0; i < superblock->u.array.length; i++) { - const char *payee = json_get_string(superblock->u.array.values[i], "payee"); - json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); - if (payee && amount) { - ++npayees; - } - } - } - sprintf(payees, "%02x", npayees); - strcat(templ->coinb2, payees); - if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); - if(superblocks_enabled && superblock) { - for(int i = 0; i < superblock->u.array.length; i++) { - const char *payee = json_get_string(superblock->u.array.values[i], "payee"); - json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); - if (payee && amount) { - npayees++; - available -= amount; - // superblock payments are going to use P2SH addresses / segwit transactions - base58_decode(payee, script_payee); - char eamount[32]; - encode_tx_value(eamount, amount); - strcat(templ->coinb2, eamount); - char coinb2_part[1024] = { 0 }; - char coinb2_len[3] = { 0 }; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - strcat(templ->coinb2, coinb2_len); - strcat(templ->coinb2, coinb2_part); - debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); - } - } - } - if (masternode_enabled && masternode) { - const char *payee = json_get_string(masternode, "payee"); - json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) { - npayees++; - available -= amount; - base58_decode(payee, script_payee); - job_pack_tx(coind, templ->coinb2, amount, script_payee); - } - } - job_pack_tx(coind, templ->coinb2, available, NULL); - strcat(templ->coinb2, "00000000"); // locktime - - coind->reward = (double)available / 100000000 * coind->reward_mul; - return; - } // 2 txs are required on these coins, one for foundation (dev fees) if(coind->charity_percent) From daac1a10c6ad6b13436a4835a56100a1fbf9cb5e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 21:39:30 +0200 Subject: [PATCH 032/115] stratum: merge P2SH superblock code to prevent duplicated code --- stratum/coinbase.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index be21ad1c0..4db9df820 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -296,7 +296,20 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * npayees++; available -= amount; base58_decode(payee, script_payee); - job_pack_tx(coind, script_dests, amount, script_payee); + bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); + if(superblock_use_p2sh) { + char eamount[32]; + char coinb2_part[512] = { 0 }; + char coinb2_len[4] = { 0 }; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(eamount, amount); + strcat(templ->coinb2, eamount); + strcat(templ->coinb2, coinb2_len); + strcat(templ->coinb2, coinb2_part); + } else { + job_pack_tx(coind, script_dests, amount, script_payee); + } //debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); } } From b43d6465486572b3451c34bf373eada3a5262145 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 6 May 2018 16:50:23 +0200 Subject: [PATCH 033/115] handle allium algo, kind of double lyra2 --- rc.local | 3 +- stratum/algos/allium.c | 46 ++++++++++++++++++++++++++++++ stratum/algos/allium.h | 16 +++++++++++ stratum/algos/makefile | 2 +- stratum/config.sample/allium.conf | 15 ++++++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 ++ 8 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 stratum/algos/allium.c create mode 100644 stratum/algos/allium.h create mode 100644 stratum/config.sample/allium.conf diff --git a/rc.local b/rc.local index 9da2b84e3..dec333643 100644 --- a/rc.local +++ b/rc.local @@ -49,7 +49,8 @@ screen -dmS jha $STRATUM_DIR/run.sh jha #screen -dmS dmd-gr $STRATUM_DIR/run.sh dmd-gr screen -dmS myr-gr $STRATUM_DIR/run.sh myr-gr screen -dmS lbry $STRATUM_DIR/run.sh lbry -screen -dmS lyra2 $STRATUM_DIR/run.sh lyra2 +screen -dmS allium $STRATUM_DIR/run.sh allium +#screen -dmS lyra2 $STRATUM_DIR/run.sh lyra2 screen -dmS lyra2v2 $STRATUM_DIR/run.sh lyra2v2 screen -dmS zero $STRATUM_DIR/run.sh lyra2z diff --git a/stratum/algos/allium.c b/stratum/algos/allium.c new file mode 100644 index 000000000..4c3569d36 --- /dev/null +++ b/stratum/algos/allium.c @@ -0,0 +1,46 @@ +#include + +#include "sha3/sph_blake.h" +#include "sha3/sph_groestl.h" +#include "sha3/sph_skein.h" +#include "sha3/sph_keccak.h" +#include "sha3/sph_cubehash.h" + +#include "Lyra2.h" + +void allium_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hashA[8], hashB[8]; + + sph_blake256_context ctx_blake; + sph_keccak256_context ctx_keccak; + sph_cubehash512_context ctx_cubehash; + sph_skein256_context ctx_skein; + sph_groestl256_context ctx_groestl; + + sph_blake256_init(&ctx_blake); + sph_blake256(&ctx_blake, input, 80); + sph_blake256_close(&ctx_blake, hashA); + + sph_keccak256_init(&ctx_keccak); + sph_keccak256(&ctx_keccak, hashA, 32); + sph_keccak256_close(&ctx_keccak, hashB); + + LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); + + sph_cubehash256_init(&ctx_cubehash); + sph_cubehash256(&ctx_cubehash, hashA, 32); + sph_cubehash256_close(&ctx_cubehash, hashB); + + LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); + + sph_skein256_init(&ctx_skein); + sph_skein256(&ctx_skein, hashA, 32); + sph_skein256_close(&ctx_skein, hashB); + + sph_groestl256_init(&ctx_groestl); + sph_groestl256(&ctx_groestl, hashB, 32); + sph_groestl256_close(&ctx_groestl, hashA); + + memcpy(output, hashA, 32); +} diff --git a/stratum/algos/allium.h b/stratum/algos/allium.h new file mode 100644 index 000000000..3705161f7 --- /dev/null +++ b/stratum/algos/allium.h @@ -0,0 +1,16 @@ +#ifndef ALLIUM_H +#define ALLIUM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void allium_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/algos/makefile b/stratum/algos/makefile index c6e5200da..e2a714134 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -8,7 +8,7 @@ CXXFLAGS = -O2 -I.. -march=native CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp -SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ +SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c allium.c \ blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ diff --git a/stratum/config.sample/allium.conf b/stratum/config.sample/allium.conf new file mode 100644 index 000000000..ec9d41ff3 --- /dev/null +++ b/stratum/config.sample/allium.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 4443 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = allium +difficulty = 0.01 +max_ttf = 4000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 8f6f09ed9..73717ae42 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -133,6 +133,7 @@ YAAMP_ALGO g_algos[] = {"jha", jha_hash, 0x10000, 0}, + {"allium", allium_hash, 1, 0, 0}, {"lyra2", lyra2re_hash, 0x80, 0, 0}, {"lyra2v2", lyra2v2_hash, 0x100, 0, 0}, {"lyra2z", lyra2z_hash, 0x100, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index 6604d1a72..fdbf124f2 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -164,6 +164,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/hsr14.h" #include "algos/quark.h" #include "algos/neoscrypt.h" +#include "algos/allium.h" #include "algos/lyra2re.h" #include "algos/lyra2v2.h" #include "algos/lyra2z.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0167c941b..e7adae219 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -8,6 +8,7 @@ function yaamp_get_algos() 'sha256t', 'scrypt', 'scryptn', + 'allium', 'argon2', 'bastion', 'bitcore', @@ -148,6 +149,7 @@ function getAlgoColors($algo) 'x16s' => '#f0b080', 'x17' => '#f0b0a0', 'xevan' => '#f0b0a0', + 'allium' => '#80a0d0', 'argon2' => '#e0d0e0', 'bastion' => '#e0b0b0', 'blake' => '#f0f0f0', @@ -227,6 +229,7 @@ function getAlgoPort($algo) 'neoscrypt' => 4233, 'argon2' => 4234, 'scryptn' => 4333, + 'allium' => 4443, 'lyra2' => 4433, 'lyra2v2' => 4533, 'lyra2z' => 4553, From d428130df324255b2b6e145c786661b6fa5e19b7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 6 May 2018 17:09:11 +0200 Subject: [PATCH 034/115] allium: fix pool diff ratio, same as lyra2v2, cf cpuminer-opt --- stratum/config.sample/allium.conf | 2 +- stratum/stratum.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/config.sample/allium.conf b/stratum/config.sample/allium.conf index ec9d41ff3..1f8f1921a 100644 --- a/stratum/config.sample/allium.conf +++ b/stratum/config.sample/allium.conf @@ -11,5 +11,5 @@ password = patofpaq [STRATUM] algo = allium -difficulty = 0.01 +difficulty = 1 max_ttf = 4000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 73717ae42..4fcba4015 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -133,7 +133,7 @@ YAAMP_ALGO g_algos[] = {"jha", jha_hash, 0x10000, 0}, - {"allium", allium_hash, 1, 0, 0}, + {"allium", allium_hash, 0x100, 0, 0}, {"lyra2", lyra2re_hash, 0x80, 0, 0}, {"lyra2v2", lyra2v2_hash, 0x100, 0, 0}, {"lyra2z", lyra2z_hash, 0x100, 0, 0}, From db7a145c0b30df61407420235eca064a43c4c5be Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 7 May 2018 15:00:41 +0200 Subject: [PATCH 035/115] stratum: fix superblock script order was not easy to code without the future wallet code to test it ;) --- stratum/coinbase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 4db9df820..ee23e63fd 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -298,15 +298,15 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(superblock_use_p2sh) { - char eamount[32]; - char coinb2_part[512] = { 0 }; - char coinb2_len[4] = { 0 }; + char eamount[32] = { 0 }; + char coinb2_part[256]; + char coinb2_len[4]; sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); encode_tx_value(eamount, amount); - strcat(templ->coinb2, eamount); - strcat(templ->coinb2, coinb2_len); - strcat(templ->coinb2, coinb2_part); + strcat(script_dests, eamount); + strcat(script_dests, coinb2_len); + strcat(script_dests, coinb2_part); } else { job_pack_tx(coind, script_dests, amount, script_payee); } From ed97818e612c3b0eb6017bf75b5eefe5db8f9998 Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 7 May 2018 15:41:20 +0200 Subject: [PATCH 036/115] stratum: support for MAC P2SH masternodes too (#266) note: a field "isscript" should be added to getblocktemplate masternode/superblock objects if the type of address can vary over time... Code may be refactored later (common func and p2sh fields in coind object) --- stratum/coinbase.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index ee23e63fd..06bb4c69b 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -321,7 +321,20 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * npayees++; available -= amount; base58_decode(payee, script_payee); - job_pack_tx(coind, script_dests, amount, script_payee); + bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); + if(masternode_use_p2sh) { + char eamount[32] = { 0 }; + char coinb2_part[256]; + char coinb2_len[4]; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(eamount, amount); + strcat(script_dests, eamount); + strcat(script_dests, coinb2_len); + strcat(script_dests, coinb2_part); + } else { + job_pack_tx(coind, script_dests, amount, script_payee); + } } } sprintf(payees, "%02x", npayees); From b114a1c66f0a6a08f0dc7abf60766afc63579209 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 7 May 2018 16:15:56 +0200 Subject: [PATCH 037/115] stratum: common p2sh_pack_tx func for p2sh masternodes --- stratum/coinbase.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 06bb4c69b..15db7a2a4 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -32,6 +32,19 @@ static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char // debuglog("pack tx %lld\n", amount); } +static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *payee) +{ + char evalue[32]; + char coinb2_part[256]; + char coinb2_len[4]; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(payee) >> 1) & 0xFF, payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(evalue, amount); + strcat(data, evalue); + strcat(data, coinb2_len); + strcat(data, coinb2_part); +} + void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script) { vector hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size); @@ -298,15 +311,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(superblock_use_p2sh) { - char eamount[32] = { 0 }; - char coinb2_part[256]; - char coinb2_len[4]; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - encode_tx_value(eamount, amount); - strcat(script_dests, eamount); - strcat(script_dests, coinb2_len); - strcat(script_dests, coinb2_part); + p2sh_pack_tx(coind, script_dests, amount, script_payee); } else { job_pack_tx(coind, script_dests, amount, script_payee); } @@ -323,15 +328,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(masternode_use_p2sh) { - char eamount[32] = { 0 }; - char coinb2_part[256]; - char coinb2_len[4]; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - encode_tx_value(eamount, amount); - strcat(script_dests, eamount); - strcat(script_dests, coinb2_len); - strcat(script_dests, coinb2_part); + p2sh_pack_tx(coind, script_dests, amount, script_payee); } else { job_pack_tx(coind, script_dests, amount, script_payee); } From ca974e661f468a3770617716c44056c048c76006 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 8 May 2018 23:49:53 +0200 Subject: [PATCH 038/115] backend: keep blocks history at least 7 days --- web/yaamp/core/backend/system.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/system.php b/web/yaamp/core/backend/system.php index 9d5478a92..b70da2ce9 100644 --- a/web/yaamp/core/backend/system.php +++ b/web/yaamp/core/backend/system.php @@ -35,8 +35,7 @@ function BackendQuickClean() foreach($coins as $coin) { - $delay = time() - 24*60*60; - if ($coin->symbol=='DCR') $delay = time() - 7*24*60*60; + $delay = time() - 7*24*60*60; $id = dboscalar("select id from blocks where coin_id=$coin->id and time<$delay and id not in (select blockid from earnings where coinid=$coin->id) From f358e723c83fe7b26c969cdddea403348064ef25 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 9 May 2018 00:12:44 +0200 Subject: [PATCH 039/115] exchanges: ignore coins 'created' by tradesatoshi they have a very huge amount of scams... --- web/yaamp/core/backend/rawcoins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index fbd96a668..c4539afda 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -406,7 +406,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } // some other to ignore... - if (in_array($marketname, array('yobit','kucoin'))) + if (in_array($marketname, array('yobit','kucoin','tradesatoshi'))) return; if (market_get($marketname, $symbol, "disabled")) { From a98b631a87f946b5bf5f4462c2e3a6b6750c8e14 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 9 May 2018 00:24:50 +0200 Subject: [PATCH 040/115] coindb: avoid incapsuda html on cryptopia icons --- web/yaamp/commands/CoindbCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/commands/CoindbCommand.php b/web/yaamp/commands/CoindbCommand.php index 7d6913b01..a2098506b 100644 --- a/web/yaamp/commands/CoindbCommand.php +++ b/web/yaamp/commands/CoindbCommand.php @@ -441,7 +441,7 @@ public function grabCryptopiaIcons() } catch (Exception $e) { continue; } - if (strlen($data) < 2048) continue; + if (strlen($data) < 3000 || strstr($data, 'script src')) continue; echo $symbol." icon found\n"; file_put_contents($local, $data); if (filesize($local) > 0) { From 495dcbba00761d4b266b9453e0d31a78f599e7ed Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 11 May 2018 10:12:30 +0200 Subject: [PATCH 041/115] stratum: detect if master wallet is p2sh + mn started field --- stratum/coinbase.cpp | 9 +++++++-- stratum/coind.cpp | 2 ++ stratum/coind.h | 1 + web/yaamp/core/backend/coins.php | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 15db7a2a4..2d20a8776 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -320,9 +320,10 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } } if (masternode_enabled && masternode) { + bool started = json_get_bool(json_result, "masternode_payments_started"); const char *payee = json_get_string(masternode, "payee"); json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) { + if (payee && amount && started) { npayees++; available -= amount; base58_decode(payee, script_payee); @@ -338,7 +339,11 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * strcat(templ->coinb2, payees); if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); strcat(templ->coinb2, script_dests); - job_pack_tx(coind, templ->coinb2, available, NULL); + if (coind->p2sh_address) { // "MAC 0.16" + p2sh_pack_tx(coind, templ->coinb2, available, coind->script_pubkey); + } else { + job_pack_tx(coind, templ->coinb2, available, NULL); + } strcat(templ->coinb2, "00000000"); // locktime coind->reward = (double)available/100000000*coind->reward_mul; //debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests); diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 4ba9ab84f..154480357 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -139,6 +139,8 @@ bool coind_validate_address(YAAMP_COIND *coind) if (!base58_decode(coind->wallet, coind->script_pubkey)) stratumlog("Warning: unable to decode %s %s script pubkey\n", coind->symbol, coind->wallet); + coind->p2sh_address = json_get_bool(json_result, "isscript"); + // if base58 decode fails if (!strlen(coind->script_pubkey)) { const char *pk = json_get_string(json_result, "scriptPubKey"); diff --git a/stratum/coind.h b/stratum/coind.h index d008a24e7..f58f091b7 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -35,6 +35,7 @@ class YAAMP_COIND: public YAAMP_OBJECT char pubkey[1024]; char script_pubkey[1024]; + bool p2sh_address; bool pos; bool hassubmitblock; diff --git a/web/yaamp/core/backend/coins.php b/web/yaamp/core/backend/coins.php index 34a1c32b7..11126716c 100644 --- a/web/yaamp/core/backend/coins.php +++ b/web/yaamp/core/backend/coins.php @@ -145,7 +145,8 @@ function BackendCoinsUpdate() } else if(isset($template['masternode']) && arraySafeVal($template,'masternode_payments_enforced')) { - $coin->reward -= arraySafeVal($template['masternode'],'amount',0)/100000000; + if (arraySafeVal($template,'masternode_payments_started')) + $coin->reward -= arraySafeVal($template['masternode'],'amount',0)/100000000; $coin->hasmasternodes = true; } From a3103af7ba4c098a668e652f90a342a6f3ab6dc8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 14 May 2018 17:35:09 +0200 Subject: [PATCH 042/115] stratum: fix client memory leak in yescrypt --- stratum/algos/yescrypt.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index 150174539..2959dfa4b 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -327,35 +327,25 @@ static int yescrypt_bsty(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, uint8_t * buf, size_t buflen) { - static __thread int initialized = 0; - static __thread yescrypt_shared_t shared; - static __thread yescrypt_local_t local; + yescrypt_shared_t shared; + yescrypt_local_t local; int retval; - if (!initialized) { -/* "shared" could in fact be shared, but it's simpler to keep it private - * along with "local". It's dummy and tiny anyway. */ - if (yescrypt_init_shared(&shared, NULL, 0, + if (yescrypt_init_shared(&shared, NULL, 0, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return -1; - if (yescrypt_init_local(&local)) { + if (yescrypt_init_local(&local)) { yescrypt_free_shared(&shared); return -1; - } - initialized = 1; } + retval = yescrypt_kdf(&shared, &local, passwd, passwdlen, salt, saltlen, N, r, p, 0, YESCRYPT_FLAGS, buf, buflen); -#if 0 - if (yescrypt_free_local(&local)) { - yescrypt_free_shared(&shared); - return -1; - } - if (yescrypt_free_shared(&shared)) - return -1; - initialized = 0; -#endif + + yescrypt_free_local(&local); + yescrypt_free_shared(&shared); + return retval; } @@ -364,6 +354,7 @@ void yescrypt_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 2048, 8, 1, (uint8_t*)output, 32); } + void yescryptR16_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32); From a9dc8c5dfdff2e3cc458f4b9c319b168028c55d9 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 16 May 2018 09:53:44 -0300 Subject: [PATCH 043/115] trading: don't send coins to exchange which have late tx already --- web/yaamp/core/backend/sell.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/yaamp/core/backend/sell.php b/web/yaamp/core/backend/sell.php index 5b25a2ce6..7fba09b3c 100644 --- a/web/yaamp/core/backend/sell.php +++ b/web/yaamp/core/backend/sell.php @@ -38,7 +38,7 @@ function sellCoinToExchange($coin) $market = getBestMarket($coin); if(!$market) return; - if(!$coin->sellonbid && $market->lastsent != null && $market->lastsent > $market->lasttraded) + if($market->lastsent != null && $market->lastsent > $market->lasttraded) { // debuglog("*** not sending $coin->name to $market->name. last tx is late ***"); return; @@ -77,9 +77,6 @@ function sellCoinToExchange($coin) $amount = round($amount, 8); // debuglog("sending $amount $coin->symbol to $marketname, $deposit_address"); - $market->lastsent = time(); - $market->save(); - // sleep(1); $tx = $remote->sendtoaddress($deposit_address, $amount); @@ -107,6 +104,12 @@ function sellCoinToExchange($coin) return; } } + + if($tx) + { + $market->lastsent = time(); + $market->save(); + } $exchange = new db_exchange; $exchange->market = $marketname; From 8c1964d0d960380a11958a6adf42e5513b5521be Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 18 May 2018 12:52:10 +0200 Subject: [PATCH 044/115] lyra2z: prevent filenames with different cases + rename blake2 to blake2s and reorder algo makefile --- stratum/algos/{Lyra2z.c => Lyra2-z.c} | 0 stratum/algos/{Lyra2z.h => Lyra2-z.h} | 0 stratum/algos/{blake2.c => blake2s.c} | 0 stratum/algos/{blake2.h => blake2s.h} | 0 stratum/algos/lyra2z.c | 2 +- stratum/algos/makefile | 21 ++++++++++----------- stratum/stratum.h | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) rename stratum/algos/{Lyra2z.c => Lyra2-z.c} (100%) rename stratum/algos/{Lyra2z.h => Lyra2-z.h} (100%) rename stratum/algos/{blake2.c => blake2s.c} (100%) rename stratum/algos/{blake2.h => blake2s.h} (100%) diff --git a/stratum/algos/Lyra2z.c b/stratum/algos/Lyra2-z.c similarity index 100% rename from stratum/algos/Lyra2z.c rename to stratum/algos/Lyra2-z.c diff --git a/stratum/algos/Lyra2z.h b/stratum/algos/Lyra2-z.h similarity index 100% rename from stratum/algos/Lyra2z.h rename to stratum/algos/Lyra2-z.h diff --git a/stratum/algos/blake2.c b/stratum/algos/blake2s.c similarity index 100% rename from stratum/algos/blake2.c rename to stratum/algos/blake2s.c diff --git a/stratum/algos/blake2.h b/stratum/algos/blake2s.h similarity index 100% rename from stratum/algos/blake2.h rename to stratum/algos/blake2s.h diff --git a/stratum/algos/lyra2z.c b/stratum/algos/lyra2z.c index b83b83881..0d946def4 100644 --- a/stratum/algos/lyra2z.c +++ b/stratum/algos/lyra2z.c @@ -3,7 +3,7 @@ #include #include -#include "Lyra2z.h" +#include "Lyra2-z.h" #include diff --git a/stratum/algos/makefile b/stratum/algos/makefile index e2a714134..d7c296f9c 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -8,19 +8,18 @@ CXXFLAGS = -O2 -I.. -march=native CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp -SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c allium.c \ - blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ - hsr14.c sm3.c \ - x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ - bitcore.c timetravel.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ - skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ - blake2.c \ - yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ - m7m.c magimath.cpp velvet.c \ +SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ + c11.c x11.c x12.c x13.c hsr14.c sm3.c x14.c x15.c x17.c \ + blake.c blakecoin.c blake2s.c jha.c keccak.c lbry.c tribus.c \ + deep.c fresh.c groestl.c neoscrypt.c nist5.c quark.c qubit.c skein.c skein2.c \ + bitcore.c timetravel.c x11evo.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ + bmw.c luffa.c pentablake.c vitalium.c whirlpool.c whirlpoolx.c zr5.c \ + scrypt.c scryptn.c sha256.c sha256t.c \ + yescrypt.c yescrypt-opt.c sha256_Y.c \ + a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ - a5a.c a5amath.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c vitalium.c + phi.c polytimos.c skunk.c sib.c veltor.c gost.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/stratum.h b/stratum/stratum.h index fdbf124f2..b4b6fe7a8 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -170,7 +170,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/lyra2z.h" #include "algos/blake.h" #include "algos/blakecoin.h" -#include "algos/blake2.h" +#include "algos/blake2s.h" #include "algos/qubit.h" #include "algos/groestl.h" #include "algos/jha.h" From f3d9f253b35613a02fb4f4aabbbb8563aa56c579 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 18 May 2018 13:35:17 +0200 Subject: [PATCH 045/115] ci: add travis config (#212) --- .travis.yml | 5 +++++ README.md | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..f9546188c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: cpp +script: + - (cd blocknotify && make) + - (cd stratum/iniparser && make) + - (cd stratum && make) diff --git a/README.md b/README.md index 3472e5567..99c19e84d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/tpruvot/yiimp.svg?branch=next)](https://travis-ci.org/tpruvot/yiimp) + #yiimp - yaamp fork Required: From 2b932a8a9694e2ace76c464e409c84581af36885 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 21 May 2018 15:52:57 +0200 Subject: [PATCH 046/115] stratum: check json version string ptr validity --- stratum/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 6f0c9d5b1..37232e404 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -45,8 +45,8 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) if(json_params->u.array.length>0) { - strncpy(client->version, json_params->u.array.values[0]->u.string.ptr, 1023); - // if(!strcmp(client->version, "stratum-proxy/0.0.1")) return false; + if (json_params->u.array.values[0]->u.string.ptr) + strncpy(client->version, json_params->u.array.values[0]->u.string.ptr, 1023); if(strstr(client->version, "NiceHash") || strstr(client->version, "proxy") || strstr(client->version, "/3.")) client->reconnectable = false; From afc80e2a68dde51f836e4a37cac7d6f6a23c3373 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:11:37 +0200 Subject: [PATCH 047/115] stratum: handle ismine check moved in getaddressinfo --- stratum/coind.cpp | 3 ++- stratum/coind.h | 2 +- stratum/db.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 154480357..fe1c955f3 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,7 +114,8 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - json_value *json = rpc_call(&coind->rpc, "validateaddress", params); + // assume, if the wallet has dropped getinfo, that it use the new getaddressinfo rpc for ismine and account + json_value *json = rpc_call(&coind->rpc, coind->hasgetinfo ? "validateaddress" : "getaddressinfo", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); diff --git a/stratum/coind.h b/stratum/coind.h index f58f091b7..611020b79 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -69,7 +69,7 @@ class YAAMP_COIND: public YAAMP_OBJECT bool hasmasternodes; bool oldmasternodes; bool multialgos; // pow_hash field (or mined_hash) - + bool hasgetinfo; bool usesegwit; char commitment[128]; char witness_magic[16]; diff --git a/stratum/db.cpp b/stratum/db.cpp index f8c513cd8..fb0ca4eaf 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -193,7 +193,7 @@ void db_update_coinds(YAAMP_DB *db) db_query(db, "SELECT id, name, rpchost, rpcport, rpcuser, rpcpasswd, rpcencoding, master_wallet, reward, price, " "hassubmitblock, txmessage, enable, auto_ready, algo, pool_ttf, charity_address, charity_amount, charity_percent, " "reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes, algo, symbol2, " - "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit " + "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit, hasgetinfo " "FROM coins WHERE enable AND auto_ready AND algo='%s' ORDER BY index_avg", g_stratum_algo); MYSQL_RES *result = mysql_store_result(&db->mysql); @@ -304,6 +304,7 @@ void db_update_coinds(YAAMP_DB *db) if(row[33] && atoi(row[33]) > 0) g_stratum_max_cons = atoi(row[33]); if(row[34] && atol(row[34]) > 0) g_max_shares = atol(row[34]); if(row[35]) coind->usesegwit = atoi(row[35]) > 0; + if(row[36]) coind->hasgetinfo = atoi(row[36]) > 0; if(coind->usesegwit) g_stratum_segwit = true; From c72dd9151106b9e85a5ec989d5a9cfb412071d96 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:48:33 +0200 Subject: [PATCH 048/115] Revert "stratum: handle ismine check moved in getaddressinfo" most wallets are not ready for that... This reverts commit afc80e2a68dde51f836e4a37cac7d6f6a23c3373. --- stratum/coind.cpp | 3 +-- stratum/coind.h | 2 +- stratum/db.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index fe1c955f3..154480357 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,8 +114,7 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - // assume, if the wallet has dropped getinfo, that it use the new getaddressinfo rpc for ismine and account - json_value *json = rpc_call(&coind->rpc, coind->hasgetinfo ? "validateaddress" : "getaddressinfo", params); + json_value *json = rpc_call(&coind->rpc, "validateaddress", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); diff --git a/stratum/coind.h b/stratum/coind.h index 611020b79..f58f091b7 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -69,7 +69,7 @@ class YAAMP_COIND: public YAAMP_OBJECT bool hasmasternodes; bool oldmasternodes; bool multialgos; // pow_hash field (or mined_hash) - bool hasgetinfo; + bool usesegwit; char commitment[128]; char witness_magic[16]; diff --git a/stratum/db.cpp b/stratum/db.cpp index fb0ca4eaf..f8c513cd8 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -193,7 +193,7 @@ void db_update_coinds(YAAMP_DB *db) db_query(db, "SELECT id, name, rpchost, rpcport, rpcuser, rpcpasswd, rpcencoding, master_wallet, reward, price, " "hassubmitblock, txmessage, enable, auto_ready, algo, pool_ttf, charity_address, charity_amount, charity_percent, " "reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes, algo, symbol2, " - "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit, hasgetinfo " + "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit " "FROM coins WHERE enable AND auto_ready AND algo='%s' ORDER BY index_avg", g_stratum_algo); MYSQL_RES *result = mysql_store_result(&db->mysql); @@ -304,7 +304,6 @@ void db_update_coinds(YAAMP_DB *db) if(row[33] && atoi(row[33]) > 0) g_stratum_max_cons = atoi(row[33]); if(row[34] && atol(row[34]) > 0) g_max_shares = atol(row[34]); if(row[35]) coind->usesegwit = atoi(row[35]) > 0; - if(row[36]) coind->hasgetinfo = atoi(row[36]) > 0; if(coind->usesegwit) g_stratum_segwit = true; From b5e22c5a002064b8b7630f9c5b2a58d4baf95294 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:58:42 +0200 Subject: [PATCH 049/115] stratum: DGB getaddressinfo to check master wallet --- stratum/coind.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 154480357..08073c6e5 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,7 +114,11 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - json_value *json = rpc_call(&coind->rpc, "validateaddress", params); + json_value *json; + if(strcmp(coind->symbol,"DGB") == 0) + json = rpc_call(&coind->rpc, "getaddressinfo", params); + else + json = rpc_call(&coind->rpc, "validateaddress", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); From ab24ba8145b432d7f4c2b32ad763f908e2d6eb9d Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 19:22:00 +0200 Subject: [PATCH 050/115] stratum: getaddressinfo doesnt return isvalid --- stratum/coind.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 08073c6e5..cfda91cfe 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -115,7 +115,8 @@ bool coind_validate_address(YAAMP_COIND *coind) sprintf(params, "[\"%s\"]", coind->wallet); json_value *json; - if(strcmp(coind->symbol,"DGB") == 0) + bool getaddressinfo = (strcmp(coind->symbol,"DGB") == 0); + if(getaddressinfo) json = rpc_call(&coind->rpc, "getaddressinfo", params); else json = rpc_call(&coind->rpc, "validateaddress", params); @@ -128,11 +129,12 @@ bool coind_validate_address(YAAMP_COIND *coind) return false; } - bool isvalid = json_get_bool(json_result, "isvalid"); + bool isvalid = getaddressinfo || json_get_bool(json_result, "isvalid"); if(!isvalid) stratumlog("%s wallet %s is not valid.\n", coind->name, coind->wallet); bool ismine = json_get_bool(json_result, "ismine"); if(!ismine) stratumlog("%s wallet %s is not mine.\n", coind->name, coind->wallet); + else isvalid = ismine; const char *p = json_get_string(json_result, "pubkey"); strcpy(coind->pubkey, p ? p : ""); From 5fcb58e9c9ce49889d5408946b20088503ce5f34 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 28 May 2018 11:32:17 +0200 Subject: [PATCH 051/115] api: add mbtc_mh_factor (mBTC/MH) to status api 1000 means mBTC/GH 0.001 for mBTC/kH --- web/yaamp/modules/api/ApiController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index 9a5a1568c..bb4ba8055 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -82,6 +82,7 @@ public function actionStatus() "estimate_current" => $price, "estimate_last24h" => $avgprice, "actual_last24h" => $btcmhday1, + "mbtc_mh_factor" => $algo_unit_factor, "hashrate_last24h" => (double) $hashrate1, ); if(YAAMP_RENTAL) { From c1f2ad7cf02b5f9a6d34b7dd8cb4ba73e5fbae88 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 30 May 2018 15:22:24 +0200 Subject: [PATCH 052/115] api: disable rental apis if not enabled --- web/yaamp/modules/api/ApiController.php | 41 +++++++------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index bb4ba8055..d1217c5b4 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -6,8 +6,6 @@ class ApiController extends CommonController ///////////////////////////////////////////////// -// debuglog("saving renter {$_SERVER['REMOTE_ADDR']} $renter->address"); - public function actionStatus() { $client_ip = arraySafeVal($_SERVER,'REMOTE_ADDR'); @@ -289,9 +287,12 @@ public function actionWalletEx() echo "}"; } + ///////////////////////////////////////////////// + public function actionRental() { if(!LimitRequest('api-rental', 10)) return; + if(!YAAMP_RENTAL) return; $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); @@ -336,6 +337,8 @@ public function actionRental() public function actionRental_price() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -353,6 +356,8 @@ public function actionRental_price() public function actionRental_hashrate() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -370,6 +375,8 @@ public function actionRental_hashrate() public function actionRental_start() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter || $renter->balance<=0) return; @@ -386,6 +393,8 @@ public function actionRental_start() public function actionRental_stop() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -400,33 +409,5 @@ public function actionRental_stop() $job->save(); } -// public function actionNodeReport() -// { -// $name = getparam('name'); -// $uptime = getparam('uptime'); - -// $server = getdbosql('db_servers', "name='$name'"); -// if(!$server) -// { -// $server = new db_servers; -// $server->name = $name; -// } - -// $server->uptime = $uptime; -// $server->save(); -// } - } -// function dummy() -// { -// $uptime = system('uptime'); -// $name = system('hostname'); - -// fetch_url("http://".YAAMP_SITE_URL."/api/nodereport?name=$name&uptime=$uptime"); -// } - - - - - From 3343328da56226d2b9fb52c53d721ac50be6da7a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 31 May 2018 00:56:32 +0200 Subject: [PATCH 053/115] rpc: prevent any dump command --- web/yaamp/core/rpc/wallet-rpc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/rpc/wallet-rpc.php b/web/yaamp/core/rpc/wallet-rpc.php index 70104fbc6..533bb13aa 100644 --- a/web/yaamp/core/rpc/wallet-rpc.php +++ b/web/yaamp/core/rpc/wallet-rpc.php @@ -55,6 +55,12 @@ function __construct($userOrCoin, $pw='', $host='localhost', $port=8332, $url=nu function __call($method, $params) { + if (stripos($method, "dump") !== false) { + $this->error = "$method not authorized!"; + debuglog("$method rpc method is not authorized!"); + return false; + } + if ($this->type == 'Ethereum') { if (!isset($this->accounts)) { $this->accounts = $this->rpc->eth_accounts(); @@ -64,11 +70,6 @@ function __call($method, $params) // if wallet is stopped return false; } - if (stripos($method, "key") !== false) { - $this->error = "$method not authorized!"; - debuglog("$method not authorized (key)!"); - return false; - } // convert common methods used by yiimp switch ($method) { case 'getaccountaddress': From b0a0e53293d81cd3a2f86df64aa8b1749fd5dd87 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 31 May 2018 15:11:01 +0200 Subject: [PATCH 054/115] rpc: also prevent dangerous methods in core btc class --- web/yaamp/core/rpc/easybitcoin.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/yaamp/core/rpc/easybitcoin.php b/web/yaamp/core/rpc/easybitcoin.php index 59d834202..5021887f0 100644 --- a/web/yaamp/core/rpc/easybitcoin.php +++ b/web/yaamp/core/rpc/easybitcoin.php @@ -135,6 +135,11 @@ function __call($method, $params) // The ID should be unique for each call $this->id++; + if (stripos($method, 'dump') !== false) { + $this->error = "$method method is not authorized!"; + return FALSE; + } + // If no parameters are passed, this will be an empty array if($method == 'getblocktemplate') { From ba20dc3ffaaa7a705bae3c7adc91e756afcb4219 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 1 Jun 2018 18:11:28 +0200 Subject: [PATCH 055/115] stratum: check if blocknotify string param is set --- stratum/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 37232e404..3308b9f27 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -291,7 +291,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) { // password, id, block hash - if(json_params->u.array.length < 3) + if(json_params->u.array.length < 3 || !json_params->u.array.values[0]->u.string.ptr) { clientlog(client, "update block, bad params"); return false; From 411a6c734301edb430d5a4d2983d004646c8f50a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 3 Jun 2018 18:41:33 +0200 Subject: [PATCH 056/115] stratum: more string params checks --- stratum/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 3308b9f27..3c2bd94ca 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -202,7 +202,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) return false; } - if(json_params->u.array.length>1) + if(json_params->u.array.length>1 && json_params->u.array.values[1]->u.string.ptr) strncpy(client->password, json_params->u.array.values[1]->u.string.ptr, 1023); if (g_list_client.count >= g_stratum_max_cons) { @@ -210,7 +210,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) return false; } - if(json_params->u.array.length>0) + if(json_params->u.array.length>0 && json_params->u.array.values[0]->u.string.ptr) { strncpy(client->username, json_params->u.array.values[0]->u.string.ptr, 1023); From 5e0f1e1d1c3e78871caab853edfc08137ae66ef1 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 6 Jun 2018 18:28:17 +0200 Subject: [PATCH 057/115] handle phi2 algo --- stratum/algos/makefile | 2 +- stratum/algos/phi2.c | 62 ++++++++++++++++++++++++++++++ stratum/algos/phi2.h | 16 ++++++++ stratum/config.sample/phi2.conf | 16 ++++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 ++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/phi2.c create mode 100644 stratum/algos/phi2.h create mode 100644 stratum/config.sample/phi2.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index d7c296f9c..90b261425 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -19,7 +19,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c + phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/algos/phi2.c b/stratum/algos/phi2.c new file mode 100644 index 000000000..59d34bb5d --- /dev/null +++ b/stratum/algos/phi2.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "gost.h" + +#include "Lyra2.h" + +#include "common.h" + +void phi2_hash(const char* input, char* output, uint32_t len) +{ + unsigned char _ALIGN(128) hash[128] = { 0 }; + unsigned char _ALIGN(128) hashA[64] = { 0 }; + unsigned char _ALIGN(128) hashB[64] = { 0 }; + + sph_cubehash512_context ctx_cubehash; + sph_jh512_context ctx_jh; + sph_gost512_context ctx_gost; + sph_echo512_context ctx_echo; + sph_skein512_context ctx_skein; + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, input, 80); + sph_cubehash512_close(&ctx_cubehash, (void*)hashB); + + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, (const void*)hashA, 64); + sph_jh512_close(&ctx_jh, (void*)hash); + + if (hash[0] & 1) { + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, (const void*)hash, 64); + sph_gost512_close(&ctx_gost, (void*)hash); + } else { + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*)hash, 64); + sph_echo512_close(&ctx_echo, (void*)hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*)hash, 64); + sph_echo512_close(&ctx_echo, (void*)hash); + } + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, (const void*)hash, 64); + sph_skein512_close(&ctx_skein, (void*)hash); + + for (int i=0; i<32; i++) + hash[i] ^= hash[i+32]; + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/phi2.h b/stratum/algos/phi2.h new file mode 100644 index 000000000..d551d2849 --- /dev/null +++ b/stratum/algos/phi2.h @@ -0,0 +1,16 @@ +#ifndef PHI2_H +#define PHI2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void phi2_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/phi2.conf b/stratum/config.sample/phi2.conf new file mode 100644 index 000000000..f96111283 --- /dev/null +++ b/stratum/config.sample/phi2.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 8332 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = phi2 +difficulty = 1 +max_ttf = 40000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 4fcba4015..f1f0c61bd 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -158,6 +158,7 @@ YAAMP_ALGO g_algos[] = {"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex }, {"keccakc", keccak256_hash, 0x100, 0, 0}, {"phi", phi_hash, 1, 0, 0}, + {"phi2", phi2_hash, 0x100, 0, 0}, {"polytimos", polytimos_hash, 1, 0, 0}, {"skunk", skunk_hash, 1, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index b4b6fe7a8..0cdf9c39b 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -196,6 +196,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/sib.h" #include "algos/m7m.h" #include "algos/phi.h" +#include "algos/phi2.h" #include "algos/polytimos.h" #include "algos/tribus.h" #include "algos/veltor.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index e7adae219..c9a96e014 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -49,6 +49,7 @@ function yaamp_get_algos() 'myr-gr', 'm7m', 'phi', + 'phi2', 'sib', 'skein', 'skein2', @@ -173,6 +174,7 @@ function getAlgoColors($algo) 'lyra2v2' => '#80c0f0', 'lyra2z' => '#80b0f0', 'phi' => '#a0a0e0', + 'phi2' => '#a0a0e0', 'polytimos' => '#dedefe', 'sib' => '#a0a0c0', 'skein' => '#80a0a0', @@ -263,6 +265,7 @@ function getAlgoPort($algo) 'bastion' => 6433, 'hsr' => 7433, 'phi' => 8333, + 'phi2' => 8332, 'polytimos' => 8463, 'skunk' => 8433, 'tribus' => 8533, From 8841bf4201387fcfb046f6ca6ec950c494cbed93 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 6 Jun 2018 13:38:20 -0300 Subject: [PATCH 058/115] explorer: support for DUO multialgo (#272) --- web/yaamp/modules/explorer/util.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index 39ce81fb0..ed7db0736 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -160,6 +160,9 @@ function versionToAlgo($coin, $version) $algos['DGC'] = array( 0=>'scrypt', 1=>'sha256', 2=>'x11' ); + $algos['DUO'] = array( + 0=>'sha256', 1=>'scrypt' + ); $algos['J'] = array( 2 =>'sha256', 3=>'x11', 4=>'x13', 5=>'x15', 6=>'scrypt', 7 =>'nist5', 8 =>'myr-gr', 9=>'penta', 10=>'whirlpool', From 6e874602165511d2b83d6c1c55bcfe669105349e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 7 Jun 2018 11:07:16 +0200 Subject: [PATCH 059/115] stratum: reduce valid ntime range --- stratum/client_submit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 78fc94cb0..c3f19d60a 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -339,10 +339,10 @@ static bool ntime_valid_range(const char ntimehex[]) uint32_t ntime = 0; if (strlen(ntimehex) != 8) return false; sscanf(ntimehex, "%8x", &ntime); - if (ntime < 0x57000000 || ntime > 0x60000000) // 14 Jan 2021 - ntime = bswap32(ntime); // just in case... + if (ntime < 0x5b000000 || ntime > 0x60000000) // 14 Jan 2021 + return false; time(&rawtime); - return ((rawtime - ntime) < (23 * 60 * 60)); + return (abs(rawtime - ntime) < (30 * 60)); } bool client_submit(YAAMP_CLIENT *client, json_value *json_params) From eee06c920b1ca70b66fb78c1b2f3bf35a8de674d Mon Sep 17 00:00:00 2001 From: itamarcps <32653934+itamarcps@users.noreply.github.com> Date: Fri, 8 Jun 2018 14:49:48 -0300 Subject: [PATCH 060/115] stratum: add aergo algo (#274) + spaces fixes --- stratum/algos/aergo.c | 162 +++++++++++++++++++++++++++++ stratum/algos/aergo.h | 17 +++ stratum/algos/makefile | 2 +- stratum/config.sample/aergo.conf | 15 +++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 7 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/aergo.c create mode 100644 stratum/algos/aergo.h create mode 100644 stratum/config.sample/aergo.conf diff --git a/stratum/algos/aergo.c b/stratum/algos/aergo.c new file mode 100644 index 000000000..7a791846c --- /dev/null +++ b/stratum/algos/aergo.c @@ -0,0 +1,162 @@ +#include "aergo.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gost.h" + +#include "common.h" + +void aergo_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hash[16]; + + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_skein512_context ctx_skein; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_hamsi512_context ctx_hamsi; + sph_fugue512_context ctx_fugue; + sph_shabal512_context ctx_shabal; + sph_gost512_context ctx_gost; + sph_whirlpool_context ctx_whirlpool; + sph_haval256_5_context ctx_haval; + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, input, len); + sph_echo512_close(&ctx_echo, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, hash, 64); + sph_blake512_close(&ctx_blake, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_whirlpool_init(&ctx_whirlpool); + sph_whirlpool(&ctx_whirlpool, hash, 64); + sph_whirlpool_close(&ctx_whirlpool, hash); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, hash, 64); + sph_groestl512_close(&ctx_groestl, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, hash, 64); + sph_skein512_close(&ctx_skein, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, hash, 64); + sph_luffa512_close(&ctx_luffa, hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, hash, 64); + sph_keccak512_close(&ctx_keccak, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, hash, 64); + sph_hamsi512_close(&ctx_hamsi, hash); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512(&ctx_fugue, hash, 64); + sph_fugue512_close(&ctx_fugue, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_shabal512_init(&ctx_shabal); + sph_shabal512(&ctx_shabal, hash, 64); + sph_shabal512_close(&ctx_shabal, hash); + + sph_haval256_5_init(&ctx_haval); + sph_haval256_5(&ctx_haval,(const void*) hash, 64); + sph_haval256_5_close(&ctx_haval, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, hash, 64); + sph_blake512_close(&ctx_blake, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/aergo.h b/stratum/algos/aergo.h new file mode 100644 index 000000000..ad129b32a --- /dev/null +++ b/stratum/algos/aergo.h @@ -0,0 +1,17 @@ + +#ifndef AERGO_H +#define AERGO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void aergo_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 90b261425..612d5087f 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -19,7 +19,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ hive.c pomelo.c \ - phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c + phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c aergo.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/config.sample/aergo.conf b/stratum/config.sample/aergo.conf new file mode 100644 index 000000000..c7488e3a7 --- /dev/null +++ b/stratum/config.sample/aergo.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 3691 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = aergo +difficulty = 0.001 +max_ttf = 400000000 \ No newline at end of file diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index f1f0c61bd..26fd17561 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -179,6 +179,7 @@ YAAMP_ALGO g_algos[] = {"velvet", velvet_hash, 0x10000, 0, 0}, {"argon2", argon2_hash, 0x10000, 0, sha256_hash_hex }, {"vitalium", vitalium_hash, 1, 0, 0}, + {"aergo", aergo_hash, 1, 0, 0}, {"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x diff --git a/stratum/stratum.h b/stratum/stratum.h index 0cdf9c39b..549084f40 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -203,4 +203,5 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/velvet.h" #include "algos/argon2a.h" #include "algos/vitalium.h" +#include "algos/aergo.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index c9a96e014..4307f8a97 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -10,6 +10,7 @@ function yaamp_get_algos() 'scryptn', 'allium', 'argon2', + 'aergo', 'bastion', 'bitcore', 'blake', @@ -152,6 +153,7 @@ function getAlgoColors($algo) 'xevan' => '#f0b0a0', 'allium' => '#80a0d0', 'argon2' => '#e0d0e0', + 'aergo' => '#e0d0e0', 'bastion' => '#e0b0b0', 'blake' => '#f0f0f0', 'blakecoin' => '#f0f0f0', @@ -222,6 +224,7 @@ function getAlgoPort($algo) 'x16r' => 3636, 'x16s' => 3663, 'x17' => 3737, + 'aergo' => 3691, 'xevan' => 3739, 'hmq1725' => 3747, 'nist5' => 3833, From 035d304150073ca05826148074f66a05b60d58db Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 9 Jun 2018 08:20:17 +0200 Subject: [PATCH 061/115] checkup: delete images containing cloudcrap scripts + +END; +?> From 8a168dcffedf0d835d47c4332568e6cf27ab7ed1 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Tue, 21 Aug 2018 04:06:46 +0200 Subject: [PATCH 093/115] Update defaultconfig.php --- web/yaamp/defaultconfig.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index e89fe79b0..912baff85 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -74,11 +74,15 @@ // Lightning Network if (!defined('LN_ENABLED')) define('LN_ENABLED', false); -if (!defined('LN_ENABLED')) define('LN_MY_BTC_ADDRESS', ''); -if (!defined('LN_ENABLED')) define('LN_MY_LN_ADDRESS', ''); -if (!defined('LN_ENABLED')) define('LN_MY_IP', ''); -if (!defined('LN_ENABLED')) define('LN_MY_PORT', '9735'); -if (!defined('LN_ENABLED')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels -if (!defined('LN_ENABLED')) define('LN_MIN_PAY', 3000); -if (!defined('LN_ENABLED')) define('LN_MIN_PAY', 10000); +if (!defined('LN_MY_BTC_ADDRESS')) define('LN_MY_BTC_ADDRESS', ''); +if (!defined('LN_MY_LN_ADDRESS')) define('LN_MY_LN_ADDRESS', ''); +if (!defined('LN_MY_IP')) define('LN_MY_IP', ''); +if (!defined('LN_MY_PORT')) define('LN_MY_PORT', '9735'); +if (!defined('LN_FRACTION')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels +if (!defined('LN_MIN_PAY')) define('LN_MIN_PAY', 3000); +if (!defined('LN_MAIN_NODE')) define('LN_MAIN_NODE', ''); +if (!isset($configLNGamePlayers)) $configLNGamePlayers = array ( + 'testnet.millionbitcoinhomepage.net' => array('023bcc1daeb7c85208991e993a2eacf86f7d9584a6dc33291bbe5e19c986a31568', '51.15.250.152', '9735'), + 'yalls.org' => array('02212d3ec887188b284dbb7b2e6eb40629a6e14fb049673f22d2a0aa05f902090e', '54.236.55.50', '9735'), + 'testnet.satoshis.place' => array('02dd4cef0192611bc34cd1c3a0a7eb0f381e7229aa3309ae961a7fc0076b4d2bb6', '35.198.136.5', '9735')); From f0c26f165e22f5c20e341f58a202b342f7797133 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Wed, 29 Aug 2018 03:07:24 +0200 Subject: [PATCH 094/115] Update rc.local --- rc.local | 1 + 1 file changed, 1 insertion(+) diff --git a/rc.local b/rc.local index dec333643..9dea15bd2 100644 --- a/rc.local +++ b/rc.local @@ -15,6 +15,7 @@ STRATUM_DIR=/var/stratum screen -dmS main $WEB_DIR/main.sh screen -dmS loop2 $WEB_DIR/loop2.sh screen -dmS blocks $WEB_DIR/blocks.sh +#screen -dmS ln $WEB_DIR/ln.sh screen -dmS debug tail -f $LOG_DIR/debug.log # Stratum instances (skipped/exit if no .conf) From 3f3c2a4995309780425c5b493624503a10aa3217 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 15:46:39 +0200 Subject: [PATCH 095/115] new column 'work' into workers table --- sql/2018-08-lightning-testnet.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/2018-08-lightning-testnet.sql b/sql/2018-08-lightning-testnet.sql index bcd29cb4a..6e296103f 100644 --- a/sql/2018-08-lightning-testnet.sql +++ b/sql/2018-08-lightning-testnet.sql @@ -8,3 +8,5 @@ CREATE TABLE `invoices` ( `status` varchar(80) DEFAULT NULL, `exectime` int(10) UNSIGNED NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `workers` ADD `work` DOUBLE NOT NULL DEFAULT '0.0' AFTER `algo`; From 4e6b66cec8f4d9424e806e39bb88080421c20334 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 15:49:00 +0200 Subject: [PATCH 096/115] YAAMP_LN_WORKERS & YAAMP_LN_FACTOR --- web/yaamp/defaultconfig.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 912baff85..b57c9b71c 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -81,6 +81,8 @@ if (!defined('LN_FRACTION')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels if (!defined('LN_MIN_PAY')) define('LN_MIN_PAY', 3000); if (!defined('LN_MAIN_NODE')) define('LN_MAIN_NODE', ''); +if (!define('YAAMP_LN_WORKERS')) define('YAAMP_LN_WORKERS', false); +if (!define('YAAMP_LN_FACTOR')) define('YAAMP_LN_FACTOR', 0.8); if (!isset($configLNGamePlayers)) $configLNGamePlayers = array ( 'testnet.millionbitcoinhomepage.net' => array('023bcc1daeb7c85208991e993a2eacf86f7d9584a6dc33291bbe5e19c986a31568', '51.15.250.152', '9735'), From 2a271493041a4f364471914a4faa2f8e9cea06f7 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 15:53:17 +0200 Subject: [PATCH 097/115] accounting per worker: to verify & enhance! --- web/yaamp/core/backend/blocks.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/yaamp/core/backend/blocks.php b/web/yaamp/core/backend/blocks.php index 8b82548d2..ca5c0bcf5 100644 --- a/web/yaamp/core/backend/blocks.php +++ b/web/yaamp/core/backend/blocks.php @@ -61,6 +61,12 @@ function BackendBlockNew($coin, $db_block) $user->save(); } + $target = yaamp_hashrate_constant($coin->algo); + $interval = yaamp_hashrate_step(); + $delay = time()-$interval; + + dborun("UPDATE workers w SET work = w.work + (SELECT (sum(difficulty) * $target / $interval / 1000) FROM shares WHERE valid AND time>".time()-$interval." AND workerid=w.id)"); + $delay = time() - 5*60; $sqlCond = "time < $delay"; if(!YAAMP_ALLOW_EXCHANGE) // only one coin mined From c6ac57d7e7d196758b4b77d489281b270361411c Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 16:38:00 +0200 Subject: [PATCH 098/115] LN invoices for mainet: to verify&enhance --- web/yaamp/core/backend/payment.php | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/web/yaamp/core/backend/payment.php b/web/yaamp/core/backend/payment.php index b3704ea95..09abacc4b 100644 --- a/web/yaamp/core/backend/payment.php +++ b/web/yaamp/core/backend/payment.php @@ -32,6 +32,14 @@ function BackendUserCancelFailedPayment($userid) return 0.0; } +function is_ln_invoice($bill) +{ +if (!empty($bill) && preg_match('/[^A-Za-z0-9]/', $bill)) + return false; +else + return true; // TODO: Enhance the check of the bolt11 invoice (length, first characters, ...) +} + function BackendCoinPayments($coin) { // debuglog("BackendCoinPayments $coin->symbol"); @@ -106,6 +114,34 @@ function BackendCoinPayments($coin) { $total_to_pay += round($user->balance, 8); $addresses[$user->username] = round($user->balance, 8); + if ($coin->symbol=='BTC' && YAAMP_LN_WORKERS == true) { + $ln_works = getdbolist('db_workers', "work > 0 AND worker <> '' AND userid=".$user->id); + foreach($ln_works as $ln_work) { + if (is_ln_invoice($ln_work->worker)) { + $output = shell_exec('sudo lightning-cli -J decodepay '.$ln_work->worker); + $bill = json_decode($output); + // TODO: Enhance and add pool fee + if ($ln_work->work * YAAMP_LN_FACTOR > $bill->msatoshi / 1000 && $user->balance > $bill->msatoshi / 1000) { + $db_bill = getdbosql('db_invoices', "bolt11=:bolt11", array(':bolt11'=>$ln_work->worker)); + if (!$db_bill) { + dborun("INSERT IGNORE INTO invoices(bolt11, status) VALUES (:key,:val)", array( + ':key'=>$bill,':val'=>"New" + )); + } + if ($db_bill && $db_bill->status == "complete") { + // Invoice is already paid, no need to change total_to_pay and addresses + } + else { + // Invoice is not paid yet: some value should be kept to pay it + // TODO: Add pool fee + $total_to_pay -= round($bill->msatoshi / 1000, 8); + $addresses[$user->username] -= round($bill->msatoshi / 1000, 8); + } + } + } + } + } + // transaction xxx has too many sigops: 1035 > 1000 if ($coin->symbol == 'DCR' && count($addresses) > 990) { debuglog("payment: more than 990 {$coin->symbol} users to pay, limit to top balances..."); From a97e19d4ca391fc653d7c4535920d289c3151b86 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 16:41:07 +0200 Subject: [PATCH 099/115] LN webpage restricted to admin --- web/yaamp/modules/site/SiteController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index 709845713..c4bc2911b 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -1194,6 +1194,7 @@ public function actionMainbtc() public function actionLn() { + if(LN_ENABLED == false || !$this->admin) return; $this->render('/site/ln'); } } From 684ebb1d3a99d290117051a442ab412f5cba660b Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 1 Sep 2018 16:45:43 +0200 Subject: [PATCH 100/115] LN webpage only for admin --- web/yaamp/ui/main.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/yaamp/ui/main.php b/web/yaamp/ui/main.php index 693791d2f..770022b76 100644 --- a/web/yaamp/ui/main.php +++ b/web/yaamp/ui/main.php @@ -120,6 +120,10 @@ function showPageHeader() if (YAAMP_USE_NICEHASH_API) showItemHeader(controller()->id=='nicehash', '/nicehash', 'Nicehash'); + + if (LN_ENABLED) + showItemHeader(controller()->id=='ln', '/site/ln', 'LN'); + } echo ''; From e6a8e9d65aa3d0c7b5bdaefa092f174d588c497b Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 00:48:22 +0200 Subject: [PATCH 101/115] invoice per userid --- sql/2018-08-lightning-testnet.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/2018-08-lightning-testnet.sql b/sql/2018-08-lightning-testnet.sql index 6e296103f..1fb666e19 100644 --- a/sql/2018-08-lightning-testnet.sql +++ b/sql/2018-08-lightning-testnet.sql @@ -1,5 +1,6 @@ CREATE TABLE `invoices` ( `id` int(11) NOT NULL, + `userid` int(11) NOT NULL, `bolt11` varchar(1000) NOT NULL, `amount` int(11) NOT NULL, `paid` int(11) NOT NULL, From 64edc94a821a9eea75df72ee1c9a9cac57f79ac7 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 00:50:09 +0200 Subject: [PATCH 102/115] Update defaultconfig.php --- web/yaamp/defaultconfig.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index b57c9b71c..f180e471d 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -85,6 +85,10 @@ if (!define('YAAMP_LN_FACTOR')) define('YAAMP_LN_FACTOR', 0.8); if (!isset($configLNGamePlayers)) $configLNGamePlayers = array ( + /* + // testnet: 'testnet.millionbitcoinhomepage.net' => array('023bcc1daeb7c85208991e993a2eacf86f7d9584a6dc33291bbe5e19c986a31568', '51.15.250.152', '9735'), 'yalls.org' => array('02212d3ec887188b284dbb7b2e6eb40629a6e14fb049673f22d2a0aa05f902090e', '54.236.55.50', '9735'), - 'testnet.satoshis.place' => array('02dd4cef0192611bc34cd1c3a0a7eb0f381e7229aa3309ae961a7fc0076b4d2bb6', '35.198.136.5', '9735')); + 'testnet.satoshis.place' => array('02dd4cef0192611bc34cd1c3a0a7eb0f381e7229aa3309ae961a7fc0076b4d2bb6', '35.198.136.5', '9735') + */ + ); From 6afcad3fa78fdbf3716905c431a3030068616f25 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:14:35 +0200 Subject: [PATCH 103/115] Update payment.php --- web/yaamp/core/backend/payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/payment.php b/web/yaamp/core/backend/payment.php index 09abacc4b..1e7573f13 100644 --- a/web/yaamp/core/backend/payment.php +++ b/web/yaamp/core/backend/payment.php @@ -114,7 +114,7 @@ function BackendCoinPayments($coin) { $total_to_pay += round($user->balance, 8); $addresses[$user->username] = round($user->balance, 8); - if ($coin->symbol=='BTC' && YAAMP_LN_WORKERS == true) { + if ($coin->symbol=='BTC' && LN_ENABLED == true && YAAMP_LN_WORKERS == true) { $ln_works = getdbolist('db_workers', "work > 0 AND worker <> '' AND userid=".$user->id); foreach($ln_works as $ln_work) { if (is_ln_invoice($ln_work->worker)) { From b2e7d2117901125d5641d085c822ce3123fb5ac8 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:15:36 +0200 Subject: [PATCH 104/115] Update defaultconfig.php --- web/yaamp/defaultconfig.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index f180e471d..195b30e85 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -81,6 +81,7 @@ if (!defined('LN_FRACTION')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels if (!defined('LN_MIN_PAY')) define('LN_MIN_PAY', 3000); if (!defined('LN_MAIN_NODE')) define('LN_MAIN_NODE', ''); +if (!define('YAAMP_LN_NET')) define('YAAMP_LN_NET', 'TESTNET'); // TESTNET or MAINET if (!define('YAAMP_LN_WORKERS')) define('YAAMP_LN_WORKERS', false); if (!define('YAAMP_LN_FACTOR')) define('YAAMP_LN_FACTOR', 0.8); From 7fecdd4e79c86e90ddb0509127d6242e5538cd2c Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:17:50 +0200 Subject: [PATCH 105/115] Display /site/ln for visitors if testnet --- web/yaamp/modules/site/SiteController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index c4bc2911b..c06a571e2 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -1194,7 +1194,7 @@ public function actionMainbtc() public function actionLn() { - if(LN_ENABLED == false || !$this->admin) return; + if(LN_ENABLED == false || (YAAMP_LN_NET == 'MAINET' && !$this->admin)) return; $this->render('/site/ln'); } } From 66fd97be224ae16c9fbaf5735e8f9250cbba1c3a Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:20:40 +0200 Subject: [PATCH 106/115] Update main.php --- web/yaamp/ui/main.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/yaamp/ui/main.php b/web/yaamp/ui/main.php index 770022b76..7cff2039e 100644 --- a/web/yaamp/ui/main.php +++ b/web/yaamp/ui/main.php @@ -121,11 +121,13 @@ function showPageHeader() if (YAAMP_USE_NICEHASH_API) showItemHeader(controller()->id=='nicehash', '/nicehash', 'Nicehash'); - if (LN_ENABLED) + if (YAAMP_LN_ENABLED) showItemHeader(controller()->id=='ln', '/site/ln', 'LN'); - } - + + if (YAAMP_LN_ENABLED && YAAMP_LN_NET == 'TESTNET' && !controller()->admin) + showItemHeader(controller()->id=='ln', '/site/ln', 'LN (testnet)'); + echo ''; $mining = getdbosql('db_mining'); From 79104c9522eeb392f82effa1de548c0067cf3a2b Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:21:54 +0200 Subject: [PATCH 107/115] Update main.php --- web/yaamp/ui/main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/yaamp/ui/main.php b/web/yaamp/ui/main.php index 7cff2039e..68be000cd 100644 --- a/web/yaamp/ui/main.php +++ b/web/yaamp/ui/main.php @@ -121,11 +121,11 @@ function showPageHeader() if (YAAMP_USE_NICEHASH_API) showItemHeader(controller()->id=='nicehash', '/nicehash', 'Nicehash'); - if (YAAMP_LN_ENABLED) + if (LN_ENABLED) showItemHeader(controller()->id=='ln', '/site/ln', 'LN'); } - if (YAAMP_LN_ENABLED && YAAMP_LN_NET == 'TESTNET' && !controller()->admin) + if (LN_ENABLED && YAAMP_LN_NET == 'TESTNET' && !controller()->admin) showItemHeader(controller()->id=='ln', '/site/ln', 'LN (testnet)'); echo ''; From 4ff7228ec5444417fcfcfb2167242d0e9ba11d6e Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:22:53 +0200 Subject: [PATCH 108/115] Update defaultconfig.php --- web/yaamp/defaultconfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 195b30e85..bd6172fe6 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -79,7 +79,7 @@ if (!defined('LN_MY_IP')) define('LN_MY_IP', ''); if (!defined('LN_MY_PORT')) define('LN_MY_PORT', '9735'); if (!defined('LN_FRACTION')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels -if (!defined('LN_MIN_PAY')) define('LN_MIN_PAY', 3000); +if (!defined('LN_MIN_PAY')) define('LN_MIN_PAY', 1000); // min payout in satoshis if (!defined('LN_MAIN_NODE')) define('LN_MAIN_NODE', ''); if (!define('YAAMP_LN_NET')) define('YAAMP_LN_NET', 'TESTNET'); // TESTNET or MAINET if (!define('YAAMP_LN_WORKERS')) define('YAAMP_LN_WORKERS', false); From 43e7a3da615a622c33515c2f59948f1e610a56a8 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:24:11 +0200 Subject: [PATCH 109/115] Update CronjobController.php --- web/yaamp/modules/thread/CronjobController.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index ec8731120..7be813779 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -39,15 +39,7 @@ private function monitorApache() } } - public function actionRunStartLightning() - { - debuglog(__METHOD__); - set_time_limit(0); - $output = shell_exec('lightningd --bitcoin-rpcconnect=192.168.10.35 --bitcoin-rpcuser=bitcoin --bitcoin-rpcpassword=Test'); - $output = json_decode($output); - debuglog($output); - } - + public function actionRunLightning() { debuglog(__METHOD__); From 893ea213bba91220ec20e48cf978f33243e2712d Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:35:22 +0200 Subject: [PATCH 110/115] Update index.php --- web/yaamp/modules/site/index.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/yaamp/modules/site/index.php b/web/yaamp/modules/site/index.php index a1888b8ce..8b4141e7a 100644 --- a/web/yaamp/modules/site/index.php +++ b/web/yaamp/modules/site/index.php @@ -67,6 +67,17 @@
  • As optional password, you can use -p c=<SYMBOL> if yiimp does not set the currency correctly on the Wallet page.
  • See the "Pool Status" area on the right for PORT numbers. Algorithms without associated coins are disabled.
  • + +Lightning Network payments are enabled on this pool on . You can send Lightning Network invoices using LN page'; +if (YAAMP_LN_NET == 'TESTNET' && YAAMP_LN_WORKERS == true) echo ' or '; +if (YAAMP_LN_WORKERS == true) { + ?>the workername to send the invoice. Example: +

    + -o stratum+tcp://:<PORT> -u <WALLET_ADDRESS>.<invoice> [-p <OPTIONS>]

    +
    From 81e7d520479effc9a2b5b7e027784004d68e6078 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Mon, 3 Sep 2018 16:13:13 +0200 Subject: [PATCH 111/115] Update index.php --- web/yaamp/modules/site/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/modules/site/index.php b/web/yaamp/modules/site/index.php index 8b4141e7a..824eaffd2 100644 --- a/web/yaamp/modules/site/index.php +++ b/web/yaamp/modules/site/index.php @@ -75,6 +75,7 @@ ?>the workername to send the invoice. Example:

    -o stratum+tcp://:<PORT> -u <WALLET_ADDRESS>.<invoice> [-p <OPTIONS>]

    + Lightning Network invoices can be generated from a LN wallet or directly on a merchant's website (List of merchants (mainet), List of merchants (testnet)). From 0f3dc2fd13cab0143c5dcb82320a1eb1f1fa832a Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Mon, 3 Sep 2018 16:38:11 +0200 Subject: [PATCH 112/115] Update defaultconfig.php --- web/yaamp/defaultconfig.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index bd6172fe6..7d95e97f6 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -76,6 +76,7 @@ if (!defined('LN_ENABLED')) define('LN_ENABLED', false); if (!defined('LN_MY_BTC_ADDRESS')) define('LN_MY_BTC_ADDRESS', ''); if (!defined('LN_MY_LN_ADDRESS')) define('LN_MY_LN_ADDRESS', ''); +if (!defined('LN_COIN')) define('LN_COIN', 'BTC'); if (!defined('LN_MY_IP')) define('LN_MY_IP', ''); if (!defined('LN_MY_PORT')) define('LN_MY_PORT', '9735'); if (!defined('LN_FRACTION')) define('LN_FRACTION', 7); // Fraction of main BTC wallet to fund channels From a1e1fecda5a42697bbc30afafd9e673275d94c38 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Mon, 3 Sep 2018 16:39:08 +0200 Subject: [PATCH 113/115] Update payment.php --- web/yaamp/core/backend/payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/payment.php b/web/yaamp/core/backend/payment.php index 1e7573f13..3f2915857 100644 --- a/web/yaamp/core/backend/payment.php +++ b/web/yaamp/core/backend/payment.php @@ -114,7 +114,7 @@ function BackendCoinPayments($coin) { $total_to_pay += round($user->balance, 8); $addresses[$user->username] = round($user->balance, 8); - if ($coin->symbol=='BTC' && LN_ENABLED == true && YAAMP_LN_WORKERS == true) { + if ($coin->symbol==LN_COIN && LN_ENABLED == true && YAAMP_LN_WORKERS == true) { $ln_works = getdbolist('db_workers', "work > 0 AND worker <> '' AND userid=".$user->id); foreach($ln_works as $ln_work) { if (is_ln_invoice($ln_work->worker)) { From 4d2ed2ba0a132da817dcca79a6ad03da28eca136 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Mon, 3 Sep 2018 17:01:53 +0200 Subject: [PATCH 114/115] Update CronjobController.php --- .../modules/thread/CronjobController.php | 367 +++++++++--------- 1 file changed, 182 insertions(+), 185 deletions(-) diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 7be813779..0f7b026ca 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -42,123 +42,121 @@ private function monitorApache() public function actionRunLightning() { - debuglog(__METHOD__); - set_time_limit(0); + debuglog(__METHOD__); + set_time_limit(0); // $this->monitorApache(); - $last_complete = memcache_get($this->memcache->memcache, "cronjob_ln_time_start"); - - // debuglog("Lightning turned on ?"); - $output = shell_exec('sudo lightning-cli -J getinfo'); - $output = json_decode($output); + $last_complete = memcache_get($this->memcache->memcache, "cronjob_ln_time_start"); - $lightning = false; - foreach ($output as $key => $out) - { - if ($key == 'id') { - debuglog("[LN] 1. Lightning is turned ON: OK"); - debuglog("[LN] My LN id = $out"); - $lightning = true; - } - } - if (!$lightning) - debuglog("[LN] Error: Please run lightningd in a screen"); - else { + // debuglog("Lightning turned on ?"); + $output = shell_exec('sudo lightning-cli -J getinfo'); + $output = json_decode($output); - - debuglog("[LN] 2. Check LN BTC address"); - $outpute = shell_exec("sudo lightning-cli -J dev-listaddrs"); - $output = json_decode($outpute); - //debuglog("ok"); -// debuglog($outpute); - - $found = false; - //if (isset($output->addresses)) - foreach ($output->addresses as $out) { + $lightning = false; + foreach ($output as $key => $out) + { + if ($key == 'id') { + debuglog("[LN] 1. Lightning is turned ON: OK"); + debuglog("[LN] My LN id = $out"); + $lightning = true; + } + } + if (!$lightning) + debuglog("[LN] Error: Please run lightningd in a screen"); + else { + debuglog("[LN] 2. Check LN BTC address"); + $outpute = shell_exec("sudo lightning-cli -J dev-listaddrs"); + $output = json_decode($outpute); + //debuglog("ok"); +// debuglog($outpute); + + $found = false; + //if (isset($output->addresses)) + foreach ($output->addresses as $out) { // debuglog("in"); // value = ".$out["value"]." status = ".$out["status"]); - if (LN_MY_BTC_ADDRESS == $out->p2sh) { - $found = true; - debuglog("[LN] LN_MY_BTC_ADDRESS found and own : OK"); - break; - } - } - if ($found == false) { - debuglog("[LN] Error: Please create a p2sh-segwit address using lightning-cli newaddr then fill LN_MY_BTC_ADDRESS"); - } - else { - - debuglog("[LN] 3. Check funds"); - - $output = shell_exec("sudo lightning-cli -J listfunds"); - $listfunds = json_decode($output); + if (LN_MY_BTC_ADDRESS == $out->p2sh) { + $found = true; + debuglog("[LN] LN_MY_BTC_ADDRESS found and own : OK"); + break; + } + } + if ($found == false) { + debuglog("[LN] Error: Please create a p2sh-segwit address using lightning-cli newaddr then fill LN_MY_BTC_ADDRESS"); + } + else { + debuglog("[LN] 3. Check funds"); // TODO: Enhance the logic + + $output = shell_exec("sudo lightning-cli -J listfunds"); + $listfunds = json_decode($output); // debuglog($output); - $ln_balance = 0; + $ln_balance = 0; - $found = false; - if (count($listfunds->outputs) > 0) - foreach ($listfunds->outputs as $out) { + $found = false; + if (count($listfunds->outputs) > 0) + foreach ($listfunds->outputs as $out) { // debuglog("in"); // value = ".$out["value"]." status = ".$out["status"]); - if ($out->status == "unconfirmed" && $out->output == 1 && count($listfunds->channels) > 0) { - debuglog("[LN] Channel creation ongoing"); - $found = true; - } + if ($out->status == "unconfirmed" && $out->output == 1 && count($listfunds->channels) > 0) { + debuglog("[LN] Channel creation ongoing"); + $found = true; + } - if ($out->status == "confirmed" && $out->output == 1 && count($listfunds->channels) > 0 && $out->value > 100) { - $ln_balance = $out->value; - debuglog("[LN] seems ok, to analyse later"); - $found = true; - } - if ("confirmed" == $out->status && 0 == $out->output && count($listfunds->channels) > 0) { - $ln_balance = $out->value; - $found = true; - debuglog("[LN] Initial funding onchain : OK"); - break; - } - } - if ($found == false) { - debuglog("[LN] Error: Please perform a Bitcoin onchain transaction to ".LN_MY_BTC_ADDRESS); -// testnet faucet : https://testnet.manu.backend.hamburg/faucet - } - else { - - debuglog("LN Balance (not in channels) = ".$ln_balance." sat = ".($ln_balance/100000000)." BTC"); - - debuglog("[LN] 4. Check connections"); - - $output = shell_exec('sudo lightning-cli -J listpeers'); - $output = json_decode($output); + if ($out->status == "confirmed" && $out->output == 1 && count($listfunds->channels) > 0 && $out->value > 100) { + $ln_balance = $out->value; + debuglog("[LN] seems ok (logic to enhance)"); + $found = true; + } + if ("confirmed" == $out->status && 0 == $out->output && count($listfunds->channels) > 0) { + $ln_balance = $out->value; + $found = true; + debuglog("[LN] Initial funding onchain : OK"); + break; + } + } + if ($found == false) { + debuglog("[LN] Error: Please perform a Bitcoin onchain transaction to ".LN_MY_BTC_ADDRESS); + // testnet faucet : https://testnet.manu.backend.hamburg/faucet + } + else { + + debuglog("LN Balance (not in channels) = ".$ln_balance." sat = ".($ln_balance/100000000)." BTC"); + + debuglog("[LN] 4. Check connections"); + + $output = shell_exec('sudo lightning-cli -J listpeers'); + $output = json_decode($output); - global $configLNGamePlayers; - foreach ($configLNGamePlayers as $player) { -//debuglog($player[0]); - $connected = false; - foreach ($output->peers as $out) { - if ($out->id == $player[1]) { - debuglog("Connected to player OK"); - $connected = true; - break; - } - } - if ($connected == false) { - debuglog("Connect to player..."); - $ttt = 'sudo lightning-cli -J connect ' . $player[1] . ' ' . $player[2] . ' ' . $player[3]; // . "'"; - //debuglog("OK"); - debuglog($ttt); - - $output = shell_exec($ttt); - debuglog($output); - // todo: handle errors to avoid this peer (into memcache ?) - // -1, "message" : "Connection establishment: Connection timed out - } - } - - debuglog("[LN] 5. Check channels funds : cancelled !"); + global $configLNGamePlayers; + + foreach ($configLNGamePlayers as $player) { + //debuglog($player[0]); + $connected = false; + foreach ($output->peers as $out) { + if ($out->id == $player[1]) { + debuglog("Connected to player OK"); + $connected = true; + break; + } + } + if ($connected == false) { + debuglog("Connect to player..."); + $ttt = 'sudo lightning-cli -J connect ' . $player[1] . ' ' . $player[2] . ' ' . $player[3]; // . "'"; + //debuglog("OK"); + debuglog($ttt); + + $output = shell_exec($ttt); + debuglog($output); + // todo: handle errors to avoid this peer (into memcache ?) + // -1, "message" : "Connection establishment: Connection timed out + } + } + + debuglog("[LN] 5. Check channels funds : cancelled !"); // $output = shell_exec('sudo lightning-cli -J list'); // $output = json_decode($output); - $found = true; + $found = true; /* if (count($listfunds->channels) > 0) foreach ($listfunds->channels as $out) { // debuglog("in"); // value = ".$out["value"]." status = ".$out["status"]); @@ -177,8 +175,8 @@ public function actionRunLightning() } } */ - if ($found == false) { - debuglog("[LN] No channels credited: Channel credit with a fraction of the remaining funds"); + if ($found == false) { + debuglog("[LN] No channels credited: Channel credit with a fraction of the remaining funds"); //foreach ($configLNGamePlayers as $player) { // code : -32602 [message] => 'Funding satoshi must be <= 16777215' // $output = shell_exec('sudo lightning-cli -J fundchannel '.$out->id_peer. ' ' . min( 16777215, round($ln_balance / LN_FRACTION))); @@ -186,9 +184,9 @@ public function actionRunLightning() // debuglog($output); //} - } - else { - debuglog("[LN] 6. Channel open on LN : cancelled !"); + } + else { + debuglog("[LN] 6. Channel open on LN : cancelled !"); /* $outpute = shell_exec('sudo lightning-cli -J listpeers'); $output = json_decode($outpute); @@ -221,18 +219,17 @@ public function actionRunLightning() } debuglog("channels chekcs ended"); */ - if (true) { - debuglog("Payment will be done"); - - if (true) { // $ln_balance > LN_MIN_PAY) { - -$db_bills = dbolist("SELECT bolt11 from invoices WHERE status='New' ORDER by id ASC"); -if (!$db_bills) { - debuglog("Nothing to pay"); - } -else { - debuglog("To pay"); - foreach ($db_bills as $bill) { + if (true) { + debuglog("Payment will be done"); + if (true) { // $ln_balance > LN_MIN_PAY) { + + $db_bills = dbolist("SELECT bolt11 from invoices WHERE status='New' ORDER by id ASC"); + if (!$db_bills) { + debuglog("Nothing to pay"); + } + else { + debuglog("There are LN invoices to pay"); + foreach ($db_bills as $bill) { // debuglog("Bill"); // break; // } @@ -245,65 +242,65 @@ public function actionRunLightning() // debuglog("before"); // debuglog($bill['bolt11']); - $oo = "sudo lightning-cli -J decodepay ".$bill['bolt11']; - debuglog($oo); - $outpute = shell_exec($oo); - $output = json_decode($outpute); - debuglog($outpute); - if (isset($output->message) && $output->message == "Invalid bolt11: Bad bech32 string") { - // debuglog("clean invalid"); - dborun("UPDATE invoices SET status = 'Invalid' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Invoice with invalid bolt11"); - break; - } - if (isset($output->description)) { - dborun("UPDATE invoices SET description = '".addslashes(htmlentities($output->description))."' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Update description"); - } - if (isset($output->payee)) { - dborun("UPDATE invoices SET shop = '".$output->payee."' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Update shop"); - } - if (isset($output->msatoshi)) { - dborun("UPDATE invoices SET amount = '".$output->msatoshi."' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Update amount"); - } - - $oo = "sudo lightning-cli -J pay maxfeepercent=4 maxdelay=1200 bolt11=".$bill['bolt11']; - debuglog($oo); - $outpute = shell_exec($oo); + $oo = "sudo lightning-cli -J decodepay ".$bill['bolt11']; + debuglog($oo); + $outpute = shell_exec($oo); + $output = json_decode($outpute); + debuglog($outpute); + if (isset($output->message) && $output->message == "Invalid bolt11: Bad bech32 string") { + // debuglog("clean invalid"); + dborun("UPDATE invoices SET status = 'Invalid' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Invoice with invalid bolt11"); + break; + } + if (isset($output->description)) { + dborun("UPDATE invoices SET description = '".addslashes(htmlentities($output->description))."' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Update description"); // TODO: add filter to prevent injections here + } + if (isset($output->payee)) { + dborun("UPDATE invoices SET shop = '".$output->payee."' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Update shop"); // TODO: add filter to prevent injections here + } + if (isset($output->msatoshi)) { + dborun("UPDATE invoices SET amount = '".$output->msatoshi."' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Update amount"); + } + + $oo = "sudo lightning-cli -J pay maxfeepercent=4 maxdelay=1200 bolt11=".$bill['bolt11']; + debuglog($oo); + $outpute = shell_exec($oo); // debuglog("ok"); - $output = json_decode($outpute); - debuglog($outpute); - if (isset($output->message) && $output->message == "Invoice expired") { - dborun("UPDATE invoices SET status = 'Expired' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Invoice expired"); - break; - } - - if (isset($output->message) && $output->message == "Invalid bolt11: Bad bech32 string") { - // debuglog("clean invalid"); - dborun("UPDATE invoices SET status = 'Invalid' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Invoice with invalid bolt11"); - break; - } - if (isset($output->message) && (strpos($output->message == "max fee requested is") !== false)) { - // Fee 2001 is 1.352941% of payment 147900; max fee requested is - // debuglog("clean invalid"); - dborun("UPDATE invoices SET status = 'maxfee' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Invoice with too much fee."); - break; - } - - if (isset($output->status) && $output->status == "complete") { - // debuglog("clean invalid"); - dborun("UPDATE invoices SET status = 'complete', exectime = '".time()."' WHERE bolt11='".$bill['bolt11']."'"); - debuglog("Bill paid ! :-)"); - if (isset($output->msatoshi_sent)) { - dborun("UPDATE invoices SET paid = '".$output->msatoshi_sent."' WHERE bolt11='".$bill['bolt11']."'"); - } - break; - } + $output = json_decode($outpute); + debuglog($outpute); + if (isset($output->message) && $output->message == "Invoice expired") { + dborun("UPDATE invoices SET status = 'Expired' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Invoice expired"); + break; + } + + if (isset($output->message) && $output->message == "Invalid bolt11: Bad bech32 string") { + // debuglog("clean invalid"); + dborun("UPDATE invoices SET status = 'Invalid' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Invoice with invalid bolt11"); + break; + } + if (isset($output->message) && (strpos($output->message == "max fee requested is") !== false)) { + // Fee 2001 is 1.352941% of payment 147900; max fee requested is + // debuglog("clean invalid"); + dborun("UPDATE invoices SET status = 'maxfee' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Invoice with too much fee."); + break; + } + + if (isset($output->status) && $output->status == "complete") { + // debuglog("clean invalid"); + dborun("UPDATE invoices SET status = 'complete', exectime = '".time()."' WHERE bolt11='".$bill['bolt11']."'"); + debuglog("Bill paid ! :-)"); + if (isset($output->msatoshi_sent)) { + dborun("UPDATE invoices SET paid = '".$output->msatoshi_sent."' WHERE bolt11='".$bill['bolt11']."'"); + } + break; + } /* @@ -332,22 +329,22 @@ public function actionRunLightning() debuglog("[LN] Bill: bad amount ".$output->msatoshi." ".(LN_MIN_PAY * 1000)); */ -break; - } - } + break; + } + } // $bill = file_get_contents(""); - } - } + } + } //debuglog($outpute); - } + } //debuglog($output["id"]); //debuglog("Refund channel if new payment occured"); - } - } + } + } } memcache_set($this->memcache->memcache, "cronjob_ln_time_start", time()); From 7c5c2e61727e80a95528dccc2d644f0609c64780 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Mon, 10 Sep 2018 14:03:34 +0200 Subject: [PATCH 115/115] DB: add workerid --- sql/2018-08-lightning-testnet.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/2018-08-lightning-testnet.sql b/sql/2018-08-lightning-testnet.sql index 1fb666e19..6b274e432 100644 --- a/sql/2018-08-lightning-testnet.sql +++ b/sql/2018-08-lightning-testnet.sql @@ -1,6 +1,7 @@ CREATE TABLE `invoices` ( `id` int(11) NOT NULL, `userid` int(11) NOT NULL, + `workerid` int(11) NOT NULL, `bolt11` varchar(1000) NOT NULL, `amount` int(11) NOT NULL, `paid` int(11) NOT NULL,