Sat Jul 13 09:15:47 CST 2019 Source Update...

This commit is contained in:
MiaoWoo 2019-07-13 09:15:47 +08:00
parent 750a54c15f
commit b415da0a52
21 changed files with 1515 additions and 3682 deletions

View File

@ -1,109 +1 @@
hljs.registerLanguage('html', FLanguage);
function FLanguage(hljs)
{
var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
var TAG_INTERNALS = {
endsWithParent: true,
illegal: /</,
relevance: 0,
contains: [
{
className: 'attr',
begin: XML_IDENT_RE,
relevance: 0
},
{
begin: /=\s*/,
relevance: 0,
contains: [
{
className: 'string',
endsParent: true,
variants: [
{begin: /"/, end: /"/},
{begin: /'/, end: /'/},
{begin: /[^\s"'=<>`]+/}
]
}
]
}
]
};
return {
aliases: ['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist'],
case_insensitive: true,
contains: [
{
className: 'meta',
begin: '<!DOCTYPE', end: '>',
relevance: 10,
contains: [{begin: '\\[', end: '\\]'}]
},
hljs.COMMENT(
'<!--',
'-->',
{
relevance: 10
}
),
{
begin: '<\\!\\[CDATA\\[', end: '\\]\\]>',
relevance: 10
},
{
className: 'meta',
begin: /<\?xml/, end: /\?>/, relevance: 10
},
{
begin: /<\?(php)?/, end: /\?>/,
subLanguage: 'php',
contains: [
// We don't want the php closing tag ?> to close the PHP block when
// inside any of the following blocks:
{begin: '/\\*', end: '\\*/', skip: true},
{begin: 'b"', end: '"', skip: true},
{begin: 'b\'', end: '\'', skip: true},
hljs.inherit(hljs.APOS_STRING_MODE, {illegal: null, className: null, contains: null, skip: true}),
hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null, className: null, contains: null, skip: true})
]
},
{
className: 'tag',
/*
The lookahead pattern (?=...) ensures that 'begin' only matches
'<style' as a single word, followed by a whitespace or an
ending braket. The '$' is needed for the lexeme to be recognized
by hljs.subMode() that tests lexemes outside the stream.
*/
begin: '<style(?=\\s|>|$)', end: '>',
keywords: {name: 'style'},
contains: [TAG_INTERNALS],
starts: {
end: '</style>', returnEnd: true,
subLanguage: ['css', 'xml']
}
},
{
className: 'tag',
// See the comment in the <style tag about the lookahead pattern
begin: '<script(?=\\s|>|$)', end: '>',
keywords: {name: 'script'},
contains: [TAG_INTERNALS],
starts: {
end: '\<\/script\>', returnEnd: true,
subLanguage: ['actionscript', 'javascript', 'handlebars', 'xml']
}
},
{
className: 'tag',
begin: '</?', end: '/?>',
contains: [
{
className: 'name', begin: /[^\/><\s]+/, relevance: 0
},
TAG_INTERNALS
]
}
]
};
};
function FLanguage(e){var n={endsWithParent:!0,illegal:/</,relevance:0,contains:[{className:"attr",begin:"[A-Za-z0-9\\._:-]+",relevance:0},{begin:/=\s*/,relevance:0,contains:[{className:"string",endsParent:!0,variants:[{begin:/"/,end:/"/},{begin:/'/,end:/'/},{begin:/[^\s"'=<>`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],case_insensitive:!0,contains:[{className:"meta",begin:"<!DOCTYPE",end:">",relevance:10,contains:[{begin:"\\[",end:"\\]"}]},e.COMMENT("\x3c!--","--\x3e",{relevance:10}),{begin:"<\\!\\[CDATA\\[",end:"\\]\\]>",relevance:10},{className:"meta",begin:/<\?xml/,end:/\?>/,relevance:10},{begin:/<\?(php)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},e.inherit(e.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]},{className:"tag",begin:"<style(?=\\s|>|$)",end:">",keywords:{name:"style"},contains:[n],starts:{end:"</style>",returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:"<script(?=\\s|>|$)",end:">",keywords:{name:"script"},contains:[n],starts:{end:"<\/script>",returnEnd:!0,subLanguage:["actionscript","javascript","handlebars","xml"]}},{className:"tag",begin:"</?",end:"/?>",contains:[{className:"name",begin:/[^\/><\s]+/,relevance:0},n]}]}}hljs.registerLanguage("html",FLanguage);

View File

@ -1,174 +1 @@
hljs.registerLanguage('javascript', FLanguage);
hljs.registerLanguage('js', FLanguage);
function FLanguage(hljs)
{
var IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
var KEYWORDS = {
keyword:
'in of if for while finally var new function do return void else break catch ' +
'instanceof with throw case default try this switch continue typeof delete ' +
'let yield const export super debugger as async await static ' +
// ECMAScript 6 modules import
'import from as'
,
literal:
'true false null undefined NaN Infinity',
built_in:
'eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent ' +
'encodeURI encodeURIComponent escape unescape Object Function Boolean Error ' +
'EvalError InternalError RangeError ReferenceError StopIteration SyntaxError ' +
'TypeError URIError Number Math Date String RegExp Array Float32Array ' +
'Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array ' +
'Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require ' +
'module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect ' +
'Promise'
};
var EXPRESSIONS;
var NUMBER = {
className: 'number',
variants: [
{ begin: '\\b(0[bB][01]+)' },
{ begin: '\\b(0[oO][0-7]+)' },
{ begin: hljs.C_NUMBER_RE }
],
relevance: 0
};
var SUBST = {
className: 'subst',
begin: '\\$\\{', end: '\\}',
keywords: KEYWORDS,
contains: [] // defined later
};
var TEMPLATE_STRING = {
className: 'string',
begin: '`', end: '`',
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
};
SUBST.contains = [
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
TEMPLATE_STRING,
NUMBER,
hljs.REGEXP_MODE
]
var PARAMS_CONTAINS = SUBST.contains.concat([
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_LINE_COMMENT_MODE
]);
return {
aliases: ['js', 'jsx'],
keywords: KEYWORDS,
contains: [
{
className: 'meta',
relevance: 10,
begin: /^\s*['"]use (strict|asm)['"]/
},
{
className: 'meta',
begin: /^#!/, end: /$/
},
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
TEMPLATE_STRING,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
NUMBER,
{ // object attr container
begin: /[{,]\s*/, relevance: 0,
contains: [
{
begin: IDENT_RE + '\\s*:', returnBegin: true,
relevance: 0,
contains: [{className: 'attr', begin: IDENT_RE, relevance: 0}]
}
]
},
{ // "value" container
begin: '(' + hljs.RE_STARTERS_RE + '|\\b(case|return|throw)\\b)\\s*',
keywords: 'return throw case',
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.REGEXP_MODE,
{
className: 'function',
begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>', returnBegin: true,
end: '\\s*=>',
contains: [
{
className: 'params',
variants: [
{
begin: IDENT_RE
},
{
begin: /\(\s*\)/,
},
{
begin: /\(/, end: /\)/,
excludeBegin: true, excludeEnd: true,
keywords: KEYWORDS,
contains: PARAMS_CONTAINS
}
]
}
]
},
{ // E4X / JSX
begin: /</, end: /(\/\w+|\w+\/)>/,
subLanguage: 'xml',
contains: [
{begin: /<\w+\s*\/>/, skip: true},
{
begin: /<\w+/, end: /(\/\w+|\w+\/)>/, skip: true,
contains: [
{begin: /<\w+\s*\/>/, skip: true},
'self'
]
}
]
}
],
relevance: 0
},
{
className: 'function',
beginKeywords: 'function', end: /\{/, excludeEnd: true,
contains: [
hljs.inherit(hljs.TITLE_MODE, {begin: IDENT_RE}),
{
className: 'params',
begin: /\(/, end: /\)/,
excludeBegin: true,
excludeEnd: true,
contains: PARAMS_CONTAINS
}
],
illegal: /\[|%/
},
{
begin: /\$[(.]/ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
},
hljs.METHOD_GUARD,
{ // ES6 class
className: 'class',
beginKeywords: 'class', end: /[{;=]/, excludeEnd: true,
illegal: /[:"\[\]]/,
contains: [
{beginKeywords: 'extends'},
hljs.UNDERSCORE_TITLE_MODE
]
},
{
beginKeywords: 'constructor', end: /\{/, excludeEnd: true
}
],
illegal: /#(?!!)/
};
};
function FLanguage(e){var n="[A-Za-z$_][0-9A-Za-z$_]*",a={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},r={className:"number",variants:[{begin:"\\b(0[bB][01]+)"},{begin:"\\b(0[oO][0-7]+)"},{begin:e.C_NUMBER_RE}],relevance:0},s={className:"subst",begin:"\\$\\{",end:"\\}",keywords:a,contains:[]},i={className:"string",begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE,s]};s.contains=[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,i,r,e.REGEXP_MODE];var t=s.contains.concat([e.C_BLOCK_COMMENT_MODE,e.C_LINE_COMMENT_MODE]);return{aliases:["js","jsx"],keywords:a,contains:[{className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},{className:"meta",begin:/^#!/,end:/$/},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,i,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,r,{begin:/[{,]\s*/,relevance:0,contains:[{begin:n+"\\s*:",returnBegin:!0,relevance:0,contains:[{className:"attr",begin:n,relevance:0}]}]},{begin:"("+e.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.REGEXP_MODE,{className:"function",begin:"(\\(.*?\\)|"+n+")\\s*=>",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:n},{begin:/\(\s*\)/},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:a,contains:t}]}]},{begin:/</,end:/(\/\w+|\w+\/)>/,subLanguage:"xml",contains:[{begin:/<\w+\s*\/>/,skip:!0},{begin:/<\w+/,end:/(\/\w+|\w+\/)>/,skip:!0,contains:[{begin:/<\w+\s*\/>/,skip:!0},"self"]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/\{/,excludeEnd:!0,contains:[e.inherit(e.TITLE_MODE,{begin:n}),{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:t}],illegal:/\[|%/},{begin:/\$[(.]/},e.METHOD_GUARD,{className:"class",beginKeywords:"class",end:/[{;=]/,excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"constructor",end:/\{/,excludeEnd:!0}],illegal:/#(?!!)/}}hljs.registerLanguage("javascript",FLanguage),hljs.registerLanguage("js",FLanguage);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1163,3 +1163,21 @@ LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成
"Pay to ID:":"收款ID:", "Account":"账号", "Owner":"拥有者", "Block num":"区块编号", "Private key (secret)":"私钥 (机密)", "Load key":"载入私钥",
"Create your first account and start using TERA":"创建你的第一个账号开启TERA之旅", "0 Accounts":"0 账号", "OWNER: {Item.Owner}":"拥有者: {Item.Owner}",
"More info":"详情", "Public key":"公钥"};
LangMap["한글"] = {"TERA WALLET":"TERA 지갑", "Generate key":"개인 키 생성", "OK":"OK", "Cancel":"취소", "Edit":"편집", "Save key":"개인 키 저장",
"+ CREATE A NEW ACCOUNT":"+ 새 계정 만들기", "Create account":"계정 만들기", "Send":"발송", "CONFIRM":"확인", "Accounts":"계정", "Account(s)":"계정",
"Blocks & Tx":"블록 & 교역 번호", "Counters":"컨디션 통계", "Open DApp":" DApp을 열기", "Back":"되돌아가기", "Delete":"삭제", "Save to book":"저장",
"Choose":"선택", "RECONNECT":"다시 연결", "DApps":"DApps", "ID":"ID", "Amount":"잔금", "Cur":"화폐", "Name":"이름", "PubKey":"공공키", "Operation":"조작 횟수",
"Smart":"DApp", "Block Num":"블록 번호", "Num":"번호", "Date":"날짜", "Data Hash":"데이터 하희", "PowHash":"Pow하희", "Block Hash":"블록 하희",
"Bytes":"바이트", "Pow":"Pow", "Miner":"바이트", "(secret)":"(비밀)", "Show":"쇼", "TERA":"TERA", "Blockchain height:":"블록높이:", "Current create:":"최근 블록:",
"Protocol ver:":"프로토콜 버전:", "ID: {Item.Num}":"ID: {Item.Num}", "Token generate":"생성대폐", "ACCOUNTS":"계정", "SEND":"발송", "DAPPS":"DAPPS",
"EXPLORER":"브라우저", "ATTENTION: Before using the wallet, save the private key.":"주의: 지갑을 사용하기 전에 반드시 개인 키를 저장해야 한다.", "Web-site":"사이트",
"Bitcointalk":"비트 화폐포럼", "Twitter":"트위터", "Telegram":"전보", "Discord":"Discord", "QQchat":"QQ ", "Buy/sell/mine TERA":"TERA거래 /채광",
"+ CREATE NEW":"+신건", "Confirm Transaction":"거래 확인", "CREATE DAPPS":" DAPPS만들기", "Set pass":"비밀번호 설정", "Unlock":"잠금 풀기", "Entrance to sub-wallet":"부속 지갑 들어가기",
"Public name":"이름", "Currency":"화폐", "Pay to:":"지불:", "Amount:":"수량:", "Description:":"묘사:", "Welcome to TERA Wallet":"TERA 지갑을 환영합니다",
"Edit your wallet":"지갑 편집", "Key settings":"개인 키 설정", "KEY SETTINGS":"개인 키 설정", "Create an account":"계정 만들기", "Sending coins":"동전 보내기",
"Decentralized applications (dApps)":"분산식 응용(DApps)", "Secure your wallet":"지갑 비밀번호 설정", "Wallet is secured":"지갑 비밀번호가 설정되었습니다. ",
"Total":"총계", "Item.Name":"Item.Name", "You have no accounts yet":"당신 아직 계정이 없다", "Wait 10-15 sec":" 10 -15초 기다리기", "Creating your account":"계정 만들기",
"From:":"부터:", "\n Item.Description\n ":"\n Item.Description\n ", "Set a password for protect entry":"접근 비밀번호 설정", "Enter password to unlock wallet":"비밀번호 잠금 풀기",
"From ID:":" ID부터:", "Pay to ID:":"ID 에게 지불:", "Account":"계정", "Owner":"소유자", "Block num":"블록 번호", "Private key (secret)":"개인 키",
"Load key":"개인 키 불러오기", "Create your first account and start using TERA":"첫 번째 계정 만들기, TERA 의 여정을 열고", "0 Accounts":"0계정",
"OWNER: {Item.Owner}":"소유자: {Item.Owner}", "More info":"자세", "Public key":"공공키", };

File diff suppressed because one or more lines are too long

View File

@ -91,7 +91,7 @@ function CheckNameAccTo()
function SetNameAccTo()
{
var Str = "";
var ToID = ($("idTo").value);
var ToID = $("idTo").value.trim();
var Item = MapAccounts[ToID];
var StrTo = GetAccountText(Item, ToID, 1);
var element = $("idNameTo");

View File

@ -528,7 +528,8 @@
function InstallApp()
{
CreateNewAccount(0);
CreateNewAccount(BASE_ACCOUNT.Currency);
if(idInstallApp)
{

View File

@ -1126,6 +1126,7 @@
if(CurBlockNum<ServerBlockNumDB+8)
CurBlockNum=ServerBlockNumDB;
var WasArr=0;
var Arr=[];
for(var i=ArrInfo.length-1;i>=0;i--)
@ -1144,6 +1145,7 @@
{
if(!Item.PowerArr[n])//есть нули
{
//ToLog("n="+n+" Item.BlockNum1="+Item.BlockNum1);
MustUpdate=1;
break;
}
@ -1153,7 +1155,6 @@
var DeltaTime=Math.abs(Item.TimeBlockNum-TimeBlockNum);
if(DeltaTime>Item.Delta/20)
{
//ToLog("i="+i+" DeltaTime="+DeltaTime+" > "+(Item.Delta/20))
MustUpdate=1;
}
}

View File

@ -8,9 +8,37 @@
* Telegram: https://t.me/terafoundation
*/
global.PERIOD_GET_BLOCK = 300, global.COUNT_HISTORY_BLOCKS_FOR_LOAD = 600, global.COUNT_BLOCKS_FOR_CHECK_POW = 50, global.MAX_DELTA_COUNT_SUM_FOR_LOAD = 10,
global.MAX_COUNT_CHAIN_LOAD = 120, global.PACKET_ALIVE_PERIOD = 4 * CONSENSUS_PERIOD_TIME, global.PACKET_ALIVE_PERIOD_NEXT_NODE = PACKET_ALIVE_PERIOD / 2,
global.MAX_BLOCK_SEND = 8, global.COUNT_TASK_FOR_NODE = 10, global.FORMAT_BLOCK_TRANSFER = "{ BlockNum:uint, TreeHash:hash, arrContent:[tr], }",
global.WRK_BLOCK_TRANSFER = {}, global.MAX_ACCOUNTS_TRANSFER = 1024, global.MAX_SMARTS_TRANSFER = 10, global.TEST_NETWORK && (global.MAX_ACCOUNTS_TRANSFER = 128,
global.MAX_SMARTS_TRANSFER = 10), global.FORMAT_REST_TRANSFER = "{ Result:uint, Version:uint, Arr:[arr200], ProofHash:hash, ProofArrL:<hash>, ProofArrR:<hash>, }",
global.FORMAT_SMART_TRANSFER = "{ Result:uint, Arr:[tr], }";
global.PERIOD_GET_BLOCK = 300;
global.COUNT_HISTORY_BLOCKS_FOR_LOAD = 600;
global.COUNT_BLOCKS_FOR_CHECK_POW = 50;
global.MAX_DELTA_COUNT_SUM_FOR_LOAD = 10;
global.MAX_COUNT_CHAIN_LOAD = 120;
global.PACKET_ALIVE_PERIOD = 4 * CONSENSUS_PERIOD_TIME;
global.PACKET_ALIVE_PERIOD_NEXT_NODE = PACKET_ALIVE_PERIOD / 2;
global.MAX_BLOCK_SEND = 8;
global.COUNT_TASK_FOR_NODE = 10;
global.FORMAT_BLOCK_TRANSFER = "{\
BlockNum:uint,\
TreeHash:hash,\
arrContent:[tr],\
}";
global.WRK_BLOCK_TRANSFER = {};
global.MAX_ACCOUNTS_TRANSFER = 1024;
global.MAX_SMARTS_TRANSFER = 10;
if(global.TEST_NETWORK)
{
global.MAX_ACCOUNTS_TRANSFER = 128;
global.MAX_SMARTS_TRANSFER = 10;
}
global.FORMAT_REST_TRANSFER = "{\
Result:uint,\
Version:uint,\
Arr:[arr200],\
ProofHash:hash,\
ProofArrL:<hash>,\
ProofArrR:<hash>,\
}";
global.FORMAT_SMART_TRANSFER = "{\
Result:uint,\
Arr:[tr],\
}";

View File

@ -133,7 +133,7 @@ module.exports = class CBlock extends require("./rest-loader.js")
var PrevHash = CalcHashFromArray(arr, true);
return PrevHash;
}
StartSyncBlockchain(Node, bSilent, bCheckPoint)
StartSyncBlockchain(Node, bSilent, bCheckPoint, PrevStartedBlockNum)
{
this.FREE_ALL_MEM_CHAINS()
if(global.NO_HISTORY_MODE)
@ -149,9 +149,24 @@ module.exports = class CBlock extends require("./rest-loader.js")
this.RelayMode = false
if(!bSilent)
this.RelayMode = true
var StartBlockNum;
if(PrevStartedBlockNum)
{
var DeltaNum = Math.floor(1.2 * (this.BlockNumDB - PrevStartedBlockNum));
if(DeltaNum < 1000)
DeltaNum = 1000
StartBlockNum = this.BlockNumDB - DeltaNum
if(StartBlockNum <= 0)
StartBlockNum = 15
ToLog("Current DeltaNum=" + DeltaNum + " StartBlockNum=" + StartBlockNum, 2)
}
else
{
StartBlockNum = this.BlockNumDB
}
this.LoadHistoryMode = true
this.LoadHistoryMessage = !bSilent
this.LoadHistoryContext = {PrevBlockNum: - 1, Node:Node, BlockNum:this.BlockNumDB, MapSend:{}, Foward:1, Pause:0, DeltaBlockNum:10,
this.LoadHistoryContext = {PrevBlockNum: - 1, Node:Node, BlockNum:StartBlockNum, MapSend:{}, Foward:1, Pause:0, DeltaBlockNum:10,
StartTimeHistory:Date.now(), MaxTimeOut:30 * 1000}
if(!bSilent && !bCheckPoint && REST_START_COUNT)
{
@ -184,7 +199,7 @@ module.exports = class CBlock extends require("./rest-loader.js")
if(DeltaTime > Context.MaxTimeOut)
{
ToLog("DETECT TIMEOUT LOAD")
this.StartSyncBlockchain()
this.StartSyncBlockchain(undefined, undefined, undefined, Context.BlockNum)
return ;
}
}
@ -543,6 +558,7 @@ module.exports = class CBlock extends require("./rest-loader.js")
{
if(!Context.WasLoadNum)
{
ToLog("Not found: " + Context.BlockNum + " from node:" + NodeName(Info.Node), 2)
Context.BlockNum = Math.floor(Context.BlockNum - Context.DeltaBlockNum)
Context.DeltaBlockNum = Context.DeltaBlockNum * 1.2
if(Context.BlockNum < BLOCK_PROCESSING_LENGTH2)

View File

@ -8,357 +8,665 @@
* Telegram: https://t.me/terafoundation
*/
module.exports.GetNewBuffer = GetNewBuffer;
module.exports.GetReadBuffer = GetReadBuffer;
module.exports.alloc = GetNewBuffer;
module.exports.from = GetReadBuffer;
module.exports.Write = Write;
module.exports.Read = Read;
module.exports.GetObjectFromBuffer = GetObjectFromBuffer;
module.exports.GetBufferFromObject = GetBufferFromObject;
function Write(e,r,t,n,l)
function Write(buf,data,StringFormat,ParamValue,WorkStruct)
{
if(!(e.len >= e.length))
if(buf.len >= buf.length)
{
if("number" == typeof t)
throw ToLogTrace("ERRR StringFormat "), "ERR!!";
var a = t;
if("buffer" === a.substr(0, 6) && 6 < a.length)
n = parseInt(a.substr(6)), a = "buffer";
return ;
}
if(typeof StringFormat === "number")
{
ToLogTrace("ERRR StringFormat ");
throw "ERR!!";
}
else
{
var format = StringFormat;
if(format.substr(0, 6) === "buffer" && format.length > 6)
{
ParamValue = parseInt(format.substr(6));
format = "buffer";
}
else
if("arr" === a.substr(0, 3) && 3 < a.length)
n = parseInt(a.substr(3)), a = "arr";
if(format.substr(0, 3) === "arr" && format.length > 3)
{
ParamValue = parseInt(format.substr(3));
format = "arr";
}
else
if("str" === a.substr(0, 3) && 3 < a.length)
if(format.substr(0, 3) === "str" && format.length > 3)
{
var i = parseInt(a.substr(3));
return r && e.write(r, e.len, i), void (e.len += i);
var length = parseInt(format.substr(3));
if(data)
buf.write(data, buf.len, length);
buf.len += length;
return ;
}
switch(a)
switch(format)
{
case "str":
var f = toUTF8Array(r);
65535 < (i = f.length) && (i = 0), e[e.len] = 255 & i, e[e.len + 1] = i >>> 8 & 255, e.len += 2;
for(var s = 0; s < i; s++)
e[e.len + s] = f[s];
e.len += i;
break;
{
var arr = toUTF8Array(data);
var length = arr.length;
if(length > 65535)
length = 0;
buf[buf.len] = length & 255;
buf[buf.len + 1] = (length >>> 8) & 255;
buf.len += 2;
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = arr[i];
}
buf.len += length;
break;
}
case "byte":
r < 0 && (r = 0), e[e.len] = r, e.len += 1;
break;
{
if(data < 0)
data = 0;
buf[buf.len] = data;
buf.len += 1;
break;
}
case "double":
e.writeDoubleLE(r, e.len, 8), e.len += 8;
break;
{
buf.writeDoubleLE(data, buf.len, 8);
buf.len += 8;
break;
}
case "uint":
r < 0 && (r = 0), 0xffffffffffff <= r && (r = 0), e.writeUIntLE(r, e.len, 6), e.len += 6;
break;
{
if(data < 0)
data = 0;
if(data >= 281474976710655)
data = 0;
buf.writeUIntLE(data, buf.len, 6);
buf.len += 6;
break;
}
case "uint16":
r < 0 && (r = 0), e[e.len] = 255 & r, e[e.len + 1] = r >>> 8 & 255, e.len += 2;
break;
{
if(data < 0)
data = 0;
buf[buf.len] = data & 255;
buf[buf.len + 1] = (data >>> 8) & 255;
buf.len += 2;
break;
}
case "uint32":
r < 0 && (r = 0), e.writeUInt32LE(r, e.len, 4), e.len += 4;
break;
{
if(data < 0)
data = 0;
buf.writeUInt32LE(data, buf.len, 4);
buf.len += 4;
break;
}
case "time":
var u = r.valueOf();
e.writeUIntLE(u, e.len, 6), e.len += 6;
break;
{
var Time = data.valueOf();
buf.writeUIntLE(Time, buf.len, 6);
buf.len += 6;
break;
}
case "addres":
case "hash":
i = r ? Math.min(32, r.length) : 0;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += 32;
break;
case "buffer":
i = void 0 === n ? r.length : Math.min(n, r.length);
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += n;
break;
case "arr":
i = r ? Math.min(n, r.length) : 0;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += n;
break;
case "tr":
i = r.length;
MAX_TRANSACTION_SIZE > MAX_TRANSACTION_SIZE && (i = MAX_TRANSACTION_SIZE), e[e.len] = 255 & i, e[e.len + 1] = i >>> 8 & 255,
e.len += 2;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += i;
break;
case "data":
i = r.length;
e.writeUInt32LE(i, e.len, 4), e.len += 4;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += i;
break;
case "hashSTR":
var o = GetHexFromAddres(r);
e.write(o, e.len, 64), e.len += 64;
break;
case "uintSTR":
o = r.toString();
e.write(o, e.len, 10), e.len += 10;
break;
default:
l = l || {};
var d = t.substr(0, 1);
if("[" === d)
{
r && (i = r.length);
var b = GetMiddleString(a);
Write(e, i, "uint32");
for(s = 0; s < i; s++)
Write(e, r[s], b, void 0, l);
var length;
if(data)
length = Math.min(32, data.length);
else
length = 0;
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = data[i];
}
buf.len += 32;
break;
}
case "buffer":
{
var length;
if(ParamValue === undefined)
length = data.length;
else
length = Math.min(ParamValue, data.length);
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = data[i];
}
buf.len += ParamValue;
break;
}
case "arr":
{
var length;
if(data)
length = Math.min(ParamValue, data.length);
else
length = 0;
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = data[i];
}
buf.len += ParamValue;
break;
}
case "tr":
{
var length = data.length;
if(MAX_TRANSACTION_SIZE > MAX_TRANSACTION_SIZE)
length = MAX_TRANSACTION_SIZE;
buf[buf.len] = length & 255;
buf[buf.len + 1] = (length >>> 8) & 255;
buf.len += 2;
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = data[i];
}
buf.len += length;
break;
}
case "data":
{
var length = data.length;
buf.writeUInt32LE(length, buf.len, 4);
buf.len += 4;
for(var i = 0; i < length; i++)
{
buf[buf.len + i] = data[i];
}
buf.len += length;
break;
}
case "hashSTR":
{
var Str = GetHexFromAddres(data);
buf.write(Str, buf.len, 64);
buf.len += 64;
break;
}
case "uintSTR":
{
var Str = data.toString();
buf.write(Str, buf.len, 10);
buf.len += 10;
break;
}
default:
{
WorkStruct = WorkStruct || {};
var CurFormat = StringFormat.substr(0, 1);
if(CurFormat === "[")
{
var length;
if(data)
length = data.length;
var formatNext = GetMiddleString(format);
Write(buf, length, "uint32");
for(var i = 0; i < length; i++)
{
Write(buf, data[i], formatNext, undefined, WorkStruct);
}
}
else
if(CurFormat === "<")
{
var length;
if(data)
length = data.length;
var formatNext = GetMiddleString(format);
var IndexCount = 0;
var len = buf.len;
buf.len += 4;
for(var i = 0; i < length; i++)
{
if(data[i])
{
IndexCount++;
Write(buf, i, "uint32");
Write(buf, data[i], formatNext, undefined, WorkStruct);
}
}
buf.writeUInt32LE(IndexCount, len, 4);
}
else
if(CurFormat === "{")
{
var attrs = WorkStruct[format];
if(!attrs)
{
attrs = GetAttributes(GetMiddleString(format));
WorkStruct[format] = attrs;
}
for(var i = 0; i < attrs.length; i++)
{
var type = attrs[i];
Write(buf, data[type.Key], type.Value, undefined, WorkStruct);
}
}
else
{
throw "Bad write type params: " + format;
}
}
}
}
};
function Read(buf,StringFormat,ParamValue,WorkStruct,bDisableTime)
{
var ret;
if(typeof StringFormat === "number")
{
ToLogTrace("ERR StringFormat");
throw "ERRR!";
}
else
{
var format = StringFormat;
if(format.substr(0, 6) === "buffer")
{
if(format.length > 6)
{
ParamValue = parseInt(format.substr(6));
format = "buffer";
}
else
{
ParamValue = 0;
}
}
else
if(format.substr(0, 3) === "arr")
{
if(format.length > 3)
{
ParamValue = parseInt(format.substr(3));
format = "arr";
}
else
if("<" === d)
{
ParamValue = 0;
}
}
else
if(format.substr(0, 3) === "str")
{
if(format.length > 3)
{
r && (i = r.length);
b = GetMiddleString(a);
var h = 0, c = e.len;
e.len += 4;
for(s = 0; s < i; s++)
r[s] && (h++, Write(e, s, "uint32"), Write(e, r[s], b, void 0, l));
e.writeUInt32LE(h, c, 4);
var length = parseInt(format.substr(3));
ret = buf.toString('utf8', buf.len, buf.len + length);
buf.len += length;
var nEnd = - 1;
for(var i = ret.length - 1; i >= 0; i--)
{
if(ret.charCodeAt(i) !== 0)
{
nEnd = i;
break;
}
}
if(nEnd >= 0)
ret = ret.substr(0, i + 1);
else
ret = "";
return ret;
}
else
{
if("{" !== d)
throw "Bad write type params: " + a;
var g = l[a];
g || (g = GetAttributes(GetMiddleString(a)), l[a] = g);
for(s = 0; s < g.length; s++)
ParamValue = 0;
}
}
switch(format)
{
case "str":
{
var length;
if(buf.len + 2 <= buf.length)
length = buf[buf.len] + buf[buf.len + 1] * 256;
else
length = 0;
buf.len += 2;
var arr = buf.slice(buf.len, buf.len + length);
ret = Utf8ArrayToStr(arr);
buf.len += length;
break;
}
case "byte":
{
if(buf.len + 1 <= buf.length)
ret = buf[buf.len];
else
ret = 0;
buf.len += 1;
break;
}
case "double":
{
if(buf.len + 8 <= buf.length)
ret = buf.readDoubleLE(buf.len, 8);
else
ret = 0;
buf.len += 8;
break;
}
case "uint":
{
if(buf.len + 6 <= buf.length)
ret = buf.readUIntLE(buf.len, 6);
else
ret = 0;
buf.len += 6;
break;
}
case "uint16":
{
if(buf.len + 2 <= buf.length)
ret = buf[buf.len] + buf[buf.len + 1] * 256;
else
ret = 0;
buf.len += 2;
break;
}
case "uint32":
{
if(buf.len + 4 <= buf.length)
ret = buf.readUInt32LE(buf.len, 4);
else
ret = 0;
buf.len += 4;
break;
}
case "time":
{
if(bDisableTime)
throw "Bad read type params: time - DisableTime ON";
if(buf.len + 6 <= buf.length)
ret = buf.readUIntLE(buf.len, 6);
else
ret = 0;
ret = new Date(ret);
buf.len += 6;
break;
}
case "addres":
case "hash":
{
ret = [];
for(var i = 0; i < 32; i++)
{
if(buf.len + i <= buf.length)
ret[i] = buf[buf.len + i];
else
ret[i] = 0;
}
buf.len += 32;
break;
}
case "buffer":
case "arr":
{
if(buf.len + ParamValue <= buf.length)
ret = buf.slice(buf.len, buf.len + ParamValue);
else
ret = Buffer.alloc(ParamValue);
buf.len += ParamValue;
break;
}
case "tr":
{
if(buf.len + 1 >= buf.length)
{
ret = undefined;
break;
}
var length = buf[buf.len] + buf[buf.len + 1] * 256;
buf.len += 2;
ret = buf.slice(buf.len, buf.len + length);
buf.len += length;
break;
}
case "data":
{
var length;
if(buf.len + 4 <= buf.length)
length = buf.readUInt32LE(buf.len, 4);
else
length = 0;
if(length > buf.length - buf.len - 4)
length = 0;
buf.len += 4;
ret = buf.slice(buf.len, buf.len + length);
buf.len += length;
break;
}
case "hashSTR":
{
var Str = buf.toString('utf8', buf.len, buf.len + 64);
ret = GetAddresFromHex(Str);
buf.len += 64;
break;
}
case "uintSTR":
{
var Str = buf.toString('utf8', buf.len, buf.len + 10);
ret = parseInt(Str);
buf.len += 10;
break;
}
default:
{
WorkStruct = WorkStruct || {};
var LStr = format.substr(0, 1);
if(LStr === "[" || LStr === "<")
{
var bIndexArr = (LStr === "<");
ret = [];
var formatNext = GetMiddleString(format);
var length = Read(buf, "uint32");
for(var i = 0; i < length; i++)
{
var v = g[s];
Write(e, r[v.Key], v.Value, void 0, l);
if(buf.len <= buf.length)
{
if(bIndexArr)
{
var index = Read(buf, "uint32");
ret[index] = Read(buf, formatNext, undefined, WorkStruct, bDisableTime);
}
else
{
ret[i] = Read(buf, formatNext, undefined, WorkStruct, bDisableTime);
}
}
else
break;
}
}
}
}
};
function Read(e,r,t,n,l)
{
var a;
if("number" == typeof r)
throw ToLogTrace("ERR StringFormat"), "ERRR!";
var i = r;
if("buffer" === i.substr(0, 6))
6 < i.length ? (t = parseInt(i.substr(6)), i = "buffer") : t = 0;
else
if("arr" === i.substr(0, 3))
3 < i.length ? (t = parseInt(i.substr(3)), i = "arr") : t = 0;
else
if("str" === i.substr(0, 3))
{
if(3 < i.length)
{
var f = parseInt(i.substr(3));
a = e.toString("utf8", e.len, e.len + f), e.len += f;
for(var s = - 1, u = a.length - 1; 0 <= u; u--)
if(0 !== a.charCodeAt(u))
else
if(LStr === "{")
{
s = u;
break;
var attrs = WorkStruct[format];
if(!attrs)
{
attrs = GetAttributes(GetMiddleString(format));
WorkStruct[format] = attrs;
}
ret = {};
for(var i = 0; i < attrs.length; i++)
{
var type = attrs[i];
ret[type.Key] = Read(buf, type.Value, undefined, WorkStruct, bDisableTime);
}
}
else
{
throw "Bad read type params: " + format;
}
return a = 0 <= s ? a.substr(0, u + 1) : "";
}
t = 0;
}
switch(i)
{
case "str":
f = e.len + 2 <= e.length ? e[e.len] + 256 * e[e.len + 1] : 0, e.len += 2;
var o = e.slice(e.len, e.len + f);
a = Utf8ArrayToStr(o), e.len += f;
break;
case "byte":
a = e.len + 1 <= e.length ? e[e.len] : 0, e.len += 1;
break;
case "double":
a = e.len + 8 <= e.length ? e.readDoubleLE(e.len, 8) : 0, e.len += 8;
break;
case "uint":
a = e.len + 6 <= e.length ? e.readUIntLE(e.len, 6) : 0, e.len += 6;
break;
case "uint16":
a = e.len + 2 <= e.length ? e[e.len] + 256 * e[e.len + 1] : 0, e.len += 2;
break;
case "uint32":
a = e.len + 4 <= e.length ? e.readUInt32LE(e.len, 4) : 0, e.len += 4;
break;
case "time":
if(l)
throw "Bad read type params: time - DisableTime ON";
a = e.len + 6 <= e.length ? e.readUIntLE(e.len, 6) : 0, a = new Date(a), e.len += 6;
break;
case "addres":
case "hash":
a = [];
for(u = 0; u < 32; u++)
e.len + u <= e.length ? a[u] = e[e.len + u] : a[u] = 0;
e.len += 32;
break;
case "buffer":
case "arr":
a = e.len + t <= e.length ? e.slice(e.len, e.len + t) : Buffer.alloc(t), e.len += t;
break;
case "tr":
if(e.len + 1 >= e.length)
{
a = void 0;
break;
}
f = e[e.len] + 256 * e[e.len + 1];
e.len += 2, a = e.slice(e.len, e.len + f), e.len += f;
break;
case "data":
(f = e.len + 4 <= e.length ? e.readUInt32LE(e.len, 4) : 0) > e.length - e.len - 4 && (f = 0), e.len += 4, a = e.slice(e.len,
e.len + f), e.len += f;
break;
case "hashSTR":
var d = e.toString("utf8", e.len, e.len + 64);
a = GetAddresFromHex(d), e.len += 64;
break;
case "uintSTR":
d = e.toString("utf8", e.len, e.len + 10);
a = parseInt(d), e.len += 10;
break;
default:
n = n || {};
var b = i.substr(0, 1);
if("[" === b || "<" === b)
{
var h = "<" === b;
a = [];
var c = GetMiddleString(i);
for(f = Read(e, "uint32"), u = 0; u < f && e.len <= e.length; u++)
{
h ? a[Read(e, "uint32")] = Read(e, c, void 0, n, l) : a[u] = Read(e, c, void 0, n, l);
}
}
else
{
if("{" !== b)
throw "Bad read type params: " + i;
var g = n[i];
g || (g = GetAttributes(GetMiddleString(i)), n[i] = g), a = {};
for(u = 0; u < g.length; u++)
{
var v = g[u];
a[v.Key] = Read(e, v.Value, void 0, n, l);
}
}
}
return a;
};
function BufWriteByte(e)
{
this[this.len] = e, this.len += 1;
};
function BufWrite(e,r,t)
{
Write(this, e, r, t);
};
function BufRead(e,r)
{
return Read(this, e, r);
};
function GetNewBuffer(e)
{
var r = Buffer.alloc(e);
return r.Read = BufRead.bind(r), r.Write = BufWrite.bind(r), r.len = 0, r;
};
function GetReadBuffer(e)
{
var r = Buffer.from(e);
return r.Read = BufRead.bind(r), r.Write = BufWrite.bind(r), r.len = 0, r;
};
function GetObjectFromBuffer(e,r,t,n)
{
var l = Buffer.from(e);
return l.len = 0, Read(l, r, void 0, t, n);
};
function GetBufferFromObject(e,r,t,n,l)
{
var a = Buffer.alloc(t);
return a.len = 0, Write(a, e, r, void 0, n), l || (a = a.slice(0, a.len)), a;
};
function GetMiddleString(e)
{
return e.substr(1, e.length - 2);
};
function GetMiddleString2(e,r,t)
{
for(var n = 0, l = "", a = 0; a < e.length; a++)
{
var i = e.substr(a, 1);
if(" " !== i && "\n" !== i && (i !== r || 1 != ++n))
{
if(i === t && 0 === --n)
break;
n && (l += i);
}
}
return l;
return ret;
};
function GetAttributeStrings(e)
function BufWriteByte(value)
{
for(var r = 0, t = [], n = "", l = 0; l < e.length; l++)
this[this.len] = value;
this.len += 1;
};
function BufWrite(data,StringFormat,ParamValue)
{
Write(this, data, StringFormat, ParamValue);
};
function BufRead(StringFormat,ParamValue)
{
return Read(this, StringFormat, ParamValue);
};
function GetNewBuffer(size)
{
var buf = Buffer.alloc(size);
buf.Read = BufRead.bind(buf);
buf.Write = BufWrite.bind(buf);
buf.len = 0;
return buf;
};
function GetReadBuffer(buffer)
{
var buf = Buffer.from(buffer);
buf.Read = BufRead.bind(buf);
buf.Write = BufWrite.bind(buf);
buf.len = 0;
return buf;
};
function GetObjectFromBuffer(buffer,format,WorkStruct,bDisableTime)
{
var buf = Buffer.from(buffer);
buf.len = 0;
return Read(buf, format, undefined, WorkStruct, bDisableTime);
};
function GetBufferFromObject(data,format,size,WorkStruct,bNotSlice)
{
var buf = Buffer.alloc(size);
buf.len = 0;
Write(buf, data, format, undefined, WorkStruct);
if(!bNotSlice)
{
var a = e.substr(l, 1);
if("{" === a)
r++;
buf = buf.slice(0, buf.len);
}
return buf;
};
function GetMiddleString(Str)
{
return Str.substr(1, Str.length - 2);
};
function GetMiddleString2(Str,FromStr,ToStr)
{
var Count = 0;
var Result = "";
for(var i = 0; i < Str.length; i++)
{
var FStr = Str.substr(i, 1);
if(FStr === " " || FStr === "\n")
{
continue;
}
if(FStr === FromStr)
{
Count++;
if(Count === 1)
continue;
}
if(FStr === ToStr)
{
Count--;
if(Count === 0)
break;
}
if(Count)
Result = Result + FStr;
}
return Result;
};
function GetAttributeStrings(Str)
{
var Count = 0;
var Result = [];
var Element = "";
for(var i = 0; i < Str.length; i++)
{
var FStr = Str.substr(i, 1);
if(FStr === "{")
{
Count++;
}
else
if("}" === a)
r--;
else
if(FStr === "}")
{
if("," === a && 0 === r)
Count--;
}
else
if(FStr === "," && Count === 0)
{
0 < n.length && t.push(n), n = "";
if(Element.length > 0)
Result.push(Element);
Element = "";
continue;
}
if(" " === a || "\n" === a)
continue;
}
n += a;
else
if(FStr === " " || FStr === "\n")
continue;
Element = Element + FStr;
}
return 0 < n.length && t.push(n), t;
if(Element.length > 0)
Result.push(Element);
return Result;
};
function GetKeyValueStrings(e)
function GetKeyValueStrings(Str)
{
for(var r = "", t = 0; t < e.length; t++)
var Key = "";
for(var i = 0; i < Str.length; i++)
{
var n = e.substr(t, 1);
if(" " !== n && "\n" !== n)
var FStr = Str.substr(i, 1);
if(FStr === " " || FStr === "\n")
{
if(":" === n)
return {Key:r, Value:e.substr(t + 1)};
r += n;
continue;
}
if(FStr === ":")
{
var Value = Str.substr(i + 1);
return {Key:Key, Value:Value};
}
Key = Key + FStr;
}
throw "Error format Key:Value = " + e;
throw "Error format Key:Value = " + Str;
};
function GetAttributes(e)
function GetAttributes(Str)
{
for(var r = [], t = GetAttributeStrings(e), n = 0; n < t.length; n++)
var arr = [];
var attrstr = GetAttributeStrings(Str);
for(var i = 0; i < attrstr.length; i++)
{
var l = GetKeyValueStrings(t[n]);
r.push(l);
var type = GetKeyValueStrings(attrstr[i]);
arr.push(type);
}
return r;
return arr;
};
module.exports.GetNewBuffer = GetNewBuffer, module.exports.GetReadBuffer = GetReadBuffer, module.exports.alloc = GetNewBuffer,
module.exports.from = GetReadBuffer, module.exports.Write = Write, module.exports.Read = Read, module.exports.GetObjectFromBuffer = GetObjectFromBuffer,
module.exports.GetBufferFromObject = GetBufferFromObject;

View File

@ -8,7 +8,7 @@
* Telegram: https://t.me/terafoundation
*/
global.UPDATE_CODE_VERSION_NUM = 1131;
global.UPDATE_CODE_VERSION_NUM = 1133;
global.MIN_CODE_VERSION_NUM = 1114;
global.MINING_VERSION_NUM = 0;
global.InitParamsArg = InitParamsArg;
@ -18,8 +18,8 @@ global.CONST_NAME_ARR = ["AUTO_CORRECT_TIME", "DELTA_CURRENT_TIME", "COMMON_KEY"
"ALL_LOG_TO_CLIENT", "LOG_LEVEL", "USE_MINING", "MINING_START_TIME", "MINING_PERIOD_TIME", "POW_MAX_PERCENT", "COUNT_MINING_CPU",
"SIZE_MINING_MEMORY", "POW_RUN_COUNT", "USE_AUTO_UPDATE", "RESTART_PERIOD_SEC", "MAX_GRAY_CONNECTIONS_TO_SERVER", "TRANSACTION_PROOF_COUNT",
"UPDATE_NUM_COMPLETE", "LIMIT_SEND_TRAFIC", "WATCHDOG_DEV", "ADDRLIST_MODE", "CheckPointDelta", "MIN_VER_STAT", "DEBUG_WALLET",
"HTTP_HOSTING_PORT", "HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "HTTP_ADMIN_PASSORD", "WATCHDOG_BADACCOUNT", "RESYNC_CONDITION",
"MAX_CONNECTIONS_COUNT", "TRUST_PROCESS_COUNT", "REST_START_COUNT", "LOAD_TO_BEGIN", ];
"HTTP_HOSTING_PORT", "HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "HTTP_ADMIN_PASSWORD", "HTTP_START_PAGE", "WATCHDOG_BADACCOUNT",
"RESYNC_CONDITION", "MAX_CONNECTIONS_COUNT", "TRUST_PROCESS_COUNT", "REST_START_COUNT", "LOAD_TO_BEGIN", ];
global.MAX_LENGTH_SENDER_MAP = 3000;
global.DELTA_START_SENDER_MAP = 24;
global.NODES_DELTA_CALC_HOUR = 4;
@ -73,7 +73,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.js");
global.MIN_POWER_POW_HANDSHAKE = 12;
global.USE_HINT = 0;

View File

@ -8,80 +8,127 @@
* Telegram: https://t.me/terafoundation
*/
var BufIP, fs = require("fs");
var fs = require('fs');
require("./library.js");
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 BufIP;
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)
function SetGeoLocation(Item)
{
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 ReadItem(e,t)
{
return BufIP.len = e * t, BufLib.Read(BufIP, Format, void 0, FormatStruct);
};
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(!Item.ip || !BufIP || !BufIP.length)
return false;
var Num = IPToUint(Item.ip);
var Location = FindItem(BufIP, 20, Num);
if(Location)
{
if(f--, !(n = ReadItem(o, t)))
return void ToLog("GEO FindItem - Error read num: " + o);
if(n.Value > i)
Item.latitude = Location.latitude;
Item.longitude = Location.longitude;
Item.name = MapNames[Location.id];
}
Item.Geo = 1;
return true;
};
function ReadItem(Num,Size)
{
BufIP.len = Num * Size;
var Data = BufLib.Read(BufIP, Format, undefined, FormatStruct);
return Data;
};
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(u = o - 1, 0 === (l = o - a))
return ;
o -= l = Math.trunc((1 + l) / 2);
}
else
if(n.Value < i)
if(Item.Value > FindValue)
{
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);
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
{
ToLog("GEO FindItem - Error read num: " + CurNum);
return undefined;
}
}
return undefined;
};
function Init()
{
if(fs.existsSync(FileIp) && fs.existsSync(FileNames))
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)
{
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;
}
}
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)
function IPToUint(IPv4)
{
var t = e.split(".");
return 256 * (256 * (256 * + t[0] + + t[1]) + + t[2]) + + t[3];
var d = IPv4.split('.');
return (((((( + d[0]) * 256) + ( + d[1])) * 256) + ( + d[2])) * 256) + ( + d[3]);
};
global.SetGeoLocation = SetGeoLocation, Init();
global.SetGeoLocation = SetGeoLocation;
Init();

View File

@ -1951,6 +1951,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)
{
@ -1966,7 +1969,7 @@ HTTPCaller.GetHashRate = function (ArrParams)
var CountSum = 0;
for(var d = 0; d < CountAvg; d++)
{
var Block = SERVER.ReadBlockHeaderDB(Num + d);
var Block = SERVER.ReadBlockHeaderDB(Num + d * StepDeltaAvg);
if(Block)
{
CountSum++;

View File

@ -9,259 +9,492 @@
*/
require("./constant.js");
var fs = require("fs");
var fs = require('fs');
require("./log-strict.js");
var file_name_info = GetDataPath("info.log"), file_name_infoPrev = GetDataPath("info-prev.log");
var file_name_info = GetDataPath("info.log");
var file_name_infoPrev = GetDataPath("info-prev.log");
CheckSizeLogFile(file_name_info, file_name_infoPrev);
var file_name_log = GetDataPath("log.log"), file_name_logPrev = GetDataPath("log-prev.log");
var file_name_log = GetDataPath("log.log");
var file_name_logPrev = GetDataPath("log-prev.log");
CheckSizeLogFile(file_name_log, file_name_logPrev);
var file_name_log_web = GetDataPath("web.log"), file_name_log_webPrev = GetDataPath("web-prev.log");
var file_name_log_web = GetDataPath("web.log");
var file_name_log_webPrev = GetDataPath("web-prev.log");
CheckSizeLogFile(file_name_log_web, file_name_log_webPrev);
var file_name_error = GetDataPath("err.log"), file_name_errorPrev = GetDataPath("err-prev.log");
var file_name_error = GetDataPath("err.log");
var file_name_errorPrev = GetDataPath("err-prev.log");
CheckSizeLogFile(file_name_error, file_name_errorPrev);
var StartStatTime, file_name_error_tx = GetDataPath("err-tx.log"), file_name_error_txPrev = GetDataPath("err-tx-prev.log");
function ToLogFile(e,t,r)
var file_name_error_tx = GetDataPath("err-tx.log");
var file_name_error_txPrev = GetDataPath("err-tx-prev.log");
CheckSizeLogFile(file_name_error_tx, file_name_error_txPrev);
global.ToLog = function (Str,Level)
{
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({cmd:"log",
message:t}) : (console.log(START_PORT_NUMBER + ": " + 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;
global.ToLogWeb = function (Str)
{
if(global.WEB_LOG)
{
SaveToLogFileSync(file_name_log_web, Str);
}
};
global.SmallAddr = function (Str)
{
return Str.substr(0, 5);
};
global.ToErrorTrace = function (Str)
{
ToError("" + Str + ":" + new Error().stack);
};
global.ToLogTrace = function (Str)
{
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);
ToLog(Str);
};
function ToLogClient(e,t,r)
function ToLogFile(file_name,Str,bNoFile)
{
e && (ToLogFile(file_name_log, e), t = t || "", ArrLogClient.push({text:GetStrOnlyTime() + " " + e, key:t, final:r}), 13 < ArrLogClient.length && ArrLogClient.shift());
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("" + START_PORT_NUMBER + ": " + GetStrOnlyTime() + ": " + Str);
}
if(bNoFile)
return ;
SaveToLogFileSync(file_name, Str);
};
CheckSizeLogFile(file_name_error_tx, file_name_error_txPrev), global.ToLog = function (e,t)
global.ArrLogClient = [];
function ToLogClient(Str,StrKey,bFinal)
{
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.WEB_LOG = 0, global.ToLogWeb = function (e)
if(!Str)
return ;
ToLogFile(file_name_log, Str);
if(!StrKey)
StrKey = "";
ArrLogClient.push({text:GetStrOnlyTime() + " " + Str, key:StrKey, final:bFinal, });
if(ArrLogClient.length > 13)
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.WEB_LOG && SaveToLogFileSync(file_name_log_web, e);
}, global.SmallAddr = function (e)
CurStatIndex++;
var index = GetCurrentStatIndex();
CopyStatInterval(CONTEXT_STATS, index);
CopyStatInterval(CONTEXT_ERRORS, index);
};
global.TO_ERROR_LOG = function (Module,ErrNum,Str,type,data1,data2)
{
return e.substr(0, 5);
}, global.ToErrorTrace = function (e)
{
ToError(e + ":" + (new Error).stack);
}, global.ToLogTrace = function (e)
{
ToErrorTrace(e);
}, global.ToInfo = function (e)
{
ToLogFile(file_name_info, e, 1);
}, global.ToError = function (e)
{
ToLogFile(file_name_error, e);
}, global.ToErrorTx = function (e)
{
SaveToLogFileSync(file_name_error_tx, e), ToLog(e);
}, global.ArrLogClient = [], global.ToLogClient = ToLogClient, global.ToLogClient0 = ToLogClient;
var CONTEXT_STATS = {Total:{}, Interval:[]}, CONTEXT_ERRORS = {Total:{}, Interval:[]}, CurStatIndex = 0;
if(Str instanceof Error)
{
Str = Str.message + "\n";
}
if(type === "rinfo")
Str += " from: " + data1.address + ':' + data1.port;
else
if(type === "node")
Str += " from: " + data1.ip + ':' + data1.port;
var Key = Module + ":" + ErrNum;
ToError(" ==ERROR== " + Key + " " + Str);
AddToStatContext(CONTEXT_ERRORS, Key);
ADD_TO_STAT("ERRORS");
};
function GetCurrentStatIndex()
{
var e = 2 * MAX_STAT_PERIOD + 2;
return CurStatIndex % e;
var DefMaxStatPeriod = MAX_STAT_PERIOD * 2 + 2;
return CurStatIndex % DefMaxStatPeriod;
};
function ResizeArrMax(e)
global.HASH_RATE = 0;
global.ADD_HASH_RATE = function (Count)
{
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;
Count = Count / 1000000;
global.HASH_RATE += Count;
ADD_TO_STAT("HASHRATE", Count);
};
function ResizeArrAvg(e)
global.GET_STAT = function (Key)
{
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;
var Val = CONTEXT_STATS.Total[Key];
if(!Val)
Val = 0;
return Val;
};
function ResizeArr(e)
global.ADD_TO_STAT_TIME = function (Name,startTime,bDetail)
{
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++)
if(global.STAT_MODE)
{
var S = g % o;
if(n = e.Interval[S])
if(bDetail && global.STAT_MODE !== 2)
return ;
var Time = process.hrtime(startTime);
var deltaTime = Time[0] * 1000 + Time[1] / 1e6;
ADD_TO_STAT(Name, deltaTime);
}
};
global.ADD_TO_STAT = function (Key,Count,bDetail)
{
if(global.STAT_MODE)
{
if(bDetail && global.STAT_MODE !== 2)
return ;
AddToStatContext(CONTEXT_STATS, Key, Count);
}
};
global.GET_STATDIAGRAMS = function (Keys)
{
var now = GetCurrentTime();
var index = GetCurrentStatIndex();
if(!Keys || !Keys.length)
return [];
var Data = [];
for(var i = 0; i < Keys.length; i++)
{
var name = Keys[i];
var Value = GetDiagramData(CONTEXT_STATS, name);
Data.push({name:name, maxindex:index, arr:Value, starttime:(StartStatTime - 0), steptime:1});
}
var MinLength = undefined;
for(var i = 0; i < Data.length; i++)
{
var arr = Data[i].arr;
if(arr.length > 0 && (MinLength === undefined || arr.length < MinLength))
MinLength = arr.length;
}
var MaxSizeArr = 500;
for(var i = 0; i < Data.length; i++)
{
var ItemServer = Data[i];
var arr = ItemServer.arr;
if(MinLength && arr.length > MinLength)
{
var _ = n[t];
void 0 !== _ ? r ? i.push(_) : (void 0 !== T ? i.push(_ - T) : i.push(_), T = _) : i.push(0);
arr = arr.slice(arr.length - MinLength);
}
if(MinLength)
if(",POWER_MY_WIN,POWER_BLOCKCHAIN,".indexOf("," + ItemServer.name + ",") >= 0)
{
arr = SERVER.GetStatBlockchain(ItemServer.name, MinLength);
}
var AvgValue = 0;
for(var j = 0; j < arr.length; j++)
{
if(arr[j])
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;
}
}
}
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 || 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 = GetStrTime() + " : " + o + "\r\n";
fs.write(r, t, null, "utf8", function (e,t)
while(arr.length >= MaxSizeArr)
{
e ? console.log("Ошибка записи в лог-файл ошибок!") : fs.close(r, function (e)
arr = ResizeArrAvg(arr);
StepTime = StepTime * 2;
}
}
ItemServer.AvgValue = AvgValue;
ItemServer.steptime = StepTime;
ItemServer.arr = arr.slice(1);
}
return Data;
};
global.GET_STATS = function (Key)
{
var now = GetCurrentTime();
var index = GetCurrentStatIndex();
var stats = {Counter:CONTEXT_STATS.Total, Counter10S:CalcInterval(CONTEXT_STATS, index, 10), Counter10M:CalcInterval(CONTEXT_STATS,
index, 10 * 60), };
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 ()
{
for(var key in CONTEXT_STATS.Total)
return ;
ClearCommonStat();
};
global.ClearCommonStat = function ()
{
CurStatIndex = 0;
StartStatTime = undefined;
CONTEXT_STATS = {Total:{}, Interval:[]};
CONTEXT_ERRORS = {Total:{}, Interval:[]};
global.HASH_RATE = 0;
SERVER.ClearStat();
};
function ResizeArrMax(arr)
{
var arr2 = [];
var Count2 = Math.trunc(arr.length / 2);
for(var i = 0; i < Count2; i++)
{
arr2[i] = Math.max(arr[i * 2], arr[i * 2 + 1]);
}
return arr2;
};
function ResizeArrAvg(arr)
{
var arr2 = [];
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 = MAX_STAT_PERIOD * 2 + 2;
var IsMax;
if(Key.substr(0, 4) === "MAX:")
IsMax = true;
else
IsMax = false;
var delta = 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)
{
e && console.log(e);
});
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 = 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 = 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(DEBUG_MODE)
global.TO_DEBUG_LOG = function (Str,type,data1,data2)
{
if(!DEBUG_MODE)
return ;
if(type === "rinfo")
Str += " from: " + data1.address + ':' + data1.port + ' - ' + data2.length;
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 = 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(e,t)
function SaveToLogFileSync(fname,Str)
{
try
{
var r = GetStrTime() + " : " + t + "\r\n", o = fs.openSync(e, "a");
fs.writeSync(o, r, null, "utf8"), fs.closeSync(o);
var StrLog = GetStrTime() + " : " + Str + "\r\n";
var file_handle = fs.openSync(fname, "a");
fs.writeSync(file_handle, StrLog, null, 'utf8');
fs.closeSync(file_handle);
}
catch(e)
catch(err)
{
console.log(e.message);
console.log(err.message);
}
};
global.PrepareStatEverySecond = function ()
{
CurStatIndex++;
var e = GetCurrentStatIndex();
CopyStatInterval(CONTEXT_STATS, e), CopyStatInterval(CONTEXT_ERRORS, e);
}, 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);
var l = e + ":" + t;
ToError(" ==ERROR== " + l + " " + r), AddToStatContext(CONTEXT_ERRORS, l), ADD_TO_STAT("ERRORS");
}, global.HASH_RATE = 0, global.ADD_HASH_RATE = function (e)
{
e /= 1e6, global.HASH_RATE += e, 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;
ADD_TO_STAT(e, n);
}
}, global.ADD_TO_STAT = function (e,t,r)
{
if(global.STAT_MODE)
{
if(r && 2 !== global.STAT_MODE)
return ;
AddToStatContext(CONTEXT_STATS, e, t);
}
}, global.GET_STATDIAGRAMS = function (e)
{
GetCurrentTime();
var t = GetCurrentStatIndex();
if(!e || !e.length)
return [];
for(var r = [], o = 0; o < e.length; o++)
{
var n = e[o], a = GetDiagramData(CONTEXT_STATS, n);
r.push({name:n, maxindex:t, arr:a, starttime:StartStatTime - 0, steptime:1});
}
var l = void 0;
for(o = 0; o < r.length; o++)
{
0 < (T = r[o].arr).length && (void 0 === l || T.length < l) && (l = T.length);
}
for(o = 0; o < r.length; o++)
{
var i = r[o], T = i.arr;
l && T.length > l && (T = T.slice(T.length - l)), l && 0 <= ",POWER_MY_WIN,POWER_BLOCKCHAIN,".indexOf("," + i.name + ",") && (T = SERVER.GetStatBlockchain(i.name,
l));
for(var g = 0, S = 0; S < T.length; S++)
T[S] && (g += T[S]);
0 < T.length && (g /= T.length);
var _ = 1;
if("MAX:" === i.name.substr(0, 4))
for(; 500 <= T.length; )
T = ResizeArrMax(T), _ *= 2;
else
for(; 500 <= T.length; )
T = ResizeArrAvg(T), _ *= 2;
i.AvgValue = g, i.steptime = _, i.arr = T.slice(1);
}
return r;
}, global.GET_STATS = function (e)
{
var t = GetCurrentTime(), r = GetCurrentStatIndex();
return {stats:{Counter:CONTEXT_STATS.Total, Counter10S:CalcInterval(CONTEXT_STATS, r, 10), Counter10M:CalcInterval(CONTEXT_STATS,
r, 600)}, errors:{Counter:CONTEXT_ERRORS.Total, Counter10S:CalcInterval(CONTEXT_ERRORS, r, 10), Counter10M:CalcInterval(CONTEXT_ERRORS,
r, 600)}, period:(t - StartStatTime) / 1e3, Confirmation:[]};
}, global.StartCommonStat = function ()
{
for(var e in CONTEXT_STATS.Total)
return ;
ClearCommonStat();
}, global.ClearCommonStat = function ()
{
StartStatTime = void (CurStatIndex = 0), CONTEXT_STATS = {Total:{}, Interval:[]}, CONTEXT_ERRORS = {Total:{}, Interval:[]},
global.HASH_RATE = 0, SERVER.ClearStat();
}, global.ResizeArrAvg = ResizeArrAvg, global.ResizeArrMax = ResizeArrMax, DEBUG_MODE ? global.TO_DEBUG_LOG = function (e,t,r,o)
{
DEBUG_MODE && ("rinfo" === t && (e += " from: " + r.address + ":" + r.port + " - " + o.length), ToLog(e));
} : global.TO_DEBUG_LOG = function (e,t,r,o)
{
}, global.GetStrOnlyTime = function (e)
global.GetStrOnlyTime = function (now)
{
if(!global.GetCurrentTime)
return ":::";
var t = "" + (e = e || GetCurrentTime()).getHours().toStringZ(2);
return t = (t = (t = t + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
}, global.GetStrTime = function (e)
if(!now)
now = 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 ":::";
var t = "" + (e = e || GetCurrentTime()).getDate().toStringZ(2);
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);
if(!now)
now = 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;
};

View File

@ -9,65 +9,108 @@
*/
function DoRest(r,t,e)
function DoRest(RestData,Data,BlockNum)
{
var u = r.Arr[0], o = Math.floor(e / REST_BLOCK_SCALE);
if(o !== Math.floor((u.BlockNum - 1) / REST_BLOCK_SCALE))
var Prev = RestData.Arr[0];
var BlockNum0 = Math.floor(BlockNum / REST_BLOCK_SCALE);
if(BlockNum0 !== Math.floor((Prev.BlockNum - 1) / REST_BLOCK_SCALE))
{
for(var n = GetRestArr(o), l = [], a = n.length - 2; 0 <= a; a--)
l.push(n[a] * REST_BLOCK_SCALE);
RestPush(r, l, e, 1);
var arr = GetRestArr(BlockNum0);
var arr2 = [];
for(var i = arr.length - 2; i >= 0; i--)
{
arr2.push(arr[i] * 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)
function RestPush(RestData,ArrRest,BlockNum,Index)
{
var o = r.Arr[u - 1], n = r.Arr[u];
if(1 < u)
var Prev = RestData.Arr[Index - 1];
var Cur = RestData.Arr[Index];
if(Index > 1)
{
var l = t[u - 2];
if(o.BlockNum > l)
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)
function GetRestArr(CurBlockNum)
{
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 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 a = t[l];
if(t[l] = n, n = a, 0 == ((o = o << 4 | 15) & u))
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 = GetCurrentBlockNumByTime(), t = Math.floor(r / REST_BLOCK_SCALE), e = RestArrMap[t];
if(void 0 === e)
var BlockNum = GetCurrentBlockNumByTime();
var BlockNum0 = Math.floor(BlockNum / REST_BLOCK_SCALE);
var arr = RestArrMap[BlockNum0];
if(arr === undefined)
{
RestArrMap = {}, (e = GetRestArr(t)).length = e.length - 1;
for(var u = 0; u < e.length; u++)
e[u] = e[u] * REST_BLOCK_SCALE;
RestArrMap[t] = e;
RestArrMap = {};
arr = GetRestArr(BlockNum0);
arr.length = arr.length - 1;
for(var i = 0; i < arr.length; i++)
{
arr[i] = arr[i] * REST_BLOCK_SCALE;
}
RestArrMap[BlockNum0] = arr;
}
return e;
return arr;
};
function GetCurrentRestNum(r)
function GetCurrentRestNum(NumDelta)
{
for(var t = GetCurrentBlockNumByTime() - r, e = GetCurrentRestArr(), u = e.length - 1; 0 <= u; u--)
if(e[u] <= t)
return e[u];
var BlockNum = 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.GetCurrentRestNum = GetCurrentRestNum;
global.DoRest = DoRest;
global.GetRestArr = GetRestArr;
global.GetCurrentRestArr = GetCurrentRestArr;
global.GetCurrentRestNum = GetCurrentRestNum;

View File

@ -9,42 +9,77 @@
*/
var fs = require("fs");
function CopyFiles(l,o,t)
global.GetDataPath = function GetDataPath(name)
{
if(fs.existsSync(l))
for(var e = fs.readdirSync(l), n = 0; n < e.length; n++)
if(global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) !== "/")
global.DATA_PATH = global.DATA_PATH + "/";
return 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 GetNormalPathString(global.CODE_PATH + name);
};
global.GetNormalPathString = function (Str)
{
return Str.split("\\").join('/');
};
global.CheckCreateDir = function (Path,bHidden,IsFile)
{
Path = GetNormalPathString(Path);
if(!fs.existsSync(Path))
{
if(!bHidden)
console.log("Create: " + Path);
var arr = Path.split('/');
var CurPath = arr[0];
if(IsFile)
{
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
arr.length--;
}
for(var i = 1; i < arr.length; i++)
{
CurPath += "/" + arr[i];
if(!fs.existsSync(CurPath))
{
var r = fs.readFileSync(a), i = fs.openSync(s, "w");
fs.writeSync(i, r, 0, r.length), fs.closeSync(i);
fs.mkdirSync(CurPath);
}
}
};
global.GetDataPath = function (l)
{
return "/" !== global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) && (global.DATA_PATH = global.DATA_PATH + "/"), 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 + "/"), GetNormalPathString(global.CODE_PATH + l);
}, global.GetNormalPathString = function (l)
{
return l.split("\\").join("/");
}, global.CheckCreateDir = function (l,o,t)
{
if(l = 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)
};
global.CopyFiles = CopyFiles;
function CopyFiles(FromPath,ToPath,bRecursive)
{
console.log(l);
});
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);
};

View File

@ -8,49 +8,37 @@
* Telegram: https://t.me/terafoundation
*/
global.PROCESS_NAME = "POW", global.POWPROCESS = 1, require("../core/library"), require("../core/crypto-library"), require("../core/terahashmining");
global.PROCESS_NAME = "POW";
global.POWPROCESS = 1;
require("../core/library");
require("../core/crypto-library");
require("../core/terahashmining");
var PROCESS = process;
process.send && !global.DEBUGPROCESS ? process.send({cmd:"online", message:"OK"}) : PROCESS = global.DEBUGPROCESS;
if(process.send && !global.DEBUGPROCESS)
{
process.send({cmd:"online", message:"OK"});
}
else
{
PROCESS = global.DEBUGPROCESS;
}
var LastAlive = Date.now();
setInterval(CheckAlive, 1e3);
var idInterval = void 0, Block = {};
function CheckAlive()
setInterval(CheckAlive, 1000);
var idInterval = undefined;
var Block = {};
PROCESS.on('message', function (msg)
{
if(!global.NOALIVE)
LastAlive = Date.now();
if(msg.cmd === "FastCalcBlock")
{
var e = Date.now() - LastAlive;
Math.abs(e) > CHECK_STOP_CHILD_PROCESS && PROCESS.exit(0);
}
};
function CalcPOWHash()
{
if(Block.SeqHash)
{
if(new Date - Block.Time > Block.Period)
return clearInterval(idInterval), void (idInterval = void 0);
var FastBlock = msg;
StartHashPump(FastBlock);
FastBlock.RunCount = 0;
try
{
CreatePOWVersionX(Block) && process.send({cmd:"POW", BlockNum:Block.BlockNum, SeqHash:Block.SeqHash, Hash:Block.Hash, PowHash:Block.PowHash,
AddrHash:Block.AddrHash, Num:Block.Num});
}
catch(e)
{
ToError(e);
}
}
};
PROCESS.on("message", function (e)
{
if(LastAlive = Date.now(), "FastCalcBlock" === e.cmd)
{
var o = e;
StartHashPump(o), o.RunCount = 0;
try
{
CreatePOWVersionX(o) && process.send({cmd:"POW", BlockNum:o.BlockNum, SeqHash:o.SeqHash, Hash:o.Hash, PowHash:o.PowHash, AddrHash:o.AddrHash,
Num:o.Num});
if(CreatePOWVersionX(FastBlock))
process.send({cmd:"POW", BlockNum:FastBlock.BlockNum, SeqHash:FastBlock.SeqHash, Hash:FastBlock.Hash, PowHash:FastBlock.PowHash,
AddrHash:FastBlock.AddrHash, Num:FastBlock.Num});
}
catch(e)
{
@ -58,40 +46,113 @@ PROCESS.on("message", function (e)
}
}
else
if("SetBlock" === e.cmd)
if(msg.cmd === "SetBlock")
{
var a = 1e6 * (1 + e.Num);
Block.HashCount && process.send({cmd:"HASHRATE", CountNonce:Block.HashCount, Hash:Block.Hash}), Block.HashCount = 0, (Block = e).Time = Date.now(),
Block.LastNonce = a, Block.Period = CONSENSUS_PERIOD_TIME * Block.Percent / 100, 0 < Block.Period && 0 < Block.RunPeriod && (CalcPOWHash(),
void 0 !== idInterval && clearInterval(idInterval), idInterval = setInterval(CalcPOWHash, Block.RunPeriod));
var StartNonce = 1000000 * (1 + msg.Num);
if(Block.HashCount)
{
process.send({cmd:"HASHRATE", CountNonce:Block.HashCount, Hash:Block.Hash});
}
Block.HashCount = 0;
Block = msg;
Block.Time = Date.now();
Block.LastNonce = StartNonce;
Block.Period = CONSENSUS_PERIOD_TIME * Block.Percent / 100;
if(Block.Period > 0 && Block.RunPeriod > 0)
{
CalcPOWHash();
if(idInterval !== undefined)
{
clearInterval(idInterval);
}
idInterval = setInterval(CalcPOWHash, Block.RunPeriod);
}
}
else
"Alive" === e.cmd || "Exit" === e.cmd && PROCESS.exit(0);
if(msg.cmd === "Alive")
{
}
else
if(msg.cmd === "Exit")
{
PROCESS.exit(0);
}
});
var idIntervalPump = global.BlockPump = void 0;
function StartHashPump(e)
function CheckAlive()
{
(!BlockPump || BlockPump.BlockNum < e.BlockNum || BlockPump.MinerID !== e.MinerID || BlockPump.Percent !== e.Percent) && (global.BlockPump = {BlockNum:e.BlockNum,
RunCount:e.RunCount, MinerID:e.MinerID, Percent:e.Percent, LastNonce:0}), idIntervalPump = idIntervalPump || setInterval(PumpHash,
global.POWRunPeriod);
if(global.NOALIVE)
return ;
var Delta = Date.now() - LastAlive;
if(Math.abs(Delta) > CHECK_STOP_CHILD_PROCESS)
{
PROCESS.exit(0);
return ;
}
};
var StartTime = 1, EndTime = 0;
function CalcPOWHash()
{
if(!Block.SeqHash)
return ;
if(new Date() - Block.Time > Block.Period)
{
clearInterval(idInterval);
idInterval = undefined;
return ;
}
try
{
if(CreatePOWVersionX(Block))
process.send({cmd:"POW", BlockNum:Block.BlockNum, SeqHash:Block.SeqHash, Hash:Block.Hash, PowHash:Block.PowHash, AddrHash:Block.AddrHash,
Num:Block.Num});
}
catch(e)
{
ToError(e);
}
};
global.BlockPump = undefined;
var idIntervalPump = undefined;
function StartHashPump(SetBlock)
{
if(!BlockPump || BlockPump.BlockNum < SetBlock.BlockNum || BlockPump.MinerID !== SetBlock.MinerID || BlockPump.Percent !== SetBlock.Percent)
{
global.BlockPump = {BlockNum:SetBlock.BlockNum, RunCount:SetBlock.RunCount, MinerID:SetBlock.MinerID, Percent:SetBlock.Percent,
LastNonce:0, };
}
if(!idIntervalPump)
{
idIntervalPump = setInterval(PumpHash, global.POWRunPeriod);
}
};
var StartTime = 1;
var EndTime = 0;
function PumpHash()
{
if(BlockPump)
if(!BlockPump)
return ;
var CurTime = Date.now();
if(StartTime > EndTime)
{
var e = Date.now();
if(EndTime < StartTime)
var Delta = CurTime - StartTime;
var PeriodPercent = 100 * Delta / CONSENSUS_PERIOD_TIME;
if(PeriodPercent >= BlockPump.Percent)
{
if(100 * (e - StartTime) / CONSENSUS_PERIOD_TIME >= BlockPump.Percent)
return void (EndTime = e);
CreatePOWVersionX(BlockPump, 1);
EndTime = CurTime;
return ;
}
else
CreatePOWVersionX(BlockPump, 1);
}
else
{
var Delta = CurTime - EndTime;
var PeriodPercent = 100 * Delta / CONSENSUS_PERIOD_TIME;
if(PeriodPercent > 100 - BlockPump.Percent)
{
100 * (e - EndTime) / CONSENSUS_PERIOD_TIME > 100 - BlockPump.Percent && (StartTime = e);
StartTime = CurTime;
}
}
};

View File

@ -274,7 +274,8 @@ function GETREST(msg)
var Tree = GetRestMerkleTree(BlockNumRest, RestIndexArr);
if(CompareArr(Data.AccHash, Tree.Root) !== 0)
{
ToLog("Get bad rest acc hash: " + BlockNumRest + " = " + GetHexFromArr(Data.AccHash) + "/" + GetHexFromArr(Tree.Root), 2);
ToLog("Get bad rest acc hash: " + BlockNumRest + " = " + GetHexFromArr(Data.AccHash).substr(0, 8) + "/" + GetHexFromArr(Tree.Root).substr(0,
8), 2);
ArrRest = [];
nResult = 0;
}

View File

@ -296,10 +296,15 @@ function RunListenServer()
bWasRun = 1;
});
};
var SiteFolder = GetNormalPathString("./SITE");
if(!fs.existsSync(SiteFolder))
if(global.HTTP_START_PAGE)
IndexName = global.HTTP_START_PAGE;
else
{
IndexName = "web-wallet.html";
var SiteFolder = GetNormalPathString("./SITE");
if(!fs.existsSync(SiteFolder))
{
IndexName = "web-wallet.html";
}
}
var LangPathMap = {};
LangPathMap["ru"] = 1;