1
0
Fork 0

Tue Sep 3 09:01:40 CST 2019 Source Update...

master
MiaoWoo 3 years ago
parent 48fe258e2e
commit 228076945f
  1. 31
      Source/HTML/JS/client.js
  2. 9
      Source/HTML/JS/coinlib.js
  3. 370
      Source/HTML/JS/dapp-inner.js
  4. 7
      Source/HTML/JS/mobile-wallet.js
  5. 7
      Source/HTML/JS/terahashlib.js
  6. 4
      Source/HTML/JS/wallet-lib.js
  7. 2
      Source/HTML/dapp-edit.html
  8. 122
      Source/HTML/dapp-frame.html
  9. 1095
      Source/HTML/wallet.html
  10. 2
      Source/HTML/web-wallet.html
  11. 5
      Source/core/constant.js
  12. 15
      Source/core/html-server.js
  13. 2
      Source/core/rest-loader.js
  14. 14
      Source/process/web-process.js
  15. 8
      Source/system/accounts.js
  16. 134
      Source/system/smart.js

@ -198,13 +198,35 @@ function GetProtocolServerPath(Item)
return "http://" + Item.ip + ":" + Item.port;
};
function ToFixed(Sum,Currency)
{
var Fixed = GetCurrencyFixed(Currency);
var Str = Sum.toFixed(Fixed);
var Index = Str.indexOf(".");
if(Index > 0)
{
for(var i = Str.length - 1; i >= Index; i--)
{
var c = Str.substr(i, 1);
if(c !== "0")
{
if(c === ".")
Str = Str.substr(0, i);
break;
}
Str = Str.substr(0, i);
}
}
return Str;
};
function SUM_TO_STRING(Value,Currency,bFloat,bLocal)
{
var Str;
if(Value.SumCOIN || Value.SumCENT)
if(bFloat)
{
Str = "" + FLOAT_FROM_COIN(Value).toStringF();
Str = ToFixed(FLOAT_FROM_COIN(Value), Currency);
}
else
{
@ -1284,8 +1306,7 @@ function GetTokenName(Num,Name)
{
if(!Name)
Name = "Token";
return "(" + Num + "." + Name + ")";
return "{" + Num + "." + Name + "}";
return String(Name).toLowerCase();
};
function CurrencyNameItem(Item)
@ -1294,11 +1315,15 @@ function CurrencyNameItem(Item)
if(!Name)
{
if(Item.CurrencyObj)
{
Name = GetTokenName(Item.Currency, Item.CurrencyObj.ShortName);
}
else
Name = GetTokenName(Item.Currency, "");
MapCurrency[Item.Currency] = Name;
}
if(Item.CurrencyObj && Item.CurrencyObj.TokenDescription)
Name += " : " + Item.CurrencyObj.TokenDescription;
return Name;
};

@ -108,6 +108,15 @@ function COIN_FROM_STRING(Str)
{
throw "TODO: COIN_FROM_STRING";
};
function GetCurrencyFixed(Currency)
{
var Fixed = 9;
var Name = CurrencyName(Currency);
if(Name === "BTC")
Fixed = 8;
return Fixed;
};
if(typeof global === "object")
{
global.CHECKSUM = CHECKSUM;

@ -175,6 +175,11 @@ function SendTransaction(Body,TR,SumPow,F)
SetError("Cannt SEND TR: " + JSON.stringify(TR));
};
function ReloadDapp()
{
SendData({cmd:"ReloadDapp"});
};
function CurrencyName(Num)
{
var Name = MapCurrency[Num];
@ -232,6 +237,8 @@ function FindAllCurrencyNext(StartNum)
function GetFilePath(Path)
{
if(Path.substr(0, 5) === "http:" || Path.substr(0, 6) === "https:")
return Path;
if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/"))
{
if(Path.substr(0, 1) !== "/")
@ -277,6 +284,89 @@ function GetState(AccNum,F,FErr)
}
});
};
var glWasModal = 0;
function openModal(id)
{
glWasModal = 1;
var modal = document.querySelector("#" + id);
var overlay = document.querySelector("#idOverlay");
modal.style.display = "block";
overlay.style.display = "block";
};
function closeModal()
{
glWasModal = 0;
var modals = document.querySelectorAll(".ModalDlg");
var overlay = document.querySelector("#idOverlay");
modals.forEach(function (item)
{
item.style.display = "none";
});
overlay.style.display = "none";
};
var TEMP_DISABLED_MAP = {};
function SetTempDisabled(Id,TimeSec)
{
if(!TimeSec)
TimeSec = 8;
$(Id).disabled = 1;
TEMP_DISABLED_MAP[Id] = 1;
setTimeout(function ()
{
$(Id).disabled = 0;
delete TEMP_DISABLED_MAP[Id];
}, TimeSec * 1000);
};
var glConfirmF;
function DoConfirm(StrTitle,StrText,F,bDirect)
{
if(!bDirect && window.openModal && $("idConfirm"))
{
$("idConfirmTitle").innerHTML = StrTitle;
$("idConfirmText").innerHTML = StrText;
glConfirmF = F;
openModal("idConfirm");
}
else
{
F();
}
};
function OnConfirmOK()
{
closeModal();
if(glConfirmF)
glConfirmF();
glConfirmF = undefined;
};
function GetDappBlock(Block,Tr,F)
{
DappBlockFile(Block, Tr, function (Err,Data)
{
if(!Err && Data.Type === 135)
{
try
{
var Params = JSON.parse(Data.Params);
}
catch(e)
{
}
if(Params)
{
F(0, Params, Data.MethodName, Data.FromNum);
return ;
}
}
F(1);
});
};
function UpdateListArr(Block,Tr,Arr,StopBlock,IgnoreTailBlock,MaxDepth,F)
{
@ -286,53 +376,251 @@ function UpdateListArr(Block,Tr,Arr,StopBlock,IgnoreTailBlock,MaxDepth,F)
});
if(Arr.length)
StopBlock = Math.max(StopBlock, Arr[Arr.length - 1].BlockNum);
UpdateListArrNext(Block, Tr, Arr, StopBlock, IgnoreTailBlock, MaxDepth, F);
UpdateRowArr(Block, Tr, Arr, StopBlock, IgnoreTailBlock, MaxDepth, F);
};
function UpdateListArrNext(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F)
function UpdateRowArr(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F)
{
if(Block <= StopMinBlock || !MaxDepth)
return ;
SendCountUpdate++;
DappBlockFile(Block, Tr, function (Err,Data)
GetDappBlock(Block, Tr, function (Err,Params)
{
SendCountUpdate--;
if(!Err && Data.Type === 135)
if(!Err)
{
try
if(Block <= INFO.CurBlockNum - IgnoreTailBlock)
{
var Params = JSON.parse(Data.Params);
Params.BlockNum = Block;
Params.TrNum = Tr;
Params.Num = Params.BlockNum * 100000 + Params.TrNum;
Params.Time = Date.now();
if(!Arr.length || Arr[Arr.length - 1].Num !== Params.Num)
{
if(F)
{
if(F(Params))
{
return ;
}
}
else
{
Arr.push(Params);
}
}
}
catch(e)
if(Params.PrevBlock)
{
UpdateRowArr(Params.PrevBlock, Params.PrevTr, Arr, StopMinBlock, IgnoreTailBlock, MaxDepth - 1, F);
}
if(Params)
}
});
};
function GetKeyNum(Key)
{
var Arr;
if(typeof Key === "number")
{
Arr = sha3("" + Key);
}
else
{
Arr = sha3(Key);
}
var KeyNum = ReadUintFromArr(Arr, 0);
return KeyNum;
};
function GetKeyInner(Key,DBBlock,DBTr,F)
{
FindItem(DBBlock, DBTr, Key, function (Result,PathArr)
{
for(var i = 0; i < PathArr.length; i++)
{
var Elem = PathArr[i];
if(Elem.Key === Key)
{
if(Block <= INFO.CurBlockNum - IgnoreTailBlock)
if(Elem.VB)
{
Params.BlockNum = Block;
Params.TrNum = Tr;
Params.Num = Params.BlockNum * 100000 + Params.TrNum;
Params.Time = Date.now();
if(!Arr.length || Arr[Arr.length - 1].Num !== Params.Num)
Arr.push(Params);
LoadElement(Elem, i, PathArr, F);
}
if(Params.PrevBlock)
else
{
UpdateListArrNext(Params.PrevBlock, Params.PrevTr, Arr, StopMinBlock, IgnoreTailBlock, MaxDepth - 1, F);
F(1, Elem, PathArr);
}
return ;
}
}
if(F && SendCountUpdate === 0)
F(0, undefined, PathArr);
});
};
function SetKeyInner(Key,Value,DBBlock,DBTr,F)
{
FindItem(DBBlock, DBTr, Key, function (Result,PathArr)
{
var Elem;
var bCreate = 1;
var ElemEdit = undefined;
for(var i = 0; i < PathArr.length; i++)
{
Elem = PathArr[i];
if(Elem.Key === Key)
{
Elem.Key = undefined;
Elem.VB = undefined;
Elem.VT = undefined;
Elem.Level = undefined;
if(i === PathArr.length - 1)
bCreate = 0;
if(typeof Value === "number")
ElemEdit = Elem;
}
if(Elem.VB)
{
Elem.Value = undefined;
}
}
var L = PathArr.length - 1;
if(ElemEdit)
{
Elem = ElemEdit;
}
else
{
if(L === - 1 || bCreate)
{
L++;
PathArr[L] = {};
}
Elem = PathArr[L];
}
Elem.Key = Key;
Elem.Value = Value;
F(PathArr);
});
};
var GetBlockKeyCount = 0;
function FindItem(Block,Tr,Key,F)
{
GetBlockKeyCount = 0;
var KeyNum = GetKeyNum(Key);
FindItemNext(Block, Tr, Key, KeyNum, [], 0, F);
};
function FindItemNext(Block,Tr,Key,KeyNum,PathArr,Level,F)
{
GetBlockKeyCount++;
GetDappBlock(Block, Tr, function (Err,Params)
{
GetBlockKeyCount--;
if(!Err)
{
Arr.sort(function (a,b)
var KeyNumStr = KeyNum.toString(2);
var Arr = Params.Arr;
for(var L = Level; Arr && L < Arr.length; L++)
{
return a.Num - b.Num;
});
F(Arr);
var Elem = Arr[L];
PathArr[L] = Elem;
if(Elem.Key !== undefined)
{
if(Elem.Key !== Key && !Elem.VB && typeof Elem.Value !== "number")
{
Elem.VB = Block;
Elem.VT = Tr;
}
}
var Bit = + KeyNumStr.substr(L, 1);
if(Bit !== Elem.t)
{
var IB = Elem.IB;
var IT = Elem.IT;
Elem.t = Bit;
Elem.IB = Block;
Elem.IT = Tr;
if(IB)
{
FindItemNext(IB, IT, Key, KeyNum, PathArr, L + 1, F);
}
else
{
break;
}
return ;
}
}
F(1, PathArr);
return ;
}
if(GetBlockKeyCount === 0)
F(0, []);
});
};
function LoadElement(Element,Level,PathArr,F)
{
GetBlockKeyCount++;
GetDappBlock(Element.VB, Element.VT, function (Err,Params)
{
GetBlockKeyCount--;
if(!Err)
{
F(1, Params.Arr[Level], PathArr);
return ;
}
if(GetBlockKeyCount === 0)
F(0);
});
};
function GetXORArr(Arr1,Arr2)
{
var Arr3 = [];
for(var i = 0; i < 32; i++)
{
Arr3[i] = Arr1[i] ^ Arr2[i];
}
return Arr3;
};
function EncryptUint32(ArrSecret,RandomNum,Value)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var ValueArr = [];
WriteUint32ToArr(ValueArr, Value);
return GetHexFromArr(DoSecret(ValueArr, ArrSecret));
};
function DecryptUint32(ArrSecret,RandomNum,StrValue)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var Arr0 = GetArrFromHex(StrValue);
var ValueArr = DoSecret(Arr0, ArrSecret);
ValueArr.len = 0;
var Value = ReadUint32FromArr(ValueArr);
return Value;
};
function EncryptArr32(ArrSecret,RandomNum,ValueArr)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
return GetHexFromArr(DoSecret(ValueArr, ArrSecret));
};
function DecryptArr32(ArrSecret,RandomNum,StrValue)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var Arr0 = GetArrFromHex(StrValue);
var ValueArr = DoSecret(Arr0, ArrSecret);
return ValueArr;
};
var glMapF = {};
var glKeyF = 0;
@ -492,23 +780,13 @@ function GetDappParams(BNum,TrNum,F,bAll)
return ;
}
SendCountDappParams++;
DappBlockFile(BNum, TrNum, function (Err,Data)
GetDappBlock(BNum, TrNum, function (Err,Params,MethodName,FromNum)
{
SendCountDappParams--;
if(!Err && Data.Type === 135)
if(!Err)
{
try
{
var Params = JSON.parse(Data.Params);
}
catch(e)
{
}
if(Params)
{
F(Params, Data.MethodName, Data.FromNum);
return ;
}
F(Params, MethodName, FromNum);
return ;
}
if(bAll)
F();
@ -595,3 +873,23 @@ window.addEventListener('load', function ()
UpdateDappInfo();
setInterval(UpdateDappInfo, 1000);
});
window.onkeydown = function (e)
{
if(e.keyCode === 116)
{
e.preventDefault();
ReloadDapp();
}
else
if(e.keyCode === 27)
{
if(window.closeModal)
closeModal();
}
else
if(e.keyCode === 13)
{
if(glConfirmF)
OnConfirmOK();
}
};

@ -468,7 +468,7 @@ function SetAccountsCard(Data,AccountsDataStr)
Str1 = "";
Str2 = "";
}
var StrCurrencyName = CurrencyName(Item.Currency);
var StrCurrencyName = CurrencyNameItem(Item);
Str = Str.replace("$Value.SumCOIN", Str1);
Str = Str.replace("$Value.SumCENT", Str2);
Str = Str.replace("$Value.CurrencyName", StrCurrencyName);
@ -1295,8 +1295,7 @@ LangMap["RUS"] = {"TERA WALLET":"TERA КОШЕЛЕК", "Generate key":"Сген
"Load key":"Загруз.", "Create your first account and start using TERA":"Создайте свой первый счет и начните использовать TERA",
"0 Accounts":"0 Счетов", "OWNER: {Item.Owner}":"Владелец: {Item.Owner}", "More info":"Инфо", "Public key":"Публичный ключ",
"Enter number of dapp":"Введите номер Dapp", "Enter the dapps number that will be added to your account. Attention make sure that you trust this dapp, otherwise you may lose all funds in this account.":"Введите номер Dapp, который будет добавлен в ваш аккаунт. Внимание убедитесь, что Вы доверяете ему, в противном случае вы можете потерять все средства на этом счете.",
"Sending Tx":"Отправка транзакции", "Wallet ver:":"Версия:", "HELP: Tera Wallet creation Guide...":"Руководство по созданию Tera Wallet...",
"==HELP-LINK==":"https://medium.com/@evkara777/tera-%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D0%B0%D0%BB%D1%8E%D1%82%D0%BD%D1%8B%D0%B9-%D0%BA%D0%BE%D1%88%D0%B5%D0%BB%D0%B5%D0%BA-%D0%B2%D0%B8%D0%B4%D1%8B-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5-%D1%81%D1%87%D0%B5%D1%82%D0%B0-6402531ecc11",
"Sending Tx":"Отправка транзакции", "Wallet ver:":"Версия:", "Tera Wallet Guide...":"Руководство по Tera Wallet...", "==HELP-LINK==":"https://medium.com/@evkara777/tera-%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D0%B0%D0%BB%D1%8E%D1%82%D0%BD%D1%8B%D0%B9-%D0%BA%D0%BE%D1%88%D0%B5%D0%BB%D0%B5%D0%BA-%D0%B2%D0%B8%D0%B4%D1%8B-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5-%D1%81%D1%87%D0%B5%D1%82%D0%B0-6402531ecc11",
};
LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成私钥", "OK":"OK", "Cancel":"取消", "Edit":"编辑", "Save key":"保存私钥",
"+ CREATE A NEW ACCOUNT":"+ 新建账号", "Create account":"创建账号", "Send":"发送", "SEND":"转账", "CONFIRM":"确认", "Accounts":"账号", "Account(s)":"账号",
@ -1314,7 +1313,7 @@ LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成
"From:":"付款:", "Set a password for protect entry":"设置密码保护钱包", "Enter password to unlock wallet":"输入密码解锁钱包", "From ID:":"付款ID:",
"Pay to ID:":"收款ID:", "Account":"账号", "Owner":"拥有者", "Block num":"区块编号", "Private key (secret)":"私钥 (机密)", "Load key":"载入私钥",
"Create your first account and start using TERA":"创建你的第一个账号,开启TERA之旅", "0 Accounts":"0 账号", "OWNER: {Item.Owner}":"拥有者: {Item.Owner}",
"More info":"详情", "Public key":"公钥", "HELP: Tera Wallet creation Guide...":"TERA钱包创指南", "==HELP-LINK==":"https://terafoundation.org/files/Tera-Wallet-cn.pdf",
"More info":"详情", "Public key":"公钥", "Tera Wallet Guide...":"TERA钱包创指南", "==HELP-LINK==":"https://terafoundation.org/files/Tera-Wallet-cn.pdf",
};
LangMap["한글"] = {"TERA WALLET":"TERA 지갑", "Generate key":"개인 키 생성", "OK":"OK", "Cancel":"취소", "Edit":"편집", "Save key":"개인 키 저장",
"+ CREATE A NEW ACCOUNT":"+ 새 계정 만들기", "Create account":"계정 만들기", "Send":"발송", "CONFIRM":"확인", "Accounts":"계정", "Account(s)":"계정",

@ -216,6 +216,13 @@ function WriteUintToArrOnPos(arr,Num,Pos)
arr[Pos + 5] = (NumH >>> 8) & 0xFF;
};
function WriteUint16ToArr(arr,Num)
{
var len = arr.length;
arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF;
};
function WriteUint32ToArr(arr,Num)
{
var len = arr.length;

@ -129,8 +129,8 @@ function GetAccountText(Item,Num,bGetSum)
text = "" + Num + ". " + text;
if(bGetSum)
{
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency);
text += " (" + StrSum + ")";
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency, 1);
text += " : " + StrSum;
}
return text;
}

@ -933,7 +933,7 @@
<DIV>
<DIV>
Name:<INPUT type="string" id="idName" style="width: 20%;" value="">
Accounts:<INPUT type="number" id="idAccountLength" min=1 max=50 style="width: 5%;" value="1">
Acc count:<INPUT type="number" id="idAccountLength" min=1 max=50 style="width: 5%;" value="1">
<INPUT type="button" onclick="SendToBlockchain()" class="bt btdoit" style="width: 150px; " id="idBtSendSmart" value="Send to blockchain">
<select size="1" id="idUser" class="" style="width: 300px" onchange="SaveValues()">
<option value="">loading</option>

@ -26,6 +26,7 @@
var NumDappGet=0;
var NumDappInfo=0;
var DAPPPREFIX="DAPP-";
var MAX_DELTA_IGNORE_BUFFER=10;
//DAPP TRANSFER
@ -70,8 +71,8 @@
case "getstorage":
{
Data.Value=Storage.getItem(DAPPPREFIX+DapNumber+"-"+Data.Key);
if(Data.Value)
Data.Value=JSON.parse(Data.Value);
if(Data.Value && Data.Value!=="undefined")
try {Data.Value=JSON.parse(Data.Value);}catch (e){};
SendMessage(Data);
break;
}
@ -83,8 +84,8 @@
case "getcommon":
{
Data.Value=Storage.getItem(DAPPPREFIX+Data.Key);
if(Data.Value)
Data.Value=JSON.parse(Data.Value);
if(Data.Value && Data.Value!=="undefined")
try {Data.Value=JSON.parse(Data.Value);}catch (e){};
SendMessage(Data);
break;
}
@ -136,16 +137,27 @@
{
if(SetData)
{
//ToLog("glSession="+glSession+" RES:"+SetData.result+" SetData.cache="+SetData.cache+" CurBlockNum="+SetData.CurBlockNum);
Data.Err=!SetData.result;
Data.cache=SetData.cache;
if(SetData.result)
{
CONFIG_DATA=SetData;
SMART=SetData.Smart;
BASE_ACCOUNT=SetData.Account;
SetBlockChainConstant(SetData);
if(SetData.cache)
{
for(var key in SetData)
CONFIG_DATA[key]=SetData[key];
SetData=CONFIG_DATA;
}
else
{
CONFIG_DATA=SetData;
SMART=SetData.Smart;
BASE_ACCOUNT=SetData.Account;
SetArrLog(SetData.ArrLog);
}
NumDappInfo=SetData.NumDappInfo;
SetArrLog(SetData.ArrLog);
SetBlockChainConstant(SetData);
for(var key in SetData)
@ -179,11 +191,13 @@
case "DappTransactionList":
{
if(Data.cmd==="DappBlockFile")
if(Data.cmd==="DappBlockFile"
&& Data.Params.BlockNum<=CONFIG_DATA.CurBlockNum-MAX_DELTA_IGNORE_BUFFER)
{
//check storage
var StrKeyStorage=Data.Params.BlockNum+"-"+Data.Params.TrNum;
//ToLog("StrKeyStorage: "+StrKeyStorage);
var Storage2=sessionStorage;
var SavedTextData=Storage2[StrKeyStorage];
if(SavedTextData)
@ -277,6 +291,12 @@
CreateNewAccount(Data.Currency);
break;
}
case "ReloadDapp":
{
ReloadDapp();
break;
}
}
}
@ -378,6 +398,7 @@
{
var StrPath=GetProtocolServerPath(MainServer);
//поддрежка старого кода dapp (после обновления dapp этот код возможно будет удален)
SetData.Body=SetData.Body.replace(/.\/CSS\/[0-9a-z_-]+.css\">/g,StrPath+"$&");
SetData.Body=SetData.Body.replace(/.\/JS\/[0-9a-z_-]+.js\">/g,StrPath+"$&");
@ -407,6 +428,14 @@
<script type="text/javascript" src="./JS/terahashlib.js"><\/script>\
'+SriptLW+SetData.Body;
SetData.Body+=$("idModalCSS").outerHTML;
SetData.Body+=$("idOverlay").outerHTML;
SetData.Body+=$("idConfirm").outerHTML;
iframe.srcdoc=SetData.Body;
document.getElementsByTagName('body')[0].appendChild(iframe);
@ -455,7 +484,6 @@
StrRef='<A class="btcreate" href="'+GetWalletLink()+'">Accounts</A>';
}
//var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button> or goto '+StrRef+' tab and Set smart number <B>'+SMART.Num+'</B> to your account<DIV>';
var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button><DIV>';
SetStatus(Str);
}
@ -662,7 +690,7 @@
CloseMenu();
}
break;
case 115:
case 116:
e.preventDefault();
ReloadDapp();
break;
@ -814,6 +842,7 @@
</style>
</head>
<body>
<DIV id="idStatus" class="top"></DIV>
@ -821,16 +850,77 @@
<div id="idMenuList" class="top open">
<div class="item" onclick="OpenWalletPage();">Open wallet page</div>
<div class="item" onclick="RunDappFromFile();" id="idRunItem">Load from file...</div>
<div class="item" onclick="ReloadDapp();">F4: Rerun</div>
<div class="item" onclick="ReloadDapp();">F5: ReRun</div>
<div class="item" onclick="window.location.reload();">Reset</div>
<div class="item" onclick="InstallApp();" id="idCreateItem">Create account with DApp NNN</div>
</div>
</DIV>
<input type="file" id="idFile" style="display: none">
<!--modal support dor dapp-->
<style id="idModalCSS">
/*modal support*/
#idOverlay
{
background: rgba(68, 83, 104, 0.65);
position: fixed;
width: 100%;
height: 100vh;
top: 0;
display: none;
}
.ModalDlg
{
z-index: 1000;
padding: 30px;
background: #fff;
border-radius: 5px;
border: 1px solid #727473;
box-shadow: 0px 8px 10px rgba(68, 83, 104, 0.15);
color: #000;
position: fixed;
margin: 0 auto;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 250px;
width: 87%;
}
.bt-confirm
{
border-radius: 4px;
min-height: 14px;
margin: 5px;
width: 100px;
height: 36px;
color:white;
background-color: #53687e;
border-color: #445368;
}
.bt-confirm:hover
{
color: #cb763a;
cursor: pointer;
}
</style>
<div id="idOverlay" onclick="closeModal()" style="display: none;"></div>
<section id="idConfirm" class="ModalDlg" style="display: none;">
<DIV align='center'>
<h2 id="idConfirmTitle">Confirm</h2>
<p id="idConfirmText">A you sure?</p>
<button class="bt-confirm" onclick="OnConfirmOK()">OK</button>
<button class="bt-confirm" onclick="closeModal()">Cancel</button>
</DIV>
</section>
</body>
</html>
<script>
var glDebugPath="";
//glDebugPath="./dapp-smart/mixer/mixer.html";
//{"HTMLBlock":2303846,"HTMLTr":0}
</script>

File diff suppressed because it is too large Load Diff

@ -63,7 +63,7 @@
</svg>
</div>
<h1 class="welcome__title title">Welcome to TERA Wallet</h1>
<p><a onclick="OpenHelp()" class="pointer">HELP: Tera Wallet creation Guide...</a></p>
<p><a onclick="OpenHelp()" class="pointer">Tera Wallet Guide...</a></p>
<p><a onclick="SelectTab('TabKeySet')" class="pointer">ATTENTION: Before using the wallet, save the private key.</a></p>
<ul id="idStableScroll" align='center' class="social-list">

@ -8,7 +8,7 @@
* Telegram: https://t.me/terafoundation
*/
global.UPDATE_CODE_VERSION_NUM = 1194;
global.UPDATE_CODE_VERSION_NUM = 1213;
global.MIN_CODE_VERSION_NUM = 1114;
global.MINING_VERSION_NUM = 0;
global.InitParamsArg = InitParamsArg;
@ -21,6 +21,7 @@ global.CONST_NAME_ARR = ["AUTO_CORRECT_TIME", "DELTA_CURRENT_TIME", "COMMON_KEY"
"HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "HTTP_ADMIN_PASSWORD", "HTTP_START_PAGE", "WATCHDOG_BADACCOUNT", "RESYNC_CONDITION",
"MAX_CONNECTIONS_COUNT", "TRUST_PROCESS_COUNT", "REST_START_COUNT", "LOAD_TO_BEGIN", ];
global.UPDATE_CODE_1 = 36000000;
global.UPDATE_CODE_2 = 40000000;
global.MAX_LENGTH_SENDER_MAP = 3000;
global.DELTA_START_SENDER_MAP = 24;
global.NODES_DELTA_CALC_HOUR = 4;
@ -171,6 +172,7 @@ if(global.LOCAL_RUN)
global.AUTO_CORRECT_TIME = 0;
global.CHECK_GLOBAL_TIME = 0;
global.UPDATE_CODE_1 = 0;
global.UPDATE_CODE_2 = 0;
}
else
if(global.TEST_NETWORK)
@ -207,6 +209,7 @@ else
global.LOAD_TO_BEGIN = 2;
global.START_BAD_ACCOUNT_CONTROL = 3105000;
global.UPDATE_CODE_1 = 3180000;
global.UPDATE_CODE_2 = 4000000;
}
global.GetNetworkName = function ()
{

@ -332,6 +332,14 @@ function SendToResponceResult0(response)
var glBlock0;
HTTPCaller.DappStaticCall = function (Params,response)
{
var Result = RunStaticSmartMethod(ParseNum(Params.Account), Params.MethodName, Params.Params);
var Str = JSON.stringify(Result);
if(Str.length > 16000)
{
return {result:0, RetValue:"Error result length (more 16000)"};
}
response.end(Str);
return null;
DApps.Accounts.BeginBlock();
DApps.Accounts.BeginTransaction();
global.TickCounter = 100000;
@ -345,7 +353,9 @@ HTTPCaller.DappStaticCall = function (Params,response)
var RetValue;
try
{
RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, 0, 0, undefined, Params.MethodName, Params.Params, 1);
var BlockNum = GetCurrentBlockNumByTime();
RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, BlockNum, 0, undefined, Params.MethodName, Params.Params,
1);
}
catch(e)
{
@ -409,7 +419,6 @@ HTTPCaller.DappInfo = function (Params,responce,ObjectOnly)
{
Ret.CurTime = Date.now();
Ret.CurBlockNum = GetCurrentBlockNumByTime();
Ret.BlockNumDB = SERVER.BlockNumDB;
Ret.MaxAccID = DApps.Accounts.GetMaxAccount();
Ret.MaxDappsID = DApps.Smart.GetMaxNum();
}
@ -1895,6 +1904,8 @@ function GetUserContext(Params)
if(!Context)
{
Context = {NumDappInfo:0, PrevDappInfo:"", NumAccountList:0, PrevAccountList:"", LastTime:0, FromEventNum:0};
Context.Session = Params.Session;
Context.Key = StrKey;
WebWalletUser[StrKey] = Context;
}
return Context;

@ -42,7 +42,7 @@ module.exports = class CRest extends require("./db/block-db")
return ;
}
this.LoadRestContext = {Mode:0, BlockNum:BlockNumRest, BlockNumRest:BlockNumRest, WasDelta:Delta, BlockNumProof:BlockNumRest + DELTA_BLOCK_ACCOUNT_HASH,
CountProof:COUNT_BLOCKS_FOR_LOAD, StartTimeHistory:Date.now(), MaxTimeOut:600 * 1000, LoopSyncRest:1, SendGetHeaderCount:0,
CountProof:COUNT_BLOCKS_FOR_LOAD, StartTimeHistory:Date.now(), MaxTimeOut:3600 * 1000, LoopSyncRest:1, SendGetHeaderCount:0,
ReceiveHeaderCount:0, ArrProof:[], MapSend:{}}
for(var i = 0; i < this.NodesArr.length; i++)
{

@ -632,7 +632,7 @@ HostingCaller.GetAccountListByKey = function (Params,aaa,bbb,bRet)
if(!Data.PubKeyStr)
Data.PubKeyStr = GetHexFromArr(Data.PubKey);
if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency);
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1);
if(Data.Value.Smart)
{
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart);
@ -742,15 +742,17 @@ HostingCaller.DappInfo = function (Params)
var StrInfo = JSON.stringify(Ret);
if(!Params.AllData && Context.PrevDappInfo === StrInfo)
{
return {result:0, cache:1};
Ret = {result:2, cache:1, Session:Context.Session};
}
else
{
Context.PrevDappInfo = StrInfo;
Context.NumDappInfo++;
Context.LastTime = Date.now();
}
Context.PrevDappInfo = StrInfo;
Context.NumDappInfo++;
Context.LastTime = Date.now();
Ret.NumDappInfo = Context.NumDappInfo;
Ret.CurTime = Date.now();
Ret.CurBlockNum = GetCurrentBlockNumByTime();
Ret.BlockNumDB = SERVER.BlockNumDB;
Ret.MaxAccID = DApps.Accounts.GetMaxAccount();
Ret.MaxDappsID = DApps.Smart.GetMaxNum();
return Ret;

@ -973,7 +973,7 @@ class AccountApp extends require("./dapp")
var Count = 0;
for(var num = 0; true; num++)
{
if(this.IsHole(num) || HiddenMap[num] !== undefined)
if(this.IsHole(num) || (HiddenMap && HiddenMap[num] !== undefined))
continue;
var Data = this.ReadState(num);
if(!Data)
@ -1002,7 +1002,9 @@ class AccountApp extends require("./dapp")
Data.WN = map[key]
Data.Name = NormalizeName(Data.Name)
if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency)
{
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1)
}
if(Data.Value.Smart)
{
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart)
@ -1093,7 +1095,7 @@ class AccountApp extends require("./dapp")
if(bGetState)
{
if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1)
if(Data.Value.Smart)
{
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart)

@ -28,7 +28,9 @@ global.FORMAT_SMART_CREATE = "{\
Category1:byte,\
Category2:byte,\
Category3:byte,\
Reserve:arr20,\
Fixed:byte,\
CentName:str5,\
Reserve:arr14,\
IconBlockNum:uint,\
IconTrNum:uint16,\
ShortName:str5,\
@ -82,7 +84,9 @@ class SmartApp extends require("./dapp")
Category2:byte,\
Category3:byte,\
Owner:uint,\
Reserve:arr20,\
Fixed:byte,\
CentName:str5,\
Reserve:arr14,\
StateFormat:str,\
Description:str,\
Code:str,\
@ -238,7 +242,6 @@ class SmartApp extends require("./dapp")
Smart.Zip = 0
Smart.BlockNum = BlockNum
Smart.TrNum = TrNum
Smart.Reserve = []
Smart.Num = undefined
Smart.Owner = ContextFrom.FromID
this.DBSmart.CheckNewNum(Smart)
@ -275,6 +278,10 @@ class SmartApp extends require("./dapp")
this.DBSmart.DeleteMap("EVAL" + Smart.Num)
return e;
}
if(BlockNum < global.UPDATE_CODE_2)
{
Smart.Reserve = []
}
this.DBSmartWrite(Smart)
return true;
}
@ -502,7 +509,7 @@ class SmartApp extends require("./dapp")
}
return Smart;
}
ReadSimple(Num)
ReadSimple(Num, bTokenDescription)
{
var Smart = this.DBSmart.GetMap("SIMPLE" + Num);
if(!Smart)
@ -512,14 +519,70 @@ class SmartApp extends require("./dapp")
{
Smart.CodeLength = Smart.Code.length
Smart.HTMLLength = Smart.HTML.length
Smart.Code = undefined
Smart.HTML = undefined
Smart.Description = undefined
Object.defineProperties(Smart, {Reserve:{configurable:true, enumerable:false}})
Object.defineProperties(Smart, {Code:{configurable:true, enumerable:false}})
Object.defineProperties(Smart, {HTML:{configurable:true, enumerable:false}})
Object.defineProperties(Smart, {Description:{configurable:true, enumerable:false}})
this.DBSmart.SetMap("SIMPLE" + Num, Smart)
}
}
if(bTokenDescription)
this.AddCurrencyTokenDescription(Smart)
return Smart;
}
AddCurrencyTokenDescription(Smart)
{
if(!Smart.Num)
return ;
if(!this.MapTokenDescription)
this.MapTokenDescription = {}
var Item = this.MapTokenDescription[Smart.Num];
var Time = Date.now();
if(!Item)
{
Item = {Time:Time, Description:""}
this.MapTokenDescription[Smart.Num] = Item
}
if(Time - Item.Time > 5 * 1000)
{
Item.Time = Time
var Params = undefined;
var BlockNum = GetCurrentBlockNumByTime();
if(BlockNum < UPDATE_CODE_2)
{
try
{
var Account = DApps.Accounts.ReadState(Smart.Account);
if(Smart.StateFormat)
{
var State = BufLib.GetObjectFromBuffer(Account.Value.Data, Smart.StateFormat, {}, 1);
Params = {State:State, PayCur:GET_SMART(DApps.Smart.ReadSmart(State.PayCurrency)), OpnCur:GET_SMART(DApps.Smart.ReadSmart(State.Currency)),
}
}
}
catch(e)
{
}
}
else
{
Params = {}
}
var Result;
if(Params)
Result = RunStaticSmartMethod(Smart.Account, "GetTokenDescription", Params)
if(Result && Result.result)
{
Item.TokenDescription = Result.RetValue
}
else
{
Item.TokenDescription = ""
Item.Time = Time + 1000 * 1000
}
}
Smart.TokenDescription = Item.TokenDescription
}
InitHole()
{
if(global.LOCAL_RUN || global.TEST_NETWORK)
@ -628,7 +691,7 @@ function RunSmartMethod(Block,SmartOrSmartID,Account,BlockNum,TrNum,PayContext,M
if(PayContext.Value)
context.Value = {SumCOIN:PayContext.Value.SumCOIN, SumCENT:PayContext.Value.SumCENT};
}
if(BlockNum === 0)
if(Block.BlockNum === 0)
{
context.GetBlockHeader = StaticGetBlockHeader;
context.GetBlockNumDB = StaticGetBlockNumDB;
@ -653,6 +716,32 @@ function RunSmartMethod(Block,SmartOrSmartID,Account,BlockNum,TrNum,PayContext,M
}
return RetValue;
};
var glBlock0;
global.RunStaticSmartMethod = RunStaticSmartMethod;
function RunStaticSmartMethod(AccountNum,MethodName,Params)
{
DApps.Accounts.BeginBlock();
DApps.Accounts.BeginTransaction();
global.TickCounter = 100000;
var Account = DApps.Accounts.ReadStateTR(AccountNum);
if(!Account)
{
return {result:0, RetValue:"Error account Num: " + AccountNum};
}
if(!glBlock0)
glBlock0 = SERVER.ReadBlockHeaderDB(0);
try
{
var BlockNum = GetCurrentBlockNumByTime();
var RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, BlockNum, 0, undefined, MethodName, Params, 1);
return {result:1, RetValue:RetValue};
}
catch(e)
{
return {result:0, RetValue:"" + e};
}
};
function GET_ACCOUNT(Obj)
{
@ -739,6 +828,15 @@ function GET_SMART(Obj)
}, get HTML()
{
return Data.HTML;
}, get Fixed()
{
return Data.Fixed;
}, get CoinName()
{
return Data.ShortName;
}, get CentName()
{
return Data.CentName;
}, };
return GET_PROP;
};
@ -937,6 +1035,7 @@ function InitEval()
Object.freeze($GetHexFromArr);
Object.freeze($GetArrFromHex);
Object.freeze($sha);
Object.freeze($ReadSmart);
Object.freeze($isFinite);
Object.freeze($isNaN);
Object.freeze($parseFloat);
@ -1083,6 +1182,7 @@ function $SetValue(ID,CoinSum)
{
CoinSum = COIN_FROM_FLOAT(CoinSum);
}
CHECKSUM(CoinSum);
if(CoinSum.SumCENT >= 1e9)
{
throw "ERROR SumCENT>=1e9";
@ -1119,7 +1219,7 @@ function $Send(ToID,CoinSum,Description)
}
if(RunContext.Account.Currency !== ToData.Currency)
{
throw "Different currencies";
throw "Different currencies. Accounts: " + RunContext.Account.Num + " and " + ToID;
}
DApps.Accounts.SendMoneyTR(RunContext.Block, RunContext.Account.Num, ToID, CoinSum, RunContext.BlockNum, RunContext.TrNum,
Description, Description, 1);
@ -1142,7 +1242,7 @@ function $Move(FromID,ToID,CoinSum,Description)
}
if(FromData.Currency !== ToData.Currency)
{
throw "Different currencies";
throw "Different currencies. Accounts: " + FromID + " and " + ToID;
}
if(FromData.Value.Smart !== RunContext.Smart.Num)
{
@ -1190,6 +1290,20 @@ function $ReadAccount(ID)
return GET_ACCOUNT(Account);
};
function $ReadSmart(ID)
{
if(RunContext.BlockNum < global.UPDATE_CODE_2)
{
throw "Method call not available";
}
DO(900);
ID = ParseNum(ID);
var Smart = DApps.Smart.ReadSmart(ID);
if(!Smart)
throw "Error smart ID: " + ID;
return GET_SMART(Smart);
};
function $ReadState(ID)
{
DO(900);

Loading…
Cancel
Save