fix getting pack content hashes

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-06-08 17:29:34 +02:00
parent 1d1b0eb8ae
commit 1116b225a4
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 19 additions and 5 deletions

View File

@ -11,5 +11,13 @@ class StickerPackContract:
)
def getAllPacks(self):
return self.contract.functions.totalSupply().call()
#for i=0; i<stickerTypeContract stickerTypeContract.functions.getPackSummary(i)
count = self.contract.functions.totalSupply().call()
return [
self.contentHashFromPack(
self.contract.functions.getPackSummary(i).call()
) for i in range(count)
]
@staticmethod
def contentHashFromPack(pack):
return pack[2].hex()

View File

@ -17,4 +17,5 @@ w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
s = StickerPackContract(STICKER_PACK_CONTRACT, STICKER_PACK_ABI, w3)
print(s.getAllPacks())
packs = s.getAllPacks()
print(packs)

View File

@ -1,11 +1,16 @@
IPFS_GATEWAY = "https://cloudflare-ipfs.com/ipfs"
class StickerPack:
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md
# All content hashes in Sticker Pack metadata have the same prefix.
content_hash_rgx = r'e30101701220\w+'
def __init__(self, url):
resp = requests.get(url)
def __init__(self, chash):
self.content_hash = chash
resp = requests.get("{}/{}".format(IPFS_GATEWAY, chash))
resp.raise_for_status()
self.image_hashes = SticketPack.parse_clj_meta(resp.text)
@staticmethod