Exemple #1
0
def newwebdeclaration():
    jsoninput = json.loads(request.data)
    fromaddr = str(jsoninput['public_address'])
    fee_each = jsoninput['fee_each']
    privatekey = str(jsoninput['private_key'])
    tx = ''
    if 'plain_message' in jsoninput:
        message = str(jsoninput['plain_message'])
        dest = fromaddr
        specific_inputs = addresses.unspent(fromaddr)
        tx = transactions.send_op_return(fromaddr, dest, fee_each, message,
                                         privatekey, specific_inputs)
        print tx
    elif 'hash_message' in jsoninput:
        hashmessage = str(jsoninput['hash_message'])

        message = hashlib.sha256(hashmessage).digest()
        dest = fromaddr
        specific_inputs = addresses.unspent(fromaddr)
        tx = transactions.send_op_return(fromaddr, dest, fee_each, message,
                                         privatekey, specific_inputs)
        print tx

    jsonresponse = {}
    jsonresponse['transaction_hash'] = tx
    jsonresponse = json.dumps(jsonresponse)
    response = make_response(str(jsonresponse), 200)
    response.headers['Content-Type'] = 'application/json'
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Exemple #2
0
def newwebdeclaration():
  jsoninput=json.loads(request.data)
  fromaddr=str(jsoninput['public_address'])
  fee_each=jsoninput['fee_each']
  privatekey=str(jsoninput['private_key'])
  tx=''
  if 'plain_message' in jsoninput:
    message=str(jsoninput['plain_message'])
    dest=fromaddr
    specific_inputs=addresses.unspent(fromaddr)
    tx = transactions.send_op_return(fromaddr, dest, fee_each, message, privatekey, specific_inputs)
    print tx
  elif 'hash_message' in jsoninput:
    hashmessage=str(jsoninput['hash_message'])

    message=hashlib.sha256(hashmessage).digest()
    dest=fromaddr
    specific_inputs=addresses.unspent(fromaddr)
    tx = transactions.send_op_return(fromaddr, dest, fee_each, message, privatekey, specific_inputs)
    print tx

  jsonresponse={}
  jsonresponse['transaction_hash']=tx
  jsonresponse=json.dumps(jsonresponse)
  response=make_response(str(jsonresponse), 200)
  response.headers['Content-Type'] = 'application/json'
  response.headers['Access-Control-Allow-Origin']= '*'
  return response
def checkaddresses():
  dbstring="SELECT * FROM ADDRESSES WHERE amount_withdrawn=0;"
  addresslist=databases.dbexecute(dbstring,True)
  print addresslist

  for address in addresslist:
    unspents=addresses.unspent(address[0])
    value=0
    for x in unspents:
      value=value+x['value']
    print "currently available in "+str(address[0])+" : "+str(value/100000000)

    if value>=address[2] and address[3]<address[2]:
      #makenewcoins
      fromaddr=address[0]
      colornumber=address[6]
      colorname=address[5]
      destination=address[7]
      fee_each=0.00004
      private_key=address[1]
      ticker=address[9]
      description=address[8]
      txdata=transactions.make_new_coin(fromaddr, colornumber, colorname, destination, fee_each, private_key, description)

      txhash=txdata[0]
      txhash=txhash+":0" #issuance always first output

      #mark as completed
      databases.edit_address(fromaddr, value, value, colornumber)

      #add entry to colors db
      # #referencehex=bitsource.tx_lookup(specific_inputs)
      # color_address=bitsource.script_to_coloraddress()
      #databases.add_color(color_address, fromaddr, colornumber, colorname)
      databases.dbexecute("insert into colors (source_address, color_name) values ('"+fromaddr+"','"+colorname+"');",False)
Exemple #4
0
def make_raw_multiple_outputs(fromaddress, output_n, output_amount_each, destination, fee):

  global ins, outs,h, tx, tx2, outputs
  outputs=[]
  for i in range(0,output_n):
    outputs.append({'value': int(output_amount_each*100000000), 'address': destination})

  fee=int(fee*100000000)

  unspents=addresses.unspent(fromaddress)  #using vitalik's version could be problematic

  totalout=0
  for x in outputs:
    totalout=totalout+x['value']
  ins=[]
  ok=False
  outs=[]
  totalfound=0
  for unsp in unspents:
    ins.append(unsp)
    totalfound=totalfound+unsp['value']
  change_amount=totalfound-totalout-fee
  outs=outputs
  if change_amount>int(dust*100000000):
    outs.append({'value': change_amount, 'address': profit_address})

  print 'ins'
  print ins
  print ''
  print 'outs'
  print outs

  tx=mktx(ins,outs)

  return tx
def checkaddresses():
  dbstring="SELECT * FROM ADDRESSES WHERE amount_withdrawn=0;"
  addresslist=databases.dbexecute(dbstring,True)
  print addresslist

  for address in addresslist:
    unspents=addresses.unspent(address[0])
    value=0
    for x in unspents:
      value=value+x['value']
    print "currently available in "+str(address[0])+" : "+str(value/100000000)

    if value>=address[2] and address[3]<address[2]:
      #makenewcoins
      fromaddr=address[0]
      colornumber=address[6]
      colorname=address[5]
      destination=address[7]
      fee_each=0.00005
      private_key=address[1]
      ticker=address[9]
      description=address[8]
      txdata=transactions.make_new_coin(fromaddr, colornumber, colorname, destination, fee_each, private_key, description)

      txhash=txdata[0]
      txhash=txhash+":0" #issuance always first output

      #mark as completed
      if len(txhash)>10:
        databases.edit_address(fromaddr, value, value, colornumber)
        their_email=address[9]
        email_commands.email_creation(str(their_email), str(colorname), str(colornumber), str(description), str(txhash))
        databases.dbexecute("insert into colors (source_address, color_name) values ('"+fromaddr+"','"+colorname+"');",False)
def find_transfer_inputs(fromaddr, coloraddress, coloramt, btc):
  if coloraddress is None:
    coloraddress="none"
  available_inputs=databases.dbexecute("SELECT * FROM OUTPUTS WHERE spent='False' and destination_address='"+fromaddr+"' and color_address='"+coloraddress+"';",True)
  other_inputs=addresses.unspent(fromaddr)
  totalfound=0
  btc=int(btc*100000000)
  totalavailable=0
  btcfound=0
  btcavailable=0
  answer=[]
  totalinputamt=0
  for x in available_inputs:
    totalavailable=totalavailable+x[1]
  for x in other_inputs:
    btcavailable=btcavailable+x['value']

  if totalavailable>=coloramt and btcavailable>=btc:
    n=0
    while totalfound<coloramt and n<len(available_inputs):
      r={}
      r['output']=available_inputs[n][7]
      r['value']=available_inputs[n][0]
      btcfound=btcfound+r['value']
      totalinputamt=totalinputamt+r['value']
      totalfound=totalfound+available_inputs[n][1]
      answer.append(r)
      n=n+1
    n=0
    while btcfound<btc and n<len(other_inputs):
      r={}
      if n<len(other_inputs):
        r=other_inputs[n]

        found=False
        for x in answer:
          if x['output']==r['output']:
            found=True

        if other_inputs[n]['value']>dust and not found:
          btcfound=btcfound+other_inputs[n]['value']
          answer.append(r)
      n=n+1

  return answer, totalfound
Exemple #7
0
def checkaddresses():  #FOR PAYMENT DUE      #WORKS
  #check all addresses that are still pending
    #for each that is ready, go through makenewcoins process
    #mark as completed
    #send profits elsewhere

  #read all addresses
  dbstring="SELECT * FROM ADDRESSES WHERE amount_withdrawn=0;"
  addresslist=databases.dbexecute(dbstring,True)
  print addresslist

  for address in addresslist:
    unspents=addresses.unspent(address[0])
    value=0
    for x in unspents:
      value=value+x['value']
    print "currently available in "+str(address[0])+" : "+str(value/100000000)

    if value>=address[2] and address[3]<address[2]:
      #makenewcoins
      fromaddr=address[0]
      colornumber=address[6]
      colorname=address[5]
      destination=address[7]
      fee_each=0.00004
      private_key=address[1]
      ticker=address[9]
      description=address[8]
      txdata=transactions.make_new_coin(fromaddr, colornumber, colorname, destination, fee_each, private_key, ticker, description)

      txhash=txdata[0]
      txhash=txhash+":0" #issuance always first output
      specific_inputs=txdata[1]['output']  #THIS IS CRUCIAL IN FINDING COLOR ADDRESS

      #mark as completed
      databases.edit_address(fromaddr, value, value, colornumber)

      #add entry to colors db
      #referencehex=bitsource.tx_lookup(specific_inputs)
      color_address=bitsource.script_to_coloraddress()
      databases.add_color(color_address, fromaddr, colornumber, colorname)
Exemple #8
0
def make_raw(fromaddress,destination,fee):  #TAILORED FOR THIS SPECIFIC USE CASE
  global ins, outs, totalin
  fee=int(fee*100000000)
  unspents=addresses.unspent(fromaddress)

  ins=[]
  outs=[]
  totalin=0

  print 'unspents below'
  print unspents
  print ''

  for uns in unspents:
    if 'value' in uns:
      totalin=totalin+uns['value']
      ins.append(uns)

  if totalin>=fee+int(dust*100000000):
    outs.append({'value': totalin-fee, 'address': destination})

  tx=mktx(ins,outs)
  return tx