def watch(self, entries):
        company_list = company_list_factory.get()

        for entry in entries:
            token_address = entry["args"]["tokenAddress"]

            if not token_list.is_registered(token_address):
                continue

            token = token_factory.get_coupon(token_address)

            company = company_list.find(token.owner_address)

            metadata = {
                "company_name": company.corporate_name,
                "token_address": token_address,
                "token_name": token.name,
                "exchange_address": IBET_CP_EXCHANGE_CONTRACT_ADDRESS,
                "token_type": "IbetCoupon"
            }

            notification = Notification()
            notification.notification_id = self._gen_notification_id(entry, 1)
            notification.notification_type = NotificationType.BUY_AGREEMENT.value
            notification.priority = 1
            notification.address = entry["args"]["buyAddress"]
            notification.block_timestamp = self._gen_block_timestamp(entry)
            notification.args = dict(entry["args"])
            notification.metainfo = metadata
            db_session.merge(notification)
 def db_merge(self, token_contract, entries):
     company_list = company_list_factory.get()
     for entry in entries:
         # Exchangeアドレスが移転元の場合、処理をSKIPする
         tradable_exchange = token_contract.functions.tradableExchange(
         ).call()
         if entry["args"]["from"] == tradable_exchange:
             continue
         token_owner_address = token_contract.functions.owner().call()
         token_name = token_contract.functions.name().call()
         company = company_list.find(token_owner_address)
         metadata = {
             "company_name": company.corporate_name,
             "token_address": entry["address"],
             "token_name": token_name,
             "exchange_address": "",
             "token_type": "IbetCoupon"
         }
         notification = Notification()
         notification.notification_id = self._gen_notification_id(entry)
         notification.notification_type = NotificationType.TRANSFER.value
         notification.priority = 0
         notification.address = entry["args"]["to"]
         notification.block_timestamp = self._gen_block_timestamp(entry)
         notification.args = dict(entry["args"])
         notification.metainfo = metadata
         db_session.merge(notification)
コード例 #3
0
    def watch(self, entries):
        company_list = company_list_factory.get()

        for entry in entries:
            token_address = entry["args"]["tokenAddress"]

            if not token_list.is_registered(token_address):
                continue

            token = token_factory.get_membership(token_address)

            company = company_list.find(token.owner_address)

            metadata = {
                "company_name": company.corporate_name,
                "token_address": token_address,
                "token_name": token.name,
                "exchange_address": IBET_MEMBERSHIP_EXCHANGE_CONTRACT_ADDRESS,
                "token_type": "IbetMembership"
            }

            notification = Notification()
            notification.notification_id = self._gen_notification_id(entry, 2)
            notification.notification_type = NotificationType.SELL_SETTLEMENT_NG.value
            notification.priority = 2
            notification.address = entry["args"]["sellAddress"]
            notification.block_timestamp = self._gen_block_timestamp(entry)
            notification.args = dict(entry["args"])
            notification.metainfo = metadata
            db_session.merge(notification)
    def watch(self, entries):
        company_list = company_list_factory.get()

        for entry in entries:
            token_address = entry["args"]["tokenAddress"]

            if not token_list.is_registered(token_address):
                continue

            # NOTE: OTCExchangeはShare以外のトークンでも利用される可能性があるため、
            #       token_templateがShareではない場合処理をスキップする
            if token_list.get_token(token_address)[1] != "IbetShare":
                continue

            token = token_factory.get_share(token_address)

            company = company_list.find(token.owner_address)

            metadata = {
                "company_name": company.corporate_name,
                "token_address": token_address,
                "token_name": token.name,
                "exchange_address": IBET_SHARE_EXCHANGE_CONTRACT_ADDRESS,
                "token_type": "IbetShare"
            }

            notification = Notification()
            notification.notification_id = self._gen_notification_id(entry, 2)
            notification.notification_type = NotificationType.SELL_SETTLEMENT_NG.value
            notification.priority = 2
            notification.address = entry["args"]["sellAddress"]
            notification.block_timestamp = self._gen_block_timestamp(entry)
            notification.args = dict(entry["args"])
            notification.metainfo = metadata
            db_session.merge(notification)
    def watch(self, entries):
        company_list = company_list_factory.get()

        for entry in entries:
            token_address = entry["args"]["tokenAddress"]

            if not token_list.is_registered(token_address):
                continue

            token = token_factory.get_straight_bond(token_address)

            company = company_list.find(token.owner_address)

            metadata = {
                "company_name": company.corporate_name,
                "token_address": token_address,
                "token_name": token.name,
                "exchange_address": IBET_SB_EXCHANGE_CONTRACT_ADDRESS,
                "token_type": "IbetStraightBond"
            }

            notification = Notification()
            notification.notification_id = self._gen_notification_id(entry)
            notification.notification_type = NotificationType.CANCEL_ORDER.value
            notification.priority = 0
            notification.address = entry["args"]["accountAddress"]
            notification.block_timestamp = self._gen_block_timestamp(entry)
            notification.args = dict(entry["args"])
            notification.metainfo = metadata
            db_session.merge(notification)
コード例 #6
0
 def watch(self, entries):
     for entry in entries:
         notification = Notification()
         notification.notification_id = self._gen_notification_id(entry)
         notification.notification_type = NotificationType.PAYMENT_ACCOUNT_BAN.value
         notification.priority = 2
         notification.address = entry["args"]["account_address"]
         notification.block_timestamp = self._gen_block_timestamp(entry)
         notification.args = dict(entry["args"])
         notification.metainfo = {}
         db_session.merge(notification)
コード例 #7
0
def notification():
    if request.method == "GET":
        a = request.args.get('a', None, int)
        if a is not None and a != 0:
            return jsonify(
                {k: v
                 for k, v in NotificationType.__members__.items()})
        nts = Notification.query.filter_by(username=session['username']).all()
        if nts is None:
            abort(404)
        return jsonify(nts)
    elif request.method == "POST":
        action = request.args.get('action', None)
        if action == "add":
            # TODO: rate limit / 60s retry
            try:
                # 如果有未验证的玩意先要求之前验证
                if Notification.query.filter_by(
                        username=session['username']).first() is not None:
                    raise InputValidationError('请先完成之前的验证')
                ntype = request.form.get('type', None, int)
                nt_new = Notification()
                nt_new.read_from_form(request.form)
                if ntype is None:
                    abort(400)
                nt_new.type = NotificationType(ntype)
                nt_new.username = session['username']
                db.session.add(nt_new)
                new_challenge = ChallengeReason(ChallengeReason.PLACEHOLDER,
                                                '')
                if nt_new.type == NotificationType.EMAIL:
                    new_challenge.type = ChallengeReason.EMAIL_VERIFY
                    new_challenge.note = nt_new.address
                    token = create_challenge(new_challenge, commit=False)
                    send_email_sendcloud(
                        nt_new.address, '烧饼米表 邮箱验证请求',
                        '您好,使用此链接来验证您的邮箱:%s' % url_for(
                            'challenge_verify', token=token, _external=True))
                db.session.commit()
            except InputValidationError as e:
                flash(e.message, 'error')
                return redirect(url_for('user.notification'))
            except exc.IntegrityError as e:
                abort(409)
            except exc.DBAPIError as e:
                print(e)
                abort(500)
            return jsonify({"msg": "created"}), 201
        else:
            ntid = request.form.get('id', None, int)
            if ntid is None:
                abort(400)
            nt_now = Notification.query.filter_by(id=ntid).first_or_404()
            if action == "delete":
                db.session.delete(nt_now)
                db.session.commit()
                return jsonify({'msg': 'deleted'})
            else:
                abort(400)
コード例 #8
0
 def db_merge(self, token_contract, entries):
     company_list = company_list_factory.get()
     for entry in entries:
         token_owner_address = token_contract.functions.owner().call()
         token_name = token_contract.functions.name().call()
         company = company_list.find(token_owner_address)
         metadata = {
             "company_name": company.corporate_name,
             "token_address": entry["address"],
             "token_name": token_name,
             "exchange_address": "",
             "token_type": "IbetShare"
         }
         notification = Notification()
         notification.notification_id = self._gen_notification_id(entry)
         notification.notification_type = NotificationType.ALLOT.value
         notification.priority = 1
         notification.address = entry["args"]["accountAddress"]
         notification.block_timestamp = self._gen_block_timestamp(entry)
         notification.args = dict(entry["args"])
         notification.metainfo = metadata
         db_session.merge(notification)
コード例 #9
0
    def _insert_test_data(self, session):
        self.session = session  # HACK: updateでcommitされてしまう対策

        n = Notification()
        n.notification_id = "0x00000021034300000000000000"
        n.notification_type = "SampleNotification1"
        n.priority = 1
        n.address = "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
        n.is_read = True
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 6, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {
            "aaa": "bbb",
        }
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000021034000000000000000"
        n.notification_type = "SampleNotification2"
        n.priority = 1
        n.address = "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
        n.is_read = False
        n.is_flagged = False
        n.is_deleted = True
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 5, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000011034000000000000000"
        n.notification_type = "SampleNotification3"
        n.priority = 2
        n.address = "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
        n.is_read = False
        n.is_flagged = True
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 4, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000011032000000000000000"
        n.notification_type = "SampleNotification4"
        n.priority = 1
        n.address = "0x7E5F4552091A69125d5DfCb7b8C2659029395B00"
        n.is_read = True
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 3, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000001034000000000000000"
        n.notification_type = "SampleNotification5"
        n.priority = 0
        n.address = "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
        n.is_read = False
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 2, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        session.add(n)

        session.commit()
コード例 #10
0
    def _insert_test_data(self, session):

        n = Notification()
        n.notification_id = "0x00000021034300000000000000"
        n.notification_type = "NewOrder"
        n.priority = 1
        n.address = self.address
        n.is_read = True
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 6, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {
            "aaa": "bbb",
        }
        n.created = datetime.strptime("2022/01/01 15:20:30",
                                      '%Y/%m/%d %H:%M:%S')
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000021034000000000000000"
        n.notification_type = "NewOrderCounterpart"
        n.priority = 1
        n.address = self.address
        n.is_read = False
        n.is_flagged = False
        n.is_deleted = True
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 5, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        n.created = datetime.strptime("2022/01/01 16:20:30",
                                      '%Y/%m/%d %H:%M:%S')
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000011034000000000000000"
        n.notification_type = "NewOrder"
        n.priority = 2
        n.address = self.address
        n.is_read = False
        n.is_flagged = True
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 4, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        n.created = datetime.strptime("2022/01/01 17:20:30",
                                      '%Y/%m/%d %H:%M:%S')
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000011032000000000000000"
        n.notification_type = "NewOrderCounterpart"
        n.priority = 1
        n.address = self.address_2
        n.is_read = True
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 3, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        n.created = datetime.strptime("2022/01/01 18:20:30",
                                      '%Y/%m/%d %H:%M:%S')
        session.add(n)

        n = Notification()
        n.notification_id = "0x00000001034000000000000000"
        n.notification_type = "NewOrder"
        n.priority = 0
        n.address = self.address
        n.is_read = False
        n.is_flagged = False
        n.is_deleted = False
        n.deleted_at = None
        n.block_timestamp = datetime(2017, 2, 10, 10, 0, 0)
        n.args = {
            "hoge": "fuga",
        }
        n.metainfo = {}
        n.created = datetime.strptime("2022/01/01 19:20:30",
                                      '%Y/%m/%d %H:%M:%S')
        session.add(n)