pochette 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c505a9f75cdfc003b454e87cd97c48f8fc11aeb7
4
- data.tar.gz: 9e6c94633014b5d0f1ab9328dd1d9f0edea20ca1
3
+ metadata.gz: a017e533b5f1d3f65ac7b806d1d91efae1a1ee6b
4
+ data.tar.gz: a561a5c25acb769f73308b2aa2d8086da9f2e7c3
5
5
  SHA512:
6
- metadata.gz: ba821bb23b235bb6ca4b9a2249c6ca6a3844665bcfe1a967e16066da4976e37d1cf01ce7e7004cc83c522fc84359d0a419e14a352264c1a4a5aa570a8b3b55cf
7
- data.tar.gz: 2b312820cb91d983c0638473d957a13b4f45fe99044aa4361eede24d61d1ec638b2da51fcc4243e1f8c9d13a2d96107e0f687e0a9a9a8ea6869e76ab348f3f3e
6
+ metadata.gz: eda52dde1acbf52a00edb364840506beacaf4f36176852dd4ba35035382802f7461bcd573a60d89e34cfee950163720ef7706c0a18fb15231ede2cbaaa28b1ba
7
+ data.tar.gz: aaf7184e79879a6b6b6303f05d108a3678a66a64170d0a8803370f468b4a2a3d688413d4eae4891cc26cac36110fe44d6f66755aadb2708a0d4cff051ffc8fcc
data/README.md CHANGED
@@ -93,7 +93,7 @@ The TransactionBuilder's initializer receives a single options hash with:
93
93
  <dd>
94
94
  List of pairs [recipient_address, amount]
95
95
  This will not be all the final outputs in the transaction,
96
- as a 'change' output may be adted if needed.
96
+ as a 'change' output may be added if needed.
97
97
  </dd>
98
98
  <dt>utxo_blacklist:</dt>
99
99
  <dd>
@@ -426,19 +426,20 @@ amount seen on the network for a given address, and the final confirmed amount a
426
426
  'mhLAgRz5f1YogfYBZCDFSRt3ceeKBPVEKg',
427
427
  ]
428
428
  >>> backend.balances_for(addresses, 6)
429
- >>> [
430
- "mhLAgRz5f1YogfYBZCDFSRt3ceeKBPVEKg" =>
431
- [0.00544426, 0.00544426, 0.0, 0.00544426, 0.00544426, 0.0],
432
- "mjfa56Keq7PXRKgdPSDB6eWLp4aaAVcj6L" =>
433
- [0.005, 0.0, 0.005, 0.006, 0.0, 0.006],
434
- "mvrDG7Ts6Mq9ejhZxdsQLjbScycVaktqsg" =>
435
- [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
436
- "mwZE4QfzzriE7nsgHSWbgmtT7s6SDysYvP" =>
437
- [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
438
- "mxYzRdJfPk8PcaKSsSzNkX85mMfNcr2CGr" =>
439
- [0.002, 0.0, 0.002, 0.002, 0.0, 0.002],
440
- "mzbXim4u1Nq4J2kVggu471pZL3ahxNkmE9" =>
441
- [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
429
+ => {
430
+ "mhLAgRz5f1YogfYBZCDFSRt3ceeKBPVEKg" =>
431
+ [0.00544426, 0.00544426, 0.0, 0.00544426, 0.00544426, 0.0],
432
+ "mjfa56Keq7PXRKgdPSDB6eWLp4aaAVcj6L" =>
433
+ [0.005, 0.0, 0.005, 0.006, 0.0, 0.006],
434
+ "mvrDG7Ts6Mq9ejhZxdsQLjbScycVaktqsg" =>
435
+ [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
436
+ "mwZE4QfzzriE7nsgHSWbgmtT7s6SDysYvP" =>
437
+ [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
438
+ "mxYzRdJfPk8PcaKSsSzNkX85mMfNcr2CGr" =>
439
+ [0.002, 0.0, 0.002, 0.002, 0.0, 0.002],
440
+ "mzbXim4u1Nq4J2kVggu471pZL3ahxNkmE9" =>
441
+ [0.005, 0.0, 0.005, 0.005, 0.0, 0.005],
442
+ }
442
443
  ```
443
444
 
444
445
  ## list_unspent(addresses)
@@ -89,7 +89,8 @@ class Pochette::Backends::BlockchainInfo
89
89
  uri = URI.parse("https://blockchain.info/pushtx")
90
90
  params = { "tx" => hex }
91
91
  params['api_code'] = api_key if api_key
92
- Net::HTTP.post_form(uri, params)
92
+ response = Net::HTTP.post_form(uri, params)
93
+ raise StandardError.new(response) if response.code.to_i != 200
93
94
  Bitcoin::Protocol::Tx.new(hex.htb).hash
94
95
  end
95
96
 
@@ -5,6 +5,8 @@
5
5
  # you can query the results via to_hash.
6
6
 
7
7
  class Pochette::TransactionBuilder
8
+ include Contracts::Core
9
+
8
10
  # Backend can be set globally, or independently for each class and instance.
9
11
  class_attribute :backend
10
12
  def self.backend
@@ -17,10 +19,17 @@ class Pochette::TransactionBuilder
17
19
  cattr_accessor(:network_minimum_fee){ 10000 }
18
20
  cattr_accessor(:default_fee_per_kb){ 10000 }
19
21
 
22
+ Contract ({
23
+ :addresses => C::ArrayOf[String],
24
+ :outputs => C::Maybe[C::ArrayOf[[String, C::Num]]],
25
+ :utxo_blacklist => C::Maybe[C::ArrayOf[[String, Integer]]],
26
+ :change_address => C::Maybe[String],
27
+ :fee_per_kb => C::Maybe[C::Num],
28
+ :spend_all => C::Maybe[C::Bool],
29
+ }) => C::Any
20
30
  def initialize(options)
21
31
  self.backend = options[:backend] if options[:backend]
22
32
  initialize_options(options)
23
- return unless valid?
24
33
  initialize_fee
25
34
  initialize_outputs
26
35
  return unless valid?
@@ -29,6 +38,14 @@ class Pochette::TransactionBuilder
29
38
  validate_final_amounts
30
39
  end
31
40
 
41
+ Contract C::None => C::Maybe[({
42
+ :input_total => C::Num,
43
+ :output_total => C::Num,
44
+ :fee => C::Num,
45
+ :outputs => C::ArrayOf[[String, C::Num]],
46
+ :inputs => C::ArrayOf[[String, String, Integer, C::Num]],
47
+ :utxos_to_blacklist => C::ArrayOf[[String, Integer]]
48
+ })]
32
49
  def as_hash
33
50
  return nil unless valid?
34
51
  { input_total: inputs_amount,
@@ -58,9 +75,6 @@ protected
58
75
  self.options = options
59
76
  self.errors ||= []
60
77
  self.addresses = options[:addresses]
61
- if addresses.nil? || addresses.empty?
62
- return errors << :no_addresses_given
63
- end
64
78
  end
65
79
 
66
80
  def initialize_fee
@@ -1,37 +1,16 @@
1
1
  # Same as TransactionBuilder but outputs a transaction hash with all the
2
2
  # required data to create and sign a transaction using a BitcoinTrezor.
3
- # * Uses BIP32 addresses instead of regular strings.
4
- # Each address is represented as a pair, with the public address string
5
- # and the BIP32 path as a list of integers, for example:
6
- # ['public-address-as-string', [44, 1, 3, 11]]
7
- #
8
- # * Includes associated transaction data for each input being spent,
9
- # ready to be consumed by your Trezor device.
10
- #
11
- # * Outputs are represented as JSON with script_type as expected by Trezor.
12
- # { script_type: 'PAYTOADDRESS',
13
- # address: '1address-as-string',
14
- # amount: amount_in_satoshis }
15
- #
16
- # Options:
17
- # bip32_addresses:
18
- # List of [address, path] pairs in wallet.
19
- # We will be spending their unspent outputs.
20
- # outputs:
21
- # List of pairs [recipient_address, amount]
22
- # This will not be all the final outputs in the transaction,
23
- # as a 'change' output may be added if needed.
24
- # utxo_blacklist:
25
- # List of utxos to ignore, a list of pairs [transaction hash, position]
26
- # change_address:
27
- # Change address to use. Will default to the first source address.
28
- # fee_per_kb:
29
- # Defaults to 10000 satoshis.
30
- # spend_all:
31
- # Wether to spend all available utxos or just select enough to
32
- # cover the given outputs.
33
3
 
34
4
  class Pochette::TrezorTransactionBuilder < Pochette::TransactionBuilder
5
+
6
+ Contract ({
7
+ :bip32_addresses => C::ArrayOf[[String, C::ArrayOf[Integer]]],
8
+ :outputs => C::Maybe[C::ArrayOf[[String, C::Num]]],
9
+ :utxo_blacklist => C::Maybe[C::ArrayOf[[String, Integer]]],
10
+ :change_address => C::Maybe[String],
11
+ :fee_per_kb => C::Maybe[C::Num],
12
+ :spend_all => C::Maybe[C::Bool],
13
+ }) => C::Any
35
14
  def initialize(options)
36
15
  options = options.dup
37
16
  initialize_bip32_addresses(options)
@@ -42,6 +21,25 @@ class Pochette::TrezorTransactionBuilder < Pochette::TransactionBuilder
42
21
  build_transactions
43
22
  end
44
23
 
24
+ Contract C::None => C::Maybe[({
25
+ :input_total => C::Num,
26
+ :output_total => C::Num,
27
+ :fee => C::Num,
28
+ :outputs => C::ArrayOf[[String, C::Num]],
29
+ :inputs => C::ArrayOf[[String, String, Integer, C::Num]],
30
+ :utxos_to_blacklist => C::ArrayOf[[String, Integer]],
31
+ :transactions => C::ArrayOf[Hash],
32
+ :trezor_inputs => C::ArrayOf[{
33
+ address_n: C::ArrayOf[Integer],
34
+ prev_hash: String,
35
+ prev_index: Integer
36
+ }],
37
+ :trezor_outputs => C::ArrayOf[{
38
+ script_type: String,
39
+ address: String,
40
+ amount: C::Num
41
+ }]
42
+ })]
45
43
  def as_hash
46
44
  return nil unless valid?
47
45
  super.merge(
@@ -1,3 +1,3 @@
1
1
  module Pochette
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/pochette.rb CHANGED
@@ -3,17 +3,26 @@ require "bitcoin_rpc"
3
3
  require "active_support"
4
4
  require "active_support/core_ext"
5
5
  require "bitcoin"
6
+ require "contracts"
7
+ C = Contracts
6
8
 
7
9
  module Pochette
10
+ include Contracts::Core
11
+
8
12
  mattr_accessor :backend
9
13
 
14
+ Contract C::Bool => C::Bool
10
15
  def self.testnet=(v)
11
- @testnet = v
12
16
  Bitcoin.network = v ? :testnet : :bitcoin
17
+ @testnet = v
13
18
  end
19
+
20
+ Contract C::None => C::Bool
14
21
  def self.testnet
15
- @testnet
22
+ @testnet || false
16
23
  end
24
+
25
+ Contract C::None => C::Bool
17
26
  def self.testnet?
18
27
  self.testnet
19
28
  end
data/pochette.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "activesupport", "~> 4.2"
24
24
  spec.add_dependency "bitcoin_rpc", "~> 0.1.1"
25
25
  spec.add_dependency "bitcoin-ruby", "~> 0.0.7"
26
+ spec.add_dependency "contracts"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.9"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pochette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nubis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-28 00:00:00.000000000 Z
12
+ date: 2015-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.0.7
56
+ - !ruby/object:Gem::Dependency
57
+ name: contracts
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: bundler
58
72
  requirement: !ruby/object:Gem::Requirement