feat: alpine 0.0.1 version complate

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-07-11 13:35:16 +08:00
parent 63536569cf
commit 13607ba157
38 changed files with 1376 additions and 1064 deletions

View File

@@ -10,11 +10,12 @@
"use strict";
import * as fs from 'fs'
const DBRow = require("../core/db/db-row");
import DApp from './dapp'
import DBRow from '../core/db/db-row'
import DBLib from "../core/db/db"
require('../core/rest_tables');
const MAX_SUM_TER = 1e9;
const MAX_SUM_CENT = 1e9;
const DBLib = require("../core/db/db");
global.HistoryDB = new DBLib();
const FILE_NAME_HISTORY = "history-body";
var WorkStructHistory = {};
@@ -135,8 +136,7 @@ class MerkleDBRow extends DBRow {
}
}
};
class AccountApp extends require("./dapp")
{
class AccountApp extends DApp {
CreateTrCount
FORMAT_ACCOUNT_ROW
SIZE_ACCOUNT_ROW
@@ -178,8 +178,7 @@ class AccountApp extends require("./dapp")
}"
this.SIZE_ACCOUNT_ROW_REST = 1024
this.DBRest = new DBRow("accounts-rest", this.SIZE_ACCOUNT_ROW_REST, this.FORMAT_ACCOUNT_ROW_REST, 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, NextPos:uint, OperationID:uint,Smart:uint32,Data:arr80}, Mode:byte, TrNum:uint16, Reserve: arr9}",
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, NextPos:uint, OperationID:uint,Smart:uint32,Data:arr80}, Mode:byte, TrNum:uint16, Reserve: arr9}", 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)
@@ -188,8 +187,7 @@ class AccountApp extends require("./dapp")
this.DBStateTX = new DBRow("accounts-tx", 6 + 6 + 88, "{BlockNum:uint, BlockNumMin:uint, Reserve: arr88}", bReadOnly)
if (global.READ_ONLY_DB)
return;
this.DBAccountsHash = new DBRow("accounts-hash3", 6 + 32 + 32 + 32 + 6 + 6 + 14, "{BlockNum:uint, AccHash:hash, SumHash:hash, SmartHash:hash, AccountMax:uint, SmartCount:uint, Reserve: arr14}",
bReadOnly)
this.DBAccountsHash = new DBRow("accounts-hash3", 6 + 32 + 32 + 32 + 6 + 6 + 14, "{BlockNum:uint, AccHash:hash, SumHash:hash, SmartHash:hash, AccountMax:uint, SmartCount:uint, Reserve: arr14}", bReadOnly)
if (global.START_SERVER)
return;
if (!bReadOnly)
@@ -210,8 +208,9 @@ class AccountApp extends require("./dapp")
this.DBStateTX.Truncate(- 1)
this.DBRest.Truncate(- 1)
this._DBStateWrite({ Num: 0, PubKey: [], Value: { BlockNum: 1, SumCOIN: 0.95 * global.TOTAL_SUPPLY_TERA }, Name: "System account" }, 1)
for (var i = 1; i < 8; i++)
for (var i = 1; i < 8; i++) {
this._DBStateWrite({ Num: i, PubKey: [], Value: { BlockNum: 1 }, Name: "" })
}
this._DBStateWrite({ Num: 8, PubKey: global.GetArrFromHex(global.ARR_PUB_KEY[0]), Value: { BlockNum: 1, SumCOIN: 0.05 * global.TOTAL_SUPPLY_TERA }, Name: "Founder account" })
this._DBStateWrite({ Num: 9, PubKey: global.GetArrFromHex(global.ARR_PUB_KEY[1]), Value: { BlockNum: 1, SumCOIN: 0 }, Name: "Developer account" })
for (var i = 10; i < global.BLOCK_PROCESSING_LENGTH2; i++)
@@ -296,18 +295,19 @@ class AccountApp extends require("./dapp")
var FileNameFull2 = this.DBActPrev.FileNameFull + "_del";
try {
fs.renameSync(this.DBActPrev.FileNameFull, FileNameFull2)
}
catch (e) {
global.ToLog("Can-t rename for delete act-file: " + FileNameFull2)
} catch (e) {
global.ToLog("Can-t rename for delete act-file: " + FileNameFull2 + " " + e)
return;
}
fs.unlinkSync(FileNameFull2)
}
try {
fs.renameSync(this.DBAct.FileNameFull, this.DBActPrev.FileNameFull)
}
catch (e) {
} catch (e) {
global.ToLog("Can-t rename act-file!")
console.error(e)
console.log(`${this.DBAct}, ${this.DBActPrev}`)
console.log(`${this.DBAct.FileNameFull}, ${this.DBActPrev.FileNameFull}`)
return;
}
}
@@ -358,8 +358,7 @@ class AccountApp extends require("./dapp")
var Result;
try {
Result = this.OnWriteTransactionTR(Block, Body, BlockNum, TrNum, ContextFrom)
}
catch (e) {
} catch (e) {
Result = "" + e
}
if (Result !== true) {
@@ -396,8 +395,7 @@ class AccountApp extends require("./dapp")
Result = 1
if (global.LOCAL_RUN || global.TEST_NETWORK) {
}
else {
} else {
if (BlockNum < global.global.START_BLOCK_ACCOUNT_HASH + 200000)
break;
}
@@ -531,34 +529,35 @@ class AccountApp extends require("./dapp")
global.ConvertBufferToStr(TR)
return JSON.stringify(TR, undefined, 2);
}
TRCheckAccountHash(Body, BlockNum, TrNum) {
if (BlockNum % global.PERIOD_ACCOUNT_HASH !== 0)
TRCheckAccountHash(Body, BlockNum, TrNum?) {
if (BlockNum % global.PERIOD_ACCOUNT_HASH !== 0) {
return 1;
}
try {
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_ACCOUNT_HASH3, {});
}
catch (e) {
} catch (e) {
return 0;
}
if (BlockNum < global.START_BLOCK_ACCOUNT_HASH + 200000)
if (BlockNum < global.START_BLOCK_ACCOUNT_HASH + 200000) {
return 1;
}
var Item = this.GetAccountHashItem(TR.BlockNum);
if (Item && Item.BlockNum === TR.BlockNum) {
if (global.CompareArr(Item.AccHash, TR.AccHash) === 0) {
if (TR.BlockNum >= global.START_BLOCK_ACCOUNT_HASH3) {
if (global.CompareArr(Item.SmartHash, TR.SmartHash) === 0 && Item.AccountMax === TR.AccountMax && Item.SmartCount === TR.SmartCount) {
return 1;
}
else
} else {
return 0;
}
}
return 1;
}
else
} else {
return 0;
}
else
}
} else {
return 2;
}
}
TRCreateAccount(Body, BlockNum, TrNum, ContextFrom) {
if (Body.length < 90)
@@ -913,7 +912,7 @@ class AccountApp extends require("./dapp")
GetMaxAccount() {
return this.DBState.GetMaxNum();
}
GetRowsAccounts(start, count, Filter, bGetState) {
GetRowsAccounts(start, count, Filter?, bGetState?) {
if (Filter) {
Filter = Filter.trim()
}
@@ -1005,7 +1004,7 @@ class AccountApp extends require("./dapp")
GetActsMaxNum() {
return this.DBActPrev.GetMaxNum() + this.DBAct.GetMaxNum();
}
GetActList(start, count) {
GetActList(start, count, b?) {
var arr = [];
var num;
for (num = start; num < start + count; num++) {
@@ -1338,7 +1337,7 @@ class AccountApp extends require("./dapp")
}
return Position;
}
GetHistory(Num, Count, StartPos, MinConfirm) {
GetHistory(Num, Count, StartPos, MinConfirm?) {
if (!MinConfirm)
MinConfirm = 0
var MaxNumBlockDB = global.SERVER.GetMaxNumBlockDB();
@@ -1392,7 +1391,6 @@ class AccountApp extends require("./dapp")
return global.FLOAT_FROM_COIN(SumCoin);
}
};
module.exports = AccountApp;
var App = new AccountApp;
global.DApps["Accounts"] = App;
global.DAppByType[global.TYPE_TRANSACTION_CREATE] = App;
@@ -1401,6 +1399,7 @@ global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App;
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
global.DAppByType[global.TYPE_TRANSACTION_ACC_HASH] = App;
export default AccountApp;
// function TestStateFiles(Size, Format) {
// return;
// if (global.PROCESS_NAME !== "MAIN")