1
0
forked from circlecloud/tera

update HTML file...

This commit is contained in:
MiaoWoo 2019-07-13 09:26:12 +08:00
parent 1225f4b2f5
commit 5fd017eaf1
44 changed files with 17847 additions and 19887 deletions

17
a.sh
View File

@ -1,17 +0,0 @@
#!/bin/bash
EXT=js
DIST=ts
for name in `ls *.${EXT}`; do
mv $name ${name%.${EXT}}.${DIST}
done
: Function;
global.
: any
as any
BlockNumDB
BlockNumDBMin
UseTruncateBlockDB
ContextSendLoadToBegin

View File

@ -2532,10 +2532,6 @@ td.hash {
} }
.pointer
{
cursor: pointer;
}
.nodapp .editdapp .nodapp .editdapp
{ {
@ -2742,3 +2738,18 @@ th.minwidth
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
iframe
{
left:0;
top: 0px;
width: 100%;
height: 97vh;
border: 0;
}
.pointer,.olink
{
cursor: pointer;
}

View File

@ -10,16 +10,20 @@
const ipcRenderer = require('electron').ipcRenderer; const ipcRenderer = require('electron').ipcRenderer;
function GetDataElectron(Method, ObjPost, Func) { function GetDataElectron(Method,ObjPost,Func)
if (Func === undefined) { {
if(Func === undefined)
{
Func = ObjPost; Func = ObjPost;
ObjPost = null; ObjPost = null;
} }
var reply; var reply;
try { try
{
reply = ipcRenderer.sendSync('GetData', {path:Method, obj:ObjPost}); reply = ipcRenderer.sendSync('GetData', {path:Method, obj:ObjPost});
} }
catch (e) { catch(e)
{
reply = undefined; reply = undefined;
} }
if(Func) if(Func)

File diff suppressed because it is too large Load Diff

View File

@ -11,63 +11,75 @@
var MAX_SUM_TER = 1e9; var MAX_SUM_TER = 1e9;
var MAX_SUM_CENT = 1e9; var MAX_SUM_CENT = 1e9;
function ADD(Coin, Value2) { function ADD(Coin,Value2)
{
Coin.SumCOIN += Value2.SumCOIN; Coin.SumCOIN += Value2.SumCOIN;
Coin.SumCENT += Value2.SumCENT; Coin.SumCENT += Value2.SumCENT;
if (Coin.SumCENT >= MAX_SUM_CENT) { if(Coin.SumCENT >= MAX_SUM_CENT)
{
Coin.SumCENT -= MAX_SUM_CENT; Coin.SumCENT -= MAX_SUM_CENT;
Coin.SumCOIN++; Coin.SumCOIN++;
} }
return true; return true;
}; };
function SUB(Coin, Value2) { function SUB(Coin,Value2)
{
Coin.SumCOIN -= Value2.SumCOIN; Coin.SumCOIN -= Value2.SumCOIN;
if (Coin.SumCENT >= Value2.SumCENT) { if(Coin.SumCENT >= Value2.SumCENT)
{
Coin.SumCENT -= Value2.SumCENT; Coin.SumCENT -= Value2.SumCENT;
} }
else { else
{
Coin.SumCENT = MAX_SUM_CENT + Coin.SumCENT - Value2.SumCENT; Coin.SumCENT = MAX_SUM_CENT + Coin.SumCENT - Value2.SumCENT;
Coin.SumCOIN--; Coin.SumCOIN--;
} }
if (Coin.SumCOIN < 0) { if(Coin.SumCOIN < 0)
{
return false; return false;
} }
return true; return true;
}; };
function DIV(Coin, Value) { function DIV(Coin,Value)
{
Coin.SumCOIN = Coin.SumCOIN / Value; Coin.SumCOIN = Coin.SumCOIN / Value;
Coin.SumCENT = Math.floor(Coin.SumCENT / Value); Coin.SumCENT = Math.floor(Coin.SumCENT / Value);
var SumCOIN = Math.floor(Coin.SumCOIN); var SumCOIN = Math.floor(Coin.SumCOIN);
var SumCENT = Math.floor((Coin.SumCOIN - SumCOIN) * MAX_SUM_CENT); var SumCENT = Math.floor((Coin.SumCOIN - SumCOIN) * MAX_SUM_CENT);
Coin.SumCOIN = SumCOIN; Coin.SumCOIN = SumCOIN;
Coin.SumCENT = Coin.SumCENT + SumCENT; Coin.SumCENT = Coin.SumCENT + SumCENT;
if (Coin.SumCENT >= MAX_SUM_CENT) { if(Coin.SumCENT >= MAX_SUM_CENT)
{
Coin.SumCENT -= MAX_SUM_CENT; Coin.SumCENT -= MAX_SUM_CENT;
Coin.SumCOIN++; Coin.SumCOIN++;
} }
return true; return true;
}; };
function FLOAT_FROM_COIN(Coin) { function FLOAT_FROM_COIN(Coin)
{
var Sum = Coin.SumCOIN + Coin.SumCENT / MAX_SUM_CENT; var Sum = Coin.SumCOIN + Coin.SumCENT / MAX_SUM_CENT;
return Sum; return Sum;
}; };
function STRING_FROM_COIN(Coin) { function STRING_FROM_COIN(Coin)
{
var Sum = FLOAT_FROM_COIN(Coin); var Sum = FLOAT_FROM_COIN(Coin);
return Sum.toLocaleString(undefined, {useGrouping:true, style:'decimal', maximumFractionDigits:9}); return Sum.toLocaleString(undefined, {useGrouping:true, style:'decimal', maximumFractionDigits:9});
}; };
function COIN_FROM_FLOAT(Sum) { function COIN_FROM_FLOAT(Sum)
{
var SumCOIN = Math.floor(Sum); var SumCOIN = Math.floor(Sum);
var SumCENT = Math.floor((Sum - SumCOIN) * MAX_SUM_CENT); var SumCENT = Math.floor((Sum - SumCOIN) * MAX_SUM_CENT);
var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT}; var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT};
return Coin; return Coin;
}; };
function COIN_FROM_FLOAT2(Sum) { function COIN_FROM_FLOAT2(Sum)
{
var SumCOIN = Math.floor(Sum); var SumCOIN = Math.floor(Sum);
var SumCENT = Math.floor(Sum * MAX_SUM_CENT - SumCOIN * MAX_SUM_CENT); var SumCENT = Math.floor(Sum * MAX_SUM_CENT - SumCOIN * MAX_SUM_CENT);
var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT}; var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT};
@ -76,17 +88,20 @@ function COIN_FROM_FLOAT2(Sum) {
if(typeof window === "object") if(typeof window === "object")
window.COIN_FROM_FLOAT = COIN_FROM_FLOAT2; window.COIN_FROM_FLOAT = COIN_FROM_FLOAT2;
function ISZERO(Coin) { function ISZERO(Coin)
{
if(Coin.SumCOIN === 0 && Coin.SumCENT === 0) if(Coin.SumCOIN === 0 && Coin.SumCENT === 0)
return true; return true;
else else
return false; return false;
}; };
function COIN_FROM_STRING(Str) { function COIN_FROM_STRING(Str)
{
throw "TODO: COIN_FROM_STRING"; throw "TODO: COIN_FROM_STRING";
}; };
if (typeof global === "object") { if(typeof global === "object")
{
global.ADD = ADD; global.ADD = ADD;
global.SUB = SUB; global.SUB = SUB;
global.DIV = DIV; global.DIV = DIV;

View File

@ -11,7 +11,8 @@
var MAX_SUPER_VALUE_POW = (1 << 30) * 2; var MAX_SUPER_VALUE_POW = (1 << 30) * 2;
window.TYPE_TRANSACTION_CREATE = 100; window.TYPE_TRANSACTION_CREATE = 100;
function GetHashWithValues(hash0, value1, value2, bNotCopy) { function GetHashWithValues(hash0,value1,value2,bNotCopy)
{
var hash; var hash;
if(bNotCopy) if(bNotCopy)
hash = hash0; hash = hash0;
@ -29,14 +30,20 @@ function GetHashWithValues(hash0, value1, value2, bNotCopy) {
return arrhash; return arrhash;
}; };
function GetPowPower(arrhash) { function GetPowPower(arrhash)
{
var SumBit = 0; var SumBit = 0;
for (var i = 0; i < arrhash.length; i++) { for(var i = 0; i < arrhash.length; i++)
{
var byte = arrhash[i]; var byte = arrhash[i];
for (var b = 7; b >= 0; b--) { for(var b = 7; b >= 0; b--)
if ((byte >> b) & 1) { {
if((byte >> b) & 1)
{
return SumBit; return SumBit;
} else { }
else
{
SumBit++; SumBit++;
} }
} }
@ -44,14 +51,16 @@ function GetPowPower(arrhash) {
return SumBit; return SumBit;
}; };
function GetPowValue(arrhash) { function GetPowValue(arrhash)
{
var value = (arrhash[0] << 23) * 2 + (arrhash[1] << 16) + (arrhash[2] << 8) + arrhash[3]; var value = (arrhash[0] << 23) * 2 + (arrhash[1] << 16) + (arrhash[2] << 8) + arrhash[3];
value = value * 256 + arrhash[4]; value = value * 256 + arrhash[4];
value = value * 256 + arrhash[5]; value = value * 256 + arrhash[5];
return value; return value;
}; };
function CreateNoncePOWExtern(arr0, BlockNum, count, startnone) { function CreateNoncePOWExtern(arr0,BlockNum,count,startnone)
{
var arr = []; var arr = [];
for(var i = 0; i < arr0.length; i++) for(var i = 0; i < arr0.length; i++)
arr[i] = arr0[i]; arr[i] = arr0[i];
@ -59,10 +68,12 @@ function CreateNoncePOWExtern(arr0, BlockNum, count, startnone) {
startnone = 0; startnone = 0;
var maxnonce = 0; var maxnonce = 0;
var supervalue = MAX_SUPER_VALUE_POW; var supervalue = MAX_SUPER_VALUE_POW;
for (var nonce = startnone; nonce <= startnone + count; nonce++) { for(var nonce = startnone; nonce <= startnone + count; nonce++)
{
var arrhash = GetHashWithValues(arr, nonce, BlockNum, true); var arrhash = GetHashWithValues(arr, nonce, BlockNum, true);
var value = GetPowValue(arrhash); var value = GetPowValue(arrhash);
if (value < supervalue) { if(value < supervalue)
{
maxnonce = nonce; maxnonce = nonce;
supervalue = value; supervalue = value;
} }
@ -71,7 +82,8 @@ function CreateNoncePOWExtern(arr0, BlockNum, count, startnone) {
}; };
window.TR_TICKET_HASH_LENGTH = 10; window.TR_TICKET_HASH_LENGTH = 10;
function CreateHashBody(body, Num, Nonce) { function CreateHashBody(body,Num,Nonce)
{
var length = body.length - 12; var length = body.length - 12;
body[length + 0] = Num & 0xFF; body[length + 0] = Num & 0xFF;
body[length + 1] = (Num >>> 8) & 0xFF; body[length + 1] = (Num >>> 8) & 0xFF;
@ -99,7 +111,8 @@ window.MIN_POWER_POW_TR = 0;
window.CONSENSUS_PERIOD_TIME = 1000; window.CONSENSUS_PERIOD_TIME = 1000;
window.FIRST_TIME_BLOCK = 1530446400000; window.FIRST_TIME_BLOCK = 1530446400000;
window.NEW_SIGN_TIME = 25500000; window.NEW_SIGN_TIME = 25500000;
window.SetBlockChainConstant = function(Data) { window.SetBlockChainConstant = function (Data)
{
var DeltaServerClient = new Date() - Data.CurTime; var DeltaServerClient = new Date() - Data.CurTime;
if(!Data.DELTA_CURRENT_TIME) if(!Data.DELTA_CURRENT_TIME)
Data.DELTA_CURRENT_TIME = 0; Data.DELTA_CURRENT_TIME = 0;
@ -108,7 +121,8 @@ window.SetBlockChainConstant = function(Data) {
window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK; window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK;
window.NEW_SIGN_TIME = Data.NEW_SIGN_TIME; window.NEW_SIGN_TIME = Data.NEW_SIGN_TIME;
window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME; window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME;
window.GetCurrentBlockNumByTime = function() { window.GetCurrentBlockNumByTime = function ()
{
var CurrentTime = Date.now() + DELTA_CURRENT_TIME2; var CurrentTime = Date.now() + DELTA_CURRENT_TIME2;
var CurTimeNum = CurrentTime - FIRST_TIME_BLOCK; var CurTimeNum = CurrentTime - FIRST_TIME_BLOCK;
var StartBlockNum = Math.floor((CurTimeNum + CONSENSUS_PERIOD_TIME) / CONSENSUS_PERIOD_TIME); var StartBlockNum = Math.floor((CurTimeNum + CONSENSUS_PERIOD_TIME) / CONSENSUS_PERIOD_TIME);
@ -116,13 +130,16 @@ window.SetBlockChainConstant = function(Data) {
}; };
window.NWMODE = Data.NWMODE; window.NWMODE = Data.NWMODE;
}; };
window.GetCurrentBlockNumByTime = function() { window.GetCurrentBlockNumByTime = function ()
{
return 0; return 0;
}; };
function GetBlockNumTr(arr) { function GetBlockNumTr(arr)
{
var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime(); var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
if (arr[0] === TYPE_TRANSACTION_CREATE) { if(arr[0] === TYPE_TRANSACTION_CREATE)
{
var BlockNum2 = Math.floor(BlockNum / 10) * 10; var BlockNum2 = Math.floor(BlockNum / 10) * 10;
if(BlockNum2 < BlockNum) if(BlockNum2 < BlockNum)
BlockNum2 = BlockNum2 + 10; BlockNum2 = BlockNum2 + 10;
@ -134,20 +151,26 @@ var LastCreatePOWTrType = 0;
var LastCreatePOWBlockNum = 0; var LastCreatePOWBlockNum = 0;
var LastCreatePOWHash = [255, 255, 255, 255]; var LastCreatePOWHash = [255, 255, 255, 255];
function CreateHashBodyPOWInnerMinPower(arr, MinPow, startnonce) { function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
{
var TrType = arr[0]; var TrType = arr[0];
var BlockNum = GetBlockNumTr(arr); var BlockNum = GetBlockNumTr(arr);
if (MinPow === undefined) { if(MinPow === undefined)
{
MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128); MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128);
} }
var nonce = startnonce; var nonce = startnonce;
while (1) { while(1)
{
var arrhash = CreateHashBody(arr, BlockNum, nonce); var arrhash = CreateHashBody(arr, BlockNum, nonce);
var power = GetPowPower(arrhash); var power = GetPowPower(arrhash);
if (power >= MinPow) { if(power >= MinPow)
if (LastCreatePOWBlockNum === BlockNum && LastCreatePOWTrType === TrType && CompareArr(LastCreatePOWHash, arrhash) > 0) { {
if(LastCreatePOWBlockNum === BlockNum && LastCreatePOWTrType === TrType && CompareArr(LastCreatePOWHash, arrhash) > 0)
{
} }
else { else
{
LastCreatePOWBlockNum = BlockNum; LastCreatePOWBlockNum = BlockNum;
LastCreatePOWTrType = TrType; LastCreatePOWTrType = TrType;
LastCreatePOWHash = arrhash; LastCreatePOWHash = arrhash;
@ -155,17 +178,20 @@ function CreateHashBodyPOWInnerMinPower(arr, MinPow, startnonce) {
} }
} }
nonce++; nonce++;
if (nonce % 2000 === 0) { if(nonce % 2000 === 0)
{
BlockNum = GetBlockNumTr(arr); BlockNum = GetBlockNumTr(arr);
} }
} }
}; };
function CalcHashFromArray(ArrHashes, bOriginalSeq) { function CalcHashFromArray(ArrHashes,bOriginalSeq)
{
if(bOriginalSeq === undefined) if(bOriginalSeq === undefined)
ArrHashes.sort(CompareArr); ArrHashes.sort(CompareArr);
var Buf = []; var Buf = [];
for (var i = 0; i < ArrHashes.length; i++) { for(var i = 0; i < ArrHashes.length; i++)
{
var Value = ArrHashes[i]; var Value = ArrHashes[i];
for(var n = 0; n < Value.length; n++) for(var n = 0; n < Value.length; n++)
Buf.push(Value[n]); Buf.push(Value[n]);
@ -179,7 +205,8 @@ function CalcHashFromArray(ArrHashes, bOriginalSeq) {
return Hash; return Hash;
}; };
function GetArrFromValue(Num) { function GetArrFromValue(Num)
{
var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
arr[0] = Num & 0xFF; arr[0] = Num & 0xFF;
arr[1] = (Num >>> 8) & 0xFF; arr[1] = (Num >>> 8) & 0xFF;
@ -191,42 +218,52 @@ function GetArrFromValue(Num) {
return arr; return arr;
}; };
function LoadLib(Path) { function LoadLib(Path)
{
var item = document.createElement('script'); var item = document.createElement('script');
item.type = "text/javascript"; item.type = "text/javascript";
item.src = Path; item.src = Path;
document.getElementsByTagName('head')[0].appendChild(item); document.getElementsByTagName('head')[0].appendChild(item);
}; };
function IsMS() { function IsMS()
{
var ua = window.navigator.userAgent; var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE "); var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { if(msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
return 1; return 1;
} }
else { else
{
return 0; return 0;
} }
}; };
function LoadSignLib() { function LoadSignLib()
{
if(window.SignLib) if(window.SignLib)
return ; return ;
LoadLib("./JS/sign-lib-min.js"); LoadLib("./JS/sign-lib-min.js");
}; };
function ComputeSecretWithCheck(PubKey, StrPrivKey, F) { function ComputeSecretWithCheck(PubKey,StrPrivKey,F)
if (!window.SignLib) { {
if(!window.SignLib)
{
SetError("Error - SignLib not installed"); SetError("Error - SignLib not installed");
return ; return ;
} }
if (!IsHexStr(StrPrivKey) || StrPrivKey.length !== 64) { if(!IsHexStr(StrPrivKey) || StrPrivKey.length !== 64)
{
SetError("Error set PrivKey"); SetError("Error set PrivKey");
return ; return ;
} }
var PrivKey = Buffer.from(GetArrFromHex(StrPrivKey)); var PrivKey = Buffer.from(GetArrFromHex(StrPrivKey));
if (typeof PubKey === "string") { if(typeof PubKey === "string")
if (!IsHexStr(PubKey) || PubKey.length !== 66) { {
if(!IsHexStr(PubKey) || PubKey.length !== 66)
{
SetError("Error PubKey"); SetError("Error PubKey");
return ; return ;
} }
@ -236,12 +273,16 @@ function ComputeSecretWithCheck(PubKey, StrPrivKey, F) {
F(sha3(Result)); F(sha3(Result));
}; };
function ComputeSecret(Account, PubKey, F) { function ComputeSecret(Account,PubKey,F)
if (GetPrivKey()) { {
if(GetPrivKey())
{
ComputeSecretWithCheck(PubKey, GetPrivKey(), F); ComputeSecretWithCheck(PubKey, GetPrivKey(), F);
} }
else { else
GetData("GetWalletInfo", { Account: Account }, function(Data) { {
GetData("GetWalletInfo", {Account:Account}, function (Data)
{
if(!Data || !Data.result) if(!Data || !Data.result)
return ; return ;
ComputeSecretWithCheck(PubKey, Data.PrivateKey, F); ComputeSecretWithCheck(PubKey, Data.PrivateKey, F);
@ -249,13 +290,15 @@ function ComputeSecret(Account, PubKey, F) {
} }
}; };
function Encrypt(ArrSecret, StartEncrypt, StrName, StrValue) { function Encrypt(ArrSecret,StartEncrypt,StrName,StrValue)
{
var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt)); var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt));
var Arr = toUTF8Array(StrValue); var Arr = toUTF8Array(StrValue);
return DoSecret(Arr, arrRnd); return DoSecret(Arr, arrRnd);
}; };
function Decrypt(ArrSecret, StartEncrypt, StrName, Arr) { function Decrypt(ArrSecret,StartEncrypt,StrName,Arr)
{
if(!ArrSecret) if(!ArrSecret)
return "".padEnd(Arr.length / 2, "."); return "".padEnd(Arr.length / 2, ".");
if(typeof Arr === "string") if(typeof Arr === "string")
@ -266,15 +309,18 @@ function Decrypt(ArrSecret, StartEncrypt, StrName, Arr) {
return Str; return Str;
}; };
function DoSecret(Arr, arrRnd) { function DoSecret(Arr,arrRnd)
{
var Arr2 = []; var Arr2 = [];
var CryptID = 0; var CryptID = 0;
var Pos = 0; var Pos = 0;
while (Pos < Arr.length) { while(Pos < Arr.length)
{
CryptID++; CryptID++;
WriteUintToArrOnPos(arrRnd, CryptID, 0); WriteUintToArrOnPos(arrRnd, CryptID, 0);
var CurBuf = sha3(arrRnd); var CurBuf = sha3(arrRnd);
for (var i = 0; i < 32 && Pos < Arr.length; i++ , Pos++) { for(var i = 0; i < 32 && Pos < Arr.length; i++, Pos++)
{
Arr2[Pos] = Arr[Pos] ^ CurBuf[i]; Arr2[Pos] = Arr[Pos] ^ CurBuf[i];
} }
} }
@ -282,22 +328,26 @@ function DoSecret(Arr, arrRnd) {
}; };
var glEncryptInit = 0; var glEncryptInit = 0;
function EncryptInit() { function EncryptInit()
{
glEncryptInit++; glEncryptInit++;
var Time = Date.now() - new Date(2019, 0, 1); var Time = Date.now() - new Date(2019, 0, 1);
return Math.floor(Time * 100 + Math.random() * 100) * 100 + glEncryptInit; return Math.floor(Time * 100 + Math.random() * 100) * 100 + glEncryptInit;
}; };
function EncryptID(ArrSecret, StartEncrypt, id) { function EncryptID(ArrSecret,StartEncrypt,id)
{
var Value = $(id).value; var Value = $(id).value;
Value = Value.padEnd(Value.length + random(5), " "); Value = Value.padEnd(Value.length + random(5), " ");
return GetHexFromArr(Encrypt(ArrSecret, StartEncrypt, id, Value)); return GetHexFromArr(Encrypt(ArrSecret, StartEncrypt, id, Value));
}; };
function EncryptFields(ArrSecret, Params, ArrName) { function EncryptFields(ArrSecret,Params,ArrName)
{
if(!Params.Crypto) if(!Params.Crypto)
Params.Crypto = EncryptInit(); Params.Crypto = EncryptInit();
for (var i = 0; i < ArrName.length; i++) { for(var i = 0; i < ArrName.length; i++)
{
var Name = ArrName[i]; var Name = ArrName[i];
var Value = Params[Name]; var Value = Params[Name];
Value = Value.padEnd(Value.length + random(5), " "); Value = Value.padEnd(Value.length + random(5), " ");
@ -305,13 +355,17 @@ function EncryptFields(ArrSecret, Params, ArrName) {
} }
}; };
function DecryptFields(ArrSecret, Params, ArrName) { function DecryptFields(ArrSecret,Params,ArrName)
for (var i = 0; i < ArrName.length; i++) { {
for(var i = 0; i < ArrName.length; i++)
{
var Name = ArrName[i]; var Name = ArrName[i];
if (Params[Name]) { if(Params[Name])
{
Params[Name] = Decrypt(ArrSecret, Params.Crypto, Name, GetArrFromHex(Params[Name])); Params[Name] = Decrypt(ArrSecret, Params.Crypto, Name, GetArrFromHex(Params[Name]));
} }
else { else
{
Params[Name] = ""; Params[Name] = "";
} }
} }

View File

@ -9,43 +9,52 @@
*/ */
function SendPay(Data) { function SendPay(Data)
{
Data.cmd = "pay"; Data.cmd = "pay";
SendData(Data); SendData(Data);
}; };
function SetStorage(Key, Value) { function SetStorage(Key,Value)
{
var Data = {cmd:"setstorage", Key:Key, Value:Value}; var Data = {cmd:"setstorage", Key:Key, Value:Value};
SendData(Data); SendData(Data);
}; };
function GetStorage(Key, F) { function GetStorage(Key,F)
{
var Data = {cmd:"getstorage", Key:Key}; var Data = {cmd:"getstorage", Key:Key};
SendData(Data, F); SendData(Data, F);
}; };
function SetCommon(Key, Value) { function SetCommon(Key,Value)
{
var Data = {cmd:"setcommon", Key:Key, Value:Value}; var Data = {cmd:"setcommon", Key:Key, Value:Value};
SendData(Data); SendData(Data);
}; };
function GetCommon(Key, F) { function GetCommon(Key,F)
{
var Data = {cmd:"getcommon", Key:Key}; var Data = {cmd:"getcommon", Key:Key};
SendData(Data, F); SendData(Data, F);
}; };
function GetInfo(F, bUseCache) { function GetInfo(F,bUseCache)
{
var Data = {cmd:"DappInfo", AllAccounts:ALL_ACCOUNTS, AllData:!bUseCache}; var Data = {cmd:"DappInfo", AllAccounts:ALL_ACCOUNTS, AllData:!bUseCache};
SendData(Data, F); SendData(Data, F);
}; };
function Call(Account, MethodName, Params, F) { function Call(Account,MethodName,Params,F)
{
var Data = {cmd:"DappCall", MethodName:MethodName, Params:Params, Account:Account}; var Data = {cmd:"DappCall", MethodName:MethodName, Params:Params, Account:Account};
SendData(Data, F); SendData(Data, F);
}; };
function SendCall(Account, MethodName, Params, FromNum) { function SendCall(Account,MethodName,Params,FromNum)
if (!INFO.WalletCanSign) { {
if(!INFO.WalletCanSign)
{
SetError("Pls, open wallet"); SetError("Pls, open wallet");
return 0; return 0;
} }
@ -54,100 +63,125 @@ function SendCall(Account, MethodName, Params, FromNum) {
return 1; return 1;
}; };
function GetWalletAccounts(F) { function GetWalletAccounts(F)
{
var Data = {cmd:"DappWalletList"}; var Data = {cmd:"DappWalletList"};
SendData(Data, F); SendData(Data, F);
}; };
function GetAccountList(Params, F) { function GetAccountList(Params,F)
{
var Data = {cmd:"DappAccountList", Params:Params}; var Data = {cmd:"DappAccountList", Params:Params};
SendData(Data, F); SendData(Data, F);
}; };
function GetSmartList(Params, F) { function GetSmartList(Params,F)
{
var Data = {cmd:"DappSmartList", Params:Params}; var Data = {cmd:"DappSmartList", Params:Params};
SendData(Data, F); SendData(Data, F);
}; };
function GetBlockList(Params, F) { function GetBlockList(Params,F)
{
var Data = {cmd:"DappBlockList", Params:Params}; var Data = {cmd:"DappBlockList", Params:Params};
SendData(Data, F); SendData(Data, F);
}; };
function GetTransactionList(Params, F) { function GetTransactionList(Params,F)
{
var Data = {cmd:"DappTransactionList", Params:Params}; var Data = {cmd:"DappTransactionList", Params:Params};
SendData(Data, F); SendData(Data, F);
}; };
function DappSmartHTMLFile(Smart, F) { function DappSmartHTMLFile(Smart,F)
{
var Data = {cmd:"DappSmartHTMLFile", Params:{Smart:Smart}}; var Data = {cmd:"DappSmartHTMLFile", Params:{Smart:Smart}};
SendData(Data, F); SendData(Data, F);
}; };
function DappBlockFile(BlockNum, TrNum, F) { function DappBlockFile(BlockNum,TrNum,F)
{
var Data = {cmd:"DappBlockFile", Params:{BlockNum:BlockNum, TrNum:TrNum}}; var Data = {cmd:"DappBlockFile", Params:{BlockNum:BlockNum, TrNum:TrNum}};
SendData(Data, F); SendData(Data, F);
}; };
function SetStatus(Str) { function SetStatus(Str)
{
SendData({cmd:"SetStatus", Message:Str}); SendData({cmd:"SetStatus", Message:Str});
}; };
function SetError(Str) { function SetError(Str)
{
SendData({cmd:"SetError", Message:Str}); SendData({cmd:"SetError", Message:Str});
}; };
function SetLocationPath(Str) { function SetLocationPath(Str)
{
SendData({cmd:"SetLocationHash", Message:Str}); SendData({cmd:"SetLocationHash", Message:Str});
}; };
function CreateNewAccount(Currency) { function CreateNewAccount(Currency)
{
SendData({cmd:"CreateNewAccount", Currency:Currency}); SendData({cmd:"CreateNewAccount", Currency:Currency});
}; };
function OpenLink(Str) { function OpenLink(Str)
{
SendData({cmd:"OpenLink", Message:Str}); SendData({cmd:"OpenLink", Message:Str});
}; };
function SetMobileMode() { function SetMobileMode()
{
SendData({cmd:"SetMobileMode"}); SendData({cmd:"SetMobileMode"});
}; };
function ComputeSecret(PubKey, F, Account) { function ComputeSecret(PubKey,F,Account)
if (!INFO.WalletCanSign) { {
if(!INFO.WalletCanSign)
{
SetError("Pls, open wallet"); SetError("Pls, open wallet");
return 0; return 0;
} }
if(!Account && USER_ACCOUNT.length) if(!Account && USER_ACCOUNT.length)
Account = USER_ACCOUNT[0].Num; Account = USER_ACCOUNT[0].Num;
if (typeof PubKey === "number") { if(typeof PubKey === "number")
{
var AccNum = PubKey; var AccNum = PubKey;
GetAccountList({ StartNum: AccNum, CountNum: 1 }, function(Err, Arr) { GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
if (Err) { {
if(Err)
{
SetError(Err); SetError(Err);
} }
else { else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:Arr[0].PubKey.data}, F); SendData({cmd:"ComputeSecret", Account:Account, PubKey:Arr[0].PubKey.data}, F);
} }
}); });
} }
else { else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:PubKey}, F); SendData({cmd:"ComputeSecret", Account:Account, PubKey:PubKey}, F);
} }
}; };
function CheckInstall() { function CheckInstall()
{
SendData({cmd:"CheckInstall"}); SendData({cmd:"CheckInstall"});
}; };
function SendTransaction(Body, TR, SumPow, F) { function SendTransaction(Body,TR,SumPow,F)
{
SetError("Cannt SEND TR: " + JSON.stringify(TR)); SetError("Cannt SEND TR: " + JSON.stringify(TR));
}; };
function CurrencyName(Num) { function CurrencyName(Num)
{
var Name = MapCurrency[Num]; var Name = MapCurrency[Num];
if (!Name) { if(!Name)
GetSmartList({ StartNum: Num, CountNum: 1, TokenGenerate: 1 }, function(Err, Arr) { {
GetSmartList({StartNum:Num, CountNum:1, TokenGenerate:1}, function (Err,Arr)
{
if(Err || Arr.length === 0) if(Err || Arr.length === 0)
return ; return ;
var Smart = Arr[0]; var Smart = Arr[0];
@ -160,15 +194,19 @@ function CurrencyName(Num) {
}; };
var SendCountUpdate = 0; var SendCountUpdate = 0;
function FindAllCurrency() { function FindAllCurrency()
{
SendCountUpdate++; SendCountUpdate++;
GetSmartList({ StartNum: 8, CountNum: 100, TokenGenerate: 1 }, function(Err, Arr) { GetSmartList({StartNum:8, CountNum:100, TokenGenerate:1}, function (Err,Arr)
{
SendCountUpdate--; SendCountUpdate--;
if(Err) if(Err)
return ; return ;
for (var i = 0; i < Arr.length; i++) { for(var i = 0; i < Arr.length; i++)
{
var Smart = Arr[i]; var Smart = Arr[i];
if (!MapCurrency[Smart.Num]) { if(!MapCurrency[Smart.Num])
{
var Name = GetTokenName(Smart.Num, Smart.ShortName); var Name = GetTokenName(Smart.Num, Smart.ShortName);
MapCurrency[Smart.Num] = Name; MapCurrency[Smart.Num] = Name;
} }
@ -176,8 +214,10 @@ function FindAllCurrency() {
}); });
}; };
function GetFilePath(Path) { function GetFilePath(Path)
if (window.PROTOCOL_SERVER_PATH && Path.indexOf("file/")) { {
if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/"))
{
if(Path.substr(0, 1) !== "/") if(Path.substr(0, 1) !== "/")
Path = "/" + Path; Path = "/" + Path;
Path = window.PROTOCOL_SERVER_PATH + Path; Path = window.PROTOCOL_SERVER_PATH + Path;
@ -185,29 +225,37 @@ function GetFilePath(Path) {
return Path; return Path;
}; };
function GetParamsFromPath(Name) { function GetParamsFromPath(Name)
{
if(!OPEN_PATH) if(!OPEN_PATH)
return undefined; return undefined;
var arr = OPEN_PATH.split("&"); var arr = OPEN_PATH.split("&");
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
if (arr[i].indexOf(Name + "=") === 0) { {
if(arr[i].indexOf(Name + "=") === 0)
{
return arr[i].split("=")[1]; return arr[i].split("=")[1];
} }
} }
}; };
function GetState(AccNum, F, FErr) { function GetState(AccNum,F,FErr)
{
SendCountUpdate++; SendCountUpdate++;
GetAccountList({ StartNum: AccNum, CountNum: 1 }, function(Err, Arr) { GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
{
SendCountUpdate--; SendCountUpdate--;
if (!Err && Arr.length) { if(!Err && Arr.length)
{
var Item = Arr[0].SmartState; var Item = Arr[0].SmartState;
if (Item) { if(Item)
{
F(Item); F(Item);
return ; return ;
} }
} }
if (FErr) { if(FErr)
{
FErr(); FErr();
return ; return ;
} }
@ -216,10 +264,12 @@ function GetState(AccNum, F, FErr) {
var glMapF = {}; var glMapF = {};
var glKeyF = 0; var glKeyF = 0;
function SendData(Data, F) { function SendData(Data,F)
{
if(!window.parent) if(!window.parent)
return ; return ;
if (F) { if(F)
{
glKeyF++; glKeyF++;
Data.CallID = glKeyF; Data.CallID = glKeyF;
glMapF[glKeyF] = F; glMapF[glKeyF] = F;
@ -227,18 +277,22 @@ function SendData(Data, F) {
window.parent.postMessage(Data, "*"); window.parent.postMessage(Data, "*");
}; };
function OnMessage(event) { function OnMessage(event)
{
var Data = event.data; var Data = event.data;
if(!Data || typeof Data !== "object") if(!Data || typeof Data !== "object")
return ; return ;
var CallID = Data.CallID; var CallID = Data.CallID;
var cmd = Data.cmd; var cmd = Data.cmd;
if (CallID) { if(CallID)
{
var F = glMapF[CallID]; var F = glMapF[CallID];
if (F) { if(F)
{
delete Data.CallID; delete Data.CallID;
delete Data.cmd; delete Data.cmd;
switch (cmd) { switch(cmd)
{
case "getstorage": case "getstorage":
case "getcommon": case "getcommon":
F(Data.Key, Data.Value); F(Data.Key, Data.Value);
@ -269,14 +323,17 @@ function OnMessage(event) {
delete glMapF[CallID]; delete glMapF[CallID];
} }
} }
else { else
switch (cmd) { {
switch(cmd)
{
case "History": case "History":
var eventEvent = new CustomEvent("History", {detail:Data}); var eventEvent = new CustomEvent("History", {detail:Data});
window.dispatchEvent(eventEvent); window.dispatchEvent(eventEvent);
break; break;
case "OnEvent": case "OnEvent":
if (window.OnEvent) { if(window.OnEvent)
{
window.OnEvent(Data); window.OnEvent(Data);
} }
var eventEvent = new CustomEvent("Event", {detail:Data}); var eventEvent = new CustomEvent("Event", {detail:Data});
@ -285,23 +342,29 @@ function OnMessage(event) {
} }
}; };
function OpenRefFile(Str) { function OpenRefFile(Str)
{
var Param = ParseFileName(Str); var Param = ParseFileName(Str);
if(Param.BlockNum) if(Param.BlockNum)
DappBlockFile(Param.BlockNum, Param.TrNum, function(Err, Body) { DappBlockFile(Param.BlockNum, Param.TrNum, function (Err,Body)
{
document.write(Body); document.write(Body);
}); });
else { else
{
OpenLink(Str); OpenLink(Str);
} }
}; };
function SaveToStorageByArr(Arr) { function SaveToStorageByArr(Arr)
{
SetStorage("VerSave", "1"); SetStorage("VerSave", "1");
for (var i = 0; i < Arr.length; i++) { for(var i = 0; i < Arr.length; i++)
{
var name = Arr[i]; var name = Arr[i];
var Item = $(name); var Item = $(name);
if (Item) { if(Item)
{
if(Item.type === "checkbox") if(Item.type === "checkbox")
SetStorage(name, 0 + Item.checked); SetStorage(name, 0 + Item.checked);
else else
@ -310,10 +373,14 @@ function SaveToStorageByArr(Arr) {
} }
}; };
function LoadFromStorageByArr(Arr, F, bAll) { function LoadFromStorageByArr(Arr,F,bAll)
GetStorage("VerSave", function(Key, Value) { {
if (Value === "1") { GetStorage("VerSave", function (Key,Value)
for (var i = 0; i < Arr.length; i++) { {
if(Value === "1")
{
for(var i = 0; i < Arr.length; i++)
{
if(i === Arr.length - 1) if(i === Arr.length - 1)
LoadFromStorageById(Arr[i], F); LoadFromStorageById(Arr[i], F);
else else
@ -325,10 +392,13 @@ function LoadFromStorageByArr(Arr, F, bAll) {
}); });
}; };
function LoadFromStorageById(Name, F) { function LoadFromStorageById(Name,F)
GetStorage(Name, function(Key, Value) { {
GetStorage(Name, function (Key,Value)
{
var Item = document.getElementById(Name); var Item = document.getElementById(Name);
if (Item) { if(Item)
{
if(Item.type === "checkbox") if(Item.type === "checkbox")
Item.checked = parseInt(Value); Item.checked = parseInt(Value);
else else
@ -340,22 +410,29 @@ function LoadFromStorageById(Name, F) {
}; };
var SendCountDappParams = 0; var SendCountDappParams = 0;
function GetDappParams(BNum, TrNum, F, bAll) { function GetDappParams(BNum,TrNum,F,bAll)
if (!BNum) { {
if(!BNum)
{
if(bAll) if(bAll)
F(); F();
return ; return ;
} }
SendCountDappParams++; SendCountDappParams++;
DappBlockFile(BNum, TrNum, function(Err, Data) { DappBlockFile(BNum, TrNum, function (Err,Data)
{
SendCountDappParams--; SendCountDappParams--;
if (!Err && Data.Type === 135) { if(!Err && Data.Type === 135)
try { {
try
{
var Params = JSON.parse(Data.Params); var Params = JSON.parse(Data.Params);
} }
catch (e) { catch(e)
{
} }
if (Params) { if(Params)
{
F(Params, Data.MethodName, Data.FromNum); F(Params, Data.MethodName, Data.FromNum);
return ; return ;
} }
@ -364,20 +441,26 @@ function GetDappParams(BNum, TrNum, F, bAll) {
F(); F();
}); });
}; };
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function ()
{
var refs = document.getElementsByTagName("A"); var refs = document.getElementsByTagName("A");
for (var i = 0, L = refs.length; i < L; i++) { for(var i = 0, L = refs.length; i < L; i++)
if (refs[i].href.indexOf("/file/") >= 0) { {
refs[i].onclick = function() { if(refs[i].href.indexOf("/file/") >= 0)
{
refs[i].onclick = function ()
{
OpenRefFile(this.href); OpenRefFile(this.href);
}; };
} }
} }
}); });
if (window.addEventListener) { if(window.addEventListener)
{
window.addEventListener("message", OnMessage); window.addEventListener("message", OnMessage);
} }
else { else
{
window.attachEvent("onmessage", OnMessage); window.attachEvent("onmessage", OnMessage);
} }
var SMART = {}, BASE_ACCOUNT = {}, INFO = {}, USER_ACCOUNT = [], USER_ACCOUNT_MAP = {}, OPEN_PATH = "", ACCOUNT_OPEN_NUM = 0; var SMART = {}, BASE_ACCOUNT = {}, INFO = {}, USER_ACCOUNT = [], USER_ACCOUNT_MAP = {}, OPEN_PATH = "", ACCOUNT_OPEN_NUM = 0;
@ -385,9 +468,12 @@ var ALL_ACCOUNTS = 0;
var WasStartInit = 0, WasStartInit2 = 0; var WasStartInit = 0, WasStartInit2 = 0;
var eventInfo = new Event("UpdateInfo"); var eventInfo = new Event("UpdateInfo");
function UpdateDappInfo() { function UpdateDappInfo()
GetInfo(function(Err, Data) { {
if (Err) { GetInfo(function (Err,Data)
{
if(Err)
{
return ; return ;
} }
INFO = Data; INFO = Data;
@ -400,29 +486,34 @@ function UpdateDappInfo() {
USER_ACCOUNT_MAP = {}; USER_ACCOUNT_MAP = {};
for(var i = 0; i < USER_ACCOUNT.length; i++) for(var i = 0; i < USER_ACCOUNT.length; i++)
USER_ACCOUNT_MAP[USER_ACCOUNT[i].Num] = USER_ACCOUNT[i]; USER_ACCOUNT_MAP[USER_ACCOUNT[i].Num] = USER_ACCOUNT[i];
if (window.OnInit && !WasStartInit) { if(window.OnInit && !WasStartInit)
{
WasStartInit = 1; WasStartInit = 1;
window.OnInit(1); window.OnInit(1);
} }
else else
if (window.OnUpdateInfo) { if(window.OnUpdateInfo)
{
window.OnUpdateInfo(); window.OnUpdateInfo();
} }
if (!WasStartInit2) { if(!WasStartInit2)
{
WasStartInit2 = 1; WasStartInit2 = 1;
var eventInit = new Event("Init"); var eventInit = new Event("Init");
window.dispatchEvent(eventInit); window.dispatchEvent(eventInit);
} }
window.dispatchEvent(eventInfo); window.dispatchEvent(eventInfo);
if(Data.ArrEvent) if(Data.ArrEvent)
for (var i = 0; i < Data.ArrEvent.length; i++) { for(var i = 0; i < Data.ArrEvent.length; i++)
{
var Item = Data.ArrEvent[i]; var Item = Data.ArrEvent[i];
Item.cmd = "OnEvent"; Item.cmd = "OnEvent";
OnMessage({data:Item}); OnMessage({data:Item});
} }
}, 1); }, 1);
}; };
window.addEventListener('load', function() { window.addEventListener('load', function ()
{
if(!window.sha3) if(!window.sha3)
LoadLib("./JS/sha3.js"); LoadLib("./JS/sha3.js");
UpdateDappInfo(); UpdateDappInfo();

View File

@ -12,18 +12,21 @@ var DiagramMap = {};
var DiagramMapId = {}; var DiagramMapId = {};
var LMouseOn = false; var LMouseOn = false;
if(!window.toStaticHTML) if(!window.toStaticHTML)
toStaticHTML = function(Str) { toStaticHTML = function (Str)
{
return Str; return Str;
}; };
function Rigth(Str, Count) { function Rigth(Str,Count)
{
if(Str.length < Count) if(Str.length < Count)
return Str; return Str;
else else
return Str.substr(Str.length - Count); return Str.substr(Str.length - Count);
}; };
function SetHTMLDiagramItem(Item, width) { function SetHTMLDiagramItem(Item,width)
{
Item.mouseX = width - 50; Item.mouseX = width - 50;
if(Item.Extern || Item.Delete) if(Item.Extern || Item.Delete)
return ; return ;
@ -32,46 +35,56 @@ function SetHTMLDiagramItem(Item, width) {
Item.id = "DgrmId" + Item.num; Item.id = "DgrmId" + Item.num;
DiagramMap[Item.name] = Item; DiagramMap[Item.name] = Item;
DiagramMapId[Item.id] = Item; DiagramMapId[Item.id] = Item;
if (Item.isLine) { if(Item.isLine)
{
if(Item.text) if(Item.text)
Str = "<BR><B>" + Item.text + '</B><INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X">'; Str = "<BR><B>" + Item.text + '</B><INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X">';
else else
Str = "<HR>"; Str = "<HR>";
} }
else { else
{
Str = '<BR><DIV>' + Item.text + '<INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X"></DIV>\ Str = '<BR><DIV>' + Item.text + '<INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X"></DIV>\
<BR><canvas class="DIAGRAM" width="' + width + '" height="' + MinHeight + '" id="' + Item.id + '"></canvas>'; <BR><canvas class="DIAGRAM" width="' + width + '" height="' + MinHeight + '" id="' + Item.id + '"></canvas>';
} }
var ElBlock = document.getElementById("B" + Item.id); var ElBlock = document.getElementById("B" + Item.id);
if(ElBlock) if(ElBlock)
ElBlock.innerHTML = toStaticHTML(Str); ElBlock.innerHTML = toStaticHTML(Str);
else { else
{
var diargams = document.getElementById("diargams"); var diargams = document.getElementById("diargams");
diargams.innerHTML = toStaticHTML(diargams.innerHTML + "<DIV id='B" + Item.id + "'>" + Str + "</DIV>"); diargams.innerHTML = toStaticHTML(diargams.innerHTML + "<DIV id='B" + Item.id + "'>" + Str + "</DIV>");
} }
}; };
function SetDiagramMouseX(event, mode) { function SetDiagramMouseX(event,mode)
if (event.srcElement && event.srcElement.className && event.srcElement.className.indexOf && event.srcElement.className.indexOf("DIAGRAM") >= 0) { {
if(event.srcElement && event.srcElement.className && event.srcElement.className.indexOf && event.srcElement.className.indexOf("DIAGRAM") >= 0)
{
if(mode === "down") if(mode === "down")
LMouseOn = true; LMouseOn = true;
else else
if(mode === "up") if(mode === "up")
LMouseOn = false; LMouseOn = false;
event.preventDefault(); event.preventDefault();
if (LMouseOn === true) { if(LMouseOn === true)
{
var obj = event.srcElement; var obj = event.srcElement;
var mouse = getMouse(obj, event); var mouse = getMouse(obj, event);
if (event.ctrlKey === true) { if(event.ctrlKey === true)
for (var key in DiagramMapId) { {
for(var key in DiagramMapId)
{
var Item = DiagramMapId[key]; var Item = DiagramMapId[key];
Item.mouseX = mouse.x; Item.mouseX = mouse.x;
DrawDiagram(Item); DrawDiagram(Item);
} }
} }
else { else
{
var Item = DiagramMapId[obj.id]; var Item = DiagramMapId[obj.id];
if (Item) { if(Item)
{
Item.mouseX = mouse.x; Item.mouseX = mouse.x;
DrawDiagram(Item); DrawDiagram(Item);
} }
@ -80,7 +93,8 @@ function SetDiagramMouseX(event, mode) {
} }
}; };
function DrawDiagram(Item) { function DrawDiagram(Item)
{
if(Item.Delete) if(Item.Delete)
return ; return ;
var arr = Item.arr; var arr = Item.arr;
@ -116,7 +130,8 @@ function DrawDiagram(Item) {
var MaxValue = arr[0]; var MaxValue = arr[0];
var MinValue = arr[0]; var MinValue = arr[0];
var AvgValue = 0; var AvgValue = 0;
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
if(arr[i] > MaxValue) if(arr[i] > MaxValue)
MaxValue = arr[i]; MaxValue = arr[i];
if(arr[i] < MinValue) if(arr[i] < MinValue)
@ -145,7 +160,8 @@ function DrawDiagram(Item) {
var KY = (obj.height - Top - Button) / HValue; var KY = (obj.height - Top - Button) / HValue;
var DeltaY = 0; var DeltaY = 0;
var bLine = Item.line; var bLine = Item.line;
if (Item.zero) { if(Item.zero)
{
bLine = 1; bLine = 1;
DeltaY -= Item.zero * KY; DeltaY -= Item.zero * KY;
MaxValue -= Item.zero; MaxValue -= Item.zero;
@ -165,26 +181,31 @@ function DrawDiagram(Item) {
var mouseValue = undefined; var mouseValue = undefined;
var mouseColor = undefined; var mouseColor = undefined;
function DrawLines(arr, mode, color) { function DrawLines(arr,mode,color)
{
var WasMove0 = 0; var WasMove0 = 0;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(Left, obj.height - Button); ctx.moveTo(Left, obj.height - Button);
ctx.strokeStyle = color; ctx.strokeStyle = color;
var PrevX = undefined; var PrevX = undefined;
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
var Value = arr[i]; var Value = arr[i];
if(!Value) if(!Value)
Value = 0; Value = 0;
if (Value) { if(Value)
{
if(Pow2) if(Pow2)
Value = Math.pow(2, Value) / 1000000; Value = Math.pow(2, Value) / 1000000;
} }
if (mode === "green") { if(mode === "green")
{
if(Value > GreenValue) if(Value > GreenValue)
continue; continue;
} }
else else
if (mode === "red") { if(mode === "red")
{
if(Value <= GreenValue) if(Value <= GreenValue)
continue; continue;
} }
@ -196,23 +217,29 @@ function DrawDiagram(Item) {
if(VX1 === VX2) if(VX1 === VX2)
VX1 -= 2; VX1 -= 2;
var x = StartX + ctx.lineWidth / 2 + (i) * KX; var x = StartX + ctx.lineWidth / 2 + (i) * KX;
if (bLine) { if(bLine)
if (!WasMove0) { {
if(!WasMove0)
{
WasMove0 = 1; WasMove0 = 1;
ctx.moveTo(x, StartY - VX2); ctx.moveTo(x, StartY - VX2);
} }
else { else
{
ctx.lineTo(x, StartY - VX2); ctx.lineTo(x, StartY - VX2);
} }
} }
else { else
{
ctx.moveTo(x, StartY - VX1); ctx.moveTo(x, StartY - VX1);
ctx.lineTo(x, StartY - VX2); ctx.lineTo(x, StartY - VX2);
} }
if (mouseX) { if(mouseX)
{
var deltaCur = Math.abs(x - mouseX); var deltaCur = Math.abs(x - mouseX);
var deltaWas = Math.abs(mouseValueX - mouseX); var deltaWas = Math.abs(mouseValueX - mouseX);
if (deltaCur < deltaWas) { if(deltaCur < deltaWas)
{
mouseValueX = x; mouseValueX = x;
mouseValue = Value; mouseValue = Value;
if(Item.zero) if(Item.zero)
@ -225,10 +252,12 @@ function DrawDiagram(Item) {
}; };
if(!Item.red) if(!Item.red)
Item.red = "#A00"; Item.red = "#A00";
if (bLine) { if(bLine)
{
DrawLines(arr, "line", Item.red); DrawLines(arr, "line", Item.red);
} }
else { else
{
DrawLines(arr, "red", Item.red); DrawLines(arr, "red", Item.red);
if(GreenValue > 0) if(GreenValue > 0)
DrawLines(arr, "green", "#0A0"); DrawLines(arr, "green", "#0A0");
@ -246,14 +275,16 @@ function DrawDiagram(Item) {
ctx.moveTo(StartX, StartY + DeltaY); ctx.moveTo(StartX, StartY + DeltaY);
ctx.lineTo(obj.width - 10, StartY + DeltaY); ctx.lineTo(obj.width - 10, StartY + DeltaY);
ctx.stroke(); ctx.stroke();
if (mouseX !== undefined) { if(mouseX !== undefined)
{
ctx.beginPath(); ctx.beginPath();
ctx.lineWidth = 0.5; ctx.lineWidth = 0.5;
ctx.strokeStyle = "#00F"; ctx.strokeStyle = "#00F";
ctx.moveTo(mouseX, Top); ctx.moveTo(mouseX, Top);
ctx.lineTo(mouseX, StartY); ctx.lineTo(mouseX, StartY);
ctx.stroke(); ctx.stroke();
if (mouseValue !== undefined) { if(mouseValue !== undefined)
{
ctx.fillStyle = mouseColor; ctx.fillStyle = mouseColor;
var Val = GetValueByItemProperty(mouseValue, Item); var Val = GetValueByItemProperty(mouseValue, Item);
var mouseTextX = mouseX; var mouseTextX = mouseX;
@ -267,12 +298,14 @@ function DrawDiagram(Item) {
ctx.fillStyle = "#000"; ctx.fillStyle = "#000";
if(!Item.NoTextMax) if(!Item.NoTextMax)
ctx.fillText(Rigth("" + MaxValueText, 8), 0, Top - 3); ctx.fillText(Rigth("" + MaxValueText, 8), 0, Top - 3);
if (MaxValue > 0 && AvgValue > 0) { if(MaxValue > 0 && AvgValue > 0)
{
var heigh = StartY - Top; var heigh = StartY - Top;
var KKY = AvgValue / MaxValue; var KKY = AvgValue / MaxValue;
var y = (heigh - Math.floor(KKY * heigh)); var y = (heigh - Math.floor(KKY * heigh));
var yT = y; var yT = y;
if (yT < 10) { if(yT < 10)
{
yT = 10; yT = 10;
} }
ctx.beginPath(); ctx.beginPath();
@ -289,15 +322,18 @@ function DrawDiagram(Item) {
var KDelitel = 1; var KDelitel = 1;
var Step = arr.length / CountNameX; var Step = arr.length / CountNameX;
var StartTime, bNumber; var StartTime, bNumber;
if (arrX) { if(arrX)
{
} }
else else
if (StartNumber !== undefined) { if(StartNumber !== undefined)
{
bNumber = 1; bNumber = 1;
StartTime = StartNumber; StartTime = StartNumber;
} }
else else
if (StartServer) { if(StartServer)
{
bNumber = 1; bNumber = 1;
StartTime = Math.floor(((Date.now() - StartServer) - StepTime * arr.length * 1000) / 1000); StartTime = Math.floor(((Date.now() - StartServer) - StepTime * arr.length * 1000) / 1000);
if(StartTime < 0) if(StartTime < 0)
@ -306,14 +342,17 @@ function DrawDiagram(Item) {
if(KDelitel == 0) if(KDelitel == 0)
KDelitel = 1; KDelitel = 1;
} }
else { else
{
bNumber = 0; bNumber = 0;
StartTime = Date.now() - StepTime * arr.length * 1000; StartTime = Date.now() - StepTime * arr.length * 1000;
StartX = StartX - 16; StartX = StartX - 16;
} }
for (i = 0; i <= CountNameX; i++) { for(i = 0; i <= CountNameX; i++)
{
var Val; var Val;
if (i === CountNameX) { if(i === CountNameX)
{
Val = arr.length * StepTime; Val = arr.length * StepTime;
KDelitel = 1; KDelitel = 1;
} }
@ -323,18 +362,21 @@ function DrawDiagram(Item) {
else else
Val = i * Step * StepTime; Val = i * Step * StepTime;
var Str; var Str;
if (arrX) { if(arrX)
{
Val = Math.floor(Val); Val = Math.floor(Val);
Str = arrX[Val]; Str = arrX[Val];
if(Str === undefined) if(Str === undefined)
Str = ""; Str = "";
} }
else else
if (bNumber) { if(bNumber)
{
Val = Math.floor((StartTime + Val) / KDelitel) * KDelitel; Val = Math.floor((StartTime + Val) / KDelitel) * KDelitel;
Str = Val; Str = Val;
} }
else { else
{
var Time = new Date(StartTime + Val * 1000); var Time = new Date(StartTime + Val * 1000);
Str = "" + Time.getHours(); Str = "" + Time.getHours();
Str += ":" + Rigth("0" + Time.getMinutes(), 2); Str += ":" + Rigth("0" + Time.getMinutes(), 2);
@ -344,8 +386,10 @@ function DrawDiagram(Item) {
} }
}; };
function GetValueByItemProperty(Value, Item) { function GetValueByItemProperty(Value,Item)
if (Item.MathPow && Item.MathDiv) { {
if(Item.MathPow && Item.MathDiv)
{
Value = Math.pow(Item.MathPow, Value) / Item.MathDiv; Value = Math.pow(Item.MathPow, Value) / Item.MathDiv;
} }
var KPrecision = Item.KPrecision; var KPrecision = Item.KPrecision;
@ -355,23 +399,29 @@ function GetValueByItemProperty(Value, Item) {
return Value; return Value;
}; };
function InitDiagramByArr(Arr, width) { function InitDiagramByArr(Arr,width)
for (var i = 0; i < Arr.length; i++) { {
for(var i = 0; i < Arr.length; i++)
{
Arr[i].num = i + 1; Arr[i].num = i + 1;
SetHTMLDiagramItem(Arr[i], width); SetHTMLDiagramItem(Arr[i], width);
} }
window.addEventListener('mousedown', function(event) { window.addEventListener('mousedown', function (event)
{
SetDiagramMouseX(event, "down"); SetDiagramMouseX(event, "down");
}, false); }, false);
window.addEventListener('mouseup', function(event) { window.addEventListener('mouseup', function (event)
{
SetDiagramMouseX(event, "up"); SetDiagramMouseX(event, "up");
}, false); }, false);
window.addEventListener('onmousemove', function(event) { window.addEventListener('onmousemove', function (event)
{
SetDiagramMouseX(event, "move"); SetDiagramMouseX(event, "move");
}, false); }, false);
}; };
function getMouse(canvas, e) { function getMouse(canvas,e)
{
var x = e.clientX - getTrueOffsetLeft(canvas); var x = e.clientX - getTrueOffsetLeft(canvas);
if(window.pageXOffset) if(window.pageXOffset)
x = x + window.pageXOffset; x = x + window.pageXOffset;
@ -382,18 +432,22 @@ function getMouse(canvas, e) {
return coord; return coord;
}; };
function getTrueOffsetLeft(ele) { function getTrueOffsetLeft(ele)
{
var n = 0; var n = 0;
while (ele) { while(ele)
{
n += ele.offsetLeft || 0; n += ele.offsetLeft || 0;
ele = ele.offsetParent; ele = ele.offsetParent;
} }
return n; return n;
}; };
function getTrueOffsetTop(ele) { function getTrueOffsetTop(ele)
{
var n = 0; var n = 0;
while (ele) { while(ele)
{
n += ele.offsetTop || 0; n += ele.offsetTop || 0;
ele = ele.offsetParent; ele = ele.offsetParent;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,39 +11,48 @@
"use strict"; "use strict";
var der = require("./der"), toString = Object.prototype.toString, exports = {}, assert = exports; var der = require("./der"), toString = Object.prototype.toString, exports = {}, assert = exports;
exports.isArray = function(e, s) { exports.isArray = function (e,s)
{
if(!Array.isArray(e)) if(!Array.isArray(e))
throw TypeError(s); throw TypeError(s);
}, exports.isBoolean = function(e, s) { }, exports.isBoolean = function (e,s)
{
if("[object Boolean]" !== toString.call(e)) if("[object Boolean]" !== toString.call(e))
throw TypeError(s); throw TypeError(s);
}, exports.isBuffer = function(e, s) { }, exports.isBuffer = function (e,s)
{
if(!Buffer.isBuffer(e)) if(!Buffer.isBuffer(e))
throw TypeError(s); throw TypeError(s);
}, exports.isFunction = function(e, s) { }, exports.isFunction = function (e,s)
{
if("[object Function]" !== toString.call(e)) if("[object Function]" !== toString.call(e))
throw TypeError(s); throw TypeError(s);
}, exports.isNumber = function(e, s) { }, exports.isNumber = function (e,s)
{
if("[object Number]" !== toString.call(e)) if("[object Number]" !== toString.call(e))
throw TypeError(s); throw TypeError(s);
}, exports.isObject = function(e, s) { }, exports.isObject = function (e,s)
{
if("[object Object]" !== toString.call(e)) if("[object Object]" !== toString.call(e))
throw TypeError(s); throw TypeError(s);
}, exports.isBufferLength = function(e, s, r) { }, exports.isBufferLength = function (e,s,r)
{
if(e.length !== s) if(e.length !== s)
throw RangeError(r); throw RangeError(r);
}, exports.isBufferLength2 = function(e, s, r, _) { }, exports.isBufferLength2 = function (e,s,r,_)
{
if(e.length !== s && e.length !== r) if(e.length !== s && e.length !== r)
throw RangeError(_); throw RangeError(_);
}, exports.isLengthGTZero = function(e, s) { }, exports.isLengthGTZero = function (e,s)
{
if(0 === e.length) if(0 === e.length)
throw RangeError(s); throw RangeError(s);
}, exports.isNumberInInterval = function(e, s, r, _) { }, exports.isNumberInInterval = function (e,s,r,_)
{
if(e <= s || r <= e) if(e <= s || r <= e)
throw RangeError(_); throw RangeError(_);
}; };
var messages = { var messages = {COMPRESSED_TYPE_INVALID:"compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID:"private key should be a Buffer",
COMPRESSED_TYPE_INVALID: "compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID: "private key should be a Buffer",
EC_PRIVATE_KEY_LENGTH_INVALID:"private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID:"private key range is invalid", EC_PRIVATE_KEY_LENGTH_INVALID:"private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID:"private key range is invalid",
EC_PRIVATE_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL:"tweak out of range", EC_PRIVATE_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL:"tweak out of range",
EC_PRIVATE_KEY_EXPORT_DER_FAIL:"couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL:"couldn't import from DER format", EC_PRIVATE_KEY_EXPORT_DER_FAIL:"couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL:"couldn't import from DER format",
@ -57,104 +66,125 @@ var messages = {
MSG32_TYPE_INVALID:"message should be a Buffer", MSG32_LENGTH_INVALID:"message length is invalid", OPTIONS_TYPE_INVALID:"options should be an Object", MSG32_TYPE_INVALID:"message should be a Buffer", MSG32_LENGTH_INVALID:"message length is invalid", OPTIONS_TYPE_INVALID:"options should be an Object",
OPTIONS_DATA_TYPE_INVALID:"options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID:"options.data length is invalid", OPTIONS_DATA_TYPE_INVALID:"options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID:"options.data length is invalid",
OPTIONS_NONCEFN_TYPE_INVALID:"options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID:"recovery should be a Number", OPTIONS_NONCEFN_TYPE_INVALID:"options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID:"recovery should be a Number",
RECOVERY_ID_VALUE_INVALID: "recovery should have value between -1 and 4", TWEAK_TYPE_INVALID: "tweak should be a Buffer", TWEAK_LENGTH_INVALID: "tweak length is invalid" RECOVERY_ID_VALUE_INVALID:"recovery should have value between -1 and 4", TWEAK_TYPE_INVALID:"tweak should be a Buffer", TWEAK_LENGTH_INVALID:"tweak length is invalid"};
};
function initCompressedValue(e, s) { function initCompressedValue(e,s)
{
return void 0 === e ? s : (assert.isBoolean(e, messages.COMPRESSED_TYPE_INVALID), e); return void 0 === e ? s : (assert.isBoolean(e, messages.COMPRESSED_TYPE_INVALID), e);
}; };
module.exports = function(E) { module.exports = function (E)
return { {
privateKeyVerify: function(e) { return {privateKeyVerify:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), 32 === e.length && E.privateKeyVerify(e); return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), 32 === e.length && E.privateKeyVerify(e);
}, privateKeyExport: function(e, s) { }, privateKeyExport:function (e,s)
{
assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0); s = initCompressedValue(s, !0);
var r = E.privateKeyExport(e, s); var r = E.privateKeyExport(e, s);
return der.privateKeyExport(e, r, s); return der.privateKeyExport(e, r, s);
}, privateKeyImport: function(e) { }, privateKeyImport:function (e)
{
if(assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), (e = der.privateKeyImport(e)) && 32 === e.length && E.privateKeyVerify(e)) if(assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), (e = der.privateKeyImport(e)) && 32 === e.length && E.privateKeyVerify(e))
return e; return e;
throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL); throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL);
}, privateKeyNegate: function(e) { }, privateKeyNegate:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyNegate(e); E.privateKeyNegate(e);
}, privateKeyModInverse: function(e) { }, privateKeyModInverse:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyModInverse(e); E.privateKeyModInverse(e);
}, privateKeyTweakAdd: function(e, s) { }, privateKeyTweakAdd:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakAdd(e, assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakAdd(e,
s); s);
}, privateKeyTweakMul: function(e, s) { }, privateKeyTweakMul:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakMul(e, assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakMul(e,
s); s);
}, publicKeyCreate: function(e, s) { }, publicKeyCreate:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyCreate(e, s); s = initCompressedValue(s, !0), E.publicKeyCreate(e, s);
}, publicKeyConvert: function(e, s) { }, publicKeyConvert:function (e,s)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyConvert(e, s); s = initCompressedValue(s, !0), E.publicKeyConvert(e, s);
}, publicKeyVerify: function(e) { }, publicKeyVerify:function (e)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), E.publicKeyVerify(e); return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), E.publicKeyVerify(e);
}, publicKeyTweakAdd: function(e, s, r) { }, publicKeyTweakAdd:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r, assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakAdd(e, s, r); !0), E.publicKeyTweakAdd(e, s, r);
}, publicKeyTweakMul: function(e, s, r) { }, publicKeyTweakMul:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r, assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakMul(e, s, r); !0), E.publicKeyTweakMul(e, s, r);
}, publicKeyCombine: function(e, s) { }, publicKeyCombine:function (e,s)
{
assert.isArray(e, messages.EC_PUBLIC_KEYS_TYPE_INVALID), assert.isLengthGTZero(e, messages.EC_PUBLIC_KEYS_LENGTH_INVALID); assert.isArray(e, messages.EC_PUBLIC_KEYS_TYPE_INVALID), assert.isLengthGTZero(e, messages.EC_PUBLIC_KEYS_LENGTH_INVALID);
for(var r = 0; r < e.length; ++r) for(var r = 0; r < e.length; ++r)
assert.isBuffer(e[r], messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e[r], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID); assert.isBuffer(e[r], messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e[r], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID);
return s = initCompressedValue(s, !0), E.publicKeyCombine(e, s); return s = initCompressedValue(s, !0), E.publicKeyCombine(e, s);
}, signatureNormalize: function(e) { }, signatureNormalize:function (e)
{
return assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), return assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID),
E.signatureNormalize(e); E.signatureNormalize(e);
}, signatureExport: function(e) { }, signatureExport:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID); assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = E.signatureExport(e); var s = E.signatureExport(e);
return der.signatureExport(s); return der.signatureExport(s);
}, signatureImport: function(e) { }, signatureImport:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID); assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImport(e); var s = der.signatureImport(e);
if(s) if(s)
return E.signatureImport(s); return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL); throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, signatureImportLax: function(e) { }, signatureImportLax:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID); assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImportLax(e); var s = der.signatureImportLax(e);
if(s) if(s)
return E.signatureImport(s); return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL); throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, sign: function(e, s, r) { }, sign:function (e,s,r)
{
assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s, assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID); messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID);
var _ = null, t = null; var _ = null, t = null;
return void 0 !== r && (assert.isObject(r, messages.OPTIONS_TYPE_INVALID), void 0 !== r.data && (assert.isBuffer(r.data, messages.OPTIONS_DATA_TYPE_INVALID), return void 0 !== r && (assert.isObject(r, messages.OPTIONS_TYPE_INVALID), void 0 !== r.data && (assert.isBuffer(r.data, messages.OPTIONS_DATA_TYPE_INVALID),
assert.isBufferLength(r.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID), _ = r.data), void 0 !== r.noncefn && (assert.isFunction(r.noncefn, assert.isBufferLength(r.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID), _ = r.data), void 0 !== r.noncefn && (assert.isFunction(r.noncefn,
messages.OPTIONS_NONCEFN_TYPE_INVALID), t = r.noncefn)), E.sign(e, s, t, _); messages.OPTIONS_NONCEFN_TYPE_INVALID), t = r.noncefn)), E.sign(e, s, t, _);
}, verify: function(e, s, r) { }, verify:function (e,s,r)
{
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s, return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isBuffer(r, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isBuffer(r,
messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(r, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), E.verify(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(r, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), E.verify(e,
s, r); s, r);
}, recover: function(e, s, r, _) { }, recover:function (e,s,r,_)
{
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s, return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isNumber(r, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isNumber(r,
messages.RECOVERY_ID_TYPE_INVALID), assert.isNumberInInterval(r, - 1, 4, messages.RECOVERY_ID_VALUE_INVALID), _ = initCompressedValue(_, messages.RECOVERY_ID_TYPE_INVALID), assert.isNumberInInterval(r, - 1, 4, messages.RECOVERY_ID_VALUE_INVALID), _ = initCompressedValue(_,
!0), E.recover(e, s, r, _); !0), E.recover(e, s, r, _);
}, ecdh: function(e, s) { }, ecdh:function (e,s)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.ecdh(e, s); E.ecdh(e, s);
}, ecdhUnsafe: function(e, s, r) { }, ecdhUnsafe:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID), assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
r = initCompressedValue(r, !0), E.ecdhUnsafe(e, s, r); r = initCompressedValue(r, !0), E.ecdhUnsafe(e, s, r);
} }};
};
}, global.SIGN_LIB = module.exports; }, global.SIGN_LIB = module.exports;

View File

@ -8,14 +8,17 @@
* Telegram: https://t.me/terafoundation * Telegram: https://t.me/terafoundation
*/ */
(function() { (function ()
{
'use strict'; 'use strict';
var root = typeof window === 'object' ? window : {}; var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS && !root.RUN_NW_CLIENT) { if(NODE_JS && !root.RUN_NW_CLIENT)
{
root = global; root = global;
} }
if (root.RUN_CLIENT) { if(root.RUN_CLIENT)
{
root = window; root = window;
} }
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports; var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
@ -34,117 +37,141 @@
var SHAKE_BITS = [128, 256]; var SHAKE_BITS = [128, 256];
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array']; var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
var CSHAKE_BYTEPAD = {'128':168, '256':136}; var CSHAKE_BYTEPAD = {'128':168, '256':136};
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) { if(root.JS_SHA3_NO_NODE_JS || !Array.isArray)
Array.isArray = function(obj) { {
Array.isArray = function (obj)
{
return Object.prototype.toString.call(obj) === '[object Array]'; return Object.prototype.toString.call(obj) === '[object Array]';
}; };
} }
var createOutputMethod = function(bits, padding, outputType) { var createOutputMethod = function (bits,padding,outputType)
return function(message) { {
return function (message)
{
return new Keccak(bits, padding, bits).update(message)[outputType](); return new Keccak(bits, padding, bits).update(message)[outputType]();
}; };
}; };
var createShakeOutputMethod = function(bits, padding, outputType) { var createShakeOutputMethod = function (bits,padding,outputType)
return function(message, outputBits) { {
return function (message,outputBits)
{
return new Keccak(bits, padding, outputBits).update(message)[outputType](); return new Keccak(bits, padding, outputBits).update(message)[outputType]();
}; };
}; };
var createCshakeOutputMethod = function(bits, padding, outputType) { var createCshakeOutputMethod = function (bits,padding,outputType)
return function(message, outputBits, n, s) { {
return function (message,outputBits,n,s)
{
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType](); return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
}; };
}; };
var createKmacOutputMethod = function(bits, padding, outputType) { var createKmacOutputMethod = function (bits,padding,outputType)
return function(key, message, outputBits, s) { {
return function (key,message,outputBits,s)
{
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType](); return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
}; };
}; };
var createOutputMethods = function(method, createMethod, bits, padding) { var createOutputMethods = function (method,createMethod,bits,padding)
for (var i = 0; i < OUTPUT_TYPES.length; ++i) { {
for(var i = 0; i < OUTPUT_TYPES.length; ++i)
{
var type = OUTPUT_TYPES[i]; var type = OUTPUT_TYPES[i];
method[type] = createMethod(bits, padding, type); method[type] = createMethod(bits, padding, type);
} }
return method; return method;
}; };
var createMethod = function(bits, padding, outputs) { var createMethod = function (bits,padding,outputs)
{
var method = createOutputMethod(bits, padding, outputs); var method = createOutputMethod(bits, padding, outputs);
method.create = function() { method.create = function ()
{
return new Keccak(bits, padding, bits); return new Keccak(bits, padding, bits);
}; };
method.update = function(message) { method.update = function (message)
{
return method.create().update(message); return method.create().update(message);
}; };
return createOutputMethods(method, createOutputMethod, bits, padding); return createOutputMethods(method, createOutputMethod, bits, padding);
}; };
var createMethodArray = function(bits, padding) { var createMethodArray = function (bits,padding)
{
var method = createOutputMethod(bits, padding, 'array'); var method = createOutputMethod(bits, padding, 'array');
method.create = function() { method.create = function ()
{
return new Keccak(bits, padding, bits); return new Keccak(bits, padding, bits);
}; };
method.update = function(message) { method.update = function (message)
{
return method.create().update(message); return method.create().update(message);
}; };
return createOutputMethods(method, createOutputMethod, bits, padding); return createOutputMethods(method, createOutputMethod, bits, padding);
}; };
var createShakeMethod = function(bits, padding) { var createShakeMethod = function (bits,padding)
{
var method = createShakeOutputMethod(bits, padding, 'hex'); var method = createShakeOutputMethod(bits, padding, 'hex');
method.create = function(outputBits) { method.create = function (outputBits)
{
return new Keccak(bits, padding, outputBits); return new Keccak(bits, padding, outputBits);
}; };
method.update = function(message, outputBits) { method.update = function (message,outputBits)
{
return method.create(outputBits).update(message); return method.create(outputBits).update(message);
}; };
return createOutputMethods(method, createShakeOutputMethod, bits, padding); return createOutputMethods(method, createShakeOutputMethod, bits, padding);
}; };
var createCshakeMethod = function(bits, padding) { var createCshakeMethod = function (bits,padding)
{
var w = CSHAKE_BYTEPAD[bits]; var w = CSHAKE_BYTEPAD[bits];
var method = createCshakeOutputMethod(bits, padding, 'hex'); var method = createCshakeOutputMethod(bits, padding, 'hex');
method.create = function(outputBits, n, s) { method.create = function (outputBits,n,s)
if (!n && !s) { {
if(!n && !s)
{
return methods['shake' + bits].create(outputBits); return methods['shake' + bits].create(outputBits);
} }
else { else
{
return new Keccak(bits, padding, outputBits).bytepad([n, s], w); return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
} }
}; };
method.update = function(message, outputBits, n, s) { method.update = function (message,outputBits,n,s)
{
return method.create(outputBits, n, s).update(message); return method.create(outputBits, n, s).update(message);
}; };
return createOutputMethods(method, createCshakeOutputMethod, bits, padding); return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
}; };
var createKmacMethod = function(bits, padding) { var createKmacMethod = function (bits,padding)
{
var w = CSHAKE_BYTEPAD[bits]; var w = CSHAKE_BYTEPAD[bits];
var method = createKmacOutputMethod(bits, padding, 'hex'); var method = createKmacOutputMethod(bits, padding, 'hex');
method.create = function(key, outputBits, s) { method.create = function (key,outputBits,s)
{
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w); return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
}; };
method.update = function(key, message, outputBits, s) { method.update = function (key,message,outputBits,s)
{
return method.create(key, outputBits, s).update(message); return method.create(key, outputBits, s).update(message);
}; };
return createOutputMethods(method, createKmacOutputMethod, bits, padding); return createOutputMethods(method, createKmacOutputMethod, bits, padding);
}; };
var algorithms = [{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod }, { var algorithms = [{name:'keccak', padding:KECCAK_PADDING, bits:BITS, createMethod:createMethod}, {name:'sha3', padding:PADDING,
name: 'sha3', padding: PADDING, bits:BITS, createMethod:createMethod, outputs:'hex'}, {name:'sha3_array', padding:PADDING, bits:BITS, createMethod:createMethod,
bits: BITS, createMethod: createMethod, outputs: 'hex' outputs:'array'}, {name:'sha3_buf', padding:PADDING, bits:BITS, createMethod:createMethod, outputs:'buffer'}, {name:'shake',
}, { padding:SHAKE_PADDING, bits:SHAKE_BITS, createMethod:createShakeMethod}, {name:'cshake', padding:CSHAKE_PADDING, bits:SHAKE_BITS,
name: 'sha3_array', padding: PADDING, bits: BITS, createMethod: createMethod, createMethod:createCshakeMethod}, {name:'kmac', padding:CSHAKE_PADDING, bits:SHAKE_BITS, createMethod:createKmacMethod}];
outputs: 'array'
}, { name: 'sha3_buf', padding: PADDING, bits: BITS, createMethod: createMethod, outputs: 'buffer' }, {
name: 'shake',
padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod
}, {
name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS,
createMethod: createCshakeMethod
}, { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }];
var methods = {}, methodNames = []; var methods = {}, methodNames = [];
for (var i = 0; i < algorithms.length; ++i) { for(var i = 0; i < algorithms.length; ++i)
{
var algorithm = algorithms[i]; var algorithm = algorithms[i];
var bits = algorithm.bits; var bits = algorithm.bits;
for (var j = 0; j < bits.length; ++j) { for(var j = 0; j < bits.length; ++j)
{
var methodName = algorithm.name + '_' + bits[j]; var methodName = algorithm.name + '_' + bits[j];
methodNames.push(methodName); methodNames.push(methodName);
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding, algorithm.outputs); methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding, algorithm.outputs);
if (algorithm.name !== 'sha3') { if(algorithm.name !== 'sha3')
{
var newMethodName = algorithm.name + bits[j]; var newMethodName = algorithm.name + bits[j];
methodNames.push(newMethodName); methodNames.push(newMethodName);
methods[newMethodName] = methods[methodName]; methods[newMethodName] = methods[methodName];
@ -152,7 +179,8 @@
} }
} }
function Keccak(bits, padding, outputBits) { function Keccak(bits,padding,outputBits)
{
this.blocks = []; this.blocks = [];
this.s = []; this.s = [];
this.padding = padding; this.padding = padding;
@ -164,55 +192,71 @@
this.byteCount = this.blockCount << 2; this.byteCount = this.blockCount << 2;
this.outputBlocks = outputBits >> 5; this.outputBlocks = outputBits >> 5;
this.extraBytes = (outputBits & 31) >> 3; this.extraBytes = (outputBits & 31) >> 3;
for (var i = 0; i < 50; ++i) { for(var i = 0; i < 50; ++i)
{
this.s[i] = 0; this.s[i] = 0;
} }
}; };
Keccak.prototype.update = function(message) { Keccak.prototype.update = function (message)
{
var notString = typeof message !== 'string'; var notString = typeof message !== 'string';
if (notString && message.constructor === root.ArrayBuffer) { if(notString && message.constructor === root.ArrayBuffer)
{
TO_ERROR_LOG("SHA3", 10, 'ERROR: Error type ArrayBuffer, use Uint8Array instead!'); TO_ERROR_LOG("SHA3", 10, 'ERROR: Error type ArrayBuffer, use Uint8Array instead!');
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
} }
var length = message.length; var length = message.length;
if (notString) { if(notString)
if (typeof length !== 'number' || !Array.isArray(message) && !(ARRAY_BUFFER && ArrayBuffer.isView(message))) { {
if(typeof length !== 'number' || !Array.isArray(message) && !(ARRAY_BUFFER && ArrayBuffer.isView(message)))
{
TO_ERROR_LOG("SHA3", 20, 'ERROR: Input is invalid type, message=' + JSON.stringify(message)); TO_ERROR_LOG("SHA3", 20, 'ERROR: Input is invalid type, message=' + JSON.stringify(message));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
} }
} }
var blocks = this.blocks, byteCount = this.byteCount, blockCount = this.blockCount, index = 0, s = this.s, i, code; var blocks = this.blocks, byteCount = this.byteCount, blockCount = this.blockCount, index = 0, s = this.s, i, code;
while (index < length) { while(index < length)
if (this.reset) { {
if(this.reset)
{
this.reset = false; this.reset = false;
blocks[0] = this.block; blocks[0] = this.block;
for (i = 1; i < blockCount + 1; ++i) { for(i = 1; i < blockCount + 1; ++i)
{
blocks[i] = 0; blocks[i] = 0;
} }
} }
if (notString) { if(notString)
for (i = this.start; index < length && i < byteCount; ++index) { {
for(i = this.start; index < length && i < byteCount; ++index)
{
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
} }
} }
else { else
for (i = this.start; index < length && i < byteCount; ++index) { {
for(i = this.start; index < length && i < byteCount; ++index)
{
code = message.charCodeAt(index); code = message.charCodeAt(index);
if (code < 0x80) { if(code < 0x80)
{
blocks[i >> 2] |= code << SHIFT[i++ & 3]; blocks[i >> 2] |= code << SHIFT[i++ & 3];
} }
else else
if (code < 0x800) { if(code < 0x800)
{
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} }
else else
if (code < 0xd800 || code >= 0xe000) { if(code < 0xd800 || code >= 0xe000)
{
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} }
else { else
{
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
@ -222,73 +266,91 @@
} }
} }
this.lastByteIndex = i; this.lastByteIndex = i;
if (i >= byteCount) { if(i >= byteCount)
{
this.start = i - byteCount; this.start = i - byteCount;
this.block = blocks[blockCount]; this.block = blocks[blockCount];
for (i = 0; i < blockCount; ++i) { for(i = 0; i < blockCount; ++i)
{
s[i] ^= blocks[i]; s[i] ^= blocks[i];
} }
f(s); f(s);
this.reset = true; this.reset = true;
} }
else { else
{
this.start = i; this.start = i;
} }
} }
return this; return this;
}; };
Keccak.prototype.encode = function(x, right) { Keccak.prototype.encode = function (x,right)
{
var o = x & 255, n = 1; var o = x & 255, n = 1;
var bytes = [o]; var bytes = [o];
x = x >> 8; x = x >> 8;
o = x & 255; o = x & 255;
while (o > 0) { while(o > 0)
{
bytes.unshift(o); bytes.unshift(o);
x = x >> 8; x = x >> 8;
o = x & 255; o = x & 255;
++n; ++n;
} }
if (right) { if(right)
{
bytes.push(n); bytes.push(n);
} }
else { else
{
bytes.unshift(n); bytes.unshift(n);
} }
this.update(bytes); this.update(bytes);
return bytes.length; return bytes.length;
}; };
Keccak.prototype.encodeString = function(str) { Keccak.prototype.encodeString = function (str)
{
str = str || ''; str = str || '';
var notString = typeof str !== 'string'; var notString = typeof str !== 'string';
if (notString && str.constructor === root.ArrayBuffer) { if(notString && str.constructor === root.ArrayBuffer)
{
str = new Uint8Array(str); str = new Uint8Array(str);
} }
var length = str.length; var length = str.length;
if (notString) { if(notString)
if (typeof length !== 'number' || !Array.isArray(str) && !(ARRAY_BUFFER && ArrayBuffer.isView(str))) { {
if(typeof length !== 'number' || !Array.isArray(str) && !(ARRAY_BUFFER && ArrayBuffer.isView(str)))
{
TO_ERROR_LOG("SHA3", 30, 'ERROR: Input is invalid type, str=' + JSON.stringify(str)); TO_ERROR_LOG("SHA3", 30, 'ERROR: Input is invalid type, str=' + JSON.stringify(str));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
} }
} }
var bytes = 0; var bytes = 0;
if (notString) { if(notString)
{
bytes = length; bytes = length;
} }
else { else
for (var i = 0; i < str.length; ++i) { {
for(var i = 0; i < str.length; ++i)
{
var code = str.charCodeAt(i); var code = str.charCodeAt(i);
if (code < 0x80) { if(code < 0x80)
{
bytes += 1; bytes += 1;
} }
else else
if (code < 0x800) { if(code < 0x800)
{
bytes += 2; bytes += 2;
} }
else else
if (code < 0xd800 || code >= 0xe000) { if(code < 0xd800 || code >= 0xe000)
{
bytes += 3; bytes += 3;
} }
else { else
{
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff)); code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
bytes += 4; bytes += 4;
} }
@ -298,9 +360,11 @@
this.update(str); this.update(str);
return bytes; return bytes;
}; };
Keccak.prototype.bytepad = function(strs, w) { Keccak.prototype.bytepad = function (strs,w)
{
var bytes = this.encode(w); var bytes = this.encode(w);
for (var i = 0; i < strs.length; ++i) { for(var i = 0; i < strs.length; ++i)
{
bytes += this.encodeString(strs[i]); bytes += this.encodeString(strs[i]);
} }
var paddingBytes = w - bytes % w; var paddingBytes = w - bytes % w;
@ -309,82 +373,104 @@
this.update(zeros); this.update(zeros);
return this; return this;
}; };
Keccak.prototype.finalize = function() { Keccak.prototype.finalize = function ()
{
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3]; blocks[i >> 2] |= this.padding[i & 3];
if (this.lastByteIndex === this.byteCount) { if(this.lastByteIndex === this.byteCount)
{
blocks[0] = blocks[blockCount]; blocks[0] = blocks[blockCount];
for (i = 1; i < blockCount + 1; ++i) { for(i = 1; i < blockCount + 1; ++i)
{
blocks[i] = 0; blocks[i] = 0;
} }
} }
blocks[blockCount - 1] |= 0x80000000; blocks[blockCount - 1] |= 0x80000000;
for (i = 0; i < blockCount; ++i) { for(i = 0; i < blockCount; ++i)
{
s[i] ^= blocks[i]; s[i] ^= blocks[i];
} }
f(s); f(s);
}; };
Keccak.prototype.toString = Keccak.prototype.hex = function() { Keccak.prototype.toString = Keccak.prototype.hex = function ()
{
this.finalize(); this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0; var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var hex = '', block; var hex = '', block;
while (j < outputBlocks) { while(j < outputBlocks)
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { {
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
block = s[i]; block = s[i];
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F]; hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
} }
if (j % blockCount === 0) { if(j % blockCount === 0)
{
f(s); f(s);
i = 0; i = 0;
} }
} }
if (extraBytes) { if(extraBytes)
{
block = s[i]; block = s[i];
if (extraBytes > 0) { if(extraBytes > 0)
{
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F]; hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
} }
if (extraBytes > 1) { if(extraBytes > 1)
{
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F]; hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
} }
if (extraBytes > 2) { if(extraBytes > 2)
{
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F]; hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
} }
} }
return hex; return hex;
}; };
Keccak.prototype.arrayBuffer = function() { Keccak.prototype.arrayBuffer = function ()
{
this.finalize(); this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0; var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var bytes = this.outputBits >> 3; var bytes = this.outputBits >> 3;
var buffer; var buffer;
if (extraBytes) { if(extraBytes)
{
buffer = new ArrayBuffer((outputBlocks + 1) << 2); buffer = new ArrayBuffer((outputBlocks + 1) << 2);
} }
else { else
{
buffer = new ArrayBuffer(bytes); buffer = new ArrayBuffer(bytes);
} }
var array = new Uint32Array(buffer); var array = new Uint32Array(buffer);
while (j < outputBlocks) { while(j < outputBlocks)
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { {
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
array[j] = s[i]; array[j] = s[i];
} }
if (j % blockCount === 0) { if(j % blockCount === 0)
{
f(s); f(s);
} }
} }
if (extraBytes) { if(extraBytes)
{
array[i] = s[i]; array[i] = s[i];
buffer = buffer.slice(0, bytes); buffer = buffer.slice(0, bytes);
} }
return buffer; return buffer;
}; };
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer; Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
Keccak.prototype.digest = Keccak.prototype.array = function() { Keccak.prototype.digest = Keccak.prototype.array = function ()
{
this.finalize(); this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0; var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var array = [], offset, block; var array = [], offset, block;
while (j < outputBlocks) { while(j < outputBlocks)
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { {
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
offset = j << 2; offset = j << 2;
block = s[i]; block = s[i];
array[offset] = block & 0xFF; array[offset] = block & 0xFF;
@ -392,39 +478,48 @@
array[offset + 2] = (block >> 16) & 0xFF; array[offset + 2] = (block >> 16) & 0xFF;
array[offset + 3] = (block >> 24) & 0xFF; array[offset + 3] = (block >> 24) & 0xFF;
} }
if (j % blockCount === 0) { if(j % blockCount === 0)
{
f(s); f(s);
} }
} }
if (extraBytes) { if(extraBytes)
{
offset = j << 2; offset = j << 2;
block = s[i]; block = s[i];
if (extraBytes > 0) { if(extraBytes > 0)
{
array[offset] = block & 0xFF; array[offset] = block & 0xFF;
} }
if (extraBytes > 1) { if(extraBytes > 1)
{
array[offset + 1] = (block >> 8) & 0xFF; array[offset + 1] = (block >> 8) & 0xFF;
} }
if (extraBytes > 2) { if(extraBytes > 2)
{
array[offset + 2] = (block >> 16) & 0xFF; array[offset + 2] = (block >> 16) & 0xFF;
} }
} }
return array; return array;
}; };
function Kmac(bits, padding, outputBits) { function Kmac(bits,padding,outputBits)
{
Keccak.call(this, bits, padding, outputBits); Keccak.call(this, bits, padding, outputBits);
}; };
Kmac.prototype = new Keccak(); Kmac.prototype = new Keccak();
Kmac.prototype.finalize = function() { Kmac.prototype.finalize = function ()
{
this.encode(this.outputBits, true); this.encode(this.outputBits, true);
return Keccak.prototype.finalize.call(this); return Keccak.prototype.finalize.call(this);
}; };
var f = function(s) { var f = function (s)
{
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40,
b41, b42, b43, b44, b45, b46, b47, b48, b49; b41, b42, b43, b44, b45, b46, b47, b48, b49;
for (n = 0; n < 48; n += 2) { for(n = 0; n < 48; n += 2)
{
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
@ -602,47 +697,58 @@
root.sha3_str = methods.sha3_256; root.sha3_str = methods.sha3_256;
root.sha3_array_256 = methods.sha3_array_256; root.sha3_array_256 = methods.sha3_array_256;
root.sha3 = methods.sha3_array_256; root.sha3 = methods.sha3_array_256;
root.sha = function(data) { root.sha = function (data)
{
return meshhash(methods.sha3_256(data)); return meshhash(methods.sha3_256(data));
}; };
root.shaarr = function(data) { root.shaarr = function (data)
{
return meshhash(methods.sha3_array_256(data)); return meshhash(methods.sha3_array_256(data));
}; };
root.shabuf = function(data) { root.shabuf = function (data)
{
return Buffer.from(shaarr(data)); return Buffer.from(shaarr(data));
}; };
root.shabuf = function(data) { root.shabuf = function (data)
{
return Buffer.from(shaarr(data)); return Buffer.from(shaarr(data));
}; };
root.SHA3BUF = function(data, num) { root.SHA3BUF = function (data,num)
{
return Buffer.from(SHA3ARR(data, num)); return Buffer.from(SHA3ARR(data, num));
}; };
root.SHA3ARR = function(data, num) { root.SHA3ARR = function (data,num)
{
if(!NEW_SIGN_TIME || !num || num >= NEW_SIGN_TIME) if(!NEW_SIGN_TIME || !num || num >= NEW_SIGN_TIME)
return sha3(data); return sha3(data);
else else
return meshhash(methods.sha3_array_256(data)); return meshhash(methods.sha3_array_256(data));
}; };
root.shaarrblock = function(data, num) { root.shaarrblock = function (data,num)
{
return meshhash(methods.sha3_array_256(data), num); return meshhash(methods.sha3_array_256(data), num);
}; };
})(); })();
function meshhash(hash, num) { function meshhash(hash,num)
{
var regs = [hash[3], hash[2], hash[1], hash[0]]; var regs = [hash[3], hash[2], hash[1], hash[0]];
var mem = []; var mem = [];
for (var i = 0; i < 16; i++) { for(var i = 0; i < 16; i++)
{
mem[i] = hash[i * 2] + (hash[i * 2 + 1] << 8); mem[i] = hash[i * 2] + (hash[i * 2 + 1] << 8);
} }
var WasGoto = 0; var WasGoto = 0;
var L = 0; var L = 0;
for (var i = 0; i < 64; i++) { for(var i = 0; i < 64; i++)
{
var c = hash[L & 31]; var c = hash[L & 31];
L++; L++;
var a = (c >> 4) & 0xF; var a = (c >> 4) & 0xF;
var b = c & 0xF; var b = c & 0xF;
var r = c & 0x3; var r = c & 0x3;
switch (a) { switch(a)
{
case 0: case 0:
regs[0] = regs[0] + regs[r]; regs[0] = regs[0] + regs[r];
break; break;
@ -662,13 +768,15 @@ function meshhash(hash, num) {
regs[0] = regs[0] + regs[1] + regs[2] + regs[3]; regs[0] = regs[0] + regs[1] + regs[2] + regs[3];
break; break;
case 8: case 8:
if ((regs[0] & 0xFFFF) < 32768 && !WasGoto) { if((regs[0] & 0xFFFF) < 32768 && !WasGoto)
{
L = 32 + L - b; L = 32 + L - b;
WasGoto = 1; WasGoto = 1;
} }
break; break;
case 9: case 9:
if ((regs[0] & 0xFFFF) > 32768 && !WasGoto) { if((regs[0] & 0xFFFF) > 32768 && !WasGoto)
{
L += b; L += b;
WasGoto = 1; WasGoto = 1;
} }
@ -678,14 +786,16 @@ function meshhash(hash, num) {
} }
var index1 = regs[0] & 0xF; var index1 = regs[0] & 0xF;
var index2 = (regs[0] >> 8) & 0xF; var index2 = (regs[0] >> 8) & 0xF;
if (index1 !== index2) { if(index1 !== index2)
{
var temp = mem[index1]; var temp = mem[index1];
mem[index1] = mem[index2]; mem[index1] = mem[index2];
mem[index2] = temp; mem[index2] = temp;
} }
} }
var ret = []; var ret = [];
for (var i = 0; i < 16; i++) { for(var i = 0; i < 16; i++)
{
ret[i * 2] = mem[i] & 0xFF; ret[i * 2] = mem[i] & 0xFF;
ret[i * 2 + 1] = mem[i] >> 8; ret[i * 2 + 1] = mem[i] >> 8;
} }

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,8 @@ var DELTA_LONG_MINING = 5000;
var BLOCKNUM_ALGO2 = 6560000; var BLOCKNUM_ALGO2 = 6560000;
var BLOCKNUM_HASH_NEW = 10195000; var BLOCKNUM_HASH_NEW = 10195000;
var BLOCKNUM_TICKET_ALGO = 16070000; var BLOCKNUM_TICKET_ALGO = 16070000;
if (typeof global === "object") { if(typeof global === "object")
{
global.GetHashFromSeqAddr = GetHashFromSeqAddr; global.GetHashFromSeqAddr = GetHashFromSeqAddr;
global.CalcHashBlockFromSeqAddr = CalcHashBlockFromSeqAddr; global.CalcHashBlockFromSeqAddr = CalcHashBlockFromSeqAddr;
global.GetHashFromNum2 = GetHashFromNum2; global.GetHashFromNum2 = GetHashFromNum2;
@ -20,21 +21,26 @@ if (typeof global === "object") {
global.GetHashFromArrNum2 = GetHashFromArrNum2; global.GetHashFromArrNum2 = GetHashFromArrNum2;
global.XORArr = XORArr; global.XORArr = XORArr;
global.GetHash = GetHash; global.GetHash = GetHash;
if (global.LOCAL_RUN || global.TEST_NETWORK) { if(global.LOCAL_RUN || global.TEST_NETWORK)
{
BLOCKNUM_ALGO2 = 0; BLOCKNUM_ALGO2 = 0;
if (global.TEST_NETWORK) { if(global.TEST_NETWORK)
{
BLOCKNUM_HASH_NEW = 100; BLOCKNUM_HASH_NEW = 100;
BLOCKNUM_TICKET_ALGO = 0; BLOCKNUM_TICKET_ALGO = 0;
} }
else { else
{
BLOCKNUM_HASH_NEW = 100; BLOCKNUM_HASH_NEW = 100;
BLOCKNUM_TICKET_ALGO = 0; BLOCKNUM_TICKET_ALGO = 0;
} }
} }
} }
function GetHashFromSeqAddr(SeqHash, AddrHash, BlockNum, PrevHash, MiningVer) { function GetHashFromSeqAddr(SeqHash,AddrHash,BlockNum,PrevHash,MiningVer)
if (BlockNum < BLOCKNUM_ALGO2) { {
if(BlockNum < BLOCKNUM_ALGO2)
{
var Hash = shaarrblock2(SeqHash, AddrHash, BlockNum); var Hash = shaarrblock2(SeqHash, AddrHash, BlockNum);
return {Hash:Hash, PowHash:Hash, Hash1:Hash, Hash2:Hash}; return {Hash:Hash, PowHash:Hash, Hash1:Hash, Hash2:Hash};
} }
@ -45,15 +51,19 @@ function GetHashFromSeqAddr(SeqHash, AddrHash, BlockNum, PrevHash, MiningVer) {
var DeltaNum1 = ReadUint16FromArr(AddrHash, 24); var DeltaNum1 = ReadUint16FromArr(AddrHash, 24);
var DeltaNum2 = ReadUint16FromArr(AddrHash, 26); var DeltaNum2 = ReadUint16FromArr(AddrHash, 26);
var PrevHashNum; var PrevHashNum;
if (PrevHash) { if(PrevHash)
{
PrevHashNum = ReadUint32FromArr(PrevHash, 28); PrevHashNum = ReadUint32FromArr(PrevHash, 28);
} }
else { else
{
PrevHashNum = ReadUint32FromArr(AddrHash, 28); PrevHashNum = ReadUint32FromArr(AddrHash, 28);
} }
var Data = GetHash(SeqHash, PrevHashNum, BlockNum, MinerID, Nonce0, Nonce1, Nonce2, DeltaNum1, DeltaNum2); var Data = GetHash(SeqHash, PrevHashNum, BlockNum, MinerID, Nonce0, Nonce1, Nonce2, DeltaNum1, DeltaNum2);
if (MiningVer) { if(MiningVer)
if (AddrHash[17] !== MiningVer || AddrHash[23] !== MiningVer) { {
if(AddrHash[17] !== MiningVer || AddrHash[23] !== MiningVer)
{
Data.PowHash = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, Data.PowHash = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255]; 255, 255, 255, 255, 255, 255, 255, 255, 255, 255];
} }
@ -61,7 +71,8 @@ function GetHashFromSeqAddr(SeqHash, AddrHash, BlockNum, PrevHash, MiningVer) {
return Data; return Data;
}; };
function GetHash(BlockHash, PrevHashNum, BlockNum, Miner, Nonce0, Nonce1, Nonce2, DeltaNum1, DeltaNum2) { function GetHash(BlockHash,PrevHashNum,BlockNum,Miner,Nonce0,Nonce1,Nonce2,DeltaNum1,DeltaNum2)
{
if(DeltaNum1 > DELTA_LONG_MINING) if(DeltaNum1 > DELTA_LONG_MINING)
DeltaNum1 = 0; DeltaNum1 = 0;
if(DeltaNum2 > DELTA_LONG_MINING) if(DeltaNum2 > DELTA_LONG_MINING)
@ -73,13 +84,16 @@ function GetHash(BlockHash, PrevHashNum, BlockNum, Miner, Nonce0, Nonce1, Nonce2
var Hash1 = XORArr(HashBase, HashNonce1); var Hash1 = XORArr(HashBase, HashNonce1);
var Hash2 = XORArr(HashCurrent, HashNonce2); var Hash2 = XORArr(HashCurrent, HashNonce2);
var Ret = {Hash:Hash2, Hash1:Hash1, Hash2:Hash2}; var Ret = {Hash:Hash2, Hash1:Hash1, Hash2:Hash2};
if (CompareArr(Hash1, Hash2) > 0) { if(CompareArr(Hash1, Hash2) > 0)
{
Ret.PowHash = Hash1; Ret.PowHash = Hash1;
} }
else { else
{
Ret.PowHash = Hash2; Ret.PowHash = Hash2;
} }
if (BlockNum >= BLOCKNUM_HASH_NEW) { if(BlockNum >= BLOCKNUM_HASH_NEW)
{
if(BlockNum >= BLOCKNUM_TICKET_ALGO) if(BlockNum >= BLOCKNUM_TICKET_ALGO)
Ret.Hash = sha3arr2(Hash1, Hash2); Ret.Hash = sha3arr2(Hash1, Hash2);
else else
@ -88,28 +102,33 @@ function GetHash(BlockHash, PrevHashNum, BlockNum, Miner, Nonce0, Nonce1, Nonce2
return Ret; return Ret;
}; };
function CalcHashBlockFromSeqAddr(Block, PrevHash, MiningVer) { function CalcHashBlockFromSeqAddr(Block,PrevHash,MiningVer)
{
var Value = GetHashFromSeqAddr(Block.SeqHash, Block.AddrHash, Block.BlockNum, PrevHash, MiningVer); var Value = GetHashFromSeqAddr(Block.SeqHash, Block.AddrHash, Block.BlockNum, PrevHash, MiningVer);
Block.Hash = Value.Hash; Block.Hash = Value.Hash;
Block.PowHash = Value.PowHash; Block.PowHash = Value.PowHash;
}; };
function XORArr(Arr1, Arr2) { function XORArr(Arr1,Arr2)
{
var Ret = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var Ret = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < 32; i++) { for(var i = 0; i < 32; i++)
{
Ret[i] = Arr1[i] ^ Arr2[i]; Ret[i] = Arr1[i] ^ Arr2[i];
} }
return Ret; return Ret;
}; };
function GetHashFromNum2(Value1, Value2) { function GetHashFromNum2(Value1,Value2)
{
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
WriteUintToArrOnPos(MeshArr, Value1, 0); WriteUintToArrOnPos(MeshArr, Value1, 0);
WriteUintToArrOnPos(MeshArr, Value2, 6); WriteUintToArrOnPos(MeshArr, Value2, 6);
return sha3(MeshArr); return sha3(MeshArr);
}; };
function GetHashFromArrNum2(Arr, Value1, Value2) { function GetHashFromArrNum2(Arr,Value1,Value2)
{
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]; 0, 0, 0, 0, 0, 0, 0, 0];
WriteArrToArrOnPos(MeshArr, Arr, 0, 32); WriteArrToArrOnPos(MeshArr, Arr, 0, 32);
@ -118,7 +137,8 @@ function GetHashFromArrNum2(Arr, Value1, Value2) {
return sha3(MeshArr); return sha3(MeshArr);
}; };
function GetHashFromNum3(Value1, Value2, Value3) { function GetHashFromNum3(Value1,Value2,Value3)
{
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
WriteUintToArrOnPos(MeshArr, Value1, 0); WriteUintToArrOnPos(MeshArr, Value1, 0);
WriteUintToArrOnPos(MeshArr, Value2, 6); WriteUintToArrOnPos(MeshArr, Value2, 6);
@ -126,8 +146,10 @@ function GetHashFromNum3(Value1, Value2, Value3) {
return sha3(MeshArr); return sha3(MeshArr);
}; };
function ReadUintFromArr(arr, len) { function ReadUintFromArr(arr,len)
if (len === undefined) { {
if(len === undefined)
{
len = arr.len; len = arr.len;
arr.len += 6; arr.len += 6;
} }
@ -137,8 +159,10 @@ function ReadUintFromArr(arr, len) {
return value; return value;
}; };
function ReadUint32FromArr(arr, len) { function ReadUint32FromArr(arr,len)
if (len === undefined) { {
if(len === undefined)
{
len = arr.len; len = arr.len;
arr.len += 4; arr.len += 4;
} }
@ -146,8 +170,10 @@ function ReadUint32FromArr(arr, len) {
return value; return value;
}; };
function ReadUint16FromArr(arr, len) { function ReadUint16FromArr(arr,len)
if (len === undefined) { {
if(len === undefined)
{
len = arr.len; len = arr.len;
arr.len += 2; arr.len += 2;
} }
@ -155,17 +181,20 @@ function ReadUint16FromArr(arr, len) {
return value; return value;
}; };
function ReadArrFromArr(arr, length) { function ReadArrFromArr(arr,length)
{
var Ret = []; var Ret = [];
var len = arr.len; var len = arr.len;
for (var i = 0; i < length; i++) { for(var i = 0; i < length; i++)
{
Ret[i] = arr[len + i]; Ret[i] = arr[len + i];
} }
arr.len += length; arr.len += length;
return Ret; return Ret;
}; };
function WriteUintToArr(arr, Num) { function WriteUintToArr(arr,Num)
{
var len = arr.length; var len = arr.length;
arr[len] = Num & 0xFF; arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF; arr[len + 1] = (Num >>> 8) & 0xFF;
@ -176,7 +205,8 @@ function WriteUintToArr(arr, Num) {
arr[len + 5] = (NumH >>> 8) & 0xFF; arr[len + 5] = (NumH >>> 8) & 0xFF;
}; };
function WriteUintToArrOnPos(arr, Num, Pos) { function WriteUintToArrOnPos(arr,Num,Pos)
{
arr[Pos] = Num & 0xFF; arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF; arr[Pos + 1] = (Num >>> 8) & 0xFF;
arr[Pos + 2] = (Num >>> 16) & 0xFF; arr[Pos + 2] = (Num >>> 16) & 0xFF;
@ -186,7 +216,8 @@ function WriteUintToArrOnPos(arr, Num, Pos) {
arr[Pos + 5] = (NumH >>> 8) & 0xFF; arr[Pos + 5] = (NumH >>> 8) & 0xFF;
}; };
function WriteUint32ToArr(arr, Num) { function WriteUint32ToArr(arr,Num)
{
var len = arr.length; var len = arr.length;
arr[len] = Num & 0xFF; arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF; arr[len + 1] = (Num >>> 8) & 0xFF;
@ -194,41 +225,52 @@ function WriteUint32ToArr(arr, Num) {
arr[len + 3] = (Num >>> 24) & 0xFF; arr[len + 3] = (Num >>> 24) & 0xFF;
}; };
function WriteUint32ToArrOnPos(arr, Num, Pos) { function WriteUint32ToArrOnPos(arr,Num,Pos)
{
arr[Pos] = Num & 0xFF; arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF; arr[Pos + 1] = (Num >>> 8) & 0xFF;
arr[Pos + 2] = (Num >>> 16) & 0xFF; arr[Pos + 2] = (Num >>> 16) & 0xFF;
arr[Pos + 3] = (Num >>> 24) & 0xFF; arr[Pos + 3] = (Num >>> 24) & 0xFF;
}; };
function WriteUint16ToArrOnPos(arr, Num, Pos) { function WriteUint16ToArrOnPos(arr,Num,Pos)
{
arr[Pos] = Num & 0xFF; arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF; arr[Pos + 1] = (Num >>> 8) & 0xFF;
}; };
function WriteArrToArr(arr, arr2, ConstLength) { function WriteArrToArr(arr,arr2,ConstLength)
{
var len = arr.length; var len = arr.length;
for (var i = 0; i < ConstLength; i++) { for(var i = 0; i < ConstLength; i++)
{
arr[len + i] = arr2[i]; arr[len + i] = arr2[i];
} }
}; };
function WriteArrToArrOnPos(arr, arr2, Pos, ConstLength) { function WriteArrToArrOnPos(arr,arr2,Pos,ConstLength)
for (var i = 0; i < ConstLength; i++) { {
for(var i = 0; i < ConstLength; i++)
{
arr[Pos + i] = arr2[i]; arr[Pos + i] = arr2[i];
} }
}; };
function WriteArrToArrHOnPos(arr, arr2, Pos, ConstLength) { function WriteArrToArrHOnPos(arr,arr2,Pos,ConstLength)
for (var i = 0; i < ConstLength; i++) { {
for(var i = 0; i < ConstLength; i++)
{
arr[Pos + i] |= (arr2[i] << 8); arr[Pos + i] |= (arr2[i] << 8);
} }
}; };
function ConvertBufferToStr(Data) { function ConvertBufferToStr(Data)
for (var key in Data) { {
for(var key in Data)
{
var item = Data[key]; var item = Data[key];
if (item instanceof Buffer) { if(item instanceof Buffer)
{
Data[key] = GetHexFromArr(item); Data[key] = GetHexFromArr(item);
} }
else else
@ -237,11 +279,13 @@ function ConvertBufferToStr(Data) {
} }
}; };
function CopyObjValue(obj, num) { function CopyObjValue(obj,num)
{
if(num && num > 5) if(num && num > 5)
return obj; return obj;
var ret = {}; var ret = {};
for (var key in obj) { for(var key in obj)
{
var val = obj[key]; var val = obj[key];
if((typeof val === "object") && !(val instanceof Buffer) && !(val instanceof ArrayBuffer) && !(val instanceof Array)) if((typeof val === "object") && !(val instanceof Buffer) && !(val instanceof ArrayBuffer) && !(val instanceof Array))
val = CopyObjValue(val, num + 1); val = CopyObjValue(val, num + 1);
@ -250,7 +294,8 @@ function CopyObjValue(obj, num) {
return ret; return ret;
}; };
function CopyArr(arr1) { function CopyArr(arr1)
{
var arr2 = []; var arr2 = [];
if(arr1) if(arr1)
for(var i = 0; i < arr1.length; i++) for(var i = 0; i < arr1.length; i++)
@ -258,7 +303,8 @@ function CopyArr(arr1) {
return arr2; return arr2;
}; };
function ParseNum(a) { function ParseNum(a)
{
var Num = parseInt(a); var Num = parseInt(a);
if(!Num) if(!Num)
Num = 0; Num = 0;
@ -269,31 +315,37 @@ function ParseNum(a) {
return Num; return Num;
}; };
function CompareArr(a, b) { function CompareArr(a,b)
for (var i = 0; i < a.length; i++) { {
for(var i = 0; i < a.length; i++)
{
if(a[i] !== b[i]) if(a[i] !== b[i])
return a[i] - b[i]; return a[i] - b[i];
} }
return 0; return 0;
}; };
function CompareArrL(a, b) { function CompareArrL(a,b)
{
if(a.length !== b.length) if(a.length !== b.length)
return a.length - b.length; return a.length - b.length;
for (var i = 0; i < a.length; i++) { for(var i = 0; i < a.length; i++)
{
if(a[i] !== b[i]) if(a[i] !== b[i])
return a[i] - b[i]; return a[i] - b[i];
} }
return 0; return 0;
}; };
function GetSeqHash(BlockNum, PrevHash, TreeHash) { function GetSeqHash(BlockNum,PrevHash,TreeHash)
{
var arr = [GetArrFromValue(BlockNum), PrevHash, TreeHash]; var arr = [GetArrFromValue(BlockNum), PrevHash, TreeHash];
var SeqHash = CalcHashFromArray(arr, true); var SeqHash = CalcHashFromArray(arr, true);
return SeqHash; return SeqHash;
}; };
function arr2(Value1, Value2) { function arr2(Value1,Value2)
{
var Buf = []; var Buf = [];
for(var n = 0; n < Value1.length; n++) for(var n = 0; n < Value1.length; n++)
Buf.push(Value1[n]); Buf.push(Value1[n]);
@ -302,15 +354,18 @@ function arr2(Value1, Value2) {
return Buf; return Buf;
}; };
function shaarr2(Value1, Value2) { function shaarr2(Value1,Value2)
{
return shaarr(arr2(Value1, Value2)); return shaarr(arr2(Value1, Value2));
}; };
function sha3arr2(Value1, Value2) { function sha3arr2(Value1,Value2)
{
return sha3(arr2(Value1, Value2)); return sha3(arr2(Value1, Value2));
}; };
function GetBlockArrFromBuffer(BufRead, Info) { function GetBlockArrFromBuffer(BufRead,Info)
{
if(!BufRead || BufRead.length < 10) if(!BufRead || BufRead.length < 10)
return []; return [];
var BLOCK_PROCESSING_LENGTH = 8; var BLOCK_PROCESSING_LENGTH = 8;
@ -319,19 +374,24 @@ function GetBlockArrFromBuffer(BufRead, Info) {
var StartNum = ReadUintFromArr(BufRead); var StartNum = ReadUintFromArr(BufRead);
var CountLoad = ReadUint32FromArr(BufRead); var CountLoad = ReadUint32FromArr(BufRead);
var BufSize = 6 + 4 + BLOCK_PROCESSING_LENGTH2 * 32 + 32 + 6 + CountLoad * 64; var BufSize = 6 + 4 + BLOCK_PROCESSING_LENGTH2 * 32 + 32 + 6 + CountLoad * 64;
if (CountLoad <= 0 || BufSize !== BufRead.length) { if(CountLoad <= 0 || BufSize !== BufRead.length)
{
return []; return [];
} }
var PrevBlock; var PrevBlock;
var BlockArr = []; var BlockArr = [];
for (var i = 0; i < CountLoad + BLOCK_PROCESSING_LENGTH2; i++) { for(var i = 0; i < CountLoad + BLOCK_PROCESSING_LENGTH2; i++)
{
var Block = {}; var Block = {};
Block.BlockNum = StartNum + i; Block.BlockNum = StartNum + i;
if (i < BLOCK_PROCESSING_LENGTH2) { if(i < BLOCK_PROCESSING_LENGTH2)
{
Block.Hash = ReadArrFromArr(BufRead, 32); Block.Hash = ReadArrFromArr(BufRead, 32);
} }
else { else
if (i === BLOCK_PROCESSING_LENGTH2) { {
if(i === BLOCK_PROCESSING_LENGTH2)
{
Block.SumHash = ReadArrFromArr(BufRead, 32); Block.SumHash = ReadArrFromArr(BufRead, 32);
Block.SumPow = ReadUintFromArr(BufRead); Block.SumPow = ReadUintFromArr(BufRead);
} }
@ -339,7 +399,8 @@ function GetBlockArrFromBuffer(BufRead, Info) {
Block.AddrHash = ReadArrFromArr(BufRead, 32); Block.AddrHash = ReadArrFromArr(BufRead, 32);
var arr = []; var arr = [];
var start = i - BLOCK_PROCESSING_LENGTH2; var start = i - BLOCK_PROCESSING_LENGTH2;
for (var n = 0; n < BLOCK_PROCESSING_LENGTH; n++) { for(var n = 0; n < BLOCK_PROCESSING_LENGTH; n++)
{
var Prev = BlockArr[start + n]; var Prev = BlockArr[start + n];
arr.push(Prev.Hash); arr.push(Prev.Hash);
} }
@ -347,8 +408,10 @@ function GetBlockArrFromBuffer(BufRead, Info) {
Block.SeqHash = GetSeqHash(Block.BlockNum, Block.PrevHash, Block.TreeHash); Block.SeqHash = GetSeqHash(Block.BlockNum, Block.PrevHash, Block.TreeHash);
var PrevHashNum = ReadUint32FromArr(Block.PrevHash, 28); var PrevHashNum = ReadUint32FromArr(Block.PrevHash, 28);
var PrevAddrNum = ReadUint32FromArr(Block.AddrHash, 28); var PrevAddrNum = ReadUint32FromArr(Block.AddrHash, 28);
if (PrevHashNum !== PrevAddrNum && Block.BlockNum > 20000000) { if(PrevHashNum !== PrevAddrNum && Block.BlockNum > 20000000)
if (global.WATCHDOG_DEV) { {
if(global.WATCHDOG_DEV)
{
var Str = ""; var Str = "";
if(Info && Info.Node) if(Info && Info.Node)
Str = " from " + NodeName(Info.Node); Str = " from " + NodeName(Info.Node);
@ -358,7 +421,8 @@ function GetBlockArrFromBuffer(BufRead, Info) {
} }
CalcHashBlockFromSeqAddr(Block, Block.PrevHash); CalcHashBlockFromSeqAddr(Block, Block.PrevHash);
Block.Power = GetPowPower(Block.PowHash); Block.Power = GetPowPower(Block.PowHash);
if (PrevBlock) { if(PrevBlock)
{
Block.SumHash = shaarr2(PrevBlock.SumHash, Block.Hash); Block.SumHash = shaarr2(PrevBlock.SumHash, Block.Hash);
} }
PrevBlock = Block; PrevBlock = Block;
@ -368,9 +432,11 @@ function GetBlockArrFromBuffer(BufRead, Info) {
Block.TrDataLen = 0; Block.TrDataLen = 0;
BlockArr.push(Block); BlockArr.push(Block);
} }
for (var i = BlockArr.length - 1; i >= 0; i--) { for(var i = BlockArr.length - 1; i >= 0; i--)
{
var Block = BlockArr[i]; var Block = BlockArr[i];
if (!Block.SumHash) { if(!Block.SumHash)
{
BlockArr = BlockArr.slice(i + 1); BlockArr = BlockArr.slice(i + 1);
break; break;
} }
@ -378,10 +444,12 @@ function GetBlockArrFromBuffer(BufRead, Info) {
return BlockArr; return BlockArr;
}; };
function shaarrblock2(Value1, Value2, BlockNum) { function shaarrblock2(Value1,Value2,BlockNum)
{
return shaarrblock(arr2(Value1, Value2), BlockNum); return shaarrblock(arr2(Value1, Value2), BlockNum);
}; };
if (typeof global === "object") { if(typeof global === "object")
{
global.ReadUint32FromArr = ReadUint32FromArr; global.ReadUint32FromArr = ReadUint32FromArr;
global.ReadUintFromArr = ReadUintFromArr; global.ReadUintFromArr = ReadUintFromArr;
global.ReadUint16FromArr = ReadUint16FromArr; global.ReadUint16FromArr = ReadUint16FromArr;
@ -406,6 +474,7 @@ if (typeof global === "object") {
global.shaarrblock2 = shaarrblock2; global.shaarrblock2 = shaarrblock2;
} }
else else
if (typeof window === "object") { if(typeof window === "object")
{
global = window; global = window;
} }

View File

@ -19,7 +19,8 @@ var MaxBlockNum = 0;
var DelList = {}; var DelList = {};
var WasAccountsDataStr; var WasAccountsDataStr;
function SetAccountsData(Data, AccountsDataStr) { function SetAccountsData(Data,AccountsDataStr)
{
if(!Data || !Data.result) if(!Data || !Data.result)
return ; return ;
if($("idBtRun")) if($("idBtRun"))
@ -29,13 +30,15 @@ function SetAccountsData(Data, AccountsDataStr) {
WasAccountsDataStr = AccountsDataStr; WasAccountsDataStr = AccountsDataStr;
var arr = Data.arr; var arr = Data.arr;
var Select = $("idAccount"); var Select = $("idAccount");
if (arr.length !== Select.options.length) { if(arr.length !== Select.options.length)
{
var options = Select.options; var options = Select.options;
options.length = arr.length; options.length = arr.length;
} }
MaxBlockNum = GetCurrentBlockNumByTime(); MaxBlockNum = GetCurrentBlockNumByTime();
SetGridData(arr, "grid_accounts", "idMyTotalSum"); SetGridData(arr, "grid_accounts", "idMyTotalSum");
for (var i = 0; arr && i < arr.length; i++) { for(var i = 0; arr && i < arr.length; i++)
{
var Item = arr[i]; var Item = arr[i];
Item.MyAccount = true; Item.MyAccount = true;
var Num = ParseNum(Item.Num); var Num = ParseNum(Item.Num);
@ -50,25 +53,31 @@ function SetAccountsData(Data, AccountsDataStr) {
option.text = StrText; option.text = StrText;
} }
var CurentValue = LoadMapAfter["idAccount"]; var CurentValue = LoadMapAfter["idAccount"];
if (CurentValue) { if(CurentValue)
{
Select.value = CurentValue; Select.value = CurentValue;
delete LoadMapAfter["idAccount"]; delete LoadMapAfter["idAccount"];
} }
SetCurCurencyName(); SetCurCurencyName();
}; };
function CurTransactionToForm(bForce) { function CurTransactionToForm(bForce)
{
var Item = $("idTransaction"); var Item = $("idTransaction");
if(Item && (Item.className === "" || bForce)) if(Item && (Item.className === "" || bForce))
Item.value = GetJSONFromTransaction(CurrentTR); Item.value = GetJSONFromTransaction(CurrentTR);
}; };
function CheckNameAccTo() { function CheckNameAccTo()
{
MaxBlockNum = GetCurrentBlockNumByTime(); MaxBlockNum = GetCurrentBlockNumByTime();
var ToID = ParseNum($("idTo").value); var ToID = ParseNum($("idTo").value);
if (!MapAccounts[ToID] || (MapAccounts[ToID].MustUpdate && MapAccounts[ToID].MustUpdate >= MaxBlockNum)) { if(!MapAccounts[ToID] || (MapAccounts[ToID].MustUpdate && MapAccounts[ToID].MustUpdate >= MaxBlockNum))
GetData("GetAccountList", { StartNum: ToID }, function(Data) { {
if (Data && Data.result === 1 && Data.arr.length) { GetData("GetAccountList", {StartNum:ToID}, function (Data)
{
if(Data && Data.result === 1 && Data.arr.length)
{
var Item = Data.arr[0]; var Item = Data.arr[0];
Item.UpdateData = Date.now(); Item.UpdateData = Date.now();
MapAccounts[Item.Num] = Item; MapAccounts[Item.Num] = Item;
@ -79,19 +88,28 @@ function CheckNameAccTo() {
SetNameAccTo(); SetNameAccTo();
}; };
function SetNameAccTo() { function SetNameAccTo()
{
var Str = ""; var Str = "";
var ToID = ParseNum($("idTo").value); var ToID = $("idTo").value.trim();
var Item = MapAccounts[ToID]; var Item = MapAccounts[ToID];
var element = $("idNameTo");
var StrTo = GetAccountText(Item, ToID, 1); var StrTo = GetAccountText(Item, ToID, 1);
if (!element) { var element = $("idNameTo");
if(!element)
{
element = $("idNameTo2"); element = $("idNameTo2");
} }
else { else
{
StrTo = "To: " + StrTo; StrTo = "To: " + StrTo;
} }
if (element.innerText !== StrTo) { if(!ToID || ToID === "0")
{
element.innerText = "";
return ;
}
if(element && element.innerText !== StrTo)
{
element.innerText = StrTo; element.innerText = StrTo;
if(Item && Item.MyAccount) if(Item && Item.MyAccount)
element.className = "smallbold"; element.className = "smallbold";
@ -100,52 +118,73 @@ function SetNameAccTo() {
} }
}; };
function GetAccountText(Item, Num, bGetSum) { function GetAccountText(Item,Num,bGetSum)
if (Item) { {
if(Item)
{
var text = Item.Name; var text = Item.Name;
if(!text || text.length === 0) if(!text || text.length === 0)
text = Num; text = Num;
else else
text = "" + Num + ". " + text; text = "" + Num + ". " + text;
if (bGetSum) { if(bGetSum)
{
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency); var StrSum = SUM_TO_STRING(Item.Value, Item.Currency);
text += " (" + StrSum + ")"; text += " (" + StrSum + ")";
} }
return text; return text;
} }
else { else
{
if(IsPublicAddr(Num))
return Num; return Num;
else
return "<Error addres>";
} }
}; };
function OnEditIdTo() { function OnEditIdTo()
{
CheckNameAccTo(); CheckNameAccTo();
OnEditTransactionFields(); OnEditTransactionFields();
}; };
function OnEditTransactionFields() { function OnEditTransactionFields()
{
if(IsVisibleBlock("edit_transaction")) if(IsVisibleBlock("edit_transaction"))
CreateTransaction(); CreateTransaction();
SetCurCurencyName(); SetCurCurencyName();
SaveValues(); SaveValues();
}; };
function SetCurCurencyName() { function SetCurCurencyName()
{
var idCoin = $("idCoinName"); var idCoin = $("idCoinName");
if(!idCoin) if(!idCoin)
return ; return ;
var Num = ParseNum($("idAccount").value); var Num = ParseNum($("idAccount").value);
var Item = MapAccounts[Num]; var Item = MapAccounts[Num];
if (Item) { if(Item)
{
idCoin.innerText = CurrencyName(Item.Currency); idCoin.innerText = CurrencyName(Item.Currency);
} }
}; };
function CreateTransaction(F, CheckErr, Run) { function IsPublicAddr(StrTo)
{
if(StrTo.length === 66 && (StrTo.substr(0, 2) === "02" || StrTo.substr(0, 2) === "03") && IsHexStr(StrTo))
return 1;
else
return 0;
};
function CreateTransaction(F,CheckErr,Run)
{
CheckNameAccTo(); CheckNameAccTo();
CheckSending(); CheckSending();
var FromID = ParseNum($("idAccount").value); var FromID = ParseNum($("idAccount").value);
if (CheckErr && FromID === 0) { if(CheckErr && FromID === 0)
{
SetError("Select valid 'From account'"); SetError("Select valid 'From account'");
return ; return ;
} }
@ -153,31 +192,37 @@ function CreateTransaction(F, CheckErr, Run) {
var bFindAcc = 0; var bFindAcc = 0;
var ToPubKey = ""; var ToPubKey = "";
var ToID = ParseNum(StrTo); var ToID = ParseNum(StrTo);
if (StrTo !== "" + ToID) { if(StrTo !== "" + ToID)
if (StrTo.length === 66 && (StrTo.substr(0, 2) === "02" || StrTo.substr(0, 2) === "03") && IsHexStr(StrTo)) { {
if(IsPublicAddr(StrTo))
{
ToID = 0; ToID = 0;
ToPubKey = StrTo; ToPubKey = StrTo;
if (ToPubKey === PubKeyStr) if(ToPubKey === window.PubKeyStr)
bFindAcc = 1; bFindAcc = 1;
} }
else { else
{
if(CheckErr) if(CheckErr)
SetError("Valid 'Pay to' - required!"); SetError("Valid 'Pay to' - required!");
return ; return ;
} }
} }
if (CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem) { if(CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem)
{
SetError("Valid 'Pay to' - required!"); SetError("Valid 'Pay to' - required!");
return ; return ;
} }
var Description = $("idDescription").value.substr(0, 200); var Description = $("idDescription").value.substr(0, 200);
var StrSum = $("idSumSend").value; var StrSum = $("idSumSend").value;
var indDot = StrSum.indexOf("."); var indDot = StrSum.indexOf(".");
if (indDot >= 0) { if(indDot >= 0)
{
var StrTER = StrSum.substr(0, indDot); var StrTER = StrSum.substr(0, indDot);
var StrCENT = StrSum.substr(indDot + 1); var StrCENT = StrSum.substr(indDot + 1);
} }
else { else
{
var StrTER = StrSum; var StrTER = StrSum;
var StrCENT = "0"; var StrCENT = "0";
} }
@ -185,11 +230,13 @@ function CreateTransaction(F, CheckErr, Run) {
var Coin = {SumCOIN:ParseNum(StrTER), SumCENT:ParseNum(StrCENT.substr(0, 9))}; var Coin = {SumCOIN:ParseNum(StrTER), SumCENT:ParseNum(StrCENT.substr(0, 9))};
var OperationID = 0; var OperationID = 0;
var Item = MapAccounts[FromID]; var Item = MapAccounts[FromID];
if (Item) { if(Item)
{
OperationID = Item.Value.OperationID; OperationID = Item.Value.OperationID;
} }
var AttachBody = []; var AttachBody = [];
if (AttachItem) { if(AttachItem)
{
AttachBody = AttachItem.Data.Body; AttachBody = AttachItem.Data.Body;
if(!AttachBody) if(!AttachBody)
AttachBody = []; AttachBody = [];
@ -197,54 +244,58 @@ function CreateTransaction(F, CheckErr, Run) {
var ToPubKeyArr = []; var ToPubKeyArr = [];
if(ToPubKey) if(ToPubKey)
ToPubKeyArr = GetArrFromHex(ToPubKey); ToPubKeyArr = GetArrFromHex(ToPubKey);
var TR = { var TR = {Type:111, Version:3, Reserve:0, FromID:FromID, OperationID:OperationID, To:[{PubKey:ToPubKeyArr, ID:ToID, SumCOIN:Coin.SumCOIN,
Type: 111, Version: 3, Reserve: 0, FromID: FromID, OperationID: OperationID, To: [{ SumCENT:Coin.SumCENT}], Description:Description, Body:AttachBody, Sign:CurrentTR.Sign, };
PubKey: ToPubKeyArr, ID: ToID, SumCOIN: Coin.SumCOIN,
SumCENT: Coin.SumCENT
}], Description: Description, Body: AttachBody, Sign: CurrentTR.Sign,
};
Object.defineProperties(TR, {bFindAcc:{configurable:true, writable:true, enumerable:false, value:bFindAcc}}); Object.defineProperties(TR, {bFindAcc:{configurable:true, writable:true, enumerable:false, value:bFindAcc}});
Object.defineProperties(TR, {Run:{configurable:true, writable:true, enumerable:false, value:Run}}); Object.defineProperties(TR, {Run:{configurable:true, writable:true, enumerable:false, value:Run}});
if (JSON.stringify(TR) === JSON.stringify(CurrentTR)) { if(JSON.stringify(TR) === JSON.stringify(CurrentTR))
{
if(F) if(F)
F(CurrentTR); F(CurrentTR);
return ; return ;
} }
CurrentTR = TR; CurrentTR = TR;
GetSignTransaction(TR, "", function(TR) { GetSignTransaction(TR, "", function (TR)
{
CurTransactionToForm(true); CurTransactionToForm(true);
if(F) if(F)
F(TR); F(TR);
}); });
}; };
function SignJSON(F) { function SignJSON(F)
{
if($("idSignJSON").disabled) if($("idSignJSON").disabled)
return ; return ;
var TR = GetTransactionFromJSON(); var TR = GetTransactionFromJSON();
if(!TR) if(!TR)
return ; return ;
CurrentTR = TR; CurrentTR = TR;
GetSignTransaction(TR, "", function(TR) { GetSignTransaction(TR, "", function (TR)
{
CurTransactionToForm(true); CurTransactionToForm(true);
if(F) if(F)
F(); F();
}); });
}; };
function CheckSending(bToStatus) { function CheckSending(bToStatus)
{
MaxBlockNum = GetCurrentBlockNumByTime(); MaxBlockNum = GetCurrentBlockNumByTime();
var CanSend = IsPrivateMode(); var CanSend = IsPrivateMode();
var StrButton = "Send"; var StrButton = "Send";
var StrButtonSign = "Sign JSON"; var StrButtonSign = "Sign JSON";
if (!CanSend) { if(!CanSend)
{
StrButton = " "; StrButton = " ";
StrButtonSign = " "; StrButtonSign = " ";
} }
if (CanSend) { if(CanSend)
{
var FromID = ParseNum($("idAccount").value); var FromID = ParseNum($("idAccount").value);
var Item = MapAccounts[FromID]; var Item = MapAccounts[FromID];
if (Item && Item.NextSendTime && Item.NextSendTime > MaxBlockNum) { if(Item && Item.NextSendTime && Item.NextSendTime > MaxBlockNum)
{
if(bToStatus) if(bToStatus)
SetStatus("Transaction was sending. Wait... (" + Item.LastTransactionText + ")"); SetStatus("Transaction was sending. Wait... (" + Item.LastTransactionText + ")");
CanSend = false; CanSend = false;
@ -258,26 +309,31 @@ function CheckSending(bToStatus) {
return CanSend; return CanSend;
}; };
function AddWhiteList() { function AddWhiteList()
{
var ToID = ParseNum($("idTo").value); var ToID = ParseNum($("idTo").value);
if(ToID && $("idWhiteOnSend").checked) if(ToID && $("idWhiteOnSend").checked)
Storage.setItem("White:" + ToID, 1); Storage.setItem("White:" + ToID, 1);
}; };
function SendMoneyBefore() { function SendMoneyBefore()
{
if($("idSendButton").disabled) if($("idSendButton").disabled)
return ; return ;
var ToID = ParseNum($("idTo").value); var ToID = ParseNum($("idTo").value);
var Item = MapAccounts[ToID]; var Item = MapAccounts[ToID];
if (Storage.getItem("White:" + ToID) || !$("idSumSend").value || Item && Item.MyAccount) { if(Storage.getItem("White:" + ToID) || !$("idSumSend").value || Item && Item.MyAccount)
{
SendMoney(); SendMoney();
} }
else { else
{
var CoinAmount = COIN_FROM_FLOAT($("idSumSend").value); var CoinAmount = COIN_FROM_FLOAT($("idSumSend").value);
var StrTo = " to " + GetAccountText(Item, ToID); var StrTo = " to " + GetAccountText(Item, ToID);
$("idWhiteOnSend").checked = 0; $("idWhiteOnSend").checked = 0;
$("idOnSendText").innerHTML = "<B style='color:#ff4534'>" + STRING_FROM_COIN(CoinAmount) + "</B> " + $("idCoinName").innerText + StrTo; $("idOnSendText").innerHTML = "<B style='color:#ff4534'>" + STRING_FROM_COIN(CoinAmount) + "</B> " + $("idCoinName").innerText + StrTo;
if ($("idSumSend").value >= 100000) { if($("idSumSend").value >= 100000)
{
$("idOnSendText").innerHTML += "<BR><DIV style='color: yellow;'>WARNING: You are about to send a very large amount!</DIV>"; $("idOnSendText").innerHTML += "<BR><DIV style='color: yellow;'>WARNING: You are about to send a very large amount!</DIV>";
} }
SetVisibleBlock("idBlockOnSend", 1); SetVisibleBlock("idBlockOnSend", 1);
@ -285,13 +341,16 @@ function SendMoneyBefore() {
} }
}; };
function SendMoney2() { function SendMoney2()
{
AddWhiteList(); AddWhiteList();
SendMoney(); SendMoney();
}; };
function SendMoney() { function SendMoney()
if (!CanSendTransaction) { {
if(!CanSendTransaction)
{
SetError("Can't Send transaction"); SetError("Can't Send transaction");
return ; return ;
} }
@ -302,9 +361,11 @@ function SendMoney() {
CreateTransaction(SendMoneyTR, true, ClearAttach); CreateTransaction(SendMoneyTR, true, ClearAttach);
}; };
function GetJSONFromTransaction(TR) { function GetJSONFromTransaction(TR)
{
var TR2 = JSON.parse(JSON.stringify(TR)); var TR2 = JSON.parse(JSON.stringify(TR));
for (var i = 0; i < TR2.To.length; i++) { for(var i = 0; i < TR2.To.length; i++)
{
var Item = TR2.To[i]; var Item = TR2.To[i];
Item.PubKey = GetHexFromArr(Item.PubKey); Item.PubKey = GetHexFromArr(Item.PubKey);
} }
@ -314,19 +375,24 @@ function GetJSONFromTransaction(TR) {
return Str; return Str;
}; };
function GetTransactionFromJSON() { function GetTransactionFromJSON()
{
var Str = $("idTransaction").value; var Str = $("idTransaction").value;
try { try
{
var TR = JSON.parse(Str); var TR = JSON.parse(Str);
} }
catch (e) { catch(e)
{
SetError(e); SetError(e);
return undefined; return undefined;
} }
for (var i = 0; i < TR.To.length; i++) { for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i]; var Item = TR.To[i];
Item.PubKey = GetArrFromHex(Item.PubKey); Item.PubKey = GetArrFromHex(Item.PubKey);
if (Item.SumTER && Item.SumCOIN === undefined) { if(Item.SumTER && Item.SumCOIN === undefined)
{
Item.SumCOIN = Item.SumTER; Item.SumCOIN = Item.SumTER;
delete Item.SumTER; delete Item.SumTER;
} }
@ -336,8 +402,10 @@ function GetTransactionFromJSON() {
return TR; return TR;
}; };
function SendMoneyJSON() { function SendMoneyJSON()
if (!CanSendTransaction) { {
if(!CanSendTransaction)
{
SetError("Can't Send transaction"); SetError("Can't Send transaction");
return ; return ;
} }
@ -347,22 +415,28 @@ function SendMoneyJSON() {
SendMoneyTR(TR); SendMoneyTR(TR);
}; };
function SignAndSendFromJSON() { function SignAndSendFromJSON()
{
SignJSON(SendMoneyJSON); SignJSON(SendMoneyJSON);
}; };
function GetTransactionText(TR, key) { function GetTransactionText(TR,key)
{
var Str; var Str;
if (TR) { if(TR)
if (TR.Type === TYPE_TRANSACTION_CREATE) { {
if(TR.Type === TYPE_TRANSACTION_CREATE)
{
Str = "New account " + TR.Name.substr(0, 20); Str = "New account " + TR.Name.substr(0, 20);
} }
else else
if (TR.Type === 111) { if(TR.Type === 111)
{
var MapItem = {}; var MapItem = {};
var ValueTotal = {SumCOIN:0, SumCENT:0}; var ValueTotal = {SumCOIN:0, SumCENT:0};
Str = "" + TR.FromID + "/" + TR.OperationID + " to "; Str = "" + TR.FromID + "/" + TR.OperationID + " to ";
for (var i = 0; i < TR.To.length; i++) { for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i]; var Item = TR.To[i];
if(Item.ID === TR.FromID || MapItem[Item.ID]) if(Item.ID === TR.FromID || MapItem[Item.ID])
continue; continue;
@ -370,7 +444,8 @@ function GetTransactionText(TR, key) {
ADD(ValueTotal, Item); ADD(ValueTotal, Item);
if(i === 0) if(i === 0)
Str += "["; Str += "[";
if (Str.length < 16) { if(Str.length < 16)
{
if(i > 0) if(i > 0)
Str += ","; Str += ",";
if(Item.ID || (Item.PubKey && Item.PubKey.length !== 66)) if(Item.ID || (Item.PubKey && Item.PubKey.length !== 66))
@ -386,7 +461,8 @@ function GetTransactionText(TR, key) {
Str += " " + (TR.Description.substr(0, 20)).replace(/\n/g, ""); Str += " " + (TR.Description.substr(0, 20)).replace(/\n/g, "");
} }
} }
else { else
{
if(key) if(key)
Str = key; Str = key;
else else
@ -395,15 +471,18 @@ function GetTransactionText(TR, key) {
return Str; return Str;
}; };
function SendMoneyTR(TR) { function SendMoneyTR(TR)
{
var Body = GetArrFromTR(TR); var Body = GetArrFromTR(TR);
WriteArr(Body, TR.Sign, 64); WriteArr(Body, TR.Sign, 64);
Body.length += 12; Body.length += 12;
SendTransaction(Body, TR, undefined, function(Err, TR, Body) { SendTransaction(Body, TR, undefined, function (Err,TR,Body)
{
if(Err) if(Err)
return ; return ;
var Item = MapAccounts[TR.FromID]; var Item = MapAccounts[TR.FromID];
if (Item) { if(Item)
{
var key = GetHexFromArr(sha3(Body)); var key = GetHexFromArr(sha3(Body));
var BlockNum = GetCurrentBlockNumByTime(); var BlockNum = GetCurrentBlockNumByTime();
Item.LastTransactionText = GetTransactionText(TR); Item.LastTransactionText = GetTransactionText(TR);
@ -414,31 +493,37 @@ function SendMoneyTR(TR) {
}); });
}; };
function ClearTransaction() { function ClearTransaction()
{
PayList = []; PayList = [];
ClearAttach(); ClearAttach();
CheckSendList(1); CheckSendList(1);
var arr = ["idAccount", "idTo", "idSumSend", "idDescription"]; var arr = ["idAccount", "idTo", "idSumSend", "idDescription"];
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
$(arr[i]).value = ""; $(arr[i]).value = "";
} }
SaveValues(); SaveValues();
CreateTransaction(); CreateTransaction();
}; };
function StartEditTransactionJSON() { function StartEditTransactionJSON()
{
var Item = $("idTransaction"); var Item = $("idTransaction");
Item.className = "smallbold"; Item.className = "smallbold";
}; };
function EditJSONTransaction() { function EditJSONTransaction()
{
var name = "edit_transaction"; var name = "edit_transaction";
var Item = $("idTransaction"); var Item = $("idTransaction");
if (IsVisibleBlock(name)) { if(IsVisibleBlock(name))
{
SetVisibleBlock(name, false); SetVisibleBlock(name, false);
Item.className = ""; Item.className = "";
} }
else { else
{
CreateTransaction(); CreateTransaction();
SetVisibleBlock(name, true); SetVisibleBlock(name, true);
Item.className = ""; Item.className = "";
@ -446,8 +531,10 @@ function EditJSONTransaction() {
}; };
var glNumPayCount = 0; var glNumPayCount = 0;
function GetInvoiceHTML(item, onclick, classstr) { function GetInvoiceHTML(item,onclick,classstr)
if (!item.num) { {
if(!item.num)
{
glNumPayCount++; glNumPayCount++;
item.num = glNumPayCount; item.num = glNumPayCount;
} }
@ -461,44 +548,53 @@ function GetInvoiceHTML(item, onclick, classstr) {
return "<button id='" + idname + "' onclick='" + onclick + "' class='" + classstr + "'>" + value + "</button>"; return "<button id='" + idname + "' onclick='" + onclick + "' class='" + classstr + "'>" + value + "</button>";
}; };
function AddSendList(item) { function AddSendList(item)
{
PayList.push({Data:item}); PayList.push({Data:item});
}; };
function CheckSendList(bRedraw) { function CheckSendList(bRedraw)
{
TitleWarning = PayList.length; TitleWarning = PayList.length;
if(AttachItem) if(AttachItem)
TitleWarning++; TitleWarning++;
var Str = Storage.getItem("InvoiceList"); var Str = Storage.getItem("InvoiceList");
if(!Str && !bRedraw) if(!Str && !bRedraw)
return ; return ;
if (!bRedraw) { if(!bRedraw)
{
SelectTab("TabSend"); SelectTab("TabSend");
} }
if (Str) { if(Str)
{
var arr = JSON.parse(Str); var arr = JSON.parse(Str);
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
AddSendList(arr[i]); AddSendList(arr[i]);
} }
Storage.setItem("InvoiceList", ""); Storage.setItem("InvoiceList", "");
} }
var idList = $("idSendList"); var idList = $("idSendList");
if (PayList.length) { if(PayList.length)
{
idList.innerHTML = "<DIV id='PaiListInfo'>Select the item you want to sign (pay) and send to blockchain:</DIV>"; idList.innerHTML = "<DIV id='PaiListInfo'>Select the item you want to sign (pay) and send to blockchain:</DIV>";
for (var i = 0; i < PayList.length; i++) { for(var i = 0; i < PayList.length; i++)
{
var item = PayList[i]; var item = PayList[i];
idList.innerHTML += GetInvoiceHTML(item, "UseInvoice(" + i + ")", "btinvoice"); idList.innerHTML += GetInvoiceHTML(item, "UseInvoice(" + i + ")", "btinvoice");
} }
if(AttachItem === undefined) if(AttachItem === undefined)
UseInvoice(0); UseInvoice(0);
} }
else { else
{
idList.innerHTML = ""; idList.innerHTML = "";
} }
}; };
setInterval(CheckSendList, 200); setInterval(CheckSendList, 200);
function UseInvoice(Num) { function UseInvoice(Num)
{
var item = PayList[Num]; var item = PayList[Num];
if(item.Data.From) if(item.Data.From)
$("idAccount").value = item.Data.From; $("idAccount").value = item.Data.From;
@ -511,14 +607,17 @@ function UseInvoice(Num) {
CheckSendList(1); CheckSendList(1);
}; };
function ClearAttach() { function ClearAttach()
{
AttachItem = undefined; AttachItem = undefined;
if($("idAttach")) if($("idAttach"))
$("idAttach").innerHTML = ""; $("idAttach").innerHTML = "";
}; };
function OpenAttach() { function OpenAttach()
if (AttachItem) { {
if(AttachItem)
{
var Data2 = JSON.parse(JSON.stringify(AttachItem.Data)); var Data2 = JSON.parse(JSON.stringify(AttachItem.Data));
if(Data2.Body) if(Data2.Body)
Data2.Body = GetHexFromArr(Data2.Body); Data2.Body = GetHexFromArr(Data2.Body);
@ -528,61 +627,75 @@ function OpenAttach() {
}; };
var CURRENCY, PUBKEY, NAME, SMART; var CURRENCY, PUBKEY, NAME, SMART;
function SendTrCreateAccWait(Currency, PubKey, Name, Smart) { function SendTrCreateAccWait(Currency,PubKey,Name,Smart)
{
CURRENCY = Currency; CURRENCY = Currency;
PUBKEY = PubKey; PUBKEY = PubKey;
NAME = Name; NAME = Name;
SMART = Smart; SMART = Smart;
setTimeout(function() { setTimeout(function ()
{
SendTrCreateAcc(CURRENCY, PUBKEY, NAME, 0, SMART, 0, 0); SendTrCreateAcc(CURRENCY, PUBKEY, NAME, 0, SMART, 0, 0);
}, 50); }, 50);
}; };
function SendTrCreateAcc(Currency, PubKey, Description, Adviser, Smart, bFindAcc, bAddToPay) { function SendTrCreateAcc(Currency,PubKey,Description,Adviser,Smart,bFindAcc,bAddToPay)
{
var TR = GetTrCreateAcc(Currency, PubKey, Description, Adviser, Smart); var TR = GetTrCreateAcc(Currency, PubKey, Description, Adviser, Smart);
var Body = GetBodyCreateAcc(TR); var Body = GetBodyCreateAcc(TR);
TR.bFindAcc = 1; TR.bFindAcc = 1;
if (bAddToPay) { if(bAddToPay)
var Item = { {
name: Description, To: 0, Amount: CONFIG_DATA.PRICE_DAO.NewAccount, Description: "Create acc: " + Description, Body: Body, var Item = {name:Description, To:0, Amount:CONFIG_DATA.PRICE_DAO.NewAccount, Description:"Create acc: " + Description, Body:Body,
}; };
AddToInvoiceList(Item); AddToInvoiceList(Item);
} }
else { else
{
SendTransaction(Body, TR); SendTransaction(Body, TR);
} }
$("idAccountName").value = ""; $("idAccountName").value = "";
CancelCreateAccount(); CancelCreateAccount();
}; };
function ChangeSmart(NumAccount, WasSmart) { function ChangeSmart(NumAccount,WasSmart)
if (!IsPrivateMode()) { {
if(!IsPrivateMode())
{
SetError("Pls, open wallet"); SetError("Pls, open wallet");
return 0; return 0;
} }
var Result = prompt("Enter smart number:", WasSmart); var Result = prompt("Enter smart number:", WasSmart);
if (Result !== null && Result != WasSmart) { if(Result !== null && Result != WasSmart)
{
var Smart = parseInt(Result); var Smart = parseInt(Result);
if (Smart) { if(Smart)
GetData("GetDappList", { StartNum: Smart, CountNum: 1 }, function(Data) { {
if (Data && Data.result && Data.arr.length === 1) { GetData("GetDappList", {StartNum:Smart, CountNum:1}, function (Data)
{
if(Data && Data.result && Data.arr.length === 1)
{
SetSmartToAccount(NumAccount, Smart); SetSmartToAccount(NumAccount, Smart);
} }
else { else
{
SetError("Error smart number"); SetError("Error smart number");
} }
}); });
} }
else { else
{
SetSmartToAccount(NumAccount, Smart); SetSmartToAccount(NumAccount, Smart);
} }
} }
}; };
function SetSmartToAccount(NumAccount, Smart) { function SetSmartToAccount(NumAccount,Smart)
{
var OperationID = 0; var OperationID = 0;
var Item = MapAccounts[NumAccount]; var Item = MapAccounts[NumAccount];
if (Item) { if(Item)
{
OperationID = Item.Value.OperationID; OperationID = Item.Value.OperationID;
} }
OperationID++; OperationID++;
@ -597,7 +710,8 @@ function SetSmartToAccount(NumAccount, Smart) {
SendTrArrayWithSign(Body, TR.Account, TR); SendTrArrayWithSign(Body, TR.Account, TR);
}; };
function CheckLengthAccDesription(name, Length) { function CheckLengthAccDesription(name,Length)
{
var Str = $(name).value.substr(0, Length + 1); var Str = $(name).value.substr(0, Length + 1);
var arr = toUTF8Array(Str); var arr = toUTF8Array(Str);
var Len = Length - arr.length; var Len = Length - arr.length;

View File

@ -9,20 +9,24 @@
*/ */
function SavePrivateKey() { function SavePrivateKey()
{
var Select = document.getElementById("idTypeKey"); var Select = document.getElementById("idTypeKey");
if (Select.value === "brain") { if(Select.value === "brain")
{
ConvertToPrivateKey(); ConvertToPrivateKey();
return ; return ;
} }
var Str = document.getElementById("idKeyNew").value; var Str = document.getElementById("idKeyNew").value;
Str = Str.trim(); Str = Str.trim();
if (Select.value === "private" && (Str.length !== 64 || !IsHexStr(Str))) { if(Select.value === "private" && (Str.length !== 64 || !IsHexStr(Str)))
{
SetError("Error: Length must 64 HEX chars. (Length=" + Str.length + ")"); SetError("Error: Length must 64 HEX chars. (Length=" + Str.length + ")");
return ; return ;
} }
else else
if (Select.value !== "private" && (Str.length !== 66 || Str.substr(0, 1) !== "0" || !IsHexStr(Str))) { if(Select.value !== "private" && (Str.length !== 66 || Str.substr(0, 1) !== "0" || !IsHexStr(Str)))
{
SetError("Error: Length must 66 HEX chars. (Length=" + Str.length + ")"); SetError("Error: Length must 66 HEX chars. (Length=" + Str.length + ")");
return ; return ;
} }
@ -31,8 +35,10 @@ function SavePrivateKey() {
else else
if(Select.value === "public" && PubKeyStr !== Str) if(Select.value === "public" && PubKeyStr !== Str)
SetStatus("Changed public key"); SetStatus("Changed public key");
GetData("SetWalletKey", Str, function(Data) { GetData("SetWalletKey", Str, function (Data)
if (Data && Data.result === 1) { {
if(Data && Data.result === 1)
{
if(Select.value === "private") if(Select.value === "private")
SelectStyle("styleContrast1"); SelectStyle("styleContrast1");
else else
@ -44,8 +50,10 @@ function SavePrivateKey() {
}); });
}; };
function CreateCheckPoint() { function CreateCheckPoint()
if (!ServerBlockNumDB || ServerBlockNumDB < 16) { {
if(!ServerBlockNumDB || ServerBlockNumDB < 16)
{
SetError("Not set ServerBlockNumDB"); SetError("Not set ServerBlockNumDB");
return ; return ;
} }
@ -53,27 +61,35 @@ function CreateCheckPoint() {
SetCheckPoint(BlockNum); SetCheckPoint(BlockNum);
}; };
function UseAutoCheckPoint() { function UseAutoCheckPoint()
{
var Set = $("idUseAutoCheckPoint").checked; var Set = $("idUseAutoCheckPoint").checked;
var Period = ParseNum($("idPeriodAutoCheckPoint").value); var Period = ParseNum($("idPeriodAutoCheckPoint").value);
GetData("SetAutoCheckPoint", { Set: Set, Period: Period }, function(Data) { GetData("SetAutoCheckPoint", {Set:Set, Period:Period}, function (Data)
if (Data) { {
if(Data)
{
SetStatus(Data.text, !Data.result); SetStatus(Data.text, !Data.result);
} }
}); });
}; };
function UseAutoCorrTime() { function UseAutoCorrTime()
GetData("SetAutoCorrTime", document.getElementById("idUseAutoCorrTime").checked, function(Data) { {
if (Data) { GetData("SetAutoCorrTime", document.getElementById("idUseAutoCorrTime").checked, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result); SetStatus(Data.text, !Data.result);
} }
}); });
}; };
function SetCodeVersionJSON() { function SetCodeVersionJSON()
{
var Data = JSON.parse(JSON.stringify(CONFIG_DATA.CODE_VERSION)); var Data = JSON.parse(JSON.stringify(CONFIG_DATA.CODE_VERSION));
if (!Data.BlockNum) { if(!Data.BlockNum)
{
Data.LevelUpdate = 160; Data.LevelUpdate = 160;
} }
Data.BlockNum = CONFIG_DATA.CurBlockNum; Data.BlockNum = CONFIG_DATA.CurBlockNum;
@ -87,10 +103,12 @@ function SetCodeVersionJSON() {
document.getElementById("idDevService").value = Str; document.getElementById("idDevService").value = Str;
}; };
function SetCorrTimeJSON() { function SetCorrTimeJSON()
{
var AutoDelta = parseInt(document.getElementById("idDevValue").value); var AutoDelta = parseInt(document.getElementById("idDevValue").value);
var Data = {Num:CONFIG_DATA.CurBlockNum, bUse:1, bAddTime:1}; var Data = {Num:CONFIG_DATA.CurBlockNum, bUse:1, bAddTime:1};
if (AutoDelta < 0) { if(AutoDelta < 0)
{
AutoDelta = - AutoDelta; AutoDelta = - AutoDelta;
Data.bAddTime = 0; Data.bAddTime = 0;
} }
@ -101,7 +119,8 @@ function SetCorrTimeJSON() {
document.getElementById("idDevService").value = Str; document.getElementById("idDevService").value = Str;
}; };
function SetNetConstJSON() { function SetNetConstJSON()
{
var Str = JSON.stringify(Data, "", 2); var Str = JSON.stringify(Data, "", 2);
document.getElementById("idDevService").value = Str; document.getElementById("idDevService").value = Str;
var Data = {MaxTrasactionLimit:CONFIG_DATA.MAX_TRANSACTION_LIMIT}; var Data = {MaxTrasactionLimit:CONFIG_DATA.MAX_TRANSACTION_LIMIT};
@ -109,132 +128,171 @@ function SetNetConstJSON() {
document.getElementById("idDevService").value = Str; document.getElementById("idDevService").value = Str;
}; };
function SetNewCodeVersion() { function SetNewCodeVersion()
try { {
try
{
var Data = JSON.parse(document.getElementById("idDevService").value); var Data = JSON.parse(document.getElementById("idDevService").value);
} }
catch (e) { catch(e)
{
SetError("Error format setting data"); SetError("Error format setting data");
return ; return ;
} }
Data.addrArr = GetArrFromHex(Data.addrArr); Data.addrArr = GetArrFromHex(Data.addrArr);
GetData("SetNewCodeVersion", Data, function(Data) { GetData("SetNewCodeVersion", Data, function (Data)
if (Data) { {
if(Data)
{
SetStatus(Data.text, !Data.result); SetStatus(Data.text, !Data.result);
} }
}); });
}; };
function StartTimeCorrect() { function StartTimeCorrect()
try { {
try
{
var Data = JSON.parse(document.getElementById("idDevService").value); var Data = JSON.parse(document.getElementById("idDevService").value);
} }
catch (e) { catch(e)
{
SetError("Error format setting data"); SetError("Error format setting data");
return ; return ;
} }
GetData("SetCheckDeltaTime", Data, function(Data) { GetData("SetCheckDeltaTime", Data, function (Data)
if (Data) { {
if(Data)
{
SetStatus(Data.text, !Data.result); SetStatus(Data.text, !Data.result);
} }
}); });
}; };
function StartNetConst() { function StartNetConst()
try { {
try
{
var Data = JSON.parse(document.getElementById("idDevService").value); var Data = JSON.parse(document.getElementById("idDevService").value);
} }
catch (e) { catch(e)
{
SetError("Error format setting data"); SetError("Error format setting data");
return ; return ;
} }
GetData("SetCheckNetConstant", Data, function(Data) { GetData("SetCheckNetConstant", Data, function (Data)
if (Data) { {
if(Data)
{
SetStatus(Data.text, !Data.result); SetStatus(Data.text, !Data.result);
} }
}); });
}; };
function RestartNode() { function RestartNode()
{
GetData("RestartNode", {}); GetData("RestartNode", {});
DoRestartWallet(); DoRestartWallet();
}; };
function UseAutoUpdate() { function UseAutoUpdate()
{
var Data = {USE_AUTO_UPDATE:document.getElementById("idAutoUpdate").checked, DoMining:1}; var Data = {USE_AUTO_UPDATE:document.getElementById("idAutoUpdate").checked, DoMining:1};
GetData("SaveConstant", Data, function(Data) { GetData("SaveConstant", Data, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
SetStatus("Save AutoUpdate: " + document.getElementById("idAutoUpdate").checked); SetStatus("Save AutoUpdate: " + document.getElementById("idAutoUpdate").checked);
} }
}); });
}; };
function UseMining() { function UseMining()
if (!MiningAccount) { {
if(!MiningAccount)
{
SetError("Not set mining account"); SetError("Not set mining account");
return ; return ;
} }
var Data = {USE_MINING:document.getElementById("idUseMining").checked, DoMining:1}; var Data = {USE_MINING:document.getElementById("idUseMining").checked, DoMining:1};
GetData("SaveConstant", Data, function(Data) { GetData("SaveConstant", Data, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
SetStatus("Save Mining: " + document.getElementById("idUseMining").checked); SetStatus("Save Mining: " + document.getElementById("idUseMining").checked);
} }
}); });
}; };
function SetPercentMining() { function SetPercentMining()
{
var Data = {POW_MAX_PERCENT:document.getElementById("idPercentMining").value}; var Data = {POW_MAX_PERCENT:document.getElementById("idPercentMining").value};
GetData("SaveConstant", Data, function(Data) { GetData("SaveConstant", Data, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
SetStatus("Save Mining percent: " + document.getElementById("idPercentMining").value + " %"); SetStatus("Save Mining percent: " + document.getElementById("idPercentMining").value + " %");
} }
}); });
}; };
function MiningSets() { function MiningSets()
{
var name = "edit_mining_set"; var name = "edit_mining_set";
if (IsVisibleBlock(name)) { if(IsVisibleBlock(name))
{
SetVisibleBlock(name, false); SetVisibleBlock(name, false);
} }
else { else
{
SetVisibleBlock(name, true); SetVisibleBlock(name, true);
document.getElementById("idMiningAccount").value = MiningAccount; document.getElementById("idMiningAccount").value = MiningAccount;
document.getElementById("idMiningAccount").focus(); document.getElementById("idMiningAccount").focus();
} }
}; };
function SaveMiningSet(Value) { function SaveMiningSet(Value)
{
SetVisibleBlock("edit_mining_set", false); SetVisibleBlock("edit_mining_set", false);
if (Value) { if(Value)
{
MiningAccount = Value; MiningAccount = Value;
} }
else { else
{
MiningAccount = ParseNum(document.getElementById("idMiningAccount").value); MiningAccount = ParseNum(document.getElementById("idMiningAccount").value);
} }
GetData("SetMining", MiningAccount, function(Data) { GetData("SetMining", MiningAccount, function (Data)
{
}); });
}; };
function CancalMiningSet() { function CancalMiningSet()
{
var name = "edit_mining_set"; var name = "edit_mining_set";
SetVisibleBlock(name, false); SetVisibleBlock(name, false);
}; };
var WasHistoryMaxNum; var WasHistoryMaxNum;
var WasLastNumSound = 0; var WasLastNumSound = 0;
function CheckNewMoney() { function CheckNewMoney()
{
return ; return ;
if(!$("idUseSoundHistory").checked) if(!$("idUseSoundHistory").checked)
return ; return ;
if(WasHistoryMaxNum === HistoryMaxNum || !ServerBlockNumDB) if(WasHistoryMaxNum === HistoryMaxNum || !ServerBlockNumDB)
return ; return ;
WasHistoryMaxNum = HistoryMaxNum; WasHistoryMaxNum = HistoryMaxNum;
GetData("GetHistoryAct", { StartNum: HistoryMaxNum - 40, CountNum: 40 }, function(Data) { GetData("GetHistoryAct", {StartNum:HistoryMaxNum - 40, CountNum:40}, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
var arr = Data.arr; var arr = Data.arr;
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
var Item = arr[i]; var Item = arr[i];
if (Item.Direct === "+" && Item.BlockNum > ServerBlockNumDB - 60 && Item.BlockNum < ServerBlockNumDB - 20 && Item.BlockNum > WasLastNumSound) { if(Item.Direct === "+" && Item.BlockNum > ServerBlockNumDB - 60 && Item.BlockNum < ServerBlockNumDB - 20 && Item.BlockNum > WasLastNumSound)
{
WasLastNumSound = Item.BlockNum; WasLastNumSound = Item.BlockNum;
$("sound_coin").play(); $("sound_coin").play();
} }
@ -243,41 +301,52 @@ function CheckNewMoney() {
}); });
}; };
function DoRestartWallet() { function DoRestartWallet()
{
SetStatus("<H1 align='center' style='color:blue'>Restarting program...</H1>"); SetStatus("<H1 align='center' style='color:blue'>Restarting program...</H1>");
if (!WasSetRestart) { if(!WasSetRestart)
{
WasSetRestart = 1; WasSetRestart = 1;
setTimeout(function() { setTimeout(function ()
{
window.location.reload(); window.location.reload();
}, 10 * 1000); }, 10 * 1000);
} }
}; };
function SetArrLog(arr) { function SetArrLog(arr)
{
var Str = ""; var Str = "";
var bFindAccount = 0; var bFindAccount = 0;
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
var Item = arr[i]; var Item = arr[i];
var tr_text = GetTransactionText(MapSendTransaction[Item.key], Item.key.substr(0, 16)); var tr_text = GetTransactionText(MapSendTransaction[Item.key], Item.key.substr(0, 16));
var info = Item.text; var info = Item.text;
if(tr_text) if(tr_text)
info += " (" + tr_text + ")"; info += " (" + tr_text + ")";
if (Item.final) { if(Item.final)
{
var TR = MapSendTransaction[Item.key]; var TR = MapSendTransaction[Item.key];
if (TR) { if(TR)
if (Item.text.indexOf("Add to blockchain") >= 0) { {
if (TR.bFindAcc) { if(Item.text.indexOf("Add to blockchain") >= 0)
{
if(TR.bFindAcc)
{
bFindAccount = 1; bFindAccount = 1;
TR.bFindAcc = 0; TR.bFindAcc = 0;
} }
if (TR.Run) { if(TR.Run)
{
TR.Run(TR); TR.Run(TR);
TR.Run = undefined; TR.Run = undefined;
} }
} }
} }
var Account = MapCheckTransaction[Item.key]; var Account = MapCheckTransaction[Item.key];
if (Account) { if(Account)
{
delete MapCheckTransaction[Item.key]; delete MapCheckTransaction[Item.key];
Account.NextSendTime = 0; Account.NextSendTime = 0;
} }
@ -286,28 +355,36 @@ function SetArrLog(arr) {
} }
SetStatusFromServer(Str); SetStatusFromServer(Str);
CheckSending(); CheckSending();
if (bFindAccount) { if(bFindAccount)
{
FindMyAccounts(); FindMyAccounts();
} }
}; };
function SetAutoMining() { function SetAutoMining()
setTimeout(function() { {
setTimeout(function ()
{
var Select = $("idAccount"); var Select = $("idAccount");
if (Select.options.length) { if(Select.options.length)
{
SaveMiningSet(Select.options[Select.options.length - 1].value); SaveMiningSet(Select.options[Select.options.length - 1].value);
} }
}, 100); }, 100);
}; };
function ViewNetworkMode() { function ViewNetworkMode()
if (IsVisibleBlock('idNetworkView')) { {
if(IsVisibleBlock('idNetworkView'))
{
SetVisibleBlock('idNetworkView', false); SetVisibleBlock('idNetworkView', false);
} }
else { else
{
SetVisibleBlock('idNetworkView', true); SetVisibleBlock('idNetworkView', true);
var Mode = CONFIG_DATA.CONSTANTS.NET_WORK_MODE; var Mode = CONFIG_DATA.CONSTANTS.NET_WORK_MODE;
if (!Mode) { if(!Mode)
{
Mode = {}; Mode = {};
Mode.UseDirectIP = true; Mode.UseDirectIP = true;
if(INTERNET_IP_FROM_STUN) if(INTERNET_IP_FROM_STUN)
@ -325,15 +402,18 @@ function ViewNetworkMode() {
} }
}; };
function SetNetworkParams(bRestart) { function SetNetworkParams(bRestart)
{
var Mode = {}; var Mode = {};
Mode.UseDirectIP = document.getElementById("idUseDirectIP").checked; Mode.UseDirectIP = document.getElementById("idUseDirectIP").checked;
Mode.ip = document.getElementById("idIP").value; Mode.ip = document.getElementById("idIP").value;
Mode.port = ParseNum(document.getElementById("idPort").value); Mode.port = ParseNum(document.getElementById("idPort").value);
Mode.NodeWhiteList = document.getElementById("idNodeWhiteList").value; Mode.NodeWhiteList = document.getElementById("idNodeWhiteList").value;
Mode.DoRestartNode = bRestart; Mode.DoRestartNode = bRestart;
GetData("SetNetMode", Mode, function(Data) { GetData("SetNetMode", Mode, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
SetStatus("Set net work params OK"); SetStatus("Set net work params OK");
SetVisibleBlock('idNetworkView', false); SetVisibleBlock('idNetworkView', false);
} }
@ -342,27 +422,35 @@ function SetNetworkParams(bRestart) {
DoRestartWallet(); DoRestartWallet();
}; };
function ViewConstant() { function ViewConstant()
if (IsVisibleBlock('idConstantView')) { {
if(IsVisibleBlock('idConstantView'))
{
SetVisibleBlock('idConstantView', false); SetVisibleBlock('idConstantView', false);
} }
else { else
{
SetVisibleBlock('idConstantView', true); SetVisibleBlock('idConstantView', true);
document.getElementById("idConstant").value = JSON.stringify(CONFIG_DATA.CONSTANTS, "", 2); document.getElementById("idConstant").value = JSON.stringify(CONFIG_DATA.CONSTANTS, "", 2);
} }
}; };
function SaveConstant(bRestart) { function SaveConstant(bRestart)
try { {
try
{
var Data = JSON.parse(document.getElementById("idConstant").value); var Data = JSON.parse(document.getElementById("idConstant").value);
} }
catch (e) { catch(e)
{
SetError("Error JSON format setting constant"); SetError("Error JSON format setting constant");
return ; return ;
} }
Data.DoRestartNode = bRestart; Data.DoRestartNode = bRestart;
GetData("SaveConstant", Data, function(Data) { GetData("SaveConstant", Data, function (Data)
if (Data && Data.result) { {
if(Data && Data.result)
{
SetStatus("Save Constant OK"); SetStatus("Save Constant OK");
SetVisibleBlock('idConstantView', false); SetVisibleBlock('idConstantView', false);
} }
@ -371,11 +459,14 @@ function SaveConstant(bRestart) {
DoRestartWallet(); DoRestartWallet();
}; };
function ViewRemoteParams() { function ViewRemoteParams()
if (IsVisibleBlock('idRemoteView')) { {
if(IsVisibleBlock('idRemoteView'))
{
SetVisibleBlock('idRemoteView', false); SetVisibleBlock('idRemoteView', false);
} }
else { else
{
SetVisibleBlock('idRemoteView', true); SetVisibleBlock('idRemoteView', true);
if(CONFIG_DATA.HTTPPort) if(CONFIG_DATA.HTTPPort)
document.getElementById("idHTTPPort").value = CONFIG_DATA.HTTPPort; document.getElementById("idHTTPPort").value = CONFIG_DATA.HTTPPort;
@ -383,14 +474,17 @@ function ViewRemoteParams() {
} }
}; };
function SetRemoteParams(bRestart) { function SetRemoteParams(bRestart)
{
var PrevHTTPPassword = HTTPPassword; var PrevHTTPPassword = HTTPPassword;
var HTTPPort = ParseNum(document.getElementById("idHTTPPort").value); var HTTPPort = ParseNum(document.getElementById("idHTTPPort").value);
var HTTPPassword = document.getElementById("idHTTPPassword").value; var HTTPPassword = document.getElementById("idHTTPPassword").value;
GetData("SetHTTPParams", { HTTPPort: HTTPPort, HTTPPassword: HTTPPassword, DoRestartNode: bRestart }, function(Data) { GetData("SetHTTPParams", {HTTPPort:HTTPPort, HTTPPassword:HTTPPassword, DoRestartNode:bRestart}, function (Data)
{
if(!PrevHTTPPassword && HTTPPassword) if(!PrevHTTPPassword && HTTPPassword)
window.location.reload(); window.location.reload();
else { else
{
SetVisibleBlock('idRemoteView', false); SetVisibleBlock('idRemoteView', false);
SetStatus("Set HTTP params OK"); SetStatus("Set HTTP params OK");
} }
@ -399,30 +493,37 @@ function SetRemoteParams(bRestart) {
DoRestartWallet(); DoRestartWallet();
}; };
function RewriteAllTransactions() { function RewriteAllTransactions()
{
DoBlockChainProcess("RewriteAllTransactions", "Rewrite all transactions", 0); DoBlockChainProcess("RewriteAllTransactions", "Rewrite all transactions", 0);
}; };
function RewriteTransactions() { function RewriteTransactions()
{
DoBlockChainProcess("RewriteTransactions", "Rewrite transactions on last %1 blocks", 1); DoBlockChainProcess("RewriteTransactions", "Rewrite transactions on last %1 blocks", 1);
}; };
function TruncateBlockChain() { function TruncateBlockChain()
{
DoBlockChainProcess("TruncateBlockChain", "Truncate last %1 blocks", 1); DoBlockChainProcess("TruncateBlockChain", "Truncate last %1 blocks", 1);
}; };
function ClearDataBase() { function ClearDataBase()
{
DoBlockChainProcess("ClearDataBase", "Clear DataBase", 0); DoBlockChainProcess("ClearDataBase", "Clear DataBase", 0);
}; };
function CleanChain() { function CleanChain()
{
DoBlockChainProcess("CleanChain", "Clean chain on last %1 blocks", 1); DoBlockChainProcess("CleanChain", "Clean chain on last %1 blocks", 1);
}; };
function DoBlockChainProcess(FuncName, Text, LastBlock) { function DoBlockChainProcess(FuncName,Text,LastBlock)
{
SaveValues(); SaveValues();
var Params = {}; var Params = {};
if (LastBlock) { if(LastBlock)
{
Params.BlockCount = ParseNum(document.getElementById("idBlockCount").value); Params.BlockCount = ParseNum(document.getElementById("idBlockCount").value);
Text = Text.replace("%1", Params.BlockCount); Text = Text.replace("%1", Params.BlockCount);
} }
@ -431,8 +532,10 @@ function DoBlockChainProcess(FuncName, Text, LastBlock) {
return ; return ;
SetVisibleBlock("idServerBlock", 1); SetVisibleBlock("idServerBlock", 1);
SetStatus("START: " + Text); SetStatus("START: " + Text);
GetData(FuncName, Params, function(Data) { GetData(FuncName, Params, function (Data)
if (Data) { {
if(Data)
{
SetStatus("FINISH: " + Text, !Data.result); SetStatus("FINISH: " + Text, !Data.result);
} }
}); });

View File

@ -18,37 +18,23 @@ var StartTimeConnecting = 0;
var ConnectedCount = 0; var ConnectedCount = 0;
var NETWORK = "TERA-MAIN"; var NETWORK = "TERA-MAIN";
var ServerMap = {}; var ServerMap = {};
var ServerMainMap = { var ServerMainMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "t2.teraexplorer.com":{"ip":"t2.teraexplorer.com",
"127.0.0.1": { "ip": "127.0.0.1", "port": 80, "Name": "LOCAL" }, "terafoundation.org": { "port":443, "Name":"t2.teraexplorer.com", "System":1}, "t3.teraexplorer.com":{"ip":"t3.teraexplorer.com", "port":443, "Name":"t3.teraexplorer.com",
"ip": "terafoundation.org", "System":1}, "t4.teraexplorer.com":{"ip":"t4.teraexplorer.com", "port":443, "Name":"t4.teraexplorer.com", "System":1}, "t5.teraexplorer.com":{"ip":"t5.teraexplorer.com",
"port": 443, "Name": "TERA", "System": 1 "port":443, "Name":"t5.teraexplorer.com", "System":1}, "dappsgate.com":{"ip":"dappsgate.com", "port":80, "Name":"SUPPORT2",
}, "dappsgate.com": { "ip": "dappsgate.com", "port": 80, "Name": "SUPPORT2", "System": 1 }, "t1.teraexplorer.com": { "System":1}, "t1.teraexplorer.com":{"ip":"t1.teraexplorer.com", "port":80, "Name":"t1.teraexplorer.com", "System":1}, };
"ip": "t1.teraexplorer.com", var ServerTestMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "dappsgate.com":{"ip":"dappsgate.com", "port":88,
"port": 80, "Name": "t1.teraexplorer.com", "System": 1 "Name":"SUPPORT2", "System":1}, };
}, "t2.teraexplorer.com": {
"ip": "t2.teraexplorer.com", "port": 80, "Name": "t2.teraexplorer.com",
"System": 1
}, "t3.teraexplorer.com": { "ip": "t3.teraexplorer.com", "port": 80, "Name": "t3.teraexplorer.com", "System": 1 }, "t4.teraexplorer.com": {
"ip": "t4.teraexplorer.com",
"port": 80, "Name": "t4.teraexplorer.com", "System": 1
}, "t5.teraexplorer.com": {
"ip": "t5.teraexplorer.com", "port": 80, "Name": "t5.teraexplorer.com",
"System": 1
},
};
var ServerTestMap = {
"127.0.0.1": { "ip": "127.0.0.1", "port": 80, "Name": "LOCAL" }, "dappsgate.com": {
"ip": "dappsgate.com", "port": 88,
"Name": "SUPPORT2", "System": 1
},
};
function StartWebWallet() { function StartWebWallet()
if (NETWORK === "TERA-TEST2") { {
if(NETWORK === "TERA-TEST2")
{
MIN_SUM_POWER = 0; MIN_SUM_POWER = 0;
ServerMap = ServerTestMap; ServerMap = ServerTestMap;
} }
else { else
{
MIN_SUM_POWER = COUNT_BLOCK_PROOF * 35; MIN_SUM_POWER = COUNT_BLOCK_PROOF * 35;
ServerMap = ServerMainMap; ServerMap = ServerMainMap;
} }
@ -57,11 +43,14 @@ function StartWebWallet() {
ConnectWebWallet(); ConnectWebWallet();
}; };
function OnInitWebWallet() { function OnInitWebWallet()
{
var str = Storage.getItem(NETWORK + "NodesArrayList"); var str = Storage.getItem(NETWORK + "NodesArrayList");
if (str) { if(str)
{
var arr = JSON.parse(str); var arr = JSON.parse(str);
for (var i = 0; i < arr.length; i++) { for(var i = 0; i < arr.length; i++)
{
var Item = ServerMap[arr[i].ip]; var Item = ServerMap[arr[i].ip];
if(Item && Item.System) if(Item && Item.System)
continue; continue;
@ -70,38 +59,46 @@ function OnInitWebWallet() {
} }
}; };
function SaveServerMap() { function SaveServerMap()
{
var arr = []; var arr = [];
for (var key in ServerMap) { for(var key in ServerMap)
{
var Item = ServerMap[key]; var Item = ServerMap[key];
if (Item.SumPower >= MIN_SUM_POWER) { if(Item.SumPower >= MIN_SUM_POWER)
{
arr.push({ip:Item.ip, port:Item.port}); arr.push({ip:Item.ip, port:Item.port});
} }
} }
Storage.setItem(NETWORK + "NodesArrayList", JSON.stringify(arr)); Storage.setItem(NETWORK + "NodesArrayList", JSON.stringify(arr));
}; };
function SetStatus(Str) { function SetStatus(Str)
{
var id = $("idStatus"); var id = $("idStatus");
id.innerHTML = Str; id.innerHTML = Str;
if(Str) if(Str)
console.log(id.innerText); console.log(id.innerText);
}; };
function SetError(Str, bNoSound) { function SetError(Str,bNoSound)
{
SetStatus("<DIV align='left' style='color:red'><B>" + Str + "</B></DIV>"); SetStatus("<DIV align='left' style='color:red'><B>" + Str + "</B></DIV>");
}; };
var CountConnect = 0; var CountConnect = 0;
var CountWallet = 0; var CountWallet = 0;
function ConnectWebWallet() { function ConnectWebWallet()
{
StartTimeConnecting = Date.now(); StartTimeConnecting = Date.now();
ConnectedCount = 0; ConnectedCount = 0;
for (var key in ServerMap) { for(var key in ServerMap)
{
var Item = ServerMap[key]; var Item = ServerMap[key];
Item.SendHandShake = 0; Item.SendHandShake = 0;
} }
if (window.BrowserIE && !IsLocalClient()) { if(window.BrowserIE && !IsLocalClient())
{
MainServer = undefined; MainServer = undefined;
return ; return ;
} }
@ -113,10 +110,12 @@ function ConnectWebWallet() {
}; };
var Stage = 0; var Stage = 0;
function LoopHandShake() { function LoopHandShake()
{
Stage++; Stage++;
SetStatus("Connecting: " + Stage + "..."); SetStatus("Connecting: " + Stage + "...");
for (var key in ServerMap) { for(var key in ServerMap)
{
var Item = ServerMap[key]; var Item = ServerMap[key];
if(Item.SendHandShake || !Item.port) if(Item.SendHandShake || !Item.port)
continue; continue;
@ -127,7 +126,8 @@ function LoopHandShake() {
} }
}; };
function DoNodeList(Item) { function DoNodeList(Item)
{
console.log(GetProtocolServerPath(Item) + "/GetNodeList"); console.log(GetProtocolServerPath(Item) + "/GetNodeList");
if(window.location.protocol === "https:" && Item.port !== 443) if(window.location.protocol === "https:" && Item.port !== 443)
return ; return ;
@ -135,33 +135,41 @@ function DoNodeList(Item) {
return ; return ;
SetStatus("Try: " + Item.ip + ":" + Item.port); SetStatus("Try: " + Item.ip + ":" + Item.port);
Item.SendHandShake = 1; Item.SendHandShake = 1;
GetData(GetProtocolServerPath(Item) + "/GetNodeList", {}, function(Data) { GetData(GetProtocolServerPath(Item) + "/GetNodeList", {}, function (Data)
if (Data && Data.result && Data.NETWORK === NETWORK && Data.VersionNum >= MIN_VERSION) { {
if(Data && Data.result && Data.NETWORK === NETWORK && Data.VersionNum >= MIN_VERSION)
{
ConnectedCount++; ConnectedCount++;
Item.GetHandShake = 1; Item.GetHandShake = 1;
Item.BlockChain = Data.BlockChain; Item.BlockChain = Data.BlockChain;
SetStatus("Get: " + Item.ip + ":" + Item.port); SetStatus("Get: " + Item.ip + ":" + Item.port);
var bWas = 0; var bWas = 0;
for (var i = 0; i < Data.arr.length; i++) { for(var i = 0; i < Data.arr.length; i++)
{
var Node = Data.arr[i]; var Node = Data.arr[i];
if (!ServerMap[Node.ip] && Node.port) { if(!ServerMap[Node.ip] && Node.port)
{
ServerMap[Node.ip] = Node; ServerMap[Node.ip] = Node;
console.log("New: " + Node.ip + ":" + Node.port); console.log("New: " + Node.ip + ":" + Node.port);
bWas = 1; bWas = 1;
} }
} }
if (bWas && ConnectedCount < MaxConnectedCount && new Date() - StartTimeConnecting < MaxTimeConnecting) { if(bWas && ConnectedCount < MaxConnectedCount && new Date() - StartTimeConnecting < MaxTimeConnecting)
{
setTimeout(LoopHandShake, 100); setTimeout(LoopHandShake, 100);
} }
} }
}); });
}; };
function LoopWalletInfo() { function LoopWalletInfo()
{
SetStatus("Get wallets info..."); SetStatus("Get wallets info...");
for (var key in ServerMap) { for(var key in ServerMap)
{
var Item = ServerMap[key]; var Item = ServerMap[key];
if (Item.port) { if(Item.port)
{
CountWallet++; CountWallet++;
if(window.BrowserIE && CountWallet > 4) if(window.BrowserIE && CountWallet > 4)
break; break;
@ -171,15 +179,18 @@ function LoopWalletInfo() {
setTimeout(FindLider, 500); setTimeout(FindLider, 500);
}; };
function DoWalletInfo(Item) { function DoWalletInfo(Item)
{
if(window.location.protocol === "https:" && Item.port !== 443) if(window.location.protocol === "https:" && Item.port !== 443)
return ; return ;
if(Item.port === 443 && IsIPAddres(Item.ip)) if(Item.port === 443 && IsIPAddres(Item.ip))
return ; return ;
Item.StartTime = Date.now(); Item.StartTime = Date.now();
Item.SendWalletInfo = 1; Item.SendWalletInfo = 1;
GetData(GetProtocolServerPath(Item) + "/GetCurrentInfo", { BlockChain: 1 }, function(Data) { GetData(GetProtocolServerPath(Item) + "/GetCurrentInfo", {BlockChain:1}, function (Data)
if (Data && Data.result && Data.BlockChain && Data.NETWORK === NETWORK) { {
if(Data && Data.result && Data.BlockChain && Data.NETWORK === NETWORK)
{
Item.Name = Data.NODES_NAME; Item.Name = Data.NODES_NAME;
Item.GetWalletInfo = 1; Item.GetWalletInfo = 1;
Item.DeltaTime = new Date() - Item.StartTime; Item.DeltaTime = new Date() - Item.StartTime;
@ -190,18 +201,22 @@ function DoWalletInfo(Item) {
}); });
}; };
function FindLider() { function FindLider()
{
MainServer = undefined; MainServer = undefined;
var Arr = []; var Arr = [];
var MapSumPower = {}; var MapSumPower = {};
for (var key in ServerMap) { for(var key in ServerMap)
{
var Item = ServerMap[key]; var Item = ServerMap[key];
if (Item.GetWalletInfo && Item.BlockChain) { if(Item.GetWalletInfo && Item.BlockChain)
{
var arr = Item.BlockChain; var arr = Item.BlockChain;
if(arr.data) if(arr.data)
arr = arr.data; arr = arr.data;
Item.SumPower = CalcPowFromBlockChain(arr); Item.SumPower = CalcPowFromBlockChain(arr);
if (Item.SumPower < MIN_SUM_POWER) { if(Item.SumPower < MIN_SUM_POWER)
{
console.log("Skip: " + Item.ip + ":" + Item.port + " SumPower(" + Item.SumPower + ") < MIN_SUM_POWER(" + MIN_SUM_POWER + ")"); console.log("Skip: " + Item.ip + ":" + Item.port + " SumPower(" + Item.SumPower + ") < MIN_SUM_POWER(" + MIN_SUM_POWER + ")");
continue; continue;
} }
@ -212,18 +227,23 @@ function FindLider() {
} }
} }
var Max = 0, MaxKey; var Max = 0, MaxKey;
for (var key in MapSumPower) { for(var key in MapSumPower)
if (MapSumPower[key] >= Max) { {
if(MapSumPower[key] >= Max)
{
Max = MapSumPower[key]; Max = MapSumPower[key];
MaxKey = parseInt(key); MaxKey = parseInt(key);
} }
} }
Arr.sort(function(a, b) { Arr.sort(function (a,b)
{
return a.DeltaTime - b.DeltaTime; return a.DeltaTime - b.DeltaTime;
}); });
for (var i = 0; i < Arr.length; i++) { for(var i = 0; i < Arr.length; i++)
{
var Item = Arr[i]; var Item = Arr[i];
if (Item.SumPower === MaxKey) { if(Item.SumPower === MaxKey)
{
SetStatus("Find " + Item.ip + ":" + Item.port + " with pow=" + Item.SumPower + "/" + MaxKey + " ping=" + Item.DeltaTime); SetStatus("Find " + Item.ip + ":" + Item.port + " with pow=" + Item.SumPower + "/" + MaxKey + " ping=" + Item.DeltaTime);
MainServer = Item; MainServer = Item;
SaveServerMap(); SaveServerMap();
@ -233,18 +253,22 @@ function FindLider() {
OnFindServer(); OnFindServer();
}; };
function CalcPowFromBlockChain(BufRead) { function CalcPowFromBlockChain(BufRead)
{
var Sum = 0; var Sum = 0;
var Arr = GetBlockArrFromBuffer(BufRead); var Arr = GetBlockArrFromBuffer(BufRead);
if (Arr.length === COUNT_BLOCK_PROOF) { if(Arr.length === COUNT_BLOCK_PROOF)
for (var i = 0; i < Arr.length; i++) { {
for(var i = 0; i < Arr.length; i++)
{
Sum += Arr[i].Power; Sum += Arr[i].Power;
} }
} }
return Sum; return Sum;
}; };
function SetAllSum() { function SetAllSum()
{
var Item = MapAccounts[$("idAccount").value]; var Item = MapAccounts[$("idAccount").value];
if(Item) if(Item)
$("idSumSend").value = FLOAT_FROM_COIN(Item.Value).toStringF(); $("idSumSend").value = FLOAT_FROM_COIN(Item.Value).toStringF();

View File

@ -42,7 +42,7 @@
{ {
if(e.keyCode===27) if(e.keyCode===27)
{ {
window.close(); ClosePage();
} }
}; };
@ -53,6 +53,15 @@
}, false); }, false);
if (window.addEventListener)
{
window.addEventListener("message", OnMessage);
} else
{
// IE8
window.attachEvent("onmessage", OnMessage);
}
} }
function ViewBlock(BlockNum) function ViewBlock(BlockNum)
{ {
@ -74,14 +83,49 @@
{ {
} }
var FrameData;
function ClosePage()
{
if(FrameData && window.parent)
{
FrameData.cmd="Close";
window.parent.postMessage(FrameData, "*");
}
else
window.close();
}
function OnMessage(event)
{
var Data=event.data;
if(!Data || typeof Data!=="object")
return;
FrameData=Data;
if(Data.BlockNum)
{
document.getElementById("idViewBlockNum").value=Data.BlockNum;
ViewBlock();
$("MTabWelcome").className+=" back-link";
}
}
function DoBackPage()
{
if(FrameData)
ClosePage()
}
</script> </script>
</head> </head>
<body> <body>
<header class="header"> <header class="header">
<div class="header__wrapper"> <div class="header__wrapper">
<div class="header__logo header__logo--history"> <div class="header__logo header__logo--history">
<a onclick="" class="header__logo-link" id="MTabWelcome"> <a onclick="DoBackPage()" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="/PIC/TeraLogo.svg" alt="TERA Foundation"> <img class="main-logo" src="./PIC/TeraLogo.svg" alt="TERA Foundation">
<p class="header__logo-name">Blockviewer</p> <p class="header__logo-name">Blockviewer</p>
</a> </a>
</div> </div>
@ -96,7 +140,6 @@
<section class="history-page" id="idTransactionBlock" style="display: block"> <section class="history-page" id="idTransactionBlock" style="display: block">
<div class="history__text-block"> <div class="history__text-block">
<div class="history-page__id" > <div class="history-page__id" >
<!--<a class="back-link back-link&#45;&#45;history" onclick="SelectTab('TabKeySet')"><span>Accounts</span></a>-->
Transactions on block: <INPUT class="history-page__id-count" type="number" id="idViewBlockNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewBlock()"> Transactions on block: <INPUT class="history-page__id-count" type="number" id="idViewBlockNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewBlock()">
</div> </div>
<BR> <BR>

View File

@ -68,11 +68,13 @@
$("idConsoleText").value=Data.Code; $("idConsoleText").value=Data.Code;
$("idConsoleSend").value=Data.Type; $("idConsoleSend").value=Data.Type;
$("idProcessTX").checked=Data.ProcessTX; $("idProcessTX").checked=Data.ProcessTX;
$("idProcessWEB").checked=Data.ProcessWEB;
} }
else else
{ {
$("idConsoleText").value=Data; $("idConsoleText").value=Data;
$("idProcessTX").checked=0; $("idProcessTX").checked=0;
$("idProcessWEB").checked=0;
$("idConsoleSend").value="ServerCode"; $("idConsoleSend").value="ServerCode";
} }
if(bRun) if(bRun)
@ -99,7 +101,7 @@
if(Name) if(Name)
{ {
var Data={Code:$("idConsoleText").value,Type:$("idConsoleSend").value,ProcessTX:$("idProcessTX").checked}; var Data={Code:$("idConsoleText").value,Type:$("idConsoleSend").value,ProcessTX:$("idProcessTX").checked,ProcessWEB:$("idProcessWEB").checked};
CodeList[Name]=Data; CodeList[Name]=Data;
} }
@ -206,8 +208,10 @@
function SendServerCode(Value) function SendServerCode(Value)
{ {
var bProcessTX = $("idProcessTX").checked; var bProcessTX = $("idProcessTX").checked;
var bProcessWEB = $("idProcessWEB").checked;
SetStatus(""); SetStatus("");
GetData("SendDirectCode",{Code:Value,TX:bProcessTX }, function (Data) GetData("SendDirectCode",{Code:Value,TX:bProcessTX,WEB:bProcessWEB }, function (Data)
{ {
if(Data) if(Data)
{ {
@ -422,6 +426,7 @@
$("idProcessTX").checked=(localStorage["idConsoleProcessTX"]==="true"); $("idProcessTX").checked=(localStorage["idConsoleProcessTX"]==="true");
$("idProcessWEB").checked=(localStorage["idConsoleProcessWEB"]==="true");
if(localStorage["idConsolePeriodRun"]) if(localStorage["idConsolePeriodRun"])
$("idPeriodRun").value=localStorage["idConsolePeriodRun"]; $("idPeriodRun").value=localStorage["idConsolePeriodRun"];
} }
@ -437,6 +442,8 @@
//localStorage["idConsoleSendAll"]=$("idSendAll").checked; //localStorage["idConsoleSendAll"]=$("idSendAll").checked;
localStorage["idConsoleProcessTX"]=$("idProcessTX").checked; localStorage["idConsoleProcessTX"]=$("idProcessTX").checked;
localStorage["idConsoleProcessWEB"]=$("idProcessWEB").checked;
localStorage["idConsolePeriodRun"]=$("idPeriodRun").value; localStorage["idConsolePeriodRun"]=$("idPeriodRun").value;
} }
@ -498,6 +505,7 @@
<INPUT type="button" onclick="StartSendServerPeriod()" class="bt btdoit" id="idBtRun2" value="Run every"> <INPUT type="button" onclick="StartSendServerPeriod()" class="bt btdoit" id="idBtRun2" value="Run every">
<INPUT type="number" id="idPeriodRun" style="width: 50px;" onchange="SaveValues();" value="1">sec <INPUT type="number" id="idPeriodRun" style="width: 50px;" onchange="SaveValues();" value="1">sec
TX process:<INPUT type="checkbox" id="idProcessTX"> TX process:<INPUT type="checkbox" id="idProcessTX">
WEB process:<INPUT type="checkbox" id="idProcessWEB">
<BR> <BR>

View File

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

View File

@ -61,7 +61,7 @@
{ {
if(e.keyCode===27) if(e.keyCode===27)
{ {
window.close(); ClosePage();
} }
}; };
@ -72,6 +72,15 @@
}, false); }, false);
if (window.addEventListener)
{
window.addEventListener("message", OnMessage);
} else
{
// IE8
window.attachEvent("onmessage", OnMessage);
}
} }
function OnChangeAccount() function OnChangeAccount()
{ {
@ -128,12 +137,6 @@
function ViewBegin() function ViewBegin()
{ {
ViewHistory(1); ViewHistory(1);
// CurPage=0;
// var Item=ArrPos[CurPage];
// if(Item)
// {
// ViewHistory(0,Item.First);
// }
} }
function ViewPrev() function ViewPrev()
{ {
@ -192,14 +195,66 @@
return ""; return "";
return Str; return Str;
} }
var FrameData;
function ClosePage()
{
if(FrameData && window.parent)
{
FrameData.cmd="Close";
window.parent.postMessage(FrameData, "*");
}
else
window.close();
}
function OnMessage(event)
{
var Data=event.data;
if(!Data || typeof Data!=="object")
return;
FrameData=Data;
if(Data.Account)
{
AccountID=Data.Account;
document.getElementById("idViewAccountID").value=AccountID;
ViewHistory(1)
$("MTabWelcome").className+=" back-link";
}
}
function DoBackPage()
{
if(FrameData)
ClosePage()
}
function OpenBlockViewerPage(Num)
{
if(FrameData && window.parent)
{
FrameData.cmd="OpenBlockViewerPage";
FrameData.BlockNum=Num;
window.parent.postMessage(FrameData, "*");
}
else
{
window.open("./blockviewer.html#"+Num);
return;
}
}
</script> </script>
</head> </head>
<body> <body>
<header class="header"> <header class="header">
<div class="header__wrapper"> <div class="header__wrapper">
<div class="header__logo header__logo--history"> <div class="header__logo header__logo--history">
<a onclick="" class="header__logo-link" id="MTabWelcome"> <a onclick="DoBackPage()" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="/PIC/TeraLogo.svg" alt="TERA Foundation"> <img class="main-logo" src="./PIC/TeraLogo.svg" alt="TERA Foundation">
<p class="header__logo-name">History</p> <p class="header__logo-name">History</p>
</a> </a>
</div> </div>

View File

@ -2,7 +2,6 @@
<html> <html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>TERA</title> <title>TERA</title>
@ -320,6 +319,7 @@
<script> <script>
//Pagination //Pagination
var CountViewRows=20; var CountViewRows=20;
var DefAccounts={BlockName:"idPaginationAccount", NumName:"idViewAccountNum", TabName:"grid_accounts_all",APIName:"GetAccountList",Param3:"",FilterName:"idViewAccountFilter",TotalSum:"idTotalSum"}; var DefAccounts={BlockName:"idPaginationAccount", NumName:"idViewAccountNum", TabName:"grid_accounts_all",APIName:"GetAccountList",Param3:"",FilterName:"idViewAccountFilter",TotalSum:"idTotalSum"};
@ -391,6 +391,7 @@
<script> <script>
/*Get data from server Get data from server Get data from server Get data from server Get data from server */ /*Get data from server Get data from server Get data from server Get data from server Get data from server */
function UpdatesConfigData() function UpdatesConfigData()
{ {
@ -642,6 +643,8 @@
<script> <script>
//LIB //LIB
function ConfirmationFromBlock(BlockNum) function ConfirmationFromBlock(BlockNum)
{ {
@ -1123,6 +1126,7 @@
if(CurBlockNum<ServerBlockNumDB+8) if(CurBlockNum<ServerBlockNumDB+8)
CurBlockNum=ServerBlockNumDB; CurBlockNum=ServerBlockNumDB;
var WasArr=0; var WasArr=0;
var Arr=[]; var Arr=[];
for(var i=ArrInfo.length-1;i>=0;i--) for(var i=ArrInfo.length-1;i>=0;i--)
@ -1141,6 +1145,7 @@
{ {
if(!Item.PowerArr[n])//есть нули if(!Item.PowerArr[n])//есть нули
{ {
//ToLog("n="+n+" Item.BlockNum1="+Item.BlockNum1);
MustUpdate=1; MustUpdate=1;
break; break;
} }
@ -1150,7 +1155,6 @@
var DeltaTime=Math.abs(Item.TimeBlockNum-TimeBlockNum); var DeltaTime=Math.abs(Item.TimeBlockNum-TimeBlockNum);
if(DeltaTime>Item.Delta/20) if(DeltaTime>Item.Delta/20)
{ {
//ToLog("i="+i+" DeltaTime="+DeltaTime+" > "+(Item.Delta/20))
MustUpdate=1; MustUpdate=1;
} }
} }
@ -1307,12 +1311,15 @@
</script> </script>
<style type="text/css"> <style type="text/css">
table.password {
table.password
{
border-collapse: collapse; border-collapse: collapse;
width: 400px; width: 400px;
} }
#idOpenWallet { #idOpenWallet
{
z-index:1001; z-index:1001;
position:relative; position:relative;
float: right; float: right;
@ -1335,8 +1342,8 @@
cursor: pointer; cursor: pointer;
} }
#idBlockPasswordSet, #idBlockPasswordSet,#idBlockPasswordGet
#idBlockPasswordGet { {
z-index:1000; z-index:1000;
position:absolute; position:absolute;
top:150px; top:150px;
@ -1352,10 +1359,13 @@
background-repeat: no-repeat; background-repeat: no-repeat;
} }
</style> </style>
<style id="idHintStyle"> <style id="idHintStyle">
th.hint:hover:after { th.hint:hover:after
{
position: absolute; position: absolute;
content: attr(data-name); content: attr(data-name);
background: #f7efa3; background: #f7efa3;
@ -1372,7 +1382,8 @@
</script> </script>
<style> <style>
.red { .red
{
color:red; color:red;
} }
</style> </style>
@ -1384,18 +1395,10 @@
<table id="TabHeader"> <table id="TabHeader">
<tr> <tr>
<th> <th><DIV id="MTabAccounts" onclick="SelectTab('TabAccounts')" class="bttab">CONFIG</DIV></th>
<DIV id="MTabAccounts" onclick="SelectTab('TabAccounts')" class="bttab">配置</DIV> <th><DIV id="MTabSend" onclick="SelectTab('TabSend')" class="bttab">SEND</DIV></th>
</th> <th><DIV id="MTabDapps" onclick="SelectTab('TabDapps')" class="bttab">DApps</DIV></th>
<th> <th><DIV id="MTabExplorer" onclick="SelectTab('TabExplorer')" class="bttab">EXPLORER</DIV></th>
<DIV id="MTabSend" onclick="SelectTab('TabSend')" class="bttab">发送</DIV>
</th>
<th>
<DIV id="MTabDapps" onclick="SelectTab('TabDapps')" class="bttab">分布式应用</DIV>
</th>
<th>
<DIV id="MTabExplorer" onclick="SelectTab('TabExplorer')" class="bttab">浏览器</DIV>
</th>
</tr> </tr>
</table> </table>
@ -1409,21 +1412,22 @@
<DIV id="idNodeUpdateMiningStatus" style="display: block"> <DIV id="idNodeUpdateMiningStatus" style="display: block">
<DIV style="float: left"> <DIV style="float: left">
<input type="checkbox" class="checkbox" id="idAutoUpdate" onchange = "UseAutoUpdate()"/> <input type="checkbox" class="checkbox" id="idAutoUpdate" onchange = "UseAutoUpdate()"/>
<label for="idAutoUpdate">AutoUpdate</label> <label for="idAutoUpdate">Autoupdate</label>
</DIV> </DIV>
<DIV style="float: left"> <DIV style="float: left">
<input type="checkbox" class="checkbox" id="idUseMining" onchange = "UseMining()"/> <input type="checkbox" class="checkbox" id="idUseMining" onchange = "UseMining()"/>
<label for="idUseMining">UseMining</label> <label for="idUseMining">Mining</label>
</DIV> </DIV>
<DIV style="float: left;display: none" id="idMiningParams"> <DIV style="float: left;display: none" id="idMiningParams">
<DIV style="float: left; color: blue;">CPU <DIV style="float: left; color: blue;">CPU use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV>
use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV> <DIV style="float: left; margin: 2px 0 0 8px;" id="idStatusMining"></DIV>
</DIV> </DIV>
</DIV> </DIV>
<DIV id="idDevelopService" style="display: none"> <DIV id="idDevelopService" style="display: none">
<BR> <BR>
<INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')" class="btdoit bt" value="DEV SERVICE"> <INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')"
<DIV id="idDevelopServiceView"> class="btdoit bt" value="DEV SERVICE">
<DIV id="idDevelopServiceView" style="display: none">
<table> <table>
<tr> <tr>
<td style="width: 100px"> <td style="width: 100px">
@ -1456,7 +1460,6 @@
</DIV> </DIV>
<canvas width='800' height='30' id='idBlockInfo'></canvas> <canvas width='800' height='30' id='idBlockInfo'></canvas>
<BR><BR> <BR><BR>
<DIV style="float: left;" id="idStatusMining"></DIV>
<DIV style="float: left; font-family: monospace"> <DIV style="float: left; font-family: monospace">
Block:<B id="idCurBlockNum"></B> Block:<B id="idCurBlockNum"></B>
DB delta:<B id="idDeltaDB" style="min-width: 30px"></B> DB delta:<B id="idDeltaDB" style="min-width: 30px"></B>
@ -1466,30 +1469,32 @@
Max:<B id="idSpeedSignLib" style="cursor: pointer" onclick='TestSignLib()'></B> tps Max:<B id="idSpeedSignLib" style="cursor: pointer" onclick='TestSignLib()'></B> tps
</DIV> </DIV>
<DIV id="idSignLibError" style="display: none;"> <DIV id="idSignLibError" style="display: none;">
<BR><BR> <BR><BR><DIV align='center' style="border: 1px solid #ff791a;padding: 5px"><b class="red">*************** WARNING: VERY SLOW LIBRARY: secp256k1 ***************<BR>Install all dependent packages, see detail: <a href="https://www.npmjs.com/package/secp256k1">https://www.npmjs.com/package/secp256k1</a></b>
<DIV align='center' style="border: 1px solid #ff791a;padding: 5px">
<b class="red">*************** WARNING: VERY SLOW LIBRARY: secp256k1 ***************<BR>Install all dependent packages, see detail: <a href="https://www.npmjs.com/package/secp256k1">https://www.npmjs.com/package/secp256k1</a></b>
</DIV> </DIV>
<BR> <BR>
</DIV> </DIV>
<DIV id="wallet_config_tab" style="display: none;float: left"> <DIV id="wallet_config_tab" style="display: none;float: left">
DataPath: <B id="idDataPath"></B><BR> Wallet data path: <B id="idDataPath"></B><BR>
PubKey: <B id="idPubKey"></B><BR> Public key: <B id="idPubKey"></B><BR>
<!--Node addr: <B id="idNodeAddr"></B><BR>--> <!--Node addr: <B id="idNodeAddr"></B><BR>-->
<INPUT type="button" onclick="MoveUp($('edit_keys'));NewPrivateKey();" class="btdoit bt" value="NewWallet" id="idDown2">
<INPUT type="button" onclick="MoveUp($('edit_keys'));EditPrivateKey();SetImg(this,'edit_keys');" class="btdoit bt" value="EditWallet" id="idDown">
<INPUT type="button" onclick="MoveUp($('idAccountEdit'));ViewNewAccount();SetImg(this,'idAccountEdit');" class="btdoit bt" value="NewAccount" id="idDown"> <INPUT type="button" onclick="MoveUp($('edit_keys'));NewPrivateKey();" class="btdoit bt" value="New wallet..." id="idDown2">
<INPUT type="button" onclick="MoveUp($('edit_mining_set'));MiningSets();SetImg(this,'edit_mining_set');" class="btdoit bt" value="MiningSet" id="idDown"> <INPUT type="button" onclick="MoveUp($('edit_keys'));EditPrivateKey();SetImg(this,'edit_keys');" class="btdoit bt" value="Edit wallet" id="idDown">
<INPUT type="button" onclick="ViewSetPassword();itemBtPassword=this; SetImg(itemBtPassword,'idBlockPasswordSet');" class="bt btdoit" value="SetPassword" id="idDown"> <INPUT type="button" onclick="MoveUp($('idAccountEdit'));ViewNewAccount();SetImg(this,'idAccountEdit');" class="btdoit bt" value="New account" id="idDown">
<INPUT type="button" onclick="MoveUp($('edit_mining_set'));MiningSets();SetImg(this,'edit_mining_set');" class="btdoit bt" value="Set mining" id="idDown">
<INPUT type="button" onclick="ViewSetPassword();itemBtPassword=this; SetImg(itemBtPassword,'idBlockPasswordSet');" class="bt btdoit" value="Set password" id="idDown">
</DIV> </DIV>
<DIV> <DIV>
<DIV id="edit_mining_set" style="display: none"> <DIV id="edit_mining_set" style="display: none">
<table class="form_input keys" id="grid_mining_set"> <table class="form_input keys" id="grid_mining_set">
<tr> <tr>
<td> <td><DIV>Mining account:</DIV></td><td><INPUT type="number" id="idMiningAccount" min=0 max=1000000000000 value="0"></td>
<DIV>Mining account:</DIV>
</td>
<td><INPUT type="number" id="idMiningAccount" min=0 max=1000000000000 value="0"></td>
</tr> </tr>
<tr> <tr>
@ -1509,8 +1514,7 @@
<option value="public">Public key (sign from another wallet)</option> <option value="public">Public key (sign from another wallet)</option>
<option value="brain">Brain key generator</option> <option value="brain">Brain key generator</option>
</select> </select>
</td> </td><td><INPUT type="string" autocomplete="off" id="idKeyNew" value=""></td>
<td><INPUT type="string" autocomplete="off" id="idKeyNew" value=""></td>
</tr> </tr>
<tr id="idViewKeyNew2" style="display: none"> <tr id="idViewKeyNew2" style="display: none">
<td>You can repeat the secret words:</td> <td>You can repeat the secret words:</td>
@ -1531,9 +1535,7 @@
<DIV id="idAccountEdit" style="display: none"> <DIV id="idAccountEdit" style="display: none">
<table class="form_input keys" id="grid_edit_newacc"> <table class="form_input keys" id="grid_edit_newacc">
<tr> <tr>
<td> <td><DIV>Public name:</DIV></td>
<DIV>Public name:</DIV>
</td>
<td> <td>
<INPUT type="string" maxlength="40" autocomplete="off" id="idAccountName" onkeyup="CheckLengthAccDesription('idAccountName',40)" value=""> <INPUT type="string" maxlength="40" autocomplete="off" id="idAccountName" onkeyup="CheckLengthAccDesription('idAccountName',40)" value="">
</td> </td>
@ -1546,16 +1548,12 @@
<tr> <tr>
<td> <td>
<DIV>Currency:</DIV> <DIV>Currency:</DIV></td><td><INPUT type="number" id="idCurrency" min=0 max=1000000000 value="0">
</td>
<td><INPUT type="number" id="idCurrency" min=0 max=1000000000 value="0">
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<DIV>Smart:</DIV> <DIV>Smart:</DIV></td><td><INPUT type="number" id="idSmart" min=0 max=1000000000 value="0">
</td>
<td><INPUT type="number" id="idSmart" min=0 max=1000000000 value="0">
</td> </td>
</tr> </tr>
<!--<tr>--> <!--<tr>-->
@ -1564,9 +1562,7 @@
<tr id="idRowWN" style="display: none"> <tr id="idRowWN" style="display: none">
<td> <td>
<DIV>Wallet number:</DIV> <DIV>Wallet number:</DIV></td><td><INPUT type="number" id="idWN" min=0 max=100 value="0">
</td>
<td><INPUT type="number" id="idWN" min=0 max=100 value="0">
</td> </td>
</tr> </tr>
@ -1591,11 +1587,9 @@
<th id="CurrencyNameItem(Item)" data-name="Currency" class="cur hint">Cur</th> <th id="CurrencyNameItem(Item)" data-name="Currency" class="cur hint">Cur</th>
<th id="Item.Name" data-name="Account name" class="accname hint">Name</th> <th id="Item.Name" data-name="Account name" class="accname hint">Name</th>
<th id="Item.Value.OperationID" data-name="Operation ID" class="snum hint">OP</th> <th id="Item.Value.OperationID" data-name="Operation ID" class="snum hint">OP</th>
<th id="(RetHistoryAccount(Item,'Adviser'))" data-name="Adviser" class="snum hint"> <th id="(RetHistoryAccount(Item,'Adviser'))" data-name="Adviser" class="snum hint">Adv</th>
Adv</th>
<th id="(RetChangeSmart(Item))" data-name="Smart contract (DApp)" <th id="(RetChangeSmart(Item))" data-name="Smart contract (DApp)" class="smart hint">Smart</th>
class="smart hint">Smart</th>
<th id="Item.WN" class="num" style="width: 30px;"></th> <th id="Item.WN" class="num" style="width: 30px;"></th>
</tr> </tr>
</table> </table>
@ -1654,6 +1648,8 @@
<HR> <HR>
</DIV> </DIV>
</DIV> </DIV>
Style: Style:
<select size="1" id="idSelStyle" onkeyup="SelectStyle();SaveValues()" onchange="SelectStyle();SaveValues()"> <select size="1" id="idSelStyle" onkeyup="SelectStyle();SaveValues()" onchange="SelectStyle();SaveValues()">
<option value="styleBrown">Brown</option> <option value="styleBrown">Brown</option>
@ -1665,24 +1661,27 @@
<option value="styleContrast2">Contrast 2</option> <option value="styleContrast2">Contrast 2</option>
<option value="styleContrast3">Contrast 3</option> <option value="styleContrast3">Contrast 3</option>
</select> </select>
此版本由 MiaoWoo 使用 TypeScript 重构<BR>
</DIV> </DIV>
<DIV id="TabSend" style="display: none"> <DIV id="TabSend" style="display: none">
<DIV id="idSendList"> </DIV> <DIV id="idSendList"> </DIV>
<table class="form_input"> <table class="form_input">
<tr> <tr>
<td style="min-width: 115px">From account</td> <td style="min-width: 115px">From account</td>
<td> <td>
<select size="1" id="idAccount" onkeyup="OnEditTransactionFields()" onchange="OnEditTransactionFields()"> <select size="1" id="idAccount" onkeyup="OnEditTransactionFields()" onchange="OnEditTransactionFields()">
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr><td>&nbsp;</td><td><DIV id="idNameTo" class="smallbold"></DIV></td></tr>
<td>&nbsp;</td>
<td>
<DIV id="idNameTo" class="smallbold"></DIV>
</td>
</tr>
<tr> <tr>
<td>Pay to</td> <td>Pay to</td>
<td> <td>
@ -1698,12 +1697,8 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Description (optional)</td> <td>Description (optional)</td><td><textarea id="idDescription" rows="4" onkeyup="CheckLengthAccDesription('idDescription',200);OnEditTransactionFields()" onchange="OnEditTransactionFields()"></textarea></td>
<td><textarea id="idDescription" rows="4" onkeyup="CheckLengthAccDesription('idDescription',200);OnEditTransactionFields()" onchange="OnEditTransactionFields()"></textarea> <td><DIV id="idAttach"> </DIV></td>
</td>
<td>
<DIV id="idAttach"> </DIV>
</td>
</tr> </tr>
<tr> <tr>
<td> <td>
@ -1828,18 +1823,14 @@
<table id="grid_accounts_all" class="grid"> <table id="grid_accounts_all" class="grid">
<tr> <tr>
<th id="(RetHistoryAccount(Item))" class="num">ID</th> <th id="(RetHistoryAccount(Item))" class="num">ID</th>
<th id="SUM_TO_STRING(Item.Value)" class="sum smallbold">Amount <th id="SUM_TO_STRING(Item.Value)" class="sum smallbold">Amount</th>
</th>
<th id="CurrencyNameItem(Item)" class="cur">Cur</th> <th id="CurrencyNameItem(Item)" class="cur">Cur</th>
<th id="Item.Name" class="accname">Name</th> <th id="Item.Name" class="accname">Name</th>
<th id="Item.PubKeyStr" class="pubkey">PubKey</th> <th id="Item.PubKeyStr" class="pubkey">PubKey</th>
<th id="Item.Value.OperationID" class="num">Operation</th> <th id="Item.Value.OperationID" class="num">Operation</th>
<th id="(RetHistoryAccount(Item,'Adviser'))" class="num">Adviser <th id="(RetHistoryAccount(Item,'Adviser'))" class="num">Adviser</th>
</th>
<th id="Item.Value.Smart" class="num">Smart</th> <th id="Item.Value.Smart" class="num">Smart</th>
<th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="num">Block <th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="num">Block Num</th>
Num
</th>
<!--<th id="Item.Arr[0].BlockNum" class="num">0</th>--> <!--<th id="Item.Arr[0].BlockNum" class="num">0</th>-->
<!--<th id="Item.Arr[1].BlockNum" class="num">1</th>--> <!--<th id="Item.Arr[1].BlockNum" class="num">1</th>-->
<!--<th id="Item.Arr[2].BlockNum" class="num">2</th>--> <!--<th id="Item.Arr[2].BlockNum" class="num">2</th>-->
@ -1869,25 +1860,15 @@
<table id="grid_block_all" class="grid"> <table id="grid_block_all" class="grid">
<tr> <tr>
<th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))" <th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))" class="num">Num</th>
class="num">Num</th> <th id="(DateFromBlock(Item.BlockNum,1))" class="date">Date</th>
<th id="(DateFromBlock(Item.BlockNum,1))" class="date"> <th id="GetHexFromArr(Item.TreeHash)" class="hash">Data Hash</th>
Date <th id="GetHexFromArr(Item.PowHash)" class="hash">PowHash</th>
</th> <th id="GetHexFromArr(Item.Hash)" class="hash">Block Hash</th>
<th id="GetHexFromArr(Item.TreeHash)" class="hash">Data
Hash
</th>
<th id="GetHexFromArr(Item.PowHash)" class="hash">
PowHash
</th>
<th id="GetHexFromArr(Item.Hash)" class="hash">Block
Hash
</th>
<!--<th id="GetHexFromArr(Item.SumHash)" class="hash">SumHash</th>--> <!--<th id="GetHexFromArr(Item.SumHash)" class="hash">SumHash</th>-->
<th id="Item.TrDataLen" class="num">Bytes</th> <th id="Item.TrDataLen" class="num">Bytes</th>
<th id="Item.Power" class="num">Pow</th> <th id="Item.Power" class="num">Pow</th>
<th id="(RetHistoryAccount(Item,'Miner')+'<BR><b>'+Item.MinerName)+'</b>'" <th id="(RetHistoryAccount(Item,'Miner')+'<BR><b>'+Item.MinerName)+'</b>'" class="num">Miner</th>
class="num">Miner</th>
<!--<th id="GetHexFromArr(Item.Hash1)" class="hash">Hash1</th>--> <!--<th id="GetHexFromArr(Item.Hash1)" class="hash">Hash1</th>-->
@ -1925,20 +1906,13 @@
<th id="Item.Num" class="num">Num</th> <th id="Item.Num" class="num">Num</th>
<th id="Item.ID" class="num">Account</th> <th id="Item.ID" class="num">Account</th>
<th id="Item.Mode">Mode</th> <th id="Item.Mode">Mode</th>
<th id="(RetOpenBlock(Item.BlockNum,1))" <th id="(RetOpenBlock(Item.BlockNum,1))" class="num">Block</th>
class="num">Block</th>
<th id="Item.TrNum" class="num">TrNum</th> <th id="Item.TrNum" class="num">TrNum</th>
<th id="(escapeHtml(DateFromBlock(Item.BlockNum,1)))" <th id="(escapeHtml(DateFromBlock(Item.BlockNum,1)))" class="date">Date</th>
class="date">Date</th>
<th id="Item.PrevValue.OperationID" class="num"> <th id="Item.PrevValue.OperationID" class="num">Prev. Operation</th>
Prev. Operation</th> <th id="SUM_TO_STRING(Item.PrevValue)" class="sum">Prev. amount</th>
<th id="SUM_TO_STRING(Item.PrevValue)" <th id="Item.PrevValue.NextPos" class="num">Prev. History</th>
class="sum">
Prev. amount</th>
<th id="Item.PrevValue.NextPos" class="num">
Prev.
History</th>
</tr> </tr>
</table> </table>
<INPUT type="button" onclick="ViewPrev(DefActs)" class="btdoit bt" value="&lt;&lt; Prev"> <INPUT type="button" onclick="ViewPrev(DefActs)" class="btdoit bt" value="&lt;&lt; Prev">
@ -1958,22 +1932,14 @@
<table id="grid_hash_all" class="grid"> <table id="grid_hash_all" class="grid">
<tr> <tr>
<th id="Item.Num" class="num">Num</th> <th id="Item.Num" class="num">Num</th>
<th id="(RetOpenBlock(Item.BlockNum,3))" <th id="(RetOpenBlock(Item.BlockNum,3))" class="">Block</th>
class="">Block</th> <th id="(escapeHtml(DateFromBlock(Item.BlockNum,1)))" class="date">Date</th>
<th id="(escapeHtml(DateFromBlock(Item.BlockNum,1)))" <th id="GetHexFromArr(Item.AccHash)" class="code">AccHash</th>
class="date">Date</th> <th id="GetHexFromArr(Item.SumHash)" class="code">SumHash</th>
<th id="GetHexFromArr(Item.AccHash)" <th id="Item.AccountMax" class="num">AccountMax</th>
class="code">AccHash</th> <th id="Item.SmartCount" class="num">SmartCount</th>
<th id="GetHexFromArr(Item.SumHash)" <th id="GetHexFromArr(Item.SmartHash)" class="code">SmartHash</th>
class="code">SumHash</th> <th id="GetHexFromArr(Item.Hash100)" class="code">Hash100</th>
<th id="Item.AccountMax" class="num">
AccountMax</th>
<th id="Item.SmartCount" class="num">
SmartCount</th>
<th id="GetHexFromArr(Item.SmartHash)"
class="code">SmartHash</th>
<th id="GetHexFromArr(Item.Hash100)"
class="code">Hash100</th>
</tr> </tr>
</table> </table>
<INPUT type="button" onclick="ViewPrev(DefHash)" class="btdoit bt" value="&lt;&lt; Prev"> <INPUT type="button" onclick="ViewPrev(DefHash)" class="btdoit bt" value="&lt;&lt; Prev">
@ -1984,8 +1950,7 @@
<HR> <HR>
<DIV id="view_header" >UTILITES<BR></DIV> <DIV id="view_header" >UTILITES<BR></DIV>
Number of blocks in Number of blocks in depth:<INPUT type="number" id="idBlockCount" onchange = "SaveValues()" value="0"><BR>
depth:<INPUT type="number" id="idBlockCount" onchange = "SaveValues()" value="0"><BR>
<INPUT type="button" onclick="RestartNode()" class="bt btdoit btlong" value="Restart node"> <INPUT type="button" onclick="RestartNode()" class="bt btdoit btlong" value="Restart node">
<INPUT type="button" onclick="RewriteTransactions()" class="bt btdoit btlong" value="Rewrite transactions"> <INPUT type="button" onclick="RewriteTransactions()" class="bt btdoit btlong" value="Rewrite transactions">
<INPUT type="button" onclick="TruncateBlockChain()" class="btdoit btlong bt" value="Truncate chain"> <INPUT type="button" onclick="TruncateBlockChain()" class="btdoit btlong bt" value="Truncate chain">
@ -2012,38 +1977,24 @@
<BR> <BR>
<DIV id="idServerBlock" <DIV id="idServerBlock" style="width: 99.5%">
style="width: 99.5%">
<HR> <HR>
Log from node: Log from node:
<DIV id="idServerLog"></DIV><BR> <DIV id="idServerLog"></DIV><BR>
</DIV> </DIV>
<FORM id="idBlockPasswordSet" <FORM id="idBlockPasswordSet" style="display: none">
style="display: none"> <H3 align="center">Enter new password:</H3>
<H3 align="center">Enter new <table class="password" id="idTablePassword1">
password:
</H3>
<table class="password"
id="idTablePassword1">
<tr style="display: none"> <tr style="display: none">
<td> <td><DIV>Login:</DIV></td><td><INPUT type="string" id="Login1" value=""></td>
<DIV>Login:</DIV>
</td>
<td><INPUT type="string" id="Login1" value=""></td>
</tr> </tr>
<tr> <tr>
<td> <td><DIV>Password:</DIV></td><td><INPUT type="password" autocomplete="WalletPassword" id="idPassword1" value=""></td>
<DIV>Password:</DIV>
</td>
<td><INPUT type="password" autocomplete="WalletPassword" id="idPassword1" value=""></td>
</tr> </tr>
<tr> <tr>
<td> <td><DIV>Repeat:</DIV></td><td><INPUT type="password" autocomplete="WalletPassword" id="idPassword2" onkeyup="" value=""></td>
<DIV>Repeat:</DIV>
</td>
<td><INPUT type="password" autocomplete="WalletPassword" id="idPassword2" onkeyup="" value=""></td>
</tr> </tr>
<tr> <tr>
@ -2054,24 +2005,14 @@
</table> </table>
</FORM> </FORM>
<FORM id="idBlockPasswordGet" <FORM id="idBlockPasswordGet" style="display: none">
style="display: none"> <H3 align="center">Enter your password:</H3>
<H3 align="center">Enter your <table class="password" id="idTablePassword2">
password:
</H3>
<table class="password"
id="idTablePassword2">
<tr style="display: none"> <tr style="display: none">
<td> <td><DIV>Login:</DIV></td><td><INPUT type="string" id="Login2" value=""></td>
<DIV>Login:</DIV>
</td>
<td><INPUT type="string" id="Login2" value=""></td>
</tr> </tr>
<tr> <tr>
<td> <td><DIV>Password:</DIV></td><td><INPUT type="password" autocomplete="WalletPassword" id="idPasswordGet" value=""></td>
<DIV>Password:</DIV>
</td>
<td><INPUT type="password" autocomplete="WalletPassword" id="idPasswordGet" value=""></td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>
@ -2083,33 +2024,24 @@
<DIV id="idBlockOnSend" <DIV id="idBlockOnSend" style="display: none">
style="display: none">
<DIV align="center"> <DIV align="center">
Send Send <B id="idOnSendText"></B><BR>
<B id="idOnSendText"></B><BR>
<button onclick="SendMoney2()" id="idBtOnSend" class="radius">Send</button> <button onclick="SendMoney2()" id="idBtOnSend" class="radius">Send</button>
<button onclick='SetVisibleBlock("idBlockOnSend",0);' class="radius">Cancel</button> <button onclick='SetVisibleBlock("idBlockOnSend",0);' class="radius">Cancel</button>
<DIV align="left"> <DIV align="left">
<DIV id="idCheckOnSend"> <DIV id="idCheckOnSend"><input type="checkbox" id="idWhiteOnSend"/> Add this account to white list</DIV>
<input type="checkbox" id="idWhiteOnSend"/> Add this account to white list</DIV>
</DIV> </DIV>
</DIV> </DIV>
</DIV> </DIV>
<audio style="visibility: hidden;" <audio style="visibility: hidden;" controls="controls" id="sound_coin">
controls="controls" <source src="coin.mp3" type="audio/mpeg"/>
id="sound_coin">
<source src="coin.mp3"
type="audio/mpeg" />
</audio> </audio>
<audio style="visibility: hidden;" <audio style="visibility: hidden;" controls="controls" id="sound_err">
controls="controls" <source src="click.mp3" type="audio/mpeg"/>
id="sound_err">
<source src="click.mp3"
type="audio/mpeg" />
</audio> </audio>
@ -2117,7 +2049,6 @@
</DIV> </DIV>
</body> </body>
</html> </html>
<DIV id="idStableScroll" align='center'> <DIV id="idStableScroll" align='center'>
@ -2129,3 +2060,4 @@
<A href="https://jq.qq.com/?_wv=1027&k=5KpN5fw">QQ</A> <A href="https://jq.qq.com/?_wv=1027&k=5KpN5fw">QQ</A>
<!--progr76@gmail.com--> <!--progr76@gmail.com-->
</DIV> </DIV>

View File

@ -22,7 +22,7 @@
</head> </head>
<body> <body>
<header class="header"> <header id="idMainHeader" class="header">
<div class="header__wrapper"> <div class="header__wrapper">
<div class="header__logo"> <div class="header__logo">
<a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome"> <a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome">
@ -54,7 +54,7 @@
</div> </div>
</header> </header>
<main> <main id="idMain">
<section id="TabWelcome" class="welcome" > <section id="TabWelcome" class="welcome" >
<div class="welcome__img"> <div class="welcome__img">
<svg class="" xmlns="http://www.w3.org/2000/svg" fill="#445368" viewBox="0 0 992.13 992.13" width="150" height="150"> <svg class="" xmlns="http://www.w3.org/2000/svg" fill="#445368" viewBox="0 0 992.13 992.13" width="150" height="150">
@ -211,8 +211,8 @@
<div class="prod-card__first-line"> <div class="prod-card__first-line">
<span class="hidden id-sign">ID:&nbsp;</span> <span class="hidden id-sign">ID:&nbsp;</span>
<a target='_blank' class="prod-card__id prod-card__id--mobile">{Item.Num}</a> <a target='_blank' class="prod-card__id prod-card__id--mobile">{Item.Num}</a>
<a href="./history.html#{Item.Num}" target='_blank' class="prod-card__id prod-card__id--mobile-active">{Item.Num}</a> <a onclick="OpenHistoryPage({Item.Num})" class="prod-card__id prod-card__id--mobile-active pointer">{Item.Num}</a>
<a href="./history.html#{Item.Num}" target='_blank' class="prod-card__id prod-card__id--desktop">{Item.Num}</a> <a onclick="OpenHistoryPage({Item.Num})" target='_blank' class="prod-card__id prod-card__id--desktop pointer">{Item.Num}</a>
<div class="prod-card__heading"> <div class="prod-card__heading">
<span class="prod-card__coins-count">{Value.SumCOIN}<sup>,{Value.SumCENT}</sup><br> <span class="prod-card__coins-count">{Value.SumCOIN}<sup>,{Value.SumCENT}</sup><br>
<span class="light-grey-text small-text mob-hidden">{Value.CurrencyName}</span> <span class="light-grey-text small-text mob-hidden">{Value.CurrencyName}</span>
@ -318,6 +318,7 @@
</div> </div>
<div class="send-page__send-btn-wrp"> <div class="send-page__send-btn-wrp">
<!--<button class="btn btn&#45;&#45;full-width btn&#45;&#45;450" onclick="ClearSend()" id="idClearButton">Clear</button>-->
<button class="btn btn--full-width btn--450 send-page__send-btn" onclick="SendMobileBefore()" id="idSendButton">Send</button> <button class="btn btn--full-width btn--450 send-page__send-btn" onclick="SendMobileBefore()" id="idSendButton">Send</button>
</div> </div>
</div> </div>
@ -630,9 +631,7 @@
<a class="password-modal__link pointer" id="idEntrance" onclick="MyOpenWallet(0)">Entrance to sub-wallet</a> <a class="password-modal__link pointer" id="idEntrance" onclick="MyOpenWallet(0)">Entrance to sub-wallet</a>
</form> </form>
</section> </section>
<footer>
</footer>
<div class="fixed-status"> <div class="fixed-status">
<div class="fixed-status__wrap"> <div class="fixed-status__wrap">
@ -654,12 +653,13 @@
<DIV align='center'> <DIV align='center'>
<DIV align='left' style="display: none;"> <DIV align='left' style="display: none;">
<INPUT id="idCurTabName" value="TabInfo" style="display: none"> <INPUT id="idCurTabName" value="TabInfo" style="display: none">
</DIV> </DIV>
</DIV> </DIV>
<iframe id="idHistoryPage" name="HistoryPage" style="display: none" src="./history.html"></iframe>
<iframe id="idBlockViewerPage" name="BlockViewerPage" style="display: none" src="./blockviewer.html"></iframe>
</body> </body>
</html> </html>