|
|
@@ -9,6 +9,8 @@ import interceptor.AuthInterceptor;
|
|
|
import model.EthMev;
|
|
|
import util.MyRet;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -173,14 +175,88 @@ public class EthMevController extends Controller {
|
|
|
JSONObject toObjDataObj = JSONObject.parseObject(toObj.getStr("data"));
|
|
|
ethMev.put("toName", toObjDataObj.getString("name"));
|
|
|
} catch (Exception ignored) {}
|
|
|
- // 处理tokenHash
|
|
|
+ // 处理tokenHash和lpHash
|
|
|
+ String fromToSql = "select * from t_ethereum_mev_v1 where hash=?";
|
|
|
JSONArray tradeInfoList = dataObj.getJSONArray("tradeInfo");
|
|
|
for (JSONObject tradeInfo : tradeInfoList.toJavaList(JSONObject.class)) {
|
|
|
- // tokenObj容错
|
|
|
+ // tokenObj信息处理
|
|
|
try {
|
|
|
EthMev tokenObj = EthMev.dao.findFirst(findHashSql, 1, tradeInfo.getString("token"));
|
|
|
- JSONObject tokenObjDataObj = JSONObject.parseObject(tokenObj.getStr("data"));
|
|
|
- tradeInfo.put("tokenName", tokenObjDataObj.getString("name"));
|
|
|
+
|
|
|
+ if (tokenObj != null) {
|
|
|
+ JSONObject tokenObjDataObj = JSONObject.parseObject(tokenObj.getStr("data"));
|
|
|
+ tradeInfo.put("tokenSymbol", tokenObjDataObj.getString("symbol"));
|
|
|
+
|
|
|
+ BigDecimal amount = tradeInfo.getBigDecimal("amount");
|
|
|
+ BigDecimal ten = new BigDecimal("10");
|
|
|
+ int decimals = tokenObjDataObj.getInteger("decimals");
|
|
|
+
|
|
|
+ BigDecimal realAmount = amount.divide(ten.pow(decimals));
|
|
|
+ tradeInfo.put("amount", realAmount.doubleValue());
|
|
|
+ } else if (tradeInfo.getString("token").equals("0xeth")) {
|
|
|
+ tradeInfo.put("tokenSymbol", "Ethereum");
|
|
|
+
|
|
|
+ BigDecimal amount = tradeInfo.getBigDecimal("amount");
|
|
|
+ BigDecimal ten = new BigDecimal("10");
|
|
|
+ int decimals = 18;
|
|
|
+
|
|
|
+ BigDecimal realAmount = amount.divide(ten.pow(decimals));
|
|
|
+ tradeInfo.put("amount", realAmount.doubleValue());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // fromOrToObj信息处理
|
|
|
+ try {
|
|
|
+ EthMev fromLpObj = EthMev.dao.findFirst(fromToSql, tradeInfo.getString("from"));
|
|
|
+ EthMev toLpObj = EthMev.dao.findFirst(fromToSql, tradeInfo.getString("to"));
|
|
|
+
|
|
|
+ EthMev[] fromToArray = new EthMev[] {fromLpObj, toLpObj};
|
|
|
+ for (int index = 0; index < 2; index++) {
|
|
|
+ EthMev fromOrToObj = fromToArray[index];
|
|
|
+
|
|
|
+ JSONObject dataObjOfFromOrToObj = null;
|
|
|
+ // 第一种情况,屁都不是的情况
|
|
|
+ if (fromOrToObj == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ dataObjOfFromOrToObj = JSONObject.parseObject(fromOrToObj.getStr("data"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二种情况,有symbol的情况
|
|
|
+ if (dataObjOfFromOrToObj.getString("symbol") != null) {
|
|
|
+ if (index == 0) {
|
|
|
+ tradeInfo.put("fromName", dataObjOfFromOrToObj.getString("symbol"));
|
|
|
+ } else {
|
|
|
+ tradeInfo.put("toName", dataObjOfFromOrToObj.getString("symbol"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 第三种情况,只有name的情况
|
|
|
+ else if (dataObjOfFromOrToObj.getString("name") != null) {
|
|
|
+ if (index == 0) {
|
|
|
+ tradeInfo.put("fromName", dataObjOfFromOrToObj.getString("name"));
|
|
|
+ } else {
|
|
|
+ tradeInfo.put("toName", dataObjOfFromOrToObj.getString("name"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 第四种情况,有Symbol0和Symbol1的情况,也就是LP
|
|
|
+ else if (dataObjOfFromOrToObj.getString("symbol0") != null
|
|
|
+ && dataObjOfFromOrToObj.getString("symbol1") != null) {
|
|
|
+ String symbol0 = dataObjOfFromOrToObj.getString("symbol0");
|
|
|
+ String symbol1 = dataObjOfFromOrToObj.getString("symbol1");
|
|
|
+ String router = dataObjOfFromOrToObj.getString("router");
|
|
|
+ String viewName = String.format("%s-%s-%s-LP", router.substring(0, 4), symbol0, symbol1);
|
|
|
+ if (index == 0) {
|
|
|
+ tradeInfo.put("fromName", viewName);
|
|
|
+ } else {
|
|
|
+ tradeInfo.put("toName", viewName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception ignored) {}
|
|
|
}
|
|
|
} catch (Exception e) {
|