Ejemplo n.º 1
0
def _rollANumber():
    blockHash = GetCurrentBlockHash()
    tx = GetScriptContainer()
    txhash = GetTransactionHash(tx)
    theNumber = abs(blockHash ^ txhash) % 100
    theNumber = Add(abs(theNumber), 1)
    return theNumber
Ejemplo n.º 2
0
def main(Height):
    Block = GetBlock(Height)
    index = 0
    Tx = GetTransactionByIndex(Block, index)
    Txhash = GetTransactionHash(Tx)
    NewTx = GetTransactionByHash(Txhash)
    BlkHash = GetBlockHash(Block)
    print("all done")
Ejemplo n.º 3
0
def getExplodePoint():
    """
    :return: a random number in the range of 1 to 1 000 000
    """
    blockHash = GetCurrentBlockHash()
    tx = GetScriptContainer()
    txhash = GetTransactionHash(tx)
    randomNumber = abs(blockHash ^ txhash) % 1000000
    explodePoint = Add(abs(randomNumber), 1)
    return explodePoint
Ejemplo n.º 4
0
def random(min,max,salt):# min>=x and x<=max
    txid = GetTransactionHash(GetScriptContainer())
    blockTime = GetTime()
    blockHash = GetCurrentBlockHash()
    sysseed = [txid,blockHash, salt, blockTime]
    sysseed = sha256(Serialize(sysseed))
    res = abs(sysseed)
    number = res % (max-min+1)
    number = number + min
    return number
Ejemplo n.º 5
0
def callOracle(date):
    _require(CheckWitness(operaterAddress) or CheckWitness(adminAddress))

    req = getOracleReq(date)

    key = _concatKey(OraclePrefix, date)
    txhash = GetTransactionHash(GetScriptContainer())
    Put(ctx, key, txhash)
    oracleContract('CreateOracleRequest', [req, selfAddr])
    Notify([txhash])
    return True
Ejemplo n.º 6
0
def GeneratorRandom(id):
    txid = GetTransactionHash(GetScriptContainer())

    blockHeigt = GetHeight() + 1
    blockTime = GetTime()
    blockHash = GetCurrentBlockHash()

    sysseed = [0, id, blockHeigt, blockTime, blockHash]
    sysseed = sha256(Serialize(sysseed))

    resseed = sha256(Serialize([txid, sysseed]))

    resseed = sha256(Serialize([resseed, resseed]))

    res = abs(resseed)
    number = res % 100
    number = number + 1
    return number
Ejemplo n.º 7
0
def CreateOracleRequest(request, address):
    #check witness
    RequireWitness(address)

    fee = Get(GetContext(), Fee)
    #transfer ong to oracle Admin address
    res = TransferONG(address, Admin, fee)
    Require(res)

    #get transaction hash
    txHash = GetTransactionHash(GetScriptContainer())

    #update undoRequestMap
    undoRequestMap = GetUndoRequestMap()
    undoRequestMap[txHash] = request
    b = Serialize(undoRequestMap)
    Put(GetContext(), UndoRequestKey, b)
    Notify(["createOracleRequest", request, address])
    return True
Ejemplo n.º 8
0
def sendReqToOracle(jsonIndex):
    """
    call oracle to get format or info of Games, including the gameId, diskId
    """
    RequireWitness(Operater)

    req = getOracleReq(jsonIndex)

    txhash = GetTransactionHash(GetScriptContainer())
    if Get(GetContext(), concatKey(SENTREQHASH_FORMGAME_PREFIX, jsonIndex)):
        Put(GetContext(), concatKey(SENTREQHASH_SAVERES_PREFIX, jsonIndex),
            txhash)
    else:
        Put(GetContext(), concatKey(SENTREQHASH_FORMGAME_PREFIX, jsonIndex),
            txhash)
    res = OracleContract('CreateOracleRequest', [req, Operater])
    # if res == False:
    #      Notify(['callOracle failed'])
    #      return False
    Notify(["sendReqToOracle", txhash, res])
    return True
Ejemplo n.º 9
0
def _getRandomNumber(interval):
    blockHash = GetCurrentBlockHash()
    tx = GetScriptContainer()
    txhash = GetTransactionHash(tx)
    randomNumber = abs(blockHash ^ txhash) % Add(interval, 1)
    return randomNumber