Skip to content

Commit

Permalink
add fields to VoteCommission tx data, update deps and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Dec 1, 2021
1 parent df1acf0 commit 8c63a83
Show file tree
Hide file tree
Showing 10 changed files with 2,209 additions and 1,576 deletions.
12 changes: 9 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
root: true,
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
// parserOptions: {
// sourceType: 'module'
// },
Expand All @@ -28,7 +28,7 @@ module.exports = {
},
// // add your custom rules here
rules: {
'indent': ['error', 4],
'indent': ['error', 4, {SwitchCase: 1}],
// allow paren-less arrow functions
'arrow-parens': 0,
// allow braces around function body
Expand Down Expand Up @@ -91,11 +91,15 @@ module.exports = {
'unicorn/no-array-for-each': 0,
'unicorn/prefer-optional-catch-binding': 0,
'unicorn/prefer-ternary': 0,
// incorrectly treat `Big` as `Number`
'unicorn/require-number-to-fixed-digits-argument': 0,
// not supported yet
'unicorn/numeric-separators-style': 0,
'unicorn/prevent-abbreviations': ['error', {
replacements: {
'params': false,
},
whitelist: {
allowList: {
'resData': true,
'txParams': true,
'txProps': true,
Expand All @@ -118,6 +122,8 @@ module.exports = {
rules: {
'no-unused-vars': 0,
'import/extensions': 0,
// allow `expect` inside `then`
'jest/no-conditional-expect': 0,
}
},
]
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## WIP
- **BREAKING** add fields to VoteCommission tx data

## 0.38.3 - 2021.05.31
- add `CreateSwapPool`, `AddLiquidity` tx decorators

Expand Down
3,646 changes: 2,108 additions & 1,538 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minter-js-sdk",
"version": "0.38.3",
"version": "0.39.0-alpha.0",
"description": "JS SDK for Minter Blockchain",
"main": "dist/cjs/index.js",
"module": "src/index.js",
Expand Down Expand Up @@ -56,46 +56,46 @@
},
"homepage": "https://github.com/MinterTeam/minter-js-sdk#readme",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@babel/runtime": "^7.14.5",
"axios": "^0.21.1",
"big.js": "^6.0.3",
"big.js": "^6.1.1",
"bn.js": "^5.2.0",
"buffer-es6": "github:shrpne/buffer-es6#fix-internal-is-buffer",
"ethereum-cryptography": "^0.1.3",
"ethereumjs-util": "^7.0.10",
"ethjs-util": "^0.1.6",
"lodash-es": "^4.17.21",
"minterjs-tx": "^10.0.1",
"minterjs-tx": "^11.0.0-alpha.0",
"minterjs-util": "^0.21.0",
"minterjs-wallet": "^6.1.0",
"qs": "^6.10.1",
"rlp": "^2.2.6",
"secp256k1": "^4.0.2"
},
"devDependencies": {
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.15",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.5",
"@babel/eslint-parser": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"babel-eslint": "^10.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"babel-jest": "^26.6.3",
"coveralls": "^3.1.0",
"eslint": "^7.24.0",
"eslint": "^7.28.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.5",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-unicorn": "^29.0.0",
"eslint-plugin-unicorn": "^33.0.1",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-environment-jsdom": "^25",
"pre-commit": "^1.2.2",
"rollup": "^2.45.2",
"rollup": "^2.51.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
Expand Down
1 change: 1 addition & 0 deletions src/api/post-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function ensureNonce(apiInstance, txParams, {privateKey, address, seedPhrase} =
if (nonce) {
return Promise.resolve(nonce);
}
// @TODO seedPhrase not used
if (privateKey) {
const privateKeyBuffer = bufferFromBytes(privateKey);
address = privateToAddressString(privateKeyBuffer);
Expand Down
54 changes: 40 additions & 14 deletions src/api/replace-coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,46 @@ function getTxParamsPathList(txParams) {
pathList.push('gasCoin');

const txType = normalizeTxType(txParams.type);
if (txType === TX_TYPE.SEND || txType === TX_TYPE.DECLARE_CANDIDACY || txType === TX_TYPE.DELEGATE || txType === TX_TYPE.UNBOND || txType === TX_TYPE.MOVE_STAKE || txType === TX_TYPE.MINT_TOKEN || txType === TX_TYPE.BURN_TOKEN || txType === TX_TYPE.VOTE_COMMISSION) {
pathList.push('data.coin');
} else if (txType === TX_TYPE.SELL || txType === TX_TYPE.SELL_ALL || txType === TX_TYPE.BUY) {
pathList.push('data.coinToSell', 'data.coinToBuy');
} else if (txType === TX_TYPE.CREATE_SWAP_POOL || txType === TX_TYPE.ADD_LIQUIDITY || txType === TX_TYPE.REMOVE_LIQUIDITY) {
pathList.push('data.coin0', 'data.coin1');
} else if (txType === TX_TYPE.MULTISEND) {
txParams.data.list.forEach((item, index) => {
pathList.push(`data.list[${index}].coin`);
});
} else if (txType === TX_TYPE.BUY_SWAP_POOL || txType === TX_TYPE.SELL_SWAP_POOL || txType === TX_TYPE.SELL_ALL_SWAP_POOL) {
txParams.data.coins.forEach((item, index) => {
pathList.push(`data.coins[${index}]`);
});
switch (txType) {
case TX_TYPE.SEND:
case TX_TYPE.DECLARE_CANDIDACY:
case TX_TYPE.DELEGATE:
case TX_TYPE.UNBOND:
case TX_TYPE.MOVE_STAKE:
case TX_TYPE.MINT_TOKEN:
case TX_TYPE.BURN_TOKEN:
case TX_TYPE.VOTE_COMMISSION: {
pathList.push('data.coin');
break;
}
case TX_TYPE.SELL:
case TX_TYPE.SELL_ALL:
case TX_TYPE.BUY: {
pathList.push('data.coinToSell', 'data.coinToBuy');
break;
}
case TX_TYPE.CREATE_SWAP_POOL:
case TX_TYPE.ADD_LIQUIDITY:
case TX_TYPE.REMOVE_LIQUIDITY: {
pathList.push('data.coin0', 'data.coin1');
break;
}
case TX_TYPE.MULTISEND: {
txParams.data.list.forEach((item, index) => {
pathList.push(`data.list[${index}].coin`);
});
break;
}
case TX_TYPE.BUY_SWAP_POOL:
case TX_TYPE.SELL_SWAP_POOL:
case TX_TYPE.SELL_ALL_SWAP_POOL: {
txParams.data.coins.forEach((item, index) => {
pathList.push(`data.coins[${index}]`);
});
break;
}
// No default
default:
}

return pathList;
Expand Down
4 changes: 2 additions & 2 deletions src/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Check {

hash() {
// don't hash last 4 fields (lock and signature)
return rlphash(this.raw.slice(0, this.raw.length - 4));
return rlphash(this.raw.slice(0, -4));
}

sign(privateKey, password) {
Expand All @@ -96,7 +96,7 @@ class Check {
this.lock = `0x${lockWithRecovery.toString('hex')}`;

// don't hash last 3 signature fields
const messageHashWithLock = rlphash(this.raw.slice(0, this.raw.length - 3));
const messageHashWithLock = rlphash(this.raw.slice(0, -3));
const sig = ecsign(messageHashWithLock, privateKey);
Object.assign(this, sig);
}
Expand Down
23 changes: 22 additions & 1 deletion src/tx-data/vote-commission.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ import {bufferToInteger, integerToHexString, proxyNestedTxData, validateUint, va
* @param {number|string} voteCommission
* @param {number|string} voteUpdate
* @param {number|string} createSwapPool
* @param {number|string} failedTx
* @param {number|string} addLimitOrder
* @param {number|string} removeLimitOrder
* @constructor
*/
export default function VoteCommissionTxData({
Expand Down Expand Up @@ -101,6 +104,9 @@ export default function VoteCommissionTxData({
voteCommission,
voteUpdate,
createSwapPool,
failedTx,
addLimitOrder,
removeLimitOrder,
}) {
validatePublicKey(publicKey, 'publicKey');
validateUint(height, 'height');
Expand Down Expand Up @@ -149,6 +155,9 @@ export default function VoteCommissionTxData({
validateAmount(voteCommission, 'voteCommission');
validateAmount(voteUpdate, 'voteUpdate');
validateAmount(createSwapPool, 'createSwapPool');
validateAmount(createSwapPool, 'failedTx');
validateAmount(createSwapPool, 'addLimitOrder');
validateAmount(createSwapPool, 'removeLimitOrder');

this.publicKey = publicKey;
this.height = height;
Expand Down Expand Up @@ -197,6 +206,9 @@ export default function VoteCommissionTxData({
this.voteCommission = voteCommission;
this.voteUpdate = voteUpdate;
this.createSwapPool = createSwapPool;
this.failedTx = failedTx;
this.addLimitOrder = addLimitOrder;
this.removeLimitOrder = removeLimitOrder;

this.txData = new TxDataVoteCommission({
publicKey: toBuffer(publicKey),
Expand Down Expand Up @@ -246,6 +258,9 @@ export default function VoteCommissionTxData({
voteCommission: `0x${convertToPip(voteCommission, 'hex')}`,
voteUpdate: `0x${convertToPip(voteUpdate, 'hex')}`,
createSwapPool: `0x${convertToPip(createSwapPool, 'hex')}`,
failedTx: `0x${convertToPip(failedTx, 'hex')}`,
addLimitOrder: `0x${convertToPip(addLimitOrder, 'hex')}`,
removeLimitOrder: `0x${convertToPip(removeLimitOrder, 'hex')}`,
});

proxyNestedTxData(this);
Expand Down Expand Up @@ -299,9 +314,12 @@ export default function VoteCommissionTxData({
* @param {Buffer|string|number} voteCommission
* @param {Buffer|string|number} voteUpdate
* @param {Buffer|string|number} createSwapPool
* @param {Buffer|string|number} failedTx
* @param {Buffer|string|number} addLimitOrder
* @param {Buffer|string|number} removeLimitOrder
* @return {VoteCommissionTxData}
*/
VoteCommissionTxData.fromBufferFields = function fromBufferFields({publicKey, height, coin, payloadByte, send, buyBancor, sellBancor, sellAllBancor, buyPoolBase, buyPoolDelta, sellPoolBase, sellPoolDelta, sellAllPoolBase, sellAllPoolDelta, createTicker3, createTicker4, createTicker5, createTicker6, createTicker7to10, createCoin, createToken, recreateCoin, recreateToken, declareCandidacy, delegate, unbond, redeemCheck, setCandidateOn, setCandidateOff, createMultisig, multisendBase, multisendDelta, editCandidate, setHaltBlock, editTickerOwner, editMultisig, priceVote, editCandidatePublicKey, addLiquidity, removeLiquidity, editCandidateCommission, moveStake, burnToken, mintToken, voteCommission, voteUpdate, createSwapPool}) {
VoteCommissionTxData.fromBufferFields = function fromBufferFields({publicKey, height, coin, payloadByte, send, buyBancor, sellBancor, sellAllBancor, buyPoolBase, buyPoolDelta, sellPoolBase, sellPoolDelta, sellAllPoolBase, sellAllPoolDelta, createTicker3, createTicker4, createTicker5, createTicker6, createTicker7to10, createCoin, createToken, recreateCoin, recreateToken, declareCandidacy, delegate, unbond, redeemCheck, setCandidateOn, setCandidateOff, createMultisig, multisendBase, multisendDelta, editCandidate, setHaltBlock, editTickerOwner, editMultisig, priceVote, editCandidatePublicKey, addLiquidity, removeLiquidity, editCandidateCommission, moveStake, burnToken, mintToken, voteCommission, voteUpdate, createSwapPool, failedTx, addLimitOrder, removeLimitOrder}) {
return new VoteCommissionTxData({
publicKey: publicToString(publicKey),
height: bufferToInteger(toBuffer(height)),
Expand Down Expand Up @@ -350,6 +368,9 @@ VoteCommissionTxData.fromBufferFields = function fromBufferFields({publicKey, he
voteCommission: convertFromPip(bufferToInteger(toBuffer(voteCommission))),
voteUpdate: convertFromPip(bufferToInteger(toBuffer(voteUpdate))),
createSwapPool: convertFromPip(bufferToInteger(toBuffer(createSwapPool))),
failedTx: convertFromPip(bufferToInteger(toBuffer(failedTx))),
addLimitOrder: convertFromPip(bufferToInteger(toBuffer(addLimitOrder))),
removeLimitOrder: convertFromPip(bufferToInteger(toBuffer(removeLimitOrder))),
});
};

Expand Down
7 changes: 5 additions & 2 deletions test/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,14 @@ const testData = {
voteCommission: '12',
voteUpdate: '12',
createSwapPool: '12',
failedTx: '12',
addLimitOrder: '12',
removeLimitOrder: '12',
},
payload: 'custom message',
},
result: '0xf90206822b6701018020b901a4f901a1a0f9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a384075bcd158088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b000008e637573746f6d206d6573736167658001b845f8431ca0afd12882100d956ff82be316c4ce4216c852a22996edb5ef36da83c71de7f423a01086df0bd0d5a972ce1cea37282698a274ca892a26aba970f88bf9972eb5d50b',
link: 'https://bip.to/tx/-QG8ILkBpPkBoaD54DaDmin3-6LVOUvUie2pJ8y5WsyZ5QbmiOSIgIKzo4QHW80VgIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAI5jdXN0b20gbWVzc2FnZYIrZwGA',
result: '0xf90221822b6701018020b901bff901bca0f9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a384075bcd158088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b0000088a688906bd8b000008e637573746f6d206d6573736167658001b845f8431ba09261e1dbb7ad0370d1922235968d99b6460285523d7a2f588fe3e3befa22c953a00aa0335eafacc160973ea3fad85e7c8a44272ab129c3de2569e8e3ad12fbc9c8',
link: 'https://bip.to/tx/-QHXILkBv_kBvKD54DaDmin3-6LVOUvUie2pJ8y5WsyZ5QbmiOSIgIKzo4QHW80VgIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAIimiJBr2LAAAI5jdXN0b20gbWVzc2FnZYIrZwGA',
},
// 0x21 VOTE_UPDATE
{
Expand Down
3 changes: 3 additions & 0 deletions test/tx-data/vote-commission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ describe('VoteCommissionTxData', () => {
voteCommission: '12',
voteUpdate: '12',
createSwapPool: '12',
failedTx: '12',
addLimitOrder: '12',
removeLimitOrder: '12',
};
const txData = new VoteCommissionTxData(txParamsData).serialize();

Expand Down

0 comments on commit 8c63a83

Please sign in to comment.