Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalin committed Aug 1, 2022
1 parent f774bba commit 1dca323
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 147 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ You will see the updated parachainBond in the apps (chain state) if connecting t
It is possible to proxy transaction by using:
`npm run cli voteCouncil -- --network <network> --ws <ws> <address> --proxied-account <proxied-address> [--proxy-type <Any|Governance|...>]`

* proxied-account: The account that is **proxied**
* proxy-type: The type of proxy (default: null, will use the first proxy account matching)
- proxied-account: The account that is **proxied**
- proxy-type: The type of proxy (default: null, will use the first proxy account matching)

### Specific Actions

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli-ts-signer",
"version": "1.0.1",
"version": "1.1.0",
"description": "ts based signer for moonbeam",
"main": "index.js",
"repository": "[email protected]:PureStake/cli-ts-signer.git",
Expand Down
59 changes: 29 additions & 30 deletions src/commands/commonArgs.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@

import { authorizedChains } from "../methods/utils";
import { TxWrapperArgs } from "./types";

export const commonWrapperArgs = {
sudo: {
describe: "activates sudo mode",
type: "boolean" as "boolean",
default: false,
demandOption: false,
},
"proxied-account": {
describe: "address of the proxied account",
type: "string" as "string",
},
"proxy-type": {
describe: "Type of proxy",
type: "string" as "string",
},
sudo: {
describe: "activates sudo mode",
type: "boolean" as "boolean",
default: false,
demandOption: false,
},
"proxied-account": {
describe: "address of the proxied account",
type: "string" as "string",
},
"proxy-type": {
describe: "Type of proxy",
type: "string" as "string",
},
};

export const commonNetworkArgs = {
network: {
describe: "the network on which you want to send the tx",
type: "string" as "string",
choices: authorizedChains,
demandOption: true,
},
ws: {
describe: "websocket address of the endpoint on which to connect",
type: "string" as "string",
demandOption: true,
}
}
network: {
describe: "the network on which you want to send the tx",
type: "string" as "string",
choices: authorizedChains,
demandOption: true,
},
ws: {
describe: "websocket address of the endpoint on which to connect",
type: "string" as "string",
demandOption: true,
},
};

export const commonArgs = {
...commonWrapperArgs,
...commonNetworkArgs
}
...commonWrapperArgs,
...commonNetworkArgs,
};
12 changes: 7 additions & 5 deletions src/commands/createAndSendCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createAndSendTxCommand = {
builder: (yargs: Argv) => {
return yargs.options({
...commonArgs,
...createTxOptions
...createTxOptions,
});
},
handler: async (argv: CreateAndSendArgs & NetworkArgs & TxWrapperArgs) => {
Expand Down Expand Up @@ -80,10 +80,12 @@ export const createAndSendTxCommand = {
},
{
sudo: argv.sudo,
proxy: argv["proxied-account"] ? {
account: argv["proxied-account"],
type: argv["proxy-type"]
} : undefined
proxy: argv["proxied-account"]
? {
account: argv["proxied-account"],
type: argv["proxy-type"],
}
: undefined,
},
{ ws: argv.ws, network: argv.network }
);
Expand Down
9 changes: 7 additions & 2 deletions src/commands/getTransactionDataCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getTransactionDataCommand = {
builder: (yargs: Argv) => {
return yargs.options({
...commonNetworkArgs,
...createTxOptions
...createTxOptions,
});
},
handler: async (argv: CreateAndSendArgs & NetworkArgs & TxWrapperArgs) => {
Expand All @@ -36,7 +36,12 @@ export const getTransactionDataCommand = {
}
return await getTransactionData(
{ tx: argv.tx, params: JSON.parse(argv.params), address: argv.address },
{ sudo: argv.sudo, proxy: argv["proxied-account"] ? { account: argv["proxied-account"], type: argv["proxy-type"] } : undefined },
{
sudo: argv.sudo,
proxy: argv["proxied-account"]
? { account: argv["proxied-account"], type: argv["proxy-type"] }
: undefined,
},
{ ws: argv.ws, network: argv.network }
);
},
Expand Down
1 change: 0 additions & 1 deletion src/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface VoteCouncilArgs {

export type TxParam = boolean | string | number | { [key: string]: any };


// Methods args
export interface TxArgs {
nonce?: number;
Expand Down
22 changes: 14 additions & 8 deletions src/commands/voteCouncilCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const voteCouncilCommand = {
builder: (yargs: Argv) => {
return yargs.options({
...commonArgs,
...specificTxArgs
...specificTxArgs,
});
},
handler: async (argv: VoteCouncilArgs & NetworkArgs & TxWrapperArgs) => {
Expand All @@ -34,13 +34,19 @@ export const voteCouncilCommand = {
console.log(`Missing network`);
return;
}
await voteCouncilPrompt(argv.address, {
sudo: argv.sudo,
proxy: argv["proxied-account"] ? {
account: argv["proxied-account"],
type: argv["proxy-type"]
} : undefined
}, { ws: argv.ws, network: argv.network });
await voteCouncilPrompt(
argv.address,
{
sudo: argv.sudo,
proxy: argv["proxied-account"]
? {
account: argv["proxied-account"],
type: argv["proxy-type"],
}
: undefined,
},
{ ws: argv.ws, network: argv.network }
);
exit();
},
};
22 changes: 14 additions & 8 deletions src/commands/voteTechCommitteeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const voteTechCommitteeCommand = {
builder: (yargs: Argv) => {
return yargs.options({
...commonArgs,
...specificTxArgs
...specificTxArgs,
});
},
handler: async (argv: VoteCouncilArgs & NetworkArgs & TxWrapperArgs) => {
Expand All @@ -27,13 +27,19 @@ export const voteTechCommitteeCommand = {
console.log(`Missing network`);
return;
}
await voteTechCommitteePrompt(argv.address, {
sudo: argv.sudo,
proxy: argv["proxied-account"] ? {
account: argv["proxied-account"],
type: argv["proxy-type"]
} : undefined
}, { ws: argv.ws, network: argv.network });
await voteTechCommitteePrompt(
argv.address,
{
sudo: argv.sudo,
proxy: argv["proxied-account"]
? {
account: argv["proxied-account"],
type: argv["proxy-type"],
}
: undefined,
},
{ ws: argv.ws, network: argv.network }
);
exit();
},
};
37 changes: 23 additions & 14 deletions src/methods/createAndSendTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ISubmittableResult, SignerPayloadJSON } from "@polkadot/types/types";
import prompts from "prompts";
import Keyring from "@polkadot/keyring";
import { blake2AsHex } from "@polkadot/util-crypto";
import chalk from "chalk"
import chalk from "chalk";

import { moonbeamChains } from "./utils";
import { SignerResult, SubmittableExtrinsic } from "@polkadot/api/types";
Expand All @@ -18,7 +18,7 @@ export async function createAndSendTx(
signatureFunction: (payload: string) => Promise<`0x${string}`>
) {
const { tx, params, address, nonce } = txOpt;
const { sudo, proxy } = txWrapperOpt
const { sudo, proxy } = txWrapperOpt;
const { ws, network } = networkOpt;
const [sectionName, methodName] = tx.split(".");

Expand All @@ -33,21 +33,26 @@ export async function createAndSendTx(
provider: new WsProvider(ws),
});
}
let txExtrinsic: SubmittableExtrinsic<"promise", ISubmittableResult> = api.tx[sectionName][methodName](...params);
let txExtrinsic: SubmittableExtrinsic<"promise", ISubmittableResult> = api.tx[sectionName][
methodName
](...params);
if (sudo) {
txExtrinsic = api.tx.sudo.sudo(txExtrinsic);
}
if (proxy && proxy.account) {
txExtrinsic = api.tx.proxy.proxy(
proxy.account,
proxy.type || null,
txExtrinsic);
txExtrinsic = api.tx.proxy.proxy(proxy.account, proxy.type || null, txExtrinsic);
}
txExtrinsic = await txExtrinsic;

// explicit display of name, args
const { method: { args, method, section } } = txExtrinsic;
console.log(`Transaction created:\n${chalk.red(`${section}.${method}`)}(${chalk.green(`${args.map((a) => a.toString().slice(0, 200)).join(chalk.white(', '))}`)})\n`);
const {
method: { args, method, section },
} = txExtrinsic;
console.log(
`Transaction created:\n${chalk.red(`${section}.${method}`)}(${chalk.green(
`${args.map((a) => a.toString().slice(0, 200)).join(chalk.white(", "))}`
)})\n`
);

const signer = {
signPayload: (payload: SignerPayloadJSON) => {
Expand Down Expand Up @@ -81,16 +86,16 @@ export async function createAndSendTx(

if (status.isInBlock) {
console.log("Included at block hash", status.asInBlock.toHex());
console.log('Events: ');
console.log("Events: ");
events.forEach(({ event: { data, method, section } }) => {
const [error] = data as any[];
if (error?.isModule) {
const { docs, name, section } = api.registry.findMetaError(error.asModule);
console.log('\t', `${chalk.red(`${section}.${name}`)}`, `${docs}`);
console.log("\t", `${chalk.red(`${section}.${name}`)}`, `${docs}`);
} else if (section == "system" && method == "ExtrinsicSuccess") {
console.log('\t', chalk.green(`${section}.${method}`), data.toString());
console.log("\t", chalk.green(`${section}.${method}`), data.toString());
} else {
console.log('\t', `${section}.${method}`, data.toString());
console.log("\t", `${section}.${method}`, data.toString());
}
});
resolve();
Expand All @@ -105,7 +110,11 @@ export async function createAndSendTx(
});
}

export async function createAndSendTxPrompt(txOpt: TxOpt, txWrapperOpt: TxWrapperOpt, networkOpt: NetworkOpt) {
export async function createAndSendTxPrompt(
txOpt: TxOpt,
txWrapperOpt: TxWrapperOpt,
networkOpt: NetworkOpt
) {
return createAndSendTx(txOpt, txWrapperOpt, networkOpt, async (payload: string) => {
const response = await prompts({
type: "text",
Expand Down
6 changes: 5 additions & 1 deletion src/methods/getTransactionData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createAndSendTx } from "./createAndSendTx";
import { NetworkOpt, TxOpt, TxWrapperOpt } from "./types";

export async function getTransactionData(txOpt: TxOpt, txWrapperOpt: TxWrapperOpt, networkOpt: NetworkOpt) {
export async function getTransactionData(
txOpt: TxOpt,
txWrapperOpt: TxWrapperOpt,
networkOpt: NetworkOpt
) {
return createAndSendTx(
txOpt,
txWrapperOpt,
Expand Down
Loading

0 comments on commit 1dca323

Please sign in to comment.