Example #1
0
def issuenewcoinsserverside():  #TO ONE RECIPIENT ADDRESS
    jsoninput = json.loads(request.data)

    private_key = str(jsoninput['private_key'])
    public_address = str(jsoninput['public_address'])
    more_coins = int(jsoninput['more_coins'])
    recipient = str(jsoninput['recipient'])
    fee_each = str(jsoninput['fee_each'])
    name = str(jsoninput['name'])
    othermeta = str(name)

    specific_inputs = addresses.get_unspent(public_address)
    #REMOVE COLORED OUTPUTS FROM THIS
    for x in specific_inputs:
        txhash_index = x['output']
        found = databases.dbexecute(
            "select * from outputs where spent='False' and txhash_index='" +
            str(txhash_index) + "' and destination_address='" +
            str(public_address) + "';", True)
        nfound = len(found)
        if nfound > 0:
            specific_inputs.remove(x)

    print specific_inputs
    response = transactions.create_issuing_tx(public_address, recipient,
                                              fee_each, private_key,
                                              more_coins, specific_inputs,
                                              othermeta)
    jsonresponse = {}
    jsonresponse['transaction_hash'] = response
    jsonresponse = json.dumps(jsonresponse)
    response = make_response(str(jsonresponse), 200)
    response.headers['Content-Type'] = 'application/json'
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Example #2
0
def issuenewcoinsserverside():   #TO ONE RECIPIENT ADDRESS
  jsoninput=json.loads(request.data)

  private_key=str(jsoninput['private_key'])
  public_address=str(jsoninput['public_address'])
  more_coins=int(jsoninput['more_coins'])
  recipient=str(jsoninput['recipient'])
  fee_each=str(jsoninput['fee_each'])
  name=str(jsoninput['name'])
  othermeta=str(name)

  specific_inputs = addresses.get_unspent(public_address)
  #REMOVE COLORED OUTPUTS FROM THIS
  for x in specific_inputs:
    txhash_index = x['output']
    found = databases.dbexecute("select * from outputs where spent='False' and txhash_index='"+str(txhash_index)+"' and destination_address='"+str(public_address)+"';",True)
    nfound = len(found)
    if nfound>0:
      specific_inputs.remove(x)

  print specific_inputs
  response=transactions.create_issuing_tx(public_address, recipient, fee_each, private_key, more_coins, specific_inputs, othermeta)
  jsonresponse={}
  jsonresponse['transaction_hash']=response
  jsonresponse=json.dumps(jsonresponse)
  response=make_response(str(jsonresponse), 200)
  response.headers['Content-Type'] = 'application/json'
  response.headers['Access-Control-Allow-Origin']= '*'
  return response
Example #3
0
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)
    forbidden_inputs = databases.dbexecute(
        "SELECT * FROM OUTPUTS WHERE spent='False' and destination_address='" +
        fromaddr + "' and not color_address='" + str(coloraddress) +
        "' and not color_address='';", True)
    other_inputs = addresses.get_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

            for x in forbidden_inputs:
                outp = x[7]
                for y in answer:
                    if y['output'] == outp:
                        answer.remove(y)
                        totalfound = totalfound - y['value']

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

    for address in addresslist:
        unspents = addresses.get_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]

            try:
                txdata = transactions.make_new_coin(
                    fromaddr, colornumber, colorname, destination, fee_each, private_key, description
                )
            except:
                print "ERROR CREATING NEW COIN"
                print str(fromaddr) + " / " + str(colornumber) + " / " + str(colorname) + " / " + str(
                    destination
                ) + " / " + str(fee_each) + " / " + str(private_key) + " / " + str(description)

            try:
                txhash = txdata["transaction_hash"]
            except:
                txhash = "Error"
                print "ERROR reading txdata"
                print txdata

            txhash = txhash + ":0"  # issuance always first output
            # mark as completed
            if txhash == "None:0":
                k = 1  # do nothing
            else:
                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,
                )
Example #5
0
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)
  forbidden_inputs = databases.dbexecute("SELECT * FROM OUTPUTS WHERE spent='False' and destination_address='"+fromaddr+"' and not color_address='"+str(coloraddress)+"';",True)
  other_inputs=addresses.get_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


      for x in forbidden_inputs:
          outp = x[7]
          for y in answer:
              if y['output'] == outp:
                  answer.remove(y)
                  totalfound=totalfound - y['value']

  return answer, totalfound