def multiple_transfer_txs(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array): m = len(dest_array) btcneeded = m * (fee_each + dust * 4) coloraddress = databases.first_coloraddress_from_sourceaddress( sourceaddress) result = "No Color Found" responses = [] if len(coloraddress) > 0: coloramt = sum(coloramt_array) inputdata = find_transfer_inputs(fromaddr, coloraddress, coloramt, btcneeded) inputs = inputdata[0] inputcoloramt = inputdata[1] n = 0 while n < len(coloramt_array) and inputcoloramt > 0: print "What I'm inputting: " + str(inputs) print "" d = create_transfer_tx(fromaddr, dest_array[n], fee_each, privatekey, coloramt_array[n], inputs, inputcoloramt, "") r = d[1] print r inputs = r[1:len(r)] print inputs responses.append(d[0]) inputcoloramt = inputcoloramt - coloramt_array[n] print "new input color amt: " + str(inputcoloramt) n = n + 1 return responses
def colorholders(color_address=None): answer=databases.color_holders(color_address) if len(answer)==0: color_address=databases.first_coloraddress_from_sourceaddress(color_address) if not color_address is None: answer=databases.color_holders(color_address) else: answer="" colordata=databases.dbexecute("select * from colors where color_address='"+color_address+"';",True) source_address="not found" color_name="not found" if len(colordata)>0: source_address=colordata[0][1] color_name=colordata[0][3] if color_name=="color_name": color_name="" jsonresponse={} jsonresponse['owners']=[] jsonresponse['color_address']=color_address jsonresponse['issuing_address']=source_address jsonresponse['color_name']=color_name for x in answer: r={} r['public_address']=x r['quantity']=answer[x] jsonresponse['owners'].append(r) answer=json.dumps(jsonresponse) response=make_response(str(answer), 200) response.headers['Content-Type'] = 'application/json' response.headers['Access-Control-Allow-Origin']= '*' return response
def multiple_transfer_txs(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array): m=len(dest_array) btcneeded=m*(fee_each+dust*4) coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress) result="No Color Found" responses=[] if len(coloraddress)>0: coloramt=sum(coloramt_array) inputdata=find_transfer_inputs(fromaddr, coloraddress, coloramt, btcneeded) inputs=inputdata[0] inputcoloramt=inputdata[1] n=0 while n<len(coloramt_array) and inputcoloramt>0: print "What I'm inputting: "+str(inputs) print "" d=create_transfer_tx(fromaddr, dest_array[n], fee_each, privatekey, coloramt_array[n], inputs,inputcoloramt,"") r=d[1] print r inputs=r[1:len(r)] print inputs responses.append(d[0]) inputcoloramt=inputcoloramt-coloramt_array[n] print "new input color amt: "+str(inputcoloramt) n=n+1 return responses
def transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array, othermeta): m = len(dest_array) btcneeded = fee_each * (1 + m / 12) + dust * m coloraddress = databases.first_coloraddress_from_sourceaddress( sourceaddress) result = None #"No Color Found" inputcoloramt = 0 responses = [] if not coloraddress is None: if len(coloraddress) > 0: print "finding inputs for " print str(fromaddr) + " / " + str(coloraddress) + " / " + str( sum(coloramt_array)) + " / " + str( btcneeded) + " / source= " + str(sourceaddress) inputs = find_transfer_inputs(fromaddr, coloraddress, sum(coloramt_array), btcneeded) print "inputs" print inputs print "" inputcoloramt = inputs[1] inputs = inputs[0] result = create_transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, coloramt_array, inputs, inputcoloramt, "") return result, inputcoloramt
def transfer_tx(fromaddr, dest, fee, privatekey, sourceaddress, coloramt, othermeta): btcneeded=fee+dust*4 coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress) result='' if len(coloraddress)>0: coloramt=int(coloramt) inputdata=find_transfer_inputs(fromaddr, coloraddress, coloramt, btcneeded) inputs=inputdata[0] inputcoloramt=inputdata[1] result=create_transfer_tx(fromaddr, dest, fee, privatekey, coloramt, inputs, inputcoloramt, othermeta) return result
def transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array, othermeta): m=len(dest_array) btcneeded=m*(fee_each+dust*4) coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress) result="No Color Found" responses=[] if len(coloraddress)>0: inputs=find_transfer_inputs(fromaddr, coloraddress, sum(coloramt_array), btcneeded) print "inputs" print inputs print "" inputcoloramt=inputs[1] inputs=inputs[0] result=create_transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, coloramt_array, inputs, inputcoloramt, "") return result, inputcoloramt
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)
def transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, sourceaddress, coloramt_array, othermeta): m=len(dest_array) btcneeded=fee_each*(1+m/12)+dust*m coloraddress=databases.first_coloraddress_from_sourceaddress(sourceaddress) result=None #"No Color Found" inputcoloramt=0 responses=[] if not coloraddress is None: if len(coloraddress)>0: print "finding inputs for " print str(fromaddr)+" / "+ str(coloraddress)+" / " +str(sum(coloramt_array))+" / "+str(btcneeded) inputs=find_transfer_inputs(fromaddr, coloraddress, sum(coloramt_array), btcneeded) print "inputs" print inputs print "" inputcoloramt=inputs[1] inputs=inputs[0] result=create_transfer_tx_multiple(fromaddr, dest_array, fee_each, privatekey, coloramt_array, inputs, inputcoloramt, "") return result, inputcoloramt
def colorholders(color_address=None): answer = databases.color_holders(color_address) if len(answer) == 0: color_address = databases.first_coloraddress_from_sourceaddress( color_address) if not color_address is None: answer = databases.color_holders(color_address) else: answer = "" colordata = databases.dbexecute( "select * from colors where color_address='" + color_address + "';", True) source_address = "not found" color_name = "not found" if len(colordata) > 0: source_address = colordata[0][1] color_name = colordata[0][3] if color_name == "color_name": color_name = "" jsonresponse = {} jsonresponse['owners'] = [] jsonresponse['color_address'] = color_address jsonresponse['issuing_address'] = source_address jsonresponse['color_name'] = color_name for x in answer: r = {} r['public_address'] = x['public_address'] r['quantity'] = x['quantity'] jsonresponse['owners'].append(r) answer = json.dumps(jsonresponse) response = make_response(str(answer), 200) response.headers['Content-Type'] = 'application/json' response.headers['Access-Control-Allow-Origin'] = '*' return response
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)