Skip to content

Commit

Permalink
Adds support for --proxied-account
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalin committed Aug 1, 2022
1 parent 3d9e96c commit b352c24
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 202 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Then, in the two other windows run :

You will see the updated parachainBond in the apps (chain state) if connecting to ws://localhost:34102

### Proxy

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)

### Specific Actions

Some specific actions are provided as a preconfigured feature:
Expand Down
39 changes: 39 additions & 0 deletions src/commands/commonArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

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

export const commonWrapperArgs: {[Property in keyof TxWrapperArgs]: any} = {
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,
}
}

export const commonArgs = {
...commonWrapperArgs,
...commonNetworkArgs
}
36 changes: 14 additions & 22 deletions src/commands/createAndSendCommand.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { Argv } from "yargs";
import { CreateAndSendArgs } from "../methods/types";
import { createAndSendTxPrompt } from "../methods/createAndSendTx";
import { exit } from "../methods/utils";
import { ALITH, authorizedChains, BALTATHAR } from "../methods/utils";
import { commonArgs } from "./commonArgs";
import { CreateAndSendArgs, NetworkArgs, TxWrapperArgs } from "./types";

export const createTxOptions = {
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,
},
address: {
describe: "address of the sender",
type: "string" as "string",
Expand All @@ -31,12 +20,6 @@ export const createTxOptions = {
type: "string" as "string",
demandOption: true,
},
sudo: {
describe: "activates sudo mode",
type: "boolean" as "boolean",
default: false,
demandOption: false,
},
nonce: {
describe: "nonce to use",
type: "number" as "number",
Expand All @@ -54,9 +37,12 @@ export const createAndSendTxCommand = {
command: "createAndSendTx",
describe: "creates a transaction payload, prompts for signature and sends it",
builder: (yargs: Argv) => {
return yargs.options(createTxOptions);
return yargs.options({
...commonArgs,
...createTxOptions
});
},
handler: async (argv: CreateAndSendArgs) => {
handler: async (argv: CreateAndSendArgs & NetworkArgs & TxWrapperArgs) => {
if (!argv["params"]) {
console.log(`Missing params`);
return;
Expand Down Expand Up @@ -90,9 +76,15 @@ export const createAndSendTxCommand = {
tx: argv.tx,
params,
address: argv.address,
sudo: argv.sudo,
immortality: argv.immortality,
},
{
sudo: argv.sudo,
proxy: argv["proxied-account"] ? {
account: argv["proxied-account"],
type: argv["proxy-type"]
} : undefined
},
{ ws: argv.ws, network: argv.network }
);
exit();
Expand Down
14 changes: 9 additions & 5 deletions src/commands/getTransactionDataCommand.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Argv } from "yargs";
import { CreateAndSendArgs } from "../methods/types";
import { getTransactionData } from "../methods/getTransactionData";
import { createTxOptions } from "./createAndSendCommand";
import { checkArgvList } from "../methods/utils";
import { commonNetworkArgs } from "./commonArgs";
import { CreateAndSendArgs, NetworkArgs, TxWrapperArgs } from "./types";

export const getTransactionDataCommand = {
command: "getTransactionData",
description: "creates a transaction payload and resolves",
builder: (yargs: Argv) => {
return yargs.options(createTxOptions);
return yargs.options({
...commonNetworkArgs,
...createTxOptions
});
},
handler: async (argv: CreateAndSendArgs) => {
handler: async (argv: CreateAndSendArgs & NetworkArgs & TxWrapperArgs) => {
if (!argv["params"]) {
console.log(`Missing params`);
return;
Expand All @@ -32,7 +35,8 @@ export const getTransactionDataCommand = {
return;
}
return await getTransactionData(
{ tx: argv.tx, params: JSON.parse(argv.params), address: argv.address, sudo: argv.sudo },
{ 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 },
{ ws: argv.ws, network: argv.network }
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/signCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Argv } from "yargs";
import { SignArgs, SignPromptArgs } from "../methods/types";
import { SignArgs, SignPromptArgs } from "./types";
import { sign } from "../methods/sign";
import { isNetworkType } from "../methods/utils";

Expand Down
2 changes: 1 addition & 1 deletion src/commands/submitTxCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Argv } from "yargs";
import { SendTxArgs } from "../methods/types";
import { SendTxArgs } from "./types";
import { submitPreSignedTx } from "../methods/submitPreSignedTx";

export const submitTxCommand = {
Expand Down
59 changes: 59 additions & 0 deletions src/commands/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Command Args
export interface SignArgs extends SignPromptArgs {
message?: string;
}
export interface SignPromptArgs {
type?: string;
"private-key"?: string;
derivePath: string;
}
export interface VerifyArgs {
message?: string;
signature?: string;
"public-key"?: string;
type?: string;
}
export interface SendTxArgs {
ws?: string;
"tx-data"?: string;
}

export interface CreateAndSendArgs {
address?: string;
tx?: string;
params?: string;
nonce?: number;
immortality: boolean;
}
export interface VoteCouncilArgs {
address?: string;
}

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


// Methods args
export interface TxArgs {
nonce?: number;
tx: string;
params: TxParam[];
address: string;
immortality?: boolean;
}

export interface TxWrapperArgs {
sudo?: boolean;
"proxied-account"?: string;
"proxy-type"?: "Any" | string;
}

export interface NetworkArgs {
ws?: string;
network?: string;
}

export type NetworkType = "ethereum" | "sr25519";

export interface Vote {
yes: boolean;
}
4 changes: 2 additions & 2 deletions src/commands/verifyCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Argv } from "yargs";
import { VerifyArgs } from "../methods/types";
import { VerifyArgs } from "./types";
import { verify } from "../methods/verify";
import { ALITH, isNetworkType } from "../methods/utils";
import { isNetworkType } from "../methods/utils";

export const verifyOptions = {
type: {
Expand Down
32 changes: 15 additions & 17 deletions src/commands/voteCouncilCommand.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { Argv } from "yargs";
import { VoteCouncilArgs } from "../methods/types";
import { exit } from "../methods/utils";
import { ALITH, authorizedChains } from "../methods/utils";
import { voteCouncilPrompt } from "../methods/voteCouncil";
import { commonArgs } from "./commonArgs";
import { NetworkArgs, TxWrapperArgs, VoteCouncilArgs } from "./types";

export const specificTxOptions = {
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 specificTxArgs = {
address: {
describe: "address of the sender",
type: "string" as "string",
Expand All @@ -27,9 +16,12 @@ export const voteCouncilCommand = {
command: "voteCouncil",
describe: "creates a vote council payload, prompts for signature and sends it",
builder: (yargs: Argv) => {
return yargs.options(specificTxOptions);
return yargs.options({
...commonArgs,
...specificTxArgs
});
},
handler: async (argv: VoteCouncilArgs) => {
handler: async (argv: VoteCouncilArgs & NetworkArgs & TxWrapperArgs) => {
if (!argv["address"]) {
console.log(`Missing address`);
return;
Expand All @@ -42,7 +34,13 @@ export const voteCouncilCommand = {
console.log(`Missing network`);
return;
}
await voteCouncilPrompt(argv.address, { 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();
},
};
20 changes: 15 additions & 5 deletions src/commands/voteTechCommitteeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Argv } from "yargs";
import { VoteCouncilArgs } from "../methods/types";
import { voteTechCommitteePrompt } from "../methods/voteTechCommittee";
import { specificTxOptions } from "./voteCouncilCommand";
import { specificTxArgs } from "./voteCouncilCommand";
import { exit } from "../methods/utils";
import { commonArgs } from "./commonArgs";
import { NetworkArgs, TxWrapperArgs, VoteCouncilArgs } from "./types";

export const voteTechCommitteeCommand = {
command: "voteTechCommittee",
describe: "creates a tech committee vote payload, prompts for signature and sends it",
builder: (yargs: Argv) => {
return yargs.options(specificTxOptions);
return yargs.options({
...commonArgs,
...specificTxArgs
});
},
handler: async (argv: VoteCouncilArgs) => {
handler: async (argv: VoteCouncilArgs & NetworkArgs & TxWrapperArgs) => {
if (!argv["address"]) {
console.log(`Missing address`);
return;
Expand All @@ -23,7 +27,13 @@ export const voteTechCommitteeCommand = {
console.log(`Missing network`);
return;
}
await voteTechCommitteePrompt(argv.address, { 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();
},
};
Loading

0 comments on commit b352c24

Please sign in to comment.