def token_create_tui(rpc_connection): while True: try: name = input("Set your token name: ") supply = input("Set your token supply: ") description = input("Set your token description: ") except KeyboardInterrupt: break else: token_hex = rpclib.token_create(rpc_connection, name, supply, description) if token_hex['result'] == "error": print(colorize("\nSomething went wrong!\n", "pink")) print(token_hex) print("\n") input("Press [Enter] to continue...") break else: try: token_txid = rpclib.sendrawtransaction(rpc_connection, token_hex['hex']) except KeyError: print(token_txid) print("Error") input("Press [Enter] to continue...") break finally: print(colorize("Token creation transaction broadcasted: " + token_txid, "green")) file = open("tokens_list", "a") file.writelines(token_txid + "\n") file.close() print(colorize("Entry added to tokens_list file!\n", "green")) input("Press [Enter] to continue...") break
def token_converter_tui(rpc_connection): #TODO: have an idea since blackjoker new RPC call #grab all list and printout only or which owner match with node pubkey try: print(colorize("Tokens created from this instance by TUI: \n", "blue")) with open("tokens_list", "r") as file: for oracle in file: print(oracle) print(colorize('_' * 65, "blue")) print("\n") except FileNotFoundError: print("Seems like a no oracles created from this instance yet\n") pass while True: try: evalcode = "241" token_id = input("Input id of token which you want to convert: ") # informative printouts token_info = rpclib.token_info(rpc_connection, token_id) token_balance = rpclib.token_balance(rpc_connection, token_id) try: print(colorize("\n{} token supply: {}\n".format(token_id, token_info["supply"]), "blue")) print("Your pubkey balance for this token: {}\n".format(token_balance["balance"])) except (KeyError, ConnectionResetError): print(colorize("Please re-check your input", "red")) input("Press [Enter] to continue...") break print(colorize('_' * 65, "blue")) print("\n") pubkey = input("Input pubkey to which you want to convert (for initial conversion use \ 03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40): ") # TODO: have to print here pubkey with which started chain daemon supply = str(input("Input supply which you want to convert (for initial conversion set all token supply): ")) except KeyboardInterrupt: break token_convert_hex = rpclib.token_convert(rpc_connection, evalcode, token_id, pubkey, supply) if token_convert_hex['result'] == "error": print(colorize("\nSomething went wrong!\n", "pink")) print(token_convert_hex) print("\n") input("Press [Enter] to continue...") break else: try: token_convert_txid = rpclib.sendrawtransaction(rpc_connection, token_convert_hex['hex']) except KeyError: print(token_convert_hex) print("Error") input("Press [Enter] to continue...") break else: print(colorize("Token convertion transaction broadcasted: " + token_convert_txid, "green")) file = open("token_convert_list", "a") file.writelines(token_convert_txid + "\n") file.close() print(colorize("Entry added to token_convert_list file!\n", "green")) input("Press [Enter] to continue...") break
def gateways_withdrawal_tui(rpc_connection): while True: bind_txid = input("Input your gateway bind txid: ") coin_name = input("Input your external coin ticker (e.g. KMD): ") withdraw_pub = input("Input pubkey to which you want to withdraw: ") amount = input("Input amount of withdrawal: ") withdraw_hex = rpclib.gateways_withdraw(rpc_connection, bind_txid, coin_name, withdraw_pub, amount) withdraw_txid = rpclib.sendrawtransaction(withdraw_hex["hex"]) print(withdraw_txid) input("Press [Enter] to continue...") break
def oracle_subscription_utxogen(rpc_connection): # TODO: have an idea since blackjoker new RPC call # grab all list and printout only or which owner match with node pubkey try: print(colorize("Oracles created from this instance by TUI: \n", "blue")) with open("oracles_list", "r") as file: for oracle in file: print(oracle) print(colorize('_' * 65, "blue")) print("\n") except FileNotFoundError: print("Seems like a no oracles created from this instance yet\n") pass while True: try: oracle_id = input("Input oracle ID you want to subscribe to: ") #printout to fast copypaste publisher id oracle_info = rpclib.oracles_info(rpc_connection, oracle_id) publishers = 0 print(colorize("\nPublishers registered for a selected oracle: \n", "blue")) try: for entry in oracle_info["registered"]: publisher = entry["publisher"] print(publisher + "\n") publishers = publishers + 1 print("Total publishers:{}".format(publishers)) except (KeyError, ConnectionResetError): print(colorize("Please re-check your input. Oracle txid seems not valid.", "red")) pass print(colorize('_' * 65, "blue")) print("\n") if publishers == 0: print(colorize("This oracle have no publishers to subscribe.\n" "Please register as an oracle publisher first and/or wait since registration transaciton mined!", "red")) input("Press [Enter] to continue...") break publisher_id = input("Input oracle publisher id you want to subscribe to: ") data_fee = input("Input subscription fee (in COINS!): ") utxo_num = int(input("Input how many transactions you want to broadcast: ")) except KeyboardInterrupt: break while utxo_num > 0: while True: oracle_subscription_hex = rpclib.oracles_subscribe(rpc_connection, oracle_id, publisher_id, data_fee) oracle_subscription_txid = rpclib.sendrawtransaction(rpc_connection, oracle_subscription_hex['hex']) mempool = rpclib.get_rawmempool(rpc_connection) if oracle_subscription_txid in mempool: break else: pass print(colorize("Oracle subscription transaction broadcasted: " + oracle_subscription_txid, "green")) utxo_num = utxo_num - 1 input("Press [Enter] to continue...") break
def gateways_claim_tui(rpc_connection): while True: bind_txid = input("Input your gateway bind txid: ") coin_name = input("Input your external coin ticker (e.g. KMD): ") deposit_txid = input("Input your gatewaysdeposit txid: ") dest_pub = input("Input pubkey which claim deposit: ") amount = input("Input amount of your deposit: ") claim_hex = rpclib.gateways_claim(rpc_connection, bind_txid, coin_name, deposit_txid, dest_pub, amount) claim_txid = rpclib.sendrawtransaction(rpc_connection, claim_hex["hex"]) print(claim_txid) input("Press [Enter] to continue...") break
def create_table(self): tablename = self.ids["tablename"].text tablefunds = self.ids["tablefunds"].text minbet = self.ids["minbet"].text maxbet = self.ids["maxbet"].text maxodds = self.ids["maxodds"].text timeoutblocks = self.ids["timeoutblocks"].text new_table = rpclib.dice_fund(App.get_running_app().rpc_connection, tablename, tablefunds, minbet, maxbet, maxodds, timeoutblocks) try: new_table_txid = rpclib.sendrawtransaction(App.get_running_app().rpc_connection, new_table["hex"]) except Exception as e: self.ids["creationstatus"].text = str(new_table) else: self.ids["creationstatus"].text = "Table opening transaction [color=43c51a]" + new_table_txid + "[/color] succesfully broadcasted"
def create_channel(self): destpubkey = self.ids["destpubkey"].text numpayments = self.ids["numpayments"].text denomination = self.ids["denomination"].text new_channel = rpclib.channels_open( App.get_running_app().rpc_connection, destpubkey, numpayments, denomination) try: new_channel_txid = rpclib.sendrawtransaction( App.get_running_app().rpc_connection, new_channel["hex"]) except Exception as e: self.ids["creationstatus"].text = str(new_channel) else: self.ids[ "creationstatus"].text = "Channel opening transaction [color=43c51a]" + new_channel_txid + "[/color] succesfully broadcasted"
def send_payment(self): application = App.get_running_app() channel = application.active_channel_id payment_sum = application.root.ids.paymentpage.ids.paymentamount.text try: payment_hex = rpclib.channels_payment(application.rpc_connection, channel, str(int(Decimal(payment_sum)))) except Exception as e: application.root.ids.paymentpage.ids.paymentstatus.text = str(e) else: try: payment_txid = rpclib.sendrawtransaction(application.rpc_connection, payment_hex["hex"]) except Exception as e: application.root.ids.paymentpage.ids.paymentstatus.text = str(e) else: print(payment_txid) application.root.ids.paymentpage.ids.paymentstatus.text = "Payment sent. TXID: " + str(payment_txid)
def oracle_create_tui(rpc_connection): print(colorize("\nAvailiable data types:\n", "blue")) oracles_data_types = [ "Ihh -> height, blockhash, merkleroot\ns -> <256 char string\nS -> <65536 char string\nd -> <256 binary data\nD -> <65536 binary data", "c -> 1 byte signed little endian number, C unsigned\nt -> 2 byte signed little endian number, T unsigned", "i -> 4 byte signed little endian number, I unsigned\nl -> 8 byte signed little endian number, L unsigned", "h -> 32 byte hash\n" ] for oracles_type in oracles_data_types: print(str(oracles_type)) while True: try: name = input("Set your oracle name: ") description = input("Set your oracle description: ") oracle_data_type = input("Set your oracle type (e.g. Ihh): ") except KeyboardInterrupt: break else: oracle_hex = rpclib.oracles_create(rpc_connection, name, description, oracle_data_type) if oracle_hex['result'] == "error": print(colorize("\nSomething went wrong!\n", "pink")) print(oracle_hex) print("\n") input("Press [Enter] to continue...") break else: try: oracle_txid = rpclib.sendrawtransaction( rpc_connection, oracle_hex['hex']) except KeyError: print(oracle_txid) print("Error") input("Press [Enter] to continue...") break finally: print( colorize( "Oracle creation transaction broadcasted: " + oracle_txid, "green")) file = open("oracles_list", "a") file.writelines(oracle_txid + "\n") file.close() print(colorize("Entry added to oracles_list file!\n", "green")) input("Press [Enter] to continue...") break
def gateways_deposit_tui(rpc_connection): while True: bind_txid = input("Input your gateway bind txid: ") coin_name = input("Input your external coin ticker (e.g. KMD): ") coin_txid = input("Input your deposit txid: ") dest_pub = input("Input pubkey which claim deposit: ") amount = input("Input amount of your deposit: ") height = rpc_connection.getrawtransaction(coin_txid, 1)["height"] deposit_hex = rpc_connection.getrawtransaction(coin_txid, 1)["hex"] claim_vout = "0" proof_sending_block = "[\"{}\"]".format(coin_txid) proof = rpc_connection.gettxoutproof(json.loads(proof_sending_block)) deposit_hex = rpclib.gateways_deposit(rpc_connection, bind_txid, height, coin_name, \ coin_txid, claim_vout, deposit_hex, proof, dest_pub, amount) deposit_txid = rpclib.sendrawtransaction(rpc_connection, deposit_hex["hex"]) print(deposit_txid) input("Press [Enter] to continue...") break
def oracle_register_tui(rpc_connection): #TODO: have an idea since blackjoker new RPC call #grab all list and printout only or which owner match with node pubkey try: print(colorize("Oracles created from this instance by TUI: \n", "blue")) with open("oracles_list", "r") as file: for oracle in file: print(oracle) print(colorize('_' * 65, "blue")) print("\n") except FileNotFoundError: print("Seems like a no oracles created from this instance yet\n") pass while True: try: oracle_id = input("Input txid of oracle you want to register to: ") data_fee = input("Set publisher datafee (in satoshis): ") except KeyboardInterrupt: break oracle_register_hex = rpclib.oracles_register(rpc_connection, oracle_id, data_fee) if oracle_register_hex['result'] == "error": print(colorize("\nSomething went wrong!\n", "pink")) print(oracle_register_hex) print("\n") input("Press [Enter] to continue...") break else: try: oracle_register_txid = rpclib.sendrawtransaction( rpc_connection, oracle_register_hex['hex']) except KeyError: print(oracle_register_hex) print("Error") input("Press [Enter] to continue...") break else: print( colorize( "Oracle registration transaction broadcasted: " + oracle_register_txid, "green")) input("Press [Enter] to continue...") break
def gateways_deposit_tui(rpc_connection_assetchain, rpc_connection_komodo): while True: bind_txid = input("Input your gateway bind txid: ") coin_name = input("Input your external coin ticker (e.g. KMD): ") coin_txid = input("Input your deposit txid: ") dest_pub = input("Input pubkey which claim deposit: ") amount = input("Input amount of your deposit: ") height = rpc_connection_komodo.getrawtransaction(coin_txid, 1)["height"] deposit_hex = rpc_connection_komodo.getrawtransaction(coin_txid, 1)["hex"] claim_vout = "0" proof_sending_block = "[\"{}\"]".format(coin_txid) proof = rpc_connection_komodo.gettxoutproof( json.loads(proof_sending_block)) # !!! height needs to be converted to string, omegalul deposit_hex = rpclib.gateways_deposit(rpc_connection_assetchain, bind_txid, str(height), coin_name, \ coin_txid, claim_vout, deposit_hex, proof, dest_pub, amount) deposit_txid = rpclib.sendrawtransaction(rpc_connection_assetchain, deposit_hex["hex"]) print("Done! Gateways deposit txid is: " + deposit_txid + " Please not forget to claim your deposit!") input("Press [Enter] to continue...") break
def place_bet(self): application = App.get_running_app() table = application.active_table_id table_name = rpclib.dice_info(application.rpc_connection, table)["name"] bet_sum = application.root.ids.betplacepage.ids.betamount.text bet_odds = application.root.ids.betplacepage.ids.oddsamount.text try: bet_hex = rpclib.dice_bet(application.rpc_connection, table_name, table, bet_sum, bet_odds) except Exception as e: application.root.ids.betplacepage.ids.betstatus.text = str( e) + " " + str(bet_hex) else: try: bet_txid = rpclib.sendrawtransaction( application.rpc_connection, bet_hex["hex"]) except Exception as e: application.root.ids.betplacepage.ids.betstatus.text = str( e) + " " + str(bet_hex) else: print(bet_txid) application.root.ids.betplacepage.ids.betstatus.text = "Bet transaction sent. TXID: " + str( bet_txid)
def convert_file_oracle_D(rpc_connection): while True: path = input("Input path to file you want to upload to oracle: ") try: hex_data = (hexdump(path, 1)) except Exception as e: print(e) print( "Seems something goes wrong (I guess you've specified wrong path)!" ) input("Press [Enter] to continue...") break else: length = round(len(hex_data) / 2) # if length > 800000: # print("Too big file size to upload for this version of program. Maximum size is 800KB.") # input("Press [Enter] to continue...") # break if length > 8000: # if file is more than 8000 bytes - slicing it to <= 8000 bytes chunks (16000 symbols = 8000 bytes) data = [ hex_data[i:i + 16000] for i in range(0, len(hex_data), 16000) ] chunks_amount = len(data) # TODO: have to create oracle but subscribe this time chunks amount times to send whole file in same block # TODO: 2 - on some point file will not fit block - have to find this point # TODO: 3 way how I want to implement it first will keep whole file in RAM - have to implement some way to stream chunks to oracle before whole file readed # TODO: have to "optimise" registration fee # Maybe just check size first by something like a du ? print("Length: " + str(length) + " bytes.\n Chunks amount: " + str(chunks_amount)) new_oracle_hex = rpclib.oracles_create( rpc_connection, "tonyconvert_" + str(chunks_amount), path, "D") new_oracle_txid = rpclib.sendrawtransaction( rpc_connection, new_oracle_hex["hex"]) time.sleep(0.5) oracle_register_hex = rpclib.oracles_register( rpc_connection, new_oracle_txid, "10000") oracle_register_txid = rpclib.sendrawtransaction( rpc_connection, oracle_register_hex["hex"]) # subscribe chunks_amount + 1 times, but lets limit our broadcasting 100 tx per block (800KB/block) if chunks_amount > 100: utxo_num = 101 else: utxo_num = chunks_amount while utxo_num > 0: while True: oracle_subscription_hex = rpclib.oracles_subscribe( rpc_connection, new_oracle_txid, rpclib.getinfo(rpc_connection)["pubkey"], "0.001") oracle_subscription_txid = rpclib.sendrawtransaction( rpc_connection, oracle_subscription_hex['hex']) mempool = rpclib.get_rawmempool(rpc_connection) if oracle_subscription_txid in mempool: break else: pass print( colorize( "Oracle subscription transaction broadcasted: " + oracle_subscription_txid, "green")) utxo_num = utxo_num - 1 # waiting for last broadcasted subscribtion transaction to be mined to be sure that money are on oracle balance while True: mempool = rpclib.get_rawmempool(rpc_connection) if oracle_subscription_txid in mempool: print( "Waiting for oracle subscribtion tx to be mined" + "\n") time.sleep(6) pass else: break print("Oracle preparation is finished. Oracle txid: " + new_oracle_txid) # can publish data now counter = 0 for chunk in data: hex_length_bigendian = format(round(len(chunk) / 2), '#06x')[2:] # swap to get little endian length a = hex_length_bigendian[2:] b = hex_length_bigendian[:2] hex_length = a + b data_for_oracle = str(hex_length) + chunk counter = counter + 1 # print("Chunk number: " + str(counter) + "\n") # print(data_for_oracle) try: oracles_data_hex = rpclib.oracles_data( rpc_connection, new_oracle_txid, data_for_oracle) except Exception as e: print(data_for_oracle) print(e) input("Press [Enter] to continue...") break # on broadcasting ensuring that previous one reached mempool before blast next one while True: mempool = rpclib.get_rawmempool(rpc_connection) oracle_data_txid = rpclib.sendrawtransaction( rpc_connection, oracles_data_hex["hex"]) #time.sleep(0.1) if oracle_data_txid in mempool: break else: pass # blasting not more than 100 at once (so maximum capacity per block can be changed here) # but keep in mind that registration UTXOs amount needs to be changed too ! if counter % 100 == 0 and chunks_amount > 100: while True: mempool = rpclib.get_rawmempool(rpc_connection) if oracle_data_txid in mempool: print( "Waiting for previous data chunks to be mined before send new ones" + "\n") print("Sent " + str(counter) + " chunks from " + str(chunks_amount)) time.sleep(6) pass else: break print("Last baton: " + oracle_data_txid) input("Press [Enter] to continue...") break # if file suits single oraclesdata just broadcasting it straight without any slicing else: hex_length_bigendian = format(length, '#06x')[2:] # swap to get little endian length a = hex_length_bigendian[2:] b = hex_length_bigendian[:2] hex_length = a + b data_for_oracle = str(hex_length) + hex_data print("File hex representation: \n") print(data_for_oracle + "\n") print("Length: " + str(length) + " bytes") print("File converted!") new_oracle_hex = rpclib.oracles_create(rpc_connection, "tonyconvert_" + "1", path, "D") new_oracle_txid = rpclib.sendrawtransaction( rpc_connection, new_oracle_hex["hex"]) time.sleep(0.5) oracle_register_hex = rpclib.oracles_register( rpc_connection, new_oracle_txid, "10000") oracle_register_txid = rpclib.sendrawtransaction( rpc_connection, oracle_register_hex["hex"]) time.sleep(0.5) oracle_subscribe_hex = rpclib.oracles_subscribe( rpc_connection, new_oracle_txid, rpclib.getinfo(rpc_connection)["pubkey"], "0.001") oracle_subscribe_txid = rpclib.sendrawtransaction( rpc_connection, oracle_subscribe_hex["hex"]) time.sleep(0.5) while True: mempool = rpclib.get_rawmempool(rpc_connection) if oracle_subscribe_txid in mempool: print( "Waiting for oracle subscribtion tx to be mined" + "\n") time.sleep(6) pass else: break oracles_data_hex = rpclib.oracles_data(rpc_connection, new_oracle_txid, data_for_oracle) try: oracle_data_txid = rpclib.sendrawtransaction( rpc_connection, oracles_data_hex["hex"]) except Exception as e: print(oracles_data_hex) print(e) input("Press [Enter] to continue...") break else: print("Oracle created: " + str(new_oracle_txid)) print("Data published: " + str(oracle_data_txid)) input("Press [Enter] to continue...") break
def convert_file_oracle_d(rpc_connection): while True: path = input("Input path to file you want to upload to oracle: ") try: hex_data = (hexdump(path, 1))[2:] except Exception as e: print(e) print( "Seems something goes wrong (I guess you've specified wrong path)!" ) input("Press [Enter] to continue...") break else: length = round(len(hex_data) / 2) if length > 256: print("Length: " + str(length) + " bytes") print("File is too big for this app") input("Press [Enter] to continue...") break else: hex_length = format(length, '#04x')[2:] data_for_oracle = str(hex_length) + hex_data print("File hex representation: \n") print(data_for_oracle + "\n") print("Length: " + str(length) + " bytes") print("File converted!") new_oracle_hex = rpclib.oracles_create(rpc_connection, "tonyconvert", path, "d") new_oracle_txid = rpclib.sendrawtransaction( rpc_connection, new_oracle_hex["hex"]) time.sleep(0.5) oracle_register_hex = rpclib.oracles_register( rpc_connection, new_oracle_txid, "10000") oracle_register_txid = rpclib.sendrawtransaction( rpc_connection, oracle_register_hex["hex"]) time.sleep(0.5) oracle_subscribe_hex = rpclib.oracles_subscribe( rpc_connection, new_oracle_txid, rpclib.getinfo(rpc_connection)["pubkey"], "0.001") oracle_subscribe_txid = rpclib.sendrawtransaction( rpc_connection, oracle_subscribe_hex["hex"]) time.sleep(0.5) while True: mempool = rpclib.get_rawmempool(rpc_connection) if oracle_subscribe_txid in mempool: print( "Waiting for oracle subscribtion tx to be mined" + "\n") time.sleep(6) pass else: break oracles_data_hex = rpclib.oracles_data(rpc_connection, new_oracle_txid, data_for_oracle) try: oracle_data_txid = rpclib.sendrawtransaction( rpc_connection, oracles_data_hex["hex"]) except Exception as e: print(oracles_data_hex) print(e) print("Oracle created: " + str(new_oracle_txid)) print("Data published: " + str(oracle_data_txid)) input("Press [Enter] to continue...") break
def gateways_bind_tui(rpc_connection): # main loop with keyboard interrupt handling while True: try: while True: try: print( colorize( "Tokens created from this instance by TUI: \n", "blue")) with open("tokens_list", "r") as file: for oracle in file: print(oracle) print(colorize('_' * 65, "blue")) print("\n") except FileNotFoundError: print( "Seems like a no oracles created from this instance yet\n" ) pass token_id = input( "Input id of token you want to use in gw bind: ") try: token_name = rpclib.token_info(rpc_connection, token_id)["name"] except KeyError: print( colorize("Not valid tokenid. Please try again.", "red")) input("Press [Enter] to continue...") token_info = rpclib.token_info(rpc_connection, token_id) print( colorize( "\n{} token total supply: {}\n".format( token_id, token_info["supply"]), "blue")) token_supply = input("Input supply for token binding: ") try: print( colorize( "\nOracles created from this instance by TUI: \n", "blue")) with open("oracles_list", "r") as file: for oracle in file: print(oracle) print(colorize('_' * 65, "blue")) print("\n") except FileNotFoundError: print( "Seems like a no oracles created from this instance yet\n" ) pass oracle_id = input( "Input id of oracle you want to use in gw bind: ") try: oracle_name = rpclib.oracles_info(rpc_connection, oracle_id)["name"] except KeyError: print( colorize("Not valid oracleid. Please try again.", "red")) input("Press [Enter] to continue...") while True: coin_name = input( "Input external coin ticker (binded oracle and token need to have same name!): " ) if token_name == oracle_name and token_name == coin_name: break else: print( colorize( "Token name, oracle name and external coin ticker should match!", "red")) while True: M = input( "Input minimal amount of pubkeys needed for transaction confirmation (1 for non-multisig gw): " ) N = input( "Input maximal amount of pubkeys needed for transaction confirmation (1 for non-multisig gw): " ) if (int(N) >= int(M)): break else: print( "Maximal amount of pubkeys should be more or equal than minimal. Please try again." ) pubkeys = [] for i in range(int(N)): pubkeys.append(input("Input pubkey {}: ".format(i + 1))) #pubkeys = ', '.join(pubkeys) args = [ rpc_connection, token_id, oracle_id, coin_name, token_supply, M, N ] args = args + pubkeys # broadcasting block try: gateways_bind_hex = rpclib.gateways_bind(*args) except Exception as e: print(e) input("Press [Enter] to continue...") break try: gateways_bind_txid = rpclib.sendrawtransaction( rpc_connection, gateways_bind_hex["hex"]) except Exception as e: print(e) print(gateways_bind_hex) input("Press [Enter] to continue...") break else: print( colorize( "Gateway bind transaction broadcasted: " + gateways_bind_txid, "green")) file = open("gateways_list", "a") file.writelines(gateways_bind_txid + "\n") file.close() print( colorize("Entry added to gateways_list file!\n", "green")) input("Press [Enter] to continue...") break break except KeyboardInterrupt: break