fix getting pack content hashes
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
1d1b0eb8ae
commit
1116b225a4
12
contract.py
12
contract.py
|
@ -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()
|
||||
|
|
3
main.py
3
main.py
|
@ -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)
|
||||
|
|
9
pack.py
9
pack.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue