Created
June 3, 2021 08:38
-
-
Save asbjornenge/4694fcf2cf882ff93e26e035403909e4 to your computer and use it in GitHub Desktop.
TezID v1 Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Types | |
# | |
TGetProofsRequestPayload = sp.TRecord( | |
address=sp.TAddress, | |
callback_address=sp.TAddress, | |
callback_entrypoint=sp.TString | |
) | |
TGetProofsResponsePayload = sp.TRecord( | |
address = sp.TAddress, | |
proofs = sp.TMap(sp.TString, sp.TRecord( | |
register_date = sp.TTimestamp, | |
verified = sp.TBool | |
)) | |
) | |
## Contract | |
# | |
class ICO(sp.Contract): | |
def __init__(self, tezid, requiredProofs): | |
self.init( | |
tezid = tezid, | |
requiredProofs = requiredProofs, | |
participants = {} | |
) | |
@sp.entry_point | |
def signup(self): | |
c = sp.contract(TGetProofsRequestPayload, self.data.tezid, entry_point="getProofs").open_some() | |
sp.transfer(sp.record(address=sp.sender, callback_address=sp.self_address, callback_entrypoint="register"), sp.mutez(0), c) | |
@sp.entry_point | |
def register(self, ptr): | |
sp.if sp.sender != self.data.tezid: | |
sp.failwith('Only TezID can register') | |
sp.set_type(ptr, TGetProofsResponsePayload) | |
validProofs = sp.local("validProofs", []) | |
sp.for requiredProof in self.data.requiredProofs: | |
sp.if ptr.proofs.contains(requiredProof): | |
sp.if ptr.proofs[requiredProof].verified: | |
validProofs.value.push(requiredProof) | |
sp.if sp.len(self.data.requiredProofs) == sp.len(validProofs.value): | |
self.data.participants[ptr.address] = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment