Ejemplo n.º 1
0
    def transfer(self, transferObject):
        url = host + '/asset/transfer'
        transferObjectDict = transferObject.__dict__
        # 打印字典
        # 字典转化为json
        transferObjectJson = json.dumps(transferObjectDict)
        data = transferObjectJson
        print("transferJson=", data)
        result = baseDao.safeRequests(url, data, headers, "")
        if result.status_code == 200:
            jsonResult = result.json()
            print(jsonResult)
            if (jsonResult['retcode'] != 0):
                raise Exception("请求错误,请查看信息:", jsonResult)
            if jsonResult['data'] != '':
                srcUserAsset = UserAsset.UserAsset()
                toUserAsset = UserAsset.UserAsset()
                feeUserAsset = UserAsset.UserAsset()
                dataResult = jsonResult['data']

                srcUserAsset.userAddress = transferObject.srcAccount
                srcUserAsset.assetAddress = dataResult['srcAssetId']

                toUserAsset.userAddress = transferObject.dstAccount
                toUserAsset.assetAddress = dataResult['dstAssetId']
                toUserAsset.money = transferObject.amount

                feeUserAsset.userAddress = transferObject.feeAccount
                feeUserAsset.assetAddress = dataResult['feeAssetId']
                feeUserAsset.money = transferObject.feeAmount
                return srcUserAsset, toUserAsset, feeUserAsset
        return
Ejemplo n.º 2
0
def transferUser(src, to, fee, amount, feeAmount):
    userController = NewUserController.NewUserController()
    userAsset = UserAsset.UserAsset()
    userAssetArray = userController.findAssetId(src)
    assetAddressArray = ""
    money = 0
    for each in userAssetArray:
        money = int(money) + each.money
        assetAddressArray = assetAddressArray + each.assetAddress
    transferObject = NewTransferObject.NewTransferObject()
    transferObject.srcAccount = src.address
    transferObject.srcAccountPublicKey = src.publicKey
    transferObject.srcAccountUid = src.id

    transferObject.dstAccount = to.address
    transferObject.dstAccountPublicKey = to.publicKey
    transferObject.dstAccountUid = to.id

    transferObject.feeAccountPublicKey = fee.publicKey
    transferObject.feeAccount = fee.address
    transferObject.feeAccountUid = fee.id

    transferObject.amount = amount
    transferObject.feeAmount = feeAmount
    transferObject.srcAsset = assetAddressArray
    transferObject.userPrivateKey = src.privateKey
    userController = NewUserController.NewUserController()
    src_money = money
    userController.transfer(src, to, fee, src_money, transferObject)
Ejemplo n.º 3
0
def transferToAllTest(customerName,array,amount,feeAmount):
    try:
        userController = NewUserController.NewUserController()
        list = userController.getUserInfo(customerName)

        src = userController.getBossAccount( customerName)
        for each in array:
            to = list.__getitem__(each[0])
            fee =  list.__getitem__(each[1])
            if (to != {} and fee != {}):

                userAsset = UserAsset.UserAsset()
                userAssetArray = userController.findAssetId(src)
                assetAddressArray = ""
                money = 0
                for each in userAssetArray:
                    money = int(money) + each.money
                    assetAddressArray = assetAddressArray + each.assetAddress
                transferObject = NewTransferObject.NewTransferObject()
                transferObject.srcAccount = src.address
                transferObject.dstAccount = to.address
                transferObject.feeAccount = fee.address
                transferObject.amount = amount
                transferObject.feeAmount = feeAmount
                transferObject.srcAsset = assetAddressArray
                transferObject.userPrivateKey = src.privateKey
                userController = NewUserController.NewUserController()
                src_money = money
                userController.transfer(src, to, fee, src_money, transferObject)
        userController.checkAccount(list)
    except Exception as e:
        print(e)
Ejemplo n.º 4
0
 def updateAsset(self, to):
     userDao = UserDao.UserDao()
     assetAddressArray = to.assetAddress.split(",")
     for assetAddress in assetAddressArray:
         to.assetAddress = assetAddress
         usertAssetObject = UserAsset.UserAsset()
         usertAssetObject = to
         userDao.updateAsset(usertAssetObject)
     pass
Ejemplo n.º 5
0
    def settle(self, settleObject):
        userService = UserService.UserService()
        orgSrc = UserAsset.UserAsset()
        orgSrc.assetAddress = settleObject.srcAsset
        orgSrc.userAddress = settleObject.ownerAccount

        newSrc = userService.settle(settleObject)
        newSrc.money = -settleObject.amount
        orgSrc.status = 1
        userService.updateAsset(orgSrc)
        userService.insertUserAsset(newSrc)
Ejemplo n.º 6
0
def eachTransferToOther(customerName, isTest, array, amount, feeAmount,
                        settleMoney):
    try:
        userController = NewUserController.NewUserController()
        list = userController.getUserInfo(customerName)
        src = {}
        to = {}
        fee = {}
        first = True
        for each in array:
            first = True
            src = list.__getitem__(each[0])
            to = list.__getitem__(each[1])
            fee = list.__getitem__(each[2])
            if (to != {} and src != {} and fee != {}):
                userAsset = UserAsset.UserAsset()
                userAssetArray = userController.findAssetId(src)
                assetAddressArray = ""
                money = 0
                for each in userAssetArray:
                    money = int(money) + each.money
                    if first == True:
                        assetAddressArray = assetAddressArray + each.assetAddress
                        first = False
                    elif first == False:
                        assetAddressArray = assetAddressArray + "," + each.assetAddress
                transferObject = NewTransferObject.NewTransferObject()
                transferObject.srcAccount = src.address
                transferObject.srcAccountUid = src.id
                transferObject.srcAccountPublicKey = src.publicKey

                transferObject.dstAccount = to.address
                transferObject.dstAccountUid = to.id
                transferObject.dstAccountPublicKey = to.publicKey

                if fee != {}:
                    transferObject.feeAccount = fee.address
                    transferObject.feeAccountUid = fee.id
                    transferObject.feeAccountPublicKey = fee.publicKey
                transferObject.amount = amount
                if feeAmount != "":
                    transferObject.feeAmount = feeAmount
                transferObject.srcAsset = assetAddressArray
                transferObject.userPrivateKey = src.privateKey
                userController = NewUserController.NewUserController()
                src_money = money
                userController.transfer(src, to, fee, src_money,
                                        transferObject)

        userController.checkAccount(list, isTest)
    except Exception as e:
        e = e.with_traceback()
        print(e)
Ejemplo n.º 7
0
    def transfer(self, src, to, fee, srcmoney, transferObject):
        newUserService = NewUserService.NewUserService()
        money = srcmoney
        amount = transferObject.amount

        feeAmount = transferObject.feeAmount
        print("transObject=", transferObject)
        newSrc, newTo, newFee = newUserService.transfer(transferObject)
        srcAsset = UserAsset.UserAsset()
        toAsset = UserAsset.UserAsset()
        feeAsset = UserAsset.UserAsset()

        srcAsset.status = 1
        srcAsset.userAddress = transferObject.srcAccount

        srcAsset.assetAddress = transferObject.srcAsset

        toAsset.userAddress = transferObject.dstAccount
        toAsset.assetAddress = ""
        toAsset.money = 0
        if fee != {}:
            feeAsset.userAddress = transferObject.feeAccount
            feeAsset.assetAddress = ""
            feeAsset.money = 0
        if feeAmount != "":
            newSrc.money = -amount - feeAmount
        else:
            newSrc.money = -amount
        to.status = 1
        to.money = amount
        if fee != {}:
            fee.status = 1
            fee.money = feeAmount
        newUserService.updateAsset(srcAsset)
        newUserService.insertUserAsset(newSrc)
        newUserService.updateAsset(toAsset)
        newUserService.insertUserAsset(newTo)
        if fee != {}:
            newUserService.updateAsset(feeAsset)
        newUserService.insertUserAsset(newFee)
Ejemplo n.º 8
0
 def newIssue(self, bossAccount, amount):
     userDao = UserDao.UserDao()
     issueObject = IssueObject.IssueObject()
     issueObject.amount = amount
     issueObject.createUserAccountAddress = bossAccount.address
     issueObject.sourceId = "wsy_qian_yi_zhuan_yong_bao_wen"
     issueObject.content = "{\"wsy\":\"wsy_qian_yi_zhuan_yong_bao_wen\"}"
     issueObject.unit = "wsy_qian_yi_zhuan_yong_bao_wen"
     jsonResult = userDao.issue(issueObject)
     userAsset = UserAsset.UserAsset()
     userAsset.assetAddress, userAsset.status, userAsset.userAddress, userAsset.money, userAsset.sourceId = \
     jsonResult['assetId'], "0", bossAccount.address, amount, issueObject.sourceId
     return userAsset
Ejemplo n.º 9
0
    def findAssetId(self, userAsset):
        sql = """
                   select userAddress,assetAddress,money from user_asset  where status=0 and userAddress =%s limit 0,5
                   """
        array = []
        param = []
        param.append(userAsset.userAddress)
        try:
            baseDao = BaseDao.BaseDao()
            result = baseDao.executeGetAllSql(sql, param)

            for row in result:
                newUserAsset = UserAsset.UserAsset()
                newUserAsset.userAddress = row[0]
                newUserAsset.assetAddress = row[1]
                newUserAsset.money = row[2]
                array.append(newUserAsset)
            return array
        except Exception as e:
            print(e)
        return
Ejemplo n.º 10
0
    def settle(self, settleObject):
        url = host + '/asset/settle'
        settleObjectDict = settleObject.__dict__
        # 打印字典

        # 字典转化为json
        settleObjectJson = json.dumps(settleObjectDict)

        data = settleObjectJson

        result = baseDao.safeRequests(url, data, headers, "")
        print(result)
        if result.status_code == 200:
            jsonResult = result.json()
            if (jsonResult['retcode'] != 0):
                raise Exception("请求错误,请查看信息:", jsonResult)
            if jsonResult['data'] != '':
                srcUserAsset = UserAsset.UserAsset()
                dataResult = jsonResult['data']

                srcUserAsset.userAddress = settleObject.ownerAccount
                srcUserAsset.assetAddress = dataResult['srcAssetId']
                return srcUserAsset
Ejemplo n.º 11
0
 def findAssetId(self, userAddress):
     userDao = UserDao.UserDao()
     userAsset = UserAsset.UserAsset()
     userAsset.userAddress = userAddress
     userAssetArray = userDao.findAssetId(userAsset)
     return userAssetArray