App-NoodlePay

 view release on metacpan or  search on metacpan

bin/noodlepay.pl  view on Meta::CPAN

# noodlepay.pl - Convenient way to securely send Bitcoin from cold storage
# Copyright (c) Ashish Gulhati <noodlepay at hash.neo.tc>
#
# $Id: bin/noodlepay.pl v1.007 Tue Oct 16 22:06:51 PDT 2018 $

use warnings;

use Wx qw (:everything);
use Wx::Event qw (EVT_BUTTON);
use LWP::UserAgent;
use HTTP::Request;
use GD::Barcode::QRcode;
use Math::Prime::Util qw(fromdigits todigitstring);
use vars qw( $VERSION $AUTOLOAD );

my $electrum = 'electrum';
#my $electrum = 'python ~/src/Electrum-2.8.2/electrum';

# Initialize l8n
my ($lang, %lang) = initl8n();

bin/noodlepay.pl  view on Meta::CPAN

    $ProgressDialog->Update(0,"Checking balance...");
    my $balance = `$electrum getbalance`;
    if (defined $balance and $balance) {
      $balance =~ /"confirmed": "(\S+)"/s; $balance = $1 * 100000000;
      # TODO: Return error if wallet balance lower than send amount
      $ProgressDialog->Update(1,"Creating transaction...");
      my $tx = `$electrum payto $sendto $amount -f 0 -u`;
      $ProgressDialog->Update(2,"Looking up fees...");
      $tx =~ /"hex": "(\S+)"/s; my $txsize = length($1)/2 + 65;
      my $ua = new LWP::UserAgent; $ua->agent('Mozilla/5.0');
      my $req = HTTP::Request->new(GET => 'https://bitcoinfees.earn.com/api/v1/fees/recommended');
      my $res = $ua->request($req);
      my $fees = $res->content; $fees =~ s/\{\s*(.*)\s*\}/$1/; $fees =~ s/\"//g;
      my %fees = split /[:,]\s*/, $fees;
      my $fastest_fee = $fees{fastestFee} * $txsize;
      my $halfhour_fee = $fees{halfHourFee} * $txsize;
      my $hour_fee = $fees{hourFee} * $txsize;
      $ProgressDialog->Update(3);
      $dialog = Wx::TextEntryDialog->new( $frame, "Enter fee amount (in Satoshi). Recommended fees:\n\n" .
					  "- Fastest (10-20 mins): $fastest_fee\n- Within half an hour: $halfhour_fee\n" .
					  "- Within an hour: $hour_fee\n", "Send Bitcoin", $fastest_fee, wxOK|wxCANCEL, [50, 180]);



( run in 0.476 second using v1.01-cache-2.11-cpan-de7293f3b23 )