michelson 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +95 -1
- data/lib/michelson.rb +1 -1
- data/lib/michelson/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed3b5fbe9328e38ec213aa5d36c106711cdd5e1e
|
4
|
+
data.tar.gz: 0e5d7cd932220b76b7951a1db682c266cd3242c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d4c310be5fd21d7caa94fa87ab9f3b50c7a4c1a208c2f35682173d2894be1fca582e9c6eddab10ea81b5f6ffbf46c5e52c96696976b8b8cc7d86e7ef148601
|
7
|
+
data.tar.gz: a0e72f64c2dbd6a8e47cf9c9a009204c8e967411834c9119462113f88e3d335685b444f6371e9a72b9cb5faa080a7c05c98aabd1757c243158e71b2e1c1356d6
|
data/README.md
CHANGED
@@ -9,9 +9,103 @@ michelson gem / library - test simulator / runtime for type-safe 'n' functional
|
|
9
9
|
* rdoc :: [rubydoc.info/gems/michelson](http://rubydoc.info/gems/michelson)
|
10
10
|
|
11
11
|
|
12
|
+
|
12
13
|
## Usage
|
13
14
|
|
14
|
-
|
15
|
+
**What's Michelson? What's Liquidity?**
|
16
|
+
|
17
|
+
The Liquidity language lets you program contracts with (higher-level type-safe functional) OCaml or ReasonML syntax (see <http://www.liquidity-lang.org>)
|
18
|
+
compiling to (lower-level) Michelson stack machine bytecode (see <https://www.michelson-lang.com>).
|
19
|
+
|
20
|
+
Using the michelson test simulator / runtime for type-safe 'n' functional (crypto) contracts you can now use a "Yes, It's Just Ruby" syntax.
|
21
|
+
|
22
|
+
|
23
|
+
### By Example
|
24
|
+
|
25
|
+
**Let's Count - 0, 1, 2, 3**
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
type :Storage, Integer
|
29
|
+
|
30
|
+
init [],
|
31
|
+
def storage()
|
32
|
+
0
|
33
|
+
end
|
34
|
+
|
35
|
+
entry [Integer],
|
36
|
+
def inc( by, storage )
|
37
|
+
[[], storage + by]
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
And for (local) testing you can run the "Yes, It's Just Ruby" version with the michelson testnet "simulator" library. Try:
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
storage = storage()
|
45
|
+
# => calling storage()...
|
46
|
+
# => returning:
|
47
|
+
# => 0
|
48
|
+
_, storage = inc( 2, storage )
|
49
|
+
# => calling inc( 2, 0 )...
|
50
|
+
# => returning:
|
51
|
+
# => [[], 2]
|
52
|
+
_, storage = inc( 1, storage )
|
53
|
+
# => calling inc( 1, 2 )...
|
54
|
+
# => returning:
|
55
|
+
# => [[], 3]
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
**Let's Vote**
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
type :Storage, Map‹String→Integer›
|
63
|
+
|
64
|
+
init [],
|
65
|
+
def storage()
|
66
|
+
{"ocaml" => 0, "reason" => 0, "ruby" => 0}
|
67
|
+
end
|
68
|
+
|
69
|
+
entry [String],
|
70
|
+
def vote( choice, votes )
|
71
|
+
amount = Current.amount
|
72
|
+
if amount < 5.tz
|
73
|
+
failwith( "Not enough money, at least 5tz to vote" )
|
74
|
+
else
|
75
|
+
match Map.find(choice, votes), {
|
76
|
+
None: ->() { failwith( "Bad vote" ) },
|
77
|
+
Some: ->(x) { votes = Map.add(choice, x + 1, votes); [[], votes] }}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
And again for (local) testing you can run the "Yes, It's Just Ruby" version with the michelson testnet "simulator" library. Try:
|
83
|
+
|
84
|
+
``` ruby
|
85
|
+
storage = storage()
|
86
|
+
#=> calling storage()...
|
87
|
+
#=> returning:
|
88
|
+
#=> {"ocaml"=>0, "reason"=>0, "ruby"=>0}
|
89
|
+
_, storage = vote( "ruby", storage )
|
90
|
+
#=> calling vote( "ruby", {"ocaml"=>0, "reason"=>0, "ruby"=>0} )...
|
91
|
+
#=> !! RuntimeError: failwith - Not enough money, at least 5tz to vote
|
92
|
+
|
93
|
+
Current.amount = 10.tz
|
94
|
+
|
95
|
+
_, storage = vote( "ruby", storage )
|
96
|
+
#=> calling vote( "ruby", {"ocaml"=>0, "reason"=>0, "ruby"=>0} )...
|
97
|
+
#=> returning:
|
98
|
+
#=> [[], {"ocaml"=>0, "reason"=>0, "ruby"=>1}]
|
99
|
+
_, storage = vote( "reason", storage )
|
100
|
+
#=> calling vote( "reason", {"ocaml"=>0, "reason"=>0, "ruby"=>1} )...
|
101
|
+
#=> returning:
|
102
|
+
#=> [[], {"ocaml"=>0, "reason"=>1, "ruby"=>1}]
|
103
|
+
_, storage = vote( "python", storage )
|
104
|
+
#=> calling vote( "python", {"ocaml"=>0, "reason"=>1, "ruby"=>1} )...
|
105
|
+
#=> !! RuntimeError: failwith - Bad vote
|
106
|
+
```
|
107
|
+
|
108
|
+
And so on and so forth.
|
15
109
|
|
16
110
|
|
17
111
|
## License
|
data/lib/michelson.rb
CHANGED
data/lib/michelson/version.rb
CHANGED