From aa3ba28ea7e9ffbc6047cd0b62e6624804799ff8 Mon Sep 17 00:00:00 2001 From: Lennart Hansen Date: Thu, 21 Apr 2022 02:04:20 +0100 Subject: [PATCH] Working demo --- README.md | 69 ++++++++++++- dero_nameservice.pl => dero_ns_cli.pl | 139 +++++++++++++++++++++----- list | 4 + turorial.pl | 58 ----------- 4 files changed, 183 insertions(+), 87 deletions(-) rename dero_nameservice.pl => dero_ns_cli.pl (51%) create mode 100644 list delete mode 100755 turorial.pl diff --git a/README.md b/README.md index 7b43da5..59c4299 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,68 @@ -# Dero_Name_Service_Cli_Tool +# Dero Naming Service Cli Tool + +This tool allows you to easily, check one or more names if they are free to be registered on the DERO HE Block Chain + and then register the name to your own wallet if you wish to. + +## Usage + +Please example usage below + +### Check if name is already registered + +``` +$ ./dero_ns_cli.pl --name Hansen33 +Dero Name Service Cli Tool - register name to wallet +Name: (Hansen33) is taken by this address (dero1qy3dspltmkakl4gzpfvhc35kxxqpp2ypd9ehz72puyxhgs0sqglj6qgqt28kd) + +$ ./dero_ns_cli.pl --name KingZulo +Dero Name Service Cli Tool - register name to wallet +Name: (KingZulo) is FREE to register + + +``` + + +### Check if list of names are already registered +``` +$ cat list +Captain +Azylem +Nelbert442 +Hansen33 + +$ ./dero_ns_cli.pl --check-list ./list +Dero Name Service Cli Tool - register name to wallet +Name: (Captain) is taken by this address (dero1qy9s60kf40wcwhcf9ay6dgpz3gh748x6eq0cpghs4m39u55ecnrlzqg0vq5sy) +Name: (Azylem) is taken by this address (dero1qyfk5w2rvqpl9kzfd7fpteyp2k362y6audydcu2qrgcmj6vtasfkgqq9704gn) +Name: (Nelbert442) is taken by this address (dero1qytygwq00ppnef59l6r5g96yhcvgpzx0ftc0ctefs5td43vkn0p72qqlqrn8z) +Name: (Hansen33) is taken by this address (dero1qy3dspltmkakl4gzpfvhc35kxxqpp2ypd9ehz72puyxhgs0sqglj6qgqt28kd) + +``` + +### Register name to your wallet +``` +./dero_ns_cli.pl --name KingZulo --register +Dero Name Service Cli Tool - register name to wallet +Name: (KingZulo) is FREE - and will be registered in a little while +Checking wallet RPC (127.0.0.1:10103) +Wallet connected (127.0.0.1:10103) +Name: (KingZulo) registered on the DERO Stargate with TXT ID (5f0abf21b897dc432a52633cdcbb47d68fde749a18b58764f39a696bd6eabb88) +Name: (KingZulo) is now registered to this address (dero1qy3dspltmkakl4gzpfvhc35kxxqpp2ypd9ehz72puyxhgs0sqglj6qgqt28kd) - Congratulations! + +``` +(PS: If anyone want KingZulo I'm kinda willing to give it up) + + +## More About Dero + +Dero - Stargate +[https://dero.io/](https://dero.io/) +[https://github.com/deroproject/derohe/](https://github.com/deroproject/derohe/) + +## More Dero Smart Contracts Used Here + +[Nameservice](https://docs.dero.io/rtd_pages/dev_dvm.html#nameservice) +[DVM Example](https://github.com/deroproject/documentation/tree/master/DVMDOCS/examples/nameservice) + + -Script to check and register your wallet with a name on the stargate block chain. \ No newline at end of file diff --git a/dero_nameservice.pl b/dero_ns_cli.pl similarity index 51% rename from dero_nameservice.pl rename to dero_ns_cli.pl index ccdbb17..0cb53b5 100755 --- a/dero_nameservice.pl +++ b/dero_ns_cli.pl @@ -3,6 +3,8 @@ # Script Written by Hansen33 # Discord: hansen33#2541 # +# Let's have some fun and register some more names. +# # Dero name service # https://docs.dero.io/rtd_pages/dev_dvm.html#nameservice @@ -21,51 +23,136 @@ use JSON; use Data::Dumper; use WWW::Curl::Easy; -use FindBin; -use lib "$FindBin::RealBin/../lib"; -use Curses::UI; - # options use Getopt::Long; +my $name; my %options; GetOptions( 'daemon-rpc=s' => \$options{'daemon-rpc'}, 'wallet-rpc=s' => \$options{'wallet-rpc'}, - 'name=s' => \$options{'name'}, + 'register+' => \$options{'register'}, + 'name=s' => \$name, + 'check-list=s' => \$options{'list'}, + 'help+' => \$options{'help'}, ); my $daemon = 'https://dero-node.mysrv.cloud'; $daemon = $options{'daemon-rpc'} if $options{'daemon-rpc'}; -my $wallet_rpc = '127.0.0.0:10103'; +my $wallet_rpc = '127.0.0.1:10103'; $wallet_rpc = $options{'wallet-rpc'} if $options{'wallet-rpc'}; -my $name = 'MySrvCloud'; -$name = $options{'name'} if $options{'name'}; +print "Dero Name Service Cli Tool - register name to wallet\n"; -my $check = check_name($name); +sub usage { -if (defined $check and $check->{'status'} eq 'OK') { - printf "Name: (%s) is taken by this address (%s)\n", $check->{'name'}, $check->{'address'}; -} else { - printf "Name: (%s) is FREE - Do you want to register it?\n", $name; + print "usage: $0 --name [--register] [--list ] [--daemon-rpc] [--wallet-rpc]\n"; + print "\t--name name to check or register\n"; + print "\t--register will attempt to register name to your wallet\n"; + print "\t--check-list Check file with list of names - list can not be used with --register\n"; + print "\t--daemon-rpc Specify URL for daemon if you don't want to use https://dero-node.mysrv.cloud/\n"; + print "\t This is just to check if the name is registered already\n"; + print "\t--wallet-rpc Specify wallet RPC if other than 127.0.0.1:10103 (local wallet)\n"; + + exit; } -print "Checking wallet RPC\n"; -my $count = 0; -while (not defined check_wallet_rpc() and $count < 10) { +usage() if $options{'help'}; - print "Please start wallet with --rpc-server option\n" if $count == 0; +my @check_list; - sleep 1; +push @check_list, $name if defined $name; - $count++; +if ($options{'list'}) { + # Building list + if (-f $options{'list'}) { + open my $FILE, '<', $options{'list'} or die ("Failed to open file list for reading...."); + while (my $line = <$FILE>) { + chomp $line; + push @check_list, $line; + } + + } else { + usage(); + } } -#exit -my $reg = register($name); -print Dumper($reg); +foreach my $check_name (@check_list) { + + my $check = check_name($check_name); + + if (defined $check and $check->{'status'} eq 'OK') { + printf "Name: (%s) is taken by this address (%s)\n", $check->{'name'}, $check->{'address'}; + } else { + if ($options{'register'}) { + printf "Name: (%s) is FREE - and will be registered in a little while\n", $name; + } else { + printf "Name: (%s) is FREE to register\n", $name; + } + } +} + +if ($options{'register'}) { + + my $max_wait = 120; + usage() if $options{'list'}; + + if (check_name($name)) { + printf "Name: (%s) is already registered, nothing to do\n", $name; + exit 0; + } + + printf "Checking wallet RPC (%s)\n", $wallet_rpc; + my $count = 0; + while (not defined check_wallet_rpc() and $count < $max_wait) { + + print "Please start wallet with --rpc-server option\n" if $count == 0; + + printf "\rWaiting [%d/%d]... ", $count, $max_wait; + sleep 1; + + $count++; + } + + + if (check_wallet_rpc()) { + printf "Wallet connected (%s)\n", $wallet_rpc; + + my $reg = register($name); + + if (defined $reg and $reg->{'result'}) { + printf "Name: (%s) registered on the DERO Stargate with TXT ID (%s)\n", $name, $reg->{'result'}->{'txid'}; + } else { + print "Error, something went wrong!\n"; + print Dumper($reg); + exit 1; + } + + my $reg_check; + $count = 0; + while (not defined $reg_check) { + my $reg_check = check_name($name); + + if (defined $reg_check and $reg_check->{'status'} eq 'OK') { + printf "\rName: (%s) is now registered to this address (%s) - Congratulations!\n", $reg_check->{'name'}, $reg_check->{'address'}; + last; + } else { + printf "\rWaiting for registered to complete [%d/%d]... ", $count, $max_wait; + } + die "Something went wrong, it took too long to register.." if $count > $max_wait; + sleep 1; + $count++; + } + + } else { + print "Failed to connect with your wallet, please check your settings!\n"; + } + +} + + + sub register { @@ -90,17 +177,17 @@ sub register { { 'name' => 'name', 'datatype' => 'S', - 'valye' => $name, + 'value' => $name, } ], }, }; - my $url = sprintf '%s/json_rpc', $daemon; + my $url = sprintf 'http://%s/json_rpc', $wallet_rpc; my $status = decode_json( post_url($url, $data) ); - return $status->{'result'}; + return $status; } @@ -109,9 +196,7 @@ sub check_wallet_rpc { my ($ip,$port) = split /:/, $wallet_rpc; my $cmd = sprintf 'timeout 1 /usr/bin/nc -z %s %d', $ip, $port; - system "$cmd >/dev/null 2>&1"; - if ( $? == 0 ) { return 1; } diff --git a/list b/list new file mode 100644 index 0000000..8e4ef1a --- /dev/null +++ b/list @@ -0,0 +1,4 @@ +Captain +Azylem +Nelbert442 +Hansen33 diff --git a/turorial.pl b/turorial.pl deleted file mode 100755 index 58702f5..0000000 --- a/turorial.pl +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/perl -w -# Tutorial example -# 2003 (c) by Marcus Thiesen (marcus@cpan.org) -# This file is a part of Curses::UI and might be distributed -# under the same terms as perl itself. - -# Use the libraries from the distribution, instead of -# system wide libraries. -use FindBin; -use lib "$FindBin::RealBin/../lib"; - -use strict; -use Curses::UI; -my $cui = new Curses::UI( -color_support => 1 ); - -my @menu = ( - { -label => 'File', - -submenu => [ - { -label => 'Exit ^Q', -value => \&exit_dialog } - ] - }, -); - -my $menu = $cui->add( - 'menu','Menubar', - -menu => \@menu, - -fg => "blue", -); - -my $win1 = $cui->add( - 'win1', 'Window', - -border => 1, - -y => 1, - -bfg => 'red', - ); - - -sub exit_dialog() -{ - my $return = $cui->dialog( - -message => "Do you really want to quit?", - -title => "Are you sure???", - -buttons => ['yes', 'no'], - - ); - - exit(0) if $return; -} - -my $texteditor = $win1->add("text", "TextEditor", -text => "Here is some text\n" - . "And some more"); - - -$cui->set_binding(sub {$menu->focus()}, "\cX"); -$cui->set_binding( \&exit_dialog , "\cQ"); - -$texteditor->focus(); -$cui->mainloop();