From 80b5ae057560a125370053b19d2262ae98ffeb74 Mon Sep 17 00:00:00 2001 From: liu9293 Date: Sun, 18 Dec 2022 12:17:30 +0800 Subject: [PATCH] add create repo in git3 command line --- src/git3/abi.js | 3 +++ src/git3/index.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/git3/abi.js diff --git a/src/git3/abi.js b/src/git3/abi.js new file mode 100644 index 0000000..72f823d --- /dev/null +++ b/src/git3/abi.js @@ -0,0 +1,3 @@ +export default { + "ETHStorage": '[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"chunkId","type":"uint256"}],"name":"chunkStakeTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"name","type":"bytes"}],"name":"countChunks","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"}],"name":"createRepo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"name","type":"bytes"}],"name":"delRef","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"download","outputs":[{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isOptimize","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"}],"name":"listRefs","outputs":[{"components":[{"internalType":"bytes20","name":"hash","type":"bytes20"},{"internalType":"bytes","name":"name","type":"bytes"}],"internalType":"struct Git3.refData[]","name":"list","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"nameToRefInfo","outputs":[{"internalType":"bytes20","name":"hash","type":"bytes20"},{"internalType":"uint96","name":"index","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"remove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"repoNameToOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"repoNameToRefs","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"name","type":"bytes"},{"internalType":"bytes20","name":"refHash","type":"bytes20"}],"name":"setRef","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"name","type":"bytes"}],"name":"size","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"stakeTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upload","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"chunkId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uploadChunk","outputs":[],"stateMutability":"payable","type":"function"}]' +} \ No newline at end of file diff --git a/src/git3/index.js b/src/git3/index.js index a2c1100..23556eb 100644 --- a/src/git3/index.js +++ b/src/git3/index.js @@ -5,6 +5,7 @@ import bip39 from 'bip39' import inquirer from 'inquirer' import parse from 'parse-git-config' import { importActions, generateActions } from './actions.js' +import abis from './abi.js' const program = new Command() program @@ -121,6 +122,41 @@ program.command('delete') }) }) +program.command('create') + .argument('[wallet]', 'wallet to use', 'default') + .argument('[repo]', 'repo name to create') + .description('create a new repo') + .action((wallet, repo) => { + + const keyPath = process.env.HOME + "/.git3/keys" + mkdirSync(keyPath, { recursive: true }) + const content = readFileSync(`${keyPath}/${wallet}`).toString() + + const [walletType, key] = content.split('\n') + const provider = new ethers.providers.JsonRpcProvider('https://galileo.web3q.io:8545'); + + let etherWallet = walletType === 'privateKey' + ? new ethers.Wallet(key) + : ethers.Wallet.fromMnemonic(key) + + etherWallet = etherWallet.connect(provider) + const contract = new ethers.Contract( + '0x0068bD3ec8D16402690C1Eddff06ACb913A209ef', + abis.ETHStorage, + etherWallet, { + gasLimit: 10000000000 + }) + + + contract.repoNameToOwner(Buffer.from(repo)) + .then(res => { console.log(res) }) + .catch(err => { console.error(err) }) + contract.createRepo(Buffer.from(repo)) + .then(res => { console.log(res) }) + .catch(err => { console.error(err) }) + + }) + program.command('info') .argument('[wallet]', 'wallet you want to get info', 'default') .description('get info of a wallet')