Skip to content

Commit

Permalink
add new tx type edit-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Jan 15, 2019
1 parent b01c397 commit 7ea79e2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
## 4.1.0 - 2019-01-15
- add new 0x0E `MinterTxDataEditCandidate` according to minter-go-node 0.10.0

## 4.0.0 - 2018-12-06
- **BREAKING** added new fields to convert data types to support new blockchain version "minter-test-network-27"
- add `minimumValueToBuy` to `MinterTxDataSell` and `MinterTxDataSellAll`
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "minterjs-tx",
"version": "4.0.0",
"version": "4.1.0",
"description": "A simple module for creating, manipulating and signing Minter transactions",
"main": "src/index.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -6,6 +6,7 @@ import MinterTxDataBuy from './tx-data/buy';
import MinterTxDataSellAll from './tx-data/sell-all';
import MinterTxDataCreateCoin from './tx-data/create-coin';
import MinterTxDataDeclareCandidacy from './tx-data/declare-candidacy';
import MinterTxDataEditCandidate from './tx-data/edit-candidate';
import MinterTxDataSetCandidateOn from './tx-data/set-candidate-on';
import MinterTxDataSetCandidateOff from './tx-data/set-candidate-off';
import MinterTxDataDelegate from './tx-data/delegate';
Expand All @@ -25,6 +26,7 @@ export {
MinterTxDataBuy,
MinterTxDataCreateCoin,
MinterTxDataDeclareCandidacy,
MinterTxDataEditCandidate,
MinterTxDataSetCandidateOn,
MinterTxDataSetCandidateOff,
MinterTxDataDelegate,
Expand Down
39 changes: 39 additions & 0 deletions src/tx-data/edit-candidate.js
@@ -0,0 +1,39 @@
import ethUtil from 'ethereumjs-util';
import {Buffer} from 'safe-buffer';

class MinterTxDataDeclareCandidacy {
constructor(data) {
data = data || {};
// Define Properties
const fields = [
{
name: 'pubKey',
allowZero: true,
default: new Buffer([]),
},
{
name: 'rewardAddress',
allowZero: true,
length: 20,
default: new Buffer([]),
},
{
name: 'ownerAddress',
allowZero: true,
length: 20,
default: new Buffer([]),
}];

/**
* Returns the rlp encoding of the transaction
* @method serialize
* @return {Buffer}
* @memberof Transaction
* @name serialize
*/
// attached serialize
ethUtil.defineProperties(this, fields, data);
}
}

export default MinterTxDataDeclareCandidacy;
1 change: 1 addition & 0 deletions src/tx-types.js
Expand Up @@ -11,3 +11,4 @@ export const TX_TYPE_SET_CANDIDATE_ON = '0x0A';
export const TX_TYPE_SET_CANDIDATE_OFF = '0x0B';
export const TX_TYPE_CREATE_MULTISIG = '0x0C';
export const TX_TYPE_MULTISEND = '0x0D';
export const TX_TYPE_EDIT_CANDIDATE = '0x0E';
20 changes: 20 additions & 0 deletions test/tx-data/edit-candidate.test.js
@@ -0,0 +1,20 @@
import {toBuffer} from 'minterjs-util';
import {MinterTxDataEditCandidate} from '~/src';
import decodeToArray from '../decode-to-array';

describe('MinterTxDataDeclareCandidacy', () => {
test('rlp encoded fields', () => {
const serializedTxData = (new MinterTxDataEditCandidate({
pubKey: toBuffer('Mpf9e036839a29f7fba2d5394bd489eda927ccb95acc99e506e688e4888082b3a3'),
rewardAddress: toBuffer('Mx7633980c000139dd3bd24a3f54e06474fa941e16'),
ownerAddress: toBuffer('Mx7633980c000139dd3bd24a3f54e06474fa941e16'),
})).serialize();

expect(decodeToArray(serializedTxData))
.toEqual([
[249, 224, 54, 131, 154, 41, 247, 251, 162, 213, 57, 75, 212, 137, 237, 169, 39, 204, 185, 90, 204, 153, 229, 6, 230, 136, 228, 136, 128, 130, 179, 163],
[118, 51, 152, 12, 0, 1, 57, 221, 59, 210, 74, 63, 84, 224, 100, 116, 250, 148, 30, 22],
[118, 51, 152, 12, 0, 1, 57, 221, 59, 210, 74, 63, 84, 224, 100, 116, 250, 148, 30, 22],
]);
});
});

0 comments on commit 7ea79e2

Please sign in to comment.