mastercoin-ruby 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +61 -0
- data/README.md +85 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/exodus_payment +27 -0
- data/bin/mastercoin_transaction +21 -0
- data/bin/simple_send +52 -0
- data/bin/wallet.rb +169 -0
- data/lib/mastercoin-ruby/bitcoin_wrapper.rb +44 -0
- data/lib/mastercoin-ruby/exodus_payment.rb +146 -0
- data/lib/mastercoin-ruby/simple_send.rb +67 -0
- data/lib/mastercoin-ruby/transaction.rb +94 -0
- data/lib/mastercoin-ruby/util.rb +24 -0
- data/lib/mastercoin-ruby.rb +54 -0
- data/mastercoin-ruby.gemspec +77 -0
- data/spec/simple_send.rb +64 -0
- metadata +185 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
gem 'bitcoin-ruby', '~> 0.0.1', git: "https://github.com/maran/bitcoin-ruby.git"
|
10
|
+
gem 'sequel', '~> 4.1.1'
|
11
|
+
gem 'thor'
|
12
|
+
|
13
|
+
group :development do
|
14
|
+
gem "rdoc", "~> 3.12"
|
15
|
+
gem "bundler", "~> 1.0"
|
16
|
+
gem "jeweler", "~> 1.8.7"
|
17
|
+
gem "rspec"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/maran/bitcoin-ruby.git
|
3
|
+
revision: b9baf584a509e89cca0a9e5dc879f225dd9aa529
|
4
|
+
specs:
|
5
|
+
bitcoin-ruby (0.0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.5)
|
11
|
+
builder (3.2.2)
|
12
|
+
diff-lcs (1.2.4)
|
13
|
+
faraday (0.8.8)
|
14
|
+
multipart-post (~> 1.2.0)
|
15
|
+
git (1.2.6)
|
16
|
+
github_api (0.10.1)
|
17
|
+
addressable
|
18
|
+
faraday (~> 0.8.1)
|
19
|
+
hashie (>= 1.2)
|
20
|
+
multi_json (~> 1.4)
|
21
|
+
nokogiri (~> 1.5.2)
|
22
|
+
oauth2
|
23
|
+
hashie (2.0.5)
|
24
|
+
highline (1.6.19)
|
25
|
+
httpauth (0.2.0)
|
26
|
+
jeweler (1.8.7)
|
27
|
+
builder
|
28
|
+
bundler (~> 1.0)
|
29
|
+
git (>= 1.2.5)
|
30
|
+
github_api (= 0.10.1)
|
31
|
+
highline (>= 1.6.15)
|
32
|
+
nokogiri (= 1.5.10)
|
33
|
+
rake
|
34
|
+
rdoc
|
35
|
+
json (1.8.0)
|
36
|
+
jwt (0.1.8)
|
37
|
+
multi_json (>= 1.5)
|
38
|
+
multi_json (1.8.0)
|
39
|
+
multi_xml (0.5.5)
|
40
|
+
multipart-post (1.2.0)
|
41
|
+
nokogiri (1.5.10)
|
42
|
+
oauth2 (0.9.2)
|
43
|
+
faraday (~> 0.8)
|
44
|
+
httpauth (~> 0.2)
|
45
|
+
jwt (~> 0.1.4)
|
46
|
+
multi_json (~> 1.0)
|
47
|
+
multi_xml (~> 0.5)
|
48
|
+
rack (~> 1.2)
|
49
|
+
rack (1.5.2)
|
50
|
+
rake (10.1.0)
|
51
|
+
rdoc (3.12.2)
|
52
|
+
json (~> 1.4)
|
53
|
+
rspec (2.14.1)
|
54
|
+
rspec-core (~> 2.14.0)
|
55
|
+
rspec-expectations (~> 2.14.0)
|
56
|
+
rspec-mocks (~> 2.14.0)
|
57
|
+
rspec-core (2.14.5)
|
58
|
+
rspec-expectations (2.14.2)
|
59
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
60
|
+
rspec-mocks (2.14.3)
|
61
|
+
sequel (4.1.1)
|
62
|
+
thor (0.18.1)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
bitcoin-ruby (~> 0.0.1)!
|
69
|
+
bundler (~> 1.0)
|
70
|
+
jeweler (~> 1.8.7)
|
71
|
+
rdoc (~> 3.12)
|
72
|
+
rspec
|
73
|
+
sequel (~> 4.1.1)
|
74
|
+
thor
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Copyright (c) 2013 Maran
|
2
|
+
|
3
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
|
4
|
+
License
|
5
|
+
|
6
|
+
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
|
7
|
+
|
8
|
+
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
|
9
|
+
|
10
|
+
1. Definitions
|
11
|
+
|
12
|
+
"Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
|
13
|
+
"Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
|
14
|
+
"Distribute" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
|
15
|
+
"License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike.
|
16
|
+
"Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
|
17
|
+
"Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
|
18
|
+
"Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
|
19
|
+
"You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
|
20
|
+
"Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
|
21
|
+
"Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
|
22
|
+
2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
|
23
|
+
|
24
|
+
3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
|
25
|
+
|
26
|
+
to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
|
27
|
+
to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
|
28
|
+
to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
|
29
|
+
to Distribute and Publicly Perform Adaptations.
|
30
|
+
The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e).
|
31
|
+
|
32
|
+
4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
|
33
|
+
|
34
|
+
You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
|
35
|
+
You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
|
36
|
+
You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works.
|
37
|
+
If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
|
38
|
+
For the avoidance of doubt:
|
39
|
+
|
40
|
+
Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
|
41
|
+
Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
|
42
|
+
Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c).
|
43
|
+
Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
|
44
|
+
5. Representations, Warranties and Disclaimer
|
45
|
+
|
46
|
+
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
|
47
|
+
|
48
|
+
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
49
|
+
|
50
|
+
7. Termination
|
51
|
+
|
52
|
+
This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
|
53
|
+
Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
|
54
|
+
8. Miscellaneous
|
55
|
+
|
56
|
+
Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
|
57
|
+
Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
|
58
|
+
If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
|
59
|
+
No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
|
60
|
+
This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
|
61
|
+
The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# mastercoin-ruby
|
2
|
+
|
3
|
+
Mastercoin-ruby is a ruby library for Mastercoin.
|
4
|
+
|
5
|
+
## Currently implemented
|
6
|
+
|
7
|
+
* Simple Send encoding to public keys
|
8
|
+
* Simple Send encoding to Bitcoin addresses
|
9
|
+
* Advise on creating a Address based transaction
|
10
|
+
* Lookup Exodus payments based on address or transaction
|
11
|
+
|
12
|
+
## Example usage
|
13
|
+
|
14
|
+
### Decoding a address
|
15
|
+
> $ simple_send decode_from_address 1CVE9Au1XEm3MkYxeAhUDVqWvaHrP98iUt
|
16
|
+
|
17
|
+
> $ SimpleSend transaction for 100.00000000 Mastercoin.
|
18
|
+
|
19
|
+
### Decoding a public key
|
20
|
+
|
21
|
+
> $ simple_send decode_from_public_key "02000000000000000002000000000000000100000000000000000000000000000"
|
22
|
+
|
23
|
+
> $ SimpleSend transaction for 0.00000001 Test Mastercoin.
|
24
|
+
|
25
|
+
### Encoding to address
|
26
|
+
|
27
|
+
> $ simple_send encode_to_address --amount=100000000 --currency-id=2 --receiving_address=1CcJFxoEW5PUwesMVxGrq6kAPJ1TJsSVqq
|
28
|
+
|
29
|
+
> $ 1CVE9Au1XEm3MsiMuLZpzvZinf4Fgu7aeA
|
30
|
+
|
31
|
+
### Advise for Simple Send
|
32
|
+
|
33
|
+
> $ simple_send advise --amount=100000000 --currency-id=2 --receiving_address=1CcJFxoEW5PUwesMVxGrq6kAPJ1TJsSVqq
|
34
|
+
|
35
|
+
> $ Step 1: Send all funds in your wallet to the address which owns the MasterCoins (the following sends must come from that address)
|
36
|
+
Step 2: Send exactly 0.00006 BTC from your address to each of the following 3 addresses in one transaction:
|
37
|
+
The Exodus Address: 1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P
|
38
|
+
The recipient address: 1CcJFxoEW5PUwesMVxGrq6kAPJ1TJsSVqq
|
39
|
+
The data address: 1CVE9Au1XEm3MsiMuLZpzvZinf4Fgu7aeA
|
40
|
+
|
41
|
+
**Please note: The following commands will need a connection to an up-to-date bitcoin-ruby node since they need to traverse the network for Mastercoin data.**
|
42
|
+
|
43
|
+
### Checking how many coins a certain transaction to Exodus bought
|
44
|
+
|
45
|
+
> $ exodus_payment from_transaction 4c097244046e1b1fa23edc7ad8efd10babbe7c0caa13925c33097b84dae57af7 --storage="postgres://username:password@ip/database"
|
46
|
+
|
47
|
+
> $ Bought 1100.0 Mastercoins and got a 0 Mastercoins extra.
|
48
|
+
|
49
|
+
### Checking total Exodus payment for a given address
|
50
|
+
|
51
|
+
> $ exodus_payment from_address 1HRE7U9XNPD8kJBCwm5Q1VAepz25GBXnVk --storage="postgres://username:password@ip/database"
|
52
|
+
|
53
|
+
> $ Bought 1945.780909 Mastercoins and got a 2.05452329 Mastercoins extra.
|
54
|
+
|
55
|
+
### Decoding a Mastercoin transaction based on Bitcoin transaction hash
|
56
|
+
|
57
|
+
> $ bin/mastercoin_transaction lookup 4cad027f03f984d7745c077820617318c7553a90ca64be56e78217fc18cf4ea5 --storage="postgres://username:password@ip/database"
|
58
|
+
|
59
|
+
> $ Simple send:: Sent 1.3 'Mastercoin' to 1F73UPD5xBKgTSRd8q6QhuncVmDnJAHxYV
|
60
|
+
|
61
|
+
**The following commands need a connection to a Bitcoin RPC server with a Mastercoin address.**
|
62
|
+
|
63
|
+
### Sending a multisig Simple Send Mastercoin transaction via Bitcoin-QT/D
|
64
|
+
|
65
|
+
> $ wallet.rb build_transaction FROM_ADDRESS TO_ADDRESS AMOUNT_OF_TEST_MASTERCOINS --bitcoin_rpc=http://bitcoin:rpcconnection@localhost:8332
|
66
|
+
|
67
|
+
> $ wallet.rb build_transaction mgpbsAjKBw4qArWJLxpygPS5dmmTGsEHz3 n3wLS8G69kD96Czw3xbUg17ipsb2W1NGvB 10 --bitcoin_rpc=http://bitcoin:rpcconnection@localhost:8332
|
68
|
+
|
69
|
+
These commands require an unlocked wallet; please realise that this exposes private keys. Only use this code if you understand what it does.
|
70
|
+
|
71
|
+
## Contributing to mastercoin-ruby
|
72
|
+
|
73
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
74
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
75
|
+
* Fork the project.
|
76
|
+
* Start a feature/bugfix branch.
|
77
|
+
* Commit and push until you are happy with your contribution.
|
78
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
79
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
80
|
+
|
81
|
+
## Copyright
|
82
|
+
|
83
|
+
Copyright (c) 2013 Maran. See LICENSE.txt for
|
84
|
+
further details.
|
85
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mastercoin-ruby"
|
18
|
+
gem.homepage = "http://github.com/maran/mastercoin-ruby"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby library for the Mastercoin protocol}
|
21
|
+
gem.description = %Q{Basic implementation of the Mastercoin protocol.}
|
22
|
+
gem.email = "maran.hidskes@gmail.com"
|
23
|
+
gem.authors = ["Maran"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
#require 'rcov/rcovtask'
|
36
|
+
#Rcov::RcovTask.new do |test|
|
37
|
+
# test.libs << 'test'
|
38
|
+
# test.pattern = 'test/**/test_*.rb'
|
39
|
+
# test.verbose = true
|
40
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
#end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "mastercoin-ruby #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/exodus_payment
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift( File.expand_path("../../lib", __FILE__) )
|
3
|
+
require 'mastercoin-ruby'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Mastercoin
|
7
|
+
module Cli
|
8
|
+
class ExodusPayment < Thor
|
9
|
+
class_option :storage, required: true
|
10
|
+
|
11
|
+
desc "from_transaction <tx_hash>", "Calculates coins bought via Exodus payment"
|
12
|
+
def from_transaction(hash)
|
13
|
+
puts "Looking up tx with hash #{hash}"
|
14
|
+
Mastercoin.set_storage(options[:storage])
|
15
|
+
puts Mastercoin::ExodusPayment.from_transaction(hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "from_address <bitcoin_address>", "Calculates total amount of mastercoins bought"
|
19
|
+
def from_address(address)
|
20
|
+
Mastercoin.set_storage(options[:storage])
|
21
|
+
puts Mastercoin::ExodusPayment.from_address(address)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Mastercoin::Cli::ExodusPayment.start(ARGV)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift( File.expand_path("../../lib", __FILE__) )
|
3
|
+
require 'mastercoin-ruby'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Mastercoin
|
7
|
+
module Cli
|
8
|
+
class Transactions < Thor
|
9
|
+
class_option :storage, required: true
|
10
|
+
|
11
|
+
desc "lookup <tx_hash>", "Decodes the Mastercoin data in a given Bitcoin transaction hash"
|
12
|
+
def lookup(hash)
|
13
|
+
puts "Looking up tx with hash #{hash}"
|
14
|
+
Mastercoin.set_storage(options[:storage])
|
15
|
+
puts Mastercoin::Transaction.new(hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Mastercoin::Cli::Transactions.start(ARGV)
|
data/bin/simple_send
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift( File.expand_path("../../lib", __FILE__) )
|
3
|
+
require 'mastercoin-ruby'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Mastercoin
|
7
|
+
module Cli
|
8
|
+
class SimpleSend < Thor
|
9
|
+
desc "decode_from_public_key <public key>", "Decodes a simple send based on a given public key"
|
10
|
+
def decode_from_public_key(public_key)
|
11
|
+
puts Mastercoin::SimpleSend.decode_from_compressed_public_key(public_key).to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "decode_from_address <address>", "Decodes a simple send based on a address"
|
15
|
+
def decode_from_address(address)
|
16
|
+
puts Mastercoin::SimpleSend.decode_from_address(address).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "encode_to_public_key <options>", "Encodes the parameters into a public key"
|
20
|
+
option :amount, required: true
|
21
|
+
option :currency_id, required: true, type: :numeric
|
22
|
+
def encode_to_public_key
|
23
|
+
simple_send = Mastercoin::SimpleSend.new(currency_id: options[:currency_id], amount: options[:amount])
|
24
|
+
puts simple_send.encode_to_compressed_public_key
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "encode_to_address <options>", "Encodes the parameters into a bitcoin address"
|
28
|
+
option :amount, required: true
|
29
|
+
option :currency_id, required: true, type: :numeric
|
30
|
+
option :receiving_address, required: true
|
31
|
+
def encode_to_address
|
32
|
+
simple_send = Mastercoin::SimpleSend.new(currency_id: options[:currency_id], amount: options[:amount], receiving_address: options[:receiving_address])
|
33
|
+
puts simple_send.encode_to_address
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "advise <options>", "Gives advice on how to create a simple send Mastercoin address transaction"
|
37
|
+
option :amount, required: true
|
38
|
+
option :currency_id, required: true, type: :numeric
|
39
|
+
option :receiving_address, required: true
|
40
|
+
def advise
|
41
|
+
simple_send = Mastercoin::SimpleSend.new(currency_id: options[:currency_id], amount: options[:amount], receiving_address: options[:receiving_address])
|
42
|
+
puts "Step 1: Send all funds in your wallet to the address which owns the MasterCoins (the following sends must come from that address)
|
43
|
+
Step 2: Send exactly 0.00006 BTC from your address to each of the following 3 addresses in one transaction:
|
44
|
+
The Exodus Address: 1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P
|
45
|
+
The recipient address: #{options[:receiving_address]}
|
46
|
+
The data address: #{simple_send.encode_to_address}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Mastercoin::Cli::SimpleSend.start(ARGV)
|
data/bin/wallet.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift( File.expand_path("../../lib", __FILE__) )
|
3
|
+
require 'mastercoin-ruby'
|
4
|
+
require 'thor'
|
5
|
+
require 'bitcoin'
|
6
|
+
require 'json'
|
7
|
+
require 'io/console'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
module Mastercoin
|
11
|
+
module Cli
|
12
|
+
class Wallet < Thor
|
13
|
+
include Bitcoin::Builder
|
14
|
+
class_option :bitcoin_rpc, required: true
|
15
|
+
|
16
|
+
desc "from_address <bitcoin_address>", "Calculates total amount of mastercoins bought"
|
17
|
+
def build_transaction(from_address, to_address, amount)
|
18
|
+
Bitcoin.network = :bitcoin
|
19
|
+
|
20
|
+
w = Mastercoin::BitcoinWrapper.new(options[:bitcoin_rpc])
|
21
|
+
puts "+----------------------------------+"
|
22
|
+
puts "+ WARNING: ALPHA SOFTWARE +"
|
23
|
+
puts "+----------------------------------+"
|
24
|
+
puts ""
|
25
|
+
puts "This software might: "
|
26
|
+
puts "1. Skin and eat your cat alive"
|
27
|
+
puts "2. Eat your bitcoins"
|
28
|
+
puts "3. Do other scary things you never intended"
|
29
|
+
puts "So for now please only use this if you can read enough code to understand what is happening."
|
30
|
+
puts ""
|
31
|
+
puts "Please type: yup if you want to continue."
|
32
|
+
|
33
|
+
STDOUT.flush
|
34
|
+
do_it = $stdin.gets
|
35
|
+
unless do_it == "yup\n"
|
36
|
+
puts "I don't blame you, exiting"
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
|
40
|
+
puts ""
|
41
|
+
puts "This script requires the private key of your mastercoin address in order to create a signed transaction. It will need to unlock your wallet in order to do so."
|
42
|
+
puts "Please type your wallet passphrase to unlock your wallet for 30 seconds."
|
43
|
+
|
44
|
+
password = STDIN.noecho(&:gets)
|
45
|
+
password = password.gsub("\n","")
|
46
|
+
|
47
|
+
w.walletpassphrase(password, 30)
|
48
|
+
|
49
|
+
puts "Checking funds for address #{from_address}"
|
50
|
+
inputs = w.unspend_for_address(from_address).find{|x| next if x.nil?; x["amount"].to_f > (0.00006 * 3)}
|
51
|
+
unless inputs
|
52
|
+
puts("There are not enough bitcoin available to create a valid looking Mastercoin transaction. We want one output with enough funds for now.")
|
53
|
+
exit
|
54
|
+
else
|
55
|
+
puts("Enough Bitcoin funds available")
|
56
|
+
end
|
57
|
+
|
58
|
+
puts ">> Not checking for Mastercoin balance yet; assuming enough."
|
59
|
+
puts "Getting private key and public key for Mastercoin address"
|
60
|
+
|
61
|
+
private_key = w.dumpprivkey(from_address)
|
62
|
+
public_key = w.validateaddress(from_address)["pubkey"]
|
63
|
+
|
64
|
+
if inputs.is_a?(Array)
|
65
|
+
chosen_input = inputs.first
|
66
|
+
else
|
67
|
+
chosen_input = inputs
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Getting raw transaction data"
|
71
|
+
prev_tx = w.getrawtransaction(chosen_input["txid"])
|
72
|
+
|
73
|
+
puts "Found raw transaction; unpacking into tx"
|
74
|
+
prev_tx = Bitcoin::Protocol::Tx.new([prev_tx].pack("H*"))
|
75
|
+
|
76
|
+
total_amount = chosen_input["amount"]
|
77
|
+
fee = 0.0001
|
78
|
+
tx_amount = 0.00006
|
79
|
+
mastercoin_tx = (4 * tx_amount)
|
80
|
+
change_amount = total_amount - fee - mastercoin_tx
|
81
|
+
puts "Setting fees"
|
82
|
+
|
83
|
+
data_key = Mastercoin::SimpleSend.new(currency_id: 2, amount: amount.to_f * 1e8).encode_to_compressed_public_key
|
84
|
+
|
85
|
+
puts "Total amount available from input: #{total_amount}"
|
86
|
+
puts "Paying #{fee} network fees"
|
87
|
+
puts "Taking #{mastercoin_tx} out of total for each mastercoin output"
|
88
|
+
puts "Sending #{change_amount} back to mastercoin address"
|
89
|
+
puts "Using public key for data: #{data_key}"
|
90
|
+
tx = build_tx do |t|
|
91
|
+
t.input do |i|
|
92
|
+
i.prev_out prev_tx
|
93
|
+
i.prev_out_index chosen_input["vout"]
|
94
|
+
i.signature_key Bitcoin::Key.from_base58(private_key)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Change address
|
98
|
+
t.output do |o|
|
99
|
+
o.value change_amount * 1e8
|
100
|
+
|
101
|
+
o.script do |s|
|
102
|
+
s.type :address
|
103
|
+
s.recipient from_address
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Receiving address
|
108
|
+
t.output do |o|
|
109
|
+
o.value tx_amount * 1e8
|
110
|
+
|
111
|
+
o.script do |s|
|
112
|
+
s.type :address
|
113
|
+
s.recipient to_address
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Exodus address
|
118
|
+
t.output do |o|
|
119
|
+
o.value tx_amount * 1e8
|
120
|
+
|
121
|
+
o.script do |s|
|
122
|
+
s.type :address
|
123
|
+
s.recipient Mastercoin::EXODUS_ADDRESS
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Data address
|
128
|
+
t.output do |o|
|
129
|
+
o.value (tx_amount * 1e8) * 2
|
130
|
+
|
131
|
+
o.script do |s|
|
132
|
+
s.type :multisig
|
133
|
+
s.recipient 1, public_key, data_key
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
tx = Bitcoin::Protocol::Tx.new( tx.to_payload )
|
139
|
+
puts "Need #{tx.calculate_minimum_fee / 1e8} fee-wise"
|
140
|
+
puts "TX Size: #{tx.to_payload.bytesize}"
|
141
|
+
valid = tx.verify_input_signature(0, prev_tx) == true
|
142
|
+
multisig = Bitcoin::Script.new(tx.out.last.script).is_multisig?
|
143
|
+
puts "Does this transaction look valid: #{valid}"
|
144
|
+
puts "Is a valid multisig transaction: #{multisig}"
|
145
|
+
|
146
|
+
puts "Transaction looks like: "
|
147
|
+
pp tx.to_hash
|
148
|
+
transaction_hash = tx.to_payload.unpack("H*").first
|
149
|
+
puts "Raw hex encoded transaction for Bitcoind: "
|
150
|
+
puts "-------------------------------------------------"
|
151
|
+
puts transaction_hash
|
152
|
+
puts "-------------------------------------------------"
|
153
|
+
|
154
|
+
puts "Sending #{amount} Testnet Mastercoins to #{to_address}."
|
155
|
+
puts "Want me to send this transaction via Bitcoind? [no]"
|
156
|
+
STDOUT.flush
|
157
|
+
do_it = $stdin.gets
|
158
|
+
if do_it == "yes\n"
|
159
|
+
puts "Broadcasting transaction"
|
160
|
+
w.sendrawtransaction(transaction_hash)
|
161
|
+
else
|
162
|
+
puts "Not broadcasting transaction"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
Mastercoin::Cli::Wallet.start(ARGV)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# *-* encoding: utf-8 *-*
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'yaml'
|
6
|
+
module Mastercoin
|
7
|
+
class BitcoinWrapper
|
8
|
+
# also see: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
|
9
|
+
def initialize(service_url)
|
10
|
+
@uri = URI.parse(service_url)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unspend_for_address(address)
|
14
|
+
unspend = self.listunspent.find{|x| x["address"] == address}
|
15
|
+
if unspend.is_a?(Array)
|
16
|
+
return unspend
|
17
|
+
else
|
18
|
+
return [unspend]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(name, *args)
|
23
|
+
post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json
|
24
|
+
resp = JSON.parse( http_post_request(post_body) )
|
25
|
+
|
26
|
+
raise JSONRPCError, resp['error'] if resp['error']
|
27
|
+
|
28
|
+
resp['result']
|
29
|
+
end
|
30
|
+
|
31
|
+
def http_post_request(post_body)
|
32
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
33
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
34
|
+
|
35
|
+
request.basic_auth @uri.user, @uri.password
|
36
|
+
request.content_type = 'application/json'
|
37
|
+
request.body = post_body
|
38
|
+
|
39
|
+
http.request(request).body
|
40
|
+
end
|
41
|
+
|
42
|
+
class JSONRPCError < RuntimeError; end
|
43
|
+
end
|
44
|
+
end
|