Skip to content

Commit

Permalink
fix: 🐛 Fix all util.isArray and approval error
Browse files Browse the repository at this point in the history
  • Loading branch information
limsbase committed Jun 24, 2020
1 parent 49348a7 commit d025aa2
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 182 deletions.
94 changes: 47 additions & 47 deletions examples/fun-tests/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export default {
maxConfirmations: 77 * 100,
confirmationLength: 77,
fixedPoint: 10 ** 8,
totalAmount: "10000000000000000", //Bignum update
totalAmount: '10000000000000000', // Bignum update
maxTxsPerBlock: 500,

testnet: {
rewardRatio: 0.2,
milestones: [
"500000000", // Initial Reward Bignum update
"400000000", // Milestone 1
"300000000", // Milestone 2
"200000000", // Milestone 3
"100000000" // Milestone 4
'500000000', // Initial Reward Bignum update
'400000000', // Milestone 1
'300000000', // Milestone 2
'200000000', // Milestone 3
'100000000' // Milestone 4
],
beginDate: new Date(Date.UTC(2017, 10, 20, 12, 20, 20, 20)), // testnet
rewardDistance: 3000000, // Distance between each milestone
Expand All @@ -40,64 +40,64 @@ export default {

// Fees for transacton
fees: {
send: "10000000",
vote: "100000000",
secondSignature: "500000000",
delegate: "10000000000",
multiSignature: "500000000",
dappRegistration: "2500000000",
dappWithdrawal: "10000000",
dappDeposit: "10000000",
data: "10000000",
send: '10000000',
vote: '100000000',
secondSignature: '500000000',
delegate: '10000000000',
multiSignature: '500000000',
dappRegistration: '2500000000',
dappWithdrawal: '10000000',
dappDeposit: '10000000',
data: '10000000',

// todo: 测试中提供的费用
username: "10000000",
multiTransfer: "10000000",
dapp: "10000000000",
username: '10000000',
multiTransfer: '10000000',
dapp: '10000000000',

// dao
evidence: "10000000", // fixme
org: "10000000",
exchange: "10000000",
},
evidence: '10000000', // fixme
org: '10000000',
exchange: '10000000'
}
},

mainnet: {
rewardRatio: 0.2,
milestones: [
"500000000", // Initial Reward Bignum update
"400000000", // Milestone 1
"300000000", // Milestone 2
"200000000", // Milestone 3
"100000000" // Milestone 4
'500000000', // Initial Reward Bignum update
'400000000', // Milestone 1
'300000000', // Milestone 2
'200000000', // Milestone 3
'100000000' // Milestone 4
],
beginDate: new Date(Date.UTC(2017, 11, 20, 4, 0, 0, 0)), // 主网上线:2017年12月20日中午12点(+8)
beginDate: new Date(Date.UTC(2017, 11, 20, 4, 0, 0, 0)), // 主网上线:2017年12月20日中午12点(+8)
rewardDistance: 3000000, // Distance between each milestone
rewardOffset: 1, // Start rewards at block (n)
// If you have some different thing, Please set the compatibleVersion.
compatibleVersion: '0.0.0', // Peer isCompatible?

// Fees for transacton
fees: {
send: "10000000", //Bignum update
vote: "100000000",
secondSignature: "500000000",
delegate: "2500000000",
multisignature: "500000000",
dappRegistration: "2500000000",
dappWithdrawal: "10000000",
dappDeposit: "10000000",
data: "10000000",
send: '10000000', // Bignum update
vote: '100000000',
secondSignature: '500000000',
delegate: '2500000000',
multisignature: '500000000',
dappRegistration: '2500000000',
dappWithdrawal: '10000000',
dappDeposit: '10000000',
data: '10000000',

// todo: 测试中提供的费用
username: "10000000",
multiTransfer: "10000000",
dapp: "10000000000",
username: '10000000',
multiTransfer: '10000000',
dapp: '10000000000',

// dao
evidence: "10000000", // fixme
org: "10000000",
exchange: "10000000",
},
evidence: '10000000', // fixme
org: '10000000',
exchange: '10000000'
}
}
};
}
16 changes: 7 additions & 9 deletions packages/peer/src/assets/system/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* 受托人资产交易
* wangxm 2018-12-28
*/
import util from 'util'

import ByteBuffer from 'bytebuffer'
import DdnUtils from '@ddn/utils'

Expand All @@ -28,7 +26,7 @@ class Delegate {
return trs
}

async calculateFee (trs, sender) {
async calculateFee () {
// Bignum update
return DdnUtils.bignum.multiply(100, this.constants.fixedPoint)
}
Expand Down Expand Up @@ -83,7 +81,7 @@ class Delegate {
return trs
}

async process (trs, sender) {
async process (trs) {
return trs
}

Expand All @@ -102,7 +100,7 @@ class Delegate {
return false
}

async apply ({ asset }, block, { address }, dbTrans) {
async apply ({ asset }, { address }, dbTrans) {
const data = {
address,
u_is_delegate: 0, // wxm block database
Expand All @@ -120,7 +118,7 @@ class Delegate {
return await this.runtime.account.getAccountByAddress(address)
}

async undo ({ asset }, block, { address, nameexist }, dbTrans) {
async undo ({ asset }, { address, nameexist }, dbTrans) {
const data = {
address,
u_is_delegate: 1, // wxm block database
Expand All @@ -138,7 +136,7 @@ class Delegate {
return await this.runtime.account.getAccountByAddress(address)
}

async applyUnconfirmed ({ asset, type }, { isDelegate, address }, dbTrans) {
async applyUnconfirmed ({ asset, type }, { isDelegate, address }) {
if (isDelegate) {
throw new Error('Account is already a delegate')
}
Expand All @@ -153,7 +151,7 @@ class Delegate {
this.oneoff.set(idKey, true)
}

async undoUnconfirmed ({ asset, type }, { address }, dbTrans) {
async undoUnconfirmed ({ asset, type }, { address }) {
const nameKey = `${asset.delegate.name}:${type}`
const idKey = `${address}:${type}`
this.oneoff.delete(nameKey)
Expand Down Expand Up @@ -212,7 +210,7 @@ class Delegate {
}

async ready ({ signatures }, { multisignatures, multimin }) {
if (util.isArray(multisignatures) && multisignatures.length) {
if (Array.isArray(multisignatures) && multisignatures.length) {
if (!signatures) {
return false
}
Expand Down
6 changes: 2 additions & 4 deletions packages/peer/src/assets/system/multisignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Signatures
* wangxm 2019-03-25
*/
import util from 'util'

import DdnUtils from '@ddn/utils'
import ByteBuffer from 'bytebuffer'
import Diff from '../../lib/diff'
Expand Down Expand Up @@ -44,7 +42,7 @@ class Multisignature {
throw new Error(`Invalid transaction asset: ${trs.id}`)
}

if (!util.isArray(trs.asset.multisignature.keysgroup)) {
if (!Array.isArray(trs.asset.multisignature.keysgroup)) {
throw new Error(`Invalid transaction asset: ${trs.id}`)
}

Expand Down Expand Up @@ -327,7 +325,7 @@ class Multisignature {
return false
}

if (util.isArray(multisignatures) && !multisignatures.length) {
if (Array.isArray(multisignatures) && !multisignatures.length) {
const ready = signatures.length == asset.multisignature.keysgroup.length
if (!ready) {
this.logger.warn(`The number of multisignature signatures is less than ${asset.multisignature.keysgroup.length}`)
Expand Down
4 changes: 1 addition & 3 deletions packages/peer/src/assets/system/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Signatures
* wangxm 2019-03-25
*/
import util from 'util'

import DdnUtils from '@ddn/utils'
import ByteBuffer from 'bytebuffer'

Expand Down Expand Up @@ -168,7 +166,7 @@ class Signatures {
}

ready ({ signatures }, { multisignatures, multimin }) {
if (util.isArray(multisignatures) && multisignatures.length) {
if (Array.isArray(multisignatures) && multisignatures.length) {
if (!signatures) {
return false
}
Expand Down
50 changes: 2 additions & 48 deletions packages/peer/src/assets/system/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* 转账资产交易
* wangxm 2018-12-28
*/
import util from 'util'

import DdnUtil from '@ddn/utils' // DdnUtil.bignum update

class Transfer {
Expand Down Expand Up @@ -42,7 +40,7 @@ class Transfer {
throw new Error('Invalid transaction amount')
}

if (trs.recipientId == address) {
if (trs.recipientId === address) {
// wxm block database
throw new Error('Invalid recipientId, cannot be your self')
}
Expand Down Expand Up @@ -101,26 +99,6 @@ class Transfer {
},
dbTrans
)

// self.modules.accounts.setAccountAndGet({ address: trs.recipientId }, dbTrans, (err, recipient) => { //wxm block database
// if (err) {
// return cb(err);
// }

// self.modules.accounts.mergeAccountAndGet(
// {
// address: trs.recipientId, //wxm block database
// balance: trs.amount,
// u_balance: trs.amount,
// block_id: block.id, //wxm block database
// round: self.modules.round.calc(block.height).toString()
// },
// dbTrans,
// (err) => {
// cb(err);
// }
// );
// });
}

async undo ({
Expand All @@ -146,30 +124,6 @@ class Transfer {
},
dbTrans
)

// if (typeof dbTrans === 'function') {
// cb = dbTrans;
// dbTrans = null
// }
// self.modules.accounts.setAccountAndGet({ address: trs.recipientId }, dbTrans, (err, recipient) => { //wxm block database
// if (err) {
// return cb(err);
// }

// self.modules.accounts.mergeAccountAndGet(
// {
// address: trs.recipientId, //wxm block database
// balance: `-${trs.amount}`,
// u_balance: `-${trs.amount}`,
// block_id: block.id, //wxm block database
// round: self.modules.round.calc(block.height).toString()
// },
// dbTrans,
// (err) => {
// cb(err);
// }
// );
// });
}

async applyUnconfirmed (trs, sender, dbTrans) {
Expand Down Expand Up @@ -197,7 +151,7 @@ class Transfer {
multisignatures,
multimin
}) {
if (util.isArray(multisignatures) && multisignatures.length) {
if (Array.isArray(multisignatures) && multisignatures.length) {
if (!signatures) {
return false
}
Expand Down
6 changes: 2 additions & 4 deletions packages/peer/src/assets/system/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* Copyright (c) 2019 DDN Foundation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*-------------------------------------------------------------------------------------------- */
import util from 'util'

import ByteBuffer from 'bytebuffer'
import Diff from '../../lib/diff.js'
import DdnUtils from '@ddn/utils'
Expand Down Expand Up @@ -136,7 +134,7 @@ class Vote {
async dbSave ({ asset, id }, dbTrans) {
return new Promise((resolve, reject) => {
this.dao.insert('vote', {
votes: util.isArray(asset.vote.votes) ? asset.vote.votes.join(',') : null,
votes: Array.isArray(asset.vote.votes) ? asset.vote.votes.join(',') : null,
transaction_id: id
}, dbTrans, (err, result) => {
if (err) {
Expand All @@ -149,7 +147,7 @@ class Vote {
}

async ready ({ signatures }, { multisignatures, multimin }) {
if (util.isArray(multisignatures) && multisignatures.length) {
if (Array.isArray(multisignatures) && multisignatures.length) {
if (!signatures) {
return false
}
Expand Down
Loading

0 comments on commit d025aa2

Please sign in to comment.