ledger-lite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc54a08adc58f1f0a7c50cb0ce42439ed2dd5312
4
+ data.tar.gz: '05199c14456c983c82d94981f098075ea49d743b'
5
+ SHA512:
6
+ metadata.gz: e52f287dbe9e9aff4cfe896f728a19c060e730bc86db485e1ff555ac6df3239d1b032f48684adf91b8810f97e50f57cc3ae60055d0398d588ca9339a5faddfa8
7
+ data.tar.gz: a4fbb0a4344cdd8dfe161c5ec855e9e49943d4414c29b58da4cf829ffb09664b10a95b313faf45c697e9b05657c3c780f09434c99aaa4849c7a1064253759fc2
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2018-01-02
2
+
3
+ * Everything is new. First release
@@ -0,0 +1,116 @@
1
+ CC0 1.0 Universal
2
+
3
+ Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an "owner") of an original work of
8
+ authorship and/or a database (each, a "Work").
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific
12
+ works ("Commons") that the public can reliably and without fear of later
13
+ claims of infringement build upon, modify, incorporate in other works, reuse
14
+ and redistribute as freely as possible in any form whatsoever and for any
15
+ purposes, including without limitation commercial purposes. These owners may
16
+ contribute to the Commons to promote the ideal of a free culture and the
17
+ further production of creative, cultural and scientific works, or to gain
18
+ reputation or greater distribution for their Work in part through the use and
19
+ efforts of others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation
22
+ of additional consideration or compensation, the person associating CC0 with a
23
+ Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
+ and publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights ("Copyright and
31
+ Related Rights"). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+
34
+ i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
+ and translate a Work;
36
+
37
+ ii. moral rights retained by the original author(s) and/or performer(s);
38
+
39
+ iii. publicity and privacy rights pertaining to a person's image or likeness
40
+ depicted in a Work;
41
+
42
+ iv. rights protecting against unfair competition in regards to a Work,
43
+ subject to the limitations in paragraph 4(a), below;
44
+
45
+ v. rights protecting the extraction, dissemination, use and reuse of data in
46
+ a Work;
47
+
48
+ vi. database rights (such as those arising under Directive 96/9/EC of the
49
+ European Parliament and of the Council of 11 March 1996 on the legal
50
+ protection of databases, and under any national implementation thereof,
51
+ including any amended or successor version of such directive); and
52
+
53
+ vii. other similar, equivalent or corresponding rights throughout the world
54
+ based on applicable law or treaty, and any national implementations thereof.
55
+
56
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
+ unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
+ and Related Rights and associated claims and causes of action, whether now
60
+ known or unknown (including existing as well as future claims and causes of
61
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
+ duration provided by applicable law or treaty (including future time
63
+ extensions), (iii) in any current or future medium and for any number of
64
+ copies, and (iv) for any purpose whatsoever, including without limitation
65
+ commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
+ the Waiver for the benefit of each member of the public at large and to the
67
+ detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
+ shall not be subject to revocation, rescission, cancellation, termination, or
69
+ any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
+ by the public as contemplated by Affirmer's express Statement of Purpose.
71
+
72
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
73
+ judged legally invalid or ineffective under applicable law, then the Waiver
74
+ shall be preserved to the maximum extent permitted taking into account
75
+ Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
+ is so judged Affirmer hereby grants to each affected person a royalty-free,
77
+ non transferable, non sublicensable, non exclusive, irrevocable and
78
+ unconditional license to exercise Affirmer's Copyright and Related Rights in
79
+ the Work (i) in all territories worldwide, (ii) for the maximum duration
80
+ provided by applicable law or treaty (including future time extensions), (iii)
81
+ in any current or future medium and for any number of copies, and (iv) for any
82
+ purpose whatsoever, including without limitation commercial, advertising or
83
+ promotional purposes (the "License"). The License shall be deemed effective as
84
+ of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
+ License for any reason be judged legally invalid or ineffective under
86
+ applicable law, such partial invalidity or ineffectiveness shall not
87
+ invalidate the remainder of the License, and in such case Affirmer hereby
88
+ affirms that he or she will not (i) exercise any of his or her remaining
89
+ Copyright and Related Rights in the Work or (ii) assert any associated claims
90
+ and causes of action with respect to the Work, in either case contrary to
91
+ Affirmer's express Statement of Purpose.
92
+
93
+ 4. Limitations and Disclaimers.
94
+
95
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
+ surrendered, licensed or otherwise affected by this document.
97
+
98
+ b. Affirmer offers the Work as-is and makes no representations or warranties
99
+ of any kind concerning the Work, express, implied, statutory or otherwise,
100
+ including without limitation warranties of title, merchantability, fitness
101
+ for a particular purpose, non infringement, or the absence of latent or
102
+ other defects, accuracy, or the present or absence of errors, whether or not
103
+ discoverable, all to the greatest extent permissible under applicable law.
104
+
105
+ c. Affirmer disclaims responsibility for clearing rights of other persons
106
+ that may apply to the Work or any use thereof, including without limitation
107
+ any person's Copyright and Related Rights in the Work. Further, Affirmer
108
+ disclaims responsibility for obtaining any necessary consents, permissions
109
+ or other rights required for any use of the Work.
110
+
111
+ d. Affirmer understands and acknowledges that Creative Commons is not a
112
+ party to this document and has no duty or obligation with respect to this
113
+ CC0 or use of the Work.
114
+
115
+ For more information, please see
116
+ <http://creativecommons.org/publicdomain/zero/1.0/>
@@ -0,0 +1,9 @@
1
+ HISTORY.md
2
+ LICENSE.md
3
+ Manifest.txt
4
+ README.md
5
+ Rakefile
6
+ lib/ledger-lite.rb
7
+ lib/ledger-lite/version.rb
8
+ test/helper.rb
9
+ test/test_transfer.rb
@@ -0,0 +1,19 @@
1
+ # Ledger Lite (Ruby Edition)
2
+
3
+ ledger-lite library / gem - hyper ledger book for the distributed blockchain internet era; add your transactions one block at a time; transfer crypto(currencie)s and balance the accounts
4
+
5
+
6
+ * home :: [github.com/openblockchains/ledger.lite.rb](https://github.com/openblockchains/ledger.lite.rb)
7
+ * bugs :: [github.com/openblockchains/ledger.lite.rb/issues](https://github.com/openblockchains/ledger.lite.rb/issues)
8
+ * gem :: [rubygems.org/gems/ledger-lite](https://rubygems.org/gems/ledger-lite)
9
+ * rdoc :: [rubydoc.info/gems/ledger-lite](http://rubydoc.info/gems/ledger-lite)
10
+
11
+
12
+
13
+
14
+ ## License
15
+
16
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
17
+
18
+ The `ledger-lite` scripts are dedicated to the public domain.
19
+ Use it as you please with no restrictions whatsoever.
@@ -0,0 +1,29 @@
1
+ require 'hoe'
2
+ require './lib/ledger-lite/version.rb'
3
+
4
+ Hoe.spec 'ledger-lite' do
5
+
6
+ self.version = LedgerLite::VERSION
7
+
8
+ self.summary = "ledger-lite - hyper ledger book for the distributed blockchain internet era; add your transactions one block at a time; transfer crypto(currencie)s and balance the accounts"
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/openblockchains/ledger.lite.rb']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'HISTORY.md'
19
+
20
+ self.extra_deps = [
21
+ ]
22
+
23
+ self.licenses = ['Public Domain']
24
+
25
+ self.spec_extras = {
26
+ required_ruby_version: '>= 2.3'
27
+ }
28
+
29
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pp' # for pp => pretty printer
4
+
5
+ require 'date'
6
+ require 'time'
7
+ require 'json'
8
+
9
+
10
+
11
+ ## our own code
12
+ require 'ledger-lite/version' # note: let version always go first
13
+
14
+
15
+
16
+ module LedgerLite
17
+
18
+ class Ledger
19
+
20
+ attr_reader :addr ## make addr private e.g. remove - why? e.g. use hash forwards/delegates - why not?
21
+
22
+ def initialize( args=[] )
23
+ ## todo/fix: use *args - same interface as merkletree/blochchain-lite
24
+
25
+ @addr = {}
26
+
27
+ args.each do |arg|
28
+ if arg.respond_to?( :transactions ) ## bingo! assume it's block if it has transactions method
29
+ transfer( arg.transactions )
30
+ else
31
+ transfer( arg )
32
+ end
33
+ end
34
+ end # method initialize
35
+
36
+
37
+
38
+ ##
39
+ # find a better name - why? why not?
40
+ ## e.g. use can? funds? sufficient? has_funds?
41
+ def sufficient_funds?( addr, amount )
42
+ ## fix:
43
+ true
44
+ end
45
+
46
+
47
+ def transfer( arg )
48
+ ## todo/fix: use *args - same interface as merkletree/blochchain-lite
49
+
50
+ puts "transfer:"
51
+ pp arg
52
+
53
+ if arg.is_a?( Array )
54
+ txs = arg
55
+ txs.each { |tx| do_transfer( *unpack(tx) ) } ## unpack & unsplat array (to pass in args) => from, to, amount
56
+ else
57
+ ## assume single tx
58
+ tx = arg
59
+ do_transfer( *unpack(tx) ) ## unpack & unsplat array (to pass in args) => from, to, amount
60
+ end
61
+ end
62
+
63
+
64
+ def unpack( tx )
65
+ ## "unpack" from, to, amount values
66
+
67
+ puts "unpack:"
68
+ pp tx
69
+
70
+ if tx.is_a?( Hash ) ## support hashes
71
+ from = tx[:from]
72
+ to = tx[:to]
73
+ amount = tx[:amount]
74
+ else ## assume it's a transaction (tx) struct/class
75
+ from = tx.from
76
+ to = tx.to
77
+ amount = tx.amount
78
+ end
79
+ [from,to,amount]
80
+ end
81
+
82
+
83
+ ## apply/do single transaction
84
+ ## - find a different name - why? why not?
85
+ def do_transfer( from, to, amount )
86
+
87
+ if sufficient_funds?( from, amount )
88
+ @addr[ from ] ||= 0
89
+ @addr[ from ] -= amount
90
+ @addr[ to ] ||= 0
91
+ @addr[ to ] += amount
92
+ end
93
+
94
+ end # do_transfer
95
+
96
+
97
+ end # class Ledger
98
+
99
+ end # module LedgerLite
100
+
101
+
102
+ ###
103
+ # add convenience top-level shortcut / alias
104
+ Ledger = LedgerLite::Ledger
105
+
106
+ # say hello
107
+ puts LedgerLite.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module LedgerLite
5
+
6
+ MAJOR = 0
7
+ MINOR = 0
8
+ PATCH = 1
9
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
10
+
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ def self.banner
16
+ "ledger-lite/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
17
+ end
18
+
19
+ def self.root
20
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
21
+ end
22
+
23
+ end # module LedgerLite
@@ -0,0 +1,50 @@
1
+ ## $:.unshift(File.dirname(__FILE__))
2
+
3
+ ## minitest setup
4
+
5
+ require 'minitest/autorun'
6
+
7
+
8
+ ## our own code
9
+
10
+ require 'ledger-lite'
11
+
12
+
13
+
14
+ ## some helper classes for testing
15
+
16
+ class Transaction
17
+
18
+ attr_reader :from, :to, :amount
19
+
20
+ #####
21
+ # flexible for testing - allows:
22
+ # Tx.new( 'Alice', 'Bob', 12 )
23
+ # Tx.new( from: 'Alice', to: 'Bob', amount: 12 )
24
+
25
+ def initialize( *args, **kwargs )
26
+ if args.empty? # try keyword args
27
+ @from = kwargs[:from]
28
+ @to = kwargs[:to]
29
+ @amount = kwargs[:amount]
30
+ else # try positional args
31
+ @from = args[0]
32
+ @to = args[1]
33
+ @amount = args[2]
34
+ end
35
+ end
36
+
37
+ end # class Transaction
38
+
39
+ Tx = Transaction ## convenience shortcut
40
+
41
+
42
+ class Block
43
+ def initialize( *transactions )
44
+ @transactions = transactions
45
+ end
46
+
47
+ def transactions
48
+ @transactions
49
+ end
50
+ end # class Block
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_transfer.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestTransfer < MiniTest::Test
12
+
13
+
14
+ def test_do_transfer
15
+
16
+ ledger = Ledger.new
17
+
18
+ ledger.do_transfer( "Vicent", "Anne", 3 )
19
+ ledger.do_transfer( "Anne", "Julia", 2 )
20
+ ledger.do_transfer( "Julia", "Luuk", 1 )
21
+
22
+ ledger.do_transfer( "Vincent", "Max", 3 )
23
+ ledger.do_transfer( "Anne", "Martijn", 2 )
24
+ ledger.do_transfer( "Ruben", "Julia", 1 )
25
+
26
+ pp ledger
27
+
28
+ balances = {"Vicent"=>-3,
29
+ "Anne"=>-1,
30
+ "Julia"=>2,
31
+ "Luuk"=>1,
32
+ "Vincent"=>-3,
33
+ "Max"=>3,
34
+ "Martijn"=>2,
35
+ "Ruben"=>-1}
36
+ assert_equal balances, ledger.addr
37
+ end
38
+
39
+
40
+ def test_transfer_with_tx_v1
41
+
42
+ ledger = Ledger.new
43
+
44
+ ledger.transfer( Tx.new( "Vicent", "Anne", 3 ))
45
+ ledger.transfer( Tx.new( "Anne", "Julia", 2 ))
46
+ ledger.transfer( Tx.new( "Julia", "Luuk", 1 ))
47
+
48
+ ledger.transfer( Tx.new( "Vincent", "Max", 3 ))
49
+ ledger.transfer( Tx.new( "Anne", "Martijn", 2 ))
50
+ ledger.transfer( Tx.new( "Ruben", "Julia", 1 ))
51
+
52
+ pp ledger
53
+
54
+ balances = {"Vicent"=>-3,
55
+ "Anne"=>-1,
56
+ "Julia"=>2,
57
+ "Luuk"=>1,
58
+ "Vincent"=>-3,
59
+ "Max"=>3,
60
+ "Martijn"=>2,
61
+ "Ruben"=>-1}
62
+ assert_equal balances, ledger.addr
63
+ end
64
+
65
+
66
+ def test_transfer_with_tx_v2
67
+
68
+ ledger = Ledger.new
69
+
70
+ ledger.transfer( [Tx.new( "Vicent", "Anne", 3 ),
71
+ Tx.new( "Anne", "Julia", 2 ),
72
+ Tx.new( "Julia", "Luuk", 1 )])
73
+
74
+ ledger.transfer( [Tx.new( "Vincent", "Max", 3 ),
75
+ Tx.new( "Anne", "Martijn", 2 ),
76
+ Tx.new( "Ruben", "Julia", 1 )])
77
+
78
+ pp ledger
79
+
80
+ balances = {"Vicent"=>-3,
81
+ "Anne"=>-1,
82
+ "Julia"=>2,
83
+ "Luuk"=>1,
84
+ "Vincent"=>-3,
85
+ "Max"=>3,
86
+ "Martijn"=>2,
87
+ "Ruben"=>-1}
88
+ assert_equal balances, ledger.addr
89
+ end
90
+
91
+
92
+ def test_transfer_with_hash
93
+
94
+ ledger = Ledger.new
95
+
96
+ ledger.transfer( [{ from: "Vicent", to: "Anne", amount: 3 },
97
+ { from: "Anne", to: "Julia", amount: 2 },
98
+ { from: "Julia", to: "Luuk", amount: 1 }])
99
+
100
+ ledger.transfer( [{ from: "Vincent", to: "Max", amount: 3 },
101
+ { from: "Anne", to: "Martijn", amount: 2 },
102
+ { from: "Ruben", to: "Julia", amount: 1 }])
103
+
104
+ pp ledger
105
+
106
+ balances = {"Vicent"=>-3,
107
+ "Anne"=>-1,
108
+ "Julia"=>2,
109
+ "Luuk"=>1,
110
+ "Vincent"=>-3,
111
+ "Max"=>3,
112
+ "Martijn"=>2,
113
+ "Ruben"=>-1}
114
+ assert_equal balances, ledger.addr
115
+ end
116
+
117
+
118
+ end # class TestTransfer
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ledger-lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.16'
41
+ description: ledger-lite - hyper ledger book for the distributed blockchain internet
42
+ era; add your transactions one block at a time; transfer crypto(currencie)s and
43
+ balance the accounts
44
+ email: wwwmake@googlegroups.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - HISTORY.md
49
+ - LICENSE.md
50
+ - Manifest.txt
51
+ - README.md
52
+ files:
53
+ - HISTORY.md
54
+ - LICENSE.md
55
+ - Manifest.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/ledger-lite.rb
59
+ - lib/ledger-lite/version.rb
60
+ - test/helper.rb
61
+ - test/test_transfer.rb
62
+ homepage: https://github.com/openblockchains/ledger.lite.rb
63
+ licenses:
64
+ - Public Domain
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options:
68
+ - "--main"
69
+ - README.md
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '2.3'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.5.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: ledger-lite - hyper ledger book for the distributed blockchain internet
88
+ era; add your transactions one block at a time; transfer crypto(currencie)s and
89
+ balance the accounts
90
+ test_files: []