From b59c2ab7d9db489c61b9e8746e83e3b7e3dd96f3 Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Wed, 1 Mar 2023 12:47:04 +0800 Subject: [PATCH] add --- src/git3/actions.ts | 13 ++++++++ src/git3/index.ts | 73 ++++++++++++++++++++++++++++++++------------- 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/git3/actions.ts b/src/git3/actions.ts index 8fde65e..e92adf3 100644 --- a/src/git3/actions.ts +++ b/src/git3/actions.ts @@ -65,4 +65,17 @@ export const HubMemberActions = [ 'manager', ], }, +] + +export const HubGetMemberActions = [ + { + type: 'list', + name: 'role', + message: 'get members corresponding to the role', + choices: [ + 'admin', + 'contribotor', + 'manager', + ], + }, ] \ No newline at end of file diff --git a/src/git3/index.ts b/src/git3/index.ts index 6f52e52..63b6c43 100644 --- a/src/git3/index.ts +++ b/src/git3/index.ts @@ -3,7 +3,7 @@ import { ethers } from "ethers" import { Command } from "commander" import bip39 from "bip39" import inquirer from "inquirer" -import { importActions, generateActions,createHubActions,HubMemberActions } from "./actions.js" +import { importActions, generateActions,createHubActions,HubMemberActions,HubGetMemberActions } from "./actions.js" import network from "../config/evm-network.js" import { explorerTxUrl, getWallet, randomRPC } from "../common/wallet.js" import { initFactoryByChainID, parseGit3URI } from "../common/git3-protocol.js" @@ -165,7 +165,25 @@ wallet } }) +wallet + .command("clear") + .description("clear pending nonce") + .argument("", "ex: default@git3.w3q") + .argument("[num]", "number of pending nonce to clear", 1) + .action(async (uri, num) => { + if (!uri.startsWith("git3://")) { + uri = "git3://" + uri + } + const protocol = await parseGit3URI(uri, { skipRepoName: true }) + const txManager = new TxManager(protocol.hub, protocol.chainId, protocol.netConfig.txConst) + let nonce = await protocol.wallet.getTransactionCount() + console.log(`current nonce: ${nonce}`) + await txManager.clearPendingNonce(num) + nonce = await protocol.wallet.getTransactionCount() + console.log(`current nonce: ${nonce}`) + }) +// =============================Hub Commands=================================== hub .command("create") .argument("", "chain name or chain id") @@ -200,25 +218,6 @@ hub console.log("hub owner:", events[0].args.creator) }) -wallet - .command("clear") - .description("clear pending nonce") - .argument("", "ex: default@git3.w3q") - .argument("[num]", "number of pending nonce to clear", 1) - .action(async (uri, num) => { - if (!uri.startsWith("git3://")) { - uri = "git3://" + uri - } - const protocol = await parseGit3URI(uri, { skipRepoName: true }) - const txManager = new TxManager(protocol.hub, protocol.chainId, protocol.netConfig.txConst) - let nonce = await protocol.wallet.getTransactionCount() - console.log(`current nonce: ${nonce}`) - await txManager.clearPendingNonce(num) - nonce = await protocol.wallet.getTransactionCount() - console.log(`current nonce: ${nonce}`) - }) - -// =============================Hub Commands=================================== hub .command("join") .argument("", "hub_name.NS or hub_address:chain_id") @@ -235,6 +234,40 @@ hub console.log(explorerTxUrl(receipt.transactionHash, protocol.netConfig.explorers)) }) +hub + .command("getMembers") + .argument("", "hub_name.NS or hub_address:chain_id") + .description("get members corresponding to the role from hub") + .action(async (hub) => { + let protocol = await parseGit3URI(hub, { ignoreProtocolHeader: true, skipRepoName: true }) + let answers = await inquirer.prompt(HubGetMemberActions) + let role:string = "0x0000000000000000000000000000000000000000000000000000000000000000"; + switch (answers.role) { + case "admin": + role = "0x0000000000000000000000000000000000000000000000000000000000000000" + case "manager": + role = "0x0000000000000000000000000000000000000000000000000000000000000001" + case "contributor": + role = "0x0000000000000000000000000000000000000000000000000000000000000002" + } + + let members = await protocol.hub.getMembersByRole(role) + console.error(`${answers.role} : ${members}`) + }) + +hub + .command("getAllMembers") + .argument("", "hub_name.NS or hub_address:chain_id") + .description("get all members from hub") + .action(async (hub) => { + let protocol = await parseGit3URI(hub, { ignoreProtocolHeader: true, skipRepoName: true }) + let [admins, managers ,cons] = await protocol.hub.getAllMembers() + console.error(`admins : ${admins}`) + console.error(`managers : ${managers}`) + console.error(`contributors : ${cons}`) + }) + + hub .command("add-member") .argument("", "member address which will be added to the hub")