コード例 #1
0
    def post(self, exchange_contract_id):
        post_data = request.get_json()

        reserve_token_id = post_data['reserve_token_id']

        deploying_address = g.user.transfer_account.blockchain_address

        reserve_token = Token.query.get(reserve_token_id)

        if not reserve_token:
            response_object = {
                'message': f'Reserve token not found for ID {reserve_token}',
            }

            return make_response(jsonify(response_object)), 404

        exchange_contract = ExchangeContract()

        exchange_contract.add_reserve_token(reserve_token)
        db.session.add(exchange_contract)
        db.session.commit()

        exchange_contract_id = exchange_contract.id

        @copy_current_request_context
        def deploy(_deploying_address, _exchange_contract_id):
            contract_registry_address = bt.deploy_exchange_network(
                _deploying_address)
            _exchange_contract = ExchangeContract.query.get(
                _exchange_contract_id)
            _exchange_contract.contract_registry_blockchain_address = contract_registry_address

            db.session.commit()

        t = threading.Thread(target=deploy,
                             args=(deploying_address, exchange_contract_id))
        t.daemon = True
        t.start()

        response_object = {
            'message': 'success',
            'data': {
                'exchange_contract':
                exchange_contract_schema.dump(exchange_contract).data
            }
        }

        return make_response(jsonify(response_object)), 201
コード例 #2
0
ファイル: conftest.py プロジェクト: gtaschuk/SempoBlockchain
    def deploy_and_add_smart_token(name, symbol, reserve_ratio_ppm, exchange_contract=None):
        smart_token_result = bt.deploy_smart_token(
            deploying_address=deploying_address,
            name=name, symbol=symbol, decimals=18,
            reserve_deposit_wei=10,
            issue_amount_wei=1000,
            contract_registry_address=registry_address,
            reserve_token_address=reserve_token.address,
            reserve_ratio_ppm=reserve_ratio_ppm
        )

        smart_token_address = smart_token_result['smart_token_address']
        subexchange_address = smart_token_result['subexchange_address']

        smart_token = Token(address=smart_token_address, name=name, symbol=symbol, token_type=TokenType.LIQUID)
        smart_token.decimals = 18

        db.session.add(smart_token)

        if exchange_contract is None:

            exchange_contract = ExchangeContract(
                blockchain_address=subexchange_address,
                contract_registry_blockchain_address=registry_address
            )

        exchange_contract.add_reserve_token(reserve_token)
        exchange_contract.add_token(smart_token, subexchange_address, reserve_ratio_ppm)

        return smart_token, exchange_contract