Пример #1
0
 def place_order(self,
                 order_info: models.OrderInfo,
                 account=None) -> "order id":
     account = account or self.web3.eth.defaultAccount
     event_filter = self.contract.eventFilter('OrderInitiated',
                                              {'filter': {
                                                  'from': account
                                              }})
     offered_price = self.ONE_ETH_IN_WEI * order_info.value
     transaction = {'value': offered_price, 'from': account}
     tx_hash = self.contract.functions.placeOrder(
         order_info.desc_hash, order_info.buyer_rsa_pubkey,
         order_info.seller, order_info.proxy, order_info.secondary_proxy,
         order_info.proxy_value,
         order_info.time_allowed).transact(transaction)
     logging.debug(
         "Thank you for using CPChain! Initiated Tx hash {tx}".format(
             tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     order_event_list = event_filter.get_new_entries()
     if len(order_event_list) == 0:
         order_id = -1
     else:
         order_id = order_event_list[0]['args']['orderId']
     logging.debug("TransactionID: {:d}".format(order_id))
     return order_id
Пример #2
0
 def dispute(self, order_id, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).buyerDispute(order_id)
     logging.debug(
         "You have started a dispute! Tx hash {tx}".format(tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #3
0
 def confirm_order(self, order_id, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).confirmDeliver(order_id)
     logging.debug("Thank you for confirming deliver! Tx hash {tx}".format(
         tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #4
0
 def withdraw_order(self, order_id, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).buyerWithdraw(order_id)
     logging.debug(
         "Thank you for your using! Order is withdrawn, Tx hash {tx}".
         format(tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #5
0
 def claim_timeout(self, order_id, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).sellerClaimTimedOut(
         order_id)
     logging.debug(
         "Your money is claimed because of time out! Tx hash {tx}".format(
             tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #6
0
 def handle_dispute(self, order_id, result, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).proxyJudge(
         order_id, result)
     logging.debug(
         "You have submit the result for dispute on CPChain! Tx hash {tx}".
         format(tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #7
0
 def claim_relay(self, order_id, relay_hash, account=None):
     account = account or self.web3.eth.defaultAccount
     transaction = {'value': 0, 'from': account}
     tx_hash = self.contract.transact(transaction).deliverMsg(
         relay_hash, order_id)
     logging.debug(
         "You have registered relay of file on CPChain! Tx hash {tx}".
         format(tx=tx_hash))
     wait_for_transaction_receipt(self.web3, tx_hash)
     return tx_hash
Пример #8
0
 def get_order_num(self) -> "number of orders":
     order_num = self.contract.call().numOrders()
     logging.debug("Total number of orders: {:d}\n".format(order_num))
     return order_num
Пример #9
0
 def query_order(self, order_id) -> models.OrderInfo:
     order_record = self.contract.call().orderRecords(order_id)
     logging.debug("Order record NO.{:d}: {record}\n".format(
         order_id, record=order_record))
     return order_record