refactor: sync code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
8576359edc
commit
12e835d5f5
@ -9,9 +9,8 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
// import * as crypto from 'crypto';
|
||||
import CNode from './node'
|
||||
import CMessages from './transfer-msg'
|
||||
import { secp256k1 } from './library'
|
||||
global.PERIOD_FOR_RECONNECT = 3600 * 1000;
|
||||
global.CHECK_DELTA_TIME = { Num: 0, bUse: 0, StartBlockNum: 0, EndBlockNum: 0, bAddTime: 0, DeltaTime: 0, Sign: [] };
|
||||
global.CHECK_POINT = { BlockNum: 0, Hash: [], Sign: [] };
|
||||
@ -28,10 +27,11 @@ const MAX_PERIOD_GETNODES = 120 * 1000;
|
||||
global.MIN_PERIOD_PING = 4 * 1000;
|
||||
const MAX_PERIOD_PING = 120 * 1000;
|
||||
global.MAX_PING_FOR_CONNECT = 400;
|
||||
const CAN_START_TIME_AVG = 200;
|
||||
var MAX_TIME_CORRECT = 3 * 3600 * 1000;
|
||||
global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME;
|
||||
const PERIOD_FOR_START_CHECK_TIME = 300;
|
||||
const CAN_START_TIME_AVG = 200;
|
||||
import CMessages from './transfer-msg'
|
||||
export default class CConnect extends CMessages {
|
||||
ip
|
||||
port
|
||||
@ -217,17 +217,34 @@ export default class CConnect extends CMessages {
|
||||
VERSIONMAX: global.DEF_VERSION,
|
||||
FIRST_TIME_BLOCK: 0,
|
||||
PingVersion: 3,
|
||||
GrayConnect: GrayAddres, Reserve2: 0, AutoCorrectTime: global.AUTO_CORRECT_TIME,
|
||||
LevelCount: LevelCount, Time: (global.GetCurrentTime() - 0), BlockNumDB: this.BlockNumDB, LoadHistoryMode: this.LoadHistoryMode, CanStart: global.CAN_START,
|
||||
CheckPoint: global.CHECK_POINT, Reserv3: [], Key: this.KeyToNode, Name: this.NameToNode, TrafficFree: this.SendTrafficFree, AccountBlockNum: BlockNumHash,
|
||||
AccountsHash: AccountsHash, MemoryUsage: Math.trunc(process.memoryUsage().heapTotal / 1024 / 1024), CheckDeltaTime: global.CHECK_DELTA_TIME,
|
||||
CodeVersion: global.CODE_VERSION, IsAddrList: global.ADDRLIST_MODE, CheckPointHashDB: CheckPointHashDB, PortWeb: global.HTTP_HOSTING_PORT, HashDB: HashDB,
|
||||
StopGetBlock: StopGetBlock, NetConstant: global.NET_CONSTANT,
|
||||
GrayConnect: GrayAddres,
|
||||
Reserve2: 0,
|
||||
AutoCorrectTime: global.AUTO_CORRECT_TIME,
|
||||
LevelCount: LevelCount,
|
||||
Time: (global.GetCurrentTime() - 0),
|
||||
BlockNumDB: this.BlockNumDB,
|
||||
LoadHistoryMode: this.LoadHistoryMode,
|
||||
CanStart: global.CAN_START,
|
||||
CheckPoint: global.CHECK_POINT,
|
||||
Reserv3: [],
|
||||
Key: this.KeyToNode,
|
||||
Name: this.NameToNode,
|
||||
TrafficFree: this.SendTrafficFree,
|
||||
AccountBlockNum: BlockNumHash,
|
||||
AccountsHash: AccountsHash,
|
||||
MemoryUsage: Math.trunc(process.memoryUsage().heapTotal / 1024 / 1024),
|
||||
CheckDeltaTime: global.CHECK_DELTA_TIME,
|
||||
CodeVersion: global.CODE_VERSION,
|
||||
IsAddrList: global.ADDRLIST_MODE,
|
||||
CheckPointHashDB: CheckPointHashDB,
|
||||
PortWeb: global.HTTP_HOSTING_PORT,
|
||||
HashDB: HashDB,
|
||||
StopGetBlock: StopGetBlock,
|
||||
NetConstant: global.NET_CONSTANT,
|
||||
};
|
||||
return Ret;
|
||||
}
|
||||
static
|
||||
PING_F(bSend) {
|
||||
static PING_F(bSend) {
|
||||
return "{\
|
||||
VERSIONMAX:str15,\
|
||||
PingVersion:byte,\
|
||||
@ -886,7 +903,7 @@ export default class CConnect extends CMessages {
|
||||
}
|
||||
if (!this.SignCurrentTimeDev) {
|
||||
var SignArr = global.GetArrFromHex(global.SERVER.addrStr);
|
||||
this.SignCurrentTimeDev = global.GetArrFromValue(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||
this.SignCurrentTimeDev = secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||
}
|
||||
var Time = global.GetCurrentTime() - 0;
|
||||
global.ToLog("Send time: " + Time + " to " + global.NodeInfo(Node))
|
||||
|
@ -66,6 +66,8 @@ global.CONST_NAME_ARR = [
|
||||
global.MAX_LENGTH_SENDER_MAP = 3000;
|
||||
global.DELTA_START_SENDER_MAP = 24;
|
||||
global.NODES_DELTA_CALC_HOUR = 4;
|
||||
global.USE_API_WALLET = 1;
|
||||
global.USE_API_V1 = 1;
|
||||
global.USE_HARD_API_V2 = 0;
|
||||
global.USE_TICKET = 0;
|
||||
global.USE_CHECK_SENDING = 1;
|
||||
@ -76,7 +78,7 @@ global.WATCHDOG_BADACCOUNT = 1;
|
||||
global.WATCHDOG_DEV = 0;
|
||||
global.RESYNC_CONDITION = { "OWN_BLOCKS": 20, "K_POW": 5 };
|
||||
global.REST_BLOCK_SCALE = 1000;
|
||||
global.REST_START_COUNT = 10000;
|
||||
global.REST_START_COUNT = 1000;
|
||||
global.LOAD_TO_BEGIN = 2;
|
||||
global.DEBUG_WALLET = 0;
|
||||
global.CHECK_GLOBAL_TIME = 1;
|
||||
@ -114,7 +116,8 @@ global.SIZE_MINING_MEMORY = 0;
|
||||
global.HTTP_HOSTING_PORT = 0;
|
||||
global.HTTPS_HOSTING_DOMAIN = "";
|
||||
global.HTTP_MAX_COUNT_ROWS = 20;
|
||||
global.HTTP_ADMIN_PASSORD = "";
|
||||
global.HTTP_ADMIN_PASSWORD = "";
|
||||
global.HTTP_START_PAGE = "";
|
||||
require("./startlib");
|
||||
global.MIN_POWER_POW_HANDSHAKE = 12;
|
||||
global.USE_HINT = 0;
|
||||
@ -232,6 +235,8 @@ else
|
||||
global.COUNT_NODE_PROOF = 8;
|
||||
global.REST_START_COUNT = 10000;
|
||||
global.NEW_SIGN_TIME = 4859000;
|
||||
global.MAX_LENGTH_SENDER_MAP = 100;
|
||||
global.DELTA_START_SENDER_MAP = 12;
|
||||
}
|
||||
if (global.LOCAL_RUN) {
|
||||
global.BLOCKNUM_TICKET_ALGO = 0;
|
||||
|
@ -8,8 +8,8 @@
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
require("./library");
|
||||
import { secp256k1 } from './library'
|
||||
import * as crypto from 'crypto'
|
||||
import { secp256k1 } from './library'
|
||||
|
||||
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
|
||||
var BuferForStr = Buffer.alloc(32);
|
||||
@ -79,18 +79,16 @@ global.CheckDevelopSign = function(SignArr, Sign) {
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
let GetPublicKeyFromAddres = global.GetPublicKeyFromAddres;
|
||||
global.CheckContextSecret = function(Context, ContextAddrTo) {
|
||||
if (ContextAddrTo.Secret === undefined) {
|
||||
if (ContextAddrTo.publickey === undefined) {
|
||||
ContextAddrTo.publickey = GetPublicKeyFromAddres(ContextAddrTo.addrArr);
|
||||
ContextAddrTo.publickey = global.GetPublicKeyFromAddres(ContextAddrTo.addrArr);
|
||||
}
|
||||
ContextAddrTo.Secret = Context.KeyPair.computeSecret(ContextAddrTo.publickey, null);
|
||||
}
|
||||
};
|
||||
let CheckContextSecret = global.CheckContextSecret;
|
||||
global.GetSignHash = function(Context, ContextAddrTo, Msg) {
|
||||
CheckContextSecret(Context, ContextAddrTo);
|
||||
global.CheckContextSecret(Context, ContextAddrTo);
|
||||
if (typeof Msg === "string")
|
||||
Msg = Buffer.from(Msg);
|
||||
var Buf = Buffer.concat([Msg, ContextAddrTo.Secret], Msg.length + ContextAddrTo.Secret.length);
|
||||
@ -924,9 +922,9 @@ function Utf8ArrayToStr(array) {
|
||||
return out;
|
||||
};
|
||||
|
||||
// function GetArr32FromStr(Str) {
|
||||
// return GetArrFromStr(Str, 32);
|
||||
// };
|
||||
function GetArr32FromStr(Str) {
|
||||
return GetArrFromStr(Str, 32);
|
||||
};
|
||||
|
||||
function GetArrFromStr(Str, Len) {
|
||||
var arr = toUTF8Array(Str);
|
||||
@ -1035,4 +1033,4 @@ declare global {
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
147
src/core/geo.ts
147
src/core/geo.ts
@ -7,71 +7,116 @@
|
||||
* Twitter: https://twitter.com/terafoundation
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
|
||||
import * as fs from 'fs'
|
||||
import './library'
|
||||
|
||||
import "./library.js"
|
||||
var BufIP;
|
||||
var MapNames = {}, FileIp = "./SITE/DB/iplocation.db", FileNames = "./SITE/DB/locationnames.csv", Format = "{Value:uint32,Length:uint32, id:uint32, latitude:uint32, longitude:uint32}",
|
||||
FormatStruct = {};
|
||||
var MapNames = {};
|
||||
var FileIp = "./SITE/DB/iplocation.db";
|
||||
var FileNames = "./SITE/DB/locationnames.csv";
|
||||
var Format = "{Value:uint32,Length:uint32, id:uint32, latitude:uint32, longitude:uint32}";
|
||||
var FormatStruct = {};
|
||||
|
||||
function SetGeoLocation(e) {
|
||||
if (!e.ip || !BufIP || !BufIP.length)
|
||||
return !1;
|
||||
var t = IPToUint(e.ip), i = FindItem(BufIP, 20, t);
|
||||
return i && (e.latitude = i.latitude, e.longitude = i.longitude, e.name = MapNames[i.id]), e.Geo = 1, !0;
|
||||
function SetGeoLocation(Item) {
|
||||
if (!Item.ip || !BufIP || !BufIP.length)
|
||||
return false;
|
||||
var Num = IPToUint(Item.ip);
|
||||
var Location = FindItem(BufIP, 20, Num);
|
||||
if (Location) {
|
||||
Item.latitude = Location.latitude;
|
||||
Item.longitude = Location.longitude;
|
||||
Item.name = MapNames[Location.id];
|
||||
}
|
||||
Item.Geo = 1;
|
||||
return true;
|
||||
};
|
||||
|
||||
function ReadItem(e, t) {
|
||||
return BufIP.len = e * t, global.BufLib.Read(BufIP, Format, void 0, FormatStruct);
|
||||
function ReadItem(Num, Size) {
|
||||
BufIP.len = Num * Size;
|
||||
var Data = global.BufLib.Read(BufIP, Format, undefined, FormatStruct);
|
||||
return Data;
|
||||
};
|
||||
|
||||
function FindItem(e, t, i) {
|
||||
var n, r = Math.trunc(e.length / t), a = (ReadItem(0, t), ReadItem(r, t), 0), u = r, o = Math.trunc(i * r / 4294967296);
|
||||
r <= o && (o = r - 1), o < a && (o = a);
|
||||
for (var f = 40; 0 < f;) {
|
||||
if (f-- , !(n = ReadItem(o, t)))
|
||||
return void global.ToLog("GEO FindItem - Error read num: " + o);
|
||||
if (n.Value > i) {
|
||||
if (u = o - 1, 0 === (l = o - a))
|
||||
return;
|
||||
o -= l = Math.trunc((1 + l) / 2);
|
||||
}
|
||||
else
|
||||
if (n.Value < i) {
|
||||
if (n.Value + n.Length >= i)
|
||||
return n;
|
||||
var l;
|
||||
if (a = o + 1, 0 === (l = u - o))
|
||||
return;
|
||||
o += l = Math.trunc((1 + l) / 2);
|
||||
function FindItem(Buf, Size, FindValue) {
|
||||
var Item;
|
||||
var MaxNum = Math.trunc(Buf.length / Size);
|
||||
var MinItem = ReadItem(0, Size);
|
||||
var MaxItem = ReadItem(MaxNum, Size);
|
||||
var StartNum = 0;
|
||||
var EndNum = MaxNum;
|
||||
var CurNum = Math.trunc(FindValue * MaxNum / 0x100000000);
|
||||
if (CurNum >= MaxNum)
|
||||
CurNum = MaxNum - 1;
|
||||
if (CurNum < StartNum)
|
||||
CurNum = StartNum;
|
||||
var CountIt = 40;
|
||||
while (CountIt > 0) {
|
||||
CountIt--;
|
||||
Item = ReadItem(CurNum, Size);
|
||||
if (Item) {
|
||||
if (Item.Value > FindValue) {
|
||||
EndNum = CurNum - 1;
|
||||
var Delta = CurNum - StartNum;
|
||||
if (Delta === 0)
|
||||
return undefined;
|
||||
Delta = Math.trunc((1 + Delta) / 2);
|
||||
CurNum = CurNum - Delta;
|
||||
}
|
||||
else
|
||||
if (n.Value === i)
|
||||
return n;
|
||||
if (Item.Value < FindValue) {
|
||||
if (Item.Value + Item.Length >= FindValue)
|
||||
return Item;
|
||||
StartNum = CurNum + 1;
|
||||
var Delta = EndNum - CurNum;
|
||||
if (Delta === 0)
|
||||
return undefined;
|
||||
Delta = Math.trunc((1 + Delta) / 2);
|
||||
CurNum = CurNum + Delta;
|
||||
}
|
||||
else
|
||||
if (Item.Value === FindValue)
|
||||
return Item;
|
||||
}
|
||||
else {
|
||||
global.ToLog("GEO FindItem - Error read num: " + CurNum);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
function Init() {
|
||||
if (fs.existsSync(FileIp) && fs.existsSync(FileNames)) {
|
||||
BufIP = fs.readFileSync(FileIp);
|
||||
for (var e = fs.readFileSync(FileNames), t = 0; ;) {
|
||||
var i = e.indexOf("\n", t);
|
||||
if (i < 0)
|
||||
break;
|
||||
var n = e.toString("utf-8", t, i - 1);
|
||||
t = i + 1;
|
||||
var r = n.split(","), a = parseInt(r[0]);
|
||||
if (a) {
|
||||
0;
|
||||
var u = r[10];
|
||||
u = (u = u || r[7]) || r[5], MapNames[a] = u;
|
||||
}
|
||||
}
|
||||
if (!fs.existsSync(FileIp))
|
||||
return;
|
||||
if (!fs.existsSync(FileNames))
|
||||
return;
|
||||
BufIP = fs.readFileSync(FileIp);
|
||||
var Buf = fs.readFileSync(FileNames);
|
||||
var index2 = 0;
|
||||
var Count = 0;
|
||||
while (true) {
|
||||
var index = Buf.indexOf("\n", index2);
|
||||
if (index < 0)
|
||||
break;
|
||||
var Str = Buf.toString('utf-8', index2, index - 1);
|
||||
index2 = index + 1;
|
||||
var Arr = Str.split(',');
|
||||
var Num = parseInt(Arr[0]);
|
||||
if (!Num)
|
||||
continue;
|
||||
Count++;
|
||||
var Name = Arr[10];
|
||||
if (!Name)
|
||||
Name = Arr[7];
|
||||
if (!Name)
|
||||
Name = Arr[5];
|
||||
MapNames[Num] = Name;
|
||||
}
|
||||
};
|
||||
|
||||
function IPToUint(e) {
|
||||
var t = e.split(".");
|
||||
return 256 * (256 * (256 * + t[0] + + t[1]) + + t[2]) + + t[3];
|
||||
function IPToUint(IPv4) {
|
||||
var d = IPv4.split('.');
|
||||
return ((((((+ d[0]) * 256) + (+ d[1])) * 256) + (+ d[2])) * 256) + (+ d[3]);
|
||||
};
|
||||
global.SetGeoLocation = SetGeoLocation, Init();
|
||||
global.SetGeoLocation = SetGeoLocation;
|
||||
Init();
|
||||
|
@ -44,7 +44,7 @@ ContenTypeMap[".js"] = "application/javascript";
|
||||
ContenTypeMap["html"] = "text/html";
|
||||
ContenTypeMap["psd"] = "application/octet-stream";
|
||||
global.HTTPCaller = {};
|
||||
let HTTPCaller = global.HTTPCaller
|
||||
|
||||
function DoCommand(response, Type, Path, params, remoteAddress) {
|
||||
var F = global.HTTPCaller[params[0]];
|
||||
if (F) {
|
||||
@ -238,7 +238,7 @@ function SendToResponce404(response) {
|
||||
response.writeHead(404, { 'Content-Type': 'text/html' });
|
||||
response.end();
|
||||
};
|
||||
HTTPCaller.DappBlockFile = function(Params, response) {
|
||||
global.HTTPCaller.DappBlockFile = function(Params, response) {
|
||||
Params.BlockNum = global.ParseNum(Params.BlockNum);
|
||||
Params.TrNum = global.ParseNum(Params.TrNum);
|
||||
if (!Params.TrNum)
|
||||
@ -289,7 +289,7 @@ function SendToResponceResult0(response) {
|
||||
response.end("{\"result\":0}");
|
||||
};
|
||||
var glBlock0;
|
||||
HTTPCaller.DappStaticCall = function(Params, response) {
|
||||
global.HTTPCaller.DappStaticCall = function(Params, response) {
|
||||
global.DApps.Accounts.BeginBlock();
|
||||
global.DApps.Accounts.BeginTransaction();
|
||||
global.TickCounter = 100000;
|
||||
@ -312,7 +312,7 @@ HTTPCaller.DappStaticCall = function(Params, response) {
|
||||
response.end(Str);
|
||||
return null;
|
||||
};
|
||||
HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
||||
global.HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
||||
var SmartNum = global.ParseNum(Params.Smart);
|
||||
if (global.TX_PROCESS && global.TX_PROCESS.Worker)
|
||||
global.TX_PROCESS.Worker.send({ cmd: "SetSmartEvent", Smart: SmartNum });
|
||||
@ -336,7 +336,7 @@ HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
||||
DeleteOldEvents(SmartNum);
|
||||
var Context = GetUserContext(Params);
|
||||
var EArr = GetEventArray(SmartNum, Context);
|
||||
var WLData = HTTPCaller.DappWalletList(Params);
|
||||
var WLData = global.HTTPCaller.DappWalletList(Params);
|
||||
var ArrLog = [];
|
||||
for (var i = 0; i < global.ArrLogClient.length; i++) {
|
||||
var Item = global.ArrLogClient[i];
|
||||
@ -363,7 +363,7 @@ HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
||||
}
|
||||
return Ret;
|
||||
};
|
||||
HTTPCaller.DappWalletList = function(Params) {
|
||||
global.HTTPCaller.DappWalletList = function(Params) {
|
||||
var arr0 = global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap);
|
||||
var arr = [];
|
||||
for (var i = 0; i < arr0.length; i++) {
|
||||
@ -374,54 +374,54 @@ HTTPCaller.DappWalletList = function(Params) {
|
||||
var Ret: any = { result: 1, arr: arr, };
|
||||
return Ret;
|
||||
};
|
||||
HTTPCaller.DappAccountList = function(Params) {
|
||||
global.HTTPCaller.DappAccountList = function(Params) {
|
||||
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, undefined, 1);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.DappSmartList = function(Params) {
|
||||
global.HTTPCaller.DappSmartList = function(Params) {
|
||||
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, undefined, undefined, Params.GetAllData, Params.TokenGenerate);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.DappBlockList = function(Params, response) {
|
||||
global.HTTPCaller.DappBlockList = function(Params, response) {
|
||||
Params.Filter = undefined;
|
||||
return HTTPCaller.GetBlockList(Params, response, 1);
|
||||
return global.HTTPCaller.GetBlockList(Params, response, 1);
|
||||
};
|
||||
HTTPCaller.DappTransactionList = function(Params, response) {
|
||||
global.HTTPCaller.DappTransactionList = function(Params, response) {
|
||||
Params.Filter = undefined;
|
||||
Params.Param3 = Params.BlockNum;
|
||||
return HTTPCaller.GetTransactionAll(Params, response);
|
||||
return global.HTTPCaller.GetTransactionAll(Params, response);
|
||||
};
|
||||
var sessionid = global.GetHexFromAddres(crypto.randomBytes(20));
|
||||
HTTPCaller.RestartNode = function(Params) {
|
||||
global.HTTPCaller.RestartNode = function(Params) {
|
||||
global.RestartNode();
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.ToLogServer = function(Str) {
|
||||
global.HTTPCaller.ToLogServer = function(Str) {
|
||||
global.ToLogClient(Str);
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.FindMyAccounts = function(Params) {
|
||||
global.HTTPCaller.FindMyAccounts = function(Params) {
|
||||
global.WALLET.FindMyAccounts(1);
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.GetAccount = function(id) {
|
||||
global.HTTPCaller.GetAccount = function(id) {
|
||||
id = parseInt(id);
|
||||
var arr = global.DApps.Accounts.GetRowsAccounts(id, 1);
|
||||
return { Item: arr[0], result: 1 };
|
||||
};
|
||||
HTTPCaller.GetAccountList = function(Params) {
|
||||
global.HTTPCaller.GetAccountList = function(Params) {
|
||||
if (!Params.CountNum)
|
||||
Params.CountNum = 1;
|
||||
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, Params.Filter);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetDappList = function(Params) {
|
||||
global.HTTPCaller.GetDappList = function(Params) {
|
||||
if (!Params.CountNum)
|
||||
Params.CountNum = 1;
|
||||
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, Params.Filter, Params.Filter2, 1);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
||||
global.HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
||||
if (!Params.CountNum)
|
||||
Params.CountNum = 1;
|
||||
if (Params.StartNum < global.SERVER.BlockNumDBMin) {
|
||||
@ -448,7 +448,7 @@ HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
||||
var arr = global.SERVER.GetRows(Params.StartNum, Params.CountNum, Params.Filter, !bOnlyNum);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetTransactionAll = function(Params, response) {
|
||||
global.HTTPCaller.GetTransactionAll = function(Params, response) {
|
||||
if (!Params.CountNum)
|
||||
Params.CountNum = 1;
|
||||
var BlockNum = Params.Param3;
|
||||
@ -473,11 +473,11 @@ HTTPCaller.GetTransactionAll = function(Params, response) {
|
||||
var arr = global.SERVER.GetTrRows(BlockNum, Params.StartNum, Params.CountNum, Params.Filter);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetActList = function(Params) {
|
||||
global.HTTPCaller.GetActList = function(Params) {
|
||||
var arr = global.DApps.Accounts.GetActList(Params.StartNum, Params.CountNum, Params.Filter);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetHashList = function(Params) {
|
||||
global.HTTPCaller.GetHashList = function(Params) {
|
||||
var arr = global.DApps.Accounts.DBAccountsHash.GetRows(Params.StartNum, Params.CountNum, Params.Filter);
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var item = arr[i];
|
||||
@ -491,14 +491,14 @@ HTTPCaller.GetHashList = function(Params) {
|
||||
}
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetHistoryAct = function(Params) {
|
||||
global.HTTPCaller.GetHistoryAct = function(Params) {
|
||||
var arr = global.WALLET.GetHistory(Params.StartNum, Params.CountNum, Params.Filter);
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
var LastTimeGetHashRate = 0;
|
||||
var LastHashRate = 0;
|
||||
var HashRateOneSec = 0;
|
||||
HTTPCaller.GetWalletInfo = function(Params) {
|
||||
global.HTTPCaller.GetWalletInfo = function(Params) {
|
||||
var Constants = {};
|
||||
for (var i = 0; i < global.CONST_NAME_ARR.length; i++) {
|
||||
var key = global.CONST_NAME_ARR[i];
|
||||
@ -571,37 +571,37 @@ HTTPCaller.GetWalletInfo = function(Params) {
|
||||
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
||||
return Ret;
|
||||
};
|
||||
HTTPCaller.GetCurrentInfo = HTTPCaller.GetWalletInfo;
|
||||
HTTPCaller.TestSignLib = function() {
|
||||
global.HTTPCaller.GetCurrentInfo = global.HTTPCaller.GetWalletInfo;
|
||||
global.HTTPCaller.TestSignLib = function() {
|
||||
global.TestSignLib();
|
||||
};
|
||||
HTTPCaller.GetWalletAccounts = function() {
|
||||
global.HTTPCaller.GetWalletAccounts = function() {
|
||||
var Ret: any = { result: 1, arr: global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap), };
|
||||
Ret.PrivateKey = global.WALLET.KeyPair.PrivKeyStr;
|
||||
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
||||
return Ret;
|
||||
};
|
||||
HTTPCaller.SetWalletKey = function(PrivateKeyStr) {
|
||||
global.HTTPCaller.SetWalletKey = function(PrivateKeyStr) {
|
||||
global.WALLET.SetPrivateKey(PrivateKeyStr, true);
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.SetWalletPasswordNew = function(Password) {
|
||||
global.HTTPCaller.SetWalletPasswordNew = function(Password) {
|
||||
global.WALLET.SetPasswordNew(Password);
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.OpenWallet = function(Password) {
|
||||
global.HTTPCaller.OpenWallet = function(Password) {
|
||||
var res = global.WALLET.OpenWallet(Password);
|
||||
return { result: res };
|
||||
};
|
||||
HTTPCaller.CloseWallet = function() {
|
||||
global.HTTPCaller.CloseWallet = function() {
|
||||
var res = global.WALLET.CloseWallet();
|
||||
return { result: res };
|
||||
};
|
||||
HTTPCaller.GetSignTransaction = function(TR) {
|
||||
global.HTTPCaller.GetSignTransaction = function(TR) {
|
||||
var Sign = global.WALLET.GetSignTransaction(TR);
|
||||
return { Sign: Sign, result: 1 };
|
||||
};
|
||||
HTTPCaller.GetSignFromHEX = function(Params) {
|
||||
global.HTTPCaller.GetSignFromHEX = function(Params) {
|
||||
var Arr = global.GetArrFromHex(Params.Hex);
|
||||
var Sign;
|
||||
if (Params.Account)
|
||||
@ -610,7 +610,7 @@ HTTPCaller.GetSignFromHEX = function(Params) {
|
||||
Sign = global.WALLET.GetSignFromArr(Arr);
|
||||
return { Sign: Sign, result: 1 };
|
||||
};
|
||||
HTTPCaller.SendTransactionHex = function(Params) {
|
||||
global.HTTPCaller.SendTransactionHex = function(Params) {
|
||||
var body = global.GetArrFromHex(Params.Hex);
|
||||
var Result: any = { result: 1 };
|
||||
var Res = global.SERVER.AddTransactionOwn({ body: body, ToAll: 1 });
|
||||
@ -622,11 +622,16 @@ HTTPCaller.SendTransactionHex = function(Params) {
|
||||
global.ToLogClient("Send: " + Result.text, global.GetHexFromArr(global.sha3(body)), final);
|
||||
return Result;
|
||||
};
|
||||
HTTPCaller.SendDirectCode = function(Params, response) {
|
||||
global.HTTPCaller.SendDirectCode = function(Params, response) {
|
||||
var Result;
|
||||
if (Params.TX) {
|
||||
if (global.TX_PROCESS && global.TX_PROCESS.RunRPC) {
|
||||
global.TX_PROCESS.RunRPC("EvalCode", Params.Code, function(Err, Ret) {
|
||||
if (Params.TX || Params.WEB) {
|
||||
var RunProcess;
|
||||
if (Params.TX)
|
||||
RunProcess = global.TX_PROCESS;
|
||||
if (Params.WEB)
|
||||
RunProcess = global.WEB_PROCESS;
|
||||
if (RunProcess && RunProcess.RunRPC) {
|
||||
RunProcess.RunRPC("EvalCode", Params.Code, function(Err, Ret) {
|
||||
Result = { result: !Err, sessionid: sessionid, text: Ret, };
|
||||
var Str = JSON.stringify(Result);
|
||||
response.end(Str);
|
||||
@ -634,7 +639,7 @@ HTTPCaller.SendDirectCode = function(Params, response) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
Result = "No send to TX";
|
||||
Result = "No process for send call";
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -649,7 +654,7 @@ HTTPCaller.SendDirectCode = function(Params, response) {
|
||||
var Struct = { result: 1, sessionid: sessionid, text: Result };
|
||||
return Struct;
|
||||
};
|
||||
HTTPCaller.SetMining = function(MiningAccount) {
|
||||
global.HTTPCaller.SetMining = function(MiningAccount) {
|
||||
global.WALLET.SetMiningAccount(parseInt(MiningAccount));
|
||||
return { result: 1 };
|
||||
};
|
||||
@ -667,7 +672,7 @@ function CheckCorrectDevKey() {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
HTTPCaller.SendECode = function(Param) {
|
||||
global.HTTPCaller.SendECode = function(Param) {
|
||||
var Ret = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -688,7 +693,7 @@ HTTPCaller.SendECode = function(Param) {
|
||||
global.SERVER.SendECode(Param, Node);
|
||||
return { result: 1, text: "Send" };
|
||||
};
|
||||
HTTPCaller.SetCheckPoint = function(BlockNum) {
|
||||
global.HTTPCaller.SetCheckPoint = function(BlockNum) {
|
||||
var Ret = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -716,7 +721,7 @@ function SetCheckPointOnBlock(BlockNum) {
|
||||
};
|
||||
global.SetCheckPointOnBlock = SetCheckPointOnBlock;
|
||||
var idSetTimeSetCheckPoint;
|
||||
HTTPCaller.SetAutoCheckPoint = function(Param) {
|
||||
global.HTTPCaller.SetAutoCheckPoint = function(Param) {
|
||||
var Ret = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -759,7 +764,7 @@ function RunSetCheckPoint() {
|
||||
global.ToLog("SET CHECK POINT Power=" + Power + "/" + AvgPow + " BlockNum=" + BlockNum);
|
||||
}
|
||||
};
|
||||
HTTPCaller.SetNewCodeVersion = function(Data) {
|
||||
global.HTTPCaller.SetNewCodeVersion = function(Data) {
|
||||
var Ret: any = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -767,7 +772,7 @@ HTTPCaller.SetNewCodeVersion = function(Data) {
|
||||
global.SERVER.ResetNextPingAllNode();
|
||||
return { result: 1, text: Ret };
|
||||
};
|
||||
HTTPCaller.SetCheckNetConstant = function(Data) {
|
||||
global.HTTPCaller.SetCheckNetConstant = function(Data) {
|
||||
var Ret: any = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -783,7 +788,7 @@ HTTPCaller.SetCheckNetConstant = function(Data) {
|
||||
global.SERVER.ResetNextPingAllNode();
|
||||
return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum };
|
||||
};
|
||||
HTTPCaller.SetCheckDeltaTime = function(Data) {
|
||||
global.HTTPCaller.SetCheckDeltaTime = function(Data) {
|
||||
var Ret = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -798,7 +803,7 @@ HTTPCaller.SetCheckDeltaTime = function(Data) {
|
||||
return { result: 1, text: "Set check time Num=" + Data.Num };
|
||||
};
|
||||
var idAutoCorrTime;
|
||||
HTTPCaller.SetAutoCorrTime = function(bSet) {
|
||||
global.HTTPCaller.SetAutoCorrTime = function(bSet) {
|
||||
var Ret = CheckCorrectDevKey();
|
||||
if (Ret !== true)
|
||||
return Ret;
|
||||
@ -832,7 +837,7 @@ function RunAutoCorrTime() {
|
||||
global.ToLog("Auto corr time Num:" + Data.Num + " AutoDelta=" + AutoDelta);
|
||||
}
|
||||
};
|
||||
HTTPCaller.SaveConstant = function(SetObj) {
|
||||
global.HTTPCaller.SaveConstant = function(SetObj) {
|
||||
var WasUpdate = global.USE_AUTO_UPDATE;
|
||||
for (var key in SetObj) {
|
||||
global[key] = SetObj[key];
|
||||
@ -850,7 +855,7 @@ HTTPCaller.SaveConstant = function(SetObj) {
|
||||
}
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.SetHTTPParams = function(SetObj) {
|
||||
global.HTTPCaller.SetHTTPParams = function(SetObj) {
|
||||
global.HTTP_PORT_NUMBER = SetObj.HTTPPort;
|
||||
global.HTTP_PORT_PASSWORD = SetObj.HTTPPassword;
|
||||
global.SAVE_CONST(true);
|
||||
@ -858,7 +863,7 @@ HTTPCaller.SetHTTPParams = function(SetObj) {
|
||||
global.RestartNode();
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.SetNetMode = function(SetObj) {
|
||||
global.HTTPCaller.SetNetMode = function(SetObj) {
|
||||
if (!global.NET_WORK_MODE)
|
||||
global.NET_WORK_MODE = {};
|
||||
for (var key in SetObj) {
|
||||
@ -873,7 +878,7 @@ HTTPCaller.SetNetMode = function(SetObj) {
|
||||
global.RestartNode();
|
||||
return { result: 1 };
|
||||
};
|
||||
HTTPCaller.GetAccountKey = function(Num) {
|
||||
global.HTTPCaller.GetAccountKey = function(Num) {
|
||||
var Result: any = {};
|
||||
Result.result = 0;
|
||||
var KeyPair = global.WALLET.GetAccountKey(Num);
|
||||
@ -883,7 +888,7 @@ HTTPCaller.GetAccountKey = function(Num) {
|
||||
}
|
||||
return Result;
|
||||
};
|
||||
HTTPCaller.GetHotArray = function(Param) {
|
||||
global.HTTPCaller.GetHotArray = function(Param) {
|
||||
var ArrTree = global.SERVER.GetTransferTree();
|
||||
if (!ArrTree)
|
||||
return { result: 0 };
|
||||
@ -945,23 +950,50 @@ function GetCopyNode(Node, BlockCounts) {
|
||||
if (BlockCounts !== 0)
|
||||
GetTiming = Math.trunc(Node.GetTiming / BlockCounts) / 1000;
|
||||
var Item = {
|
||||
VersionNum: Node.VersionNum, NoSendTx: Node.NoSendTx, GetNoSendTx: Node.GetNoSendTx, DirectMAccount: Node.DirectMAccount,
|
||||
id: Node.id, ip: Node.ip, portweb: Node.portweb, port: Node.port, TransferCount: Node.TransferCount, GetTiming: GetTiming, ErrCountAll: Node.ErrCountAll,
|
||||
LevelCount: Node.LevelCount, LevelEnum: Node.LevelEnum, TimeTransfer: global.GetStrOnlyTimeUTC(new Date(Node.LastTimeTransfer)), BlockProcessCount: Node.BlockProcessCount,
|
||||
DeltaTime: Node.DeltaTime, DeltaTimeM: Node.DeltaTimeM, DeltaGlobTime: Node.DeltaGlobTime, PingNumber: Node.PingNumber, NextConnectDelta: Node.NextConnectDelta,
|
||||
NextGetNodesDelta: Node.NextGetNodesDelta, NextHotDelta: Node.NextHotDelta, Name: Node.Name, addrStr: Node.addrStr, CanHot: Node.CanHot,
|
||||
Active: Node.Active, Hot: Node.Hot, Info: Node.PrevInfo + Node.Info, InConnectArr: Node.WasAddToConnect, Level: Node.Level, TransferBlockNum: Node.TransferBlockNum,
|
||||
TransferSize: Node.TransferSize, TransferBlockNumFix: Node.TransferBlockNumFix, CurBlockNum: Node.CurBlockNum,
|
||||
VersionNum: Node.VersionNum,
|
||||
NoSendTx: Node.NoSendTx,
|
||||
GetNoSendTx: Node.GetNoSendTx,
|
||||
DirectMAccount: Node.DirectMAccount,
|
||||
id: Node.id,
|
||||
ip: Node.ip,
|
||||
portweb: Node.portweb,
|
||||
port: Node.port,
|
||||
TransferCount: Node.TransferCount,
|
||||
GetTiming: GetTiming,
|
||||
ErrCountAll: Node.ErrCountAll,
|
||||
LevelCount: Node.LevelCount,
|
||||
LevelEnum: Node.LevelEnum,
|
||||
TimeTransfer: global.GetStrOnlyTimeUTC(new Date(Node.LastTimeTransfer)),
|
||||
BlockProcessCount: Node.BlockProcessCount,
|
||||
DeltaTime: Node.DeltaTime,
|
||||
DeltaTimeM: Node.DeltaTimeM,
|
||||
DeltaGlobTime: Node.DeltaGlobTime,
|
||||
PingNumber: Node.PingNumber,
|
||||
NextConnectDelta: Node.NextConnectDelta,
|
||||
NextGetNodesDelta: Node.NextGetNodesDelta,
|
||||
NextHotDelta: Node.NextHotDelta,
|
||||
Name: Node.Name,
|
||||
addrStr: Node.addrStr,
|
||||
CanHot: Node.CanHot,
|
||||
Active: Node.Active,
|
||||
Hot: Node.Hot,
|
||||
Info: Node.PrevInfo + Node.Info,
|
||||
InConnectArr: Node.WasAddToConnect,
|
||||
Level: Node.Level,
|
||||
TransferBlockNum: Node.TransferBlockNum,
|
||||
TransferSize: Node.TransferSize,
|
||||
TransferBlockNumFix: Node.TransferBlockNumFix,
|
||||
CurBlockNum: Node.CurBlockNum,
|
||||
};
|
||||
return Item;
|
||||
};
|
||||
HTTPCaller.GetBlockchainStat = function(Param) {
|
||||
global.HTTPCaller.GetBlockchainStat = function(Param) {
|
||||
var Result = global.SERVER.GetStatBlockchainPeriod(Param);
|
||||
Result.result = 1;
|
||||
Result.sessionid = sessionid;
|
||||
return Result;
|
||||
};
|
||||
HTTPCaller.GetAllCounters = function(Params, response) {
|
||||
global.HTTPCaller.GetAllCounters = function(Params, response) {
|
||||
let Result = global.GET_STATS();
|
||||
Result.result = 1;
|
||||
Result.sessionid = sessionid;
|
||||
@ -997,7 +1029,7 @@ function AddStatData(Params, Result, Prefix) {
|
||||
}
|
||||
}
|
||||
};
|
||||
HTTPCaller.SetStatMode = function(flag) {
|
||||
global.HTTPCaller.SetStatMode = function(flag) {
|
||||
if (flag)
|
||||
global.StartCommonStat();
|
||||
global.STAT_MODE = flag;
|
||||
@ -1005,7 +1037,7 @@ HTTPCaller.SetStatMode = function(flag) {
|
||||
global.TX_PROCESS.RunRPC("LOAD_CONST");
|
||||
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
||||
};
|
||||
HTTPCaller.ClearStat = function() {
|
||||
global.HTTPCaller.ClearStat = function() {
|
||||
global.ClearCommonStat();
|
||||
if (global.TX_PROCESS && global.TX_PROCESS.RunRPC) {
|
||||
global.TX_PROCESS.RunRPC("ClearCommonStat", "", function(Err, Params) {
|
||||
@ -1017,15 +1049,15 @@ HTTPCaller.ClearStat = function() {
|
||||
}
|
||||
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
||||
};
|
||||
HTTPCaller.RewriteAllTransactions = function(Param) {
|
||||
global.HTTPCaller.RewriteAllTransactions = function(Param) {
|
||||
global.RewriteAllTransactions();
|
||||
return { result: 1, sessionid: sessionid };
|
||||
};
|
||||
HTTPCaller.RewriteTransactions = function(Param) {
|
||||
global.HTTPCaller.RewriteTransactions = function(Param) {
|
||||
var Ret = global.SERVER.ReWriteDAppTransactions(Param.BlockCount);
|
||||
return { result: Ret, sessionid: sessionid };
|
||||
};
|
||||
HTTPCaller.TruncateBlockChain = function(Param) {
|
||||
global.HTTPCaller.TruncateBlockChain = function(Param) {
|
||||
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
||||
var MinBlock = global.DApps.Accounts.GetMinBlockAct();
|
||||
if (MinBlock > StartNum) {
|
||||
@ -1035,12 +1067,12 @@ HTTPCaller.TruncateBlockChain = function(Param) {
|
||||
global.SERVER.TruncateBlockDB(StartNum);
|
||||
return { result: 1, sessionid: sessionid };
|
||||
};
|
||||
HTTPCaller.ClearDataBase = function(Param) {
|
||||
global.HTTPCaller.ClearDataBase = function(Param) {
|
||||
BlockTree.Clear();
|
||||
global.SERVER.ClearDataBase();
|
||||
return { result: 1, sessionid: sessionid };
|
||||
};
|
||||
HTTPCaller.CleanChain = function(Param) {
|
||||
global.HTTPCaller.CleanChain = function(Param) {
|
||||
if (global.CleanChain) {
|
||||
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
||||
global.CleanChain(StartNum);
|
||||
@ -1048,7 +1080,7 @@ HTTPCaller.CleanChain = function(Param) {
|
||||
}
|
||||
return { result: 0, sessionid: sessionid };
|
||||
};
|
||||
HTTPCaller.GetArrStats = function(Keys, response) {
|
||||
global.HTTPCaller.GetArrStats = function(Keys, response) {
|
||||
var arr = global.GET_STATDIAGRAMS(Keys);
|
||||
let Result: any = { result: 1, sessionid: sessionid, arr: arr, STAT_MODE: global.STAT_MODE };
|
||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
||||
@ -1073,7 +1105,7 @@ HTTPCaller.GetArrStats = function(Keys, response) {
|
||||
});
|
||||
return null;
|
||||
};
|
||||
HTTPCaller.GetBlockChain = function(type) {
|
||||
global.HTTPCaller.GetBlockChain = function(type) {
|
||||
if (!global.SERVER || !global.SERVER.LoadedChainList) {
|
||||
return { result: 0 };
|
||||
}
|
||||
@ -1110,14 +1142,14 @@ HTTPCaller.GetBlockChain = function(type) {
|
||||
IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr), LoadedChainCount: global.SERVER.LoadedChainList.length, StartLoadBlockTime: global.SERVER.StartLoadBlockTime,
|
||||
sessionid: sessionid, result: 1
|
||||
};
|
||||
var obj2: any = HTTPCaller.GetHotArray();
|
||||
var obj2: any = global.HTTPCaller.GetHotArray();
|
||||
obj.ArrTree = obj2.ArrTree;
|
||||
arrBlocks = [];
|
||||
arrLoadedChainList = [];
|
||||
arrLoadedBlocks = [];
|
||||
return obj;
|
||||
};
|
||||
HTTPCaller.GetHistoryTransactions = function(Params) {
|
||||
global.HTTPCaller.GetHistoryTransactions = function(Params) {
|
||||
if (typeof Params === "object" && Params.AccountID) {
|
||||
var Account = global.DApps.Accounts.ReadState(Params.AccountID);
|
||||
if (!Account)
|
||||
@ -1140,35 +1172,43 @@ HTTPCaller.GetHistoryTransactions = function(Params) {
|
||||
}
|
||||
}
|
||||
var Result: any = {
|
||||
Value: { SumCOIN: Account.Value.SumCOIN, SumCENT: Account.Value.SumCENT }, Name: Account.Name, Currency: Account.Currency,
|
||||
MaxBlockNum: global.GetCurrentBlockNumByTime(), FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK, result: arr.length > 0 ? 1 : 0, History: arr
|
||||
Value: {
|
||||
SumCOIN: Account.Value.SumCOIN,
|
||||
SumCENT: Account.Value.SumCENT
|
||||
},
|
||||
Name: Account.Name,
|
||||
Currency: Account.Currency,
|
||||
MaxBlockNum: global.GetCurrentBlockNumByTime(),
|
||||
FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK,
|
||||
result: arr.length > 0 ? 1 : 0,
|
||||
History: arr
|
||||
};
|
||||
return Result;
|
||||
}
|
||||
return { result: 0 };
|
||||
};
|
||||
|
||||
// function GetCopyBlock(Block) {
|
||||
// var Result: any = {
|
||||
// BlockNum: Block.BlockNum, bSave: Block.bSave, TreeHash: global.GetHexFromAddres(Block.TreeHash), AddrHash: global.GetHexFromAddres(Block.AddrHash),
|
||||
// PrevHash: global.GetHexFromAddres(Block.PrevHash), SumHash: global.GetHexFromAddres(Block.SumHash), SumPow: Block.SumPow, TrDataPos: Block.TrDataPos,
|
||||
// TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
|
||||
// TrCount: Block.TrCount, arrContent: Block.arrContent,
|
||||
// };
|
||||
// return Result;
|
||||
// };
|
||||
function GetCopyBlock(Block) {
|
||||
var Result: any = {
|
||||
BlockNum: Block.BlockNum, bSave: Block.bSave, TreeHash: global.GetHexFromAddres(Block.TreeHash), AddrHash: global.GetHexFromAddres(Block.AddrHash),
|
||||
PrevHash: global.GetHexFromAddres(Block.PrevHash), SumHash: global.GetHexFromAddres(Block.SumHash), SumPow: Block.SumPow, TrDataPos: Block.TrDataPos,
|
||||
TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
|
||||
TrCount: Block.TrCount, arrContent: Block.arrContent,
|
||||
};
|
||||
return Result;
|
||||
};
|
||||
var AddrLength = 16;
|
||||
|
||||
function GetHexFromAddresShort(Hash) {
|
||||
return global.GetHexFromAddres(Hash).substr(0, AddrLength);
|
||||
};
|
||||
|
||||
// function GetHexFromStrShort(Str) {
|
||||
// if (Str === undefined)
|
||||
// return Str;
|
||||
// else
|
||||
// return Str.substr(0, AddrLength);
|
||||
// };
|
||||
function GetHexFromStrShort(Str) {
|
||||
if (Str === undefined)
|
||||
return Str;
|
||||
else
|
||||
return Str.substr(0, AddrLength);
|
||||
};
|
||||
var glid = 0;
|
||||
|
||||
function GetGUID(Block) {
|
||||
@ -1201,12 +1241,34 @@ function CopyBlockDraw(Block, MainChains) {
|
||||
Mining = 0;
|
||||
GetGUID(Block);
|
||||
Item = {
|
||||
guid: Block.guid, Active: Block.Active, bSave: Block.bSave, Prepared: Block.Prepared, BlockNum: Block.BlockNum, Hash: GetHexFromAddresShort(Block.Hash),
|
||||
SumHash: GetHexFromAddresShort(Block.SumHash), SeqHash: GetHexFromAddresShort(Block.SeqHash), TreeHash: GetHexFromAddresShort(Block.TreeHash),
|
||||
AddrHash: GetHexFromAddresShort(Block.AddrHash), MinerID: MinerID, MinerName: MinerName, Comment1: Block.Comment1, Comment2: Block.Comment2,
|
||||
SumPow: Block.SumPow, Info: Block.Info, TreeLoaded: Block.TreeEq, AddToLoad: Block.AddToLoad, LoadDB: Block.LoadDB, FindBlockDB: Block.FindBlockDB,
|
||||
TrCount: Block.TrCount, ArrLength: 0, TrDataLen: Block.TrDataLen, Power: global.GetPowPower(Block.PowHash), CheckPoint: CheckPoint, Mining: Mining,
|
||||
TransferSize: Block.TransferSize, HasErr: Block.HasErr,
|
||||
guid: Block.guid,
|
||||
Active: Block.Active,
|
||||
bSave: Block.bSave,
|
||||
Prepared: Block.Prepared,
|
||||
BlockNum: Block.BlockNum,
|
||||
Hash: GetHexFromAddresShort(Block.Hash),
|
||||
SumHash: GetHexFromAddresShort(Block.SumHash),
|
||||
SeqHash: GetHexFromAddresShort(Block.SeqHash),
|
||||
TreeHash: GetHexFromAddresShort(Block.TreeHash),
|
||||
AddrHash: GetHexFromAddresShort(Block.AddrHash),
|
||||
MinerID: MinerID,
|
||||
MinerName: MinerName,
|
||||
Comment1: Block.Comment1,
|
||||
Comment2: Block.Comment2,
|
||||
SumPow: Block.SumPow,
|
||||
Info: Block.Info,
|
||||
TreeLoaded: Block.TreeEq,
|
||||
AddToLoad: Block.AddToLoad,
|
||||
LoadDB: Block.LoadDB,
|
||||
FindBlockDB: Block.FindBlockDB,
|
||||
TrCount: Block.TrCount,
|
||||
ArrLength: 0,
|
||||
TrDataLen: Block.TrDataLen,
|
||||
Power: global.GetPowPower(Block.PowHash),
|
||||
CheckPoint: CheckPoint,
|
||||
Mining: Mining,
|
||||
TransferSize: Block.TransferSize,
|
||||
HasErr: Block.HasErr,
|
||||
};
|
||||
if (Block.chain)
|
||||
Item.chainid = Block.chain.id;
|
||||
@ -1278,7 +1340,7 @@ function AddMapList(arrLoadedBlocks, type, MapMapLoaded, MainChains?) {
|
||||
}
|
||||
}
|
||||
};
|
||||
// var MapFileHTML5 = {};
|
||||
var MapFileHTML5 = {};
|
||||
|
||||
function SendWebFile(response, name?, StrCookie?, bParsing?) {
|
||||
var type = name.substr(name.length - 4, 4);
|
||||
@ -1416,28 +1478,28 @@ global.GetFileHTMLFromMarkdown = GetFileHTMLFromMarkdown;
|
||||
global.GetFileSimple = GetFileSimple;
|
||||
global.SaveFileSimple = SaveFileSimple;
|
||||
|
||||
// function GetStrTime(now) {
|
||||
// if (!now)
|
||||
// now = global.GetCurrentTime(0);
|
||||
// var Str = "" + now.getHours().toStringZ(2);
|
||||
// Str = Str + ":" + now.getMinutes().toStringZ(2);
|
||||
// Str = Str + ":" + now.getSeconds().toStringZ(2);
|
||||
// return Str;
|
||||
// };
|
||||
function GetStrTime(now) {
|
||||
if (!now)
|
||||
now = global.GetCurrentTime(0);
|
||||
var Str = "" + now.getHours().toStringZ(2);
|
||||
Str = Str + ":" + now.getMinutes().toStringZ(2);
|
||||
Str = Str + ":" + now.getSeconds().toStringZ(2);
|
||||
return Str;
|
||||
};
|
||||
|
||||
function OnGetData(arg) {
|
||||
// var response = {
|
||||
// end: function() {
|
||||
// }, writeHead: function() {
|
||||
// },
|
||||
// };
|
||||
var response = {
|
||||
end: function() {
|
||||
}, writeHead: function() {
|
||||
},
|
||||
};
|
||||
var Path = arg.path;
|
||||
var obj = arg.obj;
|
||||
if (Path.substr(0, 1) === "/")
|
||||
Path = Path.substr(1);
|
||||
var params = Path.split('/', 5);
|
||||
var Ret;
|
||||
var F = HTTPCaller[params[0]];
|
||||
var F = global.HTTPCaller[params[0]];
|
||||
if (F) {
|
||||
if (obj)
|
||||
Ret = F(obj);
|
||||
@ -1677,7 +1739,7 @@ function GetEventArray(SmartNum, Context) {
|
||||
}
|
||||
return ArrRet;
|
||||
};
|
||||
HTTPCaller.GetHashRate = function(ArrParams) {
|
||||
global.HTTPCaller.GetHashRate = function(ArrParams) {
|
||||
var CurBlockNum = global.GetCurrentBlockNumByTime();
|
||||
var ResArr = [];
|
||||
for (var i = 0; i < ArrParams.length; i++) {
|
||||
@ -1703,6 +1765,9 @@ HTTPCaller.GetHashRate = function(ArrParams) {
|
||||
var CountAvg = 10;
|
||||
if (i === ArrParams.length - 1)
|
||||
CountAvg = 3;
|
||||
var StepDeltaAvg = Math.floor(StepDelta / CountAvg);
|
||||
if (StepDeltaAvg < 1)
|
||||
StepDeltaAvg = 1;
|
||||
var ItervalArr = [];
|
||||
for (var Num = Item.BlockNum1; Num < Item.BlockNum2; Num += StepDelta) {
|
||||
var Power;
|
||||
|
@ -16,6 +16,16 @@ import * as stun from 'stun'
|
||||
import * as zip from 'zip'
|
||||
|
||||
import './constant'
|
||||
if (global.USE_PARAM_JS) {
|
||||
var PathParams = global.GetCodePath("../extern-run.js");
|
||||
if (fs.existsSync(PathParams))
|
||||
try {
|
||||
require(PathParams);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
import './log'
|
||||
|
||||
Number.prototype.toStringZ = function(count) {
|
||||
@ -58,6 +68,8 @@ if (global.USE_PARAM_JS) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
require('../HTML/JS/terahashlib.js');
|
||||
require("./crypto-library");
|
||||
global.BufLib = require("../core/buffer");
|
||||
require('../HTML/JS/sha3.js');
|
||||
require('../HTML/JS/coinlib.js');
|
||||
@ -93,7 +105,7 @@ global.SliceArr = function(arr, start, end) {
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
// var nRand = Math.floor(123 + Math.random() * 1000);
|
||||
var nRand = Math.floor(123 + Math.random() * 1000);
|
||||
|
||||
function random(max) {
|
||||
return Math.floor(Math.random() * max);
|
||||
@ -142,8 +154,7 @@ global.LoadParams = function(filename, DefaultValue) {
|
||||
if (Str.length > 0)
|
||||
return JSON.parse(Str as any);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
global.TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
|
||||
}
|
||||
return DefaultValue;
|
||||
@ -265,7 +276,7 @@ global.SAVE_CONST = function(bForce) {
|
||||
};
|
||||
|
||||
function CheckGlobalTime() {
|
||||
global.ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, NetTime) {
|
||||
global.ntpClient.getNetworkTime("ntp1.aliyun.com", 123, function(err, NetTime) {
|
||||
if (err) {
|
||||
global.TO_ERROR_LOG("MAINLIB", 110, err);
|
||||
return;
|
||||
@ -372,7 +383,7 @@ function GetCountMiningCPU() {
|
||||
}
|
||||
};
|
||||
global.GetCountMiningCPU = GetCountMiningCPU;
|
||||
var AddTrMap = [];
|
||||
var AddTrMap: any = {};
|
||||
AddTrMap[- 6] = "Inner node error";
|
||||
AddTrMap[- 5] = "Bad block num";
|
||||
AddTrMap[- 4] = "Bad type transaction";
|
||||
|
@ -7,6 +7,7 @@
|
||||
* Twitter: https://twitter.com/terafoundation
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
|
||||
import * as fs from 'fs'
|
||||
|
||||
function CheckSizeLogFile(file_name, file_name_prev) {
|
||||
|
@ -341,8 +341,7 @@ export default class CNode {
|
||||
}
|
||||
try {
|
||||
var Buf = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_CLIENT, {});
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
global.SERVER.SendCloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
||||
return 0;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ export default class CRest extends CDB {
|
||||
}
|
||||
}
|
||||
if (MaxCount < 2 || MaxPow === 0) {
|
||||
global.ToLog("****************************************************************** Error MaxPow - reload.")
|
||||
global.ToLog("****************************************************************** Error MaxPow=" + MaxPow + " - reload.")
|
||||
this.CheckSyncRest()
|
||||
return;
|
||||
}
|
||||
|
@ -9,59 +9,91 @@
|
||||
*/
|
||||
|
||||
|
||||
function DoRest(r, t, e) {
|
||||
var u = r.Arr[0], o = Math.floor(e / global.REST_BLOCK_SCALE);
|
||||
if (o !== Math.floor((u.BlockNum - 1) / global.REST_BLOCK_SCALE)) {
|
||||
for (var n = GetRestArr(o), l = [], a = n.length - 2; 0 <= a; a--)
|
||||
l.push(n[a] * global.REST_BLOCK_SCALE);
|
||||
RestPush(r, l, e, 1);
|
||||
function DoRest(RestData, Data, BlockNum) {
|
||||
var Prev = RestData.Arr[0];
|
||||
var BlockNum0 = Math.floor(BlockNum / global.REST_BLOCK_SCALE);
|
||||
if (BlockNum0 !== Math.floor((Prev.BlockNum - 1) / global.REST_BLOCK_SCALE)) {
|
||||
var arr = GetRestArr(BlockNum0);
|
||||
var arr2 = [];
|
||||
for (var i = arr.length - 2; i >= 0; i--) {
|
||||
arr2.push(arr[i] * global.REST_BLOCK_SCALE);
|
||||
}
|
||||
RestPush(RestData, arr2, BlockNum, 1);
|
||||
}
|
||||
r.Arr[0] = { BlockNum: e, Value: t.Value };
|
||||
RestData.Arr[0] = { BlockNum: BlockNum, Value: Data.Value };
|
||||
};
|
||||
|
||||
function RestPush(r, t, e, u) {
|
||||
var o = r.Arr[u - 1], n = r.Arr[u];
|
||||
if (1 < u) {
|
||||
var l = t[u - 2];
|
||||
if (o.BlockNum > l)
|
||||
function RestPush(RestData, ArrRest, BlockNum, Index) {
|
||||
var Prev = RestData.Arr[Index - 1];
|
||||
var Cur = RestData.Arr[Index];
|
||||
if (Index > 1) {
|
||||
var RestNum = ArrRest[Index - 2];
|
||||
if (Prev.BlockNum > RestNum)
|
||||
return;
|
||||
}
|
||||
if (n.BlockNum && n.BlockNum >= e || o.BlockNum >= e)
|
||||
return n.BlockNum = 0, void (n.Value = {});
|
||||
n.BlockNum && u < r.Arr.length - 1 && RestPush(r, t, e, u + 1), r.Arr[u] = o;
|
||||
if ((Cur.BlockNum && Cur.BlockNum >= BlockNum) || Prev.BlockNum >= BlockNum) {
|
||||
Cur.BlockNum = 0;
|
||||
Cur.Value = {};
|
||||
return;
|
||||
}
|
||||
if (Cur.BlockNum) {
|
||||
if (Index < RestData.Arr.length - 1) {
|
||||
RestPush(RestData, ArrRest, BlockNum, Index + 1);
|
||||
}
|
||||
}
|
||||
RestData.Arr[Index] = Prev;
|
||||
};
|
||||
|
||||
function GetRestArr(r) {
|
||||
for (var t = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], e = t.length, u = 0; u <= r; u++)
|
||||
for (var o = 0, n = u, l = e - 1; 0 <= l; l--) {
|
||||
var a = t[l];
|
||||
if (t[l] = n, n = a, 0 == ((o = o << 4 | 15) & u))
|
||||
function GetRestArr(CurBlockNum) {
|
||||
var Arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
var ArrLength = Arr.length;
|
||||
var StartNum = 0;
|
||||
for (var num = StartNum; num <= CurBlockNum; num++) {
|
||||
var maska = 0;
|
||||
var CurNum = num;
|
||||
for (var i = ArrLength - 1; i >= 0; i--) {
|
||||
var PosNum = Arr[i];
|
||||
Arr[i] = CurNum;
|
||||
CurNum = PosNum;
|
||||
maska = (maska << 4) | 15;
|
||||
if ((maska & num) === 0)
|
||||
break;
|
||||
if (0 != (o & n))
|
||||
if ((maska & CurNum) !== 0)
|
||||
break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
return Arr;
|
||||
};
|
||||
var RestArrMap = {};
|
||||
|
||||
function GetCurrentRestArr() {
|
||||
var r = global.GetCurrentBlockNumByTime(), t = Math.floor(r / global.REST_BLOCK_SCALE), e = RestArrMap[t];
|
||||
if (void 0 === e) {
|
||||
RestArrMap = {}, (e = GetRestArr(t)).length = e.length - 1;
|
||||
for (var u = 0; u < e.length; u++)
|
||||
e[u] = e[u] * global.REST_BLOCK_SCALE;
|
||||
RestArrMap[t] = e;
|
||||
var BlockNum = global.GetCurrentBlockNumByTime();
|
||||
var BlockNum0 = Math.floor(BlockNum / global.REST_BLOCK_SCALE);
|
||||
var arr = RestArrMap[BlockNum0];
|
||||
if (arr === undefined) {
|
||||
RestArrMap = {};
|
||||
arr = GetRestArr(BlockNum0);
|
||||
arr.length = arr.length - 1;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
arr[i] = arr[i] * global.REST_BLOCK_SCALE;
|
||||
}
|
||||
RestArrMap[BlockNum0] = arr;
|
||||
}
|
||||
return e;
|
||||
return arr;
|
||||
};
|
||||
|
||||
function GetCurrentRestNum(r) {
|
||||
for (var t = global.GetCurrentBlockNumByTime() - r, e = GetCurrentRestArr(), u = e.length - 1; 0 <= u; u--)
|
||||
if (e[u] <= t)
|
||||
return e[u];
|
||||
function GetCurrentRestNum(NumDelta) {
|
||||
var BlockNum = global.GetCurrentBlockNumByTime();
|
||||
var BlockNumMin = BlockNum - NumDelta;
|
||||
var arr = GetCurrentRestArr();
|
||||
for (var i = arr.length - 1; i >= 0; i--) {
|
||||
if (arr[i] <= BlockNumMin) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
global.DoRest = DoRest
|
||||
global.GetRestArr = GetRestArr
|
||||
global.GetCurrentRestArr = GetCurrentRestArr
|
||||
global.DoRest = DoRest;
|
||||
global.GetRestArr = GetRestArr;
|
||||
global.GetCurrentRestArr = GetCurrentRestArr;
|
||||
global.GetCurrentRestNum = GetCurrentRestNum;
|
||||
|
@ -32,7 +32,7 @@ const BUF_PACKET_SIZE = 32 * 1024;
|
||||
global.FORMAT_POW_TO_CLIENT = "{addrArr:hash,HashRND:hash,MIN_POWER_POW_HANDSHAKE:uint,PubKeyType:byte,Sign:arr64,Reserve:arr33}";
|
||||
global.FORMAT_POW_TO_SERVER = "{\
|
||||
DEF_NETWORK:str15,\
|
||||
global.DEF_VERSION:str9,\
|
||||
DEF_VERSION:str9,\
|
||||
DEF_CLIENT:str16, \
|
||||
addrArr:addres, \
|
||||
ToIP:str26,\
|
||||
@ -366,13 +366,11 @@ export default class CTransport extends CConnect {
|
||||
else
|
||||
if (TypeData === global.STR_TYPE) {
|
||||
BufData = Buffer.from(Data.substr(0, global.MAX_STR_BUF_DATA))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (Data === undefined) {
|
||||
TypeData = global.BUF_TYPE
|
||||
BufData = Buffer.alloc(0)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw "ERROR TYPE DATA";
|
||||
}
|
||||
}
|
||||
@ -394,8 +392,7 @@ export default class CTransport extends CConnect {
|
||||
GetDataFromBuf(buf) {
|
||||
try {
|
||||
var Meta = global.BufLib.GetObjectFromBuffer(buf, FORMAT_PACKET_SEND_TCP, WorkStructPacketSend);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
global.TO_ERROR_LOG("TRANSPORT", 640, "Error parsing Buffer")
|
||||
return undefined;
|
||||
}
|
||||
@ -420,8 +417,7 @@ export default class CTransport extends CConnect {
|
||||
Node.Socket = Socket
|
||||
if (!Socket.Buf || Socket.Buf.length === 0) {
|
||||
Socket.Buf = Buf
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Socket.Buf = Buffer.concat([Socket.Buf, Buf])
|
||||
}
|
||||
if (!Socket.SocketNum) {
|
||||
|
@ -8,39 +8,63 @@
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
|
||||
import * as fs from 'fs'
|
||||
|
||||
function CopyFiles(l, o, t) {
|
||||
if (fs.existsSync(l))
|
||||
for (var e = fs.readdirSync(l), n = 0; n < e.length; n++) {
|
||||
var a = l + "/" + e[n], s = o + "/" + e[n];
|
||||
if (fs.statSync(a).isDirectory())
|
||||
t && (fs.existsSync(s) || fs.mkdirSync(s), CopyFiles(a, s, t));
|
||||
else {
|
||||
var r = fs.readFileSync(a), i = fs.openSync(s, "w");
|
||||
fs.writeSync(i, r, 0, r.length), fs.closeSync(i);
|
||||
var fs = require("fs");
|
||||
global.GetDataPath = function GetDataPath(name) {
|
||||
if (global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) !== "/")
|
||||
global.DATA_PATH = global.DATA_PATH + "/";
|
||||
return global.GetNormalPathString(global.DATA_PATH + name);
|
||||
};
|
||||
global.GetCodePath = function GetCodePath(name) {
|
||||
if (global.CODE_PATH.substr(global.CODE_PATH.length - 1, 1) !== "/")
|
||||
global.CODE_PATH = global.CODE_PATH + "/";
|
||||
return global.GetNormalPathString(global.CODE_PATH + name);
|
||||
};
|
||||
global.GetNormalPathString = function(Str) {
|
||||
return Str.split("\\").join('/');
|
||||
};
|
||||
global.CheckCreateDir = function(Path, bHidden, IsFile) {
|
||||
Path = global.GetNormalPathString(Path);
|
||||
if (!fs.existsSync(Path)) {
|
||||
if (!bHidden)
|
||||
console.log("Create: " + Path);
|
||||
var arr = Path.split('/');
|
||||
var CurPath = arr[0];
|
||||
if (IsFile) {
|
||||
arr.length--;
|
||||
}
|
||||
for (var i = 1; i < arr.length; i++) {
|
||||
CurPath += "/" + arr[i];
|
||||
if (!fs.existsSync(CurPath)) {
|
||||
fs.mkdirSync(CurPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
global.GetDataPath = function(l) {
|
||||
return "/" !== global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) && (global.DATA_PATH = global.DATA_PATH + "/"), global.GetNormalPathString(global.DATA_PATH + l);
|
||||
}
|
||||
global.GetCodePath = function(l) {
|
||||
return "/" !== global.CODE_PATH.substr(global.CODE_PATH.length - 1, 1) && (global.CODE_PATH = global.CODE_PATH + "/"), global.GetNormalPathString(global.CODE_PATH + l);
|
||||
}
|
||||
global.GetNormalPathString = function(l: string) {
|
||||
return l.split("\\").join("/");
|
||||
}
|
||||
global.CheckCreateDir = function(l, o, t) {
|
||||
if (l = global.GetNormalPathString(l), !fs.existsSync(l)) {
|
||||
o || console.log("Create: " + l);
|
||||
var e = l.split("/"), n = e[0];
|
||||
t && e.length--;
|
||||
for (var a = 1; a < e.length; a++)
|
||||
n += "/" + e[a], fs.existsSync(n) || fs.mkdirSync(n);
|
||||
}
|
||||
}
|
||||
global.CopyFiles = CopyFiles
|
||||
global.ToLog || (global.ToLog = function(l) {
|
||||
console.log(l);
|
||||
});
|
||||
};
|
||||
global.CopyFiles = CopyFiles;
|
||||
|
||||
function CopyFiles(FromPath, ToPath, bRecursive) {
|
||||
if (fs.existsSync(FromPath)) {
|
||||
var arr = fs.readdirSync(FromPath);
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var name1 = FromPath + "/" + arr[i];
|
||||
var name2 = ToPath + "/" + arr[i];
|
||||
if (fs.statSync(name1).isDirectory()) {
|
||||
if (bRecursive) {
|
||||
if (!fs.existsSync(name2))
|
||||
fs.mkdirSync(name2);
|
||||
CopyFiles(name1, name2, bRecursive);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var data = fs.readFileSync(name1);
|
||||
var file_handle = fs.openSync(name2, "w");
|
||||
fs.writeSync(file_handle, data, 0, data.length);
|
||||
fs.closeSync(file_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!global.ToLog)
|
||||
global.ToLog = function(Str) {
|
||||
console.log(Str);
|
||||
};
|
||||
|
@ -157,8 +157,7 @@ function CreatePOWVersion3(Block, bHashPump) {
|
||||
Block.Hash = MaxLider.Hash2;
|
||||
if (global.CompareArr(MaxLider.Hash1, MaxLider.Hash2) > 0) {
|
||||
Block.PowHash = MaxLider.Hash1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Block.PowHash = MaxLider.Hash2;
|
||||
}
|
||||
if (BlockNum >= global.BLOCKNUM_TICKET_ALGO)
|
||||
|
@ -9,17 +9,17 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import CConsensus from './block-exchange'
|
||||
import { TYPE_TRANSACTION } from '../constant/account';
|
||||
import { RBTree } from './library';
|
||||
require("../system/dapp");
|
||||
require("../system/accounts");
|
||||
require("../system/smart");
|
||||
require("../system/file");
|
||||
require("../system/messager");
|
||||
require("../system/names");
|
||||
import "../system/dapp"
|
||||
import "../system/accounts"
|
||||
import "../system/smart"
|
||||
import "../system/file"
|
||||
import "../system/messager"
|
||||
import "../system/names"
|
||||
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX")
|
||||
require("./wallet");
|
||||
import CConsensus from './block-exchange'
|
||||
export default class CSmartContract extends CConsensus {
|
||||
BufHashTree
|
||||
SenderBlockHashMap
|
||||
@ -29,8 +29,8 @@ export default class CSmartContract extends CConsensus {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.BufHashTree = new RBTree(global.CompareArr)
|
||||
this.BufHashTree.LastAddNum = 0
|
||||
this.SenderBlockHashMap = {}
|
||||
this.SenderMap = {}
|
||||
this.SenderBlockHashMap = {}
|
||||
if (!global.ADDRLIST_MODE && !this.VirtualMode && global.START_SERVER) {
|
||||
setInterval(this.ClearOldSenderMapItem.bind(this), 10000)
|
||||
}
|
||||
@ -40,7 +40,7 @@ export default class CSmartContract extends CConsensus {
|
||||
var arr = Block.arrContent;
|
||||
if (arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var HASH = global.shaarr(arr[i]);
|
||||
var HASH = global.sha3(arr[i]);
|
||||
this.BufHashTree.insert(HASH)
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ export default class CSmartContract extends CConsensus {
|
||||
var arr = Block.arrContent;
|
||||
if (arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var HASH = global.shaarr(arr[i]);
|
||||
var HASH = global.sha3(arr[i]);
|
||||
this.BufHashTree.remove(HASH)
|
||||
}
|
||||
}
|
||||
@ -233,6 +233,8 @@ export default class CSmartContract extends CConsensus {
|
||||
// transfer-msg.ts(CMessages)
|
||||
}
|
||||
AddToSenderMap(Block) {
|
||||
if (!global.START_SERVER)
|
||||
return;
|
||||
var BlockNum = Block.BlockNum;
|
||||
var StrBlockHash = global.GetHexFromArr(Block.Hash);
|
||||
this.SenderBlockHashMap[BlockNum] = StrBlockHash
|
||||
@ -295,7 +297,9 @@ export default class CSmartContract extends CConsensus {
|
||||
this.WasReloadSenderMapFromDB = 1
|
||||
}
|
||||
ClearOldSenderMapItem() {
|
||||
var MinBlockNum = global.GetCurrentBlockNumByTime() - global.MAX_LENGTH_SENDER_MAP * 2;
|
||||
if (!global.START_SERVER)
|
||||
return;
|
||||
var MinBlockNum = global.GetCurrentBlockNumByTime() - (global.MAX_LENGTH_SENDER_MAP + global.COUNT_BLOCKS_FOR_LOAD);
|
||||
var ArrForDel = [];
|
||||
for (var key in this.SenderMap) {
|
||||
var ItemArr = this.SenderMap[key];
|
||||
|
@ -9,9 +9,9 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import CSmartContract from './transaction-validator'
|
||||
import { RBTree } from './library';
|
||||
const MAX_MESSAGE_COUNT = 1000;
|
||||
import CSmartContract from './transaction-validator'
|
||||
export default class CMessages extends CSmartContract {
|
||||
MemPoolMsg
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
|
@ -147,7 +147,6 @@ function RecreateAccountHashDB3() {
|
||||
};
|
||||
|
||||
import '../core/db/db-row'
|
||||
|
||||
function ReWriteDBSmartWrite() {
|
||||
global.UpdateMode = 1;
|
||||
global.ToLog("Start ReWriteDBSmartWrite");
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
"use strict";
|
||||
import { secp256k1 } from './library'
|
||||
// const fs = require('fs');
|
||||
import * as crypto from 'crypto';
|
||||
require("./library");
|
||||
require("./crypto-library");
|
||||
|
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@ -42,6 +42,8 @@ declare global {
|
||||
MAX_LENGTH_SENDER_MAP: number;
|
||||
DELTA_START_SENDER_MAP: number;
|
||||
NODES_DELTA_CALC_HOUR: number;
|
||||
USE_API_WALLET: number;
|
||||
USE_API_V1: number;
|
||||
USE_HARD_API_V2: number;
|
||||
USE_TICKET: number;
|
||||
USE_CHECK_SENDING: number;
|
||||
@ -99,7 +101,8 @@ declare global {
|
||||
HTTP_HOSTING_PORT: number;
|
||||
HTTPS_HOSTING_DOMAIN: string;
|
||||
HTTP_MAX_COUNT_ROWS: number;
|
||||
HTTP_ADMIN_PASSORD: string;
|
||||
HTTP_ADMIN_PASSWORD: string;
|
||||
HTTP_START_PAGE: string;
|
||||
MIN_POWER_POW_HANDSHAKE: number;
|
||||
USE_HINT: number;
|
||||
ALL_VIEW_ROWS: number;
|
||||
|
Loading…
Reference in New Issue
Block a user