def release_funds(self, order_id):
        """
        This function should be called to release funds from a disputed contract after
        the moderator has resolved the dispute and provided his signature.
        """
        if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")):
            file_path = os.path.join(DATA_FOLDER, "purchases", "in progress", order_id + ".json")
            outpoints = json.loads(self.db.purchases.get_outpoint(order_id))
        elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "in progress", order_id + ".json")):
            file_path = os.path.join(DATA_FOLDER, "store", "contracts", "in progress", order_id + ".json")
            outpoints = json.loads(self.db.sales.get_outpoint(order_id))

        with open(file_path, 'r') as filename:
            contract = json.load(filename, object_pairs_hook=OrderedDict)

        outputs = []

        moderator_fee = int(round(float(contract["dispute_resolution"]
                                        ["resolution"]["moderator_fee"]) * 100000000))
        if moderator_fee > 0:
            outputs.append({'value': moderator_fee,
                            'address': contract["dispute_resolution"]["resolution"]["moderator_address"]})

        if "buyer_payout" in contract["dispute_resolution"]["resolution"]:
            buyer_address = contract["buyer_order"]["order"]["refund_address"]
            outputs.append({'value': int(round(float(contract["dispute_resolution"]
                                                     ["resolution"]["buyer_payout"]) * 100000000)),
                            'address': buyer_address})

        if "vendor_payout" in contract["dispute_resolution"]["resolution"]:
            vendor_address = contract["vendor_order_confirmation"]["invoice"]["payout"]["address"]
            outputs.append({'value': int(round(float(contract["dispute_resolution"]
                                                     ["resolution"]["vendor_payout"]) * 100000000)),
                            'address': vendor_address})

        tx = BitcoinTransaction.make_unsigned(outpoints, outputs, testnet=self.protocol.multiplexer.testnet)
        chaincode = contract["buyer_order"]["order"]["payment"]["chaincode"]
        redeem_script = str(contract["buyer_order"]["order"]["payment"]["redeem_script"])
        masterkey = bitcointools.bip32_extract_key(KeyChain(self.db).bitcoin_master_privkey)
        childkey = derive_childkey(masterkey, chaincode, bitcointools.MAINNET_PRIVATE)

        own_sig = tx.create_signature(childkey, redeem_script)

        signatures = []
        for index in range(0, len(outpoints)):
            sig_ob = {"index": index, "signatures": []}
            for s in own_sig:
                if int(s["index"]) == index:
                    sig_ob["signatures"].append(s["signature"])
            for s in contract["dispute_resolution"]["resolution"]["tx_signatures"]:
                if int(s["index"]) == index:
                    sig_ob["signatures"].append(s["signature"])
            signatures.append(sig_ob)

        tx.multisign(signatures, redeem_script)
        tx.broadcast(self.protocol.multiplexer.blockchain)
        self.db.transactions.add_transaction(tx.to_raw_tx())
        self.log.info("broadcasting payout tx %s to network" % tx.get_hash())

        if self.db.purchases.get_purchase(order_id) is not None:
            self.db.purchases.update_status(order_id, 6)
        elif self.db.sales.get_sale(order_id) is not None:
            self.db.sales.update_status(order_id, 6)
dataset/ETHPy150Open OpenBazaar/OpenBazaar-Server/market/network.py/Server.release_funds/original