Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Added 0.9.6.2 finalization points (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarcia360 authored Jun 30, 2020
1 parent 8524c3e commit 8da61f7
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 39 deletions.
51 changes: 25 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prompts": "^2.1.0",
"rxjs": "^6.5.3",
"symbol-hd-wallets": "^0.11.0",
"symbol-sdk": "^0.20.2",
"symbol-sdk": "^0.20.4",
"symbol-uri-scheme": "^0.4.6",
"update-notifier": "^4.1.0"
},
Expand Down
24 changes: 23 additions & 1 deletion src/commands/transaction/votingkeylink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AnnounceTransactionsCommand } from '../../interfaces/announce.transacti
import { AnnounceTransactionsOptions } from '../../interfaces/announce.transactions.options';
import { LinkActionResolver } from '../../resolvers/action.resolver';
import { BLSPublicKeyResolver } from '../../resolvers/bls.resolver';
import { FinalizationPointResolver } from '../../resolvers/finalizationPoint.resolver';
import { MaxFeeResolver } from '../../resolvers/maxFee.resolver';
import { PasswordResolver } from '../../resolvers/password.resolver';
import { TransactionSignatureOptions } from '../../services/transaction.signature.service';
Expand All @@ -33,6 +34,16 @@ export class CommandOptions extends AnnounceTransactionsOptions {
})
linkedPublicKey: string;

@option({
description: 'Start Point.',
})
startPoint: string;

@option({
description: 'End Point.',
})
endPoint: string;

@option({
flag: 'a',
description: 'Alias action (Link, Unlink).',
Expand All @@ -58,7 +69,18 @@ export default class extends AnnounceTransactionsCommand {
const maxFee = await new MaxFeeResolver().resolve(options);
const multisigSigner = await this.getMultisigSigner(options);

const transaction = VotingKeyLinkTransaction.create(Deadline.create(), linkedPublicKey, action, profile.networkType, maxFee);
const startPoint = await new FinalizationPointResolver().resolve(options, 'Enter the start point:', 'startPoint');
const endPoint = await new FinalizationPointResolver().resolve(options, 'Enter the end point:', 'endPoint');

const transaction = VotingKeyLinkTransaction.create(
Deadline.create(),
linkedPublicKey,
startPoint,
endPoint,
action,
profile.networkType,
maxFee,
);

const signatureOptions: TransactionSignatureOptions = {
account,
Expand Down
10 changes: 5 additions & 5 deletions src/resolvers/blockOrderBy.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/
import { Options } from 'clime';
import { BlockOrderByEnum } from 'symbol-openapi-typescript-node-client';
import { BlockOrderBy } from 'symbol-sdk';

import { OptionsChoiceResolver } from '../options-resolver';
import { BlockOrderByValidator } from '../validators/blockOrderBy.validator';
Expand All @@ -31,17 +31,17 @@ export class BlockOrderByResolver implements Resolver {
* @param {Options} options - Command options.
* @param {string} altText - Alternative text.
* @param {string} altKey - Alternative key.
* @returns {Promise<BlockOrderByEnum>}
* @returns {Promise<BlockOrderBy>}
*/
async resolve(options: Options, altText?: string, altKey?: string): Promise<BlockOrderByEnum> {
async resolve(options: Options, altText?: string, altKey?: string): Promise<BlockOrderBy> {
const choices = [
{
title: 'Height',
value: BlockOrderByEnum.Height,
value: BlockOrderBy.Height,
},
{
title: 'Id',
value: BlockOrderByEnum.Id,
value: BlockOrderBy.Id,
},
];
const value = await OptionsChoiceResolver(
Expand Down
44 changes: 44 additions & 0 deletions src/resolvers/finalizationPoint.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
* Copyright 2018-present NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { Options } from 'clime';
import { UInt64 } from 'symbol-sdk';

import { OptionsResolver } from '../options-resolver';
import { FinalizationPointValidator } from '../validators/finalizationPoint.validator';
import { Resolver } from './resolver';

export class FinalizationPointResolver implements Resolver {
/**
* Resolves a finalization point provided by user.
* @param {Options} options - Command options.
* @param {string} altText - Alternative text.
* @param {string} altKey - Alternative key.
* @returns {Promise<UInt64>}
*/
async resolve(options: Options, altText?: string, altKey?: string): Promise<UInt64> {
const resolution = await OptionsResolver(
options,
altKey ? altKey : 'point',
() => undefined,
altText ? altText : 'Enter a finalization point:',
'text',
new FinalizationPointValidator(),
);
return UInt64.fromNumericString(resolution);
}
}
2 changes: 1 addition & 1 deletion src/resolvers/order.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/
import { Options } from 'clime';
import { Order } from 'symbol-openapi-typescript-node-client';
import { Order } from 'symbol-sdk';

import { OptionsChoiceResolver } from '../options-resolver';
import { OrderValidator } from '../validators/order.validator';
Expand Down
6 changes: 3 additions & 3 deletions src/validators/blockOrderBy.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
*
*/
import { Validator } from 'clime';
import { BlockOrderByEnum } from 'symbol-openapi-typescript-node-client';
import { BlockOrderBy } from 'symbol-sdk';

/**
* Validator of block order by
*/
export class BlockOrderByValidator implements Validator<string> {
/**
* Validates if a block order by value is valid.
* @param {string} value - Transaction group.
* @param {string} value
* @returns {true | string}
*/
validate(value: string): boolean | string {
const test = value in BlockOrderByEnum;
const test = value in BlockOrderBy;
return test ? true : 'BlockOrderBy must be one of (Id, Height)';
}
}
38 changes: 38 additions & 0 deletions src/validators/finalizationPoint.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* Copyright 2018-present NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { Validator } from 'clime';
import { UInt64 } from 'symbol-sdk';

/**
* Finalization point validator
*/
export class FinalizationPointValidator implements Validator<string> {
/**
* validates if a point is valid.
* @param {string} value.
* @returns {true | string}
*/
validate(value: string): boolean | string {
try {
UInt64.fromNumericString(value);
} catch (err) {
return 'Finalization point must be an integer';
}
return true;
}
}
2 changes: 1 addition & 1 deletion src/validators/order.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

import { Order } from 'symbol-openapi-typescript-node-client';
import { Order } from 'symbol-sdk';

import { Validator } from './validator';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class VotingKeyLinkView {
return {
['Action']: LinkAction[tx.linkAction],
['Linked key']: tx.linkedPublicKey,
['Start point']: tx.startPoint.toString(),
['End point']: tx.endPoint.toString(),
};
}
}
4 changes: 3 additions & 1 deletion test/mocks/transactions/votingKeyLink.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*
*/

import { Deadline, LinkAction, NetworkType, VotingKeyLinkTransaction } from 'symbol-sdk';
import { Deadline, LinkAction, NetworkType, UInt64, VotingKeyLinkTransaction } from 'symbol-sdk';

export const unsignedVotingKeyLink1 = VotingKeyLinkTransaction.create(
Deadline.create(),
'0'.repeat(96),
UInt64.fromUint(1),
UInt64.fromUint(2),
LinkAction.Link,
NetworkType.MIJIN_TEST,
);
35 changes: 35 additions & 0 deletions test/resolvers/finalizationPoint.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright 2018-present NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { expect } from 'chai';

import { FinalizationPointResolver } from '../../src/resolvers/finalizationPoint.resolver';

describe('Finalization point resolver', () => {
it('should return point', async () => {
const point = '15';
const options = { point } as any;
expect((await new FinalizationPointResolver().resolve(options)).toString()).to.be.equal(point);
});

it('should change key', async () => {
const key = '16';
const options = { key } as any;
expect((await new FinalizationPointResolver().resolve(options, 'altText', 'key')).toString()).to.be.equal(key);
});
});
Loading

0 comments on commit 8da61f7

Please sign in to comment.