def getRandomNumber(): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Require(callerHash == entryHash) randomHash = GetCurrentBlockHash() randomNumber = abs(randomHash) % 100 return randomNumber
def invokeB(param): Notify(["111_invokeB", param]) # to prevent hack from other contract callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Notify([callerHash, entryHash, ContractAddress]) return True
def checkHash(): Notify(["111_checkHash"]) # to prevent hack from other contract callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Notify([callerHash, entryHash, ContractAddress]) return True
def getRandomNumber(): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Require(callerHash == entryHash) randomHash = GetCurrentBlockHash() winers = getWiners() randomNumber = abs(randomHash) % len(winers) return randomNumber
def avoidToBeInvokedByContract(): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() if callerHash != entryHash: Notify(["You are not allowed to invoke this method through contract"]) return False else: Notify(["You can implement what you need to do here!"]) return True
def Main(op): if op == "Hash": Hash() return True if op == "Constant": Constant() return True a = GetEntryScriptHash() + GetExecutingScriptHash() Notify(a) return False
def avoidContractCallAttack(guessNumber): randomNumber = getRandomNumber() callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Notify(["randomNumber:", randomNumber, "guessNumber:", guessNumber]) if callerHash != entryHash: Notify(["You are not allowed to invoke this method through contract!"]) return False else: Notify(["You can implement what you need to do here!"]) if guessNumber == randomNumber: Notify(["You have won the big prize!"]) return True return False
def RequireNotContract(): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Require(callerHash == entryHash)
def RequireApproved(): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() if entryHash is not callerHash: approved = isApproved(callerHash) Require(approved)
def Hash(): a = GetEntryScriptHash() + GetExecutingScriptHash() Notify(a) return False
def invokeA(operation, params): callerHash = GetCallingScriptHash() entryHash = GetEntryScriptHash() Notify(["111_invokeA",callerHash, entryHash, ContractAddress]) return ContractB(operation, params)