-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaltme_on_chain.py
109 lines (94 loc) · 3.68 KB
/
altme_on_chain.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import requests
import logging
import json
logging.basicConfig(level=logging.INFO)
"""
curl -XPOST https://tezid.net/api/mainnet/issuer/altme -H 'tezid-issuer-key:p3hMf9V/OaiJjPOC2Va9uzDg6uj02E1YpCD9xdTB63Q='
-H 'Content-Type: application/json'
--data '{ "address": "tz1UZZnrre9H7KzAufFVm7ubuJh5cCfjGwam", "prooftype": "over_18", "register": true }'
"""
def register_tezid(address, id, network, mode) :
# Ghostnet controller contrat is KT1K2i7gcbM9YY4ih8urHBDbmYHLUXTWvDYj
# check if proof already registered
url = 'https://tezid.net/api/' + network + '/proofs/' + address
r = requests.get(url)
logging.info("check if proof exist : status code = %s", r.status_code)
if not 199<r.status_code<300 :
logging.error("API call to TezID rejected %s", r.status_code)
return False
if not r.json() :
return True if register_proof_type(address, id, network, mode) else False
else :
proof_registered = False
for proof in r.json() :
if proof['id'] == id and proof['verified'] :
proof_registered = True
logging.warning('Proof already exists on TezID')
break
if not proof_registered :
return True if register_proof_type(address, id, network, mode) else False
def register_proof_type(address, proof_type, network, mode) :
#[{"id":"test_type","label":"Test_type","meta":{"issuer":"altme"},"verified":true,"register_date":"2022-12-03T11:16:30Z"}]
url = 'https://tezid.net/api/' + network + '/issuer/altme'
headers = {
'Content-Type' : 'application/json',
'tezid-issuer-key' : mode.tezid_issuer_key
}
data = {
"address": address,
"prooftype": proof_type,
"register": True
}
r = requests.post(url, headers=headers, data=json.dumps(data))
logging.info("Register proof : status code = %s", r.status_code)
if not 199<r.status_code<300 :
logging.error("API call to TezID rejected %s", r.status_code)
return False
else :
logging.info('Address has been registered on TezID')
return True
def issue_sbt(address, metadata, credential_id, mode) :
metadata_ipfs = add_to_ipfs(metadata, "sbt:" + credential_id , mode)
if metadata_ipfs :
metadata_ipfs_url = "ipfs://" + metadata_ipfs
else :
return
logging.info("metadata_ipfs_url = %s", metadata_ipfs_url)
url = 'https://altme-api.dvl.compell.io/mint'
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"transfer_to" : address,
"ipfs_url" : metadata_ipfs_url
}
resp = requests.post(url, data=data, headers=headers)
if not 199<resp.status_code<300 :
logging.warning("Get access refused, SBT not sent %s", resp.status_code)
return
return True
def add_to_ipfs(data_dict, name, mode) :
api_key = mode.pinata_api_key
secret = mode.pinata_secret_api_key
headers = {
'Content-Type': 'application/json',
'pinata_api_key': api_key,
'pinata_secret_api_key': secret}
data = {
'pinataMetadata' : {
'name' : name
},
'pinataContent' : data_dict
}
r = requests.post('https://api.pinata.cloud/pinning/pinJSONToIPFS', data=json.dumps(data), headers=headers)
if not 199<r.status_code<300 :
logging.warning("POST access to Pinatta refused")
return None
else :
return r.json()['IpfsHash']
if __name__ == '__main__':
# ghostnet KT1K2i7gcbM9YY4ih8urHBDbmYHLUXTWvDYj
import environment
myenv='local'
mode = environment.currentMode(myenv)
register_tezid("tz1iQNe71wzVCCL5YUSniJekP3qf9cmDosJU", "tezotopia_membershipcard", "ghostnet", mode)