-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.py
58 lines (47 loc) · 1.54 KB
/
record.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
import json
import os
from dotenv import load_dotenv
from pathlib import Path
from web3.auto import w3
load_dotenv()
headers = {
"Content-Type": "application/json",
"pinata_api_key": os.getenv("PINATA_API_KEY"),
"pinata_secret_api_key": os.getenv("PINATA_SECRET_API_KEY"),
}
def initContract():
with open(Path("CryptoRecord.json")) as json_file:
abi = json.load(json_file)
return w3.eth.contract(address=os.getenv("CRYPTORECORD_ADDRESS"), abi=abi)
def convertDataToJSON(landlord, token_id, previous, lease, omnibus, time, description):
data = {
"pinataOptions": {"cidVersion": 1},
"pinataContent": {
"name": "Space Report",
# Apartment as "token_id"
"apartment": token_id,
"landlord": landlord,
"previous": previous,
"lease": lease,
"omnibus": omnibus,
"description": description,
# This is the uploaded v1 URI for apartment on IPFS all in lower case
"image": f"ipfs://improvemyfavoriteapartmentxoxo_{token_id}",
"time": time
},
"pinataMetadata": {
"name": description,
"keyvalues": {
"customKey": description,
"customKey2": "baes"
}
}
}
return json.dumps(data)
def pinJSONtoIPFS(json):
r = requests.post(
"https://api.pinata.cloud/pinning/pinJSONToIPFS", data=json, headers=headers
)
ipfs_hash = r.json()["IpfsHash"]
return f"ipfs://{ipfs_hash}"