This commit is contained in:
progr76@gmail.com 2019-02-12 21:41:41 +03:00
parent 9eefdc7aad
commit 4ae7e3b8bc
25 changed files with 465 additions and 88 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,9 @@
## API ## API v1
This API is available if the node is running public http-access. Set the constant HTTP_HOSTING_PORT. This API is available if the node is running public http-access. Set the constant HTTP_HOSTING_PORT.
#### Getting the current status of the blockchain #### Getting the current status of the blockchain
http://194.1.237.94/GetCurrentInfo?Diagram=0 http://194.1.237.94/api/v1/GetCurrentInfo
Result: Result:
* MaxNumBlockDB - the maximum block number stored in the database (the current height of the blockchain) * MaxNumBlockDB - the maximum block number stored in the database (the current height of the blockchain)
@ -19,7 +19,7 @@ An example of the result:
``` ```
#### Get a list of nodes that have a public API #### Get a list of nodes that have a public API
http://194.1.237.94/GetNodeList http://194.1.237.94/api/v1/GetNodeList
An example of the result: An example of the result:
``` ```
@ -28,7 +28,7 @@ An example of the result:
#### Getting a list of accounts #### Getting a list of accounts
http://194.1.237.94/GetAccountList?StartNum=0&CountNum=1 http://194.1.237.94/api/v1/GetAccountList?StartNum=0&CountNum=1
An example of the result: An example of the result:
``` ```
@ -36,7 +36,7 @@ An example of the result:
``` ```
#### Getting a list of blocks #### Getting a list of blocks
http://194.1.237.94/GetBlockList?StartNum=12373020&CountNum=1 http://194.1.237.94/api/v1/GetBlockList?StartNum=12373020&CountNum=1
An example of the result: An example of the result:
``` ```
@ -44,7 +44,7 @@ An example of the result:
``` ```
#### Getting a list of block transactions #### Getting a list of block transactions
http://194.1.237.94/GetTransactionList?BlockNum=12373020?StartNum=0&CountNum=10 http://194.1.237.94/api/v1/GetTransactionList?BlockNum=12373020?StartNum=0&CountNum=10
An example of the result: An example of the result:
``` ```
@ -54,7 +54,7 @@ An example of the result:
#### Getting a list of DAPs #### Getting a list of DAPs
http://194.1.237.94/GetDappList?StartNum=8&CountNum=1 http://194.1.237.94/api/v1/GetDappList?StartNum=8&CountNum=1
An example of the result: An example of the result:
``` ```
@ -64,7 +64,7 @@ An example of the result:
#### Getting a list of accounts by public key #### Getting a list of accounts by public key
http://194.1.237.94/GetAccountListByKey?Key=027AE0DCE92D8BE1F893525B226695DDF0FE6AD756349A76777FF51F3B59067D70 http://194.1.237.94/api/v1/GetAccountListByKey?Key=027AE0DCE92D8BE1F893525B226695DDF0FE6AD756349A76777FF51F3B59067D70
Result: Result:
``` ```
@ -74,7 +74,7 @@ Note: public key in hex format can be taken from the wallet on EXPLORER -> Accou
#### Sending a transaction #### Sending a transaction
http://194.1.237.94/SendTransactionHex?Hex=6F030000000000002D00000000000100000000008400000000000100000000000000000004007465737425000000000000007AA29739FD458DF8AB1139881DAA4584CCDA3D4995B6849FB1F55F3B2EA40704116647823E97A60C70213EFA8D83CBFBEE6D753FCA6771B4792985B57186F3BCFBCEC0000000930600000000 http://194.1.237.94/api/v1/SendTransactionHex?Hex=6F030000000000002D00000000000100000000008400000000000100000000000000000004007465737425000000000000007AA29739FD458DF8AB1139881DAA4584CCDA3D4995B6849FB1F55F3B2EA40704116647823E97A60C70213EFA8D83CBFBEE6D753FCA6771B4792985B57186F3BCFBCEC0000000930600000000
Result: Result:
``` ```

View File

@ -1,4 +1,4 @@
## API ## API v1
Данный API доступен если на ноде запущен публичный http-доступ. Т.е. задана константа HTTP_HOSTING_PORT Данный API доступен если на ноде запущен публичный http-доступ. Т.е. задана константа HTTP_HOSTING_PORT
@ -54,7 +54,7 @@ http://194.1.237.94/GetTransactionList?BlockNum=12373020?StartNum=0&CountNum=10
#### Получение списка ДАпов #### Получение списка ДАпов
http://194.1.237.94/GetDappList?StartNum=8&CountNum=1 http://194.1.237.94/api/v1/GetDappList?StartNum=8&CountNum=1
Пример результата: Пример результата:
``` ```
@ -63,7 +63,7 @@ http://194.1.237.94/GetDappList?StartNum=8&CountNum=1
#### Получение списка счетов по публичному ключу #### Получение списка счетов по публичному ключу
http://194.1.237.94/GetAccountListByKey?Key=027AE0DCE92D8BE1F893525B226695DDF0FE6AD756349A76777FF51F3B59067D70 http://194.1.237.94/api/v1/GetAccountListByKey?Key=027AE0DCE92D8BE1F893525B226695DDF0FE6AD756349A76777FF51F3B59067D70
Результат: Результат:
@ -74,7 +74,7 @@ http://194.1.237.94/GetAccountListByKey?Key=027AE0DCE92D8BE1F893525B226695DDF0FE
#### Отправка транзакции #### Отправка транзакции
http://194.1.237.94/SendTransactionHex?Hex=6F030000000000002D00000000000100000000008400000000000100000000000000000004007465737425000000000000007AA29739FD458DF8AB1139881DAA4584CCDA3D4995B6849FB1F55F3B2EA40704116647823E97A60C70213EFA8D83CBFBEE6D753FCA6771B4792985B57186F3BCFBCEC0000000930600000000 http://194.1.237.94/api/v1/SendTransactionHex?Hex=6F030000000000002D00000000000100000000008400000000000100000000000000000004007465737425000000000000007AA29739FD458DF8AB1139881DAA4584CCDA3D4995B6849FB1F55F3B2EA40704116647823E97A60C70213EFA8D83CBFBEE6D753FCA6771B4792985B57186F3BCFBCEC0000000930600000000
Результат: Результат:
``` ```

View File

@ -1300,7 +1300,6 @@ function ParseFileName(Str)
} }
return Ret; return Ret;
}; };
var glTrSendNum = 0;
window.MapSendTransaction = {}; window.MapSendTransaction = {};
function SendTransaction(Body,TR,SumPow,F) function SendTransaction(Body,TR,SumPow,F)
@ -1313,7 +1312,6 @@ function SendTransaction(Body,TR,SumPow,F)
F(1, TR, Body); F(1, TR, Body);
return ; return ;
} }
glTrSendNum++;
if(window.SetStatus) if(window.SetStatus)
SetStatus("Prepare to sending..."); SetStatus("Prepare to sending...");
CreateNonceAndSend(1, 0, 0); CreateNonceAndSend(1, 0, 0);
@ -1322,10 +1320,9 @@ function CreateNonceAndSend(bCreateNonce,startnonce,NumNext)
{ {
if(!NumNext) if(!NumNext)
NumNext = 0; NumNext = 0;
var CurTrNum = glTrSendNum;
var nonce = startnonce; var nonce = startnonce;
if(bCreateNonce) if(bCreateNonce)
nonce = CreateHashBodyPOWInnerMinPower(Body, SumPow); nonce = CreateHashBodyPOWInnerMinPower(Body, SumPow, startnonce);
var StrHex = GetHexFromArr(Body); var StrHex = GetHexFromArr(Body);
if(NumNext > 10) if(NumNext > 10)
{ {

View File

@ -110,7 +110,7 @@ window.SetBlockChainConstant = function (Data)
Data.DELTA_CURRENT_TIME = 0; Data.DELTA_CURRENT_TIME = 0;
window.DELTA_CURRENT_TIME2 = Data.DELTA_CURRENT_TIME - DeltaServerClient; window.DELTA_CURRENT_TIME2 = Data.DELTA_CURRENT_TIME - DeltaServerClient;
window.MIN_POWER_POW_TR = DELTA_POWER_POW_TR + Data.MIN_POWER_POW_TR; window.MIN_POWER_POW_TR = DELTA_POWER_POW_TR + Data.MIN_POWER_POW_TR;
window.MIN_POWER_POW_ACC_CREATE = Data.MIN_POWER_POW_ACC_CREATE + 3; window.MIN_POWER_POW_ACC_CREATE = Data.MIN_POWER_POW_ACC_CREATE;
window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK; window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK;
window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME; window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME;
window.GetCurrentBlockNumByTime = function () window.GetCurrentBlockNumByTime = function ()
@ -143,7 +143,7 @@ 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) function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
{ {
var TrType = arr[0]; var TrType = arr[0];
var BlockNum = GetBlockNumTr(arr); var BlockNum = GetBlockNumTr(arr);
@ -151,7 +151,7 @@ function CreateHashBodyPOWInnerMinPower(arr,MinPow)
{ {
MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128); MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128);
} }
var nonce = 0; var nonce = startnonce;
while(1) while(1)
{ {
var arrhash = CreateHashBody(arr, BlockNum, nonce); var arrhash = CreateHashBody(arr, BlockNum, nonce);
@ -265,7 +265,7 @@ function ComputeSecretWithCheck(PubKey,StrPrivKey,F)
F(sha3(Result)); F(sha3(Result));
}; };
function ComputeSecret(PubKey,F) function ComputeSecret(Account,PubKey,F)
{ {
if(localStorage["idPrivKey"]) if(localStorage["idPrivKey"])
{ {
@ -273,7 +273,7 @@ function ComputeSecret(PubKey,F)
} }
else else
{ {
GetData("GetWalletInfo", {}, function (Data) GetData("GetWalletInfo", {Account:Account}, function (Data)
{ {
if(!Data || !Data.result) if(!Data || !Data.result)
return ; return ;

View File

@ -125,13 +125,15 @@ function OpenLink(Str)
SendData({cmd:"OpenLink", Message:Str}); SendData({cmd:"OpenLink", Message:Str});
}; };
function ComputeSecret(PubKey,F) 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)
Account = USER_ACCOUNT[0].Num;
if(typeof PubKey === "number") if(typeof PubKey === "number")
{ {
var AccNum = PubKey; var AccNum = PubKey;
@ -143,13 +145,13 @@ function ComputeSecret(PubKey,F)
} }
else else
{ {
SendData({cmd:"ComputeSecret", PubKey:Arr[0].PubKey.data}, F); SendData({cmd:"ComputeSecret", Account:Account, PubKey:Arr[0].PubKey.data}, F);
} }
}); });
} }
else else
{ {
SendData({cmd:"ComputeSecret", PubKey:PubKey}, F); SendData({cmd:"ComputeSecret", Account:Account, PubKey:PubKey}, F);
} }
}; };

10
Source/HTML/JS/tx-lib.js Normal file
View File

@ -0,0 +1,10 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/

View File

@ -173,8 +173,9 @@ function CreateTransaction(F,CheckErr,Run)
} }
else else
{ {
ToID = 0; if(CheckErr)
ToPubKey = ""; SetError("Valid 'Pay to' - required!");
return ;
} }
} }
if(CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem) if(CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem)

View File

@ -240,7 +240,7 @@
} }
case "ComputeSecret": case "ComputeSecret":
{ {
ComputeSecret(Data.PubKey,function (Result) ComputeSecret(Data.Account,Data.PubKey,function (Result)
{ {
Data.Result=Result; Data.Result=Result;
SendMessage(Data); SendMessage(Data);

View File

@ -85,7 +85,7 @@
//CONFIG //CONFIG
function IsPrivateMode() function IsPrivateMode()
{ {
if(PrivKeyStr && PrivKeyStr.length===64) if(PrivKeyStr && PrivKeyStr.length===64 && PrivKeyStr!=="0000000000000000000000000000000000000000000000000000000000000000")
return true; return true;
else else
return false; return false;
@ -890,7 +890,7 @@
if(window.location.hash) if(window.location.hash)
{ {
var LocationPath=window.location.hash.substr(1); var LocationPath=window.location.hash.substr(1);
console.log("LocationPath="+LocationPath) //console.log("LocationPath="+LocationPath)
if(LocationPath) if(LocationPath)
{ {
SelectTab(LocationPath); SelectTab(LocationPath);

View File

@ -22,6 +22,7 @@
<script> <script>
// window.WEBWALLET=1; // window.WEBWALLET=1;
var PubKeyStr;
var NumAccountList=0; var NumAccountList=0;
//Pagination //Pagination

View File

@ -307,8 +307,8 @@
<td>120 KB</td> <td>120 KB</td>
<td>5%</td> <td>5%</td>
<td> <td>
<a href="https://sourceforge.net/p/tera/code/ci/master/tree/" target="_blank">sourceforge.net <a href="https://sourceforge.net/p/tera/code/ci/master/tree/" target="_blank">sourceforge.net</a>,
</a> <a href="https://gitlab.com/terafoundation/tera" target="_blank">gitlab.com</a>
</td> </td>
<td> <td>
<a href="https://terafoundation.org/explorer.html" target="_blank">terafoundation.org</a> <a href="https://terafoundation.org/explorer.html" target="_blank">terafoundation.org</a>

View File

@ -0,0 +1,45 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
const crypto = require('crypto');
HTTPCaller.CreateAccount = function (Params,response)
{
if(typeof Params === "object" && Params.Name && Params.PubKey)
{
var TYPE_TRANSACTION_CREATE = 100;
var TR = {Type:TYPE_TRANSACTION_CREATE, Currency:Params.Currency, PubKey:GetArrFromHex(Params.PubKey), Description:Params.Name,
Smart:Params.Smart, Adviser:0, };
var Body = BufLib.GetBufferFromObject(TR, FORMAT_CREATE, 1000, {});
return {result:1};
}
return {result:0};
};
var MaxCountViewRows = global.HTTP_MAX_COUNT_ROWS;
HTTPCaller.GetBalance = function (Params)
{
if(typeof Params === "object")
{
var arr = DApps.Accounts.GetRowsAccounts(ParseNum(Params.AccountID), 1);
if(arr.length)
{
arr[0].result = 1;
return arr[0];
}
}
return {result:0};
};
HTTPCaller.GenerateKeys = function (Params)
{
var KeyPair = crypto.createECDH('secp256k1');
var PrivKey = sha3(crypto.randomBytes(32));
KeyPair.setPrivateKey(Buffer.from(PrivKey));
var PubKey = KeyPair.getPublicKey('', 'compressed');
return {result:1, PrivKey:GetHexFromArr(PrivKey), PubKey:GetHexFromArr(PubKey)};
};

View File

@ -0,0 +1,10 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/

View File

@ -163,7 +163,6 @@ function UpdateCodeFiles(StartNum)
} }
else else
{ {
global.UPDATE_CODE_VERSION_NUM = Num;
} }
return 1; return 1;
} }

View File

@ -8,17 +8,18 @@
* Telegram: https://web.telegram.org/#/im?p=@terafoundation * Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/ */
global.UPDATE_CODE_VERSION_NUM = 884; global.UPDATE_CODE_VERSION_NUM = 886;
global.MIN_CODE_VERSION_NUM = 874; global.MIN_CODE_VERSION_NUM = 884;
global.MINING_VERSION_NUM = 2; global.MINING_VERSION_NUM = 3;
global.InitParamsArg = InitParamsArg; global.InitParamsArg = InitParamsArg;
global.CONST_NAME_ARR = ["AUTO_COORECT_TIME", "DELTA_CURRENT_TIME", "COMMON_KEY", "NODES_NAME", "SERVER_PRIVATE_KEY_HEX", "USE_NET_FOR_SERVER_ADDRES", global.CONST_NAME_ARR = ["AUTO_COORECT_TIME", "DELTA_CURRENT_TIME", "COMMON_KEY", "NODES_NAME", "SERVER_PRIVATE_KEY_HEX", "USE_NET_FOR_SERVER_ADDRES",
"NET_WORK_MODE", "STAT_MODE", "MAX_STAT_PERIOD", "HTTP_PORT_NUMBER", "HTTP_PORT_PASSWORD", "HTTP_IP_CONNECT", "WALLET_NAME", "NET_WORK_MODE", "STAT_MODE", "MAX_STAT_PERIOD", "HTTP_PORT_NUMBER", "HTTP_PORT_PASSWORD", "HTTP_IP_CONNECT", "WALLET_NAME",
"WALLET_DESCRIPTION", "COUNT_VIEW_ROWS", "USE_HINT", "ALL_VIEW_ROWS", "ALL_LOG_TO_CLIENT", "USE_MINING", "MINING_START_TIME", "WALLET_DESCRIPTION", "USE_HARD_API_V2", "COUNT_VIEW_ROWS", "USE_HINT", "ALL_VIEW_ROWS", "ALL_LOG_TO_CLIENT", "USE_MINING",
"MINING_PERIOD_TIME", "POW_MAX_PERCENT", "COUNT_MINING_CPU", "SIZE_MINING_MEMORY", "POW_RUN_COUNT", "POW_RUN_COUNT_FIND", "USE_AUTO_UPDATE", "MINING_START_TIME", "MINING_PERIOD_TIME", "POW_MAX_PERCENT", "COUNT_MINING_CPU", "SIZE_MINING_MEMORY", "POW_RUN_COUNT", "POW_RUN_COUNT_FIND",
"RESTART_PERIOD_SEC", "MAX_GRAY_CONNECTIONS_TO_SERVER", "TRANSACTION_PROOF_COUNT", "UPDATE_NUM_COMPLETE", "LIMIT_SEND_TRAFIC", "USE_AUTO_UPDATE", "RESTART_PERIOD_SEC", "MAX_GRAY_CONNECTIONS_TO_SERVER", "TRANSACTION_PROOF_COUNT", "UPDATE_NUM_COMPLETE",
"WATCHDOG_DEV", "ADDRLIST_MODE", "CheckPointDelta", "MIN_VER_STAT", "DEBUG_WALLET", "HTTP_HOSTING_PORT", "HTTPS_HOSTING_DOMAIN", "LIMIT_SEND_TRAFIC", "WATCHDOG_DEV", "ADDRLIST_MODE", "CheckPointDelta", "MIN_VER_STAT", "DEBUG_WALLET", "HTTP_HOSTING_PORT",
"HTTP_MAX_COUNT_ROWS", "WATCHDOG_BADACCOUNT", "COREY_WATCH_DOG", "MAX_CONNECTIONS_COUNT", ]; "HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "WATCHDOG_BADACCOUNT", "COREY_WATCH_DOG", "MAX_CONNECTIONS_COUNT", ];
global.USE_HARD_API_V2 = 0;
global.USE_TICKET = 0; global.USE_TICKET = 0;
global.USE_CHECK_SENDING = 1; global.USE_CHECK_SENDING = 1;
global.USE_LEVEL_WAY = 0; global.USE_LEVEL_WAY = 0;
@ -96,6 +97,7 @@ global.GENERATE_BLOCK_ACCOUNT = 0;
global.TOTAL_TER_MONEY = 1e9; global.TOTAL_TER_MONEY = 1e9;
global.TRANSACTION_PROOF_COUNT = 1000 * 1000; global.TRANSACTION_PROOF_COUNT = 1000 * 1000;
global.MIN_POWER_POW_ACC_CREATE = 16; global.MIN_POWER_POW_ACC_CREATE = 16;
global.MIN_POWER_POW_ACC_CREATE_LAST = MIN_POWER_POW_ACC_CREATE + 3;
global.START_MINING = 2 * 1000 * 1000; global.START_MINING = 2 * 1000 * 1000;
global.REF_PERIOD_MINING = 1 * 1000 * 1000; global.REF_PERIOD_MINING = 1 * 1000 * 1000;
global.DELTA_BLOCK_ACCOUNT_HASH = 1000; global.DELTA_BLOCK_ACCOUNT_HASH = 1000;
@ -132,6 +134,7 @@ if(global.LOCAL_RUN)
global.TEST_TRANSACTION_GENERATE = 0; global.TEST_TRANSACTION_GENERATE = 0;
global.MIN_POWER_POW_TR = 8; global.MIN_POWER_POW_TR = 8;
global.MIN_POWER_POW_ACC_CREATE = 8; global.MIN_POWER_POW_ACC_CREATE = 8;
global.MIN_POWER_POW_ACC_CREATE_LAST = 8;
NETWORK = "LOCAL"; NETWORK = "LOCAL";
global.ALL_VIEW_ROWS = 1; global.ALL_VIEW_ROWS = 1;
} }
@ -146,6 +149,7 @@ else
global.REF_PERIOD_MINING = 1000; global.REF_PERIOD_MINING = 1000;
global.MIN_POWER_POW_TR = 8; global.MIN_POWER_POW_TR = 8;
global.MIN_POWER_POW_ACC_CREATE = 8; global.MIN_POWER_POW_ACC_CREATE = 8;
global.MIN_POWER_POW_ACC_CREATE_LAST = 8;
global.TRANSACTION_PROOF_COUNT = 200 * 1000; global.TRANSACTION_PROOF_COUNT = 200 * 1000;
global.MAX_SIZE_LOG = 20 * 1024 * 1024; global.MAX_SIZE_LOG = 20 * 1024 * 1024;
global.DELTA_BLOCK_ACCOUNT_HASH = 1000; global.DELTA_BLOCK_ACCOUNT_HASH = 1000;

View File

@ -302,7 +302,7 @@ HTTPCaller.DappInfo = function (Params,responce,ObjectOnly)
ArrLog.push(Item); ArrLog.push(Item);
} }
var Ret = {result:1, DELTA_CURRENT_TIME:DELTA_CURRENT_TIME, MIN_POWER_POW_TR:MIN_POWER_POW_TR, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK, var Ret = {result:1, DELTA_CURRENT_TIME:DELTA_CURRENT_TIME, MIN_POWER_POW_TR:MIN_POWER_POW_TR, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK,
CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME, MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE, PRICE_DAO:PRICE_DAO(SERVER.BlockNumDB), CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME, MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE_LAST, PRICE_DAO:PRICE_DAO(SERVER.BlockNumDB),
Smart:Smart, Account:Account, ArrWallet:WLData.arr, ArrEvent:EArr, ArrLog:ArrLog, }; Smart:Smart, Account:Account, ArrWallet:WLData.arr, ArrEvent:EArr, ArrLog:ArrLog, };
if(global.WALLET) if(global.WALLET)
{ {
@ -429,7 +429,7 @@ HTTPCaller.GetHistoryAct = function (Params)
var LastTimeGetHashRate = 0; var LastTimeGetHashRate = 0;
var LastHashRate = 0; var LastHashRate = 0;
var HashRateOneSec = 0; var HashRateOneSec = 0;
HTTPCaller.GetWalletInfo = function () HTTPCaller.GetWalletInfo = function (Params)
{ {
var Constants = {}; var Constants = {};
for(var i = 0; i < global.CONST_NAME_ARR.length; i++) for(var i = 0; i < global.CONST_NAME_ARR.length; i++)
@ -456,13 +456,16 @@ HTTPCaller.GetWalletInfo = function ()
ArrLog:ArrLogClient, MaxAccID:DApps.Accounts.GetMaxAccount(), MaxActNum:DApps.Accounts.GetActsMaxNum(), MaxDappsID:DApps.Smart.GetMaxNum(), ArrLog:ArrLogClient, MaxAccID:DApps.Accounts.GetMaxAccount(), MaxActNum:DApps.Accounts.GetActsMaxNum(), MaxDappsID:DApps.Smart.GetMaxNum(),
NeedRestart:global.NeedRestart, ip:SERVER.ip, port:SERVER.port, NET_WORK_MODE:global.NET_WORK_MODE, INTERNET_IP_FROM_STUN:global.INTERNET_IP_FROM_STUN, NeedRestart:global.NeedRestart, ip:SERVER.ip, port:SERVER.port, NET_WORK_MODE:global.NET_WORK_MODE, INTERNET_IP_FROM_STUN:global.INTERNET_IP_FROM_STUN,
HistoryMaxNum:MaxHistory, DELTA_CURRENT_TIME:DELTA_CURRENT_TIME, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK, CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME, HistoryMaxNum:MaxHistory, DELTA_CURRENT_TIME:DELTA_CURRENT_TIME, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK, CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME,
MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE, DATA_PATH:(DATA_PATH.substr(1, 1) === ":" ? DATA_PATH : GetNormalPathString(process.cwd() + "/" + DATA_PATH)), MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE_LAST, DATA_PATH:(DATA_PATH.substr(1, 1) === ":" ? DATA_PATH : GetNormalPathString(process.cwd() + "/" + DATA_PATH)),
NodeAddrStr:SERVER.addrStr, STAT_MODE:global.STAT_MODE, HTTPPort:global.HTTP_PORT_NUMBER, HTTPPassword:HTTP_PORT_PASSWORD, NodeAddrStr:SERVER.addrStr, STAT_MODE:global.STAT_MODE, HTTPPort:global.HTTP_PORT_NUMBER, HTTPPassword:HTTP_PORT_PASSWORD,
CONSTANTS:Constants, CheckPointBlockNum:CHECK_POINT.BlockNum, MiningAccount:global.GENERATE_BLOCK_ACCOUNT, CountMiningCPU:GetCountMiningCPU(), CONSTANTS:Constants, CheckPointBlockNum:CHECK_POINT.BlockNum, MiningAccount:global.GENERATE_BLOCK_ACCOUNT, CountMiningCPU:GetCountMiningCPU(),
CountRunCPU:global.ArrMiningWrk.length, MiningPaused:global.MiningPaused, HashRate:HashRateOneSec, MIN_POWER_POW_TR:MIN_POWER_POW_TR, CountRunCPU:global.ArrMiningWrk.length, MiningPaused:global.MiningPaused, HashRate:HashRateOneSec, MIN_POWER_POW_TR:MIN_POWER_POW_TR,
PRICE_DAO:PRICE_DAO(SERVER.BlockNumDB), NWMODE:global.NWMODE, PERIOD_ACCOUNT_HASH:PERIOD_ACCOUNT_HASH, MAX_ACCOUNT_HASH:DApps.Accounts.DBAccountsHash.GetMaxNum(), PRICE_DAO:PRICE_DAO(SERVER.BlockNumDB), NWMODE:global.NWMODE, PERIOD_ACCOUNT_HASH:PERIOD_ACCOUNT_HASH, MAX_ACCOUNT_HASH:DApps.Accounts.DBAccountsHash.GetMaxNum(),
TXBlockNum:TXBlockNum, }; TXBlockNum:TXBlockNum, };
Ret.PrivateKey = WALLET.KeyPair.PrivKeyStr; if(Params.Account)
Ret.PrivateKey = GetHexFromArr(WALLET.GetPrivateKey(WALLET.AccountMap[Params.Account]));
else
Ret.PrivateKey = GetHexFromArr(WALLET.GetPrivateKey());
Ret.PublicKey = WALLET.KeyPair.PubKeyStr; Ret.PublicKey = WALLET.KeyPair.PubKeyStr;
return Ret; return Ret;
}; };
@ -512,7 +515,7 @@ HTTPCaller.SendTransactionHex = function (Params)
{ {
var body = GetArrFromHex(Params.Hex); var body = GetArrFromHex(Params.Hex);
var Result = {result:1}; var Result = {result:1};
var Res = WALLET.AddTransaction({body:body, ToAll:1}); var Res = SERVER.AddTransactionOwn({body:body, ToAll:1});
Result.sessionid = sessionid; Result.sessionid = sessionid;
Result.text = AddTrMap[Res]; Result.text = AddTrMap[Res];
var final = false; var final = false;
@ -1339,10 +1342,12 @@ if(global.HTTP_PORT_NUMBER)
var remoteAddress = request.socket.remoteAddress.replace(/^.*:/, ''); var remoteAddress = request.socket.remoteAddress.replace(/^.*:/, '');
if(remoteAddress === "1") if(remoteAddress === "1")
remoteAddress = "127.0.0.1"; remoteAddress = "127.0.0.1";
var CheckPassword;
if(!global.HTTP_PORT_PASSWORD && remoteAddress.indexOf("127.0.0.1") < 0) if(!global.HTTP_PORT_PASSWORD && remoteAddress.indexOf("127.0.0.1") < 0)
return ; return ;
if(global.HTTP_IP_CONNECT && remoteAddress.indexOf("127.0.0.1") < 0 && global.HTTP_IP_CONNECT.indexOf(remoteAddress) < 0) if(global.HTTP_IP_CONNECT && remoteAddress.indexOf("127.0.0.1") < 0 && global.HTTP_IP_CONNECT.indexOf(remoteAddress) < 0)
return ; return ;
CheckPassword = 1;
SetSafeResponce(response); SetSafeResponce(response);
if(!global.SERVER) if(!global.SERVER)
{ {
@ -1358,7 +1363,7 @@ if(global.HTTP_PORT_NUMBER)
ToLog("CONNECT TO HTTP ACCESS FROM: " + remoteAddress); ToLog("CONNECT TO HTTP ACCESS FROM: " + remoteAddress);
ToLog("Path: " + Path); ToLog("Path: " + Path);
} }
if(global.HTTP_PORT_PASSWORD) if(CheckPassword && global.HTTP_PORT_PASSWORD)
{ {
var StrPort = ""; var StrPort = "";
if(global.HTTP_PORT_NUMBER !== 80) if(global.HTTP_PORT_NUMBER !== 80)

View File

@ -214,4 +214,12 @@ module.exports = class CSmartContract extends require("./block-exchange")
{ {
} }
} }
AddTransactionOwn(Tr)
{
if(!global.TX_PROCESS.Worker)
return 0;
var StrHex = GetHexFromArr(sha3(Tr.body));
global.TX_PROCESS.Worker.send({cmd:"FindTX", TX:StrHex})
return this.AddTransaction(Tr, 1);
}
}; };

View File

@ -243,10 +243,10 @@ class CApp
} }
return this.KeyPair; return this.KeyPair;
} }
GetSignFromArr(Arr, Num) GetPrivateKey(Num)
{ {
if(!this.KeyPair.WasInit) if(!this.KeyPair.WasInit)
return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; 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 KeyPair; var KeyPair;
if(Num) if(Num)
{ {
@ -256,39 +256,24 @@ class CApp
{ {
KeyPair = this.KeyPair KeyPair = this.KeyPair
} }
return KeyPair.getPrivateKey();
}
GetSignFromArr(Arr, Num)
{
if(!this.KeyPair.WasInit)
return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
var PrivKey = this.GetPrivateKey(Num);
var hash = shabuf(Arr); var hash = shabuf(Arr);
var sigObj = secp256k1.sign(hash, KeyPair.getPrivateKey()); var sigObj = secp256k1.sign(hash, Buffer.from(PrivKey));
return GetHexFromArr(sigObj.signature); return GetHexFromArr(sigObj.signature);
} }
GetSignTransaction(TR) GetSignTransaction(TR)
{ {
var Arr; if(!this.KeyPair.WasInit)
if(TR.Version === 2 || TR.Version === 3) return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
{ var PrivKey = this.GetPrivateKey(this.AccountMap[TR.FromID]);
var format; var Arr = DApps.Accounts.GetSignTransferTx(TR, PrivKey);
if(TR.Version === 2) return GetHexFromArr(Arr);
format = FORMAT_MONEY_TRANSFER_BODY2
else
format = FORMAT_MONEY_TRANSFER_BODY3
Arr = []
for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i];
var DataTo = DApps.Accounts.ReadState(Item.ID);
if(!DataTo)
return "";
for(var j = 0; j < 33; j++)
Arr[Arr.length] = DataTo.PubKey[j]
}
var Body = BufLib.GetBufferFromObject(TR, format, MAX_TRANSACTION_SIZE, {});
for(var j = 0; j < Body.length; j++)
Arr[Arr.length] = Body[j]
}
else
{
Arr = BufLib.GetBufferFromObject(TR, FORMAT_MONEY_TRANSFER_BODY, MAX_TRANSACTION_SIZE, {})
}
return this.GetSignFromArr(Arr, this.AccountMap[TR.FromID]);
} }
GetHistoryMaxNum() GetHistoryMaxNum()
{ {

View File

@ -13,7 +13,7 @@ const fs = require('fs');
const DBRow = require("../core/db/db-row"); const DBRow = require("../core/db/db-row");
const MAX_SUM_TER = 1e9; const MAX_SUM_TER = 1e9;
const MAX_SUM_CENT = 1e9; const MAX_SUM_CENT = 1e9;
const TYPE_TRANSACTION_CREATE = 100; global.TYPE_TRANSACTION_CREATE = 100;
const TYPE_TRANSACTION_TRANSFER = 105; const TYPE_TRANSACTION_TRANSFER = 105;
const TYPE_TRANSACTION_TRANSFER2 = 110; const TYPE_TRANSACTION_TRANSFER2 = 110;
const TYPE_TRANSACTION_TRANSFER3 = 111; const TYPE_TRANSACTION_TRANSFER3 = 111;
@ -419,7 +419,7 @@ class AccountApp extends require("./dapp")
} }
return 1; return 1;
} }
GetScriptTransaction(Body) GetObjectTransaction(Body)
{ {
var Type = Body[0]; var Type = Body[0];
var format; var format;
@ -453,14 +453,21 @@ class AccountApp extends require("./dapp")
default: default:
return ""; return "";
} }
var TR;
try try
{ {
var TR = BufLib.GetObjectFromBuffer(Body, format, {}); TR = BufLib.GetObjectFromBuffer(Body, format, {})
} }
catch(e) catch(e)
{ {
return "";
} }
return TR;
}
GetScriptTransaction(Body)
{
var TR = this.GetObjectTransaction(Body);
if(!TR)
return "";
if(TR.Body && TR.Body.length) if(TR.Body && TR.Body.length)
{ {
var App = DAppByType[TR.Body[0]]; var App = DAppByType[TR.Body[0]];
@ -528,7 +535,7 @@ class AccountApp extends require("./dapp")
{ {
power = GetPowPower(shaarr(Body)) power = GetPowPower(shaarr(Body))
} }
if(CheckMinPower) if(CheckMinPower && BlockNum < 19600000)
{ {
var MinPower; var MinPower;
if(BlockNum < 2500000) if(BlockNum < 2500000)
@ -537,7 +544,7 @@ class AccountApp extends require("./dapp")
if(BlockNum < 2800000) if(BlockNum < 2800000)
MinPower = MIN_POWER_POW_ACC_CREATE + 2 MinPower = MIN_POWER_POW_ACC_CREATE + 2
else else
MinPower = MIN_POWER_POW_ACC_CREATE + 3 MinPower = MIN_POWER_POW_ACC_CREATE_LAST
if(power < MinPower) if(power < MinPower)
return "Error min power POW for create account (update client)"; return "Error min power POW for create account (update client)";
} }
@ -1285,6 +1292,39 @@ class AccountApp extends require("./dapp")
RunSmartMethod(Block, ToData.Value.Smart, ToData, BlockNum, TrNum, Context, "OnGet") RunSmartMethod(Block, ToData.Value.Smart, ToData, BlockNum, TrNum, Context, "OnGet")
} }
} }
GetSignTransferTx(TR, PrivKey)
{
var Arr;
if(TR.Version === 2 || TR.Version === 3)
{
var format;
if(TR.Version === 2)
format = FORMAT_MONEY_TRANSFER_BODY2
else
format = FORMAT_MONEY_TRANSFER_BODY3
Arr = []
for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i];
var DataTo = DApps.Accounts.ReadState(Item.ID);
if(!DataTo)
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, 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 j = 0; j < 33; j++)
Arr[Arr.length] = DataTo.PubKey[j]
}
var Body = BufLib.GetBufferFromObject(TR, format, MAX_TRANSACTION_SIZE, {});
for(var j = 0; j < Body.length; j++)
Arr[Arr.length] = Body[j]
}
else
{
Arr = BufLib.GetBufferFromObject(TR, FORMAT_MONEY_TRANSFER_BODY, MAX_TRANSACTION_SIZE, {})
}
var hash = shabuf(Arr);
var sigObj = secp256k1.sign(hash, Buffer.from(PrivKey));
return sigObj.signature;
}
}; };
module.exports = AccountApp; module.exports = AccountApp;
var App = new AccountApp; var App = new AccountApp;

View File

@ -457,7 +457,7 @@ class SmartApp extends require("./dapp")
if(global.LOCAL_RUN || global.TEST_NETWORK) if(global.LOCAL_RUN || global.TEST_NETWORK)
this.RowHole = {} this.RowHole = {}
else else
this.RowHole = {"19":1, "22":1, "23":1, "24":1, "26":1, "27":1, "30":1} this.RowHole = {"19":1, "22":1, "23":1, "24":1, "26":1, "27":1, "29":1, "30":1, "34":1}
} }
IsHole(num) IsHole(num)
{ {

View File

@ -0,0 +1,245 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
const crypto = require('crypto');
WebApi2.CreateAccount = function (Params,response)
{
if(typeof Params === "object" && Params.Name && Params.PubKey)
{
var TR = {Type:TYPE_TRANSACTION_CREATE, Currency:Params.Currency, PubKey:GetArrFromHex(Params.PubKey), Name:Params.Name, Smart:Params.Smart,
};
var Body = BufLib.GetBufferFromObject(TR, FORMAT_CREATE, 1000, {}, 1);
Body = Body.slice(0, Body.len + 12);
SendTransaction(Body, TR, MIN_POWER_POW_ACC_CREATE_LAST, function (result,TR,Body)
{
var Result = {result:result < 1 ? 0 : 1, text:TR._text, TxID:GetHexFromArr(TR._TxID.slice(0, TR_TICKET_HASH_LENGTH + 6)), BlockNum:TR._BlockNum,
Meta:Params.Meta, };
var Str = JSON.stringify(Result);
response.end(Str);
});
return null;
}
return {result:0, Meta:Params.Meta};
};
WebApi2.GetBalance = function (Params,response)
{
if(typeof Params === "object")
{
var arr = DApps.Accounts.GetRowsAccounts(ParseNum(Params.AccountID), 1);
if(arr.length)
{
var Value = arr[0].Value;
var Result = {result:1, SumCOIN:Value.SumCOIN, SumCENT:Value.SumCENT, Meta:Params.Meta, };
return Result;
}
}
return {result:0, Meta:Params.Meta};
};
var MapSendID = {};
WebApi2.Send = function (Params,response)
{
if(typeof Params !== "object")
return {result:0};
var Coin;
if(typeof Params.Amount === "number")
Coin = COIN_FROM_FLOAT(Params.Amount);
else
Coin = Params.Amount;
var FromNum = ParseNum(Params.FromID);
if(!Coin)
return {result:0, Meta:Params.Meta, text:"Params.Amount required"};
if(!FromNum)
return {result:0, Meta:Params.Meta, text:"Params.FromID required"};
if(!Params.FromPrivKey)
return {result:0, Meta:Params.Meta, text:"Params.FromPrivKey required"};
if(!Params.ToID)
return {result:0, Meta:Params.Meta, text:"Params.ToID required"};
var ToPubKeyArr = [];
var ToID = 0;
if(typeof Params.ToID === "string" && Params.ToID.length === 66)
ToPubKeyArr = GetArrFromHex(Params.ToID);
else
ToID = ParseNum(Params.ToID);
var DataFrom = DApps.Accounts.ReadState(FromNum);
if(!DataFrom)
return {result:0, Meta:Params.Meta, text:"Error read account: " + FromNum};
var OperationID;
if(!MapSendID[FromNum])
{
OperationID = DataFrom.Value.OperationID + 10;
MapSendID[FromNum] = {};
}
else
{
OperationID = MapSendID[FromNum].OperationID;
if((new Date() - MapSendID[FromNum].Date) > 8 * 1000)
{
OperationID += 20;
}
}
OperationID++;
MapSendID[FromNum].OperationID = OperationID;
MapSendID[FromNum].Date = Date.now();
var TR = {Type:111, Version:3, Reserve:0, FromID:FromNum, OperationID:OperationID, To:[{PubKey:ToPubKeyArr, ID:ToID, SumCOIN:Coin.SumCOIN,
SumCENT:Coin.SumCENT}], Description:Params.Description, Body:[], };
TR.Sign = DApps.Accounts.GetSignTransferTx(TR, GetArrFromHex(Params.FromPrivKey));
var Body = BufLib.GetBufferFromObject(TR, FORMAT_MONEY_TRANSFER3, MAX_TRANSACTION_SIZE, {}, 1);
Body = Body.slice(0, Body.len + 12);
SendTransaction(Body, TR, undefined, function (result,TR,Body)
{
var Result = {result:result < 1 ? 0 : 1, text:TR._text, TxID:GetHexFromArr(TR._TxID.slice(0, TR_TICKET_HASH_LENGTH + 6)), BlockNum:TR._BlockNum,
Meta:Params.Meta, };
var Str = JSON.stringify(Result);
response.end(Str);
});
return null;
};
WebApi2.GetTransaction = function (Params)
{
if(typeof Params === "object" && Params.TxID)
{
var Arr = GetArrFromHex(Params.TxID);
var BlockNum = ReadUintFromArr(Arr, TR_TICKET_HASH_LENGTH);
var Block = SERVER.ReadBlockDB(BlockNum);
if(Block)
{
Arr = Arr.slice(0, TR_TICKET_HASH_LENGTH);
for(var i = 0; i < Block.arrContent.length; i++)
{
var Body = Block.arrContent[i];
var Nonce = ReadUintFromArr(Body, Body.length - 6);
var Arr2 = CreateTxID(Body, BlockNum, Nonce);
Arr2 = Arr2.slice(0, TR_TICKET_HASH_LENGTH);
if(CompareArr(Arr2, Arr) === 0)
{
var TR = DApps.Accounts.GetObjectTransaction(Body);
if(TR)
{
ConvertBufferToStr(TR);
TR.result = 1;
TR.Meta = Params.Meta;
return TR;
}
}
}
}
}
return {result:0, Meta:Params.Meta};
};
WebApi2.GetHistoryTransactions = function (Params)
{
};
WebApi2.GenerateKeys = function (Params)
{
var KeyPair = crypto.createECDH('secp256k1');
var PrivKey = sha3(crypto.randomBytes(32));
KeyPair.setPrivateKey(Buffer.from(PrivKey));
var PubKey = KeyPair.getPublicKey('', 'compressed');
return {result:1, PrivKey:GetHexFromArr(PrivKey), PubKey:GetHexFromArr(PubKey), Meta:Params.Meta};
};
var DELTA_FOR_TIME_TX = 1;
function CreateTxID(body,BlockNum,Nonce)
{
body.writeUIntLE(BlockNum, body.length - 12, 6);
body.writeUIntLE(Nonce, body.length - 6, 6);
var HASH = sha3(body);
var FullHashTicket = [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 < TR_TICKET_HASH_LENGTH; i++)
FullHashTicket[i] = HASH[i];
WriteUintToArrOnPos(FullHashTicket, BlockNum, TR_TICKET_HASH_LENGTH);
return FullHashTicket;
};
function GetBlockNumTr(arr)
{
var BlockNum = DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
if(arr[0] === TYPE_TRANSACTION_CREATE)
{
var BlockNum2 = Math.floor(BlockNum / 10) * 10;
if(BlockNum2 < BlockNum)
BlockNum2 = BlockNum2 + 10;
BlockNum = BlockNum2;
}
return BlockNum;
};
function CreateHashBodyPOWInnerMinPower(TR,arr,MinPow,startnonce)
{
var BlockNum = GetBlockNumTr(arr);
if(MinPow === undefined)
{
MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128);
}
var nonce = startnonce;
while(1)
{
var TxID = CreateTxID(arr, BlockNum, nonce);
var power = GetPowPower(sha3(TxID));
if(power >= MinPow)
{
TR._TxID = TxID;
TR._BlockNum = BlockNum;
ToLog("Find: " + power + " for block:" + BlockNum);
return nonce;
}
nonce++;
if(nonce % 2000 === 0)
{
BlockNum = GetBlockNumTr(arr);
}
}
};
function SendTransaction(Body,TR,SumPow,F)
{
if(Body.length > 16000)
{
TR._result = 0;
TR._text = "Error length transaction =" + Body.length + " (max size=16000)";
F(1, TR, Body);
return ;
}
CreateNonceAndSend(0, 0);
function CreateNonceAndSend(startnonce,NumNext)
{
if(!NumNext)
NumNext = 0;
if(NumNext > 10)
{
F(0, TR, Body);
return ;
}
var nonce = CreateHashBodyPOWInnerMinPower(TR, Body, SumPow, startnonce);
process.RunRPC("AddTransactionFromWeb", GetHexFromArr(Body), function (Err,text)
{
TR._result = Err ? 0 : 1;
TR._text = text;
if(text === "Not add" || text === "Bad PoW")
{
CreateNonceAndSend(nonce + 1, NumNext + 1);
return ;
}
else
if(text === "Bad time")
{
if(DELTA_FOR_TIME_TX < 6)
{
DELTA_FOR_TIME_TX++;
ToLog("New set Delta time: " + DELTA_FOR_TIME_TX);
CreateNonceAndSend(0, NumNext + 1);
return ;
}
}
F(TR._result, TR, Body);
});
};
};

View File

@ -72,7 +72,7 @@ process.on('error', function (err)
}); });
var ArrChildProcess = []; var ArrChildProcess = [];
var WebProcess = {Name:"WEB PROCESS", idInterval:0, idInterval1:0, idInterval2:0, LastAlive:Date.now(), Worker:undefined, Path:"./process/web-process.js", var WebProcess = {Name:"WEB PROCESS", idInterval:0, idInterval1:0, idInterval2:0, LastAlive:Date.now(), Worker:undefined, Path:"./process/web-process.js",
OnMessage:OnMessageWeb, PeriodAlive:3000}; OnMessage:OnMessageWeb, PeriodAlive:20 * 1000};
if(global.HTTP_HOSTING_PORT && !global.NWMODE) if(global.HTTP_HOSTING_PORT && !global.NWMODE)
{ {
ArrChildProcess.push(WebProcess); ArrChildProcess.push(WebProcess);

View File

@ -271,6 +271,7 @@ WalletFileMap["style.css"] = 1;
WalletFileMap["wallet.css"] = 1; WalletFileMap["wallet.css"] = 1;
WalletFileMap["blockviewer.html"] = 1; WalletFileMap["blockviewer.html"] = 1;
WalletFileMap["web-wallet.html"] = 1; WalletFileMap["web-wallet.html"] = 1;
global.WebApi2 = {};
global.HostingCaller = {}; global.HostingCaller = {};
function DoCommandNew(response,Type,Path,Params) function DoCommandNew(response,Type,Path,Params)
@ -278,12 +279,35 @@ function DoCommandNew(response,Type,Path,Params)
if(Path.substring(0, 1) === "/") if(Path.substring(0, 1) === "/")
Path = Path.substring(1); Path = Path.substring(1);
var ArrPath = Path.split('/', 3); var ArrPath = Path.split('/', 3);
var Caller = HostingCaller;
var Method = ArrPath[0]; var Method = ArrPath[0];
var F = HostingCaller[Method]; if(ArrPath[0] === "api")
{
if(ArrPath[1] === "v2")
{
if(!global.USE_HARD_API_V2)
{
response.writeHead(200, {'Content-Type':'text/plain', 'Access-Control-Allow-Origin':"*"});
response.end(JSON.stringify({result:0, text:"You must set const USE_HARD_API_V2:1"}));
return ;
}
Caller = WebApi2;
}
Method = ArrPath[2];
}
var F = Caller[Method];
if(F) if(F)
{ {
response.writeHead(200, {'Content-Type':'text/plain', 'Access-Control-Allow-Origin':"*"}); response.writeHead(200, {'Content-Type':'text/plain', 'Access-Control-Allow-Origin':"*"});
var Ret = F(Params, response); var Ret;
try
{
Ret = F(Params, response);
}
catch(e)
{
Ret = {result:0, text:e.message, text2:e.stack};
}
if(Ret === null) if(Ret === null)
return ; return ;
try try
@ -382,7 +406,7 @@ HostingCaller.GetCurrentInfo = function (Params)
{ {
var Ret = {result:1, VersionNum:global.UPDATE_CODE_VERSION_NUM, MaxNumBlockDB:SERVER.GetMaxNumBlockDB(), CurBlockNum:GetCurrentBlockNumByTime(), var Ret = {result:1, VersionNum:global.UPDATE_CODE_VERSION_NUM, MaxNumBlockDB:SERVER.GetMaxNumBlockDB(), CurBlockNum:GetCurrentBlockNumByTime(),
MaxAccID:DApps.Accounts.GetMaxAccount(), MaxDappsID:DApps.Smart.GetMaxNum(), NETWORK:global.NETWORK, CurTime:Date.now(), DELTA_CURRENT_TIME:DELTA_CURRENT_TIME, MaxAccID:DApps.Accounts.GetMaxAccount(), MaxDappsID:DApps.Smart.GetMaxNum(), NETWORK:global.NETWORK, CurTime:Date.now(), DELTA_CURRENT_TIME:DELTA_CURRENT_TIME,
MIN_POWER_POW_TR:MIN_POWER_POW_TR, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK, CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME, MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE, MIN_POWER_POW_TR:MIN_POWER_POW_TR, FIRST_TIME_BLOCK:FIRST_TIME_BLOCK, CONSENSUS_PERIOD_TIME:CONSENSUS_PERIOD_TIME, MIN_POWER_POW_ACC_CREATE:MIN_POWER_POW_ACC_CREATE_LAST,
}; };
if(typeof Params === "object" && Params.Diagram == 1) if(typeof Params === "object" && Params.Diagram == 1)
{ {
@ -745,3 +769,4 @@ setInterval(function ()
NodeBlockChain = BufWrite; NodeBlockChain = BufWrite;
} }
}, 1000); }, 1000);
require("./api-exchange.js");