Skip to content

Commit

Permalink
More docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 18, 2024
1 parent 6f9e437 commit c45319b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Using Foundry.
Compile:

```shell
foundry up
forge build
```

Expand Down Expand Up @@ -123,15 +124,22 @@ Get the hash of the message:
ipython
```

Then type `%cpaste` and copy-paste in:

```python
from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash
print(get_signing_hash(INITIAL_ACCEPTANCE_MESSAGE).hex())
```
new_line_escaped_msg = INITIAL_ACCEPTANCE_MESSAGE.replace("\n", "\\n")
print("Paste to your shell:")
print("")
print(f"""export ACCEPTANCE_MESSAGE_HASH={get_signing_hash(INITIAL_ACCEPTANCE_MESSAGE).hex()}""")
print(f"""export ACCEPTANCE_MESSAGE="{new_line_escaped_msg}" """)
````

```shell
export ACCEPTANCE_MESSAGE_HASH=808318f1c18ddfb861cd9755fe5005e3028f816039dc42a1b52e4f5031b645a4
export ACCEPTANCE_MESSAGE_HASH= # Copy from above output
export ACCEPTANCE_MESSAGE= # Copy from above output
export TERMS_OF_SERVICE_VERSION=1
export CONTRACT_ADDRESS=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d
export CONTRACT_ADDRESS=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d # Set your deployed contract
```

Then set the initial version:
Expand All @@ -141,9 +149,38 @@ cast send \
--private-key $DEPLOY_PRIVATE_KEY \
--rpc-url $JSON_RPC_POLYGON \
$CONTRACT_ADDRESS \
"updateTermsOfService(uint16,bytes32)" \
$TERMS_OF_SERVICE_VERSION \
$ACCEPTANCE_MESSAGE_HASH
"updateTermsOfService(uint16,bytes32,string)" \
"$TERMS_OF_SERVICE_VERSION" \
"$ACCEPTANCE_MESSAGE_HASH" \
"$ACCEPTANCE_MESSAGE"
```

You can also run the above command using [scripts/set-terms-of-service.sh](./scripts/set-terms-of-service.sh).
The script will complain if you have some variables unset.

## Updating terms of service version

With `ipython`:

```python
from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash

NEW_ACCEPTANCE_MESSAGE="""Update: December 23th, 2023
In our ongoing commitment to adhere to legal regulations, we will restrict IP addresses located in certain jurisdictions from accessing our application’s frontend user interface. These jurisdictions include: United States, United Kingdom, Cuba, Iran, North Korea, Syria and Russia. Thank you for your understanding and ongoing support
Last Modified: December 23rd, 2023"""

new_line_escaped_msg = NEW_ACCEPTANCE_MESSAGE.replace("\n", "\\n")
print("Paste to your shell:")
print("")
print(f"""export ACCEPTANCE_MESSAGE_HASH={get_signing_hash(NEW_ACCEPTANCE_MESSAGE).hex()}""")
print(f"""export ACCEPTANCE_MESSAGE="{new_line_escaped_msg}" """)
print(f"""export TERMS_OF_SERVICE_VERSION=2""")
```

```shell
scripts/set-terms-of-service.sh
```

## Deployment
Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ src = "src"
out = "out"
libs = ["lib"]

solc_version = "0.8.23"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
14 changes: 14 additions & 0 deletions scripts/set-terms-of-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -x
set -e
set -u

cast send \
--private-key $DEPLOY_PRIVATE_KEY \
--rpc-url $JSON_RPC_POLYGON \
$CONTRACT_ADDRESS \
"updateTermsOfService(uint16,bytes32,string)" \
"$TERMS_OF_SERVICE_VERSION" \
"$ACCEPTANCE_MESSAGE_HASH" \
"$ACCEPTANCE_MESSAGE"
10 changes: 3 additions & 7 deletions terms_of_service/acceptance_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""The default terms of service message that is signed.
- The terms of service itself is not signed as it is too big to fit to small input boxes of the wallet.
Instead, we sign a message that refers to the terms of service.
- Uses EIP-151
- See `EthAccout.sign_message implementation <https://github.com/ethereum/eth-account/blob/b4883627557839bed906c89b93eec0fbbb017ec5/eth_account/account.py#L535>`__.
Expand All @@ -10,13 +13,6 @@
from eth_account.messages import encode_defunct, _hash_eip191_message
from eth_account.signers.local import LocalAccount

DEFAULT_ACCEPTANCE_MESSAGE_TEMPLATE = """
I read and agree on terms of service (version {version}) to use
smart contract software deployed on a blockchain.
The terms of service text was published {human_date} at {link}.
The unique identifier hash for this terms of service text was {hash}.
""".strip()

INITIAL_ACCEPTANCE_MESSAGE = """
I read and agree on terms of service (version 1) to use
Expand Down

0 comments on commit c45319b

Please sign in to comment.