0.895
This commit is contained in:
parent
5affe69fe0
commit
38de781bd4
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
# API v2 (for exchanges)
|
# API v2 (for exchanges)
|
||||||
|
Works with update version 0.895
|
||||||
|
|
||||||
The API is designed to make it easier to write third-party applications. Server-side cryptography and POW operations are performed. Therefore, it is not recommended for public access, because it is not protected from DDOS attacks. Use it if applications such as the exchange server are on the same private network.
|
The API is designed to make it easier to write third-party applications. Server-side cryptography and POW operations are performed. Therefore, it is not recommended for public access, because it is not protected from DDOS attacks. Use it if applications such as the exchange server are on the same private network.
|
||||||
|
|
||||||
@ -223,7 +223,74 @@ return:
|
|||||||
|
|
||||||
6)**/api/v2/GetHistoryTransactions** - to get the transaction history of the account
|
6)**/api/v2/GetHistoryTransactions** - to get the transaction history of the account
|
||||||
|
|
||||||
#### **TODO**
|
#### Parameters:
|
||||||
|
* AccountID - account (account) number)
|
||||||
|
* Count - maximum number of rows returned - history depth (default 100)
|
||||||
|
|
||||||
|
option to set parameters for organizing page navigation:
|
||||||
|
* NextPos - history line ID number (this value is taken from the last line of the previous result)
|
||||||
|
* Count - number of rows returned
|
||||||
|
|
||||||
|
Advanced setting:
|
||||||
|
* GetTxID - if set to 1, the transaction ID in hex-format is returned in the TxID field
|
||||||
|
|
||||||
|
|
||||||
|
example1:
|
||||||
|
```js
|
||||||
|
http://127.0.0.1/api/v2/GetHistoryTransactions
|
||||||
|
{
|
||||||
|
"AccountID": 190480
|
||||||
|
}
|
||||||
|
```
|
||||||
|
return:
|
||||||
|
```js
|
||||||
|
|
||||||
|
{
|
||||||
|
"result": 1,
|
||||||
|
"History": [
|
||||||
|
{
|
||||||
|
"Type": 1,
|
||||||
|
"BlockNum": 19994502,
|
||||||
|
"TrNum": 0,
|
||||||
|
"Pos": 498190,
|
||||||
|
"NextPos": 439090,
|
||||||
|
"Direct": "+",
|
||||||
|
"CorrID": 190478,
|
||||||
|
"SumCOIN": 1,
|
||||||
|
"SumCENT": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Type": 1,
|
||||||
|
"BlockNum": 19993514,
|
||||||
|
"TrNum": 0,
|
||||||
|
"Pos": 439090,
|
||||||
|
"NextPos": 0,
|
||||||
|
"Direct": "+",
|
||||||
|
"CorrID": 190478,
|
||||||
|
"SumCOIN": 1,
|
||||||
|
"SumCENT": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Tail": {
|
||||||
|
"NextPos": 498190,
|
||||||
|
"Reserv": {
|
||||||
|
"type": "Buffer",
|
||||||
|
"data": [
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Num": 190480
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
example2:
|
||||||
|
```js
|
||||||
|
http://127.0.0.1/api/v2/GetHistoryTransactions
|
||||||
|
{
|
||||||
|
"NextPos": 439090
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
# API v2 (для бирж и обменников)
|
# API v2 (для бирж и обменников)
|
||||||
|
Работает с версии обновления 0.895
|
||||||
|
|
||||||
|
|
||||||
API предназначено для облегчения написания сторонних приложений. На стороне сервера выполняется криптография и операции POW. Поэтому оно не рекомендуется для публичного доступа, т.к. нет защиты от DDOS атак. Используйте его, если приложения такие как сервер биржи находятся в одной приватной сети.
|
API предназначено для облегчения написания сторонних приложений. На стороне сервера выполняется криптография и операции POW. Поэтому оно не рекомендуется для публичного доступа, т.к. нет защиты от DDOS атак. Используйте его, если приложения такие как сервер биржи находятся в одной приватной сети.
|
||||||
|
|
||||||
@ -167,6 +169,10 @@ return:
|
|||||||
#### Параметры:
|
#### Параметры:
|
||||||
* TxID - ИД транзакции в hex-формате
|
* TxID - ИД транзакции в hex-формате
|
||||||
|
|
||||||
|
альтернативный вариант задания параметров:
|
||||||
|
* BlockNum - номер блока
|
||||||
|
* TrNum - номер транзакции в блоке
|
||||||
|
|
||||||
example1:
|
example1:
|
||||||
```js
|
```js
|
||||||
http://127.0.0.1/api/v2/GetTransaction
|
http://127.0.0.1/api/v2/GetTransaction
|
||||||
@ -193,7 +199,9 @@ return:
|
|||||||
"OperationID": 41,
|
"OperationID": 41,
|
||||||
"Body": "",
|
"Body": "",
|
||||||
"Sign": "8C761F539A6A24427CF810A49140CA1FFBF0F3A48DCF58AEE0DD9E4A4E631E1A1B6DA86ED6E2EF92DBF537270AA02B5EAE3A7C822B3F70628CAD78525ED9E0F7",
|
"Sign": "8C761F539A6A24427CF810A49140CA1FFBF0F3A48DCF58AEE0DD9E4A4E631E1A1B6DA86ED6E2EF92DBF537270AA02B5EAE3A7C822B3F70628CAD78525ED9E0F7",
|
||||||
"result": 1
|
"result": 1,
|
||||||
|
"BlockNum": 19781201,
|
||||||
|
"TrNum": 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -214,15 +222,83 @@ return:
|
|||||||
"Adviser": 0,
|
"Adviser": 0,
|
||||||
"Smart": 0,
|
"Smart": 0,
|
||||||
"Reserve": "000000",
|
"Reserve": "000000",
|
||||||
"result": 190552
|
"result": 190552,
|
||||||
|
"BlockNum": 19889100,
|
||||||
|
"TrNum": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## GetHistoryTransactions
|
## GetHistoryTransactions
|
||||||
|
|
||||||
6)**/api/v2/GetHistoryTransactions** - получить историю транзакций счета
|
6)**/api/v2/GetHistoryTransactions** - получить историю транзакций счета
|
||||||
|
|
||||||
#### **TODO**
|
#### Параметры:
|
||||||
|
* AccountID - номер счета (аккаунта)
|
||||||
|
* Count - максимальное число возвращаемых строк - глубина истории (по умолчанию 100)
|
||||||
|
|
||||||
|
вариант задания параметров для организации постраничной навигации:
|
||||||
|
* NextPos - номер ид строки истории (это значение берется из последней строки предыдущего результата)
|
||||||
|
* Count - число возвращаемых строк
|
||||||
|
|
||||||
|
Дополнительные параметры:
|
||||||
|
* GetTxID - если стоит 1 - то возвращается в поле TxID возвращается ID транзакции в 16 формате
|
||||||
|
|
||||||
|
|
||||||
|
example1:
|
||||||
|
```js
|
||||||
|
http://127.0.0.1/api/v2/GetHistoryTransactions
|
||||||
|
{
|
||||||
|
"AccountID": 190480
|
||||||
|
}
|
||||||
|
```
|
||||||
|
return:
|
||||||
|
```js
|
||||||
|
|
||||||
|
{
|
||||||
|
"result": 1,
|
||||||
|
"History": [
|
||||||
|
{
|
||||||
|
"Type": 1,
|
||||||
|
"BlockNum": 19994502,
|
||||||
|
"TrNum": 0,
|
||||||
|
"Pos": 498190,
|
||||||
|
"NextPos": 439090,
|
||||||
|
"Direct": "+",
|
||||||
|
"CorrID": 190478,
|
||||||
|
"SumCOIN": 1,
|
||||||
|
"SumCENT": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Type": 1,
|
||||||
|
"BlockNum": 19993514,
|
||||||
|
"TrNum": 0,
|
||||||
|
"Pos": 439090,
|
||||||
|
"NextPos": 0,
|
||||||
|
"Direct": "+",
|
||||||
|
"CorrID": 190478,
|
||||||
|
"SumCOIN": 1,
|
||||||
|
"SumCENT": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Tail": {
|
||||||
|
"NextPos": 498190,
|
||||||
|
"Reserv": {
|
||||||
|
"type": "Buffer",
|
||||||
|
"data": [
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Num": 190480
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
example2:
|
||||||
|
```js
|
||||||
|
http://127.0.0.1/api/v2/GetHistoryTransactions
|
||||||
|
{
|
||||||
|
"NextPos": 439090
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -269,6 +269,7 @@ Version = 3 - поддержка переводов на счета со сма
|
|||||||
* [Техническое WP - черновик](https://docs.google.com/document/d/1B6_qlAp2xs4aHkqOwyvRMCDJTjgeNiOJiGpIeT0VAzY/edit?usp=sharing)
|
* [Техническое WP - черновик](https://docs.google.com/document/d/1B6_qlAp2xs4aHkqOwyvRMCDJTjgeNiOJiGpIeT0VAzY/edit?usp=sharing)
|
||||||
* [Торрент блокчейна (каталог DATA/DB)](https://sourceforge.net/p/tera/code/ci/master/tree/Torrent/Tera-folder-DB.torrent?format=raw)
|
* [Торрент блокчейна (каталог DATA/DB)](https://sourceforge.net/p/tera/code/ci/master/tree/Torrent/Tera-folder-DB.torrent?format=raw)
|
||||||
* [API](https://sourceforge.net/p/tera/code/ci/master/tree/Doc/Rus/API.md)
|
* [API](https://sourceforge.net/p/tera/code/ci/master/tree/Doc/Rus/API.md)
|
||||||
|
* [API2](https://sourceforge.net/p/tera/code/ci/master/tree/Doc/Rus/API2.md)
|
||||||
* [CONSTANTS](https://sourceforge.net/p/tera/code/ci/master/tree/Doc/Rus/CONSTANTS.MD)
|
* [CONSTANTS](https://sourceforge.net/p/tera/code/ci/master/tree/Doc/Rus/CONSTANTS.MD)
|
||||||
* [Презентация - Проблематика блокчейна и пути решения](https://docs.google.com/presentation/d/1NvaGQTUpeP3y7CmHpaqFmaqWlCEMMoPdvCyylFVJ3lk/edit?usp=sharing)
|
* [Презентация - Проблематика блокчейна и пути решения](https://docs.google.com/presentation/d/1NvaGQTUpeP3y7CmHpaqFmaqWlCEMMoPdvCyylFVJ3lk/edit?usp=sharing)
|
||||||
|
|
||||||
|
@ -1513,7 +1513,7 @@
|
|||||||
{
|
{
|
||||||
var Item=MapAccounts[$("idAccount").value];
|
var Item=MapAccounts[$("idAccount").value];
|
||||||
if(Item)
|
if(Item)
|
||||||
$("idSumSend").value=FLOAT_FROM_COIN(Item.Value);
|
$("idSumSend").value=FLOAT_FROM_COIN(Item.Value).toStringF();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -1694,6 +1694,7 @@
|
|||||||
|
|
||||||
<th id="Item.PrevValue.OperationID" class="num">Prev. Operation</th>
|
<th id="Item.PrevValue.OperationID" class="num">Prev. Operation</th>
|
||||||
<th id="SUM_TO_STRING(Item.PrevValue)" class="sum">Prev. amount</th>
|
<th id="SUM_TO_STRING(Item.PrevValue)" 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="<< Prev">
|
<INPUT type="button" onclick="ViewPrev(DefActs)" class="btdoit bt" value="<< Prev">
|
||||||
|
@ -955,7 +955,7 @@
|
|||||||
{
|
{
|
||||||
var Item=MapAccounts[$("idAccount").value];
|
var Item=MapAccounts[$("idAccount").value];
|
||||||
if(Item)
|
if(Item)
|
||||||
$("idSumSend").value=FLOAT_FROM_COIN(Item.Value);
|
$("idSumSend").value=FLOAT_FROM_COIN(Item.Value).toStringF();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
|
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
global.UPDATE_CODE_VERSION_NUM = 893;
|
global.UPDATE_CODE_VERSION_NUM = 895;
|
||||||
global.MIN_CODE_VERSION_NUM = 884;
|
global.MIN_CODE_VERSION_NUM = 884;
|
||||||
global.MINING_VERSION_NUM = 3;
|
global.MINING_VERSION_NUM = 3;
|
||||||
global.InitParamsArg = InitParamsArg;
|
global.InitParamsArg = InitParamsArg;
|
||||||
|
@ -52,7 +52,7 @@ module.exports = class CDBState extends require("./db")
|
|||||||
var written = fs.writeSync(FI.fd, BufWrite, 0, BufWrite.length, Position);
|
var written = fs.writeSync(FI.fd, BufWrite, 0, BufWrite.length, Position);
|
||||||
if(written !== BufWrite.length)
|
if(written !== BufWrite.length)
|
||||||
{
|
{
|
||||||
TO_ERROR_LOG("DB-STATE", 10, "Error write to file:" + written + " <> " + BufWrite.length)
|
TO_ERROR_LOG("DB-ROW", 10, "Error write to file:" + written + " <> " + BufWrite.length)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(RetBuf)
|
if(RetBuf)
|
||||||
|
@ -952,7 +952,7 @@ HTTPCaller.TruncateBlockChain = function (Param)
|
|||||||
var MinBlock = DApps.Accounts.GetMinBlockAct();
|
var MinBlock = DApps.Accounts.GetMinBlockAct();
|
||||||
if(MinBlock > StartNum)
|
if(MinBlock > StartNum)
|
||||||
{
|
{
|
||||||
ToLog("Cant Truncate BlockChain. Very long length. Max length=" + (SERVER.BlockNumDB - MinBlock));
|
ToLog("Cant Truncate BlockChain. Very long length. Max length=" + (SERVER.BlockNumDB - MinBlock), 0);
|
||||||
return {result:0, sessionid:sessionid};
|
return {result:0, sessionid:sessionid};
|
||||||
}
|
}
|
||||||
SERVER.TruncateBlockDB(StartNum);
|
SERVER.TruncateBlockDB(StartNum);
|
||||||
@ -1359,8 +1359,8 @@ if(global.HTTP_PORT_NUMBER)
|
|||||||
if(!ClientIPMap[remoteAddress])
|
if(!ClientIPMap[remoteAddress])
|
||||||
{
|
{
|
||||||
ClientIPMap[remoteAddress] = 1;
|
ClientIPMap[remoteAddress] = 1;
|
||||||
ToLog("CONNECT TO HTTP ACCESS FROM: " + remoteAddress);
|
ToLog("CONNECT TO HTTP ACCESS FROM: " + remoteAddress, 0);
|
||||||
ToLog("Path: " + Path);
|
ToLog("Path: " + Path, 0);
|
||||||
}
|
}
|
||||||
if(CheckPassword && global.HTTP_PORT_PASSWORD)
|
if(CheckPassword && global.HTTP_PORT_PASSWORD)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,10 @@ 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 DBLib = require("../core/db/db");
|
||||||
|
global.HistoryDB = new DBLib();
|
||||||
|
const FILE_NAME_HISTORY = "history-body";
|
||||||
|
var WorkStructHistory = {};
|
||||||
global.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;
|
||||||
@ -141,9 +145,13 @@ class AccountApp extends require("./dapp")
|
|||||||
}"
|
}"
|
||||||
this.ACCOUNT_ROW_SIZE = 6 + 33 + 40 + (6 + 4 + 6 + 84) + 6 + 6 + 9
|
this.ACCOUNT_ROW_SIZE = 6 + 33 + 40 + (6 + 4 + 6 + 84) + 6 + 6 + 9
|
||||||
this.DBState = new MerkleDBRow("accounts-state", this.ACCOUNT_ROW_SIZE, this.FORMAT_ACCOUNT_ROW, bReadOnly)
|
this.DBState = new MerkleDBRow("accounts-state", this.ACCOUNT_ROW_SIZE, this.FORMAT_ACCOUNT_ROW, bReadOnly)
|
||||||
this.DBAct = new DBRow("accounts-act", 6 + 6 + (6 + 4 + 6 + 6 + 84) + 1 + 11, "{ID:uint, BlockNum:uint,PrevValue:{SumCOIN:uint,SumCENT:uint32, Reserve0:uint, OperationID:uint,Smart:uint32,Data:arr80}, Mode:byte, TrNum:uint16, Reserve: arr9}",
|
this.DBAct = new DBRow("accounts-act", 6 + 6 + (6 + 4 + 6 + 6 + 84) + 1 + 11, "{ID:uint, BlockNum:uint,PrevValue:{SumCOIN:uint,SumCENT:uint32, NextPos:uint, OperationID:uint,Smart:uint32,Data:arr80}, Mode:byte, TrNum:uint16, Reserve: arr9}",
|
||||||
bReadOnly)
|
bReadOnly)
|
||||||
this.DBActPrev = new DBRow("accounts-act-prev", this.DBAct.DataSize, this.DBAct.Format, bReadOnly)
|
this.DBActPrev = new DBRow("accounts-act-prev", this.DBAct.DataSize, this.DBAct.Format, bReadOnly)
|
||||||
|
this.FORMAT_STATE_HISTORY = "{NextPos:uint,Reserv:arr2}"
|
||||||
|
this.DBStateHistory = new DBRow("history-state", 8, this.FORMAT_STATE_HISTORY, bReadOnly)
|
||||||
|
HistoryDB.OpenDBFile(FILE_NAME_HISTORY, !bReadOnly)
|
||||||
|
this.HistoryFormatArr = ["{Type:byte, BlockNum:uint32,TrNum:uint16, NextPos:uint}", "{Type:byte, BlockNum:uint32,TrNum:uint16, NextPos:uint, Direct:str1,CorrID:uint, SumCOIN:uint,SumCENT:uint32}"]
|
||||||
if(global.READ_ONLY_DB)
|
if(global.READ_ONLY_DB)
|
||||||
return ;
|
return ;
|
||||||
this.DBAccountsHash = new DBRow("accounts-hash2", 6 + 32 + 32 + 10, "{BlockNum:uint, Hash:hash, SumHash:hash, Reserve: arr10}",
|
this.DBAccountsHash = new DBRow("accounts-hash2", 6 + 32 + 32 + 10, "{BlockNum:uint, Hash:hash, SumHash:hash, Reserve: arr10}",
|
||||||
@ -163,6 +171,7 @@ class AccountApp extends require("./dapp")
|
|||||||
return ;
|
return ;
|
||||||
this.DBState.MerkleTree = undefined
|
this.DBState.MerkleTree = undefined
|
||||||
this.DBState.Truncate( - 1)
|
this.DBState.Truncate( - 1)
|
||||||
|
this.DBStateHistory.Truncate( - 1)
|
||||||
this.DBAct.Truncate( - 1)
|
this.DBAct.Truncate( - 1)
|
||||||
this.DBActPrev.Truncate( - 1)
|
this.DBActPrev.Truncate( - 1)
|
||||||
this.DBAccountsHash.Truncate( - 1)
|
this.DBAccountsHash.Truncate( - 1)
|
||||||
@ -187,6 +196,8 @@ class AccountApp extends require("./dapp")
|
|||||||
this.DBAccountsHash.Close()
|
this.DBAccountsHash.Close()
|
||||||
if(this.DBStateTX)
|
if(this.DBStateTX)
|
||||||
this.DBStateTX.Close()
|
this.DBStateTX.Close()
|
||||||
|
if(this.DBStateHistory)
|
||||||
|
this.DBStateHistory.Close()
|
||||||
}
|
}
|
||||||
ClearDataBase()
|
ClearDataBase()
|
||||||
{
|
{
|
||||||
@ -829,6 +840,12 @@ class AccountApp extends require("./dapp")
|
|||||||
var Data = this.DBState.Read(Item.ID);
|
var Data = this.DBState.Read(Item.ID);
|
||||||
Data.Value = Item.PrevValue
|
Data.Value = Item.PrevValue
|
||||||
this.DBState.Write(Data)
|
this.DBState.Write(Data)
|
||||||
|
var History = this.DBStateHistory.Read(Item.ID);
|
||||||
|
if(History)
|
||||||
|
{
|
||||||
|
History.NextPos = Item.PrevValue.NextPos
|
||||||
|
this.DBStateHistory.Write(History)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(bWas)
|
if(bWas)
|
||||||
@ -836,6 +853,7 @@ class AccountApp extends require("./dapp")
|
|||||||
if(NumTruncateState)
|
if(NumTruncateState)
|
||||||
{
|
{
|
||||||
this.DBState.Truncate(NumTruncateState - 1)
|
this.DBState.Truncate(NumTruncateState - 1)
|
||||||
|
this.DBStateHistory.Truncate(NumTruncateState - 1)
|
||||||
}
|
}
|
||||||
DBAct.Truncate(StartNum - 1)
|
DBAct.Truncate(StartNum - 1)
|
||||||
}
|
}
|
||||||
@ -1126,6 +1144,16 @@ class AccountApp extends require("./dapp")
|
|||||||
{
|
{
|
||||||
var BlockNum = Block.BlockNum;
|
var BlockNum = Block.BlockNum;
|
||||||
var DBChanges = this.DBChanges;
|
var DBChanges = this.DBChanges;
|
||||||
|
for(var i = 0; i < DBChanges.BlockHistory.length; i++)
|
||||||
|
{
|
||||||
|
var Data = DBChanges.BlockHistory[i];
|
||||||
|
var Account = DBChanges.BlockMap[Data.CurID];
|
||||||
|
Data.Type = 1
|
||||||
|
Data.NextPos = Account.Value.NextPos
|
||||||
|
Account.Value.NextPos = this.SaveHistory(Data)
|
||||||
|
if(WALLET.AccountMap[Data.CurID] !== undefined)
|
||||||
|
WALLET.OnDoHistoryAct(Data, BlockNum)
|
||||||
|
}
|
||||||
var arr = [];
|
var arr = [];
|
||||||
for(var key in DBChanges.BlockMap)
|
for(var key in DBChanges.BlockMap)
|
||||||
{
|
{
|
||||||
@ -1146,10 +1174,18 @@ class AccountApp extends require("./dapp")
|
|||||||
var BackLog = {Num:undefined, ID:Account.Num, BlockNum:BlockNum, PrevValue:Account.BackupValue, TrNum:Account.ChangeTrNum,
|
var BackLog = {Num:undefined, ID:Account.Num, BlockNum:BlockNum, PrevValue:Account.BackupValue, TrNum:Account.ChangeTrNum,
|
||||||
Mode:Account.New};
|
Mode:Account.New};
|
||||||
this.DBAct.Write(BackLog)
|
this.DBAct.Write(BackLog)
|
||||||
|
}
|
||||||
|
for(var i = 0; i < arr.length; i++)
|
||||||
|
{
|
||||||
|
var Account = arr[i];
|
||||||
this.DBState.Write(Account)
|
this.DBState.Write(Account)
|
||||||
}
|
}
|
||||||
for(var i = 0; i < DBChanges.BlockHistory.length; i++)
|
for(var i = 0; i < arr.length; i++)
|
||||||
WALLET.OnDoHistoryAct(DBChanges.BlockHistory[i], BlockNum)
|
{
|
||||||
|
var Account = arr[i];
|
||||||
|
var History = {Num:Account.Num, NextPos:Account.Value.NextPos};
|
||||||
|
this.DBStateHistory.Write(History)
|
||||||
|
}
|
||||||
for(var i = 0; i < DBChanges.BlockEvent.length; i++)
|
for(var i = 0; i < DBChanges.BlockEvent.length; i++)
|
||||||
{
|
{
|
||||||
var Data = DBChanges.BlockEvent[i];
|
var Data = DBChanges.BlockEvent[i];
|
||||||
@ -1240,13 +1276,17 @@ class AccountApp extends require("./dapp")
|
|||||||
return undefined;
|
return undefined;
|
||||||
BData.Num = Num
|
BData.Num = Num
|
||||||
Value = BData.Value
|
Value = BData.Value
|
||||||
BData.BackupValue = {SumCOIN:Value.SumCOIN, SumCENT:Value.SumCENT, OperationID:Value.OperationID, Smart:Value.Smart, Data:Value.Data}
|
var BHistory = this.DBStateHistory.Read(Num);
|
||||||
|
if(BHistory)
|
||||||
|
Value.NextPos = BHistory.NextPos
|
||||||
|
BData.BackupValue = {SumCOIN:Value.SumCOIN, SumCENT:Value.SumCENT, OperationID:Value.OperationID, Smart:Value.Smart, Data:Value.Data,
|
||||||
|
NextPos:Value.NextPos}
|
||||||
BlockMap[Num] = BData
|
BlockMap[Num] = BData
|
||||||
}
|
}
|
||||||
Value = BData.Value
|
Value = BData.Value
|
||||||
Data = {Num:Num, Currency:BData.Currency, PubKey:BData.PubKey, Name:BData.Name, BlockNumCreate:BData.BlockNumCreate, Adviser:BData.Adviser,
|
Data = {Num:Num, Currency:BData.Currency, PubKey:BData.PubKey, Name:BData.Name, BlockNumCreate:BData.BlockNumCreate, Adviser:BData.Adviser,
|
||||||
Value:{SumCOIN:Value.SumCOIN, SumCENT:Value.SumCENT, OperationID:Value.OperationID, Smart:Value.Smart, Data:CopyArr(Value.Data)},
|
Value:{SumCOIN:Value.SumCOIN, SumCENT:Value.SumCENT, OperationID:Value.OperationID, Smart:Value.Smart, Data:CopyArr(Value.Data),
|
||||||
BackupValue:BData.BackupValue}
|
NextPos:Value.NextPos}, BackupValue:BData.BackupValue}
|
||||||
TRMap[Num] = Data
|
TRMap[Num] = Data
|
||||||
}
|
}
|
||||||
return Data;
|
return Data;
|
||||||
@ -1274,10 +1314,11 @@ class AccountApp extends require("./dapp")
|
|||||||
throw "Not enough money on the account ID:" + FromID;
|
throw "Not enough money on the account ID:" + FromID;
|
||||||
}
|
}
|
||||||
this.WriteStateTR(FromData, TrNum)
|
this.WriteStateTR(FromData, TrNum)
|
||||||
if(WALLET.AccountMap[FromID] !== undefined)
|
if(FromID > 15)
|
||||||
{
|
{
|
||||||
this.DBChanges.TRHistory.push({Direct:"-", FromID:FromID, ToID:ToID, SumCOIN:CoinSum.SumCOIN, SumCENT:CoinSum.SumCENT, Description:DescriptionFrom,
|
this.DBChanges.TRHistory.push({Direct:"-", Receive:0, CurID:FromID, CorrID:ToID, BlockNum:BlockNum, TrNum:TrNum, FromID:FromID,
|
||||||
FromOperationID:FromData.Value.OperationID, Currency:FromData.Currency})
|
ToID:ToID, SumCOIN:CoinSum.SumCOIN, SumCENT:CoinSum.SumCENT, Description:DescriptionFrom, FromOperationID:FromData.Value.OperationID,
|
||||||
|
Currency:FromData.Currency})
|
||||||
}
|
}
|
||||||
var ToData = this.ReadStateTR(ToID);
|
var ToData = this.ReadStateTR(ToID);
|
||||||
if(!ToData)
|
if(!ToData)
|
||||||
@ -1286,10 +1327,11 @@ class AccountApp extends require("./dapp")
|
|||||||
}
|
}
|
||||||
ADD(ToData.Value, CoinSum)
|
ADD(ToData.Value, CoinSum)
|
||||||
this.WriteStateTR(ToData, TrNum)
|
this.WriteStateTR(ToData, TrNum)
|
||||||
if(WALLET.AccountMap[ToID] !== undefined)
|
if(ToID > 15)
|
||||||
{
|
{
|
||||||
this.DBChanges.TRHistory.push({Direct:"+", FromID:FromID, ToID:ToID, SumCOIN:CoinSum.SumCOIN, SumCENT:CoinSum.SumCENT, Description:DescriptionTo,
|
this.DBChanges.TRHistory.push({Direct:"+", Receive:1, CurID:ToID, CorrID:FromID, BlockNum:BlockNum, TrNum:TrNum, FromID:FromID,
|
||||||
FromOperationID:FromData.Value.OperationID, Currency:ToData.Currency})
|
ToID:ToID, SumCOIN:CoinSum.SumCOIN, SumCENT:CoinSum.SumCENT, Description:DescriptionTo, FromOperationID:FromData.Value.OperationID,
|
||||||
|
Currency:ToData.Currency})
|
||||||
}
|
}
|
||||||
FromData.Value.OperationID += OperationCount
|
FromData.Value.OperationID += OperationCount
|
||||||
if(FromData.Value.Smart)
|
if(FromData.Value.Smart)
|
||||||
@ -1336,6 +1378,66 @@ class AccountApp extends require("./dapp")
|
|||||||
var sigObj = secp256k1.sign(hash, Buffer.from(PrivKey));
|
var sigObj = secp256k1.sign(hash, Buffer.from(PrivKey));
|
||||||
return sigObj.signature;
|
return sigObj.signature;
|
||||||
}
|
}
|
||||||
|
SaveHistory(Data)
|
||||||
|
{
|
||||||
|
var FileItem = HistoryDB.OpenDBFile(FILE_NAME_HISTORY, 1);
|
||||||
|
var FD = FileItem.fd;
|
||||||
|
var Position = FileItem.size;
|
||||||
|
if(!Position)
|
||||||
|
Position = 100
|
||||||
|
var BufWrite = BufLib.GetBufferFromObject(Data, this.HistoryFormatArr[Data.Type], 100, WorkStructHistory);
|
||||||
|
var written = fs.writeSync(FD, BufWrite, 0, BufWrite.length, Position);
|
||||||
|
if(written !== BufWrite.length)
|
||||||
|
{
|
||||||
|
TO_ERROR_LOG("DB-HISTORY", 10, "Error write to file:" + written + " <> " + BufWrite.length)
|
||||||
|
throw "Error write to FILE_NAME_HISTORY";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(Position >= FileItem.size)
|
||||||
|
{
|
||||||
|
FileItem.size = Position + written
|
||||||
|
}
|
||||||
|
return Position;
|
||||||
|
}
|
||||||
|
GetHistory(Num, Count, StartPos)
|
||||||
|
{
|
||||||
|
var Position = StartPos;
|
||||||
|
var FileItem = HistoryDB.OpenDBFile(FILE_NAME_HISTORY, 0);
|
||||||
|
var FD = FileItem.fd;
|
||||||
|
if(Position === undefined)
|
||||||
|
{
|
||||||
|
var Account = this.DBStateHistory.Read(Num);
|
||||||
|
if(!Account)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
Position = Account.NextPos
|
||||||
|
}
|
||||||
|
var arr = [];
|
||||||
|
while(Count > 0 && Position)
|
||||||
|
{
|
||||||
|
Count--
|
||||||
|
var BufRead = BufLib.GetNewBuffer(100);
|
||||||
|
var bytesRead = fs.readSync(FD, BufRead, 0, BufRead.length, Position);
|
||||||
|
if(bytesRead < 13)
|
||||||
|
{
|
||||||
|
ToLog("bytesRead<13 Position=" + Position)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var Type = BufRead[0];
|
||||||
|
var format = this.HistoryFormatArr[Type];
|
||||||
|
if(!format)
|
||||||
|
{
|
||||||
|
ToLog("Error from history, type = " + Type)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var Item = BufLib.GetObjectFromBuffer(BufRead, format, WorkStructHistory);
|
||||||
|
Item.Pos = Position
|
||||||
|
Position = Item.NextPos
|
||||||
|
arr.push(Item)
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
module.exports = AccountApp;
|
module.exports = AccountApp;
|
||||||
var App = new AccountApp;
|
var App = new AccountApp;
|
||||||
|
@ -119,29 +119,30 @@ WebApi2.GetTransaction = function (Params)
|
|||||||
var Arr = GetArrFromHex(Params.TxID);
|
var Arr = GetArrFromHex(Params.TxID);
|
||||||
var BlockNum = ReadUintFromArr(Arr, TR_TICKET_HASH_LENGTH);
|
var BlockNum = ReadUintFromArr(Arr, TR_TICKET_HASH_LENGTH);
|
||||||
var Block = SERVER.ReadBlockDB(BlockNum);
|
var Block = SERVER.ReadBlockDB(BlockNum);
|
||||||
if(Block)
|
if(Block && Block.arrContent)
|
||||||
{
|
{
|
||||||
Arr = Arr.slice(0, TR_TICKET_HASH_LENGTH);
|
|
||||||
for(var i = 0; i < Block.arrContent.length; i++)
|
for(var i = 0; i < Block.arrContent.length; i++)
|
||||||
{
|
{
|
||||||
var Body = Block.arrContent[i];
|
var Body = Block.arrContent[i];
|
||||||
var Nonce = ReadUintFromArr(Body, Body.length - 6);
|
var Arr2 = GetTxID(BlockNum, Body);
|
||||||
var Arr2 = CreateTxID(Body, BlockNum, Nonce);
|
|
||||||
Arr2 = Arr2.slice(0, TR_TICKET_HASH_LENGTH);
|
|
||||||
if(CompareArr(Arr2, Arr) === 0)
|
if(CompareArr(Arr2, Arr) === 0)
|
||||||
{
|
{
|
||||||
var TR = DApps.Accounts.GetObjectTransaction(Body);
|
return GetTransactionFromBody(Params, Block, i, Body);
|
||||||
if(TR)
|
}
|
||||||
{
|
}
|
||||||
ConvertBufferToStr(TR);
|
}
|
||||||
TR.result = 1;
|
}
|
||||||
TR.Meta = Params.Meta;
|
else
|
||||||
if(Block.VersionBody === 1 && Block.arrContentResult)
|
{
|
||||||
{
|
if(typeof Params === "object" && Params.BlockNum && Params.TrNum !== undefined)
|
||||||
TR.result = Block.arrContentResult[i];
|
{
|
||||||
}
|
var Block = SERVER.ReadBlockDB(Params.BlockNum);
|
||||||
return TR;
|
if(Block && Block.arrContent)
|
||||||
}
|
{
|
||||||
|
var Body = Block.arrContent[Params.TrNum];
|
||||||
|
if(Body)
|
||||||
|
{
|
||||||
|
return GetTransactionFromBody(Params, Block, Params.TrNum, Body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,9 +151,39 @@ WebApi2.GetTransaction = function (Params)
|
|||||||
};
|
};
|
||||||
WebApi2.GetHistoryTransactions = function (Params)
|
WebApi2.GetHistoryTransactions = function (Params)
|
||||||
{
|
{
|
||||||
|
if(typeof Params === "object" && Params.AccountID)
|
||||||
|
{
|
||||||
|
if(!Params.Count)
|
||||||
|
Params.Count = 100;
|
||||||
|
var arr = DApps.Accounts.GetHistory(Params.AccountID, Params.Count, Params.NextPos);
|
||||||
|
if(Params.GetTxID)
|
||||||
|
{
|
||||||
|
for(var i = 0; i < arr.length; i++)
|
||||||
|
{
|
||||||
|
var Item = arr[i];
|
||||||
|
var Block = SERVER.ReadBlockDB(Item.BlockNum);
|
||||||
|
if(!Block || (!Block.arrContent))
|
||||||
|
continue;
|
||||||
|
var Body = Block.arrContent[Item.TrNum];
|
||||||
|
if(!Body)
|
||||||
|
continue;
|
||||||
|
Item.TxID = GetHexFromArr(GetTxID(Item.BlockNum, Body));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var Result = {result:arr.length > 0 ? 1 : 0, History:arr, Tail:DApps.Accounts.DBStateHistory.Read(Params.AccountID), Meta:Params ? Params.Meta : undefined};
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
return {result:0, Meta:Params ? Params.Meta : undefined};
|
||||||
};
|
};
|
||||||
var DELTA_FOR_TIME_TX = 1;
|
var DELTA_FOR_TIME_TX = 1;
|
||||||
|
|
||||||
|
function GetTxID(BlockNum,Body)
|
||||||
|
{
|
||||||
|
var Nonce = ReadUintFromArr(Body, Body.length - 6);
|
||||||
|
var Arr2 = CreateTxID(Body, BlockNum, Nonce);
|
||||||
|
return Arr2.slice(0, TR_TICKET_HASH_LENGTH + 6);
|
||||||
|
};
|
||||||
|
|
||||||
function CreateTxID(body,BlockNum,Nonce)
|
function CreateTxID(body,BlockNum,Nonce)
|
||||||
{
|
{
|
||||||
body.writeUIntLE(BlockNum, body.length - 12, 6);
|
body.writeUIntLE(BlockNum, body.length - 12, 6);
|
||||||
@ -259,3 +290,22 @@ function CreateNonceAndSend(startnonce,NumNext)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function GetTransactionFromBody(Params,Block,TrNum,Body)
|
||||||
|
{
|
||||||
|
var TR = DApps.Accounts.GetObjectTransaction(Body);
|
||||||
|
if(TR)
|
||||||
|
{
|
||||||
|
ConvertBufferToStr(TR);
|
||||||
|
TR.result = 1;
|
||||||
|
TR.Meta = Params.Meta;
|
||||||
|
if(Block.VersionBody === 1 && Block.arrContentResult)
|
||||||
|
{
|
||||||
|
TR.result = Block.arrContentResult[TrNum];
|
||||||
|
}
|
||||||
|
TR.BlockNum = Block.BlockNum;
|
||||||
|
TR.TrNum = TrNum;
|
||||||
|
return TR;
|
||||||
|
}
|
||||||
|
return {result:0, Meta:Params ? Params.Meta : undefined};
|
||||||
|
};
|
||||||
|
@ -896,7 +896,7 @@ function TestSignLib(MaxTime)
|
|||||||
{
|
{
|
||||||
ToLog("*************** WARNING: VERY SLOW LIBRARY: secp256k1 ***************");
|
ToLog("*************** WARNING: VERY SLOW LIBRARY: secp256k1 ***************");
|
||||||
ToLog("You can only process: " + Num + " transactions");
|
ToLog("You can only process: " + Num + " transactions");
|
||||||
ToLog("Install all dependent packages and run the installation command:\ncd Source/node_modules/secp256k1 \nnode-gyp build");
|
ToLog("Install all dependent packages, see detail: https://www.npmjs.com/package/secp256k1");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ function CheckAlive()
|
|||||||
var Delta = Date.now() - LastAlive;
|
var Delta = Date.now() - LastAlive;
|
||||||
if(Delta > CHECK_STOP_CHILD_PROCESS)
|
if(Delta > CHECK_STOP_CHILD_PROCESS)
|
||||||
{
|
{
|
||||||
ToLog("HOSTING: ALIVE TIMEOUT Stop and exit: " + Delta + "/" + global.CHECK_STOP_CHILD_PROCESS);
|
ToLog("HOSTING: ALIVE TIMEOUT Stop and exit: " + Delta + "/" + global.CHECK_STOP_CHILD_PROCESS, 0);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ process.on('uncaughtException', function (err)
|
|||||||
ToError(err.stack);
|
ToError(err.stack);
|
||||||
ToLog(err.stack);
|
ToLog(err.stack);
|
||||||
TO_ERROR_LOG("HOSTING", 777, err);
|
TO_ERROR_LOG("HOSTING", 777, err);
|
||||||
ToLog("-----------------HOSTING EXIT------------------");
|
ToLog("-----------------HOSTING EXIT------------------", 0);
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
process.on('error', function (err)
|
process.on('error', function (err)
|
||||||
@ -169,7 +169,7 @@ if(global.HTTPS_HOSTING_DOMAIN)
|
|||||||
}
|
}
|
||||||
if(GetNewSert)
|
if(GetNewSert)
|
||||||
{
|
{
|
||||||
ToLog("Start get new SERT");
|
ToLog("Start get new SERT", 0);
|
||||||
var opts = {domains:[global.HTTPS_HOSTING_DOMAIN], email:'progr76@gmail.com', agreeTos:true, communityMember:true, };
|
var opts = {domains:[global.HTTPS_HOSTING_DOMAIN], email:'progr76@gmail.com', agreeTos:true, communityMember:true, };
|
||||||
greenlock.register(opts).then(function (certs)
|
greenlock.register(opts).then(function (certs)
|
||||||
{
|
{
|
||||||
@ -209,7 +209,7 @@ function MainHTTPFunction(request,response)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var Str = "Error postDataChunk.length=" + postDataChunk.length;
|
var Str = "Error postDataChunk.length=" + postDataChunk.length;
|
||||||
ToLog(Str);
|
ToLog(Str, 0);
|
||||||
Response.writeHead(405, {'Content-Type':'text/html'});
|
Response.writeHead(405, {'Content-Type':'text/html'});
|
||||||
Response.end(Str);
|
Response.end(Str);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user