This repository was archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange_8cpp.html
174 lines (167 loc) · 12.6 KB
/
exchange_8cpp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>EOS.IO: contracts/exchange/exchange.cpp File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="eos-logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">EOS.IO
 <span id="projectnumber">DAWN3.0.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_ae9b15dd87e066e1908bbd90e8f38627.html">contracts</a></li><li class="navelem"><a class="el" href="dir_5dc13a1abd435123f7be5ea8dc751d1b.html">exchange</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#namespaces">Namespaces</a> |
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">exchange.cpp File Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>defines an example exchange contract
<a href="#details">More...</a></p>
<div class="textblock"><code>#include <<a class="el" href="exchange_8hpp_source.html">exchange/exchange.hpp</a>></code><br />
<code>#include <<a class="el" href="print_8hpp_source.html">eoslib/print.hpp</a>></code><br />
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:namespaceexchange"><td class="memItemLeft" align="right" valign="top">  </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html">exchange</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a4af1058806fad580b07a5da05729a6e0"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a4af1058806fad580b07a5da05729a6e0">exchange::save</a> (const <a class="el" href="structaccount.html">account</a> &a)</td></tr>
<tr class="separator:a4af1058806fad580b07a5da05729a6e0"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a13d8f4e165215611a7879766e215b855"><td class="memTemplParams" colspan="2">template<typename Lambda > </td></tr>
<tr class="memitem:a13d8f4e165215611a7879766e215b855"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a13d8f4e165215611a7879766e215b855">exchange::modify_account</a> (<a class="el" href="group__types.html#ga3b44deb4b3b8d6ebab339d1263692117">account_name</a> a, Lambda &&modify)</td></tr>
<tr class="separator:a13d8f4e165215611a7879766e215b855"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a32b7d74a91010152d37cace85418e6f7"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a32b7d74a91010152d37cace85418e6f7">exchange::apply_currency_transfer</a> (const currency::transfer &transfer)</td></tr>
<tr class="separator:a32b7d74a91010152d37cace85418e6f7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a7b4f0fec8b7a1d9c97dc3f5127872297"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a7b4f0fec8b7a1d9c97dc3f5127872297">exchange::apply_eos_transfer</a> (const eosio::transfer &transfer)</td></tr>
<tr class="separator:a7b4f0fec8b7a1d9c97dc3f5127872297"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a15c24418c4ed503becae07191757dee2"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a15c24418c4ed503becae07191757dee2">exchange::match</a> (bid &bid_to_match, <a class="el" href="structaccount.html">account</a> &buyer, ask &ask_to_match, <a class="el" href="structaccount.html">account</a> &seller)</td></tr>
<tr class="separator:a15c24418c4ed503becae07191757dee2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:abaf272c3c6eb0eb097e95916798b6b14"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#abaf272c3c6eb0eb097e95916798b6b14">exchange::apply_exchange_buy</a> (<a class="el" href="structexchange_1_1buy__order.html">buy_order</a> order)</td></tr>
<tr class="separator:abaf272c3c6eb0eb097e95916798b6b14"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a3832570cd9040ea2ceb28c4e43028a5e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a3832570cd9040ea2ceb28c4e43028a5e">exchange::apply_exchange_sell</a> (<a class="el" href="structexchange_1_1sell__order.html">sell_order</a> order)</td></tr>
<tr class="separator:a3832570cd9040ea2ceb28c4e43028a5e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a539153eabc5f4d000b83633a50d78105"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#a539153eabc5f4d000b83633a50d78105">exchange::apply_exchange_cancel_buy</a> (<a class="el" href="structexchange_1_1order__id.html">order_id</a> order)</td></tr>
<tr class="separator:a539153eabc5f4d000b83633a50d78105"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ab6a1d78f1483a78bf31301a3a175d0ff"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceexchange.html#ab6a1d78f1483a78bf31301a3a175d0ff">exchange::apply_exchange_cancel_sell</a> (<a class="el" href="structexchange_1_1order__id.html">order_id</a> order)</td></tr>
<tr class="separator:ab6a1d78f1483a78bf31301a3a175d0ff"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a02fd73d861ef2e4aabb38c0c9ff82947"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="exchange_8cpp.html#a02fd73d861ef2e4aabb38c0c9ff82947">init</a> ()</td></tr>
<tr class="separator:a02fd73d861ef2e4aabb38c0c9ff82947"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a3c01edc4ed313916967237c16feb1446"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="exchange_8cpp.html#a3c01edc4ed313916967237c16feb1446">apply</a> (<a class="el" href="group__types.html#gaaa5d1cd013383c889537491c3cfd9aad">uint64_t</a> code, <a class="el" href="group__types.html#gaaa5d1cd013383c889537491c3cfd9aad">uint64_t</a> <a class="el" href="structeosio_1_1action.html">action</a>)</td></tr>
<tr class="separator:a3c01edc4ed313916967237c16feb1446"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><dl class="section copyright"><dt>Copyright</dt><dd>defined in eos/LICENSE.txt This exchange contract assumes the existence of two currency contracts located at and . These currency contracts have provided an API header defined in <a class="el" href="currency_8hpp.html">currency.hpp</a> which the exchange contract will use to process messages related to deposits and withdraws.</dd></dl>
<p>The exchange contract knows that the currency contracts require_notice() of both the sender and receiver; therefore, the exchange contract can implement a message handler that will be called anytime funds are deposited to or withdrawn from the exchange.</p>
<p>When tokens are sent to from another account the exchange will credit the user's balance of the proper currency.</p>
<p>To withdraw from the exchange, the user simply reverses the "to" and "from" fields of the currency contract transfer message. The currency contract will require the "authority" of the exchange, but the exchange's <a class="el" href="exchange_8cpp.html#a02fd73d861ef2e4aabb38c0c9ff82947">init()</a> function configured this permission to allow <em>anyone</em> to transfer from the exchange.</p>
<p>To prevent people from stealing all the money from the exchange, the exchange's transfer handler requires both the authority of the receiver and asserts that the user has a sufficient balance on the exchange. Lacking both of these the exchange will kill the transfer.</p>
<p>The exchange and one of the currency contracts are forced to execute in the same thread anytime there is a deposit or withdraw. The transaction containing the transfer are already required to include the exchange in the scope by the currency contract.</p>
<p>creating, canceling, and filling orders do not require blocking either currency contract. Users can only deposit or withdraw to their own currency account. </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a3c01edc4ed313916967237c16feb1446"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3c01edc4ed313916967237c16feb1446">◆ </a></span>apply()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void apply </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__types.html#gaaa5d1cd013383c889537491c3cfd9aad">uint64_t</a> </td>
<td class="paramname"><em>code</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="group__types.html#gaaa5d1cd013383c889537491c3cfd9aad">uint64_t</a> </td>
<td class="paramname"><em>action</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>The apply method implements the dispatch of events to this contract </p>
</div>
</div>
<a id="a02fd73d861ef2e4aabb38c0c9ff82947"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a02fd73d861ef2e4aabb38c0c9ff82947">◆ </a></span>init()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void init </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>