Skip to content

Commit

Permalink
bugfix asset last price;
Browse files Browse the repository at this point in the history
new version 0.2.5-SNAPSHOT;
some cleanup;
  • Loading branch information
de-luxe committed Oct 27, 2016
1 parent 4845a18 commit ac076b7
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 168 deletions.
4 changes: 1 addition & 3 deletions observer.default.properties
Expand Up @@ -27,16 +27,14 @@ burstcoin.observer.network.serverUrls=\
https://wallet.burst-team.us:8127,\
https://wallet.burst-team.us:8128,\
http://pool.burstmining.club,\
http://pool.burstcoin.de,\
http://178.62.39.204:8121,\
http://pool.burstcoin.biz,\
http://pool.burst-team.us,\
http://pool.burstcoin.it,\
http://pool.burstcoin.eu,\
http://util.burst-team.us:8889,\
http://burst.ninja,\
http://burstpool.ddns.net:8080,\
http://burstcoinpool.devip.xyz:8080
http://pool.burstcoin.party

# Mail - Fork Notification (optional)
burstcoin.observer.mail.enableStuckNotify=false
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -12,7 +12,7 @@
<name>burstcoin-observer</name>
<groupId>burstcoin</groupId>
<artifactId>burstcoin-observer</artifactId>
<version>0.2.4-SNAPSHOT</version>
<version>0.2.5-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>
Expand Down
86 changes: 58 additions & 28 deletions src/main/java/burstcoin/observer/service/AssetService.java
Expand Up @@ -23,9 +23,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -82,8 +83,7 @@ public void run()
{
long volume7Days = 0L;
long volume30Days = 0L;
Long lastPrice = null;
String s = "";
String lastPrice = "";
List<Trade> trades = tradeLookup.get(asset);
if(trades != null && !trades.isEmpty())
{
Expand All @@ -93,39 +93,18 @@ public void run()
while(withinLast30Days && iterator.hasNext())
{
Trade trade = iterator.next();
if(lastPrice == null)
if(StringUtils.isEmpty(lastPrice))
{
lastPrice = Long.valueOf(trade.getPriceNQT());

if(lastPrice < 100000000)
{
s = String.valueOf(100000000 + lastPrice);
s = "0." + s.substring(1, s.length());
}
else
{
s = String.valueOf(lastPrice);
s = s.substring(0, s.length() - 8) + "." + s.substring(s.length() - 8, s.length());
}
while(s.lastIndexOf("0") == s.length() - 1)
{
s = s.substring(0, s.length() - 1);
}
if(s.lastIndexOf(".") == s.length() - 1)
{
s = s.substring(0, s.length() - 1);
}
lastPrice = convertPrice(trade.getPriceNQT(), trade.getDecimals());
}


Integer bidOrderBlock = Integer.valueOf(trade.getBidOrderHeight());
Integer askOrderBlock = Integer.valueOf(trade.getAskOrderHeight());
int block = bidOrderBlock >= askOrderBlock ? bidOrderBlock : askOrderBlock;
withinLast30Days = state.getNumberOfBlocks() - 360 * 30 < block;

if(withinLast30Days)
{

long volume = Long.valueOf(trade.getPriceNQT()) * Long.valueOf(trade.getQuantityQNT());
volume30Days += volume;

Expand All @@ -146,7 +125,7 @@ public void run()
assetBeans.add(new AssetBean(asset.getAsset(), asset.getName(), asset.getDescription(), asset.getAccountRS(), asset.getAccount(),
asset.getQuantityQNT(), asset.getDecimals(), asset.getNumberOfAccounts(), asset.getNumberOfTransfers(),
asset.getNumberOfTrades(), buyOrders.size(), sellOrders.size(),
formatAmountNQT(volume7Days, 8), formatAmountNQT(volume30Days, 8), s));
formatAmountNQT(volume7Days, 8), formatAmountNQT(volume30Days, 8), lastPrice));
}
}
Collections.sort(assetBeans, new Comparator<AssetBean>()
Expand All @@ -170,12 +149,46 @@ public int compare(AssetBean o1, AssetBean o2)
}
catch(Exception e)
{
LOG.error("Failed update assets!");
LOG.error("Failed update assets!", e);
}
}
}, 200, ObserverProperties.getAssetRefreshInterval());
}

private String convertPrice(String priceString, int decimals)
{
BigInteger price = new BigInteger(priceString);
BigInteger amount = price.multiply(new BigInteger("" + (long) Math.pow(10, decimals)));
String negative = "";
String afterComma = "";
String fractionalPart = amount.mod(new BigInteger("100000000")).toString();
amount = amount.divide(new BigInteger("100000000"));
if(amount.compareTo(BigInteger.ZERO) < 0)
{
amount = amount.abs();
negative = "-";
}
if(!fractionalPart.equals("0"))
{
afterComma = ".";
for(int i = fractionalPart.length(); i < 8; i++)
{
afterComma += "0";
}
afterComma += fractionalPart.replace("0+$", "");
}
String result = negative + amount + afterComma;
while(result.lastIndexOf("0") == result.length() - 1)
{
result = result.substring(0, result.length() - 1);
}
if(result.lastIndexOf(".") == result.length() - 1)
{
result = result.substring(0, result.length() - 1);
}
return result;
}

private String formatAmountNQT(Long amount, int decimals)
{
String amountStr = String.valueOf(amount);
Expand Down Expand Up @@ -349,4 +362,21 @@ private void addOrders(OrderType orderType, Map<OrderType, Map<Asset, List<Order
}
orderLookup.put(orderType, askOrderLookup);
}

// 3 possibilities to blacklist a asset
// - issuer has blacklisted it (has to send assetId to provided account (from asset or issuer account))
// - blacklisted in properties
// - blacklisted via trusted community member accounts (from properties)
private List<String> getBlacklistedAssets()
{
// todo get messages from blacklist account
// todo filter valid messages
// todo filter allowed messages by moderator / issuer
// todo re-add whitelisted
// todo return remaining assetIds


return null;
}

}
62 changes: 31 additions & 31 deletions src/main/java/burstcoin/observer/service/NetworkService.java
Expand Up @@ -188,9 +188,9 @@ public int compare(NetworkBean o1, NetworkBean o2)
}
}
}

long maxHeight = 0;

for(NetworkBean networkBean : networkBeans)
{
if(networkBean.getAvailable())
Expand All @@ -202,7 +202,7 @@ public int compare(NetworkBean o1, NetworkBean o2)
boolean appStartedAfterForkHappened = lastBlockWithSameGenSig == null;

boolean sendMail = false;

for(NetworkBean networkBean : networkBeans)
{
if(networkBean.getAvailable())
Expand All @@ -214,26 +214,21 @@ public int compare(NetworkBean o1, NetworkBean o2)
networkBean.setState(NetworkState.FORKED);
sendMail = true;
}
if (height + 4 < maxHeight) // when the wallet is 4 blocks behind -> stuck

if(height + 4 < maxHeight) // when the wallet is 4 blocks behind -> stuck
{
if (!networkBean.getState().equals(NetworkState.FORKED)) // if it's forked, then ignore the stuck-check, because forks may also be behind
{
networkBean.setState(NetworkState.STUCK);

if (ObserverProperties.isEnableStuckNotify() &&
(!previousStateLookup.containsKey(networkBean.getDomain()) || !previousStateLookup.get(networkBean.getDomain()).equals(NetworkState.STUCK)) //send only once
)
{
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(ObserverProperties.getMailReceiver());
mailMessage.setReplyTo(ObserverProperties.getMailReplyTo());
mailMessage.setFrom(ObserverProperties.getMailSender());
mailMessage.setSubject("Burstcoin-Observer - Stuck at block: " + networkBean.getHeight().toString());
mailMessage.setText(networkBean.getDomain() + "\r\n" + "Please check: " + ObserverProperties.getObserverUrl());
mailSender.send(mailMessage);
}
}
if(!networkBean.getState().equals(NetworkState.FORKED)) // if it's forked, then ignore the stuck-check, because forks may also be behind
{
networkBean.setState(NetworkState.STUCK);

if(ObserverProperties.isEnableStuckNotify()
&& (!previousStateLookup.containsKey(networkBean.getDomain())
|| !previousStateLookup.get(networkBean.getDomain()).equals(NetworkState.STUCK))) //send only once
{
sendMessage("Burstcoin-Observer - Stuck at block: " + networkBean.getHeight(),
networkBean.getDomain() + "\r\n" + "Please check: " + ObserverProperties.getObserverUrl());
}
}
}
}
}
Expand All @@ -248,20 +243,14 @@ public int compare(NetworkBean o1, NetworkBean o2)
// ensure only one mail send per lastBlockWithSameGenSig e.g. if forked wallet pops off blocks over and over again
lastBlockWithSameGenSigMailSend = lastBlockWithSameGenSig;

SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(ObserverProperties.getMailReceiver());
mailMessage.setReplyTo(ObserverProperties.getMailReplyTo());
mailMessage.setFrom(ObserverProperties.getMailSender());
mailMessage.setSubject("Burstcoin-Observer - Fork after block: " + lastBlockWithSameGenSig);
mailMessage.setText("Please check: " + ObserverProperties.getObserverUrl());
mailSender.send(mailMessage);
sendMessage("Burstcoin-Observer - Fork after block: " + lastBlockWithSameGenSig, "Please check: " + ObserverProperties.getObserverUrl());
}
}
else if(!sendMail && !appStartedAfterForkHappened)
{
forkMailSend = false;
}

// store the network state for next check-loop
for(NetworkBean networkBean : networkBeans)
{
Expand All @@ -270,7 +259,7 @@ else if(!sendMail && !appStartedAfterForkHappened)
previousStateLookup.put(networkBean.getDomain(), networkBean.getState());
}
}

publisher.publishEvent(new NetworkUpdateEvent(networkBeans, lastBlockWithSameGenSig));
}
catch(Exception e)
Expand All @@ -281,6 +270,17 @@ else if(!sendMail && !appStartedAfterForkHappened)
}, 200, ObserverProperties.getNetworkRefreshInterval());
}

private void sendMessage(String subject, String message)
{
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(ObserverProperties.getMailReceiver());
mailMessage.setReplyTo(ObserverProperties.getMailReplyTo());
mailMessage.setFrom(ObserverProperties.getMailSender());
mailMessage.setSubject(subject);
mailMessage.setText(message);
mailSender.send(mailMessage);
}

private MiningInfo getMiningInfo(String server)
{
MiningInfo result = null;
Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/templates/api.html
@@ -1,25 +1,4 @@
<!DOCTYPE HTML>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
~ and associated documentation files (the "Software"), to deal in the Software without restriction,
~ including without limitation the rights to use, copy, modify, merge, publish, distribute,
~ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
~ is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies
~ or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
~ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
~ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~
-->

<html xmlns:th="http://www.thymeleaf.org">

Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/templates/asset.html
@@ -1,25 +1,4 @@
<!DOCTYPE HTML>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
~ and associated documentation files (the "Software"), to deal in the Software without restriction,
~ including without limitation the rights to use, copy, modify, merge, publish, distribute,
~ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
~ is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies
~ or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
~ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
~ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~
-->

<html xmlns:th="http://www.thymeleaf.org">

Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/templates/crowdfund.html
@@ -1,25 +1,4 @@
<!DOCTYPE HTML>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
~ and associated documentation files (the "Software"), to deal in the Software without restriction,
~ including without limitation the rights to use, copy, modify, merge, publish, distribute,
~ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
~ is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies
~ or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
~ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
~ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~
-->

<html xmlns:th="http://www.thymeleaf.org">

Expand Down
21 changes: 0 additions & 21 deletions src/main/resources/templates/network.html
@@ -1,25 +1,4 @@
<!DOCTYPE HTML>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
~ and associated documentation files (the "Software"), to deal in the Software without restriction,
~ including without limitation the rights to use, copy, modify, merge, publish, distribute,
~ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
~ is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies
~ or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
~ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
~ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
~ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~
-->

<html xmlns:th="http://www.thymeleaf.org">

Expand Down

0 comments on commit ac076b7

Please sign in to comment.