diff --git a/contracts/tokens.js b/contracts/tokens.js index 509f64b..3709783 100644 --- a/contracts/tokens.js +++ b/contracts/tokens.js @@ -52,59 +52,6 @@ actions.createSSC = async () => { token.undelegationCooldown = 7; await api.db.update('tokens', token); } - - // fix delegations to accounts with whitespaces - const balances = await api.db.find('balances', { - $and: [ - { - delegationsIn: { - $exists: true, - }, - }, - { - delegationsIn: { - $ne: '0', - }, - }, - ], - }); - - for (let index = 0; index < balances.length; index += 1) { - const balance = balances[index]; - - if (balance.account.trim() !== balance.account) { - const delegations = await api.db.find('delegations', { to: balance.account, symbol: balance.symbol }); - - for (let idx = 0; idx < delegations.length; idx += 1) { - const delegation = delegations[idx]; - const balanceFrom = await api.db.findOne('balances', { account: delegation.from, symbol: delegation.symbol }); - - const tkn = await api.db.findOne('tokens', { symbol: balance.symbol }); - - // update the balanceFrom - balanceFrom.stake = calculateBalance( - balanceFrom.stake, delegation.quantity, tkn.precision, true, - ); - balanceFrom.delegationsOut = calculateBalance( - balanceFrom.delegationsOut, delegation.quantity, tkn.precision, false, - ); - - // update balance - balance.delegationsIn = calculateBalance( - balance.delegationsIn, delegation.quantity, tkn.precision, false, - ); - - await api.db.update('balances', balanceFrom); - await api.db.remove('delegations', delegation); - - if (api.BigNumber(balance.balance).eq(0) && api.BigNumber(balance.delegationsIn).eq(0)) { - await api.db.remove('balances', balance); - } else { - await api.db.update('balances', balance); - } - } - } - } }; actions.updateParams = async (payload) => { @@ -602,8 +549,8 @@ actions.enableStaking = async (payload) => { if (api.assert(isSignedWithActiveKey === true, 'you must use a custom_json signed with your active key') && api.assert(symbol && typeof symbol === 'string', 'invalid symbol') - && api.assert(unstakingCooldown && Number.isInteger(unstakingCooldown) && unstakingCooldown > 0 && unstakingCooldown <= 365, 'unstakingCooldown must be an integer between 1 and 365') - && api.assert(numberTransactions && Number.isInteger(numberTransactions) && numberTransactions > 0 && numberTransactions <= 365, 'numberTransactions must be an integer between 1 and 365')) { + && api.assert(unstakingCooldown && Number.isInteger(unstakingCooldown) && unstakingCooldown > 0 && unstakingCooldown <= 18250, 'unstakingCooldown must be an integer between 1 and 18250') + && api.assert(numberTransactions && Number.isInteger(numberTransactions) && numberTransactions > 0 && numberTransactions <= 18250, 'numberTransactions must be an integer between 1 and 18250')) { const token = await api.db.findOne('tokens', { symbol }); if (api.assert(token !== null, 'symbol does not exist') @@ -928,7 +875,7 @@ actions.enableDelegation = async (payload) => { if (api.assert(isSignedWithActiveKey === true, 'you must use a custom_json signed with your active key') && api.assert(symbol && typeof symbol === 'string', 'invalid symbol') - && api.assert(undelegationCooldown && Number.isInteger(undelegationCooldown) && undelegationCooldown > 0 && undelegationCooldown <= 365, 'undelegationCooldown must be an integer between 1 and 365')) { + && api.assert(undelegationCooldown && Number.isInteger(undelegationCooldown) && undelegationCooldown > 0 && undelegationCooldown <= 18250, 'undelegationCooldown must be an integer between 1 and 18250')) { const token = await api.db.findOne('tokens', { symbol }); if (api.assert(token !== null, 'symbol does not exist') diff --git a/test/smarttokens.js b/test/smarttokens.js index bf307aa..6c14153 100644 --- a/test/smarttokens.js +++ b/test/smarttokens.js @@ -188,9 +188,9 @@ describe('smart tokens', function () { transactions.push(new Transaction(12345678901, 'TXID1236', 'harpagon', 'tokens', 'create', '{ "isSignedWithActiveKey": true, "name": "token", "symbol": "NKT", "precision": 8, "maxSupply": "1000", "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1238', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 7, "numberTransactions": 1, "isSignedWithActiveKey": true }')); - transactions.push(new Transaction(12345678901, 'TXID1240', 'satoshi', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 365, "numberTransactions": 1, "isSignedWithActiveKey": true }')); + transactions.push(new Transaction(12345678901, 'TXID1240', 'satoshi', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 18250, "numberTransactions": 1, "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1241', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 0, "isSignedWithActiveKey": true }')); - transactions.push(new Transaction(12345678901, 'TXID1242', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 366, "isSignedWithActiveKey": true }')); + transactions.push(new Transaction(12345678901, 'TXID1242', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 18251, "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1243', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1244', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }')); @@ -213,8 +213,8 @@ describe('smart tokens', function () { assert.equal(JSON.parse(txs[4].logs).errors[0], 'staking not enabled'); assert.equal(JSON.parse(txs[6].logs).errors[0], 'must be the issuer'); - assert.equal(JSON.parse(txs[7].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 365'); - assert.equal(JSON.parse(txs[8].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 365'); + assert.equal(JSON.parse(txs[7].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 18250'); + assert.equal(JSON.parse(txs[8].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 18250'); assert.equal(JSON.parse(txs[10].logs).errors[0], 'delegation already enabled'); resolve(); @@ -915,7 +915,7 @@ describe('smart tokens', function () { transactions.push(new Transaction(12345678901, 'TXID1236', 'harpagon', 'tokens', 'create', '{ "isSignedWithActiveKey": true, "name": "token", "symbol": "NKT", "precision": 8, "maxSupply": "1000", "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1237', 'satoshi', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 7, "numberTransactions": 1, "isSignedWithActiveKey": true }')); transactions.push(new Transaction(12345678901, 'TXID1238', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 0, "numberTransactions": 1, "isSignedWithActiveKey": true }')); - transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 366, "numberTransactions": 1, "isSignedWithActiveKey": true }')); + transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 18251, "numberTransactions": 1, "isSignedWithActiveKey": true }')); let block = { refSteemBlockNumber: 12345678901, @@ -953,8 +953,8 @@ describe('smart tokens', function () { let txs = res.payload.transactions; assert.equal(JSON.parse(txs[4].logs).errors[0], 'must be the issuer'); - assert.equal(JSON.parse(txs[5].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 365'); - assert.equal(JSON.parse(txs[6].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 365'); + assert.equal(JSON.parse(txs[5].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 18250'); + assert.equal(JSON.parse(txs[6].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 18250'); resolve(); })