|
1 | 1 | # libs for processing the deterministic stream location
|
2 |
| -import hashlib |
3 | 2 | import json
|
4 | 3 |
|
5 | 4 | # Making GET requests against the CERAMIC_URL to read streams
|
6 | 5 | import requests
|
7 | 6 |
|
8 |
| -# Base36 is the expected encoding for a ceramic streamID |
9 |
| -from .base36 import base36 |
10 |
| - |
11 | 7 | # Location of a Ceramic node that we can read state from
|
12 | 8 | CERAMIC_URL = "https://ceramic.passport-iam.gitcoin.co"
|
13 | 9 |
|
@@ -48,25 +44,28 @@ def get_did(address, network="1"):
|
48 | 44 | return f"did:pkh:eip155:{network}:{address}"
|
49 | 45 |
|
50 | 46 | 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 |
| - |
62 | 47 | # return streams in a dict
|
63 | 48 | streams = {}
|
64 | 49 |
|
65 | 50 | 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 | + }) |
68 | 66 | # get the state and default to empty content
|
69 | 67 | state = stream_response.json().get('state', {"content": {}})
|
| 68 | + |
70 | 69 | # check for a next record else pull from content
|
71 | 70 | content = state['next']['content'] if state.get('next') else state['content']
|
72 | 71 |
|
|
0 commit comments