nanook 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +26 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +18 -7
  6. data/Rakefile +18 -0
  7. data/docs/0.7.0/apple-touch-icon.png +0 -0
  8. data/docs/0.7.0/classes/Nanook.html +572 -0
  9. data/docs/0.7.0/classes/Nanook/Account.html +909 -0
  10. data/docs/0.7.0/classes/Nanook/Block.html +717 -0
  11. data/docs/0.7.0/classes/Nanook/Error.html +84 -0
  12. data/docs/0.7.0/classes/Nanook/Key.html +253 -0
  13. data/docs/0.7.0/classes/Nanook/Node.html +657 -0
  14. data/docs/0.7.0/classes/Nanook/Rpc.html +247 -0
  15. data/docs/0.7.0/classes/Nanook/Util.html +197 -0
  16. data/docs/0.7.0/classes/Nanook/Wallet.html +986 -0
  17. data/docs/0.7.0/classes/Nanook/WalletAccount.html +446 -0
  18. data/docs/0.7.0/classes/Nanook/WorkPeer.html +294 -0
  19. data/docs/0.7.0/created.rid +14 -0
  20. data/docs/0.7.0/css/github.css +123 -0
  21. data/docs/0.7.0/css/main.css +374 -0
  22. data/docs/0.7.0/css/panel.css +360 -0
  23. data/docs/0.7.0/css/reset.css +48 -0
  24. data/docs/0.7.0/favicon.ico +0 -0
  25. data/docs/0.7.0/files/README_md.html +418 -0
  26. data/docs/0.7.0/files/lib/nanook/account_rb.html +89 -0
  27. data/docs/0.7.0/files/lib/nanook/block_rb.html +89 -0
  28. data/docs/0.7.0/files/lib/nanook/error_rb.html +89 -0
  29. data/docs/0.7.0/files/lib/nanook/key_rb.html +89 -0
  30. data/docs/0.7.0/files/lib/nanook/node_rb.html +89 -0
  31. data/docs/0.7.0/files/lib/nanook/rpc_rb.html +99 -0
  32. data/docs/0.7.0/files/lib/nanook/util_rb.html +89 -0
  33. data/docs/0.7.0/files/lib/nanook/version_rb.html +84 -0
  34. data/docs/0.7.0/files/lib/nanook/wallet_account_rb.html +89 -0
  35. data/docs/0.7.0/files/lib/nanook/wallet_rb.html +89 -0
  36. data/docs/0.7.0/files/lib/nanook/work_peer_rb.html +89 -0
  37. data/docs/0.7.0/files/lib/nanook_rb.html +94 -0
  38. data/docs/0.7.0/i/arrow-down.svg +8 -0
  39. data/docs/0.7.0/i/arrow-right.svg +8 -0
  40. data/docs/0.7.0/i/search.svg +12 -0
  41. data/docs/0.7.0/i/tree_bg.svg +8 -0
  42. data/docs/0.7.0/index.html +11 -0
  43. data/docs/0.7.0/js/highlight.pack.js +1 -0
  44. data/docs/0.7.0/js/jquery-1.3.2.min.js +19 -0
  45. data/docs/0.7.0/js/main.js +25 -0
  46. data/docs/0.7.0/js/navigation.js +142 -0
  47. data/docs/0.7.0/js/search_index.js +1 -0
  48. data/docs/0.7.0/js/searchdoc.js +465 -0
  49. data/docs/0.7.0/js/searcher.js +229 -0
  50. data/docs/0.7.0/panel/index.html +47 -0
  51. data/docs/0.7.0/panel/links.html +32 -0
  52. data/docs/0.7.0/panel/tree.js +1 -0
  53. data/docs/0.8.0/apple-touch-icon.png +0 -0
  54. data/docs/0.8.0/classes/Nanook.html +621 -0
  55. data/docs/0.8.0/classes/Nanook/Account.html +971 -0
  56. data/docs/0.8.0/classes/Nanook/Block.html +759 -0
  57. data/docs/0.8.0/classes/Nanook/Error.html +84 -0
  58. data/docs/0.8.0/classes/Nanook/Key.html +295 -0
  59. data/docs/0.8.0/classes/Nanook/Node.html +657 -0
  60. data/docs/0.8.0/classes/Nanook/Rpc.html +247 -0
  61. data/docs/0.8.0/classes/Nanook/Util.html +264 -0
  62. data/docs/0.8.0/classes/Nanook/Wallet.html +1056 -0
  63. data/docs/0.8.0/classes/Nanook/WalletAccount.html +582 -0
  64. data/docs/0.8.0/classes/Nanook/WorkPeer.html +294 -0
  65. data/docs/0.8.0/created.rid +14 -0
  66. data/docs/0.8.0/css/github.css +123 -0
  67. data/docs/0.8.0/css/main.css +374 -0
  68. data/docs/0.8.0/css/panel.css +360 -0
  69. data/docs/0.8.0/css/reset.css +48 -0
  70. data/docs/0.8.0/favicon.ico +0 -0
  71. data/docs/0.8.0/files/README_md.html +423 -0
  72. data/docs/0.8.0/files/lib/nanook/account_rb.html +89 -0
  73. data/docs/0.8.0/files/lib/nanook/block_rb.html +89 -0
  74. data/docs/0.8.0/files/lib/nanook/error_rb.html +89 -0
  75. data/docs/0.8.0/files/lib/nanook/key_rb.html +89 -0
  76. data/docs/0.8.0/files/lib/nanook/node_rb.html +89 -0
  77. data/docs/0.8.0/files/lib/nanook/rpc_rb.html +99 -0
  78. data/docs/0.8.0/files/lib/nanook/util_rb.html +97 -0
  79. data/docs/0.8.0/files/lib/nanook/version_rb.html +84 -0
  80. data/docs/0.8.0/files/lib/nanook/wallet_account_rb.html +89 -0
  81. data/docs/0.8.0/files/lib/nanook/wallet_rb.html +89 -0
  82. data/docs/0.8.0/files/lib/nanook/work_peer_rb.html +89 -0
  83. data/docs/0.8.0/files/lib/nanook_rb.html +94 -0
  84. data/docs/0.8.0/i/arrow-down.svg +8 -0
  85. data/docs/0.8.0/i/arrow-right.svg +8 -0
  86. data/docs/0.8.0/i/search.svg +12 -0
  87. data/docs/0.8.0/i/tree_bg.svg +8 -0
  88. data/docs/0.8.0/index.html +11 -0
  89. data/docs/0.8.0/js/highlight.pack.js +1 -0
  90. data/docs/0.8.0/js/jquery-1.3.2.min.js +19 -0
  91. data/docs/0.8.0/js/main.js +25 -0
  92. data/docs/0.8.0/js/navigation.js +142 -0
  93. data/docs/0.8.0/js/search_index.js +1 -0
  94. data/docs/0.8.0/js/searchdoc.js +465 -0
  95. data/docs/0.8.0/js/searcher.js +229 -0
  96. data/docs/0.8.0/panel/index.html +47 -0
  97. data/docs/0.8.0/panel/links.html +32 -0
  98. data/docs/0.8.0/panel/tree.js +1 -0
  99. data/docs/1.0.0/apple-touch-icon.png +0 -0
  100. data/docs/1.0.0/classes/Nanook.html +621 -0
  101. data/docs/1.0.0/classes/Nanook/Account.html +971 -0
  102. data/docs/1.0.0/classes/Nanook/Block.html +759 -0
  103. data/docs/1.0.0/classes/Nanook/Error.html +84 -0
  104. data/docs/1.0.0/classes/Nanook/Key.html +295 -0
  105. data/docs/1.0.0/classes/Nanook/Node.html +657 -0
  106. data/docs/1.0.0/classes/Nanook/Rpc.html +247 -0
  107. data/docs/1.0.0/classes/Nanook/Util.html +264 -0
  108. data/docs/1.0.0/classes/Nanook/Wallet.html +1056 -0
  109. data/docs/1.0.0/classes/Nanook/WalletAccount.html +582 -0
  110. data/docs/1.0.0/classes/Nanook/WorkPeer.html +294 -0
  111. data/docs/1.0.0/created.rid +14 -0
  112. data/docs/1.0.0/css/github.css +123 -0
  113. data/docs/1.0.0/css/main.css +374 -0
  114. data/docs/1.0.0/css/panel.css +360 -0
  115. data/docs/1.0.0/css/reset.css +48 -0
  116. data/docs/1.0.0/favicon.ico +0 -0
  117. data/docs/1.0.0/files/README_md.html +423 -0
  118. data/docs/1.0.0/files/lib/nanook/account_rb.html +89 -0
  119. data/docs/1.0.0/files/lib/nanook/block_rb.html +89 -0
  120. data/docs/1.0.0/files/lib/nanook/error_rb.html +89 -0
  121. data/docs/1.0.0/files/lib/nanook/key_rb.html +89 -0
  122. data/docs/1.0.0/files/lib/nanook/node_rb.html +89 -0
  123. data/docs/1.0.0/files/lib/nanook/rpc_rb.html +99 -0
  124. data/docs/1.0.0/files/lib/nanook/util_rb.html +97 -0
  125. data/docs/1.0.0/files/lib/nanook/version_rb.html +84 -0
  126. data/docs/1.0.0/files/lib/nanook/wallet_account_rb.html +89 -0
  127. data/docs/1.0.0/files/lib/nanook/wallet_rb.html +89 -0
  128. data/docs/1.0.0/files/lib/nanook/work_peer_rb.html +89 -0
  129. data/docs/1.0.0/files/lib/nanook_rb.html +94 -0
  130. data/docs/1.0.0/i/arrow-down.svg +8 -0
  131. data/docs/1.0.0/i/arrow-right.svg +8 -0
  132. data/docs/1.0.0/i/search.svg +12 -0
  133. data/docs/1.0.0/i/tree_bg.svg +8 -0
  134. data/docs/1.0.0/index.html +11 -0
  135. data/docs/1.0.0/js/highlight.pack.js +1 -0
  136. data/docs/1.0.0/js/jquery-1.3.2.min.js +19 -0
  137. data/docs/1.0.0/js/main.js +25 -0
  138. data/docs/1.0.0/js/navigation.js +142 -0
  139. data/docs/1.0.0/js/search_index.js +1 -0
  140. data/docs/1.0.0/js/searchdoc.js +465 -0
  141. data/docs/1.0.0/js/searcher.js +229 -0
  142. data/docs/1.0.0/panel/index.html +47 -0
  143. data/docs/1.0.0/panel/links.html +32 -0
  144. data/docs/1.0.0/panel/tree.js +1 -0
  145. data/docs/apple-touch-icon.png +0 -0
  146. data/docs/classes/Nanook.html +572 -0
  147. data/docs/classes/Nanook/Account.html +907 -0
  148. data/docs/classes/Nanook/Block.html +717 -0
  149. data/docs/classes/Nanook/Error.html +84 -0
  150. data/docs/classes/Nanook/Key.html +253 -0
  151. data/docs/classes/Nanook/Node.html +657 -0
  152. data/docs/classes/Nanook/Rpc.html +247 -0
  153. data/docs/classes/Nanook/Util.html +197 -0
  154. data/docs/classes/Nanook/Wallet.html +778 -0
  155. data/docs/classes/Nanook/WalletAccount.html +447 -0
  156. data/docs/classes/Nanook/WorkPeer.html +294 -0
  157. data/docs/created.rid +14 -0
  158. data/docs/css/github.css +123 -0
  159. data/docs/css/main.css +374 -0
  160. data/docs/css/panel.css +360 -0
  161. data/docs/css/reset.css +48 -0
  162. data/docs/favicon.ico +0 -0
  163. data/docs/files/README_md.html +408 -0
  164. data/docs/files/lib/nanook/account_rb.html +89 -0
  165. data/docs/files/lib/nanook/block_rb.html +89 -0
  166. data/docs/files/lib/nanook/error_rb.html +89 -0
  167. data/docs/files/lib/nanook/key_rb.html +89 -0
  168. data/docs/files/lib/nanook/node_rb.html +89 -0
  169. data/docs/files/lib/nanook/rpc_rb.html +99 -0
  170. data/docs/files/lib/nanook/util_rb.html +89 -0
  171. data/docs/files/lib/nanook/version_rb.html +84 -0
  172. data/docs/files/lib/nanook/wallet_account_rb.html +89 -0
  173. data/docs/files/lib/nanook/wallet_rb.html +89 -0
  174. data/docs/files/lib/nanook/work_peer_rb.html +89 -0
  175. data/docs/files/lib/nanook_rb.html +94 -0
  176. data/docs/i/arrow-down.svg +8 -0
  177. data/docs/i/arrow-right.svg +8 -0
  178. data/docs/i/search.svg +12 -0
  179. data/docs/i/tree_bg.svg +8 -0
  180. data/docs/index.html +11 -0
  181. data/docs/js/highlight.pack.js +1 -0
  182. data/docs/js/jquery-1.3.2.min.js +19 -0
  183. data/docs/js/main.js +25 -0
  184. data/docs/js/navigation.js +142 -0
  185. data/docs/js/search_index.js +1 -0
  186. data/docs/js/searchdoc.js +465 -0
  187. data/docs/js/searcher.js +229 -0
  188. data/docs/panel/index.html +47 -0
  189. data/docs/panel/links.html +32 -0
  190. data/docs/panel/tree.js +1 -0
  191. data/lib/nanook.rb +40 -4
  192. data/lib/nanook/account.rb +250 -8
  193. data/lib/nanook/block.rb +25 -2
  194. data/lib/nanook/key.rb +10 -2
  195. data/lib/nanook/node.rb +4 -0
  196. data/lib/nanook/rpc.rb +5 -1
  197. data/lib/nanook/util.rb +9 -1
  198. data/lib/nanook/version.rb +1 -1
  199. data/lib/nanook/wallet.rb +275 -14
  200. data/lib/nanook/wallet_account.rb +63 -11
  201. data/lib/nanook/work_peer.rb +4 -0
  202. metadata +188 -3
@@ -0,0 +1,229 @@
1
+ Searcher = function(data) {
2
+ this.data = data;
3
+ this.handlers = [];
4
+ }
5
+
6
+ Searcher.prototype = new function() {
7
+ // search is performed in chunks of 1000 for non-blocking user input
8
+ var CHUNK_SIZE = 1000;
9
+ // do not try to find more than 100 results
10
+ var MAX_RESULTS = 100;
11
+ var huid = 1;
12
+ var suid = 1;
13
+ var runs = 0;
14
+
15
+ this.find = function(query) {
16
+ var queries = splitQuery(query);
17
+ var regexps = buildRegexps(queries);
18
+ var highlighters = buildHilighters(queries);
19
+ var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
20
+ var _this = this;
21
+
22
+ this.currentSuid = state.n;
23
+
24
+ if (!query) return;
25
+
26
+ var run = function() {
27
+ // stop current search thread if new search started
28
+ if (state.n != _this.currentSuid) return;
29
+
30
+ var results =
31
+ performSearch(_this.data, regexps, queries, highlighters, state);
32
+ var hasMore = (state.limit > 0 && state.pass < 4);
33
+
34
+ triggerResults.call(_this, results, !hasMore);
35
+ if (hasMore) {
36
+ setTimeout(run, 2);
37
+ }
38
+ runs++;
39
+ };
40
+ runs = 0;
41
+
42
+ // start search thread
43
+ run();
44
+ }
45
+
46
+ /* ----- Events ------ */
47
+ this.ready = function(fn) {
48
+ fn.huid = huid;
49
+ this.handlers.push(fn);
50
+ }
51
+
52
+ /* ----- Utilities ------ */
53
+ function splitQuery(query) {
54
+ return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
55
+ return string.match(/\S/);
56
+ });
57
+ }
58
+
59
+ function buildRegexps(queries) {
60
+ return jQuery.map(queries, function(query) {
61
+ return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
62
+ });
63
+ }
64
+
65
+ function buildHilighters(queries) {
66
+ return jQuery.map(queries, function(query) {
67
+ return jQuery.map(query.split(''), function(l, i) {
68
+ return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
69
+ }).join('');
70
+ });
71
+ }
72
+
73
+ // function longMatchRegexp(index, longIndex, regexps) {
74
+ // for (var i = regexps.length - 1; i >= 0; i--){
75
+ // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
76
+ // };
77
+ // return true;
78
+ // }
79
+
80
+
81
+ /* ----- Mathchers ------ */
82
+
83
+ /*
84
+ * This record matches if the index starts with queries[0] and the record
85
+ * matches all of the regexps
86
+ */
87
+ function matchPassBeginning(index, longIndex, queries, regexps) {
88
+ if (index.indexOf(queries[0]) != 0) return false;
89
+ for (var i=1, l = regexps.length; i < l; i++) {
90
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
91
+ return false;
92
+ };
93
+ return true;
94
+ }
95
+
96
+ /*
97
+ * This record matches if the longIndex starts with queries[0] and the
98
+ * longIndex matches all of the regexps
99
+ */
100
+ function matchPassLongIndex(index, longIndex, queries, regexps) {
101
+ if (longIndex.indexOf(queries[0]) != 0) return false;
102
+ for (var i=1, l = regexps.length; i < l; i++) {
103
+ if (!longIndex.match(regexps[i]))
104
+ return false;
105
+ };
106
+ return true;
107
+ }
108
+
109
+ /*
110
+ * This record matches if the index contains queries[0] and the record
111
+ * matches all of the regexps
112
+ */
113
+ function matchPassContains(index, longIndex, queries, regexps) {
114
+ if (index.indexOf(queries[0]) == -1) return false;
115
+ for (var i=1, l = regexps.length; i < l; i++) {
116
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
117
+ return false;
118
+ };
119
+ return true;
120
+ }
121
+
122
+ /*
123
+ * This record matches if regexps[0] matches the index and the record
124
+ * matches all of the regexps
125
+ */
126
+ function matchPassRegexp(index, longIndex, queries, regexps) {
127
+ if (!index.match(regexps[0])) return false;
128
+ for (var i=1, l = regexps.length; i < l; i++) {
129
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
130
+ return false;
131
+ };
132
+ return true;
133
+ }
134
+
135
+
136
+ /* ----- Highlighters ------ */
137
+ function highlightRegexp(info, queries, regexps, highlighters) {
138
+ var result = createResult(info);
139
+ for (var i=0, l = regexps.length; i < l; i++) {
140
+ result.title = result.title.replace(regexps[i], highlighters[i]);
141
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
142
+ };
143
+ return result;
144
+ }
145
+
146
+ function hltSubstring(string, pos, length) {
147
+ return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
148
+ }
149
+
150
+ function highlightQuery(info, queries, regexps, highlighters) {
151
+ var result = createResult(info);
152
+ var pos = 0;
153
+ var lcTitle = result.title.toLowerCase();
154
+
155
+ pos = lcTitle.indexOf(queries[0]);
156
+ if (pos != -1) {
157
+ result.title = hltSubstring(result.title, pos, queries[0].length);
158
+ }
159
+
160
+ result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
161
+ for (var i=1, l = regexps.length; i < l; i++) {
162
+ result.title = result.title.replace(regexps[i], highlighters[i]);
163
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
164
+ };
165
+ return result;
166
+ }
167
+
168
+ function createResult(info) {
169
+ var result = {};
170
+ result.title = info[0];
171
+ result.namespace = info[1];
172
+ result.path = info[2];
173
+ result.params = info[3];
174
+ result.snippet = info[4];
175
+ result.badge = info[6];
176
+ return result;
177
+ }
178
+
179
+ /* ----- Searching ------ */
180
+ function performSearch(data, regexps, queries, highlighters, state) {
181
+ var searchIndex = data.searchIndex;
182
+ var longSearchIndex = data.longSearchIndex;
183
+ var info = data.info;
184
+ var result = [];
185
+ var i = state.from;
186
+ var l = searchIndex.length;
187
+ var togo = CHUNK_SIZE;
188
+ var matchFunc, hltFunc;
189
+
190
+ while (state.pass < 4 && state.limit > 0 && togo > 0) {
191
+ if (state.pass == 0) {
192
+ matchFunc = matchPassBeginning;
193
+ hltFunc = highlightQuery;
194
+ } else if (state.pass == 1) {
195
+ matchFunc = matchPassLongIndex;
196
+ hltFunc = highlightQuery;
197
+ } else if (state.pass == 2) {
198
+ matchFunc = matchPassContains;
199
+ hltFunc = highlightQuery;
200
+ } else if (state.pass == 3) {
201
+ matchFunc = matchPassRegexp;
202
+ hltFunc = highlightRegexp;
203
+ }
204
+
205
+ for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
206
+ if (info[i].n == state.n) continue;
207
+ if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
208
+ info[i].n = state.n;
209
+ result.push(hltFunc(info[i], queries, regexps, highlighters));
210
+ state.limit--;
211
+ }
212
+ };
213
+ if (searchIndex.length <= i) {
214
+ state.pass++;
215
+ i = state.from = 0;
216
+ } else {
217
+ state.from = i;
218
+ }
219
+ }
220
+ return result;
221
+ }
222
+
223
+ function triggerResults(results, isLast) {
224
+ jQuery.each(this.handlers, function(i, fn) {
225
+ fn.call(this, results, isLast)
226
+ })
227
+ }
228
+ }
229
+
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>search index</title>
5
+ <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
6
+ <link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
7
+ <script src="../js/search_index.js" type="text/javascript" charset="utf-8"></script>
8
+ <script src="../js/searcher.js" type="text/javascript" charset="utf-8"></script>
9
+ <script src="tree.js" type="text/javascript" charset="utf-8"></script>
10
+ <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
11
+ <script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
12
+ <script type="text/javascript" charset="utf-8">
13
+ $(function() {
14
+ $('#links').hide();
15
+ var panel = new Searchdoc.Panel($('#panel'), search_data, tree, top.frames[1]);
16
+ $('#search').focus();
17
+
18
+ var s = window.parent.location.search.match(/\?q=([^&]+)/);
19
+ if (s) {
20
+ s = decodeURIComponent(s[1]).replace(/\+/g, ' ');
21
+ if (s.length > 0) {
22
+ $('#search').val(s);
23
+ panel.search(s, true);
24
+ }
25
+ }
26
+ })
27
+ </script>
28
+ </head>
29
+
30
+ <body>
31
+ <div class="panel panel_tree" id="panel">
32
+ <div class="header">
33
+ <input type="text" placeholder="Search for a class, method, ..." autosave="searchdoc" results="10" id="search" autocomplete="off" />
34
+ </div>
35
+ <div class="tree">
36
+ <ul>
37
+ </ul>
38
+ </div>
39
+ <div class="result">
40
+ <ul>
41
+ </ul>
42
+ </div>
43
+ </div>
44
+ <a href="links.html" id="links">index</a>
45
+ </body>
46
+
47
+ </html>
@@ -0,0 +1,32 @@
1
+ <html>
2
+ <head>File index</head>
3
+ <body>
4
+
5
+ <a href="../files/README_md.html">README.md</a>
6
+
7
+ <a href="../files/lib/nanook_rb.html">lib/nanook.rb</a>
8
+
9
+ <a href="../files/lib/nanook/account_rb.html">lib/nanook/account.rb</a>
10
+
11
+ <a href="../files/lib/nanook/block_rb.html">lib/nanook/block.rb</a>
12
+
13
+ <a href="../files/lib/nanook/error_rb.html">lib/nanook/error.rb</a>
14
+
15
+ <a href="../files/lib/nanook/key_rb.html">lib/nanook/key.rb</a>
16
+
17
+ <a href="../files/lib/nanook/node_rb.html">lib/nanook/node.rb</a>
18
+
19
+ <a href="../files/lib/nanook/rpc_rb.html">lib/nanook/rpc.rb</a>
20
+
21
+ <a href="../files/lib/nanook/util_rb.html">lib/nanook/util.rb</a>
22
+
23
+ <a href="../files/lib/nanook/version_rb.html">lib/nanook/version.rb</a>
24
+
25
+ <a href="../files/lib/nanook/wallet_rb.html">lib/nanook/wallet.rb</a>
26
+
27
+ <a href="../files/lib/nanook/wallet_account_rb.html">lib/nanook/wallet_account.rb</a>
28
+
29
+ <a href="../files/lib/nanook/work_peer_rb.html">lib/nanook/work_peer.rb</a>
30
+
31
+ </body>
32
+ </html>
@@ -0,0 +1 @@
1
+ var tree = [["","","files",[["README.md","files/README_md.html","",[]],["","","lib",[["","","nanook",[["account.rb","files/lib/nanook/account_rb.html","",[]],["block.rb","files/lib/nanook/block_rb.html","",[]],["error.rb","files/lib/nanook/error_rb.html","",[]],["key.rb","files/lib/nanook/key_rb.html","",[]],["node.rb","files/lib/nanook/node_rb.html","",[]],["rpc.rb","files/lib/nanook/rpc_rb.html","",[]],["util.rb","files/lib/nanook/util_rb.html","",[]],["version.rb","files/lib/nanook/version_rb.html","",[]],["wallet.rb","files/lib/nanook/wallet_rb.html","",[]],["wallet_account.rb","files/lib/nanook/wallet_account_rb.html","",[]],["work_peer.rb","files/lib/nanook/work_peer_rb.html","",[]]]],["nanook.rb","files/lib/nanook_rb.html","",[]]]]]],["Nanook","classes/Nanook.html"," < Object",[["Account","classes/Nanook/Account.html"," < Object",[]],["Block","classes/Nanook/Block.html"," < Object",[]],["Error","classes/Nanook/Error.html"," < StandardError",[]],["Key","classes/Nanook/Key.html"," < Object",[]],["Node","classes/Nanook/Node.html"," < Object",[]],["Rpc","classes/Nanook/Rpc.html"," < Object",[]],["Util","classes/Nanook/Util.html"," < Object",[]],["Wallet","classes/Nanook/Wallet.html"," < Object",[]],["WalletAccount","classes/Nanook/WalletAccount.html"," < Object",[]],["WorkPeer","classes/Nanook/WorkPeer.html"," < Object",[]]]]]
@@ -3,22 +3,58 @@ require 'uri'
3
3
 
4
4
  Dir[File.dirname(__FILE__) + '/nanook/*.rb'].each {|file| require file }
5
5
 
6
+ # ==== Initializing
7
+ #
8
+ # Connect to the default RPC host at http://localhost:7076 and with a timeout of 500 seconds:
9
+ #
10
+ # nanook = Nanook.new
11
+ #
12
+ # To connect to another host instead:
13
+ #
14
+ # nanook = Nanook.new("http://ip6-localhost.com:7076")
15
+ #
16
+ # To give a specific timeout value:
17
+ #
18
+ # Nanook.new(timeout: 600)
19
+ # Nanook.new("http://ip6-localhost.com:7076", timeout: 600)
6
20
  class Nanook
7
21
 
22
+ # ==== Arguments
23
+ #
24
+ # * +uri+ - RPC host to connect to (default is "http://localhost:7076")
25
+ # * +timeout:+ - Connection timeout in number of seconds (default is 500)
26
+ #
27
+ # ==== Examples
28
+ #
29
+ # Nanook.new # Connect to http://localhost:7076 with 500s timeout
30
+ #
31
+ # Nanook.new(timeout: 600)
32
+ # Nanook.new("http://ip6-localhost.com:7076", timeout: 600)
8
33
  def initialize(uri=Nanook::Rpc::DEFAULT_URI, timeout:Nanook::Rpc::DEFAULT_TIMEOUT)
9
34
  @rpc = Nanook::Rpc.new(uri, timeout: timeout)
10
35
  end
11
36
 
37
+ ##
38
+ # Returns a Nanook::Account instance.
39
+ #
40
+ # nanook = Nanook.new
41
+ #
42
+ # account = nanook.account
43
+ # account = nanook.account("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000")
12
44
  def account(account=nil)
13
- Nanook::Account.new(account, @rpc)
45
+ Nanook::Account.new(@rpc, account)
14
46
  end
15
47
 
16
48
  def block(block=nil)
17
- Nanook::Block.new(block, @rpc)
49
+ Nanook::Block.new(@rpc, block)
50
+ end
51
+
52
+ def inspect # :nodoc
53
+ "#{self.class.name}(rpc: #{@rpc.inspect}, object_id: \"#{"0x00%x" % (object_id << 1)}\")"
18
54
  end
19
55
 
20
56
  def key(key=nil)
21
- Nanook::Key.new(key, @rpc)
57
+ Nanook::Key.new(@rpc, key)
22
58
  end
23
59
 
24
60
  def node
@@ -26,7 +62,7 @@ class Nanook
26
62
  end
27
63
 
28
64
  def wallet(wallet=nil)
29
- Nanook::Wallet.new(wallet, @rpc)
65
+ Nanook::Wallet.new(@rpc, wallet)
30
66
  end
31
67
 
32
68
  def work_peers
@@ -1,54 +1,290 @@
1
1
  class Nanook
2
+
3
+ # The <tt>Nanook::Account</tt> class contains methods to discover
4
+ # publicly-available information about accounts on the nano network.
5
+ #
6
+ # === Initializing
7
+ #
8
+ # Initialize this class through the convenient Nanook#account method:
9
+ #
10
+ # nanook = Nanook.new
11
+ # account = nanook.account("xrb_...")
12
+ #
13
+ # Or compose the longhand way like this:
14
+ #
15
+ # rpc_conn = Nanook::Rpc.new
16
+ # account = Nanook::Account.new(rpc_conn, "xrb_...")
2
17
  class Account
3
18
 
4
- def initialize(account, rpc)
5
- @account = account
19
+ def initialize(rpc, account)
6
20
  @rpc = rpc
21
+ @account = account
7
22
  end
8
23
 
24
+ # ==== Example response
25
+ # {
26
+ # "xrb_13bqhi1cdqq8yb9szneoc38qk899d58i5rcrgdk5mkdm86hekpoez3zxw5sd": "500000000000000000000000000000000000",
27
+ # "xrb_17k6ug685154an8gri9whhe5kb5z1mf5w6y39gokc1657sh95fegm8ht1zpn": "961647970820730000000000000000000000"
28
+ # }
9
29
  def delegators
10
30
  account_required!
11
31
  rpc(:delegators)[:delegators]
12
32
  end
13
33
 
34
+ # Returns a boolean indicating if account is known. Note, the
35
+ # reliability of the check depends on the node host having
36
+ # synchronized itself with most of the blocks on the nano network,
37
+ # otherwise you may get a false +false+. You can check if a node's
38
+ # synchronization is particular low using Nanook::Node#sync_progress.
39
+ #
40
+ # ==== Example response
41
+ # true
14
42
  def exists?
15
43
  account_required!
16
44
  response = rpc(:validate_account_number)
17
45
  !response.empty? && response[:valid] == 1
18
46
  end
19
47
 
48
+ # Returns an account's history of send and receive payments.
49
+ # Amounts are in {raw}[https://nano.org/en/faq#what-are-nano-units-].
50
+ #
51
+ # ==== Arguments
52
+ #
53
+ # [+limit:+] Integer representing the maximum number of history
54
+ # items to return (default is 1000)
55
+ #
56
+ # ==== Example
57
+ #
58
+ # account.history
59
+ # account.history(limit: 1)
60
+ #
61
+ # ==== Example response
62
+ # [
63
+ # {
64
+ # :type=>"send",
65
+ # :account=>"xrb_1kdc5u48j3hr5r7eof9iao47szqh81ndqgq5e5hrsn1g9a3sa4hkkcotn3uq",
66
+ # :amount=>200000000000000000000000000000,
67
+ # :hash=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570"
68
+ # },
69
+ # {
70
+ # :type=>"receive",
71
+ # :account=>"xrb_1niabkx3gbxit5j5yyqcpas71dkffggbr6zpd3heui8rpoocm5xqbdwq44oh",
72
+ # :amount=>7836413000000000000000000000000,
73
+ # :hash=>"16743E8FF52F454E876E68EDD11F23094DCB96795A3B7F32F74F88563ACDDB04"
74
+ # }
75
+ # ]
20
76
  def history(limit: 1000)
21
77
  account_required!
22
78
  rpc(:account_history, count: limit)[:history]
23
79
  end
24
80
 
81
+ # Returns the public key belonging to an account.
82
+ #
83
+ # ==== Example response
84
+ # "3068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039"
25
85
  def public_key
26
86
  account_required!
27
87
  rpc(:account_key)[:key]
28
88
  end
29
89
 
90
+ # Returns a String of the representative account for the account.
91
+ # Representatives are accounts which cast votes in the case of a
92
+ # fork in the network.
93
+ #
94
+ # ==== Example response
95
+ #
96
+ # "xrb_3pczxuorp48td8645bs3m6c3xotxd3idskrenmi65rbrga5zmkemzhwkaznh"
30
97
  def representative
31
98
  account_required!
32
99
  rpc(:account_representative)[:representative]
33
100
  end
34
101
 
35
- def balance
102
+ # Returns a Hash containing the account's balance. Units are in
103
+ # {raw}[https://nano.org/en/faq#what-are-nano-units-].
104
+ #
105
+ # [+:balance+] Account balance
106
+ # [+:pending+] Amount pending and not yet received by the account
107
+ #
108
+ # ==== Arguments
109
+ #
110
+ # [+unit:+] Symbol (default is +:nano+) Represents the unit that
111
+ # the balances will be returned in.
112
+ # Must be either +:nano+ or +:raw+. (Note: this method
113
+ # interprets +:nano+ as NANO, which is technically Mnano
114
+ # See {What are Nano's Units}[https://nano.org/en/faq#what-are-nano-units-])
115
+ #
116
+ # ===== Example response
117
+ # {
118
+ # "balance": "2",
119
+ # "pending": "1"
120
+ # }
121
+ def balance(unit: Nanook::WalletAccount::DEFAULT_UNIT)
36
122
  account_required!
37
- rpc(:account_balance)
123
+
124
+ unless Nanook::WalletAccount::UNITS.include?(unit)
125
+ raise ArgumentError.new("Unsupported unit: #{unit}")
126
+ end
127
+
128
+ rpc(:account_balance).tap do |r|
129
+ if unit == :nano
130
+ r[:balance] = Nanook::Util.raw_to_NANO(r[:balance])
131
+ r[:pending] = Nanook::Util.raw_to_NANO(r[:pending])
132
+ end
133
+ end
134
+ end
135
+
136
+ def id
137
+ @block
38
138
  end
39
139
 
40
- def info
140
+ # Returns a Hash containing the following information about an
141
+ # account:
142
+ #
143
+ # [+:frontier+] The latest block hash
144
+ # [+:open_block+] The first block in every account's blockchain. When this block was published the account was officially open
145
+ # [+:representative_block+] The block that named the representative for the account
146
+ # [+:balance+] Amount in {NANO}[https://nano.org/en/faq#what-are-nano-units-]
147
+ # [+:last_modified+] Unix timestamp
148
+ # [+:block_count+] Number of blocks in the account's blockchain
149
+ #
150
+ # When <tt>detailed: true</tt> is passed as an argument, this method
151
+ # makes four additional calls to the RPC to return more information
152
+ # about an account:
153
+ #
154
+ # [+:weight+] See #weight
155
+ # [+:pending+] See #balance
156
+ # [+:representative+] See #representative
157
+ # [+:public_key+] See #public_key
158
+ #
159
+ # ==== Arguments
160
+ #
161
+ # [+detailed:+] Boolean (default is false). When +true+, four
162
+ # additional calls are made to the RPC to return more
163
+ # information
164
+ #
165
+ # ==== Example 1
166
+ #
167
+ # account.info
168
+ #
169
+ # ==== Example 1 response
170
+ # {
171
+ # :balance=>11.439597000000001,
172
+ # :block_count=>4
173
+ # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
174
+ # :modified_timestamp=>1520500357,
175
+ # :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
176
+ # :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
177
+ # }
178
+ #
179
+ # ==== Example 2
180
+ #
181
+ # account.info(detailed: true)
182
+ #
183
+ # ==== Example 2 response
184
+ # {
185
+ # :balance=>11.439597000000001,
186
+ # :block_count=>4,
187
+ # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
188
+ # :modified_timestamp=>1520500357,
189
+ # :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
190
+ # :pending=>0,
191
+ # :public_key=>"A82C906460046D230D7D37C6663723DC3EFCECC4B3254EBF45294B66746F4FEF",
192
+ # :representative=>"xrb_3pczxuorp48td8645bs3m6c3xotxd3idskrenmi65rbrga5zmkemzhwkaznh",
193
+ # :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
194
+ # :weight=>0
195
+ # }
196
+ def info(detailed: false)
41
197
  account_required!
42
- rpc(:account_info)
198
+
199
+ response = rpc(:account_info)
200
+
201
+ # Return the response if we don't need any more info
202
+ return response unless detailed
203
+
204
+ # Otherwise make additional calls
205
+ response = response.merge({
206
+ weight: weight,
207
+ pending: balance[:pending],
208
+ representative: representative,
209
+ public_key: public_key
210
+ })
211
+
212
+ # Sort this new hash by keys
213
+ Hash[response.sort].to_symbolized_hash
214
+ end
215
+
216
+ def inspect # :nodoc:
217
+ "#{self.class.name}(id: \"#{id}\", object_id: \"#{"0x00%x" % (object_id << 1)}\")"
43
218
  end
44
219
 
220
+ # Returns information about the given account as well as other
221
+ # accounts up the ledger. The number of accounts returned is determined
222
+ # by the <tt>limit:</tt> argument.
223
+ #
224
+ # The information in each Hash is the same as what the
225
+ # #info(detailed: false) method returns.
226
+ #
227
+ # ==== Arguments
228
+ #
229
+ # [+limit:+] Number of accounts to return in the ledger (default is 1)
230
+ #
231
+ # ==== Example
232
+ #
233
+ # ledger(limit: 2)
234
+ #
235
+ # ==== Example response
236
+ # {
237
+ # :xrb_3c3ek3k8135f6e8qtfy8eruk9q3yzmpebes7btzncccdest8ymzhjmnr196j=>{
238
+ # :frontier=>"2C3C570EA8898443C0FD04A1C385A3E3A8C985AD792635FCDCEBB30ADF6A0570",
239
+ # :open_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
240
+ # :representative_block=>"C82376314C387080A753871A32AD70F4168080C317C5E67356F0A62EB5F34FF9",
241
+ # :balance=>11439597000000000000000000000000,
242
+ # :modified_timestamp=>1520500357,
243
+ # :block_count=>4
244
+ # },
245
+ # :xrb_3c3ettq59kijuuad5fnaq35itc9schtr4r7r6rjhmwjbairowzq3wi5ap7h8=>{ ... }
246
+ # }
45
247
  def ledger(limit: 1)
46
248
  account_required!
47
249
  rpc(:ledger, count: limit)[:accounts]
48
250
  end
49
251
 
50
- # Returns Array of block hashes
51
- # Or, with detailed: true, returns Hashes
252
+
253
+ # Returns information about pending block hashes that are waiting to
254
+ # be received by the account.
255
+ #
256
+ # The default response is an Array of block hashes.
257
+ # With the +detailed:+ argument, the method can return a more
258
+ # complex Hash containing the amount in
259
+ # {raw}[https://nano.org/en/faq#what-are-nano-units-] of the pending
260
+ # block and the source account that sent it.
261
+ #
262
+ # ==== Arguments
263
+ #
264
+ # [+limit:+] Number of pending blocks to return (default is 1000)
265
+ # [+detailed:+] Boolean to have this method return a more complex
266
+ # Hash of pending block information (default is +false+)
267
+ #
268
+ # ==== Example 1
269
+ #
270
+ # pending
271
+ #
272
+ # ==== Example 1 response
273
+ #
274
+ # ["000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"]
275
+ #
276
+ # ==== Example 2
277
+ #
278
+ # pending(detailed: true)
279
+ #
280
+ # ==== Example 2 response
281
+ #
282
+ # {
283
+ # "000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F"=>{
284
+ # "amount"=>"6000000000000000000000000000000",
285
+ # "source"=>"xrb_3dcfozsmekr1tr9skf1oa5wbgmxt81qepfdnt7zicq5x3hk65fg4fqj58mbr"
286
+ # }
287
+ # }
52
288
  def pending(limit: 1000, detailed: false)
53
289
  account_required!
54
290
 
@@ -59,6 +295,12 @@ class Nanook
59
295
  Nanook::Util.coerce_empty_string_to_type(response, (detailed ? Hash : Array))
60
296
  end
61
297
 
298
+ # Returns the account's weight. Weight is determined by the
299
+ # account's balance, and represents the voting weight that account
300
+ # has on the network if it is a representative.
301
+ #
302
+ # ==== Example response
303
+ # 1
62
304
  def weight
63
305
  account_required!
64
306
  rpc(:account_weight)[:weight]