App-NoodlePay
view release on metacpan or search on metacpan
bin/noodlepay.pl view on Meta::CPAN
wxPD_AUTO_HIDE | wxPD_APP_MODAL );
$ProgressDialog->Update(0,"Signing transaction...");
$signedtx = `$electrum payto $sendto $amount -f $feeamt`;
$signedtx =~ s/\"final\": false/\"final\": true/;
$ProgressDialog->Update(1);
}
else {
$tx = `$electrum payto $sendto $amount -f $feeamt -u`;
$tx =~ /"hex": "(\S+)"/s;
my $dialog = qrdialog(fromdigits($1,16), 'Scan the QR code on Noodle Air', 'Sign Transaction');
$dialog->ShowModal;
system ('v4l2-ctl --set-fmt-overlay=width=400,top=0,left=0 --overlay=1');
open (ZBAR, "zbarcam --nodisplay --prescale=640x480 /dev/video0 |");
my $signed = <ZBAR>; chomp $signed; $signed =~ s/^QR-Code://; $signed = todigitstring($signed,16);
system ('killall -9 zbarcam');
close ZBAR;
system ('v4l2-ctl --overlay=0');
$signedtx = "{\n\"complete\": true,\n\"final\": true,\n\"hex\": \"$signed\"\n}";
}
$dialog = Wx::MessageDialog->new( $frame, "Broadcast transaction?", "Confirm", wxOK|wxCANCEL);
return if $dialog->ShowModal == wxID_CANCEL;
my $id = `$electrum broadcast '$signedtx'`;
$dialog = Wx::MessageDialog->new( $frame, "Transaction ID is $id", "Payment Sent", wxOK);
$dialog->ShowModal;
}
}
show();
};
$action{Exit} = sub { # Exit
$statusBar->SetStatusText("Exit", 0);
my $dialog = Wx::MessageDialog->new( $frame, "Do you really want to exit?", "Confirm", wxOK|wxCANCEL);
return if $dialog->ShowModal == wxID_CANCEL;
$app->ExitMainLoop;
};
EVT_BUTTON($frame, $button{$_}, $action{$_}) for (qw(SendSign Exit));
# Start the UI
show();
$statusBar->SetStatusText(_('Noodle Pay Ready'), 0);
$frame->Show; $frame->Centre(wxBOTH); $frame->Refresh;
$app->MainLoop;
# Helper functions
sub qrdialog {
my ($text, $msgtxt, $title) = @_;
my $len = length($text); my ($msg, $qr, $dialog, $version);
if ($len < 7090 ) {
my $qrfh; my $level;
my @version = qw( 0 41 77 127 187 255 322 370 461 552 652 772 883 1022 1101 1250 1408 1548 1725 1903 2061 2232
2409 2620 2812 3057 3283 3517 3669 3909 4158 4417 4686 4965 5253 5529 5836 6153 6479 6743 7089 );
for (1..40) { next if $len > $version[$_]; $version = $_; last; }
my $qrxpm = GD::Barcode::QRcode->new($text, { Version => $version, Ecc => L, ModuleSize => 4 })->barcode;
$qrxpm =~ /^(.*)$/m; my $qrsize = length($1);
$qr = Wx::Bitmap->newFromXPM([ split /\n/, "$qrsize $qrsize 2 1\n0 c #FFFFFF\n1 c #000000\n$qrxpm" ]);
}
if (defined $qr) {
my $fontheight = $frame->GetCharHeight;
$msg = "\n" x ($qr->GetHeight / $fontheight) . "\n\n$msgtxt";
$dialog = Wx::TextEntryDialog->new($frame, $msg , $title, $text);
my $dialog_height = $dialog->GetSize->GetHeight;
my $dialogwidth = $dialog->GetSize->GetWidth;
my $qrheight = $qr->GetHeight; my $width = $qrheight + 20 > $dialogwidth ? $qrheight + 20 : $dialogwidth;
my $adjust = 10 unless $^O eq 'MSWin32' or $^O eq 'darwin';
my $qrpos = ($width-$qrheight)/2 + ($width == 300 ? $adjust : 0);
$dialog->SetSize([$width,$dialog_height]);
$dialog->SetMinSize([$width,$dialog_height]);
$dialog->SetMaxSize([$width,$dialog_height]);
Wx::StaticBitmap->new( $dialog, -1, $qr, [$qrpos,10] );
}
return $dialog;
}
sub show { # Update the main frame
my $bottom = $topSizer->GetMinSize->GetHeight;
my $right = $topSizer->GetMinSize->GetWidth;
my $clientsize = [$right, $bottom];
$frame->SetClientSize($clientsize);
my $windowsize = $frame->GetSize;
$frame->SetMaxSize($windowsize);
$frame->SetMinSize($windowsize);
$frame->SetSize($windowsize);
$frame->Refresh;
}
sub initui { # Initialize the UI
Wx::InitAllImageHandlers();
my $app = Wx::SimpleApp->new;
my $frame = Wx::Frame->new( undef, -1, _('Noodle Pay'), wxDefaultPosition, wxDefaultSize );
my $topSizer = Wx::BoxSizer->new(wxVERTICAL);
$frame->SetSizer($topSizer);
my $boxSizer = Wx::BoxSizer->new(wxVERTICAL);
$topSizer->Add($boxSizer, 0, wxALL | wxEXPAND, 5);
# Buttons
my %button;
if ($ARGV[0] and $ARGV[0] eq '--offline') {
$button{SendSign} = Wx::Button->new($frame, -1, _('Sign'), [-1,-1]);
}
else {
$button{SendSign} = Wx::Button->new($frame, -1, _('Send'), [-1,-1]);
}
$button{Exit} = Wx::Button->new($frame, -1, _('Exit'), [-1,-1]);
my $buttonbox1 = Wx::BoxSizer->new(wxHORIZONTAL);
$boxSizer->Add($buttonbox1, 0, wxGROW | wxALL, 5);
$buttonbox1->Add($button{SendSign}, 1, wxALL, 5);
$buttonbox1->Add($button{Exit}, 1, wxALL, 5);
# Status bar
my $statusBar = Wx::StatusBar->new($frame, wxID_ANY);
$frame->SetStatusBar($statusBar);
return ($app, $frame, $topSizer, $boxSizer, $statusBar, %button)
}
( run in 1.089 second using v1.01-cache-2.11-cpan-ceb78f64989 )