Skip to content

Commit

Permalink
adding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vittominacori committed Oct 18, 2018
1 parent e88359f commit 7f7c1be
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .env.example
@@ -1,3 +1,8 @@
# vuepress deploy
GIT_DEPLOY_DIR=docs/.vuepress/dist
GIT_DEPLOY_BRANCH=gh-pages
GIT_DEPLOY_REPO=origin

# configure your infura api key (not technically required)
INFURA_API_KEY=

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -40,3 +40,6 @@ build/

# npm package
package-lock.json

# vuepress
docs/.vuepress/dist/
33 changes: 16 additions & 17 deletions README.md
Expand Up @@ -11,27 +11,12 @@ TokenRecover allows the contract owner to recover any ERC20 token sent into the
There are lots of tokens lost forever into Smart Contracts (see [OMG](https://etherscan.io/address/0xd26114cd6ee289accf82350c8d8487fedb8a0c07) token balances).
Each Ethereum contract is a potential token trap for ERC20 tokens. They can't be recovered so it means money losses for end users.

## Code

This repo contains:

* [TokenRecover.sol](https://github.com/vittominacori/eth-token-recover/blob/master/contracts/TokenRecover.sol)

Contract has a `recoverERC20` function that transfers a `_tokens` amount of `_tokenAddress` token to the contract owner.

```solidity
function recoverERC20(address _tokenAddress, uint256 _tokens) public onlyOwner returns (bool success);
```

Note: only owner can call the `recoverERC20` function so be careful when use on contracts generated from other contracts.

## Install

```bash
npm install eth-token-recover
```


## Usage

```solidity
Expand All @@ -41,10 +26,24 @@ import "eth-token-recover/contracts/TokenRecover.sol";
contract MyContract is TokenRecover {
// your stuffs
// your stuff
}
```

## Code

This repo contains:

* [TokenRecover.sol](https://github.com/vittominacori/eth-token-recover/blob/master/contracts/TokenRecover.sol)

Contract has a `recoverERC20` function that transfers a `_tokens` amount of `_tokenAddress` token to the contract owner.

```solidity
function recoverERC20(address _tokenAddress, uint256 _tokens) public onlyOwner returns (bool success);
```

Note: only owner can call the `recoverERC20` function so be careful when use on contracts generated from other contracts.

## Development

Install Truffle
Expand Down Expand Up @@ -99,6 +98,6 @@ Test
test
```

### License
## License

Code released under the [MIT License](https://github.com/vittominacori/eth-token-recover/blob/master/LICENSE).
9 changes: 9 additions & 0 deletions docs/.vuepress/config.js
@@ -0,0 +1,9 @@
module.exports = {
title: 'TokenRecover',
description: 'TokenRecover allows the contract owner to recover any ERC20 token sent into the contract for error.',
base: '/eth-token-recover/',
ga: 'UA-115756440-2',
themeConfig: {
sidebar: 'auto',
},
};
2 changes: 2 additions & 0 deletions docs/.vuepress/override.styl
@@ -0,0 +1,2 @@
$accentColor = #008148
$codeBgColor = #f3f5f7
3 changes: 3 additions & 0 deletions docs/.vuepress/style.styl
@@ -0,0 +1,3 @@
.content
code
color #2c3e50 !important
1 change: 1 addition & 0 deletions docs/README.md
213 changes: 213 additions & 0 deletions docs/deploy/deploy.sh
@@ -0,0 +1,213 @@
#!/usr/bin/env bash
# https://github.com/X1011/git-directory-deploy
set -o errexit #abort if any command fails
me=$(basename "$0")

help_message="\
Usage: $me [-c FILE] [<options>]
Deploy generated files to a git branch.
Options:
-h, --help Show this help information.
-v, --verbose Increase verbosity. Useful for debugging.
-e, --allow-empty Allow deployment of an empty directory.
-m, --message MESSAGE Specify the message used when committing on the
deploy branch.
-n, --no-hash Don't append the source commit's hash to the deploy
commit's message.
-c, --config-file PATH Override default & environment variables' values
with those in set in the file at 'PATH'. Must be the
first option specified.
Variables:
GIT_DEPLOY_DIR Folder path containing the files to deploy.
GIT_DEPLOY_BRANCH Commit deployable files to this branch.
GIT_DEPLOY_REPO Push the deploy branch to this repository.
These variables have default values defined in the script. The defaults can be
overridden by environment variables. Any environment variables are overridden
by values set in a '.env' file (if it exists), and in turn by those set in a
file specified by the '--config-file' option."

parse_args() {
# Set args from a local environment file.
if [ -e ".env" ]; then
source .env
fi

# Set args from file specified on the command-line.
if [[ $1 = "-c" || $1 = "--config-file" ]]; then
source "$2"
shift 2
fi

# Parse arg flags
# If something is exposed as an environment variable, set/overwrite it
# here. Otherwise, set/overwrite the internal variable instead.
while : ; do
if [[ $1 = "-h" || $1 = "--help" ]]; then
echo "$help_message"
return 0
elif [[ $1 = "-v" || $1 = "--verbose" ]]; then
verbose=true
shift
elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then
allow_empty=true
shift
elif [[ ( $1 = "-m" || $1 = "--message" ) && -n $2 ]]; then
commit_message=$2
shift 2
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
GIT_DEPLOY_APPEND_HASH=false
shift
else
break
fi
done

# Set internal option vars from the environment and arg flags. All internal
# vars should be declared here, with sane defaults if applicable.

# Source directory & target branch.
deploy_directory=${GIT_DEPLOY_DIR:-dist}
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}

#if no user identity is already set in the current git environment, use this:
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
default_email=${GIT_DEPLOY_EMAIL:-}

#repository to deploy to. must be readable and writable.
repo=${GIT_DEPLOY_REPO:-origin}

#append commit hash to the end of message by default
append_hash=${GIT_DEPLOY_APPEND_HASH:-true}
}

main() {
parse_args "$@"

enable_expanded_output

if ! git diff --exit-code --quiet --cached; then
echo Aborting due to uncommitted changes in the index >&2
return 1
fi

commit_title=`git log -n 1 --format="%s" HEAD`
commit_hash=` git log -n 1 --format="%H" HEAD`

#default commit message uses last title if a custom one is not supplied
if [[ -z $commit_message ]]; then
commit_message="publish: $commit_title"
fi

#append hash to commit message unless no hash flag was found
if [ $append_hash = true ]; then
commit_message="$commit_message"$'\n\n'"generated from commit $commit_hash"
fi

previous_branch=`git rev-parse --abbrev-ref HEAD`

if [ ! -d "$deploy_directory" ]; then
echo "Deploy directory '$deploy_directory' does not exist. Aborting." >&2
return 1
fi

# must use short form of flag in ls for compatibility with OS X and BSD
if [[ -z `ls -A "$deploy_directory" 2> /dev/null` && -z $allow_empty ]]; then
echo "Deploy directory '$deploy_directory' is empty. Aborting. If you're sure you want to deploy an empty tree, use the --allow-empty / -e flag." >&2
return 1
fi

if git ls-remote --exit-code $repo "refs/heads/$deploy_branch" ; then
# deploy_branch exists in $repo; make sure we have the latest version

disable_expanded_output
git fetch --force $repo $deploy_branch:$deploy_branch
enable_expanded_output
fi

# check if deploy_branch exists locally
if git show-ref --verify --quiet "refs/heads/$deploy_branch"
then incremental_deploy
else initial_deploy
fi

restore_head
}

initial_deploy() {
git --work-tree "$deploy_directory" checkout --orphan $deploy_branch
git --work-tree "$deploy_directory" add --all
commit_push
}

incremental_deploy() {
#make deploy_branch the current branch
git symbolic-ref HEAD refs/heads/$deploy_branch
#put the previously committed contents of deploy_branch into the index
git --work-tree "$deploy_directory" reset --mixed --quiet
git --work-tree "$deploy_directory" add --all

set +o errexit
diff=$(git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD --)$?
set -o errexit
case $diff in
0) echo No changes to files in $deploy_directory. Skipping commit.;;
1) commit_push;;
*)
echo git diff exited with code $diff. Aborting. Staying on branch $deploy_branch so you can debug. To switch back to develop, use: git symbolic-ref HEAD refs/heads/develop && git reset --mixed >&2
return $diff
;;
esac
}

commit_push() {
set_user_id
git --work-tree "$deploy_directory" commit -m "$commit_message"

disable_expanded_output
#--quiet is important here to avoid outputting the repo URL, which may contain a secret token
git push --quiet $repo $deploy_branch
enable_expanded_output
}

#echo expanded commands as they are executed (for debugging)
enable_expanded_output() {
if [ $verbose ]; then
set -o xtrace
set +o verbose
fi
}

#this is used to avoid outputting the repo URL, which may contain a secret token
disable_expanded_output() {
if [ $verbose ]; then
set +o xtrace
set -o verbose
fi
}

set_user_id() {
if [[ -z `git config user.name` ]]; then
git config user.name "$default_username"
fi
if [[ -z `git config user.email` ]]; then
git config user.email "$default_email"
fi
}

restore_head() {
if [[ $previous_branch = "HEAD" ]]; then
#we weren't on any branch before, so just set HEAD back to the commit it was on
git update-ref --no-deref HEAD $commit_hash $deploy_branch
else
git symbolic-ref HEAD refs/heads/$previous_branch
fi

git reset --mixed
}

[[ $1 = --source-only ]] || main "$@"
2 changes: 1 addition & 1 deletion ethpm.json
@@ -1,6 +1,6 @@
{
"package_name": "eth-token-recover",
"version": "1.0.1",
"version": "1.0.2",
"description": "TokenRecover allows the contract owner to recover any ERC20 token sent into the contract for error",
"authors": [
"Vittorio Minacori (https://github.com/vittominacori)"
Expand Down
8 changes: 6 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "eth-token-recover",
"version": "1.0.1",
"version": "1.0.2",
"description": "TokenRecover allows the contract owner to recover any ERC20 token sent into the contract for error",
"files": [
"contracts",
Expand All @@ -14,6 +14,9 @@
"lint:sol:fix": "solium -d . --fix",
"lint": "npm run lint:js && npm run lint:sol",
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"docs:deploy": "vuepress build docs && sh docs/deploy/deploy.sh",
"console": "truffle console",
"coverage": "scripts/coverage.sh",
"version": "scripts/version.js"
Expand Down Expand Up @@ -49,7 +52,8 @@
"ganache-cli": "6.1.0",
"solidity-coverage": "^0.5.4",
"solium": "^1.1.8",
"truffle": "^4.1.14"
"truffle": "^4.1.14",
"vuepress": "^0.14.4"
},
"dependencies": {
"openzeppelin-solidity": "1.12.0"
Expand Down

0 comments on commit 7f7c1be

Please sign in to comment.