Ejemplo n.º 1
0
 def request_ledger(self, options):
     """
     获取某一账本具体信息
     :param options: dict{ledger_index: Number, ledger_hash: hash, string}
     :return:
     """
     cmd = 'ledger'
     filter = True
     req = Request(self, cmd, filter)
     if not isinstance(options, dict):
         req.message['type'] = Exception('invalid options type')
         return req
     if options.__contains__('ledger_index') and is_number(
             options['ledger_index']):
         req.message['ledger_index'] = int(options['ledger_index'])
     elif options.__contains__('ledger_hash') and is_valid_hash(
             options['ledger_hash']):
         req.message['ledger_hash'] = options['ledger_hash']
     if 'full' in options.keys() and isinstance(options['full'], bool):
         req.message['full'] = options['full']
         filter = False
     if 'expand' in options.keys() and isinstance(options['expand'], bool):
         req.message['expand'] = options['expand']
         filter = False
     if 'transactions' in options.keys() and isinstance(
             options['transactions'], bool):
         req.message['transactions'] = options['transactions']
         filter = False
     if 'accounts' in options.keys() and isinstance(options['accounts'],
                                                    bool):
         req.message['accounts'] = options['accounts']
         filter = False
     return req
Ejemplo n.º 2
0
    def request_account_offers(self, options):
        """
        查询账户挂单
        :param options: account(required): the query account
        :return:
        """
        req = Request(self, None, None)
        if not isinstance(options, dict):
            req.message['type'] = Exception('invalid options type')
            return req

        return self.request_account('account_offers', options, req)
Ejemplo n.º 3
0
    def request_account_info(self, options):
        """
        请求账号信息
        :param options: {account:’xxx’}
        :return:
        """
        req = Request(self, None, None)
        if not isinstance(options, dict):
            req.message['type'] = Exception('invalid options type')
            return req

        return self.request_account('account_info', options, req)
Ejemplo n.º 4
0
    def request_account_tums(self, options):
        """
        account tums    请求账号能交易代币
        return account supports currency, including
        send currency and receive currency
        :param options: account(required): the query account
        :return:
        """
        req = Request(self, None, None)
        if not isinstance(options, dict):
            req.message['type'] = Exception('invalid options type')
            return req

        return self.request_account('account_currencies', options, req)
Ejemplo n.º 5
0
    def request_account_relations(self, options):
        req = Request(self, None, None)
        if not isinstance(options, dict):
            req.message['type'] = Exception('invalid options type')
        if not ~RelationTypes.index(options['type']):
            req.message['relation_type'] = Exception('invalid realtion type')
            return req

        if options['type'] == 'trust':
            return self.request_account('account_lines', options, req)
        elif options['type'] == 'authorize' or options['type'] == 'freeze':
            return self.request_account('account_relation', options, req)

        req.message['msg'] = Exception('relation should not go here')
        return req
Ejemplo n.º 6
0
 def request_tx(self, options):
     """
     查询某一交易具体信息
     :param options:
     :return:
     """
     req = Request(self, 'tx', None)
     if not isinstance(options, dict):
         req.message['type'] = Exception('invalid options type')
         return req
     if not is_valid_hash(options['hash']):
         req.message['hash'] = Exception('invalid tx hash')
         return req
     req.message['transaction'] = options['hash']
     return req
Ejemplo n.º 7
0
 def request_ledger_closed(self):
     """
     获取最新账本信息
     request last closed ledger index and hash
     :return:   {Request}
     """
     return Request(self, 'ledger_closed', None)
Ejemplo n.º 8
0
 def request_server_info(self):
     """
     请求服务器底层信息
     request server info
     return version, ledger, state and node id
     no option is required
     :return: {Request}
     """
     return Request(self, 'server_info', None)
Ejemplo n.º 9
0
    def request_order_book(self, options):
        request = Request(self, 'book_offers', None)
        if not isinstance(options, object):
            request.message['type'] = Exception('invalid options type')
            return request

        # taker_gets = options['taker_gets'] or options['pays']
        if options.__contains__('taker_gets'):
            taker_gets = options['taker_gets']
        elif options.__contains__('pays'):
            taker_gets = options['pays']
        if not utils.is_valid_amount0(taker_gets):
            request.message['taker_gets'] = Exception(
                'invalid taker gets amount')
            return request

        # taker_pays = options['taker_pays'] or options['gets']
        if options.__contains__('taker_pays'):
            taker_pays = options['taker_pays']
        elif options.__contains__('gets'):
            taker_pays = options['gets']
        if not utils.is_valid_amount0(taker_pays):
            request.message['taker_pays'] = Exception(
                'invalid taker pays amount')
            return request

        if options.__contains__('limit'):
            if isinstance(options['limit'], int):
                options['limit'] = int(options['limit'])

        request.message['taker_gets'] = taker_gets
        request.message['taker_pays'] = taker_pays
        if options.__contains__('taker'):
            request.message['taker'] = options['taker']
        else:
            request.message['taker'] = Config.ACCOUNT_ONE
        # request.message['taker'] = options['taker'] if options['taker'] else utils['ACCOUNT_ONE']
        if options.__contains__('limit'):
            request.message['limit'] = options['limit']
        return request
Ejemplo n.º 10
0
    def request_account_tx(self, options):
        data = []
        request = Request(self, 'account_tx', None)
        if not isinstance(options, object):
            request.message['type'] = Exception('invalid options type')
            return request

        if not Wallet.is_valid_address(options['account']):
            request.message['account'] = Exception(
                'account parameter is invalid')
            return request

        request.message['account'] = options['account']

        if options.__contains__('ledger_min') and Number(
                options['ledger_min']):
            request.message['ledger_index_min'] = Number(options['ledger_min'])
        else:
            request.message['ledger_index_min'] = 0
        if options.__contains__('ledger_max') and Number(
                options['ledger_max']):
            request.message['ledger_index_max'] = Number(options['ledger_max'])
        else:
            request.message['ledger_index_max'] = -1

        if options.__contains__('limit') and isinstance(options['limit'], int):
            if options['limit'] > 0:  # limit must be positive
                request.message['limit'] = options['limit']

        if options.__contains__('offset') and Number(options['offset']):
            request.message['offset'] = Number(options['offset'])

        if options.__contains__('marker') and isinstance(
                options['marker'], 'object') and Number(
                    options.marker['ledger']) != None and Number(
                        options['marker']['seq']) != None:
            request.message['marker'] = options['marker']

        if options.__contains__('forward') and isinstance(
                options['forward'], 'boolean'):
            request.message['forward'] = options['forward']

        return request
Ejemplo n.º 11
0
 def subscribe(self, streams):
     request = Request(self, "subscribe", None)
     if streams:
         request.message['streams'] = streams if isinstance(
             streams, list) else [streams]
     return request