Пример #1
0
    def getMemo(self, from_account, to_account, text=None, data=None):
        if (data):
            from_account = data["from"]
            to_account = data["to"]
            #data = data["message"]

        #import traceback
        #try:
        #	from_account = self.getAccount(from_account)
        #except:
        #	traceback.print_exc()
        #	#print(from_account
        #	#print(from_account)
        try:
            to_account = self.getAccount(to_account)
            to_account_name = to_account["name"]
        except:
            to_account_name = to_account
            to_account = None
        #invert = True

        #to_account = self.getAccount(to_account)
        try:
            from_account = self.getAccount(from_account)
            from_account_name = from_account["name"]
        except:
            from_account_name = from_account
            from_account = None

        #print("TO:", to_account)
        #print("FROM:", from_account)
        #if (self.isCachedAccount(to_account['name'])):
        #	invert = False
        #else:
        #	if not(from_account):
        #		showerror(from_account_name)
        #		return False

        from bitshares.memo import Memo
        memoObj = Memo(
            from_account=None,  #from_account,
            to_account=None,  #to_account,
            bitshares_instance=self.bts)
        memoObj.chain_prefix = self.chain_prefix()
        memoObj.from_account = from_account
        memoObj.to_account = to_account
        if text:
            # { nonce, to from, message } json:
            return memoObj.encrypt(text)
        # plaintext:
        return {
            'message': memoObj.decrypt(data),
            'from': from_account_name,  #from_account['name']
            'to': to_account_name,  #to_account['name'],
        }
Пример #2
0
logger.info(f'Gateway running..')
logger.info(f'NODE_URL: {NODE_URL}')
logger.info(f'GATEWAY_ACCOUNT_ID: {GATEWAY_ACCOUNT_ID}')
logger.info(f'GATEWAY_ACCOUNT_WIF: {GATEWAY_ACCOUNT_WIF[:5]}..')
logger.info(f'EOS_NODE_URL: {eosio_config.url}')
logger.info(f'EOS_NODE_PORT: {eosio_config.port}')
logger.info(f'ISSUER_WIF: {ISSUER_WIF}')
logger.info(f'ISSUER_NAME: {ISSUER_NAME}')
logger.info(f'ISSUE_ASSET: {ISSUE_ASSET}')

for op in Blockchain().stream(['transfer']):
    amount = float(op['amount']['amount']) / 100000

    if op['to'] != GATEWAY_ACCOUNT_ID:
        continue

    if 'memo' not in op:
        logger.warn(f'No memo: {op["from"]} | {amount} | {op["block_num"]}')
        continue

    try:
        # TODO Валидация есть ли такой eos юзер
        eos_receiver = m.decrypt(op['memo'])
    except Exception as e:
        logger.exception(
            f'Invalid memo {op["from"]} | {amount} | {op["block_num"]}')
        raise e

    # TODO Обработка исключений
    eos_issue(eos_receiver, amount)
from bitshares.blockchain import Blockchain
from bitshares.account import Account
from bitshares.asset import Asset
from bitshares.memo import Memo
import btsDiceGameTransactions

nodeForConnections = 'wss://api.bitsharesdex.com'

blockchain = Blockchain(node=nodeForConnections, mode='head')

btsDGT = btsDiceGameTransactions

memo = Memo()
memo.blockchain.wallet.unlock('superSecretPassword')

for op in blockchain.stream(['transfer']):
    payee = Account(op['to']).name
    if payee == 'bts-dice-game':
        payor = Account(op['from']).name
        decryptedMemo = int(memo.decrypt(op['memo']))
        amount = op['amount']['amount'] / 100000
        btsDGT.play_game(payor, amount, decryptedMemo)