-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdapp.py
40 lines (27 loc) · 978 Bytes
/
dapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from os import environ
import os
import logging
import requests
import ipfshttpclient2
from io import BytesIO
logging.basicConfig(level="INFO")
logger = logging.getLogger(__name__)
rollup_server = environ["ROLLUP_HTTP_SERVER_URL"]
logger.info(f"HTTP rollup_server url is {rollup_server}")
data = requests.get(rollup_server + "/get_tx")
logger.info(f"Got tx {data.content}")
ipfs_api = os.getenv('IPFS_API', '/ip4/127.0.0.1/tcp/5001')
try:
ipfs_instance = ipfshttpclient2.connect(ipfs_api)
except Exception as e:
print(f"Error connecting to IPFS API: {e}")
exit(1)
content = "Hello World"
directory_path = '/state'
try:
ipfs_instance.files.mkdir(directory_path, parents=True)
output_path = f"{directory_path}/output.file"
ipfs_instance.files.write(output_path, BytesIO(content.encode('utf-8')), create=True, truncate=True)
except Exception as e:
print(f"Error writing content to IPFS: {e}")
requests.post(rollup_server + "/finish", json={})