forked from circlecloud/tera
feat: sync system code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
e693bab5a7
commit
b8239f6da9
595
src/core/log.ts
595
src/core/log.ts
@ -7,236 +7,417 @@
|
|||||||
* Twitter: https://twitter.com/terafoundation
|
* Twitter: https://twitter.com/terafoundation
|
||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
import * as fs from 'fs'
|
|
||||||
|
|
||||||
import './constant'
|
require("./constant.js");
|
||||||
import './log-strict'
|
var fs = require('fs');
|
||||||
|
require("./log-strict.js");
|
||||||
var file_name_info = global.GetDataPath("info.log")
|
var file_name_info = global.GetDataPath("info.log");
|
||||||
var file_name_infoPrev = global.GetDataPath("info-prev.log");
|
var file_name_infoPrev = global.GetDataPath("info-prev.log");
|
||||||
global.CheckSizeLogFile(file_name_info, file_name_infoPrev);
|
global.CheckSizeLogFile(file_name_info, file_name_infoPrev);
|
||||||
var file_name_log = global.GetDataPath("log.log")
|
var file_name_log = global.GetDataPath("log.log");
|
||||||
var file_name_logPrev = global.GetDataPath("log-prev.log");
|
var file_name_logPrev = global.GetDataPath("log-prev.log");
|
||||||
global.CheckSizeLogFile(file_name_log, file_name_logPrev);
|
global.CheckSizeLogFile(file_name_log, file_name_logPrev);
|
||||||
var file_name_log_web = global.GetDataPath("web.log")
|
var file_name_log_web = global.GetDataPath("web.log");
|
||||||
var file_name_log_webPrev = global.GetDataPath("web-prev.log");
|
var file_name_log_webPrev = global.GetDataPath("web-prev.log");
|
||||||
global.CheckSizeLogFile(file_name_log_web, file_name_log_webPrev);
|
global.CheckSizeLogFile(file_name_log_web, file_name_log_webPrev);
|
||||||
var StartStatTime, file_name_error = global.GetDataPath("err.log")
|
var file_name_error = global.GetDataPath("err.log");
|
||||||
var file_name_errorPrev = global.GetDataPath("err-prev.log");
|
var file_name_errorPrev = global.GetDataPath("err-prev.log");
|
||||||
|
global.CheckSizeLogFile(file_name_error, file_name_errorPrev);
|
||||||
function ToLogFile(e, t, r?) {
|
var file_name_error_tx = global.GetDataPath("err-tx.log");
|
||||||
t instanceof Error && (t = t.message + "\n" + t.stack), global.START_SERVER || (t = global.PROCESS_NAME + ": " + t), "MAIN" !== global.PROCESS_NAME && process.send ? process.send({
|
var file_name_error_txPrev = global.GetDataPath("err-tx-prev.log");
|
||||||
cmd: "log",
|
global.CheckSizeLogFile(file_name_error_tx, file_name_error_txPrev);
|
||||||
message: t
|
global.ToLog = function(Str, Level) {
|
||||||
}) : (console.log(global.START_PORT_NUMBER + ": " + global.GetStrOnlyTime() + ": " + t), r || SaveToLogFileSync(e, t));
|
if (Level === undefined)
|
||||||
|
Level = 1;
|
||||||
|
if (Level && Level > global.LOG_LEVEL)
|
||||||
|
return;
|
||||||
|
if (global.ALL_LOG_TO_CLIENT)
|
||||||
|
ToLogClient(Str, undefined, undefined);
|
||||||
|
else
|
||||||
|
ToLogFile(file_name_log, Str);
|
||||||
};
|
};
|
||||||
|
global.WEB_LOG = 0;
|
||||||
function ToLogClient(e, t, r) {
|
global.ToLogWeb = function(Str) {
|
||||||
let ArrLogClient = global.ArrLogClient;
|
if (global.WEB_LOG) {
|
||||||
e && (ToLogFile(file_name_log, e), t = t || "", ArrLogClient.push({ text: global.GetStrOnlyTime() + " " + e, key: t, final: r }), 13 < ArrLogClient.length && ArrLogClient.shift());
|
SaveToLogFileSync(file_name_log_web, Str);
|
||||||
};
|
|
||||||
global.CheckSizeLogFile(file_name_error, file_name_errorPrev), global.ToLog = function(e, t) {
|
|
||||||
void 0 === t && (t = 1), t && t > global.LOG_LEVEL || (global.ALL_LOG_TO_CLIENT ? ToLogClient(e, void 0, void 0) : ToLogFile(file_name_log,
|
|
||||||
e));
|
|
||||||
}, global.ToLogWeb = function(e) {
|
|
||||||
}, global.SmallAddr = function(e) {
|
|
||||||
return e.substr(0, 5);
|
|
||||||
}, global.ToErrorTrace = function(e) {
|
|
||||||
global.ToError(e + ":" + (new Error).stack);
|
|
||||||
}, global.ToLogTrace = function(e) {
|
|
||||||
global.ToErrorTrace(e);
|
|
||||||
}, global.ToInfo = function(e) {
|
|
||||||
ToLogFile(file_name_info, e, 1);
|
|
||||||
}, global.ToError = function(e) {
|
|
||||||
ToLogFile(file_name_error, e);
|
|
||||||
}, global.ArrLogClient = [], global.ToLogClient = ToLogClient, global.ToLogClient0 = ToLogClient;
|
|
||||||
var CONTEXT_STATS = { Total: {}, Interval: [] }, CONTEXT_ERRORS = { Total: {}, Interval: [] }, CurStatIndex = 0;
|
|
||||||
let MAX_STAT_PERIOD = global.MAX_STAT_PERIOD;
|
|
||||||
function GetCurrentStatIndex() {
|
|
||||||
var e = 2 * MAX_STAT_PERIOD + 2;
|
|
||||||
return CurStatIndex % e;
|
|
||||||
};
|
|
||||||
|
|
||||||
function ResizeArrMax(e) {
|
|
||||||
for (var t = [], r = Math.trunc(e.length / 2), o = 0; o < r; o++)
|
|
||||||
t[o] = Math.max(e[2 * o], e[2 * o + 1]);
|
|
||||||
return t;
|
|
||||||
};
|
|
||||||
|
|
||||||
function ResizeArrAvg(e) {
|
|
||||||
for (var t = [], r = Math.trunc(e.length / 2), o = 0; o < r; o++)
|
|
||||||
t[o] = (e[2 * o] + e[2 * o + 1]) / 2;
|
|
||||||
return t;
|
|
||||||
};
|
|
||||||
|
|
||||||
// function ResizeArr(e) {
|
|
||||||
// for (var t = [], r = Math.trunc(e.length / 2), o = 0; o < r; o++)
|
|
||||||
// t[o] = e[2 * o];
|
|
||||||
// return t;
|
|
||||||
// };
|
|
||||||
|
|
||||||
function GetDiagramData(e, t) {
|
|
||||||
var r, o = 2 * MAX_STAT_PERIOD + 2;
|
|
||||||
r = "MAX:" === t.substr(0, 4);
|
|
||||||
for (var n, a = MAX_STAT_PERIOD, l = (GetCurrentStatIndex() - a + o) % o, i = (e.Total, []), T = void 0, g = l; g < l + a; g++) {
|
|
||||||
var S = g % o;
|
|
||||||
if (n = e.Interval[S]) {
|
|
||||||
var _ = n[t];
|
|
||||||
void 0 !== _ ? r ? i.push(_) : (void 0 !== T ? i.push(_ - T) : i.push(_), T = _) : i.push(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
};
|
|
||||||
|
|
||||||
function CalcInterval(e, t, r) {
|
|
||||||
for (var o, n = 2 * MAX_STAT_PERIOD + 2, a = {}, l = (t - r + n) % n, i = e.Total, T = l; T < l + r; T++) {
|
|
||||||
var g = T % n;
|
|
||||||
if (o = e.Interval[g])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (o)
|
|
||||||
for (var S in i)
|
|
||||||
"MAX:" === S.substr(0, 4) ? a[S] = 0 : void 0 === o[S] ? a[S] = i[S] : a[S] = i[S] - o[S];
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
|
|
||||||
function AddToStatContext(e, t, r?) {
|
|
||||||
void 0 === r && (r = 1);
|
|
||||||
var o = e.Total[t];
|
|
||||||
o = o || 0, "MAX:" === t.substr(0, 4) ? o = Math.max(o, r) : o += r, e.Total[t] = o, StartStatTime = StartStatTime || global.GetCurrentTime(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
function CopyStatInterval(e, t) {
|
|
||||||
var r = e.Interval[t];
|
|
||||||
r || (r = {}, e.Interval[t] = r);
|
|
||||||
var o = e.Total;
|
|
||||||
for (var n in o)
|
|
||||||
r[n] = o[n], "MAX:" === n.substr(0, 4) && (o[n] = 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
// function SaveToLogFileAsync(e, o) {
|
|
||||||
// fs.open(e, "a", void 0, function(e, r) {
|
|
||||||
// if (e)
|
|
||||||
// console.log("Ошибка открытия лог-файла ошибок");
|
|
||||||
// else {
|
|
||||||
// var t = global.GetStrTime() + " : " + o + "\r\n";
|
|
||||||
// fs.write(r, t, null, "utf8", function(e, t) {
|
|
||||||
// e ? console.log("Ошибка записи в лог-файл ошибок!") : fs.close(r, function(e) {
|
|
||||||
// e && console.log(e);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
function SaveToLogFileSync(e, t) {
|
|
||||||
try {
|
|
||||||
var r = global.GetStrTime() + " : " + t + "\r\n", o = fs.openSync(e, "a");
|
|
||||||
fs.writeSync(o, r, null, "utf8"), fs.closeSync(o);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
global.SmallAddr = function(Str) {
|
||||||
|
return Str.substr(0, 5);
|
||||||
|
};
|
||||||
|
global.ToErrorTrace = function(Str) {
|
||||||
|
global.ToError("" + Str + ":" + new Error().stack);
|
||||||
|
};
|
||||||
|
global.ToLogTrace = function(Str) {
|
||||||
|
global.ToErrorTrace(Str);
|
||||||
|
};
|
||||||
|
global.ToInfo = function(Str) {
|
||||||
|
ToLogFile(file_name_info, Str, 1);
|
||||||
|
};
|
||||||
|
global.ToError = function(Str) {
|
||||||
|
ToLogFile(file_name_error, Str);
|
||||||
|
};
|
||||||
|
global.ToErrorTx = function(Str) {
|
||||||
|
SaveToLogFileSync(file_name_error_tx, Str);
|
||||||
|
global.ToLog(Str);
|
||||||
|
};
|
||||||
|
|
||||||
|
function ToLogFile(file_name, Str, bNoFile?) {
|
||||||
|
if (Str instanceof Error) {
|
||||||
|
Str = Str.message + "\n" + Str.stack;
|
||||||
|
}
|
||||||
|
if (!global.START_SERVER)
|
||||||
|
Str = global.PROCESS_NAME + ": " + Str;
|
||||||
|
if (global.PROCESS_NAME !== "MAIN" && process.send) {
|
||||||
|
process.send({ cmd: "log", message: Str });
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log("" + global.START_PORT_NUMBER + ": " + global.GetStrOnlyTime() + ": " + Str);
|
||||||
|
}
|
||||||
|
if (bNoFile)
|
||||||
|
return;
|
||||||
|
SaveToLogFileSync(file_name, Str);
|
||||||
|
};
|
||||||
|
global.ArrLogClient = [];
|
||||||
|
|
||||||
|
function ToLogClient(Str, StrKey, bFinal) {
|
||||||
|
if (!Str)
|
||||||
|
return;
|
||||||
|
ToLogFile(file_name_log, Str);
|
||||||
|
if (!StrKey)
|
||||||
|
StrKey = "";
|
||||||
|
global.ArrLogClient.push({ text: global.GetStrOnlyTime() + " " + Str, key: StrKey, final: bFinal, });
|
||||||
|
if (global.ArrLogClient.length > 13)
|
||||||
|
global.ArrLogClient.shift();
|
||||||
|
};
|
||||||
|
global.ToLogClient = ToLogClient;
|
||||||
|
global.ToLogClient0 = ToLogClient;
|
||||||
|
var StartStatTime;
|
||||||
|
var CONTEXT_STATS = { Total: {}, Interval: [] };
|
||||||
|
var CONTEXT_ERRORS = { Total: {}, Interval: [] };
|
||||||
|
var CurStatIndex = 0;
|
||||||
global.PrepareStatEverySecond = function() {
|
global.PrepareStatEverySecond = function() {
|
||||||
CurStatIndex++;
|
CurStatIndex++;
|
||||||
var e = GetCurrentStatIndex();
|
var index = GetCurrentStatIndex();
|
||||||
CopyStatInterval(CONTEXT_STATS, e), CopyStatInterval(CONTEXT_ERRORS, e);
|
CopyStatInterval(CONTEXT_STATS, index);
|
||||||
}
|
CopyStatInterval(CONTEXT_ERRORS, index);
|
||||||
global.TO_ERROR_LOG = function(e, t, r, o, n, a) {
|
};
|
||||||
r instanceof Error && (r = r.message + "\n"), "rinfo" === o ? r += " from: " + n.address + ":" + n.port : "node" === o && (r += " from: " + n.ip + ":" + n.port);
|
global.TO_ERROR_LOG = function(Module, ErrNum, Str, type, data1, data2) {
|
||||||
var l = e + ":" + t;
|
if (Str instanceof Error) {
|
||||||
global.ToError(" ==ERROR== " + l + " " + r), AddToStatContext(CONTEXT_ERRORS, l), global.ADD_TO_STAT("ERRORS");
|
Str = Str.message + "\n";
|
||||||
}
|
|
||||||
global.HASH_RATE = 0, global.ADD_HASH_RATE = function(e) {
|
|
||||||
e /= 1e6, global.HASH_RATE += e, global.ADD_TO_STAT("HASHRATE", e);
|
|
||||||
}
|
|
||||||
global.GET_STAT = function(e) {
|
|
||||||
var t = CONTEXT_STATS.Total[e];
|
|
||||||
return t = t || 0;
|
|
||||||
}
|
|
||||||
global.ADD_TO_STAT_TIME = function(e, t, r) {
|
|
||||||
if (global.STAT_MODE) {
|
|
||||||
if (r && 2 !== global.STAT_MODE)
|
|
||||||
return;
|
|
||||||
var o = process.hrtime(t), n = 1e3 * o[0] + o[1] / 1e6;
|
|
||||||
global.ADD_TO_STAT(e, n);
|
|
||||||
}
|
}
|
||||||
}
|
if (type === "rinfo")
|
||||||
global.ADD_TO_STAT = function(e, t, r) {
|
Str += " from: " + data1.address + ':' + data1.port;
|
||||||
|
else
|
||||||
|
if (type === "node")
|
||||||
|
Str += " from: " + data1.ip + ':' + data1.port;
|
||||||
|
var Key = Module + ":" + ErrNum;
|
||||||
|
global.ToError(" ==ERROR== " + Key + " " + Str);
|
||||||
|
AddToStatContext(CONTEXT_ERRORS, Key);
|
||||||
|
global.ADD_TO_STAT("ERRORS");
|
||||||
|
};
|
||||||
|
|
||||||
|
function GetCurrentStatIndex() {
|
||||||
|
var DefMaxStatPeriod = global.MAX_STAT_PERIOD * 2 + 2;
|
||||||
|
return CurStatIndex % DefMaxStatPeriod;
|
||||||
|
};
|
||||||
|
global.HASH_RATE = 0;
|
||||||
|
global.ADD_HASH_RATE = function(Count) {
|
||||||
|
Count = Count / 1000000;
|
||||||
|
global.HASH_RATE += Count;
|
||||||
|
global.ADD_TO_STAT("HASHRATE", Count);
|
||||||
|
};
|
||||||
|
global.GET_STAT = function(Key) {
|
||||||
|
var Val = CONTEXT_STATS.Total[Key];
|
||||||
|
if (!Val)
|
||||||
|
Val = 0;
|
||||||
|
return Val;
|
||||||
|
};
|
||||||
|
global.ADD_TO_STAT_TIME = function(Name, startTime, bDetail) {
|
||||||
if (global.STAT_MODE) {
|
if (global.STAT_MODE) {
|
||||||
if (r && 2 !== global.STAT_MODE)
|
if (bDetail && global.STAT_MODE !== 2)
|
||||||
return;
|
return;
|
||||||
AddToStatContext(CONTEXT_STATS, e, t);
|
var Time = process.hrtime(startTime);
|
||||||
|
var deltaTime = Time[0] * 1000 + Time[1] / 1e6;
|
||||||
|
global.ADD_TO_STAT(Name, deltaTime);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
global.GET_STATDIAGRAMS = function(e) {
|
global.ADD_TO_STAT = function(Key, Count, bDetail) {
|
||||||
global.GetCurrentTime();
|
if (global.STAT_MODE) {
|
||||||
var t = GetCurrentStatIndex();
|
if (bDetail && global.STAT_MODE !== 2)
|
||||||
if (!e || !e.length)
|
return;
|
||||||
|
AddToStatContext(CONTEXT_STATS, Key, Count);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global.GET_STATDIAGRAMS = function(Keys) {
|
||||||
|
var now = global.GetCurrentTime();
|
||||||
|
var index = GetCurrentStatIndex();
|
||||||
|
if (!Keys || !Keys.length)
|
||||||
return [];
|
return [];
|
||||||
for (var r = [], o = 0; o < e.length; o++) {
|
var Data = [];
|
||||||
var n = e[o], a = GetDiagramData(CONTEXT_STATS, n);
|
for (var i = 0; i < Keys.length; i++) {
|
||||||
r.push({ name: n, maxindex: t, arr: a, starttime: StartStatTime - 0, steptime: 1 });
|
var name = Keys[i];
|
||||||
|
var Value = GetDiagramData(CONTEXT_STATS, name);
|
||||||
|
Data.push({ name: name, maxindex: index, arr: Value, starttime: (StartStatTime - 0), steptime: 1 });
|
||||||
}
|
}
|
||||||
var l = void 0;
|
var MinLength = undefined;
|
||||||
for (o = 0; o < r.length; o++) {
|
for (var i = 0; i < Data.length; i++) {
|
||||||
0 < (T = r[o].arr).length && (void 0 === l || T.length < l) && (l = T.length);
|
var arr = Data[i].arr;
|
||||||
|
if (arr.length > 0 && (MinLength === undefined || arr.length < MinLength))
|
||||||
|
MinLength = arr.length;
|
||||||
}
|
}
|
||||||
for (o = 0; o < r.length; o++) {
|
var MaxSizeArr = 500;
|
||||||
var i = r[o], T = i.arr;
|
for (var i = 0; i < Data.length; i++) {
|
||||||
l && T.length > l && (T = T.slice(T.length - l)), l && 0 <= ",POWER_MY_WIN,POWER_BLOCKCHAIN,".indexOf("," + i.name + ",") && (T = global.SERVER.GetStatBlockchain(i.name,
|
var ItemServer = Data[i];
|
||||||
l));
|
var arr = ItemServer.arr;
|
||||||
for (var g = 0, S = 0; S < T.length; S++)
|
if (MinLength && arr.length > MinLength) {
|
||||||
T[S] && (g += T[S]);
|
arr = arr.slice(arr.length - MinLength);
|
||||||
0 < T.length && (g /= T.length);
|
}
|
||||||
var _ = 1;
|
if (MinLength)
|
||||||
if ("MAX:" === i.name.substr(0, 4))
|
if (",POWER_MY_WIN,POWER_BLOCKCHAIN,".indexOf("," + ItemServer.name + ",") >= 0) {
|
||||||
for (; 500 <= T.length;)
|
arr = global.SERVER.GetStatBlockchain(ItemServer.name, MinLength);
|
||||||
T = ResizeArrMax(T), _ *= 2;
|
}
|
||||||
else
|
var AvgValue = 0;
|
||||||
for (; 500 <= T.length;)
|
for (var j = 0; j < arr.length; j++) {
|
||||||
T = ResizeArrAvg(T), _ *= 2;
|
if (arr[j])
|
||||||
i.AvgValue = g, i.steptime = _, i.arr = T.slice(1);
|
AvgValue += arr[j];
|
||||||
|
}
|
||||||
|
if (arr.length > 0)
|
||||||
|
AvgValue = AvgValue / arr.length;
|
||||||
|
var StepTime = 1;
|
||||||
|
if (ItemServer.name.substr(0, 4) === "MAX:") {
|
||||||
|
while (arr.length >= MaxSizeArr) {
|
||||||
|
arr = ResizeArrMax(arr);
|
||||||
|
StepTime = StepTime * 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (arr.length >= MaxSizeArr) {
|
||||||
|
arr = ResizeArrAvg(arr);
|
||||||
|
StepTime = StepTime * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemServer.AvgValue = AvgValue;
|
||||||
|
ItemServer.steptime = StepTime;
|
||||||
|
ItemServer.arr = arr.slice(1);
|
||||||
}
|
}
|
||||||
return r;
|
return Data;
|
||||||
}
|
};
|
||||||
global.GET_STATS = function(e) {
|
global.GET_STATS = function(Key) {
|
||||||
var t = global.GetCurrentTime(), r = GetCurrentStatIndex();
|
var now = global.GetCurrentTime();
|
||||||
return {
|
var index = GetCurrentStatIndex();
|
||||||
stats: {
|
var stats = {
|
||||||
Counter: CONTEXT_STATS.Total, Counter10S: CalcInterval(CONTEXT_STATS, r, 10), Counter10M: CalcInterval(CONTEXT_STATS,
|
Counter: CONTEXT_STATS.Total, Counter10S: CalcInterval(CONTEXT_STATS, index, 10), Counter10M: CalcInterval(CONTEXT_STATS,
|
||||||
r, 600)
|
index, 10 * 60),
|
||||||
}, errors: {
|
|
||||||
Counter: CONTEXT_ERRORS.Total, Counter10S: CalcInterval(CONTEXT_ERRORS, r, 10), Counter10M: CalcInterval(CONTEXT_ERRORS,
|
|
||||||
r, 600)
|
|
||||||
}, period: (t - StartStatTime) / 1e3, Confirmation: []
|
|
||||||
};
|
};
|
||||||
}
|
var errors = {
|
||||||
|
Counter: CONTEXT_ERRORS.Total, Counter10S: CalcInterval(CONTEXT_ERRORS, index, 10), Counter10M: CalcInterval(CONTEXT_ERRORS,
|
||||||
|
index, 10 * 60),
|
||||||
|
};
|
||||||
|
var Period = (now - StartStatTime) / 1000;
|
||||||
|
return { stats: stats, errors: errors, period: Period, Confirmation: [] };
|
||||||
|
};
|
||||||
global.StartCommonStat = function() {
|
global.StartCommonStat = function() {
|
||||||
for (var _ in CONTEXT_STATS.Total)
|
for (var key in CONTEXT_STATS.Total)
|
||||||
return;
|
return;
|
||||||
global.ClearCommonStat();
|
global.ClearCommonStat();
|
||||||
}
|
};
|
||||||
global.ClearCommonStat = function() {
|
global.ClearCommonStat = function() {
|
||||||
StartStatTime = void (CurStatIndex = 0), CONTEXT_STATS = { Total: {}, Interval: [] }, CONTEXT_ERRORS = { Total: {}, Interval: [] },
|
CurStatIndex = 0;
|
||||||
global.HASH_RATE = 0, global.SERVER.ClearStat();
|
StartStatTime = undefined;
|
||||||
}
|
CONTEXT_STATS = { Total: {}, Interval: [] };
|
||||||
global.ResizeArrAvg = ResizeArrAvg, global.ResizeArrMax = ResizeArrMax, global.DEBUG_MODE ? global.TO_DEBUG_LOG = function(e, t, r, o) {
|
CONTEXT_ERRORS = { Total: {}, Interval: [] };
|
||||||
global.DEBUG_MODE && ("rinfo" === t && (e += " from: " + r.address + ":" + r.port + " - " + o.length), global.ToLog(e));
|
global.HASH_RATE = 0;
|
||||||
} : global.TO_DEBUG_LOG = function(e, t, r, o) {
|
global.SERVER.ClearStat();
|
||||||
}
|
};
|
||||||
global.GetStrOnlyTime = function(e) {
|
|
||||||
if (!global.GetCurrentTime)
|
function ResizeArrMax(arr) {
|
||||||
return ":::";
|
var arr2 = [];
|
||||||
e || (e = global.GetCurrentTime());
|
var Count2 = Math.trunc(arr.length / 2);
|
||||||
var t = "" + (e = e || global.GetCurrentTime()).getHours().toStringZ(2);
|
for (var i = 0; i < Count2; i++) {
|
||||||
return t = (t = (t = t + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
|
arr2[i] = Math.max(arr[i * 2], arr[i * 2 + 1]);
|
||||||
}
|
}
|
||||||
global.GetStrTime = function(e) {
|
return arr2;
|
||||||
if (!global.GetCurrentTime)
|
};
|
||||||
return ":::";
|
|
||||||
e || (e = global.GetCurrentTime());
|
function ResizeArrAvg(arr) {
|
||||||
var t = "" + (e = e || global.GetCurrentTime()).getDate().toStringZ(2);
|
var arr2 = [];
|
||||||
return t = (t = (t = (t = (t = (t = t + "." + (1 + e.getMonth()).toStringZ(2)) + "." + e.getFullYear()) + " " + e.getHours().toStringZ(2)) + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
|
var Count2 = Math.trunc(arr.length / 2);
|
||||||
|
for (var i = 0; i < Count2; i++) {
|
||||||
|
arr2[i] = (arr[i * 2] + arr[i * 2 + 1]) / 2;
|
||||||
|
}
|
||||||
|
return arr2;
|
||||||
|
};
|
||||||
|
|
||||||
|
function ResizeArr(arr) {
|
||||||
|
var arr2 = [];
|
||||||
|
var Count2 = Math.trunc(arr.length / 2);
|
||||||
|
for (var i = 0; i < Count2; i++) {
|
||||||
|
arr2[i] = arr[i * 2];
|
||||||
|
}
|
||||||
|
return arr2;
|
||||||
|
};
|
||||||
|
global.ResizeArrAvg = ResizeArrAvg;
|
||||||
|
global.ResizeArrMax = ResizeArrMax;
|
||||||
|
|
||||||
|
function GetDiagramData(Context, Key) {
|
||||||
|
var DefMaxStatPeriod = global.MAX_STAT_PERIOD * 2 + 2;
|
||||||
|
var IsMax;
|
||||||
|
if (Key.substr(0, 4) === "MAX:")
|
||||||
|
IsMax = true;
|
||||||
|
else
|
||||||
|
IsMax = false;
|
||||||
|
var delta = global.MAX_STAT_PERIOD;
|
||||||
|
var index2 = GetCurrentStatIndex();
|
||||||
|
var index1 = (index2 - delta + DefMaxStatPeriod) % DefMaxStatPeriod;
|
||||||
|
var Total = Context.Total;
|
||||||
|
var Counter1;
|
||||||
|
var arr = [];
|
||||||
|
var PrevValue = undefined;
|
||||||
|
for (var i = index1; i < index1 + delta; i++) {
|
||||||
|
var index3 = i % DefMaxStatPeriod;
|
||||||
|
Counter1 = Context.Interval[index3];
|
||||||
|
if (Counter1) {
|
||||||
|
var Value = Counter1[Key];
|
||||||
|
if (Value !== undefined) {
|
||||||
|
if (!IsMax) {
|
||||||
|
if (PrevValue !== undefined) {
|
||||||
|
arr.push(Value - PrevValue);
|
||||||
|
} else {
|
||||||
|
arr.push(Value);
|
||||||
|
}
|
||||||
|
PrevValue = Value;
|
||||||
|
} else {
|
||||||
|
arr.push(Value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
arr.push(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
|
|
||||||
|
function CalcInterval(Context, index2, delta) {
|
||||||
|
var DefMaxStatPeriod = global.MAX_STAT_PERIOD * 2 + 2;
|
||||||
|
var Res = {};
|
||||||
|
var index1 = (index2 - delta + DefMaxStatPeriod) % DefMaxStatPeriod;
|
||||||
|
var Total = Context.Total;
|
||||||
|
var Counter1;
|
||||||
|
for (var i = index1; i < index1 + delta; i++) {
|
||||||
|
var index3 = i % DefMaxStatPeriod;
|
||||||
|
Counter1 = Context.Interval[index3];
|
||||||
|
if (Counter1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Counter1)
|
||||||
|
for (var Key in Total) {
|
||||||
|
if (Key.substr(0, 4) === "MAX:")
|
||||||
|
Res[Key] = 0;
|
||||||
|
else {
|
||||||
|
if (Counter1[Key] === undefined)
|
||||||
|
Res[Key] = Total[Key];
|
||||||
|
else
|
||||||
|
Res[Key] = Total[Key] - Counter1[Key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Res;
|
||||||
|
};
|
||||||
|
|
||||||
|
function AddToStatContext(Context, Key, AddValue?) {
|
||||||
|
if (AddValue === undefined)
|
||||||
|
AddValue = 1;
|
||||||
|
var Val = Context.Total[Key];
|
||||||
|
if (!Val)
|
||||||
|
Val = 0;
|
||||||
|
if (Key.substr(0, 4) === "MAX:")
|
||||||
|
Val = Math.max(Val, AddValue);
|
||||||
|
else
|
||||||
|
Val = Val + AddValue;
|
||||||
|
Context.Total[Key] = Val;
|
||||||
|
if (!StartStatTime)
|
||||||
|
StartStatTime = global.GetCurrentTime(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
function CopyStatInterval(Context, index) {
|
||||||
|
var Counter = Context.Interval[index];
|
||||||
|
if (!Counter) {
|
||||||
|
Counter = {};
|
||||||
|
Context.Interval[index] = Counter;
|
||||||
|
}
|
||||||
|
var Total = Context.Total;
|
||||||
|
for (var Key in Total) {
|
||||||
|
Counter[Key] = Total[Key];
|
||||||
|
if (Key.substr(0, 4) === "MAX:")
|
||||||
|
Total[Key] = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (global.DEBUG_MODE)
|
||||||
|
global.TO_DEBUG_LOG = function(Str, type, data1, data2) {
|
||||||
|
if (!global.DEBUG_MODE)
|
||||||
|
return;
|
||||||
|
if (type === "rinfo")
|
||||||
|
Str += " from: " + data1.address + ':' + data1.port + ' - ' + data2.length;
|
||||||
|
global.ToLog(Str);
|
||||||
|
};
|
||||||
|
else
|
||||||
|
global.TO_DEBUG_LOG = function(Str, type, data1, data2) {
|
||||||
|
};
|
||||||
|
|
||||||
|
function SaveToLogFileAsync(fname, Str) {
|
||||||
|
fs.open(fname, "a", undefined, function(err, file_handle) {
|
||||||
|
if (!err) {
|
||||||
|
var StrLog = global.GetStrTime() + " : " + Str + "\r\n";
|
||||||
|
fs.write(file_handle, StrLog, null, 'utf8', function(err, written) {
|
||||||
|
if (!err) {
|
||||||
|
fs.close(file_handle, function(err) {
|
||||||
|
if (err)
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Ошибка записи в лог-файл ошибок!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Ошибка открытия лог-файла ошибок");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function SaveToLogFileSync(fname, Str) {
|
||||||
|
try {
|
||||||
|
var StrLog = global.GetStrTime() + " : " + Str + "\r\n";
|
||||||
|
var file_handle = fs.openSync(fname, "a");
|
||||||
|
fs.writeSync(file_handle, StrLog, null, 'utf8');
|
||||||
|
fs.closeSync(file_handle);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
global.GetStrOnlyTime = function(now) {
|
||||||
|
if (!global.GetCurrentTime)
|
||||||
|
return ":::";
|
||||||
|
if (!now)
|
||||||
|
now = global.GetCurrentTime();
|
||||||
|
var Str = "" + now.getHours().toStringZ(2);
|
||||||
|
Str = Str + ":" + now.getMinutes().toStringZ(2);
|
||||||
|
Str = Str + ":" + now.getSeconds().toStringZ(2);
|
||||||
|
Str = Str + "." + now.getMilliseconds().toStringZ(3);
|
||||||
|
return Str;
|
||||||
|
};
|
||||||
|
global.GetStrTime = function(now) {
|
||||||
|
if (!global.GetCurrentTime)
|
||||||
|
return ":::";
|
||||||
|
if (!now)
|
||||||
|
now = global.GetCurrentTime();
|
||||||
|
var Str = "" + now.getDate().toStringZ(2);
|
||||||
|
Str = Str + "." + (1 + now.getMonth()).toStringZ(2);
|
||||||
|
Str = Str + "." + now.getFullYear();
|
||||||
|
Str = Str + " " + now.getHours().toStringZ(2);
|
||||||
|
Str = Str + ":" + now.getMinutes().toStringZ(2);
|
||||||
|
Str = Str + ":" + now.getSeconds().toStringZ(2);
|
||||||
|
Str = Str + "." + now.getMilliseconds().toStringZ(3);
|
||||||
|
return Str;
|
||||||
};
|
};
|
||||||
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@ -341,6 +341,7 @@ declare global {
|
|||||||
|
|
||||||
//#region log.ts
|
//#region log.ts
|
||||||
ArrLogClient: any[];
|
ArrLogClient: any[];
|
||||||
|
WEB_LOG: any;
|
||||||
ToLogWeb: Function;
|
ToLogWeb: Function;
|
||||||
SmallAddr: Function;
|
SmallAddr: Function;
|
||||||
ToErrorTrace: Function;
|
ToErrorTrace: Function;
|
||||||
@ -348,6 +349,7 @@ declare global {
|
|||||||
ToInfo: Function;
|
ToInfo: Function;
|
||||||
ToError: Function;
|
ToError: Function;
|
||||||
ToLogClient0: Function;
|
ToLogClient0: Function;
|
||||||
|
ToErrorTx: Function;
|
||||||
PrepareStatEverySecond: Function;
|
PrepareStatEverySecond: Function;
|
||||||
HASH_RATE: number;
|
HASH_RATE: number;
|
||||||
ADD_HASH_RATE: Function;
|
ADD_HASH_RATE: Function;
|
||||||
|
@ -10,14 +10,13 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import DApp from './dapp'
|
|
||||||
import DBRow from '../core/db/db-row'
|
import DBRow from '../core/db/db-row'
|
||||||
import DBLib from "../core/db/db"
|
import '../core/rest_tables'
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1 } from '../core/library'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account'
|
import { TYPE_TRANSACTION } from '../constant/account'
|
||||||
require('../core/rest_tables');
|
|
||||||
const MAX_SUM_TER = 1e9;
|
const MAX_SUM_TER = 1e9;
|
||||||
const MAX_SUM_CENT = 1e9;
|
const MAX_SUM_CENT = 1e9;
|
||||||
|
import DBLib from "../core/db/db"
|
||||||
global.HistoryDB = new DBLib();
|
global.HistoryDB = new DBLib();
|
||||||
const FILE_NAME_HISTORY = "history-body";
|
const FILE_NAME_HISTORY = "history-body";
|
||||||
var WorkStructHistory = {};
|
var WorkStructHistory = {};
|
||||||
@ -85,7 +84,7 @@ global.FORMAT_ACCOUNT_HASH3 = "{\
|
|||||||
SmartHash:buffer32,\
|
SmartHash:buffer32,\
|
||||||
SmartCount:uint,\
|
SmartCount:uint,\
|
||||||
}";
|
}";
|
||||||
|
import DApp from './dapp'
|
||||||
class MerkleDBRow extends DBRow {
|
class MerkleDBRow extends DBRow {
|
||||||
private MerkleTree
|
private MerkleTree
|
||||||
private MerkleArr
|
private MerkleArr
|
||||||
@ -108,7 +107,7 @@ class MerkleDBRow extends DBRow {
|
|||||||
var Buf = this.Read(num, 1);
|
var Buf = this.Read(num, 1);
|
||||||
if (!Buf) {
|
if (!Buf) {
|
||||||
if (global.WATCHDOG_DEV)
|
if (global.WATCHDOG_DEV)
|
||||||
global.ToLog("CalcMerkleTree: Break account reading on num: " + num)
|
global.ToErrorTx("CalcMerkleTree: Break account reading on num: " + num)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.MerkleArr[num] = global.shaarr(Buf)
|
this.MerkleArr[num] = global.shaarr(Buf)
|
||||||
@ -138,7 +137,7 @@ class MerkleDBRow extends DBRow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class AccountApp extends DApp {
|
export default class AccountApp extends DApp {
|
||||||
CreateTrCount
|
CreateTrCount
|
||||||
FORMAT_ACCOUNT_ROW
|
FORMAT_ACCOUNT_ROW
|
||||||
SIZE_ACCOUNT_ROW
|
SIZE_ACCOUNT_ROW
|
||||||
@ -298,7 +297,7 @@ class AccountApp extends DApp {
|
|||||||
try {
|
try {
|
||||||
fs.renameSync(this.DBActPrev.FileNameFull, FileNameFull2)
|
fs.renameSync(this.DBActPrev.FileNameFull, FileNameFull2)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.ToLog("Can-t rename for delete act-file: " + FileNameFull2 + " " + e)
|
global.ToErrorTx("Can-t rename for delete act-file: " + FileNameFull2 + " " + e)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fs.unlinkSync(FileNameFull2)
|
fs.unlinkSync(FileNameFull2)
|
||||||
@ -306,10 +305,7 @@ class AccountApp extends DApp {
|
|||||||
try {
|
try {
|
||||||
fs.renameSync(this.DBAct.FileNameFull, this.DBActPrev.FileNameFull)
|
fs.renameSync(this.DBAct.FileNameFull, this.DBActPrev.FileNameFull)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
global.ToLog("Can-t rename act-file!")
|
global.ToErrorTx("Can-t rename act-file!" + e)
|
||||||
console.error(e)
|
|
||||||
console.log(`${this.DBAct}, ${this.DBActPrev}`)
|
|
||||||
console.log(`${this.DBAct.FileNameFull}, ${this.DBActPrev.FileNameFull}`)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,6 +324,8 @@ class AccountApp extends DApp {
|
|||||||
case TYPE_TRANSACTION_TRANSFER:
|
case TYPE_TRANSACTION_TRANSFER:
|
||||||
var Num = global.ReadUintFromArr(Body, 1 + 1 + 6);
|
var Num = global.ReadUintFromArr(Body, 1 + 1 + 6);
|
||||||
return Num;
|
return Num;
|
||||||
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
||||||
|
return - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -349,10 +347,9 @@ class AccountApp extends DApp {
|
|||||||
this.BeginTransaction()
|
this.BeginTransaction()
|
||||||
this.DoCoinBaseTR(Block)
|
this.DoCoinBaseTR(Block)
|
||||||
this.CommitTransaction(Block.BlockNum, 0xFFFF)
|
this.CommitTransaction(Block.BlockNum, 0xFFFF)
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
this.RollBackTransaction()
|
this.RollBackTransaction()
|
||||||
global.ToError("DoCoinBaseTR: " + e)
|
global.ToErrorTx("BlockNum:" + Block.BlockNum + " - DoCoinBaseTR: " + e)
|
||||||
}
|
}
|
||||||
this.CommitBlock(Block)
|
this.CommitBlock(Block)
|
||||||
}
|
}
|
||||||
@ -362,6 +359,8 @@ class AccountApp extends DApp {
|
|||||||
Result = this.OnWriteTransactionTR(Block, Body, BlockNum, TrNum, ContextFrom)
|
Result = this.OnWriteTransactionTR(Block, Body, BlockNum, TrNum, ContextFrom)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Result = "" + e
|
Result = "" + e
|
||||||
|
if (global.WATCHDOG_DEV)
|
||||||
|
global.ToErrorTx("BlockNum:" + BlockNum + ":" + e)
|
||||||
}
|
}
|
||||||
if (Result !== true) {
|
if (Result !== true) {
|
||||||
this.RollBackTransaction()
|
this.RollBackTransaction()
|
||||||
@ -405,8 +404,7 @@ class AccountApp extends DApp {
|
|||||||
if (!this.TRCheckAccountHash(Body, BlockNum, TrNum)) {
|
if (!this.TRCheckAccountHash(Body, BlockNum, TrNum)) {
|
||||||
Result = "BAD ACCOUNT HASH"
|
Result = "BAD ACCOUNT HASH"
|
||||||
global.ToLog("2. ****FIND BAD ACCOUNT HASH IN BLOCK: " + BlockNumHash + " DO BLOCK=" + BlockNum)
|
global.ToLog("2. ****FIND BAD ACCOUNT HASH IN BLOCK: " + BlockNumHash + " DO BLOCK=" + BlockNum)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Result = true
|
Result = true
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -417,8 +415,6 @@ class AccountApp extends DApp {
|
|||||||
DoCoinBaseTR(Block) {
|
DoCoinBaseTR(Block) {
|
||||||
if (Block.BlockNum < global.START_MINING)
|
if (Block.BlockNum < global.START_MINING)
|
||||||
return;
|
return;
|
||||||
if (!Block.PowHash)
|
|
||||||
throw "#121 ERROR NO Block.PowHash";
|
|
||||||
var SysData = this.ReadStateTR(0);
|
var SysData = this.ReadStateTR(0);
|
||||||
var SysBalance = SysData.Value.SumCOIN;
|
var SysBalance = SysData.Value.SumCOIN;
|
||||||
const REF_PERIOD_START = global.START_MINING;
|
const REF_PERIOD_START = global.START_MINING;
|
||||||
@ -430,7 +426,6 @@ class AccountApp extends DApp {
|
|||||||
if (Data && Data.Currency === 0 && Data.BlockNumCreate < Block.BlockNum) {
|
if (Data && Data.Currency === 0 && Data.BlockNumCreate < Block.BlockNum) {
|
||||||
var Sum;
|
var Sum;
|
||||||
if (Block.BlockNum >= global.NEW_FORMULA_START) {
|
if (Block.BlockNum >= global.NEW_FORMULA_START) {
|
||||||
Sum = Power * Power * SysBalance / global.TOTAL_SUPPLY_TERA / 100
|
|
||||||
if (Block.BlockNum <= global.NEW_FORMULA_TARGET1) {
|
if (Block.BlockNum <= global.NEW_FORMULA_TARGET1) {
|
||||||
Sum = SysBalance * 43 * 43 / 100 / global.TOTAL_SUPPLY_TERA
|
Sum = SysBalance * 43 * 43 / 100 / global.TOTAL_SUPPLY_TERA
|
||||||
var KMult = (global.NEW_FORMULA_TARGET2 - Block.BlockNum) / (global.NEW_FORMULA_TARGET2 - global.NEW_FORMULA_START);
|
var KMult = (global.NEW_FORMULA_TARGET2 - Block.BlockNum) / (global.NEW_FORMULA_TARGET2 - global.NEW_FORMULA_START);
|
||||||
@ -513,8 +508,7 @@ class AccountApp extends DApp {
|
|||||||
var TR;
|
var TR;
|
||||||
try {
|
try {
|
||||||
TR = global.BufLib.GetObjectFromBuffer(Body, format, {})
|
TR = global.BufLib.GetObjectFromBuffer(Body, format, {})
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
}
|
}
|
||||||
return TR;
|
return TR;
|
||||||
}
|
}
|
||||||
@ -568,8 +562,7 @@ class AccountApp extends DApp {
|
|||||||
if (BlockNum >= 7000000 || global.LOCAL_RUN || global.TEST_NETWORK) {
|
if (BlockNum >= 7000000 || global.LOCAL_RUN || global.TEST_NETWORK) {
|
||||||
if (ContextFrom && ContextFrom.To.length === 1 && ContextFrom.To[0].ID === 0 && ContextFrom.To[0].SumCOIN >= global.PRICE_DAO(BlockNum).NewAccount) {
|
if (ContextFrom && ContextFrom.To.length === 1 && ContextFrom.To[0].ID === 0 && ContextFrom.To[0].SumCOIN >= global.PRICE_DAO(BlockNum).NewAccount) {
|
||||||
CheckMinPower = 0
|
CheckMinPower = 0
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (BlockNum % BLOCK_CREATE_INTERVAL !== 0)
|
if (BlockNum % BLOCK_CREATE_INTERVAL !== 0)
|
||||||
return "The create transaction is not possible in this block: " + BlockNum;
|
return "The create transaction is not possible in this block: " + BlockNum;
|
||||||
if (this.CreateTrCount > 0)
|
if (this.CreateTrCount > 0)
|
||||||
@ -629,8 +622,7 @@ class AccountApp extends DApp {
|
|||||||
return "Error length transaction";
|
return "Error length transaction";
|
||||||
try {
|
try {
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, format_money_transfer, workstructtransfer);
|
var TR = global.BufLib.GetObjectFromBuffer(Body, format_money_transfer, workstructtransfer);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
return "Error transaction format";
|
return "Error transaction format";
|
||||||
}
|
}
|
||||||
if (!TR.Version)
|
if (!TR.Version)
|
||||||
@ -643,8 +635,7 @@ class AccountApp extends DApp {
|
|||||||
if (TR.Version < 3) {
|
if (TR.Version < 3) {
|
||||||
if (TR.OperationID !== Data.Value.OperationID)
|
if (TR.OperationID !== Data.Value.OperationID)
|
||||||
return "Error OperationID (expected: " + Data.Value.OperationID + " for ID: " + TR.FromID + ")";
|
return "Error OperationID (expected: " + Data.Value.OperationID + " for ID: " + TR.FromID + ")";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (TR.OperationID < Data.Value.OperationID)
|
if (TR.OperationID < Data.Value.OperationID)
|
||||||
return "Error OperationID (expected: " + Data.Value.OperationID + " for ID: " + TR.FromID + ")";
|
return "Error OperationID (expected: " + Data.Value.OperationID + " for ID: " + TR.FromID + ")";
|
||||||
var MaxCountOperationID = 100;
|
var MaxCountOperationID = 100;
|
||||||
@ -923,13 +914,11 @@ class AccountApp extends DApp {
|
|||||||
Filter = Filter.substring(1)
|
Filter = Filter.substring(1)
|
||||||
try {
|
try {
|
||||||
F = global.CreateEval(Filter, "Cur,Currency,ID,Operation,Amount,Adviser,Name,PubKey,Smart,BlockNum")
|
F = global.CreateEval(Filter, "Cur,Currency,ID,Operation,Amount,Adviser,Name,PubKey,Smart,BlockNum")
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
F = undefined
|
F = undefined
|
||||||
global.ToLog("" + e)
|
global.ToLog("" + e)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Filter = Filter.toUpperCase()
|
Filter = Filter.toUpperCase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1400,7 +1389,6 @@ global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App;
|
|||||||
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
|
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
|
||||||
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH] = App;
|
||||||
|
|
||||||
export default AccountApp;
|
|
||||||
// function TestStateFiles(Size, Format) {
|
// function TestStateFiles(Size, Format) {
|
||||||
// return;
|
// return;
|
||||||
// if (global.PROCESS_NAME !== "MAIN")
|
// if (global.PROCESS_NAME !== "MAIN")
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
class DApp {
|
export default class DApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
Name() {
|
Name() {
|
||||||
@ -69,19 +69,5 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function ReqDir(Path) {
|
|
||||||
// if (fs.existsSync(Path)) {
|
|
||||||
// var arr = fs.readdirSync(Path);
|
|
||||||
// for (var i = 0; i < arr.length; i++) {
|
|
||||||
// var name = arr[i];
|
|
||||||
// global.ToLog("Reg: " + name);
|
|
||||||
// var name2 = Path + "/" + arr[i];
|
|
||||||
// require(name2);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
global.DApps = {};
|
global.DApps = {};
|
||||||
global.DAppByType = {};
|
global.DAppByType = {};
|
||||||
|
|
||||||
export default DApp;
|
|
@ -9,12 +9,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import DApp from './dapp'
|
|
||||||
global.TYPE_TRANSACTION_FILE = 5;
|
global.TYPE_TRANSACTION_FILE = 5;
|
||||||
global.FORMAT_FILE_CREATE = "{type:byte,Name:str,ContentType:str,Reserve:arr10,Data:tr}";
|
global.FORMAT_FILE_CREATE = "{type:byte,Name:str,ContentType:str,Reserve:arr10,Data:tr}";
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let WorkStructRun = {};
|
let WorkStructRun = {};
|
||||||
class FileApp extends DApp {
|
import DApp from './dapp'
|
||||||
|
export default class FileApp extends DApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@ -37,5 +37,3 @@ class FileApp extends DApp {
|
|||||||
var App = new FileApp;
|
var App = new FileApp;
|
||||||
global.DApps.File = App;
|
global.DApps.File = App;
|
||||||
global.DAppByType[global.TYPE_TRANSACTION_FILE] = App;
|
global.DAppByType[global.TYPE_TRANSACTION_FILE] = App;
|
||||||
|
|
||||||
export default FileApp
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import DApp from './dapp'
|
|
||||||
require('../core/crypto-library');
|
require('../core/crypto-library');
|
||||||
const OPEN_TYPE_TRANSACTION = 11;
|
const OPEN_TYPE_TRANSACTION = 11;
|
||||||
const MESSAGE_TYPE_TRANSACTION = 12;
|
const MESSAGE_TYPE_TRANSACTION = 12;
|
||||||
@ -18,8 +17,8 @@ var TempArrayTr = new Uint8Array(MAX_MSG_SIZE);
|
|||||||
const MESSAGE_START = 9;
|
const MESSAGE_START = 9;
|
||||||
const MESSAGE_END = MAX_MSG_SIZE - 5;
|
const MESSAGE_END = MAX_MSG_SIZE - 5;
|
||||||
import './names'
|
import './names'
|
||||||
|
import DApp from './dapp'
|
||||||
class MessagerApp extends DApp {
|
export default class MessagerApp extends DApp {
|
||||||
Server
|
Server
|
||||||
Channels
|
Channels
|
||||||
NamesMap
|
NamesMap
|
||||||
@ -107,9 +106,9 @@ class MessagerApp extends DApp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function TestEncryptDecrypt() {
|
function TestEncryptDecrypt() {
|
||||||
// const CMessager = module.exports;
|
const CMessager = module.exports;
|
||||||
// var Server = { KeyPair: global.GetKeyPairTest("Test"), DApp: { Names: { KeyValueMap: {} } }, };
|
var Server = { KeyPair: global.GetKeyPairTest("Test"), DApp: { Names: { KeyValueMap: {} } }, };
|
||||||
// var Test = new CMessager(Server);
|
var Test = new CMessager(Server);
|
||||||
var KeyPair2 = global.GetKeyPairTest("Test2");
|
var KeyPair2 = global.GetKeyPairTest("Test2");
|
||||||
var StrTest1 = global.GetArrFromStr("Test2", 32);
|
var StrTest1 = global.GetArrFromStr("Test2", 32);
|
||||||
var StrKey = global.GetHexFromAddres(StrTest1);
|
var StrKey = global.GetHexFromAddres(StrTest1);
|
||||||
@ -119,9 +118,8 @@ function TestEncryptDecrypt() {
|
|||||||
console.log("Decrypt:");
|
console.log("Decrypt:");
|
||||||
console.log(Str2);
|
console.log(Str2);
|
||||||
};
|
};
|
||||||
|
|
||||||
var messager = new MessagerApp();
|
var messager = new MessagerApp();
|
||||||
global.DApps.Messager = messager;
|
global.DApps.Messager = messager;
|
||||||
global.DAppByType[OPEN_TYPE_TRANSACTION] = messager;
|
global.DAppByType[OPEN_TYPE_TRANSACTION] = messager;
|
||||||
global.DAppByType[MESSAGE_TYPE_TRANSACTION] = messager;
|
global.DAppByType[MESSAGE_TYPE_TRANSACTION] = messager;
|
||||||
|
|
||||||
export default MessagerApp;
|
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import DApp from './dapp'
|
|
||||||
const NAMES_TYPE_TRANSACTION = 10;
|
const NAMES_TYPE_TRANSACTION = 10;
|
||||||
class NameApp extends DApp {
|
import DApp from './dapp'
|
||||||
|
export default class NameApp extends DApp {
|
||||||
Server
|
Server
|
||||||
KeyValueMap;
|
KeyValueMap;
|
||||||
CurrentNameArr;
|
CurrentNameArr;
|
||||||
@ -33,8 +33,7 @@ class NameApp extends DApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Name = new NameApp();
|
var Name = new NameApp();
|
||||||
global.DApps.Names = Name;
|
global.DApps.Names = Name;
|
||||||
global.DAppByType[NAMES_TYPE_TRANSACTION] = Name;
|
global.DAppByType[NAMES_TYPE_TRANSACTION] = Name;
|
||||||
|
|
||||||
export default NameApp
|
|
@ -9,13 +9,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import DApp from './dapp'
|
|
||||||
import DBRow from '../core/db/db-row'
|
|
||||||
import { secp256k1 } from '../core/library'
|
|
||||||
|
|
||||||
const LOC_ADD_NAME = "$";
|
const LOC_ADD_NAME = "$";
|
||||||
require("../HTML/JS/lexer.js");
|
require("../HTML/JS/lexer.js");
|
||||||
global.TickCounter = 0;
|
global.TickCounter = 0;
|
||||||
|
import DBRow from '../core/db/db-row'
|
||||||
|
import DApp from './dapp'
|
||||||
|
import { secp256k1 } from '../core/library'
|
||||||
const TYPE_TRANSACTION_SMART_CREATE = 130;
|
const TYPE_TRANSACTION_SMART_CREATE = 130;
|
||||||
global.TYPE_TRANSACTION_SMART_RUN = 135;
|
global.TYPE_TRANSACTION_SMART_RUN = 135;
|
||||||
const TYPE_TRANSACTION_SMART_CHANGE = 140;
|
const TYPE_TRANSACTION_SMART_CHANGE = 140;
|
||||||
@ -63,7 +62,7 @@ global.FORMAT_SMART_CHANGE = "{\
|
|||||||
Sign:arr64,\
|
Sign:arr64,\
|
||||||
}";
|
}";
|
||||||
const WorkStructChange = {};
|
const WorkStructChange = {};
|
||||||
class SmartApp extends DApp {
|
export default class SmartApp extends DApp {
|
||||||
FORMAT_ROW
|
FORMAT_ROW
|
||||||
ROW_SIZE
|
ROW_SIZE
|
||||||
DBSmart
|
DBSmart
|
||||||
@ -1213,10 +1212,9 @@ function StaticGetSmart(Num) {
|
|||||||
};
|
};
|
||||||
ChangePrototype();
|
ChangePrototype();
|
||||||
InitEval();
|
InitEval();
|
||||||
|
|
||||||
var smartApp = new SmartApp;
|
var smartApp = new SmartApp;
|
||||||
global.DApps.Smart = smartApp;
|
global.DApps.Smart = smartApp;
|
||||||
global.DAppByType[TYPE_TRANSACTION_SMART_CREATE] = smartApp;
|
global.DAppByType[TYPE_TRANSACTION_SMART_CREATE] = smartApp;
|
||||||
global.DAppByType[global.TYPE_TRANSACTION_SMART_RUN] = smartApp;
|
global.DAppByType[global.TYPE_TRANSACTION_SMART_RUN] = smartApp;
|
||||||
global.DAppByType[TYPE_TRANSACTION_SMART_CHANGE] = smartApp;
|
global.DAppByType[TYPE_TRANSACTION_SMART_CHANGE] = smartApp;
|
||||||
|
|
||||||
export default SmartApp
|
|
Loading…
Reference in New Issue
Block a user