cryptocoin 0.0.1b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +85 -0
  7. data/Rakefile +2 -0
  8. data/cryptocoin.gemspec +24 -0
  9. data/lib/cryptocoin/core_ext/integer.rb +24 -0
  10. data/lib/cryptocoin/core_ext/string.rb +30 -0
  11. data/lib/cryptocoin/digest.rb +36 -0
  12. data/lib/cryptocoin/merkle_tree.rb +78 -0
  13. data/lib/cryptocoin/network/bitcoin.rb +9 -0
  14. data/lib/cryptocoin/network/dogecoin.rb +9 -0
  15. data/lib/cryptocoin/network/litecoin.rb +9 -0
  16. data/lib/cryptocoin/network.rb +53 -0
  17. data/lib/cryptocoin/protocol/block_header.rb +58 -0
  18. data/lib/cryptocoin/protocol/inventory_vector.rb +28 -0
  19. data/lib/cryptocoin/protocol/message/addr.rb +29 -0
  20. data/lib/cryptocoin/protocol/message/alert.rb +0 -0
  21. data/lib/cryptocoin/protocol/message/block.rb +13 -0
  22. data/lib/cryptocoin/protocol/message/getaddr.rb +17 -0
  23. data/lib/cryptocoin/protocol/message/getblocks.rb +44 -0
  24. data/lib/cryptocoin/protocol/message/getdata.rb +31 -0
  25. data/lib/cryptocoin/protocol/message/getheaders.rb +44 -0
  26. data/lib/cryptocoin/protocol/message/headers.rb +30 -0
  27. data/lib/cryptocoin/protocol/message/inv.rb +31 -0
  28. data/lib/cryptocoin/protocol/message/mempool.rb +16 -0
  29. data/lib/cryptocoin/protocol/message/notfound.rb +31 -0
  30. data/lib/cryptocoin/protocol/message/ping.rb +24 -0
  31. data/lib/cryptocoin/protocol/message/pong.rb +24 -0
  32. data/lib/cryptocoin/protocol/message/reject.rb +54 -0
  33. data/lib/cryptocoin/protocol/message/tx.rb +11 -0
  34. data/lib/cryptocoin/protocol/message/verack.rb +16 -0
  35. data/lib/cryptocoin/protocol/message/version.rb +59 -0
  36. data/lib/cryptocoin/protocol/message.rb +27 -0
  37. data/lib/cryptocoin/protocol/net_addr.rb +55 -0
  38. data/lib/cryptocoin/protocol/packet.rb +74 -0
  39. data/lib/cryptocoin/protocol/var_len_int.rb +85 -0
  40. data/lib/cryptocoin/protocol/var_len_str.rb +18 -0
  41. data/lib/cryptocoin/protocol.rb +8 -0
  42. data/lib/cryptocoin/script/op_code/constants.rb +157 -0
  43. data/lib/cryptocoin/script/op_code/functions.rb +515 -0
  44. data/lib/cryptocoin/script/op_code.rb +59 -0
  45. data/lib/cryptocoin/script.rb +234 -0
  46. data/lib/cryptocoin/structure/address.rb +64 -0
  47. data/lib/cryptocoin/structure/block.rb +109 -0
  48. data/lib/cryptocoin/structure/key_pair.rb +57 -0
  49. data/lib/cryptocoin/structure/merkle_branch.rb +37 -0
  50. data/lib/cryptocoin/structure/transaction/input.rb +80 -0
  51. data/lib/cryptocoin/structure/transaction/output.rb +49 -0
  52. data/lib/cryptocoin/structure/transaction.rb +94 -0
  53. data/lib/cryptocoin/version.rb +3 -0
  54. data/lib/cryptocoin.rb +29 -0
  55. data/spec/script_spec.rb +42 -0
  56. data/spec/spec_helper.rb +20 -0
  57. metadata +145 -0
@@ -0,0 +1,94 @@
1
+ require 'cryptocoin/structure/transaction/input'
2
+ require 'cryptocoin/structure/transaction/output'
3
+ require 'cryptocoin/protocol/var_len_int'
4
+
5
+ module Cryptocoin
6
+ module Structure
7
+ class Transaction
8
+ attr_reader :inputs, :outputs
9
+
10
+ def self.parse_from_io(io)
11
+ inputs, outputs = [], []
12
+ version_raw = io.read(4)
13
+ in_length = Cryptocoin::Protocol::VarLenInt.parse_from_io(io)
14
+ in_length.times do |i|
15
+ inputs.push(Cryptocoin::Structure::Transaction::Input.parse_from_io(i, io))
16
+ end
17
+ out_length = Cryptocoin::Protocol::VarLenInt.parse_from_io(io)
18
+ out_length.times do |i|
19
+ outputs.push(Cryptocoin::Structure::Transaction::Output.parse_from_io(i, io))
20
+ end
21
+ lock_time_raw = io.read(4)
22
+ self.new(version_raw, in_length, inputs, out_length, outputs, lock_time_raw)
23
+ end
24
+
25
+ def self.parse_from_raw(raw)
26
+ c = 0
27
+ inputs, outputs = [], []
28
+ version_raw = raw[c..5]
29
+ c += 5
30
+ in_length = Cryptocoin::Protocol::VarLenInt.new(raw[c..-1]) # Don't know the length
31
+ c += in_length.raw.bytesize
32
+ in_length.times do |i|
33
+ tx = Cryptocoin::Structure::Transaction::Input.parse_from_raw(i, raw[c..-1])
34
+ inputs.push(tx)
35
+ c += tx.raw.bytesize
36
+ end
37
+
38
+ out_length = Cryptocoin::Protocol::VarLenInt.new(raw[c..-1])
39
+ out_length.times do |i|
40
+ tx = Cryptocoin::Structure::Transaction::Output.parse_from_raw(i, raw[c..-1])
41
+ outputs.push(tx)
42
+ c += tx.raw.bytesize
43
+ end
44
+ lock_time_raw = raw[c..c+4]
45
+ self.new(version_raw, in_length, inputs, out_length, outputs, lock_time_raw)
46
+ end
47
+
48
+ def initialize(version_raw, in_length, inputs, out_length, outputs, lock_time_raw)
49
+ @version_raw = version_raw
50
+ @in_length = in_length
51
+ @inputs = inputs
52
+ @out_length = out_length
53
+ @outputs = outputs
54
+ @lock_time_raw = lock_time_raw
55
+ end
56
+
57
+ def version
58
+ @version_raw.unpack('V')[0]
59
+ end
60
+
61
+ def lock_time
62
+ @lock_time_raw.unpack('V')[0]
63
+ end
64
+
65
+ def raw
66
+ @version_raw + @in_length.raw + @inputs.map{|e| e.raw }.join + @out_length.raw + @outputs.map{|e| e.raw}.join + @lock_time_raw
67
+ end
68
+
69
+ def size
70
+ raw.bytesize
71
+ end
72
+
73
+ def copy
74
+ r = self
75
+ ['lock_time_raw', 'version_raw', 'inputs', 'outputs'].each do |i|
76
+ r.class.send(:define_method, "#{i}=") do |j|
77
+ instance_variable_set("@#{i}", j)
78
+ end
79
+ end
80
+ a = []
81
+ r.inputs.each do |i|
82
+ a.push(i.copy)
83
+ end
84
+ r.inputs = a
85
+ a = []
86
+ r.outputs.each do |i|
87
+ a.push(i.copy)
88
+ end
89
+ r.outputs = a
90
+ r
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module Cryptocoin
2
+ VERSION = "0.0.1b"
3
+ end
data/lib/cryptocoin.rb ADDED
@@ -0,0 +1,29 @@
1
+ # Version
2
+ require 'cryptocoin/version'
3
+
4
+ # Core extensions
5
+ require 'cryptocoin/core_ext/integer'
6
+ require 'cryptocoin/core_ext/string'
7
+
8
+ # Non cryptocoin files
9
+ require 'digest/sha2'
10
+ require 'digest/rmd160'
11
+
12
+ # General cryptocoin files
13
+ require 'cryptocoin/digest'
14
+ require 'cryptocoin/merkle_tree'
15
+ require 'cryptocoin/network'
16
+ require 'cryptocoin/protocol'
17
+ require 'cryptocoin/script'
18
+ require 'cryptocoin/structure/address'
19
+ require 'cryptocoin/structure/block'
20
+ require 'cryptocoin/structure/key_pair'
21
+ require 'cryptocoin/structure/transaction'
22
+ require 'cryptocoin/structure/merkle_branch'
23
+
24
+ # Networks
25
+ require 'cryptocoin/network/bitcoin'
26
+ require 'cryptocoin/network/litecoin'
27
+ require 'cryptocoin/network/dogecoin'
28
+
29
+ module Cryptocoin; end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'cryptocoin/script'
3
+
4
+ describe Cryptocoin::Script do
5
+ describe "#from_s" do
6
+ it 'returns a new Script object when passed a valid Script directive' do
7
+ script = Cryptocoin::Script.from_s('OP_1')
8
+ script.should be_an_instance_of Cryptocoin::Script
9
+ end
10
+
11
+ it 'does not return a new Script object when passed an invalid directive' do
12
+ script = Cryptocoin::Script.from_s('Gobbledegook')
13
+ script.should_not be_an_instance_of Cryptocoin::Script
14
+ end
15
+
16
+ it 'creates a Script object with an invalid opcode' do
17
+ script = Cryptocoin::Script.from_s('OP_1 OP_CAT OP_MOD')
18
+ script.should be_an_instance_of Cryptocoin::Script
19
+ end
20
+ end
21
+
22
+ describe "#new" do
23
+
24
+ end
25
+
26
+ describe "#subscript!" do
27
+
28
+ end
29
+
30
+ describe "#subscript!" do
31
+
32
+ end
33
+
34
+ describe "#subscript!" do
35
+
36
+ end
37
+
38
+ describe "#subscript!" do
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'bundler/setup'
8
+ Bundler.setup
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptocoin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1b
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Smock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Cryptocoin is a library for processing messages and information from
56
+ a cryptocoin network, such as a packet of information, and creating useful wrappers
57
+ for such data.
58
+ email:
59
+ - joshua.smock@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - cryptocoin.gemspec
71
+ - lib/cryptocoin.rb
72
+ - lib/cryptocoin/core_ext/integer.rb
73
+ - lib/cryptocoin/core_ext/string.rb
74
+ - lib/cryptocoin/digest.rb
75
+ - lib/cryptocoin/merkle_tree.rb
76
+ - lib/cryptocoin/network.rb
77
+ - lib/cryptocoin/network/bitcoin.rb
78
+ - lib/cryptocoin/network/dogecoin.rb
79
+ - lib/cryptocoin/network/litecoin.rb
80
+ - lib/cryptocoin/protocol.rb
81
+ - lib/cryptocoin/protocol/block_header.rb
82
+ - lib/cryptocoin/protocol/inventory_vector.rb
83
+ - lib/cryptocoin/protocol/message.rb
84
+ - lib/cryptocoin/protocol/message/addr.rb
85
+ - lib/cryptocoin/protocol/message/alert.rb
86
+ - lib/cryptocoin/protocol/message/block.rb
87
+ - lib/cryptocoin/protocol/message/getaddr.rb
88
+ - lib/cryptocoin/protocol/message/getblocks.rb
89
+ - lib/cryptocoin/protocol/message/getdata.rb
90
+ - lib/cryptocoin/protocol/message/getheaders.rb
91
+ - lib/cryptocoin/protocol/message/headers.rb
92
+ - lib/cryptocoin/protocol/message/inv.rb
93
+ - lib/cryptocoin/protocol/message/mempool.rb
94
+ - lib/cryptocoin/protocol/message/notfound.rb
95
+ - lib/cryptocoin/protocol/message/ping.rb
96
+ - lib/cryptocoin/protocol/message/pong.rb
97
+ - lib/cryptocoin/protocol/message/reject.rb
98
+ - lib/cryptocoin/protocol/message/tx.rb
99
+ - lib/cryptocoin/protocol/message/verack.rb
100
+ - lib/cryptocoin/protocol/message/version.rb
101
+ - lib/cryptocoin/protocol/net_addr.rb
102
+ - lib/cryptocoin/protocol/packet.rb
103
+ - lib/cryptocoin/protocol/var_len_int.rb
104
+ - lib/cryptocoin/protocol/var_len_str.rb
105
+ - lib/cryptocoin/script.rb
106
+ - lib/cryptocoin/script/op_code.rb
107
+ - lib/cryptocoin/script/op_code/constants.rb
108
+ - lib/cryptocoin/script/op_code/functions.rb
109
+ - lib/cryptocoin/structure/address.rb
110
+ - lib/cryptocoin/structure/block.rb
111
+ - lib/cryptocoin/structure/key_pair.rb
112
+ - lib/cryptocoin/structure/merkle_branch.rb
113
+ - lib/cryptocoin/structure/transaction.rb
114
+ - lib/cryptocoin/structure/transaction/input.rb
115
+ - lib/cryptocoin/structure/transaction/output.rb
116
+ - lib/cryptocoin/version.rb
117
+ - spec/script_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/joshuasmock/cryptocoin
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">"
135
+ - !ruby/object:Gem::Version
136
+ version: 1.3.1
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Cryptocoin is a library for interfacing with Bitcoin and Bitcoin-like coins
143
+ test_files:
144
+ - spec/script_spec.rb
145
+ - spec/spec_helper.rb