Exemple #1
0
def migrateContract(code, needStorage, name, version, author, email,
                    description):
    assert (CheckWitness(adminAddress))
    res = Migrate(code, needStorage, name, version, author, email, description)
    assert (res)
    Notify(["migrateContract", adminAddress, GetTime()])
    return True
def upgrade(code):
    """
    migrate data to new contract, transfer asset to admin address
    :param code:
    :return:
    """

    assert CheckWitness(ADMIN)

    # transfer ont
    ont_balance = Invoke(VERSION, ONT_ADDRESS, "balanceOf",
                         state(CONTRACT_ADDRESS))
    ont_response = Invoke(VERSION, ONT_ADDRESS, "transfer",
                          [state(CONTRACT_ADDRESS, ADMIN, ont_balance)])
    if ont_response != INVOKE_SUCCESS:
        raise Exception("contract upgrade - transfer ont failed")

    # transfer ong
    ong_balance = Invoke(VERSION, ONG_ADDRESS, "balanceOf",
                         state(CONTRACT_ADDRESS))
    ong_response = Invoke(VERSION, ONG_ADDRESS, "transfer",
                          [state(CONTRACT_ADDRESS, ADMIN, ong_balance)])
    if ong_response != INVOKE_SUCCESS:
        raise Exception("contract upgrade - transfer ong failed")

    # migrate avm
    migrate_response = Migrate(code, "", "", "", "", "", "")
    if not migrate_response:
        raise Exception("contract upgrade - migrate avm failed")

    Notify(["upgrade", "success"])

    return True
Exemple #3
0
def upgrade(code):
    """
    upgrade current smart contract to new smart contract.
    :param code:new smart contract avm code.
    :return: True or raise exception.
    """
    owner = getOwner()
    assert (CheckWitness(owner))

    ongBalance = Invoke(0, ONG_ADDRESS, 'balanceOf', state(CONTRACT_ADDRESS))
    res = Invoke(0, ONG_ADDRESS, "transfer", [state(CONTRACT_ADDRESS, owner, ongBalance)])
    if res != b'\x01':
        assert (False)

    ontBalance = Invoke(0, ONT_ADDRESS, 'balanceOf', state(CONTRACT_ADDRESS))
    res = Invoke(0, ONT_ADDRESS, "transfer", [state(CONTRACT_ADDRESS, owner, ontBalance)])
    if res != b'\x01':
        assert (False)

    # upgrade smart contract
    res = Migrate(code, "", "", "", "", "", "")
    if not res:
        assert (False)

    Notify(["upgrade smart contract"])

    return True
Exemple #4
0
def migrateContract(code, needStorage, name, version, author, email,
                    description):
    RequireWitness(Owner)
    res = Migrate(code, needStorage, name, version, author, email, description)
    Require(res)
    Notify(["Migrate Contract successfully"])
    return True
Exemple #5
0
def upgrade(code, needStorage, name, version, author, email, description):
    """
    upgrade current smart contract to new smart contract.
    :param code:new smart contract avm code.
    :return: True or raise exception.
    """
    owner = getOwner()
    assert (CheckWitness(owner))

    ontBalance = _getSelfONTBalance()
    if ontBalance > 0:
        res = Invoke(0, ONT_ADDRESS, "transfer", [state(CONTRACT_ADDRESS, owner, ontBalance)])
        assert (res)

    assert (_tryUnboundOng())
    ongBalance = _getSelfOngBalance()
    if ongBalance > 0:
        res = Invoke(0, ONG_ADDRESS, "transfer", [state(CONTRACT_ADDRESS, owner, ongBalance)])
        assert (res)
    # upgrade smart contract
    res = Migrate(code, needStorage, name, version, author, email, description)
    if not res:
        assert (False)
    Notify(["upgrade", AddressFromVmCode(code)])
    return True
def Migration(contractName, caller, keyNo, avmCode, needStorage, name, version,
              author, email, description):
    """
    :param avmCode:
    :param needStorage:
    :param name:
    :param version:
    :param author:
    :param email:
    :param description:
    :return:
    """
    # Only contract owner can migrate contract
    VerifyCaller('MigrateContract', caller, keyNo)

    newContractHash = AddressFromVmCode(avmCode)
    res = Migrate(avmCode, needStorage, name, version, author, email,
                  description)
    if res:
        Notify([
            "Smart contract has been migrated successfully", contractName,
            newContractHash
        ])
        return True
    else:
        return False
Exemple #7
0
def MigrateContract(code):
    addr = Get(GetContext(), KeyOwnerAddress)
    assert (len(addr) != 0)
    assert (CheckWitness(addr))

    success = Migrate(code, True, "name", "version", "author", "email",
                      "description")
    assert (success)
    Notify(["Migrate successfully", success])
    return success
def MigrateContract(code):
    """
    Note that the existing contract will be replaced by the newly migrated contract
    :param code: your avm code
    :return:
    """
    res = Migrate(code, True, "name", "version", "author", "email", "description")
    assert(res)
    Notify(["Migrate successfully"])
    return True
def MigrateContract(args):
    """
    Note that the existing contract will be replaced by the newly migrated contract
    :param code: your avm code
    :return:
    """
    # maybe index out of range
    success = Migrate(args[0], args[1], args[2], args[3], args[4], args[5],
                      args[6])
    Notify(["Migrate successfully"])
    return True
Exemple #10
0
def migrateContract(code, needStorage, name, version, author, email, description):
    """
    admin can migrate contract
    :param code: new contract's avm code
    :param needStorage: if need storage default true
    :param name: contract's name
    :param version: contract's version
    :param author: contract's author
    :param email: contract's email
    :param description: contract's description
    :return: bool
    """
    assert (CheckWitness(Admin))
    res = Migrate(code, needStorage, name, version, author, email, description)
    assert (res)
    Notify(["Migrate Contract successfully"])
    return True
Exemple #11
0
def upgrade(code, needStorage, name, version, author, email, description):
    """
    upgrade current smart contract to new smart contract.
    :param code:new smart contract avm code.
    :return: True or raise exception.
    """
    owner = getOwner()
    assert (CheckWitness(owner))

    # upgrade smart contract
    res = Migrate(code, needStorage, name, version, author, email, description)
    if not res:
        assert (False)

    Notify(["upgrade smart contract"])

    return True
Exemple #12
0
def migrateContract(code, needStorage, name, version, author, email,
                    description):
    RequireWitness(Dev1)
    param = state(ContractAddress)
    totalOngAmount = Invoke(0, ONGAddress, 'balanceOf', param)
    newContractHash = AddressFromVmCode(code)
    res = _transferONGFromContact(newContractHash, totalOngAmount)
    Require(res)
    if res == True:
        res = Migrate(code, needStorage, name, version, author, email,
                      description)
        Require(res)
        Notify(["Migrate Contract successfully", Dev1])
        return True
    else:
        # Error: 501, MigrateContractError, transfer ONG to new contract error
        Notify(["Error", 501])
        return False
Exemple #13
0
def migrateContract(code, needStorage, name, version, author, email,
                    description):
    RequireWitness(Admin)
    # == Please Make sure transfer all the asset within the old contract to the new Contract
    # == If you do not transfer the assets including ONG, ONT, or OEP4 out,
    # == that means these assets will be out of your control for good.
    newReversedContractHash = AddressFromVmCode(code)
    res = _transferONGFromContact(newReversedContractHash, getTotalOng())
    Require(res)
    if res == True:
        res = Migrate(code, needStorage, name, version, author, email,
                      description)
        Require(res)
        Notify(["Migrate Contract successfully", Admin, GetTime()])
        return True
    else:
        Notify(["MigrateContractError", "transfer ONG to new contract error"])
        return False
Exemple #14
0
def migrateContract(code, needStorage, name, version, author, email,
                    description):
    RequireWitness(Admin)
    Require(_whenNotPaused() == False)
    param = state(SelfContractAddress)
    totalOngAmount = Invoke(0, ONGAddress, 'balanceOf', param)
    totalOntAmount = Invoke(0, ONTAddress, 'balanceOf', param)
    # Option1: TODO
    # newContractHash = AddressFromVmCode(code)
    # res = _tranferNativeAsset(ONGAddress, SelfContractAddress, newContractHash, totalOngAmount)
    # assert (res)

    # Option2: make sure there is no ong left
    Require(totalOngAmount == 0 and totalOntAmount == 0)

    res = Migrate(code, needStorage, name, version, author, email, description)
    Require(res)
    Notify(["migreate"])
    return True
def migrate(code, needStorage, name, version, author, email, description):
    """
    migrate this contract
    :param code:
    :param needStorage:
    :param name:
    :param version:
    :param author:
    :param email:
    :param description:
    :return: True means success, False or raising exception means failure.
    """
    newAddr = AddressFromVmCode(code)
    res = Invoke(SHARD_VERSION, XSHARD_ASSET_ADDR, 'oep4Migrate', newAddr)
    assert (res)
    res = Migrate(code, needStorage, name, version, author, email, description)
    assert (res)
    Notify(["Migrate successfully"])
    return True
Exemple #16
0
def migrateContract(code, needStorage, name, version, author, email, description):
    """
    only Owner can migrate contract
    can migrate this contract to a new contract
    the code is new contract's AVM code
    old contract's all data will transfer to new contract
    :param code: new contract code
    :param needStorage: True
    :param name: ""
    :param version: ""
    :param author: ""
    :param email: ""
    :param description: ""
    :return: bool
    """
    RequireWitness(Owner)
    res = Migrate(code, needStorage, name, version, author, email, description)
    Require(res)
    Notify(["Migrate Contract successfully"])
    return True
Exemple #17
0
def upgrade(code, needStorage, name, version, author, email, description):
    """
    upgrade current smart contract to new smart contract.
    :param code:new smart contract avm code.
    :return: True or raise exception.
    """
    assert (CheckWitness(Get(GetContext(), OPERATOR_PREFIX)))
    newContractHash = AddressFromVmCode(code)
    newContractAddr = bytearray_reverse(newContractHash)
    ontBalance = _getSelfONTBalance()
    if ontBalance > 0:
        res = Invoke(0, ONT_ADDRESS, "transfer",
                     [state(CONTRACT_ADDRESS, newContractAddr, ontBalance)])
        assert (res)

    assert (_tryUnboundOng())
    ongBalance = _getSelfOngBalance()
    if ongBalance > 0:
        res = Invoke(0, ONG_ADDRESS, "transfer",
                     [state(CONTRACT_ADDRESS, newContractAddr, ongBalance)])
        assert (res)

    # transfer all the asset locked within lockproxy contract to the new contract
    fahListInfo = Get(GetContext(), FROM_ASSET_LIST_KEY)
    if len(fahListInfo) > 0:
        fahList = Deserialize(fahListInfo)
        for e in fahList:
            amount = getBalanceFor(e)
            if amount > 0:
                assert (_transferFromContract(e, newContractAddr,
                                              newContractAddr))

    # upgrade smart contract
    res = Migrate(code, needStorage, name, version, author, email, description)
    assert (res)

    Notify(["upgrade smart contract"])

    return True
Exemple #18
0
def MigrateContract(code, needStorage, name, version, author, email,
                    description):
    RequireWitness(Admin)
    res = Migrate(code, needStorage, name, version, author, email, description)
    Require(res)
    return True