Ejemplo n.º 1
0
def blocks_outputs(blockend):
  lastblockprocessed=databases.dbexecute("SELECT * FROM META;",True)
  currentblock=bitsource.get_current_block()
  if blockend>currentblock:
    blockend=currentblock
  for i in range(lastblockprocessed[0][0]+1,blockend+1):
    add_output_db(i)
    print "processed block "+str(i)
    databases.dbexecute("UPDATE META SET lastblockdone='"+str(i)+"';",False)
Ejemplo n.º 2
0
def tx_queue_batches():
  current_block=bitsource.get_current_block()
  distinct_senders=databases.dbexecute("select distinct from_public from tx_queue where success='False';",True)
  for sender in distinct_senders:
    sender=sender[0]
    colors=databases.dbexecute("select distinct source_address from tx_queue where from_public='"+sender+"';", True)
    for color in colors:
      color_needed=0
      txs=databases.dbexecute("select * from tx_queue where from_public='"+sender+"' and success='False' and source_address='"+color[0]+"';",True)
      coloramt_array=[]
      dest_array=[]
      fromaddr=sender
      btc_needed=0
      rowlist=[]

      for tx in txs:
        color_needed=color_needed+tx[5]
        btc_needed=btc_needed+(int(tx[3])+int(transactions.dust*100000000)) #INTEGER, IN SATOSHIs
        dest_array.append(tx[2])
        coloramt_array.append(tx[5])
        fee_each=float(tx[3])*0.00000001
        privatekey=tx[1]
        othermeta="multitransfer"
        rowlist.append(tx[10])

      sourceaddress=color[0]
      coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress)
      btc_needed=float(btc_needed)/100000000
      inputs=transactions.find_transfer_inputs(fromaddr, coloraddress, color_needed, btc_needed)
      inputcolortamt=inputs[1]
      inputs=inputs[0]

      try:
        result=transactions.transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array, othermeta)
        result=result[0]
      except:
        print "ERROR processing queued TX from "+str(fromaddr)
        result=None

      if result is None:
        print "No response heard from Bitcoin Network"
      else:
        print "HEARD TX RESULT: "+str(result)

        for id in rowlist:
          dbstring2="update tx_queue set txhash='"+str(result) +"', success='True' where randomid='"+str(id)+"';"
          print dbstring2
          databases.dbexecute(dbstring2,False)
Ejemplo n.º 3
0
def more_blocks(moreblocks):
    currentblock=int(bitsource.get_current_block())
    lastblockprocessed=databases.dbexecute("SELECT * FROM META;",True)
    nextblock=lastblockprocessed[0][0]+moreblocks

    print "starting block " +str(currentblock)
    print "nextblock "+str(nextblock)

    if nextblock>currentblock:
      nextblock=currentblock

    if lastblockprocessed[0][0]<currentblock:
      for i in range(lastblockprocessed[0][0]+1, nextblock+1):
        if i<=currentblock:
          output_db(i)
          print "processed block "+str(i)
          databases.dbexecute("UPDATE META SET lastblockdone='"+str(i)+"';",False)
Ejemplo n.º 4
0
def getblockcount():
    result = bitsource.get_current_block()
    response = make_response(str(result), 200)
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 5
0
def getblockcount():
  result=bitsource.get_current_block()
  response=make_response(str(result), 200)
  response.headers['Access-Control-Allow-Origin']= '*'
  return response
Ejemplo n.º 6
0
def tx_queue_batches():
  current_block=bitsource.get_current_block()
  distinct_senders=databases.dbexecute("select distinct from_public from tx_queue where success='False';",True)

  for sender in distinct_senders:
    sender=sender[0]
    colors=databases.dbexecute("select distinct source_address from tx_queue where from_public='"+sender+"';", True)
    for color in colors:

      if color[0]=='': #IS BTC TRANSFER NOT COLORED
        txs=databases.dbexecute("select * from tx_queue where from_public='"+str(sender)+"' and success='False' and source_address='';",True)

        for x in txs:
          public_address=x[0]
          private_key=x[1]
          amount=x[5]*0.00000001
          destination=x[2]
          fee=os.environ['STANDARD_BTC_FEE']
          #print str(public_address)+" / "+str(amount)+ " / "+str(destination)+" / "+str(fee)
          tx=transactions.make_raw_transaction(public_address,amount,destination, fee)
          tx2=transactions.sign_tx(tx, private_key)
          tx3=transactions.pushtx(tx2)
          if len(tx3)>0:
            databases.dbexecute("update tx_queue set success='True', txhash='"+str(tx3)+"' where randomid='"+str(x[10])+"'", False)

      else:
        color_needed=0
        txs=databases.dbexecute("select * from tx_queue where from_public='"+sender+"' and success='False' and source_address='"+color[0]+"';",True)
        coloramt_array=[]
        dest_array=[]
        fromaddr=sender
        btc_needed=0
        rowlist=[]

        if len(txs)>25:  #limit outputs per TX
          txs=txs[0:25]

        for tx in txs:
          color_needed=color_needed+tx[5]
          fee_each=float(tx[3])*0.00000001
          btc_needed=btc_needed+(int(tx[3])+int(transactions.dust*100000000)) #INTEGER, IN SATOSHIs

          if tx[5]>0:
            dest_array.append(tx[2])
            coloramt_array.append(tx[5])

          privatekey=tx[1]
          othermeta="multitransfer"
          rowlist.append(tx[10])

        sourceaddress=color[0]
        coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress)
        btc_needed=float(btc_needed)/100000000
        inputs=transactions.find_transfer_inputs(fromaddr, coloraddress, color_needed, btc_needed)
        inputcolortamt=inputs[1]
        inputs=inputs[0]

        #try:
        if len(dest_array)>6:
          fee_each=fee_each*(1+len(dest_array)/6)

        result=transactions.transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array, othermeta)
        try:
          result=result[0]
        except:
          result=None
        #except:
        #  print "ERROR processing queued TX from "+str(fromaddr)
      #    result=None

        if result is None:
          print "No response heard from Bitcoin Network"
        else:
          print "HEARD TX RESULT: "+str(result)

          for id in rowlist:
            dbstring2="update tx_queue set txhash='"+str(result) +"', success='True' where randomid='"+str(id)+"';"
            print dbstring2
            databases.dbexecute(dbstring2,False)