Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-t supports text types and can set the number of concurrencies. #15

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 60 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
# ethfs-cli

## Installation
Globally:
### Globally:
```bash
npm install -g ethfs-cli
ethfs-cli upload -f <directory|file> -a <address> -p <private-key> -r [rpc] -t [upload-type]
```

Locally:
Once installed, you can upload file or directory using:
```
ethfs-cli upload -f <directory|file> -a <address> -p <private-key> -c [chain-id] -t [upload-type]
```

### Locally:
```bash
npm install ethfs-cli
npx ethfs-cli upload -f <directory|file> -a <address> -p <private-key> -r [rpc] -t [upload-type]
```

After installation, use npx to run the command:
```
npx ethfs-cli upload -f <directory|file> -a <address> -p <private-key> -c [chain-id] -t [upload-type]
```
<br/>


## Command
| Short Name | Full Name | description |
|------------|------------------------------|--------------------------------------------|
| -p | --privateKey | private key |
| -a | --address | contract address / domain name |
| -f | --file | upload file path / name |
| -c | --chainId | chain id |
| -r | --rpc | provider url |
| -t | --type | file save type<br/>on chain: 1<br/>blob: 2 |
| -g | --gasPriceIncreasePercentage | gas price increase percentage |
| Short Name | Full Name | description |
|------------|------------------|----------------------------------------------------------------------------|
| -p | --privateKey | private key |
| -a | --address | contract address / domain name |
| -f | --file | upload file path / name |
| -c | --chainId | chain id |
| -r | --rpc | provider url |
| -t | --type | file upload type:<br/>calldata: `1` or `calldata` <br/>blob: `2` or `blob` |
| -g | --gasIncPct | gas price increase percentage |
| -s | --threadPoolSize | number of threads for concurrent file uploads |
iteyelmp marked this conversation as resolved.
Show resolved Hide resolved
<br/>


## Supported networks
| Chain Name | Chain Short Name and Chain Id |
|----------------------------|-------------------------------|
Expand Down Expand Up @@ -53,141 +64,112 @@ npx ethfs-cli upload -f <directory|file> -a <address> -p <private-key> -r [rpc]
| Harmony Testnet Shard 0 | hmy-b-s0 / 1666700000 |
| Evmos | evmos / 9001 |
| Evmos Testnet | evmos-testnet / 9000 |
| QuarkChain L2 Testnet | esl2-t / 43069 |


## Usage
### Support EIP-3770 Address
```
ethereum
Ethereum
eth:<name|address>

...

galileo
w3q-g:<name|address>
Sepolia
sep:<name|address>
...
```
##### Example
```
ethereum
Ethereum
eth:ens.eth

Sepolia
sep:0x1825...2388
...

galileo
w3q-g:0x1825...2388
```
<br/>


### Create FlatDirectory Command
Ethereum is the default network if it's not specified, otherwise, you should use "--chainId" to set it. RPC should also be specified if the network is an unlisted network.
```
ethfs-cli create -p <privateKey>
ethfs-cli create -p <privateKey> -c [chainId]
ethfs-cli create -p <privateKey> -c [chainId] -r [rpc]
ethfs-cli create -p <private-key> -c [chain-id] -r [rpc]

// output: contract address
```
##### Example
```
ethfs-cli create -p 0x32...
ethfs-cli create -p 0x32... -c 5
ethfs-cli create -p 0x32... -c 1 -r https://rpc.ankr.com/eth
ethfs-cli create -p 0x32... -c 11155111
ethfs-cli create -p 0x32... -r https://rpc.ankr.com/eth
```
<br/>



### Upload Command
Upload files, you need to specify the upload type. The default type is blob:2.<br/>
If you want to use name instead of FlatDirectory address, the name should be pointed to the FlatDirectory
address in advance. Click [here](https://docs.web3url.io/advanced-topics/bind-ens-name-to-a-chain-specific-address) for details.
address in advance. Click [here](https://docs.web3url.io/tutorials-on-ethstorage-early-testnet/bind-domain-names-to-your-flatdirectory) for details.
```
FlatDirectory address
ethfs-cli upload -f <directory|file> -a <address> -p <privateKey> -r [rpc] -t [uploadType] -g [gas-price-percentage]
ens
ethfs-cli upload -f <directory|file> -a <name> -p <privateKey> -r [rpc] -t [uploadType] -g [gas-price-percentage]
w3ns
ethfs-cli upload -f <directory|file> -a <name> -p <privateKey> -r [rpc] -t [uploadType] -g [gas-price-percentage]
ethfs-cli upload -f <address|domain> -a <address> -p <private-key> -t [upload-type] -c [chain-id] -r [rpc] -g [gas-price-increase-percentage] -s [thread-pool-size]
```
##### Example
```
FlatDirectory address
ethfs-cli upload -f index.html -a gor:0x1825...2388 -p 0x32... -g 20
ethfs-cli upload -f index.html -a xxx:0x1825...2388 -p 0x32... -r https://rpc.xxx -t 1
ethfs-cli upload -f index.html -a gor:0x1825...2388 -p 0x32... -t 1
ethfs-cli upload -f index.html -a 0x1825...2388 -p 0x32... -c 11155111 -t 1
ethfs-cli upload -f index.html -a 0x1825...2388 -p 0x32... -r https://rpc.xxx -t calldata -g 20
ethfs-cli upload -f index.html -a 0x1825...2388 -p 0x32... -r https://rpc.xxx -t calldata -s 12
ens
ethfs-cli upload -f dist -a eth:ens.eth -p 0x32... -r https://rpc.ankr.com/eth -t 2 -g 20
w3ns
ethfs-cli upload -f dist -a w3q-g:home.w3q -p 0x32... -t 2 -g 20
ethfs-cli upload -f dist -a eth:ens.eth -p 0x32... -r https://rpc.ankr.com/eth -t 2
ethfs-cli upload -f dist -a eth:ens.eth -p 0x32... -r https://rpc.ankr.com/eth -t blob
```
<br/>


### Set FlatDirectory Default Entrance
```
FlatDirectory address
ethfs-cli default -a <address> -f <fileName> -p <privateKey> -r [rpc]
ens
ethfs-cli default -a <name> -f <fileName> -p <privateKey> -r [rpc]
w3ns
ethfs-cli default -a <name> -f <fileName> -p <privateKey> -r [rpc]
ethfs-cli default -a <address|domain> -f <file-name> -p <private-key> -c [chain-id] -r [rpc]
```
##### Example
```
FlatDirectory address
ethfs-cli default -a gor:0x1825...2388 -f index.html -p 0x32...
ethfs-cli default -a xxx:0x1825...2388 -f index.html -p 0x32... -r https://rpc.xxx
ethfs-cli default -a sep:0x1825...2388 -f index.html -p 0x32...
ethfs-cli default -a 0x1825...2388 -f index.html -p 0x32... -c 11155111
ethfs-cli default -a 0x1825...2388 -f index.html -p 0x32... -r https://rpc.xxx
ens
ethfs-cli default -a eth:ens.eth -f index.html -p 0x32... -r https://rpc.ankr.com/eth
w3ns
ethfs-cli default -a w3q-g:home.w3q -f index.html -p 0x32... -r https://rpc.ankr.com/eth
```
<br/>



### Remove File
### Download File
```
FlatDirectory address
ethfs-cli remove -a <address> -f <fileName> -p <privateKey> -r [rpc]
ens
ethfs-cli remove -a <name> -f <fileName> -p <privateKey> -r [rpc]
w3ns
ethfs-cli remove -a <name> -f <fileName> -p <privateKey> -r [rpc]
ethfs-cli download -a <address|domain> -f <fileName> -c [chain-id] -r [rpc]
```
##### Example
```
FlatDirectory address
ethfs-cli remove -a gor:0x1825...2388 -f index.html -p 0x32...
ethfs-cli remove -a xxx:0x1825...2388 -f index.html -p 0x32... -r https://rpc.xxx
ethfs-cli download -a sep:0x1825...2388 -f index.html
ethfs-cli download -a 0x1825...2388 -f index.html -c 11155111
ethfs-cli download -a 0x1825...2388 -f index.html -r https://rpc.xxx
ens
ethfs-cli remove -a eth:ens.eth -f src/home.vue -p 0x32... -r https://rpc.ankr.com/eth
w3ns
ethfs-cli remove -a w3q-g:home.w3q -f src/home.vue -p 0x32... -r https://rpc.ankr.com/eth
ethfs-cli download -a eth:ens.eth -f home.vue
```
<br/>


### Download File
### Remove File
```
FlatDirectory address
ethfs-cli download -a <address> -f <fileName> -r [rpc]
ens
ethfs-cli download -a <name> -f <fileName> -r [rpc]
w3ns
ethfs-cli download --address <name> --file <fileName> --rpc [rpc]
ethfs-cli remove -a <address|domain> -f <file-name> -p <private-key> -r [rpc] -c [chain-id]
```
##### Example
```
FlatDirectory address
npx ethfs-cli download -a gor:0x1825...2388 -f index.html
npx ethfs-cli download -a xxx:0x1825...2388 -f index.html -r https://rpc.xxx
ethfs-cli remove -a sep:0x1825...2388 -f index.html -p 0x32...
ethfs-cli remove -a 0x1825...2388 -f index.html -p 0x32... -c 11155111
ethfs-cli remove -a 0x1825...2388 -f index.html -p 0x32... -r https://rpc.xxx
ens
npx ethfs-cli download -a eth:ens.eth -f home.vue
w3ns
npx ethfs-cli download --address w3q-g:home.w3q --file home.vue --rpc https://rpc.xxx
ethfs-cli remove -a eth:ens.eth -f home.vue -p 0x32...
```
<br/>

### Repo
[Github Repo](https://github.com/QuarkChain/ethfs-cli)
[Github Repo](https://github.com/ethstorage/ethfs-cli/)
5 changes: 3 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ program
.option('-t, --type [type]', 'uploader type')
.option('-c, --chainId [chainId]', 'chain id')
.option('-r, --rpc [rpc]', 'provider url')
.option('-g, --gasPriceIncreasePercentage [gasPriceIncreasePercentage]', 'gas price increase percentage')
.option('-g, --gasIncPct [gasIncPct]', 'gas price increase percentage')
.option('-s, --threadPoolSize [threadPoolSize]', 'thread pool size')
.action(() => {
const opts = program.opts();
upload(opts.privateKey, opts.address, opts.file, opts.type, opts.rpc, opts.chainId, opts.gasPriceIncreasePercentage);
upload(opts.privateKey, opts.address, opts.file, opts.type, opts.rpc, opts.chainId, opts.gasIncPct, opts.threadPoolSize);
});

program.parse(process.argv);
33 changes: 21 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const {
PROVIDER_URLS,
ETH_STORAGE_RPC,
ETHEREUM_CHAIN_ID,
FlatDirectoryAbi
FlatDirectoryAbi,
TYPE_CALLDATA,
TYPE_BLOB
} = require('./params');
const {
isPrivateKey,
Expand Down Expand Up @@ -199,7 +201,7 @@ const download = async (domain, fileName, rpc, chainId) => {
}
}

const estimateAndUpload = async (key, domain, path, type, rpc, chainId, gasPriceIncreasePercentage) => {
const estimateAndUpload = async (key, domain, path, type, rpc, chainId, gasIncPct, threadPoolSize) => {
if (!isPrivateKey(key)) {
console.error(error(`ERROR: invalid private key!`));
return;
Expand All @@ -216,9 +218,15 @@ const estimateAndUpload = async (key, domain, path, type, rpc, chainId, gasPrice
console.error(error(`ERROR: The file or folder does not exist!`), path);
return;
}
if (type && Number(type) !== UPLOAD_TYPE_CALLDATA && Number(type) !== UPLOAD_TYPE_BLOB) {
console.error(error(`ERROR: invalid upload type!`));
return;
if (type) {
if(type === TYPE_CALLDATA) {
type = UPLOAD_TYPE_CALLDATA;
} else if(type === TYPE_BLOB) {
type = UPLOAD_TYPE_BLOB;
} else if (Number(type) !== UPLOAD_TYPE_CALLDATA && Number(type) !== UPLOAD_TYPE_BLOB) {
console.error(error(`ERROR: invalid upload type!`));
return;
}
}

const handler = await getWebHandler(domain, rpc, chainId, CHAIN_ID_DEFAULT);
Expand All @@ -237,16 +245,17 @@ const estimateAndUpload = async (key, domain, path, type, rpc, chainId, gasPrice
let status = await answer(`Estimate gas cost?`);
if (status) {
// get cost
await estimateCost(uploader, path, gasPriceIncreasePercentage);
await estimateCost(uploader, path, gasIncPct, threadPoolSize);
status = await answer(`Continue?`);
if (status) {
// upload
await upload(uploader, path, gasPriceIncreasePercentage);
await upload(uploader, path, gasIncPct, threadPoolSize);
}
} else {
// upload
await upload(uploader, path, gasPriceIncreasePercentage);
await upload(uploader, path, gasIncPct, threadPoolSize);
}
process.exit(0);
}

const answer = async (text) => {
Expand All @@ -258,10 +267,10 @@ const answer = async (text) => {
return answer;
}

const estimateCost = async (uploader, path, gasPriceIncreasePercentage) => {
const estimateCost = async (uploader, path, gasIncPct, threadPoolSize) => {
const spin = ora('Start estimating cost').start();
try {
const cost = await uploader.estimateCost(spin, path, gasPriceIncreasePercentage);
const cost = await uploader.estimateCost(spin, path, gasIncPct, threadPoolSize);
spin.succeed('Estimating cost progress: 100%');

console.log();
Expand All @@ -279,9 +288,9 @@ const estimateCost = async (uploader, path, gasPriceIncreasePercentage) => {
}
}

const upload = async (uploader, path, gasPriceIncreasePercentage) => {
const upload = async (uploader, path, gasIncPct, threadPoolSize) => {
console.log();
const infoArr = await uploader.upload(path, gasPriceIncreasePercentage);
const infoArr = await uploader.upload(path, gasIncPct, threadPoolSize);
console.log();
let totalStorageCost = 0n, totalChunkCount = 0, totalDataSize = 0;
for (const file of infoArr) {
Expand Down
12 changes: 8 additions & 4 deletions src/params/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ const ETH_STORAGE_RPC = {
[QUARKCHAIN_L2_TESTNET_CHAIN_ID]: 'http://65.109.115.36:9540',
}

const VERSION_CALL_DATA = '1';
const VERSION_BLOB = '2';
const TYPE_CALLDATA = 'calldata';
const TYPE_BLOB = 'blob';

const DEFAULT_THREAD_POOL_SIZE = 6;

module.exports = {
NETWORK_MAPPING,
Expand All @@ -141,6 +143,8 @@ module.exports = {
ARBITRUM_NOVE_CHAIN_ID,
ETHEREUM_CHAIN_ID,

VERSION_CALL_DATA,
VERSION_BLOB
TYPE_CALLDATA,
TYPE_BLOB,

DEFAULT_THREAD_POOL_SIZE
}
Loading