├── bitcoin
└── bitcoin.conf.sample
├── Rakefile
├── start
├── stop
├── lib
├── smallest_escrow
│ ├── dwolla
│ │ ├── oauth.rb
│ │ ├── auth.rb
│ │ ├── soap.rb
│ │ └── api.rb
│ ├── util.rb
│ ├── deal.rb
│ └── web.rb
└── smallest_escrow.rb
├── .gitignore
├── config.ru
├── Gemfile
├── views
├── admin.erb
├── create.erb
├── layout.erb
└── show.erb
├── config.yml.sample
├── README.asciidoc
├── public
├── css
│ └── style.css
└── js
│ └── jquery-1.6.2.min.js
├── smallest-escrow.pill
├── redis.conf
└── Gemfile.lock
/bitcoin/bitcoin.conf.sample:
--------------------------------------------------------------------------------
1 | rpcuser=
2 | rpcpassword=
3 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | task :default => "test"
2 |
3 | task :test do |t|
4 | end
5 |
--------------------------------------------------------------------------------
/start:
--------------------------------------------------------------------------------
1 | bluepill --no-privileged --base-dir .bluepill load smallest-escrow.pill
2 |
--------------------------------------------------------------------------------
/stop:
--------------------------------------------------------------------------------
1 | bluepill --no-privileged --base-dir .bluepill stop
2 | bluepill --no-privileged --base-dir .bluepill quit
3 |
--------------------------------------------------------------------------------
/lib/smallest_escrow/dwolla/oauth.rb:
--------------------------------------------------------------------------------
1 | module SmallestEscrow
2 | module Dwolla
3 | class OAuth
4 | end
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | config.yml
2 | log
3 | .bluepill/
4 | .bundle/
5 | bitcoin/bitcoin.conf
6 | bitcoin/.lock
7 | bitcoin/database/
8 | bitcoin/__*
9 | bitcoin/*.dat
10 | bitcoin/*.log
11 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # config.ru
2 | $LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
3 | require 'smallest_escrow'
4 |
5 | map SmallestEscrow::Config["rack"]["map"] do
6 | run SmallestEscrow::Web
7 | end
8 |
9 |
--------------------------------------------------------------------------------
/lib/smallest_escrow/util.rb:
--------------------------------------------------------------------------------
1 | module SmallestEscrow
2 | class Util
3 | def self.tcp_accepting?(port)
4 | begin
5 | Socket.tcp('localhost',port)
6 | true
7 | rescue Errno::ECONNREFUSED
8 | false
9 | end
10 | end
11 | end
12 | end
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source :rubygems
2 |
3 | gem 'rack-mongrel2'
4 | gem 'sinatra'
5 | gem 'uuidtools'
6 | gem 'redis'
7 | gem 'datamapper'
8 | gem 'dm-redis-adapter'
9 | gem 'bitbank'
10 | gem 'savon'
11 | gem 'faraday'
12 | gem 'oauth'
13 |
14 | group :test do
15 | gem 'rack-test'
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/views/admin.erb:
--------------------------------------------------------------------------------
1 | Admin
2 |
3 |
25 |
--------------------------------------------------------------------------------
/public/css/style.css:
--------------------------------------------------------------------------------
1 | .centered { margin-left: auto; margin-right: auto; }
2 | div.bigpage { margin-left: auto; margin-right: auto; font-size:150%; text-align: center;}
3 | div.bigpage div { margin-left: 4px;
4 | margin-bottom: 1em; }
5 |
6 | .roundinput input { -webkit-border-radius: 0.2em; -moz-border-radius: 0.2em; border-radius: 0.2em;
7 | height: 1.1em; font-size: 110%;}
8 | .create .submitgo {clear:left;}
9 | div.progress div {margin-bottom: 0px;}
10 | div#btcstats { font-size: 70%; margin-left: auto; margin-right: auto; background: lightgray;}
11 |
--------------------------------------------------------------------------------
/lib/smallest_escrow/dwolla/auth.rb:
--------------------------------------------------------------------------------
1 | module SmallestEscrow
2 | module Dwolla
3 | class Auth
4 | include DataMapper::Resource
5 |
6 | property :id, Serial
7 | property :token, String
8 | property :secret, String
9 |
10 | def self.save_token(access_token)
11 | auth = first || create
12 | auth.token = access_token.token
13 | auth.secret = access_token.secret
14 | auth.save ? auth : nil
15 | end
16 |
17 | def self.get_token
18 | first
19 | end
20 |
21 | def self.remove_token
22 | token = first
23 | token.destroy if token
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/views/layout.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 | bitcoind:
14 | <% if stats %>
15 | <%= ["version", "blocks", "connections", "difficulty"].map{|k| "#{k} => #{stats[k]}"} %>
16 | <% end %>
17 |
18 |
19 | <% if session[:notice] %>
20 |
2 |
3 |
4 | Deal #<%= offer.uuid %>
5 |
6 | <%= offer.btc %> BTC
7 | <-->
8 | $<%= offer.usd %> USD
9 |
10 |
11 |
12 |
13 |
14 |
15 | Escrow Bitcoin address: <%= offer.btc_receiving_address %>
16 |
17 | <% if btc_tx %>
18 |
19 | <%= btc_tx.size %> bitcoin transactions received
20 |
21 | <% btc_tx.each do |t| %>
22 | -
23 | <%=t.category%> <%=t.amount%> <%=t.confirmations%>
24 | <% if t.category == "receive" %>
25 |
31 | <% end %>
32 |
33 | <% end %>
34 |
35 |
36 | <% else %>
37 |
38 | bitcoind failure
39 |
40 | <% end %>
41 |
42 |
43 | <% if offer.usd_paid? %>
44 | Paid. Transaction id #<%= offer.dwolla_tx_id%>
45 |
49 | <% else %>
50 |
55 | <% end %>
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/redis.conf:
--------------------------------------------------------------------------------
1 | # Redis configuration file example
2 |
3 | # By default Redis does not run as a daemon. Use 'yes' if you need it.
4 | # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5 | daemonize no
6 |
7 | # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
8 | # default. You can specify a custom pid file location here.
9 | pidfile /var/run/redis//redis.pid
10 |
11 | # Accept connections on the specified port, default is 6379.
12 | # If port 0 is specified Redis will not listen on a TCP socket.
13 | port 6380
14 |
15 | # If you want you can bind a single interface, if the bind option is not
16 | # specified all the interfaces will listen for incoming connections.
17 | bind 127.0.0.1
18 |
19 | # Specify the path for the unix socket that will be used to listen for
20 | # incoming connections. There is no default, so Redis will not listen
21 | # on a unix socket when not specified.
22 | #
23 | # unixsocket /tmp/redis.sock
24 |
25 | # Close the connection after a client is idle for N seconds (0 to disable)
26 | timeout 0
27 |
28 | # Set server verbosity to 'debug'
29 | # it can be one of:
30 | # debug (a lot of information, useful for development/testing)
31 | # verbose (many rarely useful info, but not a mess like the debug level)
32 | # notice (moderately verbose, what you want in production probably)
33 | # warning (only very important / critical messages are logged)
34 | loglevel notice
35 |
36 | # Specify the log file name. Also 'stdout' can be used to force
37 | # Redis to log on the standard output. Note that if you use standard
38 | # output for logging but daemonize, logs will be sent to /dev/null
39 | logfile stdout
40 |
41 | # To enable logging to the system logger, just set 'syslog-enabled' to yes,
42 | # and optionally update the other syslog parameters to suit your needs.
43 | # syslog-enabled no
44 |
45 | # Specify the syslog identity.
46 | # syslog-ident redis
47 |
48 | # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
49 | # syslog-facility local0
50 |
51 | # Set the number of databases. The default database is DB 0, you can select
52 | # a different one on a per-connection basis using SELECT