Example #1
0
 def updateWithTXAfterRemove(self,prevTXs,TX):
   utxoSet=copy.deepcopy(self.utxoSet)
   #outs
   outputs=utxoSet[TX.hash]
   for idx,txout in enumerate(TX.outs):
     for idx1,output in enumerate(outputs):
       if output["index"]==idx:
         del outputs[idx1]
         break
   if outputs==[]:
     del utxoSet[TX.hash]        
   else:
     utxoSet[TX.hash]=outputs
   #ins
   if TX.isCoinbase() == False:
     for idx,txin in enumerate(TX.ins):
       try:
         outs=utxoSet[txin.prevHash]
       except:
         outs=[]
       if txin.prevHash=="0042cf9d6ad3d4a53c3cce6fbda9e86171b29abd0bfe5af5fe795c15aab2eb95":
         print(utils.obj2json(prevTXs))
       prevTX=prevTXs[txin.prevHash]
       prevOuts = prevTX.outs
       outs.append({
           "index":txin.index,
           "txout":TXout({
               "amount" : prevTX.outs[txin.index].amount,
               "outAddr": prevTX.outs[txin.index].outAddr,
               "script" : prevTX.outs[txin.index].script})
                       })
       utxoSet[txin.prevHash] = outs
   self.utxoSet = utxoSet
   return utxoSet
Example #2
0
File: miner.py Project: youht88/bc
def socketioGetBlocks(range):
  print("*"*20,"getBlocks","*"*20)
  start,end = range
  blocks = node.blockchain.findRangeBlocks(start,end)
  print(start,end,type(blocks),blocks)
  if blocks:
    emit('getBlocksResponse',utils.obj2json(blocks))
Example #3
0
 def __init__(self, **args):
     Transaction.logger = logger.logger
     self.ins = args["ins"]
     self.insLen = len(self.ins)
     self.outs = args["outs"]
     self.outsLen = len(self.outs)
     if "timestamp" in args:
         self.timestamp = args["timestamp"]
     else:
         self.timestamp = int(time.time())
     if "hash" in args:
         self.hash = args["hash"]
     else:
         self.hash = utils.sha256([
             utils.obj2json(self.ins),
             utils.obj2json(self.outs), self.timestamp
         ])
Example #4
0
 def detect_faces(self, *args, **kwargs):
     """
 # the interface form hasn't been decided, so here use the common form
 :param args:
   args[0]: ImageDetectRequest Object
 :param kwargs: dict
   Temporarily not used, remain
 :return:DetectFacesResult Object
 """
     if not isinstance(args[0], DetectFacesRequest):
         raise TypeError(
             "The first argument must be a DetectRequest Object!")
     # here temporary use deepcopy avoid image content be changed
     detect_faces_request = copy.deepcopy(args[0])
     image_detect_request = ImageDetectRequest()
     image_detect_request.set_detect_faces_request(detect_faces_request)
     # if only uri specified, the content will be None
     if image_detect_request.detectFacesRequest is not None \
         and image_detect_request.detectFacesRequest.image is not None:
         image = image_detect_request.detectFacesRequest.image
         self.__check_parameter(image)
         if image.content is not None:
             image_detect_request.detectFacesRequest.image.content = \
               utils.base64_encode(image_detect_request.detectFacesRequest.image.content)
     params = utils.obj2json(image_detect_request)
     headers = utils.auth_headers(self.__method, self.__uri,
                                  self.__set_headers(), self.__credential)
     http_conf = {
         "method": self.__method,
         "host": self.__host,
         "port": self.__port,
         "resource": self.IMAGE_DETECT_RESOURCE,
         "timeout": configs.DEFAULT_CLIENT_TIMEOUT
     }
     response = httpclient.execute_http_request(http_conf, params, headers)
     try:
         result = self.__result2obj(response)
         if result is None:
             raise VisionException(
                 errMsg="error is occurred, the response is none!")
     except VisionException, ve:
         print ve
Example #5
0
File: trader.py Project: youht88/bc
    os.makedirs(CHAINDATA_DIR)
if not os.path.exists(BROADCASTED_BLOCK_DIR):
    os.makedirs(BROADCASTED_BLOCK_DIR)
if not os.path.exists(BROADCASTED_TRANSACTION_DIR):
    os.makedirs(BROADCASTED_TRANSACTION_DIR)

#make node
node = Node({"entryNode": args.entryNode, "me": args.me})

#register me and get all alive ndoe list
node.syncOverallNodes()
#sync blockchain
node.syncOverallChain(save=True)
temp = node.resetUTXO()

log.warning(utils.sha256(utils.obj2json(temp)))

#make pvkey,pbkey,wallet address
youhtWallet = Wallet(me)
jinliWallet = Wallet("jinli")

coinbaseTX = Transaction.newCoinbase(youhtWallet.address)
print(utils.obj2json(coinbaseTX))

#UTXO=node.blockchain.findUTXO(youhtWallet.address)

value = node.utxo.getBalance(youhtWallet.address)
log.warning("{}'s wallet has {}".format(me, value))
value1 = node.utxo.getBalance(jinliWallet.address)
log.warning("jinli's wallet has {}".format(value1))
Example #6
0
File: miner.py Project: youht88/bc
def kadGetbuckets():
  return utils.obj2json(node.dht.buckets.buckets)
Example #7
0
File: miner.py Project: youht88/bc
def kadGetdata():
  return utils.obj2json(node.dht.data)
Example #8
0
File: miner.py Project: youht88/bc
def kadGet(key):
  res = node.dht[key]
  return utils.obj2json(res)