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

Commit

Permalink
Added demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarcia360 committed Dec 28, 2019
1 parent cbc973c commit b9c039f
Show file tree
Hide file tree
Showing 47 changed files with 603 additions and 358 deletions.
10 changes: 0 additions & 10 deletions src/account.transactions.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ export abstract class AccountTransactionsCommand extends ProfileCommand {
super();
this.transactionService = new TransactionService();
}

/**
* Creates an account repository given a profile.
* @param {ProfileOptions} options.
* @returns {AccountHttp}
*/
public getAccountHttp(options: ProfileOptions): AccountHttp {
const profile = this.getProfile(options);
return new AccountHttp(profile.url);
}
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/commands/account/aggregatebonded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata} from 'clime';
import {AccountHttp} from 'nem2-sdk';
import {AccountTransactionsCommand, AccountTransactionsOptions} from '../../account.transactions.command';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Fetch aggregate bonded transactions from account',
Expand All @@ -31,9 +33,9 @@ export default class extends AccountTransactionsCommand {
@metadata
execute(options: AccountTransactionsOptions) {
this.spinner.start();

const address = this.getAddress(options);
const accountHttp = this.getAccountHttp(options);
const profile = this.getProfile(options);
const accountHttp = new AccountHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

accountHttp.getAccountPartialTransactions(address, options.getQueryParams())
.subscribe((transactions) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/account/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class extends Command {
const networkType = options.getNetwork(OptionsResolver(options,
'network',
() => undefined,
'Enter a network type (MIJIN_TEST, MIJIN, MAIN_NET, TEST_NET): '));
'Enter a network type: '));

const profile = options.profile || readlineSync.question('Insert the profile name: ');
profile.trim();
Expand Down
13 changes: 7 additions & 6 deletions src/commands/account/incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*
*/
import chalk from 'chalk';
import { command, metadata } from 'clime';
import { AccountHttp, PublicAccount } from 'nem2-sdk';
import { AccountTransactionsCommand, AccountTransactionsOptions } from '../../account.transactions.command';
import { OptionsResolver } from '../../options-resolver';
import {command, metadata} from 'clime';
import {AccountHttp} from 'nem2-sdk';
import {AccountTransactionsCommand, AccountTransactionsOptions} from '../../account.transactions.command';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Fetch incoming transactions from account',
Expand All @@ -34,8 +34,9 @@ export default class extends AccountTransactionsCommand {
execute(options: AccountTransactionsOptions) {
this.spinner.start();

const address = this.getAddress(options);
const accountHttp = this.getAccountHttp(options);
const profile = this.getProfile(options);
const accountHttp = new AccountHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

accountHttp.getAccountIncomingTransactions(address, options.getQueryParams())
.subscribe((transactions) => {
Expand Down
10 changes: 2 additions & 8 deletions src/commands/account/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {
} from 'nem2-sdk';
import {forkJoin, of} from 'rxjs';
import {catchError, mergeMap, toArray} from 'rxjs/operators';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {AddressValidator} from '../../validators/address.validator';
import {AddressResolver} from '../../resolvers/address.resolver';

export class CommandOptions extends ProfileOptions {
@option({
Expand Down Expand Up @@ -171,17 +171,11 @@ export default class extends ProfileCommand {
this.spinner.start();

const profile = this.getProfile(options);

const address: Address = Address.createFromRawAddress(
OptionsResolver(options,
'address',
() => profile.address.plain(),
'Enter the address: '));

const accountHttp = new AccountHttp(profile.url);
const multisigHttp = new MultisigHttp(profile.url);
const mosaicHttp = new MosaicHttp(profile.url);
const mosaicService = new MosaicService(accountHttp, mosaicHttp);
const address = new AddressResolver().resolve(options, profile);

forkJoin(
accountHttp.getAccountInfo(address),
Expand Down
9 changes: 5 additions & 4 deletions src/commands/account/outgoing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata} from 'clime';
import {AccountHttp, PublicAccount} from 'nem2-sdk';
import {AccountHttp} from 'nem2-sdk';
import {AccountTransactionsCommand, AccountTransactionsOptions} from '../../account.transactions.command';
import {OptionsResolver} from '../../options-resolver';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Fetch outgoing transactions from account',
Expand All @@ -34,8 +34,9 @@ export default class extends AccountTransactionsCommand {
execute(options: AccountTransactionsOptions) {
this.spinner.start();

const address = this.getAddress(options);
const accountHttp = this.getAccountHttp(options);
const profile = this.getProfile(options);
const accountHttp = new AccountHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

accountHttp.getAccountOutgoingTransactions(address, options.getQueryParams())
.subscribe((transactions) => {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/account/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata} from 'clime';
import {AccountHttp, PublicAccount} from 'nem2-sdk';
import {AccountHttp} from 'nem2-sdk';
import {AccountTransactionsCommand, AccountTransactionsOptions} from '../../account.transactions.command';
import {OptionsResolver} from '../../options-resolver';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Fetch transactions from account',
Expand All @@ -34,8 +34,9 @@ export default class extends AccountTransactionsCommand {
execute(options: AccountTransactionsOptions) {
this.spinner.start();

const address = this.getAddress(options);
const accountHttp = this.getAccountHttp(options);
const profile = this.getProfile(options);
const accountHttp = new AccountHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

accountHttp.getAccountTransactions(address, options.getQueryParams())
.subscribe((transactions) => {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/account/unconfirmed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata} from 'clime';
import {AccountHttp, PublicAccount} from 'nem2-sdk';
import {AccountHttp} from 'nem2-sdk';
import {AccountTransactionsCommand, AccountTransactionsOptions} from '../../account.transactions.command';
import {OptionsResolver} from '../../options-resolver';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Fetch unconfirmed transactions from account',
Expand All @@ -34,8 +34,9 @@ export default class extends AccountTransactionsCommand {
execute(options: AccountTransactionsOptions) {
this.spinner.start();

const address = this.getAddress(options);
const accountHttp = this.getAccountHttp(options);
const profile = this.getProfile(options);
const accountHttp = new AccountHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

accountHttp.getAccountUnconfirmedTransactions(address, options.getQueryParams())
.subscribe((transactions) => {
Expand Down
9 changes: 3 additions & 6 deletions src/commands/block/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import * as Table from 'cli-table3';
import {HorizontalTable} from 'cli-table3';
import {command, metadata, option} from 'clime';
import {BlockHttp, BlockInfo, NetworkType} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {HeightResolver} from '../../resolvers/height.resolver';
import {HeightValidator} from '../../validators/block.validator';

export class CommandOptions extends ProfileOptions {
Expand Down Expand Up @@ -84,15 +84,12 @@ export default class extends ProfileCommand {

@metadata
execute(options: CommandOptions) {
options.height = OptionsResolver(options,
'height',
() => undefined,
'Enter the block height: ');
this.spinner.start();
const profile = this.getProfile(options);
const blockHttp = new BlockHttp(profile.url);
const height = new HeightResolver().resolve(options);

blockHttp.getBlockByHeight(options.height)
blockHttp.getBlockByHeight(height)
.subscribe((blockInfo) => {
this.spinner.stop(true);
console.log(new BlockHeaderTable(blockInfo).toString());
Expand Down
13 changes: 4 additions & 9 deletions src/commands/block/receipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata, option} from 'clime';
import {BlockHttp, ReceiptHttp} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ReceiptHttp} from 'nem2-sdk';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {HeightResolver} from '../../resolvers/height.resolver';
import {ReceiptService} from '../../service/receipt.service';
import {HeightValidator} from '../../validators/block.validator';

Expand All @@ -45,16 +45,11 @@ export default class extends ProfileCommand {

@metadata
execute(options: CommandOptions) {
options.height = OptionsResolver(options,
'height',
() => undefined,
'Enter the block height: ');

this.spinner.start();
const profile = this.getProfile(options);
const receiptHttp = new ReceiptHttp(profile.url);

receiptHttp.getBlockReceipts(options.height)
const height = new HeightResolver().resolve(options);
receiptHttp.getBlockReceipts(height)
.subscribe((statement: any) => {
this.spinner.stop(true);
let txt = '';
Expand Down
16 changes: 6 additions & 10 deletions src/commands/block/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import chalk from 'chalk';
import {command, metadata, option} from 'clime';
import {BlockHttp, Order, QueryParams} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {TransactionService} from '../../service/transaction.service';
import {HeightValidator} from '../../validators/block.validator';
import {HeightResolver} from '../../resolvers/height.resolver';

export class CommandOptions extends ProfileOptions {
@option({
Expand Down Expand Up @@ -65,10 +65,10 @@ export default class extends ProfileCommand {
@metadata
execute(options: CommandOptions) {

options.height = OptionsResolver(options,
'height',
() => undefined,
'Enter the block height: ');
this.spinner.start();
const profile = this.getProfile(options);
const blockHttp = new BlockHttp(profile.url);
const height = new HeightResolver().resolve(options);

let pageSize = options.pageSize || 10;
if (pageSize < 10) {
Expand All @@ -84,11 +84,7 @@ export default class extends ProfileCommand {
order = 'DESC';
}

this.spinner.start();
const profile = this.getProfile(options);
const blockHttp = new BlockHttp(profile.url);

blockHttp.getBlockTransactions(options.height, new QueryParams(pageSize, id, order === 'ASC' ? Order.ASC : Order.DESC))
blockHttp.getBlockTransactions(height, new QueryParams(pageSize, id, order === 'ASC' ? Order.ASC : Order.DESC))
.subscribe((transactions: any) => {
this.spinner.stop(true);
let txt = '\n';
Expand Down
14 changes: 4 additions & 10 deletions src/commands/metadata/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import chalk from 'chalk';
import * as Table from 'cli-table3';
import {HorizontalTable} from 'cli-table3';
import {command, metadata, option} from 'clime';
import {Address, Metadata, MetadataEntry, MetadataHttp} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {Metadata, MetadataEntry, MetadataHttp} from 'nem2-sdk';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {AddressResolver} from '../../resolvers/address.resolver';
import {AddressValidator} from '../../validators/address.validator';

export class CommandOptions extends ProfileOptions {
Expand Down Expand Up @@ -73,15 +73,9 @@ export default class extends ProfileCommand {
execute(options: CommandOptions) {
this.spinner.start();
const profile = this.getProfile(options);

options.address = OptionsResolver(options,
'address',
() => profile.address.plain(),
'Enter an address: ');

const address = Address.createFromRawAddress(options.address);

const metadataHttp = new MetadataHttp(profile.url);
const address = new AddressResolver().resolve(options, profile);

metadataHttp.getAccountMetadata(address)
.subscribe((metadataEntries) => {
this.spinner.stop(true);
Expand Down
13 changes: 4 additions & 9 deletions src/commands/metadata/mosaic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
import chalk from 'chalk';
import {command, metadata, option} from 'clime';
import {Metadata, MetadataHttp, MosaicId} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {Metadata, MetadataHttp} from 'nem2-sdk';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {MosaicIdResolver} from '../../resolvers/mosaic.resolver';
import {MosaicIdValidator} from '../../validators/mosaicId.validator';
import {MetadataEntryTable} from './account';

Expand All @@ -45,14 +45,9 @@ export default class extends ProfileCommand {
execute(options: CommandOptions) {
this.spinner.start();
const profile = this.getProfile(options);

options.mosaicId = OptionsResolver(options,
'mosaicId',
() => undefined,
'Enter the mosaic id in hexadecimal format: ');
const mosaicId = new MosaicId(options.mosaicId);

const metadataHttp = new MetadataHttp(profile.url);
const mosaicId = new MosaicIdResolver().resolve(options);

metadataHttp.getMosaicMetadata(mosaicId)
.subscribe((metadataEntries) => {
this.spinner.stop(true);
Expand Down
10 changes: 3 additions & 7 deletions src/commands/metadata/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {Metadata, MetadataHttp, NamespaceId} from 'nem2-sdk';
import {OptionsResolver} from '../../options-resolver';
import {ProfileCommand, ProfileOptions} from '../../profile.command';
import {MetadataEntryTable} from './account';
import {NamespaceNameResolver} from '../../resolvers/namespace.resolver';

export class CommandOptions extends ProfileOptions {
@option({
Expand All @@ -43,14 +44,9 @@ export default class extends ProfileCommand {
execute(options: CommandOptions) {
this.spinner.start();
const profile = this.getProfile(options);

options.namespaceName = OptionsResolver(options,
'namespaceId',
() => undefined,
'Enter the namespace name: ');
const namespaceId = new NamespaceId(options.namespaceName);

const metadataHttp = new MetadataHttp(profile.url);
const namespaceId = new NamespaceNameResolver().resolve(options);

metadataHttp.getNamespaceMetadata(namespaceId)
.subscribe((metadataEntries) => {
this.spinner.stop(true);
Expand Down
9 changes: 2 additions & 7 deletions src/commands/monitor/aggregatebonded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {command, metadata} from 'clime';
import {Address, Listener} from 'nem2-sdk';
import {MonitorAddressCommand, MonitorAddressOptions} from '../../monitor.transaction.command';
import {OptionsResolver} from '../../options-resolver';
import {AddressResolver} from '../../resolvers/address.resolver';

@command({
description: 'Monitor aggregate bonded transactions added',
Expand All @@ -33,14 +34,8 @@ export default class extends MonitorAddressCommand {
@metadata
execute(options: MonitorAddressOptions) {
const profile = this.getProfile(options);

const address = Address.createFromRawAddress(
OptionsResolver(options,
'address',
() => profile.address.plain(),
'Enter the address: '));

const listener = new Listener(profile.url);
const address = new AddressResolver().resolve(options, profile);

console.log(chalk.green('Monitoring ') + `${address.pretty()} using ${profile.url}`);

Expand Down
1 change: 0 additions & 1 deletion src/commands/monitor/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default class extends ProfileCommand {
@metadata
execute(options: ProfileOptions) {
const profile = this.getProfile(options);

const listener = new Listener(profile.url);

console.log(`Using ${profile.url}`);
Expand Down

0 comments on commit b9c039f

Please sign in to comment.