├── .formatter.exs
├── .github
└── CONTRIBUTING.md
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── config
└── config.exs
├── lib
├── eosrpc.ex
└── eosrpc
│ ├── chain.ex
│ ├── error.ex
│ ├── helper.ex
│ ├── history.ex
│ ├── middleware
│ └── error.ex
│ └── wallet.ex
├── mix.exs
├── mix.lock
└── test
├── eosrpc
└── middleware
│ └── error_test.exs
├── eosrpc_test.exs
└── test_helper.exs
/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | inputs: [
3 | "lib/**/*.{ex,exs}",
4 | "test/**/*.{ex,exs}",
5 | "mix.exs"
6 | ]
7 | ]
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 | We welcome contributions from the community and are pleased to have them. Please follow this guide when logging issues or making code changes.
3 |
4 | ## Logging Issues
5 | Clearly describe the issue including steps to reproduce if there are any. Also, make sure to indicate the earliest version that has the issue being reported.
6 |
7 | ## Patching Code
8 | Code changes are welcome and should follow the guidelines below.
9 |
10 | * Fork the repository on GitHub.
11 | * Fix the issue ensuring that your code follows the credo guidelines by running `mix credo`
12 | * Add tests for your new code ensuring that you have 100% code coverage (we can help you reach 100% but will not merge without it).
13 | * [Pull requests](http://help.github.com/send-pull-requests/) should be made to the [master branch](https://github.com/bespiral/eosrpc-elixir-wrapper/tree/master).
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # The directory Mix will write compiled artifacts to.
2 | /_build/
3 |
4 | # If you run "mix test --cover", coverage assets end up here.
5 | /cover/
6 |
7 | # The directory Mix downloads your dependencies sources to.
8 | /deps/
9 |
10 | # Where 3rd-party dependencies like ExDoc output generated docs.
11 | /doc/
12 |
13 | # Ignore .fetch files in case you like to edit your project deps locally.
14 | /.fetch
15 |
16 | # If the VM crashes, it generates a dump, let's ignore it too.
17 | erl_crash.dump
18 |
19 | # Also ignore archive artifacts (built via "mix archive.build").
20 | *.ez
21 |
22 | .idea
23 | eosrpc.iml
24 |
25 | .elixir_ls
26 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: elixir
3 | elixir:
4 | - 1.6.4
5 | otp_release:
6 | - 20.0
7 | script:
8 | - mix test
9 | - mix credo --mute-exit-status
10 | after_script:
11 | # - MIX_ENV=test mix inch.report
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EOSRPC
2 |
3 | [](https://travis-ci.org/BeSpiral/eosrpc-elixir-wrapper)
4 | [](https://hex.pm/packages/eosrpc)
5 |
6 |
7 | Simple EOSRPC Wrapper for Elixir.
8 | Based on [EOS RPC Official Docs](https://developers.eos.io/eosio-nodeos/reference)
9 |
10 | ## Installation
11 |
12 | ```elixir
13 | def deps do
14 | [
15 | {:eosrpc, "~> 0.6.0"}
16 | ]
17 | end
18 | ```
19 |
20 | You need to setup the Chain, Wallet and Account History URLs. This is the default configuration:
21 |
22 |
23 | ```elixir
24 | config :eosrpc, EOSRPC.Wallet,
25 | url: "http://127.0.0.1:8999/v1/wallet"
26 |
27 | config :eosrpc, EOSRPC.Chain,
28 | url: "http://127.0.0.1:8888/v1/chain"
29 |
30 | config :eosrpc, EOSRPC.History,
31 | url: "http://127.0.0.1:8888/v1/history"
32 | ```
33 |
34 |
35 | ## Examples
36 |
37 | Autosigning and pushing a transaction.
38 |
39 | ```elixir
40 | actions = [
41 | %{
42 | account: "eosio.token",
43 | authorization: [%{actor: "eosio.token", permission: "active"}],
44 | data: %{issuer: "eosio", max_supply: "10000.00 LEO"},
45 | name: "create"
46 | }
47 | ]
48 |
49 | EOSRPC.Helper.auto_push(actions)
50 | ```
51 |
52 | Creating a new account `leo` under the owner `eosio`
53 |
54 | ```elixir
55 | EOSRPC.Helper.new_account("eosio", "leo", "EOS_OWNER_PUB_KEY", "EOS_ACTIVE_PUB_KEY")
56 | ```
57 |
58 | All of the EOSRPC APIs are in `EOSRPC.Wallet`, `EOSRPC.Chain` and `EOSRPC.History`
59 |
60 | For complete transactions signature and submission flow examples check `EOSRPC.Helper`
61 |
62 | ## License
63 |
64 | This project is licensed under the GNU GPLv3 License - see the [LICENSE](LICENSE) file for details
65 |
--------------------------------------------------------------------------------
/config/config.exs:
--------------------------------------------------------------------------------
1 | # This file is responsible for configuring your application
2 | # and its dependencies with the aid of the Mix.Config module.
3 | use Mix.Config
4 |
5 | # This configuration is loaded before any dependency and is restricted
6 | # to this project. If another project depends on this project, this
7 | # file won't be loaded nor affect the parent project. For this reason,
8 | # if you want to provide default values for your application for
9 | # 3rd-party users, it should be done in your "mix.exs" file.
10 |
11 | # You can configure your application as:
12 | #
13 | # config :eosrpc, key: :value
14 | #
15 | # and access this configuration in your application as:
16 | #
17 | # Application.get_env(:eosrpc, :key)
18 | #
19 | # You can also configure a 3rd-party app:
20 | #
21 | # config :logger, level: :info
22 | #
23 |
24 | # It is also possible to import configuration files, relative to this
25 | # directory. For example, you can emulate configuration per environment
26 | # by uncommenting the line below and defining dev.exs, test.exs and such.
27 | # Configuration from the imported file will override the ones defined
28 | # here (which is why it is important to import them last).
29 | #
30 | # import_config "#{Mix.env}.exs"
31 |
32 | config :eosrpc, EOSRPC.Wallet, url: "http://127.0.0.1:8888/v1/wallet"
33 | # config :eosrpc, EOSRPC.Wallet,
34 | # url: "http://127.0.0.1:8999/v1/wallet"
35 |
36 | config :eosrpc, EOSRPC.Chain, url: "https://eosio.bespiral.io/v1/chain"
37 | # config :eosrpc, EOSRPC.Chain, url: "http://127.0.0.1:8888/v1/chain"
38 |
39 | config :eosrpc, EOSRPC.History,
40 | url: "http://127.0.0.1:8888/v1/history"
41 |
42 | config :eosrpc, EOSRPC.Helper,
43 | symbol: "EOS"
44 |
--------------------------------------------------------------------------------
/lib/eosrpc.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC do
2 | @moduledoc """
3 | EOSRPC Wrapper for Elixir
4 |
5 | Based on: https://eosio.github.io/eos/group__eosiorpc.html
6 |
7 | See the functions on modules `EOSRPC.Wallet` and `EOSRPC.Chain`
8 |
9 | There's also a helper module that has functions to basic scenarios as
10 | easy transaction push and account creation: `EOSRPC.Helper`
11 | """
12 |
13 | @doc """
14 | Macro that "bangify" functions, and normalize the exception throws when returning status tuples: `{:ok, value}` and `{:error, reason}`
15 |
16 | ### Usage
17 | ```
18 | defmodule X do
19 | import EOSRPC
20 |
21 | def normal(param) do
22 | if param == 1 do
23 | {:ok, param + 1}
24 | else
25 | {:error, "not one"}
26 | end
27 | end
28 |
29 | def normal!() do
30 | unwrap_or_raise(normal())
31 | end
32 | end
33 | ```
34 | """
35 | defmacro unwrap_or_raise(call) do
36 | quote do
37 | case unquote(call) do
38 | {:ok, value} -> value
39 | {:error, env} -> raise EOSRPC.Error, reason: env.body, url: env.url
40 | end
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/eosrpc/chain.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Chain do
2 | @moduledoc """
3 | EOSRPC Wallet Wrapper for Elixir
4 |
5 | Based on: https://developers.eos.io/eosio-nodeos/v1.2.0/reference on Chain section
6 | """
7 |
8 | @callback get_account(account_name :: binary) :: any
9 |
10 | use Tesla
11 |
12 | import EOSRPC
13 |
14 | plug(EOSRPC.Middleware.Error)
15 | plug(Tesla.Middleware.JSON)
16 |
17 | @doc """
18 | Get latest information related to a node
19 | """
20 | def get_info, do: url("/get_info") |> get()
21 | def get_info!, do: unwrap_or_raise(get_info())
22 |
23 | @doc """
24 | Get information related to a block.
25 | """
26 | def get_block(block_num_or_id) do
27 | "/get_block" |> url() |> post(%{block_num_or_id: block_num_or_id})
28 | end
29 |
30 | def get_block!(block_num_or_id) do
31 | unwrap_or_raise(get_block(block_num_or_id))
32 | end
33 |
34 | @doc """
35 | Get information related to an account.
36 | """
37 | def get_account(account_name) do
38 | "/get_account" |> url() |> post(%{account_name: account_name})
39 | end
40 |
41 | def get_account!(account_name) do
42 | unwrap_or_raise(get_account(account_name))
43 | end
44 |
45 | @doc """
46 | Fetch smart contract code.
47 | """
48 | def get_code(account_name) do
49 | "/get_code" |> url() |> post(%{account_name: account_name})
50 | end
51 |
52 | def get_code!(account_name) do
53 | unwrap_or_raise(get_code(account_name))
54 | end
55 |
56 | @doc """
57 | Fetch smart contract data from an account.
58 | """
59 | def get_table_rows(contract, scope, table, json \\ true)
60 |
61 | def get_table_rows(contract, scope, table, json) do
62 | data = %{
63 | scope: scope,
64 | code: contract,
65 | table: table,
66 | json: json,
67 | limit: 1_000
68 | }
69 |
70 | "/get_table_rows" |> url() |> post(data)
71 | end
72 |
73 | def get_table_rows!(contract, scope, table, json \\ true)
74 |
75 | def get_table_rows!(contract, scope, table, json) do
76 | unwrap_or_raise(get_table_rows(contract, scope, table, json))
77 | end
78 |
79 | @doc """
80 | Get required keys to sign a transaction from list of your keys.
81 | """
82 | def get_required_keys(transaction_data, available_keys) do
83 | data = %{
84 | transaction: transaction_data,
85 | available_keys: available_keys
86 | }
87 |
88 | "/get_required_keys" |> url() |> post(data)
89 | end
90 |
91 | def get_required_keys!(transaction_data, available_keys) do
92 | unwrap_or_raise(get_required_keys(transaction_data, available_keys))
93 | end
94 |
95 | @doc """
96 | Serialize json to binary hex. The resulting binary hex is usually used
97 | for the data field in push_transaction.
98 | """
99 | def abi_json_to_bin(code, action, args) do
100 | "/abi_json_to_bin" |> url() |> post(%{code: code, action: action, args: args})
101 | end
102 |
103 | def abi_json_to_bin!(code, action, args) do
104 | unwrap_or_raise(abi_json_to_bin(code, action, args))
105 | end
106 |
107 | @doc """
108 | Serialize back binary hex to json.
109 | """
110 | def abi_bin_to_json(code, action, binargs) do
111 | "/abi_bin_to_json" |> url() |> post(%{code: code, action: action, binargs: binargs})
112 | end
113 |
114 | def abi_bin_to_json!(code, action, binargs) do
115 | unwrap_or_raise(abi_bin_to_json(code, action, binargs))
116 | end
117 |
118 | @doc """
119 | This method expects a transaction in JSON format and will attempt to apply it to the blockchain,
120 |
121 | `signed_transaction` should be a map like this JSON:
122 |
123 | ```
124 | {
125 | "signatures": [
126 | "EOSKZ4pTehVfqs92wujRp34qRAvUjKJrUyufZfJDo9fdBLzhieyfUSUJpKz1Z12rxh1gTQZ4BcWvKourzxCLb2fMsvN898KSn"
127 | ],
128 | "compression": "none",
129 | "transaction": {
130 | "context_free_actions": [],
131 | "delay_sec": 0,
132 | "expiration": "2018-09-25T06:28:49",
133 | "max_cpu_usage_ms": 0,
134 | "net_usage_words": 0,
135 | "ref_block_num": 32697,
136 | "ref_block_prefix": 32649123,
137 | "transaction_extensions": []
138 | "actions": [
139 | {
140 | "account": "eosio",
141 | "name": "transfer",
142 | "authorization": [
143 | {
144 | "actor": "eosio",
145 | "permission": "active"
146 | }
147 | ],
148 | "data": "0000000050a430550000000000003ab60a000000000000000045434f0000000000"
149 | }
150 | ]
151 | }
152 | }
153 | ```
154 | """
155 | def push_transaction(signed_transaction) do
156 | "/push_transaction" |> url() |> post(signed_transaction)
157 | end
158 |
159 | def push_transaction!(signed_transaction) do
160 | unwrap_or_raise(push_transaction(signed_transaction))
161 | end
162 |
163 | def push_transactions(signed_transactions) do
164 | "/push_transactions" |> url() |> post(signed_transactions)
165 | end
166 |
167 | def push_transactions!(signed_transactions) do
168 | unwrap_or_raise(push_transaction(signed_transactions))
169 | end
170 |
171 | def url(url),
172 | do:
173 | :eosrpc
174 | |> Application.get_env(__MODULE__)
175 | |> Keyword.get(:url)
176 | |> Kernel.<>(url)
177 | end
178 |
--------------------------------------------------------------------------------
/lib/eosrpc/error.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Error do
2 | require Logger
3 |
4 | defexception [:reason, :url]
5 |
6 | def exception(reason, url \\ "")
7 | def exception(reason, url), do: %__MODULE__{reason: reason, url: url}
8 |
9 | def message(%__MODULE__{reason: reason, url: url}) do
10 | Logger.error("EOSRPC call failed: #{reason}", url: url)
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/eosrpc/helper.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Helper do
2 | @moduledoc """
3 | Helper functions to most used EOS Blockchain actions
4 |
5 | You will want to use:
6 | `auto_push/1` to automatically sign, get the keys from wallet and push the transaction
7 | `new_account/4` to create accounts
8 |
9 | You can use everything else, they will help you with some default actions that you need
10 | on your daily basis
11 | """
12 |
13 | @callback new_account(
14 | creator :: binary,
15 | new_account :: binary,
16 | owner_key :: binary,
17 | active_key :: binary
18 | ) :: any
19 | @callback auto_push(actions :: [any]) :: any
20 |
21 | alias EOSRPC.Chain
22 | alias EOSRPC.Wallet
23 |
24 | @doc """
25 | Retrieves the next minute - used mostly for expiration dates of transactions
26 | """
27 | def one_minute_from_now do
28 | Timex.now()
29 | |> Timex.shift(minutes: 1)
30 | |> Timex.format!("%FT%T", :strftime)
31 | end
32 |
33 | @doc """
34 | Convert a list of actions to binary data (/chain/abi_json_to_bin)
35 | """
36 | def actions_to_bin(actions) do
37 | final_actions =
38 | actions
39 | |> Enum.map(fn i ->
40 | response = Chain.abi_json_to_bin(i[:account], i[:name], i[:data])
41 |
42 | case response do
43 | {:ok, %{body: bin}} ->
44 | %{i | data: bin["binargs"]}
45 |
46 | _ ->
47 | response
48 | end
49 | end)
50 |
51 | errors =
52 | final_actions
53 | |> Enum.filter(fn i ->
54 | case i do
55 | {:error, _} -> true
56 | _ -> false
57 | end
58 | end)
59 |
60 | if length(errors) > 0, do: {:error, errors}, else: {:ok, final_actions}
61 | end
62 |
63 | @doc """
64 | Identify the required keys for the transaction and sign with them
65 | """
66 | def sign_transaction(trx_data, chain_id) do
67 | {:ok, %{body: public_keys}} = Wallet.get_public_keys()
68 |
69 | {:ok, %{body: keys}} = Chain.get_required_keys(trx_data, public_keys)
70 |
71 | Wallet.sign_transaction(trx_data, keys["required_keys"], chain_id)
72 | end
73 |
74 | @doc """
75 | Push transaction data with the signature found on `sign_transaction/1`
76 | """
77 | def push_transaction(trx_data, signatures) do
78 | final_trx_data = %{
79 | compression: "none",
80 | signatures: signatures,
81 | transaction: trx_data
82 | }
83 |
84 | Chain.push_transaction(final_trx_data)
85 | end
86 |
87 | @doc """
88 | Get the current irreversible block data from the chain
89 | """
90 | def current_irreversible_block do
91 | {:ok, %{body: chain}} = Chain.get_info()
92 | Chain.get_block(chain["last_irreversible_block_num"])
93 | end
94 |
95 | @doc """
96 | Creates a new account - exactly like cleos
97 | """
98 | def new_account(creator, new_account, owner_key, active_key) do
99 | authorization = %{
100 | actor: creator,
101 | permission: "active"
102 | }
103 |
104 | owner = %{
105 | threshold: 1,
106 | keys: [%{key: owner_key, weight: 1}],
107 | accounts: [],
108 | waits: []
109 | }
110 |
111 | active = %{
112 | threshold: 1,
113 | keys: [%{key: active_key, weight: 1}],
114 | accounts: [],
115 | waits: []
116 | }
117 |
118 | actions = [
119 | %{
120 | account: "eosio",
121 | name: "newaccount",
122 | authorization: [authorization],
123 | data: %{
124 | creator: creator,
125 | name: new_account,
126 | active: active,
127 | owner: owner
128 | }
129 | },
130 | %{
131 | account: "eosio",
132 | name: "buyram",
133 | authorization: [authorization],
134 | data: %{
135 | payer: creator,
136 | receiver: new_account,
137 | quant: "10.0000 #{symbol()}"
138 | }
139 | },
140 | %{
141 | account: "eosio",
142 | name: "delegatebw",
143 | authorization: [authorization],
144 | data: %{
145 | from: creator,
146 | receiver: new_account,
147 | stake_net_quantity: "10.0000 #{symbol()}",
148 | stake_cpu_quantity: "10.0000 #{symbol()}",
149 | transfer: 0
150 | }
151 | }
152 | ]
153 |
154 | auto_push(actions)
155 | end
156 |
157 | @doc """
158 | Sign and submit transaction if you have binary data, otherwise utilizes `auto_push/1`
159 | """
160 | def auto_push_bin(actions) do
161 | {:ok, %{body: chain}} = Chain.get_info()
162 | {:ok, %{body: block}} = Chain.get_block(chain["last_irreversible_block_num"])
163 |
164 | trx_data = %{
165 | actions: actions,
166 | context_free_actions: [],
167 | delay_sec: 0,
168 | expiration: one_minute_from_now(),
169 | max_cpu_usage_ms: 0,
170 | net_usage_words: 0,
171 | ref_block_num: block["block_num"],
172 | ref_block_prefix: block["ref_block_prefix"],
173 | transaction_extensions: []
174 | }
175 |
176 | case sign_transaction(trx_data, chain["chain_id"]) do
177 | {:ok, %{body: sign_body}} -> push_transaction(trx_data, sign_body["signatures"])
178 | error -> error
179 | end
180 | end
181 |
182 | @doc """
183 | Convert action data to binary, identify required keys, sign and finally push transaction
184 | """
185 | def auto_push(actions) do
186 | case actions_to_bin(actions) do
187 | {:ok, final_actions} -> auto_push_bin(final_actions)
188 | error -> error
189 | end
190 | end
191 |
192 | def symbol() do
193 | :eosrpc
194 | |> Application.get_env(__MODULE__)
195 | |> Keyword.get(:symbol)
196 | end
197 | end
198 |
--------------------------------------------------------------------------------
/lib/eosrpc/history.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.History do
2 | @moduledoc """
3 | EOS History Apis Wrapper for Elixir
4 | """
5 |
6 | @callback get_transaction(id :: any) :: any
7 | @callback get_actions(account_name :: binary, post :: integer, offset :: integer) :: any
8 | @callback url(url :: binary) :: binary
9 |
10 | use Tesla
11 |
12 | import EOSRPC
13 |
14 | plug(EOSRPC.Middleware.Error)
15 | plug(Tesla.Middleware.JSON)
16 |
17 | @doc """
18 | Retrieve a transaction from the blockchain.
19 | """
20 | def get_transaction(transaction_id) do
21 | "/get_transaction" |> url() |> post(%{id: transaction_id})
22 | end
23 |
24 | def get_transaction!(transaction_id) do
25 | unwrap_or_raise(get_transaction(transaction_id))
26 | end
27 |
28 | @doc """
29 | Get actions for a given account
30 | """
31 | def get_actions(account_name, pos \\ 0, offset \\ 1_000_000_000) do
32 | "/get_actions"
33 | |> url()
34 | |> post(%{account_name: account_name, pos: pos, offset: offset})
35 | end
36 |
37 | def get_actions!(account_name, pos \\ 0, offset \\ 1_000_000_000) do
38 | unwrap_or_raise(get_actions(account_name, pos, offset))
39 | end
40 |
41 | @doc """
42 | Retrieve accounts associated with a public key
43 | """
44 | def get_key_accounts(public_key) do
45 | "/get_key_accounts" |> url() |> post(%{public_key: public_key})
46 | end
47 |
48 | def get_key_accounts!(public_key) do
49 | unwrap_or_raise(get_key_accounts(public_key))
50 | end
51 |
52 | @doc """
53 | Retrieve accounts which are created by the given account
54 | """
55 | def get_controlled_accounts(account_name) do
56 | "/get_controlled_accounts"
57 | |> url()
58 | |> post(%{controlling_account: account_name})
59 | end
60 |
61 | def get_controlled_accounts!(account_name) do
62 | unwrap_or_raise(get_controlled_accounts(account_name))
63 | end
64 |
65 | def url(url) do
66 | :eosrpc
67 | |> Application.get_env(__MODULE__)
68 | |> Keyword.get(:url)
69 | |> Kernel.<>(url)
70 | end
71 | end
72 |
--------------------------------------------------------------------------------
/lib/eosrpc/middleware/error.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Middleware.Error do
2 | @behaviour Tesla.Middleware
3 |
4 | @moduledoc """
5 | Makes requests that don't respond to HTTP Success codes to return as a error
6 |
7 |
8 | ### Example usage
9 | ```
10 | defmodule MyClient do
11 | use Tesla
12 |
13 | plug(EOSRPC.Middleware.Error)
14 | end
15 | ```
16 | """
17 |
18 | def call(env, next, _options) do
19 | env
20 | |> Tesla.run(next)
21 | |> case do
22 | {:ok, env} ->
23 | case env.status do
24 | s when s in [200, 201, 202, 203, 204] ->
25 | {:ok, env}
26 |
27 | _ ->
28 | {:error, env}
29 | end
30 |
31 | env ->
32 | env
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/lib/eosrpc/wallet.ex:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Wallet do
2 | @moduledoc """
3 | EOSRPC Wallet Wrapper for Elixir
4 |
5 | Based on source code, since there is no documentation for this
6 | https://github.com/EOSIO/eos/blob/master/plugins/wallet_api_plugin/wallet_api_plugin.cpp
7 | """
8 |
9 | @callback unlock(name :: binary, password :: binary) :: any
10 | @callback sign_transaction(transaction :: any, keys ::any) :: any
11 | @callback url(url :: binary) :: binary
12 |
13 | use Tesla
14 |
15 | import EOSRPC
16 |
17 | plug(EOSRPC.Middleware.Error)
18 | plug(Tesla.Middleware.JSON)
19 |
20 | @doc """
21 | List all wallets
22 | """
23 | def list, do: "/list_wallets" |> url() |> get()
24 | def list!, do: unwrap_or_raise(list())
25 |
26 | @doc """
27 | Lock all wallets
28 | """
29 | def lock_all, do: "/lock_all" |> url() |> get()
30 | def lock_all!, do: unwrap_or_raise(lock_all())
31 |
32 | @doc """
33 | List all public keys across all wallets
34 | """
35 | def get_public_keys, do: "/get_public_keys" |> url() |> get()
36 | def get_public_keys!, do: unwrap_or_raise(get_public_keys())
37 |
38 | @doc """
39 | List all key pairs across all wallets
40 | """
41 | def list_keys, do: "/list_keys" |> url() |> get()
42 | def list_keys!, do: unwrap_or_raise(list_keys())
43 |
44 | @doc """
45 | Create a new wallet with the given name
46 | """
47 | def create(name), do: "/create" |> url() |> post(name)
48 | def create!(name), do: unwrap_or_raise(create(name))
49 |
50 | @doc """
51 | Open an existing wallet of the given name
52 | """
53 | def open(name), do: "/open" |> url() |> post(name)
54 | def open!(name), do: unwrap_or_raise(open(name))
55 |
56 | @doc """
57 | Lock a wallet of the given name
58 | """
59 | def lock(name), do: "/lock" |> url() |> post(name)
60 | def lock!(name), do: unwrap_or_raise(lock(name))
61 |
62 | @doc """
63 | Unlock a wallet with the given name and password
64 | """
65 | def unlock(name, password) do
66 | "/unlock"
67 | |> url()
68 | |> post([name, password])
69 | end
70 | def unlock!(name, password), do: unwrap_or_raise(unlock(name, password))
71 |
72 | @doc """
73 | Import a private key to the wallet of the given name
74 | """
75 | def import_key(name, key) do
76 | "/import_key"
77 | |> url()
78 | |> post([name, key])
79 | end
80 | def import_key!(name, key), do: unwrap_or_raise(import_key(name, key))
81 |
82 | @doc """
83 | Set wallet auto lock timeout (in seconds)
84 | """
85 | def set_timeout(seconds), do: "/set_timeout" |> url() |> post(seconds)
86 | def set_timeout!(seconds), do: unwrap_or_raise(set_timeout(seconds))
87 |
88 | @doc """
89 | Sign transaction given an array of transaction, require public keys, and chain id
90 |
91 | `transaction` structure like this json:
92 |
93 | ```
94 | {
95 | "signatures": [],
96 | "compression": "none",
97 | "transaction": {
98 | "context_free_actions": [],
99 | "delay_sec": 0,
100 | "expiration": "2018-09-25T06:28:49",
101 | "max_cpu_usage_ms": 0,
102 | "net_usage_words": 0,
103 | "ref_block_num": 32697,
104 | "ref_block_prefix": 32649123,
105 | "transaction_extensions": []
106 | "actions": [
107 | {
108 | "account": "eosio",
109 | "name": "transfer",
110 | "authorization": [
111 | {
112 | "actor": "eosio",
113 | "permission": "active"
114 | }
115 | ],
116 | "data": "0000000050a430550000000000003ab60a000000000000000045434f0000000000"
117 | }
118 | ]
119 | }
120 | }
121 | ```
122 |
123 | `keys` a list of public keys
124 | `chain_id` the chain id, a field from chain_info
125 |
126 | """
127 | def sign_transaction(transaction, keys), do: sign_transaction(transaction, keys, "")
128 | def sign_transaction!(transaction, keys), do: unwrap_or_raise(sign_transaction(transaction, keys))
129 |
130 | def sign_transaction(transaction, keys, chain_id) do
131 | "/sign_transaction"
132 | |> url()
133 | |> post([transaction, keys, chain_id])
134 | end
135 | def sign_transaction!(transaction, keys, chain_id) do
136 | unwrap_or_raise(sign_transaction(transaction, keys, chain_id))
137 | end
138 |
139 | def url(url),
140 | do:
141 | :eosrpc
142 | |> Application.get_env(__MODULE__)
143 | |> Keyword.get(:url)
144 | |> Kernel.<>(url)
145 | end
146 |
--------------------------------------------------------------------------------
/mix.exs:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Mixfile do
2 | use Mix.Project
3 |
4 | def project do
5 | [
6 | app: :eosrpc,
7 | version: "0.6.2",
8 | elixir: "~> 1.5",
9 | start_permanent: Mix.env() == :prod,
10 | description: "Simple EOSRPC Wrapper for Elixir",
11 | package: package(),
12 | deps: deps(),
13 | source_url: "https://github.com/BeSpiral/eosrpc-elixir-wrapper",
14 | docs: [
15 | main: "readme",
16 | extras: ["README.md"]
17 | ]
18 | ]
19 | end
20 |
21 | # Run "mix help compile.app" to learn about applications.
22 | def application do
23 | [
24 | extra_applications: [:logger]
25 | ]
26 | end
27 |
28 | # Run "mix help deps" to learn about dependencies.
29 | defp deps do
30 | [
31 | {:tesla, "1.2.1"},
32 | {:jason, "~> 1.2"},
33 | {:timex, "~> 3.4"},
34 | {:ex_doc, "~> 0.19", only: :dev, runtime: false},
35 |
36 | # dev
37 | {:credo, "~> 0.10", only: [:dev, :test], runtime: false}
38 | ]
39 | end
40 |
41 | defp package() do
42 | [
43 | name: "eosrpc",
44 | files: ["lib", "test", "mix.exs", "README.md", "LICENSE*"],
45 | licenses: ["GNU GPLv3"],
46 | links: %{"Github" => "https://github.com/BeSpiral/eosrpc-elixir-wrapper"},
47 | maintainers: ["Leo Ribeiro", "Julien Lucca"]
48 | ]
49 | end
50 | end
51 |
--------------------------------------------------------------------------------
/mix.lock:
--------------------------------------------------------------------------------
1 | %{
2 | "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
3 | "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "01d479edba0569a7b7a2c8bf923feeb6dc6a358edc2965ef69aea9ba288bb243"},
4 | "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
5 | "credo": {:hex, :credo, "0.10.0", "66234a95effaf9067edb19fc5d0cd5c6b461ad841baac42467afed96c78e5e9e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "893f53d5a5cb0bb6f96bde8732c20376e24be208fa052bdefd49119f77b64df6"},
6 | "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm", "b42a23e9bd92d65d16db2f75553982e58519054095356a418bb8320bbacb58b1"},
7 | "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "dc87f778d8260da0189a622f62790f6202af72f2f3dee6e78d91a18dd2fcd137"},
8 | "gettext": {:hex, :gettext, "0.16.1", "e2130b25eebcbe02bb343b119a07ae2c7e28bd4b146c4a154da2ffb2b3507af2", [:mix], [], "hexpm", "dd3a7ea5e3e87ee9df29452dd9560709b4c7cc8141537d0b070155038d92bdf1"},
9 | "hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "ed15491f324aa0e95647dca8ef4340418dac479d1204d57e455d52dcfba3f705"},
10 | "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
11 | "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
12 | "makeup": {:hex, :makeup, "0.5.1", "966c5c2296da272d42f1de178c1d135e432662eca795d6dc12e5e8787514edf7", [:mix], [{:nimble_parsec, "~> 0.2.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "259748a45dfcf5f49765a7c29c9594791c82de23e22d7a3e6e59533fe8e8935b"},
13 | "makeup_elixir": {:hex, :makeup_elixir, "0.8.0", "1204a2f5b4f181775a0e456154830524cf2207cf4f9112215c05e0b76e4eca8b", [:mix], [{:makeup, "~> 0.5.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 0.2.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "393d17c5a648e3b30522b2a4743bd1dc3533e1227c8c2823ebe8c3a8e5be5913"},
14 | "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
15 | "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm", "5e839994289d60326aa86020c4fbd9c6938af188ecddab2579f07b66cd665328"},
16 | "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm", "7a4c8e1115a2732a67d7624e28cf6c9f30c66711a9e92928e745c255887ba465"},
17 | "nimble_parsec": {:hex, :nimble_parsec, "0.2.2", "d526b23bdceb04c7ad15b33c57c4526bf5f50aaa70c7c141b4b4624555c68259", [:mix], [], "hexpm", "4ababf5c44164f161872704e1cfbecab3935fdebec66c72905abaad0e6e5cef6"},
18 | "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
19 | "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
20 | "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm", "603561dc0fd62f4f2ea9b890f4e20e1a0d388746d6e20557cafb1b16950de88c"},
21 | "tesla": {:hex, :tesla, "1.2.1", "864783cc27f71dd8c8969163704752476cec0f3a51eb3b06393b3971dc9733ff", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "cfc7277b7a88955ed1f3b9a818d160ea055fd94f7d668e5a83eea18d52eef9ca"},
22 | "timex": {:hex, :timex, "3.4.2", "d74649c93ad0e12ce5b17cf5e11fbd1fb1b24a3d114643e86dba194b64439547", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "212ff08f65995f5f596406227fb1208eda68e7d4d60c233c77d3fe5b3c95dbdf"},
23 | "tzdata": {:hex, :tzdata, "0.5.19", "7962a3997bf06303b7d1772988ede22260f3dae1bf897408ebdac2b4435f4e6a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "9d73d54f2cd2780da2cb8148c5f9cd35ddc5639467568d2297002ca20ea6bbf7"},
24 | "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
25 | }
26 |
--------------------------------------------------------------------------------
/test/eosrpc/middleware/error_test.exs:
--------------------------------------------------------------------------------
1 | defmodule EOSRPC.Middleware.ErrorTest do
2 | use ExUnit.Case, async: false
3 |
4 | defmodule VanillaClient do
5 | use Tesla
6 |
7 | adapter fn (env) ->
8 | case env.url do
9 | "/200" ->
10 | {:ok, %{env | status: 200, body: "Everything fine"}}
11 |
12 | "/500" ->
13 | {:ok, %{env | status: 500, body: "Uoh!"}}
14 | end
15 | end
16 | end
17 |
18 | defmodule CustomClient do
19 | use Tesla
20 |
21 | plug(EOSRPC.Middleware.Error)
22 |
23 | adapter fn (env) ->
24 | case env.url do
25 | "/200" ->
26 | {:ok, %{env | status: 200, body: "Everything fine"}}
27 |
28 | "/500" ->
29 | {:ok, %{env | status: 500, body: "Uoh!"}}
30 | end
31 | end
32 | end
33 |
34 | describe "Errors for HTTP verbs" do
35 | test "200 response reply normaly" do
36 | assert {:ok, env} = VanillaClient.get("/200")
37 | assert env.status == 200
38 |
39 | assert {:ok, env} = CustomClient.get("/200")
40 | assert env.status == 200
41 | end
42 |
43 | test "500 response reply as error" do
44 | assert {:ok, env} = VanillaClient.get("/500")
45 | assert env.status == 500
46 |
47 | assert {:error, env} = CustomClient.get("/500")
48 | assert env.status == 500
49 | end
50 | end
51 |
52 | describe "Error with bangs" do
53 | test "200 response reply normaly" do
54 | assert env = VanillaClient.get!("/200")
55 | assert env.status == 200
56 |
57 | assert env = CustomClient.get!("/200")
58 | assert env.status == 200
59 | end
60 |
61 | test "500 response reply throws exception" do
62 | assert_raise Tesla.Error, fn ->
63 | CustomClient.get!("/500")
64 | end
65 | end
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/test/eosrpc_test.exs:
--------------------------------------------------------------------------------
1 | defmodule EOSRPCTest do
2 | use ExUnit.Case
3 | doctest EOSRPC
4 | end
5 |
--------------------------------------------------------------------------------
/test/test_helper.exs:
--------------------------------------------------------------------------------
1 | ExUnit.start()
2 |
--------------------------------------------------------------------------------