Skip to content

Commit 9646047

Browse files
authored
Merge pull request #162 from ainblockchain/develop
Release v0.5.0
2 parents 5cc4a47 + 9965999 commit 9646047

38 files changed

+2818
-1528
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: "\U0001F914 Ask a question"
3+
about: Ask about this project
4+
title: ''
5+
labels: question
6+
assignees: ''
7+
8+
---
9+
10+
## For general questions please join [AINetwork Slack](https://join.slack.com/t/cloud-native/shared_invite/zt-fyy3b8up-qHeDNVqbz1j8HDY6g1cY4w) and ask at [#help_en](https://ainetwork-dev.slack.com/archives/C016JB5VADV) channel.
11+
12+
13+
14+
**Is your feature request related to a problem? Please describe.**
15+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
16+
17+
**Describe the solution you'd like**
18+
A clear and concise description of what you want to happen.
19+
20+
**Describe alternatives you've considered**
21+
A clear and concise description of any alternative solutions or features you've considered.
22+
23+
**Additional context**
24+
Add any other context or screenshots about the feature request here.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: "\U0001F41B Bug report"
3+
about: Create a report to help us improve
4+
title: "[BUG] "
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Install and import ain-util '....'
17+
3. call function abc() '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**System information:**
24+
- OS & version: [e.g. Windows/Linux/OSX]
25+
- ain-util version: [e.g. 1.1.6]
26+
- Commit hash: [e.g. 8cf3db6]
27+
28+
**Screenshots**
29+
If applicable, add screenshots to help explain your problem.
30+
31+
**Additional context**
32+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: "\U0001F4A1 Feature request"
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: new feature
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

blockchain/block.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Block {
8181
return ChainUtil.hashString(stringify(block.header));
8282
}
8383

84-
static createBlock(lastHash, lastVotes, transactions, number, epoch,
84+
static create(lastHash, lastVotes, transactions, number, epoch,
8585
stateProofHash, proposer, validators) {
8686
return new Block(lastHash, lastVotes, transactions, number, epoch, Date.now(),
8787
stateProofHash, proposer, validators);
@@ -133,30 +133,30 @@ class Block {
133133
static validateProposedBlock(block) {
134134
if (!Block.validateHashes(block)) return false;
135135
const nonceTracker = {};
136-
let transaction;
136+
let tx;
137137
for (let i = 0; i < block.transactions.length; i++) {
138-
transaction = block.transactions[i];
139-
if (transaction.nonce < 0) {
138+
tx = block.transactions[i];
139+
if (tx.tx_body.nonce < 0) {
140140
continue;
141141
}
142-
if (!(transaction.address in nonceTracker)) {
143-
nonceTracker[transaction.address] = transaction.nonce;
142+
if (!(tx.address in nonceTracker)) {
143+
nonceTracker[tx.address] = tx.tx_body.nonce;
144144
continue;
145145
}
146-
if (transaction.nonce != nonceTracker[transaction.address] + 1) {
147-
logger.error(`Invalid noncing for ${transaction.address} ` +
148-
`Expected ${nonceTracker[transaction.address] + 1} ` +
149-
`Received ${transaction.nonce}`);
146+
if (tx.tx_body.nonce != nonceTracker[tx.address] + 1) {
147+
logger.error(`Invalid noncing for ${tx.address} ` +
148+
`Expected ${nonceTracker[tx.address] + 1} ` +
149+
`Received ${tx.tx_body.nonce}`);
150150
return false;
151151
}
152-
nonceTracker[transaction.address] = transaction.nonce;
152+
nonceTracker[tx.address] = tx.tx_body.nonce;
153153
}
154154

155155
logger.info(`Valid block of number ${block.number}`);
156156
return true;
157157
}
158158

159-
static getDbSetupTransaction(timestamp, keyBuffer) {
159+
static buildDbSetupTx(timestamp, privateKey) {
160160
const opList = [];
161161

162162
// Values operation
@@ -188,19 +188,18 @@ class Block {
188188
});
189189

190190
// Transaction
191-
const firstTxData = {
191+
const firstTxBody = {
192192
nonce: -1,
193193
timestamp,
194194
operation: {
195195
type: 'SET',
196196
op_list: opList,
197197
}
198198
};
199-
const firstSig = ainUtil.ecSignTransaction(firstTxData, keyBuffer);
200-
return (new Transaction({signature: firstSig, transaction: firstTxData}));
199+
return Transaction.signTxBody(firstTxBody, privateKey);
201200
}
202201

203-
static getAccountsSetupTransaction(ownerAddress, timestamp, keyBuffer) {
202+
static buildAccountsSetupTx(ownerAddress, timestamp, privateKey) {
204203
const transferOps = [];
205204
const otherAccounts = GenesisAccounts[AccountProperties.OTHERS];
206205
if (otherAccounts && Array.isArray(otherAccounts) && otherAccounts.length > 0 &&
@@ -219,27 +218,25 @@ class Block {
219218
}
220219

221220
// Transaction
222-
const secondTxData = {
221+
const secondTxBody = {
223222
nonce: -1,
224223
timestamp,
225224
operation: {
226225
type: 'SET',
227226
op_list: transferOps
228227
}
229228
};
230-
const secondSig = ainUtil.ecSignTransaction(secondTxData, keyBuffer);
231-
return (new Transaction({signature: secondSig, transaction: secondTxData}));
229+
return Transaction.signTxBody(secondTxBody, privateKey);
232230
}
233231

234232
static getGenesisBlockData(genesisTime) {
235233
const ownerAddress = ChainUtil.getJsObject(
236234
GenesisAccounts, [AccountProperties.OWNER, AccountProperties.ADDRESS]);
237235
const ownerPrivateKey = ChainUtil.getJsObject(
238236
GenesisAccounts, [AccountProperties.OWNER, AccountProperties.PRIVATE_KEY]);
239-
const keyBuffer = Buffer.from(ownerPrivateKey, 'hex');
240237

241-
const firstTx = this.getDbSetupTransaction(genesisTime, keyBuffer);
242-
const secondTx = this.getAccountsSetupTransaction(ownerAddress, genesisTime, keyBuffer);
238+
const firstTx = this.buildDbSetupTx(genesisTime, ownerPrivateKey);
239+
const secondTx = this.buildAccountsSetupTx(ownerAddress, genesisTime, ownerPrivateKey);
243240

244241
return [firstTx, secondTx];
245242
}

0 commit comments

Comments
 (0)