Beispiel #1
0
    async def update_contents(self, **params):
        """Updates users content row
		Accepts:
		- txid
		- cid
		- description
		- write_price
		- read_price
		- confirmed
		- coinid
		"""
        if params.get("message"):
            params = json.loads(params.get("message", "{}"))

        if not params:
            return {"error": 400, "reason": "Missed required fields"}

        txid = params.get("txid")

        coinid = params.get("coinid").upper()

        client = MotorClient()
        database = client[coinid]
        content_collection = database[settings.CONTENT]

        content = await content_collection.find_one({"txid": txid})

        if not content:
            return {
                "error": 404,
                "reason":
                "Update content. Content with txid %s not found" % txid
            }

        if content.get("hash"):
            client = SignedTornadoClient(settings.bridges[coinid])
            cid = await client.request(method_name="getcid",
                                       hash=content["hash"])

            await content_collection.find_one_and_update(
                {"txid": txid}, {"$set": {
                    "cid": int(cid)
                }})
            await content_collection.find_one_and_update(
                {"txid": txid}, {"$set": {
                    "hash": None
                }})

        updated = await content_collection.find_one({"txid": txid})

        return {i: updated[i] for i in updated if i != "_id"}
Beispiel #2
0
class Permissions:
    """Interact with storage about permissions
    """
    client_storage = SignedTornadoClient(settings.storageurl)

    async def getpermissions(self, **kwargs):
        result = await self.client_storage.request(
            method_name="getpermissions", **kwargs)
        return result

    async def _changepermissions(self, **kwargs):
        result = await self.client_storage.request(
            method_name="changepermissions", **kwargs)
        return result
Beispiel #3
0
class Balance:
    """Make request to balance
    """
    client_balance = SignedTornadoClient(settings.balanceurl)

    async def addaddr(self, **params):
        result = await self.client_balance.request(method_name="addaddr",
                                                   **params)
        return result

    async def addwallet(self, **params):
        result = await self.client_balance.request(method_name="addwallet",
                                                   **params)
        return result

    async def incbalance(self, **params):
        result = await self.client_balance.request(method_name="incbalance",
                                                   **params)
        return result

    async def decbalance(self, **params):
        result = await self.client_balance.request(method_name="decbalance",
                                                   **params)
        return result

    async def getbalance(self, **params):
        result = await self.client_balance.request(method_name="getbalance",
                                                   **params)
        return result

    async def depositbalance(self, **params):
        result = await self.client_balance.request(
            method_name="depositbalance", **params)
        return result

    async def undepositbalance(self, **params):
        result = await self.client_balance.request(
            method_name="undepositbalance", **params)
        return result

    async def confirmbalance(self, **params):
        result = await self.client_balance.request(
            method_name="confirmbalance", **params)
        return result
class Blockchain(GenesisClass):
    """Make request to bridge
    """
    client_bridge = SignedTornadoClient(settings.bridgeurl)

    def setendpoint(self, endpoint):
        self.client_bridge.endpoint = endpoint

    async def lastblockcid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="lastblockid",
                                                  *args,
                                                  **kwargs)
        return result

    async def balance(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="balance",
                                                  *args,
                                                  **kwargs)
        return result

    async def ipfscat(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="ipfscat",
                                                  *args,
                                                  **kwargs)
        return result

    async def getcid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="getcid",
                                                  *args,
                                                  **kwargs)
        return result

    async def readbycid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="readbycid",
                                                  *args,
                                                  **kwargs)
        return result

    async def ownerbycid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="ownerbycid",
                                                  *args,
                                                  **kwargs)
        return result

    async def descrbycid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="descrbycid",
                                                  *args,
                                                  **kwargs)
        return result

    async def makecid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="makecid",
                                                  *args,
                                                  **kwargs)
        return result

    async def setdescrforcid(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="setdescrforcid",
                                                  *args,
                                                  **kwargs)
        return result

    async def last_access_string(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="lastaccessstring", *args, **kwargs)
        return result

    async def changeowner(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="changeowner",
                                                  *args,
                                                  **kwargs)
        return result

    async def sellcontent(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="sellcontent",
                                                  *args,
                                                  **kwargs)
        return result

    async def setprice(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="setprice",
                                                  *args,
                                                  **kwargs)
        return result

    async def getprice(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="getprice",
                                                  *args,
                                                  **kwargs)
        return result

    async def makeoffer(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="make_offer",
                                                  *args,
                                                  **kwargs)
        return result

    async def rejectoffer(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="reject_offer",
                                                  *args,
                                                  **kwargs)
        return result

    async def addreview(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="add_review",
                                                  *args,
                                                  **kwargs)
        return result

    async def getallcontent(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="getallcontent",
                                                  *args,
                                                  **kwargs)
        return result

    async def getsinglecontent(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="getsinglecontent", *args, **kwargs)
        return result

    async def getuserscontent(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="getuserscontent", *args, **kwargs)
        return result

    async def getreviews(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="get_reviews",
                                                  *args,
                                                  **kwargs)
        return result

    async def getoffer(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="get_offer",
                                                  *args,
                                                  **kwargs)
        return result

    async def getbuyeroffers(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="get_buyer_offers", *args, **kwargs)
        return result

    async def getcidoffers(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="get_cid_offers",
                                                  *args,
                                                  **kwargs)
        return result

    async def setwriteprice(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="set_write_price", *args, **kwargs)
        return result

    async def setreadprice(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="set_read_price",
                                                  *args,
                                                  **kwargs)
        return result

    async def getwriteprice(self, *args, **kwargs):
        result = await self.client_bridge.request(
            method_name="get_write_price", *args, **kwargs)
        return result

    async def getreadprice(self, *args, **kwargs):
        result = await self.client_bridge.request(method_name="get_read_price",
                                                  *args,
                                                  **kwargs)
        return result
class Balance(GenesisClass):
    """Make request to balance
    """
    client_balance = SignedTornadoClient(settings.balanceurl)

    async def addaddr(self, **params):
        result = await self.client_balance.request(method_name="addaddr",
                                                   **params)
        return result

    async def addwallet(self, **params):
        result = await self.client_balance.request(method_name="addwallet",
                                                   **params)
        return result

    async def add_active(self, **params):
        result = await self.client_balance.request(method_name="add_active",
                                                   **params)
        return result

    async def sub_active(self, **params):
        result = await self.client_balance.request(method_name="sub_active",
                                                   **params)
        return result

    async def get_wallets(self, **params):
        result = await self.client_balance.request(method_name="get_wallets",
                                                   **params)
        return result

    async def freeze(self, **params):
        result = await self.client_balance.request(method_name="freeze",
                                                   **params)
        return result

    async def unfreeze(self, **params):
        result = await self.client_balance.request(method_name="unfreeze",
                                                   **params)
        return result

    async def sub_frozen(self, **params):
        result = await self.client_balance.request(method_name="sub_frozen",
                                                   **params)
        return result

    async def add_frozen(self, **params):
        result = await self.client_balance.request(method_name="add_frozen",
                                                   **params)
        return result

    async def confirmbalance(self, **params):
        result = await self.client_balance.request(method_name="sub_frozen",
                                                   **params)

        result = await self.client_balance.request(method_name="add_active",
                                                   **params)
        return result

    async def registerdeal(self, **params):
        result = await self.client_balance.request(method_name="registerdeal",
                                                   **params)
        return result
Beispiel #6
0
import os
import sys
import logging

from utils.tornado_components.web import SignedTornadoClient, RobustTornadoClient

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

import settings
from pdms.qtum_bridge.robin8_billing import robin8_billing

billing = robin8_billing.Robin8_Billig(settings.BILLING_FILE)

client_storage = SignedTornadoClient(settings.storageurl)
client_balance = SignedTornadoClient(settings.balanceurl)


async def upload_content_fee(*args, **kwargs):
    """Estimating uploading content
	"""
    cus = kwargs.get("cus")
    owneraddr = kwargs.get("owneraddr")
    description = kwargs.get("description")
    coinid = kwargs.get("coinid", "PUT")

    #Check if required fields exists
    if not all([cus, owneraddr, description]):
        return {"error": 400, "reason": "Missed required fields"}

    # Get upload content fee
Beispiel #7
0
class Account(GenesisClass):
    balance = Balance()
    blockchain = Blockchain()
    permissions = Permissions()
    mailer = Mail()
    client_storage = SignedTornadoClient(settings.storageurl)
    client_withdraw = TornadoClient(settings.withdrawhost)

    validator = {
        "QTUM": lambda x: Qtum.public_key_to_hex_address(x),
        "ETH": lambda x: R8_Ethereum.public_key_to_checksum_address(x),
        "PUT": lambda x: Qtum.public_key_to_hex_address(x),
    }

    withdraw_address = {
        "PUTTEST": lambda x: bip32addresses.Bip32Addresses.address_to_hex(x),
        "QTUMTEST": lambda x: x
    }

    ident_offer = {0: "read_access", 1: "write_access"}

    async def withdraw_fee(self, coinid):
        if not isinstance(coinid, str):
            return {
                "error": 400,
                "reason": "Coinid type error. Must be string."
            }
        fees = {
            "BTC": 0.001 * pow(10, 8),
            "ETH": 0.01 * pow(10, 8),
            "QTUM": 0.5 * pow(10, 8),
            "PUT": 50 * pow(10, 8),
            "LTC": 0.05 * pow(10, 8)
        }
        try:
            fee = fees[coinid]
        except KeyError:
            fee = 0
        return fee

    async def logsource(self, **params):
        result = await self.client_storage.request(method_name="logsource",
                                                   **params)
        return result

    async def createaccount(self, **params):
        result = await self.client_storage.request(method_name="createaccount",
                                                   **params)
        return result

    async def getaccountdata(self, **params):
        result = await self.client_storage.request(
            method_name="getaccountdata", **params)
        return result

    async def createwallet(self, **params):
        result = await self.client_storage.request(method_name="createwallet",
                                                   **params)
        return result

    async def getnews(self, **params):
        result = await self.client_storage.request(method_name="getnews",
                                                   **params)
        return result

    async def setnews(self, **params):
        result = await self.client_storage.request(method_name="setnews",
                                                   **params)
        return result

    async def getaccountbywallet(self, **params):
        result = await self.client_storage.request(
            method_name="getaccountbywallet", **params)
        return result

    async def updatelevel(self, **params):
        result = await self.client_storage.request(method_name="updatelevel",
                                                   **params)
        return result

    async def insertoffer(self, **params):
        result = await self.client_storage.request(method_name="insertoffer",
                                                   **params)
        return result

    async def getoffer(self, **params):
        result = await self.client_storage.request(method_name="getoffer",
                                                   **params)
        return result

    async def removeoffer(self, **params):
        result = await self.client_storage.request(method_name="removeoffer",
                                                   **params)
        return result

    async def updateoffer(self, **params):
        result = await self.client_storage.request(method_name="updateoffer",
                                                   **params)
        return result

    async def mailedconfirm(self, **params):
        result = await self.client_storage.request(method_name="mailedconfirm",
                                                   **params)
        return result

    async def getoffers(self, **params):
        result = await self.client_storage.request(method_name="getoffers",
                                                   **params)
        return result

    async def getuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="getuserscontent", **params)
        return result

    async def setuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="setuserscontent", **params)
        return result

    async def updateuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="updateuserscontent", **params)
        return result

    async def getallcontent(self):
        result = await self.client_storage.request(method_name="getallcontent")
        return result

    async def getsinglecontent(self, cid):
        result = await self.client_storage.request(
            method_name="getsinglecontent", cid=cid)
        return result

    async def changecontentowner(self, **params):
        result = await self.client_storage.request(
            method_name="changecontentowner", **params)
        return result

    async def setaccessstring(self, **params):
        result = await self.client_storage.request(
            method_name="setaccessstring", **params)
        return result

    async def getreviews(self, **params):
        result = await self.client_storage.request(method_name="getreviews",
                                                   **params)
        return result

    async def setreview(self, **params):
        result = await self.client_storage.request(method_name="setreview",
                                                   **params)
        return result

    async def updatereview(self, **params):
        result = await self.client_storage.request(method_name="updatereview",
                                                   **params)
        return result

    async def writedeal(self, **params):
        result = await self.client_storage.request(method_name="writedeal",
                                                   **params)
        return result

    async def getdeals(self, **params):
        result = await self.client_storage.request(method_name="getdeals",
                                                   **params)
        return result

    async def updatedescription(self, **params):
        result = await self.client_storage.request(
            method_name="updatedescription", **params)
        return result

    async def setwriteprice(self, **params):
        result = await self.client_storage.request(method_name="setwriteprice",
                                                   **params)
        return result

    async def setreadprice(self, **params):
        result = await self.client_storage.request(method_name="setreadprice",
                                                   **params)
        return result

    async def changeowner(self, **params):
        result = await self.client_storage.request(method_name="changeowner",
                                                   **params)
        return result

    async def sharecontent(self, **params):
        result = await self.client_storage.request(method_name="sharecontent",
                                                   **params)
        return result

    async def withdraw(self, **params):
        result = await self.client_withdraw.request(method_name="withdraw",
                                                    **params)
        return result
Beispiel #8
0
    async def insert_news(self, **params):
        """Inserts news for account
		Accepts:
			- event_type
			- cid
			- access_string (of buyer)
			- buyer_pubkey
			- buyer address
			- owner address
			- price
			- offer type
			- coin ID
		Returns:
			- dict with result
		"""
        if params.get("message"):
            params = json.loads(params.get("message", "{}"))

        if not params:
            return {"error": 400, "reason": "Missed required fields"}
        event_type = params.get("event_type")
        cid = params.get("cid")

        access_string = params.get("access_string")

        buyer_pubkey = params.get("buyer_pubkey")

        buyer_address = params.get("buyer_address")

        owneraddr = params.get("owneraddr")

        price = params.get("price")

        offer_type = int(params.get("offer_type", -1))

        coinid = params.get("coinid").upper()

        # Get address of content owner and check if it exists
        if coinid in settings.AVAILABLE_COIN_ID:
            client_bridge = SignedTornadoClient(settings.bridges[coinid])
        else:
            return {"error": 400, "reason": "Invalid coin ID"}

        owneraddr = await client_bridge.request(method_name="ownerbycid",
                                                cid=cid)

        # Get sellers account
        seller = await getaccountbywallet(wallet=owneraddr)
        if "error" in seller.keys():
            return seller

        # Connect to news table
        news_collection = self.database[settings.NEWS]

        # Get sellers price
        client_bridge.endpoint = settings.bridges[coinid]
        if offer_type == 1:
            seller_price = await client_bridge.request(
                method_name="get_write_price", cid=cid)
        elif offer_type == 0:
            seller_price = await client_bridge.request(
                method_name="get_read_price", cid=cid)

        row = {
            "offer_type": ident_offers[offer_type],
            "buyer_address": buyer_address,
            "cid": cid,
            "access_string": access_string,
            "buyer_pubkey": buyer_pubkey,
            "seller_price": seller_price,
            "buyer_price": price,
            "account_id": seller["id"],
            "event_type": event_type,
            "coinid": coinid
        }

        # Update counter inside accounts table
        database = client[settings.DBNAME]
        collection = database[settings.ACCOUNTS]
        await collection.find_one_and_update({"id": int(seller["id"])},
                                             {"$inc": {
                                                 "news_count": 1
                                             }})
        await collection.find_one({"id": int(seller["id"])})

        # Insert data to news table
        await news_collection.insert_one(row)

        return {"result": "ok"}
Beispiel #9
0
import json
import os
# Third-party
from jsonrpcserver.aio import methods
from jsonrpcclient.tornado_client import TornadoClient
from motor.motor_tornado import MotorClient
from pymongo import MongoClient
import pymongo
# Local packages
import settings
from utils.tornado_components import mongo
from utils.qtum_utils.qtum import Qtum
from utils.tornado_components.web import SignedTornadoClient, RobustTornadoClient
from utils.bip32keys.r8_ethereum.r8_eth import R8_Ethereum

client_bridge = SignedTornadoClient(settings.bridgeurl)
client_email = RobustTornadoClient(settings.emailurl)

client = MotorClient()

ident_offers = {0: "read_access", 1: "write_access"}

validator = {
    "QTUM": lambda x: Qtum.public_key_to_hex_address(x),
    "ETH": lambda x: R8_Ethereum.public_key_to_checksum_address(x)
}

coin_ids = settings.AVAILABLE_COIN_ID + ["PUT"]


def verify(func):
Beispiel #10
0
class Account(AbstractClass):
    balance = Balance()
    blockchain = Blockchain()
    permissions = Permissions()
    client_storage = SignedTornadoClient(settings.storageurl)

    async def createaccount(self, **params):
        result = await self.client_storage.request(method_name="createaccount",
                                                   **params)
        return result

    async def getaccountdata(self, **params):
        result = await self.client_storage.request(
            method_name="getaccountdata", **params)
        return result

    async def createwallet(self, **params):
        result = await self.client_storage.request(method_name="createwallet",
                                                   **params)
        return result

    async def getnews(self, **params):
        result = await self.client_storage.request(method_name="getnews",
                                                   **params)
        return result

    async def setnews(self, **params):
        result = await self.client_storage.request(method_name="setnews",
                                                   **params)
        return result

    async def getaccountbywallet(self, **params):
        result = await self.client_storage.request(
            method_name="getaccountbywallet", **params)
        return result

    async def updatelevel(self, **params):
        result = await self.client_storage.request(method_name="updatelevel",
                                                   **params)
        return result

    async def insertoffer(self, **params):
        result = await self.client_storage.request(method_name="insertoffer",
                                                   **params)
        return result

    async def getoffer(self, **params):
        result = await self.client_storage.request(method_name="getoffer",
                                                   **params)
        return result

    async def removeoffer(self, **params):
        result = await self.client_storage.request(method_name="removeoffer",
                                                   **params)
        return result

    async def updateoffer(self, **params):
        result = await self.client_storage.request(method_name="updateoffer",
                                                   **params)
        return result

    async def mailedconfirm(self, **params):
        result = await self.client_storage.request(method_name="mailedconfirm",
                                                   **params)
        return result

    async def getoffers(self, **params):
        result = await self.client_storage.request(method_name="getoffers",
                                                   **params)
        return result

    async def getuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="getuserscontent", **params)
        return result

    async def setuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="setuserscontent", **params)
        return result

    async def updateuserscontent(self, **params):
        result = await self.client_storage.request(
            method_name="updateuserscontent", **params)
        return result

    async def getallcontent(self):
        result = await self.client_storage.request(method_name="getallcontent")
        return result

    async def getsinglecontent(self, cid):
        result = await self.client_storage.request(
            method_name="getsinglecontent", cid=cid)
        return result

    async def changecontentowner(self, **params):
        result = await self.client_storage.request(
            method_name="changecontentowner", **params)
        return result

    async def setaccessstring(self, **params):
        result = await self.client_storage.request(
            method_name="setaccessstring", **params)
        return result

    async def getreviews(self, **params):
        result = self.client_storage.request(method_name="getreviews",
                                             **params)
        return result

    async def setreview(self, **params):
        result = self.client_storage.request(method_name="setreview", **params)
        return result

    async def updatereview(self, **params):
        result = self.client_storage.request(method_name="updatereview",
                                             **params)
        return result

    async def writedeal(self, **params):
        result = self.client_storage.request(method_name="writedeal", **params)
        return result

    async def getdeals(self, **params):
        result = self.client_storage.request(method_name="getdeals", **params)
        return result

    async def updatedescription(self, **params):
        result = self.client_storage.request(method_name="updatedescription",
                                             **params)
        return result

    async def setwriteprice(self, **params):
        result = self.client_storage.request(method_name="setwriteprice",
                                             **params)
        return result

    async def setreadprice(self, **params):
        result = self.client_storage.request(method_name="setreadprice",
                                             **params)
        return result

    async def changeowner(self, **params):
        result = self.client_storage.request(method_name="changeowner",
                                             **params)
        return result

    async def sharecontent(self, **params):
        result = self.client_storage.request(method_name="sharecontent",
                                             **params)
        return result
Beispiel #11
0
    async def confirmbalance(self, *args, **kwargs):
        """ Confirm balance after trading

        Accepts:
            - message (signed dictionary):
                - "txid" - str
                - "coinid" - str
                - "amount" - int

        Returns:
                - "address" - str
                - "coinid" - str
                - "amount" - int
                - "uid" - int
                - "unconfirmed" - int (0 by default)
                - "deposit" - int (0 by default)

        Verified: True

        """
        # Get data from request
        #if message.get()
        message = json.loads(kwargs.get("message", "{}"))
        txid = message.get("txid")
        coinid = message.get("coinid")
        buyer_address = message.get("buyer_address")
        cid = message.get("cid")

        # Check if required fields exists
        if not all([txid, coinid, cid, buyer_address]):
            return {
                "error": 400,
                "reason": "Confirm balance. Missed required fields"
            }

        client_bridge = SignedTornadoClient(settings.bridges[coinid])
        offer = await client_bridge.request(method_name="get_offer",
                                            cid=cid,
                                            buyer_address=buyer_address)
        # Connect to database
        coinid = "PUT"

        database = client[coinid]
        balance_collection = database[settings.BALANCE]

        amount = int(offer["price"])
        # Try to update balance if exists
        updated = await balance_collection.find_one_and_update(
            {"txid": txid}, {"$inc": {
                "amount": int(amount)
            }})
        if not updated:
            return {
                "error": 404,
                "reason": "Confirm balance. Not found current transaction id"
            }

        # Decrement unconfirmed
        await balance_collection.find_one_and_update(
            {"txid": txid}, {"$inc": {
                "unconfirmed": -amount
            }})

        # Update users level if it is equal two
        client_storage = SignedTornadoClient(settings.storageurl)
        account = await client_storage.request(method_name="getaccountdata",
                                               **{"id": updated["uid"]})
        if "error" in account.keys():
            return {
                "error": 500,
                "reason":
                "While incrementing balance current user was not found"
            }

        if int(account["level"]) == 2:
            await client_storage.request(method_name="updatelevel",
                                         **{
                                             "id": account["id"],
                                             "level": 3
                                         })

        return {i: updated[i] for i in updated if i != "_id" and i != "txid"}
Beispiel #12
0
    async def incbalance(self, *args, **kwargs):
        """ Increments users balance 

        Accepts:
            - message (signed dictionary):
                - "address" - str
                - "amount" - int
                - "uid" - str
                - "coinid" - str

        Returns:
            - dictionary with following fields:
                - "address" - str
                - "coinid" - str
                - "amount" - int
                - "uid" - int
                - "unconfirmed" - int (0 by default)
                - "deposit" - int (0 by default)
                - "txid" - None
                
        """
        # Get data from message
        message = json.loads(kwargs.get("message", "{}"))
        address = message.get("address")
        amount = int(message.get("amount", 0))
        uid = message.get("uid")
        coinid = message.get("coinid")
        txid = message.get("txid")

        # Connect to database
        db = client[coinid]
        balances = db[settings.BALANCE]

        # Check if amount
        if not amount:
            return {"error": 400, "reason": "Funds is zero"}

        # Get account by uid or address
        if uid:
            balance = await balances.find_one({"uid": int(uid)})
        elif address:
            balance = await balances.find_one({"address": address})
        # Increment balance if account exists
        if not balance:
            return {
                "error": 404,
                "reason": "Increment balance. Balance not found"
            }

        # Update balance
        if not txid:
            await balances.find_one_and_update(
                {"address": balance["address"]},
                {"$inc": {
                    "amount": int(amount)
                }})
            result = await balances.find_one({"address": balance["address"]})

        else:
            db = client["PUT"]
            balances = db[settings.BALANCE]
            await balances.find_one_and_update(
                {"uid": balance["uid"]},
                {"$inc": {
                    "unconfirmed": int(amount)
                }})
            result = await balances.find_one({"uid": balance["uid"]})

            await balances.find_one_and_update({"uid": balance["uid"]},
                                               {"$set": {
                                                   "txid": txid
                                               }})

        account_client = SignedTornadoClient(settings.storageurl)
        account = await account_client.request(method_name="getaccountdata",
                                               **{"id": balance["uid"]})

        # Send mail to user
        if account.get("email"):
            client_email = TornadoClient(settings.emailurl)
            email_data = {
                "to":
                account["email"],
                "subject":
                "Robin8 Support",
                "optional":
                "You`ve got %s tokens. Now your balance is %s" %
                (amount / pow(10, 8), int(result["amount"]) / pow(10, 8))
            }
            await client_email.request(method_name="sendmail", **email_data)

        # Return result
        result = {i: result[i] for i in result if i != "_id"}
        result["amount"] = int(result["amount"])
        return result