Skip to content

Commit f1def85

Browse files
authored
Merge pull request #118 from ainblockchain/develop
Release v0.3.1
2 parents 07bec8b + 63431de commit f1def85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2415
-1323
lines changed

blockchain/afan_shard/genesis_sharding.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"sharding_protocol": "POA",
33
"sharding_path": "/apps/afan",
44
"parent_chain_poc": "http://127.0.0.1:8081",
5-
"reporting_period": 5
5+
"reporting_period": 5,
6+
"token_exchange_scheme": "FIXED",
7+
"token_exchange_rate": 10
68
}

blockchain/block.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class Block {
241241
}
242242

243243
static getGenesisStateProofHash() {
244-
const tempGenesisState = new DB(null, -1);
244+
const tempGenesisState = new DB(null, null, false, -1);
245245
const genesisTransactions = Block.getGenesisBlockData(GenesisAccounts[AccountProperties.TIMESTAMP]);
246246
for (const tx of genesisTransactions) {
247247
const res = tempGenesisState.executeTransaction(tx);
@@ -267,7 +267,7 @@ class Block {
267267
const proposer = ownerAddress;
268268
const validators = GenesisWhitelist;
269269
const stateProofHash = Block.getGenesisStateProofHash();
270-
return new this(lastHash, lastVotes, transactions, number, epoch, genesisTime,
270+
return new Block(lastHash, lastVotes, transactions, number, epoch, genesisTime,
271271
stateProofHash, proposer, validators);
272272
}
273273
}

blockchain/genesis_functions.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
{
2+
"checkin": {
3+
"$user_addr": {
4+
"$checkin_id": {
5+
"request": {
6+
".function": {
7+
"function_type": "NATIVE",
8+
"function_id": "_openCheckin"
9+
}
10+
},
11+
"parent_finalize": {
12+
"$tx_hash": {
13+
"result": {
14+
".function": {
15+
"function_type": "NATIVE",
16+
"function_id": "_closeCheckin"
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
},
224
"deposit": {
325
"$service": {
426
"$user_addr": {

blockchain/genesis_rules.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
".write": true
1212
}
1313
},
14+
"checkin": {
15+
"$user_addr": {
16+
"$checkin_id": {
17+
"request": {
18+
".write": "data === null && auth === $user_addr && util.isDict(newData)"
19+
},
20+
"parent_finalize": {
21+
"$tx_hash": {
22+
"result": {
23+
".write": "auth === getValue('/sharding/config/shard_owner') && util.isBool(newData)"
24+
}
25+
}
26+
}
27+
}
28+
}
29+
},
1430
"consensus": {
1531
"number": {
1632
"$number": {

blockchain/genesis_sharding.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"sharding_protocol": "NONE",
33
"sharding_path": "/",
44
"parent_chain_poc": "",
5-
"reporting_period": 0
5+
"reporting_period": 0,
6+
"token_exchange_scheme": "NONE",
7+
"token_exchange_rate": 0
68
}

blockchain/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,24 @@ class Blockchain {
141141
return lastBlock.timestamp;
142142
}
143143

144-
addNewBlock(newBlock) {
144+
addNewBlockToChain(newBlock) {
145145
if (!newBlock) {
146-
logger.error(`[blockchain.addNewBlock] Block is null`);
146+
logger.error(`[blockchain.addNewBlockToChain] Block is null`);
147147
return false;
148148
}
149149
if (newBlock.number != this.lastBlockNumber() + 1) {
150-
logger.error(`[blockchain.addNewBlock] Invalid blockchain number: ${newBlock.number}`);
150+
logger.error(`[blockchain.addNewBlockToChain] Invalid blockchain number: ${newBlock.number}`);
151151
return false;
152152
}
153153
if (!(newBlock instanceof Block)) {
154154
newBlock = Block.parse(newBlock);
155155
}
156156
if (!this.backupDb.executeTransactionList(newBlock.last_votes)) {
157-
logger.error(`[blockchain.addNewBlock] Failed to execute last_votes of block ${JSON.stringify(newBlock, null, 2)}`);
157+
logger.error(`[blockchain.addNewBlockToChain] Failed to execute last_votes of block ${JSON.stringify(newBlock, null, 2)}`);
158158
return false;
159159
}
160160
if (!this.backupDb.executeTransactionList(newBlock.transactions)) {
161-
logger.error(`[blockchain.addNewBlock] Failed to execute transactions of block ${JSON.stringify(newBlock, null, 2)}`);
161+
logger.error(`[blockchain.addNewBlockToChain] Failed to execute transactions of block ${JSON.stringify(newBlock, null, 2)}`);
162162
return false;
163163
}
164164
this.chain.push(newBlock);
@@ -321,7 +321,7 @@ class Blockchain {
321321
continue;
322322
}
323323
// TODO(lia): validate the state proof of each block
324-
if (!this.addNewBlock(block)) {
324+
if (!this.addNewBlockToChain(block)) {
325325
logger.error(`[${LOG_PREFIX}] Failed to add block ` + block);
326326
return false;
327327
}

chain-util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class ChainUtil {
1717
return hash.substring(0,6) + '...' + hash.substring(hash.length - 4, hash.length);
1818
}
1919

20+
static hashSignature(sig) {
21+
const sigBuffer = ainUtil.toBuffer(sig);
22+
const lenHash = sigBuffer.length - 65;
23+
const hashedData = sigBuffer.slice(0, lenHash);
24+
return '0x' + hashedData.toString('hex');
25+
}
26+
2027
// TODO (lia): remove this function
2128
static genKeyPair() {
2229
let keyPair;

client/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@ process.on('SIGINT', _ => {
3030
if (!fs.existsSync(PROTOCOL_VERSIONS)) {
3131
throw Error('Missing protocol versions file: ' + PROTOCOL_VERSIONS);
3232
}
33+
if (!semver.valid(CURRENT_PROTOCOL_VERSION)) {
34+
throw Error("Wrong version format is specified in package.json");
35+
}
3336
const VERSION_LIST = JSON.parse(fs.readFileSync(PROTOCOL_VERSIONS));
34-
if (!VERSION_LIST[CURRENT_PROTOCOL_VERSION]) {
37+
const MAJOR_MINOR_VERSION =
38+
`${semver.major(CURRENT_PROTOCOL_VERSION)}.${semver.minor(CURRENT_PROTOCOL_VERSION)}`;
39+
if (!semver.valid(semver.coerce(MAJOR_MINOR_VERSION))) {
40+
throw Error("Given major and minor version does not correctly setup");
41+
}
42+
if (!VERSION_LIST[MAJOR_MINOR_VERSION]) {
3543
throw Error("Current protocol version doesn't exist in the protocol versions file");
3644
}
3745
const minProtocolVersion =
38-
VERSION_LIST[CURRENT_PROTOCOL_VERSION].min || CURRENT_PROTOCOL_VERSION;
39-
const maxProtocolVersion = VERSION_LIST[CURRENT_PROTOCOL_VERSION].max;
46+
VERSION_LIST[MAJOR_MINOR_VERSION].min || CURRENT_PROTOCOL_VERSION;
47+
const maxProtocolVersion = VERSION_LIST[MAJOR_MINOR_VERSION].max;
4048

4149
const app = express();
4250
app.use(express.json()); // support json encoded bodies
@@ -293,21 +301,20 @@ app.get('/pending_nonce_tracker', (req, res, next) => {
293301

294302
app.get('/get_transaction', (req, res, next) => {
295303
const transactionInfo = node.tp.transactionTracker[req.query.hash];
296-
let result = {};
297304
if (transactionInfo) {
298305
if (transactionInfo.status === TransactionStatus.BLOCK_STATUS) {
299306
const block = node.bc.getBlockByNumber(transactionInfo.number);
300307
const index = transactionInfo.index;
301-
Object.assign(result, block.transactions[index], { is_confirmed: true });
308+
transactionInfo.transaction = block.transactions[index];
302309
} else if (transactionInfo.status === TransactionStatus.POOL_STATUS) {
303310
const address = transactionInfo.address;
304311
const index = transactionInfo.index;
305-
Object.assign(result, node.tp.transactions[address][index], { is_confirmed: false });
312+
transactionInfo.transaction = node.tp.transactions[address][index];
306313
}
307314
}
308315
res.status(200)
309316
.set('Content-Type', 'application/json')
310-
.send({code: 0, result})
317+
.send({code: 0, result: transactionInfo})
311318
.end();
312319
});
313320

client/protocol_versions.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"0.1.0": {
3-
"min": "0.1.0",
4-
"max": "0.1.0"
2+
"0.3": {
3+
"min": "0.3.1",
4+
"max": "0.3.1"
55
}
66
}

0 commit comments

Comments
 (0)