Ejemplo n.º 1
0
def transferProperty(transferList):
    """
    :param transferList: [[toAccount1, DNA1],[toAccount2, DNA2]]
    :return: bool
    """
    DNACheck = transferList[0][1]
    account = Get(context, concatKey(DNA_PRE_KEY, DNACheck))
    RequireWitness(account)

    for transferE in transferList:
        toAccount = transferE[0]
        DNA = transferE[1]

        DNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account))
        DNAlist = Deserialize(DNAlist)

        toDNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, toAccount))
        if not toDNAlist:
            toDNAlist = []
        else:
            toDNAlist = Deserialize(DNAlist)

        num = 0
        while num < len(DNAlist):
            if DNAlist[num] == DNA:
                Put(context, concatKey(DNA_PRE_KEY, DNA), toAccount)
                DNAlist.remove(num)
                toDNAlist.append(DNA)
                Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account),
                    Serialize(DNAlist))
                Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, toAccount),
                    Serialize(toDNAlist))
            num += 1
    Notify(["Transfer property successfully"])
    return True
Ejemplo n.º 2
0
def removeProperty(removeList):
    """
    :param removeList: [DNA1, DNA2]
    :return: bool
    """
    DNACheck = removeList[0]
    account = Get(context, concatKey(DNA_PRE_KEY, DNACheck))
    RequireScriptHash(account)
    RequireWitness(account)

    DNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account))

    if DNAlist:
        DNAlist = Deserialize(DNAlist)
    else:
        raise Exception("NO DNA")
    removeListLen = len(removeList)
    removeListIndex = 0

    while removeListIndex < removeListLen:
        DNA = removeList[removeListIndex]
        findInList = _findInList(DNA, DNAlist)
        if findInList >= 0:
            Delete(context, concatKey(DNA_PRE_KEY, DNA))
            DNAlist.remove(findInList)
        else:
            raise Exception("Not found DNA to be removed")
        removeListIndex += 1
    Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account), Serialize(DNAlist))
    Notify(["Remove property successfully"])
    return True
Ejemplo n.º 3
0
def transferProperty(transferList):
    """
    one account can transfer many DNA to different other accounts
    :param transferList: [[toAccount1, DNA1],[toAccount2, DNA2]]
    :return: bool
    """
    DNACheck = transferList[0][1]
    account = Get(context, concatKey(DNA_PRE_KEY, DNACheck))
    RequireScriptHash(account)
    RequireWitness(account)
    DNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account))
    DNAlist = Deserialize(DNAlist)

    transferListLen = len(transferList)
    transferListIndex = 0
    while transferListIndex < transferListLen:
        toAccount = transferList[transferListIndex][0]
        DNA = transferList[transferListIndex][1]

        toDNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, toAccount))
        if not toDNAlist:
            toDNAlist = []
        else:
            toDNAlist = Deserialize(toDNAlist)

        findInList = _findInList(DNA, DNAlist)
        if findInList >= 0:
            Put(context, concatKey(DNA_PRE_KEY, DNA), toAccount)
            toDNAlist.append(DNA)
            DNAlist.remove(findInList)
        else:
            raise Exception("Not found DNA to be removed")
        transferListIndex += 1
    Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account), Serialize(DNAlist))
    Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, toAccount), Serialize(toDNAlist))
    Notify(["Transfer property successfully"])
    return True
Ejemplo n.º 4
0
def removeProperty(removeList):
    """
    :param removeList: [DNA1, DNA2]
    :return: bool
    """
    DNACheck = removeList[0]
    account = Get(context, concatKey(DNA_PRE_KEY, DNACheck))
    RequireWitness(account)

    for DNA in removeList:
        DNAlist = Get(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account))
        DNAlist = Deserialize(DNAlist)

        num = 0
        while num < len(DNAlist):
            if DNAlist[num] == DNA:
                Delete(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account))
                Delete(context, concatKey(DNA_PRE_KEY, DNA))
                DNAlist.remove(num)
                Put(context, concatKey(PLAYER_ADDRESS_PRE_KEY, account),
                    Serialize(DNAlist))
            num += 1
    Notify(["Remove property successfully"])
    return True