Skip to content

Commit

Permalink
Reinstate cleanup of director CoinJoin message for CLI and add to GUI…
Browse files Browse the repository at this point in the history
… on Runtime exit.
  • Loading branch information
Michael Pearce committed Feb 16, 2014
1 parent 9cf7641 commit ab46305
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
49 changes: 24 additions & 25 deletions cli/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,27 @@ def start
# ensure we have the key in hex
self.input_private_key = bitcoin_crypto_facade.private_key_to_hex!(input_private_key)

Kernel.trap('SIGINT') { clean_up_coin_join }
Kernel.trap('SIGTERM') { clean_up_coin_join }

message "Starting..."

data_store.connect

Cli::EventQueue.instance.start

build_mixer.tap do |mixer|
mixer.start do |event|
if event.source == :mixer && event.type == :done
Cli::EventQueue.instance.stop
Kernel.trap('SIGINT') { clean_up_coin_join }
Kernel.trap('SIGTERM') { clean_up_coin_join }

mixer.start do |event|
if event.source == :mixer && event.type == :done
Cli::EventQueue.instance.stop
else
message = event.options[:message]
if event.type == :failed
message "Error - #{message}", event.source
message "Quitting..."
else
message = event.options[:message]
if event.type == :failed
message "Error - #{message}", event.source
message "Quitting..."
else
message "#{event.type.to_s.humanize.capitalize}#{" - #{message}" if message}", event.source
if event.source == :participant && event.type == :completed
message "CoinJoin successfully created!"
end
message "#{event.type.to_s.humanize.capitalize}#{" - #{message}" if message}", event.source
if event.source == :participant && event.type == :completed
message "CoinJoin successfully created!"
end
end
end
Expand All @@ -86,6 +84,10 @@ def start

private

def mixer
@mixer ||= build_mixer
end

def build_mixer
Coinmux::Application::Mixer.new(
event_queue: Cli::EventQueue.instance,
Expand All @@ -98,15 +100,12 @@ def build_mixer
end

def clean_up_coin_join
# TODO
# warning "Cleaning up coin_join"
# if !%w(failed completed).include?(director.try(:coin_join_message).try(:state).try(:value).try(:state))
# director.coin_join_message.status.insert(Coinmux::Message::Status.build(director.coin_join_message, state: 'failed')) do
# Cli::EventQueue.instance.stop
# end
# else
# Cli::EventQueue.instance.stop
# end
if mixer
message "Canceling..."
mixer.cancel do
Cli::EventQueue.instance.stop
end
end
end

def run_list_coin_joins
Expand Down
12 changes: 12 additions & 0 deletions gui/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,25 @@ def show_frame(&block)
setLocationRelativeTo(nil)
self.coin_join_uri = preferences_view.coin_join_uri

Java::JavaLang::Runtime.getRuntime().addShutdownHook(Java::JavaLang::Thread.new do
clean_up_mixing
end)

yield

pack
setVisible(true)
root_panel.revalidate() # OSX opening with no content about 20% of time. :(
end

def clean_up_mixing
if current_view == :mixing && (mixer = views[:mixing].mixer)
Coinmux::Threading.wait_for_callback(mixer, :cancel) do
# do nothing
end
end
end

if Coinmux.os == :macosx
class AppleAdapter < Java::ComAppleEawt::ApplicationAdapter
def initialize(application)
Expand Down
4 changes: 2 additions & 2 deletions gui/view/mixing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Gui::View::Mixing < Gui::View::Base
STATES = [:initializing, :waiting_for_other_inputs, :waiting_for_other_outputs, :waiting_for_completed, :completed]
TERMINATE_TEXT = "Terminate"

attr_accessor :director, :participant, :transaction_url
attr_accessor :director, :participant, :transaction_url, :mixer

import 'java.awt.Component'
import 'java.awt.Dimension'
Expand Down Expand Up @@ -44,7 +44,7 @@ def handle_show
reset_status
action_button.setLabel(TERMINATE_TEXT)

build_mixer.start do |event|
(self.mixer = build_mixer).start do |event|
if event.source == :participant && STATES.include?(event.type)
Gui::EventQueue.instance.sync_exec do
update_status(event.type, event.options)
Expand Down
11 changes: 11 additions & 0 deletions lib/coinmux/application/mixer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ def start(&callback)
participant.start(&mixer_callback)
end

def cancel(&callback)
if !%w(failed completed).include?(director.try(:coin_join_message).try(:state).try(:value).try(:state))
director.coin_join_message.status.insert(Coinmux::Message::Status.build(director.coin_join_message, state: 'failed')) do
yield if block_given?
end
else
yield if block_given?
end
end


private

def notify_event(event)
Expand Down

0 comments on commit ab46305

Please sign in to comment.