Skip to content

Commit 3d167f2

Browse files
authored
fix: reads users genesis record from the ceramic node (#10734)
1 parent 04235b0 commit 3d167f2

File tree

3 files changed

+16
-78
lines changed

3 files changed

+16
-78
lines changed

app/dashboard/base36.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

app/dashboard/passport_reader.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# libs for processing the deterministic stream location
2-
import hashlib
32
import json
43

54
# Making GET requests against the CERAMIC_URL to read streams
65
import requests
76

8-
# Base36 is the expected encoding for a ceramic streamID
9-
from .base36 import base36
10-
117
# Location of a Ceramic node that we can read state from
128
CERAMIC_URL = "https://ceramic.passport-iam.gitcoin.co"
139

@@ -48,25 +44,28 @@ def get_did(address, network="1"):
4844
return f"did:pkh:eip155:{network}:{address}"
4945

5046
def get_stream_ids(did, ids=[CERAMIC_GITCOIN_PASSPORT_STREAM_ID]):
51-
# delay import as this is only available in celery envs
52-
import dag_cbor
53-
54-
# encode the input genesis with cborg (Concise Binary Object Representation)
55-
input_bytes = dag_cbor.encode({"header":{"controllers":[did],"family":"IDX"}})
56-
# hash the input_bytes and pad with STREAMID_CODEC and type (as bytes)
57-
stream_id_digest = [206, 1, 0, 1, 113, 18, 32] + list(bytearray(hashlib.sha256(input_bytes).digest()))
58-
59-
# encode the bytes array with base36 to get the derministic streamId from the DIDs genesis
60-
stream_id = base36(stream_id_digest)
61-
6247
# return streams in a dict
6348
streams = {}
6449

6550
try:
66-
# get the stream content for the given did according to its genesis stream_id
67-
stream_response = requests.get(f"{CERAMIC_URL}/api/v0/streams/{stream_id}")
51+
# query and pin for the streamId
52+
stream_response = requests.post(f"{CERAMIC_URL}/api/v0/streams", json={
53+
"type": 0,
54+
"genesis": {
55+
"header": {
56+
"family": "IDX",
57+
"controllers": [did],
58+
},
59+
},
60+
"opts": {
61+
"pin": True,
62+
"sync": True,
63+
"anchor": False,
64+
}
65+
})
6866
# get the state and default to empty content
6967
state = stream_response.json().get('state', {"content": {}})
68+
7069
# check for a next record else pull from content
7170
content = state['next']['content'] if state.get('next') else state['content']
7271

requirements/test.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ django-debug-toolbar==3.2.4
1717
ipfshttpclient==0.6.0
1818
dj_static==0.0.6
1919
livereload==2.6.3
20-
git+https://github.com/gdixon/dag-cbor.git#egg=dag-cbor
2120
didkit==0.2.1

0 commit comments

Comments
 (0)