@leofcoin/chain 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain.browser.js +10048 -15004
- package/dist/chain.browser.min.js +1 -1
- package/dist/chain.js +31 -219
- package/dist/node.browser.js +3770 -3738
- package/dist/node.browser.min.js +1 -1
- package/dist/node.js +1 -1
- package/docs/@leofcoin/chain/1.0.13/chain.js.html +738 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_factory.js.html +182 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_nameService.js.html +231 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_proxies_factoryProxy.js.html +135 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_proxies_nameServiceProxy.js.html +135 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_proxies_nativeTokenProxy.js.html +135 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_proxies_validatorsProxy.js.html +135 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_proxies_votingProxy.js.html +135 -0
- package/docs/@leofcoin/chain/1.0.13/contracts_validators.js.html +242 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Semibold-webfont.svg +1830 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.13/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.13/global.html +1153 -0
- package/docs/@leofcoin/chain/1.0.13/icons/home.svg +4 -0
- package/docs/@leofcoin/chain/1.0.13/icons/search.svg +4 -0
- package/docs/@leofcoin/chain/1.0.13/index.html +125 -0
- package/docs/@leofcoin/chain/1.0.13/machine.js.html +251 -0
- package/docs/@leofcoin/chain/1.0.13/scripts/linenumber.js +23 -0
- package/docs/@leofcoin/chain/1.0.13/scripts/pagelocation.js +89 -0
- package/docs/@leofcoin/chain/1.0.13/standards_roles.js.html +188 -0
- package/docs/@leofcoin/chain/1.0.13/standards_token.js.html +260 -0
- package/docs/@leofcoin/chain/1.0.13/styles/collapse.css +27 -0
- package/docs/@leofcoin/chain/1.0.13/styles/jsdoc-default.css +953 -0
- package/docs/@leofcoin/chain/1.0.13/styles/prettify-jsdoc.css +111 -0
- package/docs/@leofcoin/chain/1.0.13/styles/prettify-tomorrow.css +138 -0
- package/package.json +3 -1
- package/src/chain.js +2 -2
- package/src/machine.js +2 -3
- package/src/node.js +1 -1
- package/src/typer.js +1 -1
- package/src/addresses.json +0 -6
- package/src/bytecodes.json +0 -6
- package/src/lib.js +0 -67
- package/src/messages/block.js +0 -14
- package/src/messages/bw-request.js +0 -14
- package/src/messages/bw.js +0 -14
- package/src/messages/contract.js +0 -13
- package/src/messages/last-block-request.js +0 -14
- package/src/messages/last-block.js +0 -14
- package/src/messages/transaction.js +0 -14
- package/src/protos/block.proto.js +0 -26
- package/src/protos/bw-request.proto.js +0 -5
- package/src/protos/bw.proto.js +0 -7
- package/src/protos/contract.proto.js +0 -7
- package/src/protos/last-block-request.proto.js +0 -5
- package/src/protos/last-block.proto.js +0 -7
- package/src/protos/transaction.proto.js +0 -11
- package/src/utils/utils.js +0 -7
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
|
+
|
|
10
|
+
<title>
|
|
11
|
+
standards/roles.js - Documentation
|
|
12
|
+
</title>
|
|
13
|
+
|
|
14
|
+
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
|
|
15
|
+
|
|
16
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
|
|
17
|
+
<script>hljs.initHighlightingOnLoad();</script>
|
|
18
|
+
|
|
19
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
|
20
|
+
|
|
21
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
22
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
23
|
+
|
|
24
|
+
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
<!-- start Mixpanel -->
|
|
30
|
+
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
|
|
31
|
+
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
|
32
|
+
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
|
|
33
|
+
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
|
|
34
|
+
<!-- end Mixpanel -->
|
|
35
|
+
</head>
|
|
36
|
+
|
|
37
|
+
<body>
|
|
38
|
+
<svg style="display: none;">
|
|
39
|
+
<defs>
|
|
40
|
+
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
41
|
+
<path d="M0 0h24v24H0z" fill="none"/>
|
|
42
|
+
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
|
|
43
|
+
</symbol>
|
|
44
|
+
</defs>
|
|
45
|
+
</svg>
|
|
46
|
+
|
|
47
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
48
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
49
|
+
<div class="navicon"></div>
|
|
50
|
+
</label>
|
|
51
|
+
|
|
52
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
53
|
+
|
|
54
|
+
<div class="top-nav-wrapper">
|
|
55
|
+
<ul>
|
|
56
|
+
<li >
|
|
57
|
+
<a href="index.html">
|
|
58
|
+
|
|
59
|
+
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
60
|
+
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
|
|
61
|
+
<path d="M0 0h24v24H0z" fill="none"/>
|
|
62
|
+
</svg>
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
</a>
|
|
66
|
+
</li>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</ul>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<nav>
|
|
74
|
+
<h3 class="reference-title">
|
|
75
|
+
@leofcoin/chain
|
|
76
|
+
</h3>
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
<h3>
|
|
80
|
+
Resources
|
|
81
|
+
</h3>
|
|
82
|
+
|
|
83
|
+
<a href="https://github.com/arteontoken/monorepo/chain">github</a>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<h3 id="global-nav">Global</h3><ul><li><a href="global.html#addContract">addContract</a></li><li><a href="global.html#createTransaction">createTransaction</a></li><li><a href="global.html#createTransactionFrom">createTransactionFrom</a></li><li><a href="global.html#deployContract">deployContract</a></li><li><a href="global.html#lookup">lookup</a></li><li><a href="global.html#state">state</a></li></ul>
|
|
88
|
+
</nav>
|
|
89
|
+
|
|
90
|
+
<div id="main">
|
|
91
|
+
|
|
92
|
+
<h1 class="page-title">
|
|
93
|
+
standards/roles.js
|
|
94
|
+
</h1>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
<section>
|
|
101
|
+
<article>
|
|
102
|
+
<pre class="prettyprint source linenums"><code>export default class Roles {
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Object => Array
|
|
106
|
+
*/
|
|
107
|
+
#roles = {
|
|
108
|
+
'OWNER': [],
|
|
109
|
+
'MINT': [],
|
|
110
|
+
'BURN': []
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
constructor(roles) {
|
|
114
|
+
// allow devs to set their own roles but always keep the default ones included
|
|
115
|
+
// also allows roles to be loaded from the stateStore
|
|
116
|
+
// carefull when includin gthe roles make sure to add the owner
|
|
117
|
+
// since no roles are granted by default when using custom roles
|
|
118
|
+
if (roles) {
|
|
119
|
+
if (roles instanceof Object) {
|
|
120
|
+
this.#roles = {...roles, ...this.#roles}
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(`expected roles to be an object`)
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
// no roles given so default to the msg sender
|
|
126
|
+
this.#grantRole(msg.sender, 'OWNER')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get state() {
|
|
131
|
+
return { roles: this.roles }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get roles() {
|
|
135
|
+
return {...this.#roles}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
hasRole(address, role) {
|
|
139
|
+
return this.#roles[role] ? this.#roles[role].indexOf(address) !== -1 : false
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#grantRole(address, role) {
|
|
143
|
+
if (this.hasRole(address, role)) throw new Error(`${role} role already granted for ${address}`)
|
|
144
|
+
|
|
145
|
+
this.#roles[role].push(address)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#revokeRole(address, role) {
|
|
149
|
+
if (!this.hasRole(address, role)) throw new Error(`${role} role already revoked for ${address}`)
|
|
150
|
+
if (role === 'OWNER' && this.#roles[role].length === 1) throw new Error(`atleast one owner is needed!`)
|
|
151
|
+
|
|
152
|
+
this.#roles[role].splice(this.#roles[role].indexOf(address))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
grantRole(address, role) {
|
|
156
|
+
if (!this.hasRole(address, 'OWNER')) throw new Error('Not allowed')
|
|
157
|
+
|
|
158
|
+
this.#grantRole(address, role)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
revokeRole(address, role) {
|
|
162
|
+
if (!this.hasRole(address, 'OWNER')) throw new Error('Not allowed')
|
|
163
|
+
|
|
164
|
+
this.#revokeRole(address, role)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
</code></pre>
|
|
168
|
+
</article>
|
|
169
|
+
</section>
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<br class="clear">
|
|
177
|
+
|
|
178
|
+
<footer>
|
|
179
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a>
|
|
180
|
+
</footer>
|
|
181
|
+
|
|
182
|
+
<script src="scripts/linenumber.js"></script>
|
|
183
|
+
<script src="scripts/pagelocation.js"></script>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
</body>
|
|
188
|
+
</html>
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
|
+
|
|
10
|
+
<title>
|
|
11
|
+
standards/token.js - Documentation
|
|
12
|
+
</title>
|
|
13
|
+
|
|
14
|
+
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
|
|
15
|
+
|
|
16
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
|
|
17
|
+
<script>hljs.initHighlightingOnLoad();</script>
|
|
18
|
+
|
|
19
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
|
20
|
+
|
|
21
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
22
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
23
|
+
|
|
24
|
+
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
<!-- start Mixpanel -->
|
|
30
|
+
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
|
|
31
|
+
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
|
32
|
+
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
|
|
33
|
+
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
|
|
34
|
+
<!-- end Mixpanel -->
|
|
35
|
+
</head>
|
|
36
|
+
|
|
37
|
+
<body>
|
|
38
|
+
<svg style="display: none;">
|
|
39
|
+
<defs>
|
|
40
|
+
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
41
|
+
<path d="M0 0h24v24H0z" fill="none"/>
|
|
42
|
+
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
|
|
43
|
+
</symbol>
|
|
44
|
+
</defs>
|
|
45
|
+
</svg>
|
|
46
|
+
|
|
47
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
48
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
49
|
+
<div class="navicon"></div>
|
|
50
|
+
</label>
|
|
51
|
+
|
|
52
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
53
|
+
|
|
54
|
+
<div class="top-nav-wrapper">
|
|
55
|
+
<ul>
|
|
56
|
+
<li >
|
|
57
|
+
<a href="index.html">
|
|
58
|
+
|
|
59
|
+
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
60
|
+
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
|
|
61
|
+
<path d="M0 0h24v24H0z" fill="none"/>
|
|
62
|
+
</svg>
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
</a>
|
|
66
|
+
</li>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
</ul>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<nav>
|
|
74
|
+
<h3 class="reference-title">
|
|
75
|
+
@leofcoin/chain
|
|
76
|
+
</h3>
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
<h3>
|
|
80
|
+
Resources
|
|
81
|
+
</h3>
|
|
82
|
+
|
|
83
|
+
<a href="https://github.com/arteontoken/monorepo/chain">github</a>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<h3 id="global-nav">Global</h3><ul><li><a href="global.html#addContract">addContract</a></li><li><a href="global.html#createTransaction">createTransaction</a></li><li><a href="global.html#createTransactionFrom">createTransactionFrom</a></li><li><a href="global.html#deployContract">deployContract</a></li><li><a href="global.html#lookup">lookup</a></li><li><a href="global.html#state">state</a></li></ul>
|
|
88
|
+
</nav>
|
|
89
|
+
|
|
90
|
+
<div id="main">
|
|
91
|
+
|
|
92
|
+
<h1 class="page-title">
|
|
93
|
+
standards/token.js
|
|
94
|
+
</h1>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
<section>
|
|
101
|
+
<article>
|
|
102
|
+
<pre class="prettyprint source linenums"><code>import Roles from './roles.js'
|
|
103
|
+
|
|
104
|
+
export default class Token extends Roles {
|
|
105
|
+
/**
|
|
106
|
+
* string
|
|
107
|
+
*/
|
|
108
|
+
#name
|
|
109
|
+
/**
|
|
110
|
+
* String
|
|
111
|
+
*/
|
|
112
|
+
#symbol
|
|
113
|
+
/**
|
|
114
|
+
* uint
|
|
115
|
+
*/
|
|
116
|
+
#holders = 0
|
|
117
|
+
/**
|
|
118
|
+
* Object => Object => uint
|
|
119
|
+
*/
|
|
120
|
+
#balances = {}
|
|
121
|
+
/**
|
|
122
|
+
* Object => Object => uint
|
|
123
|
+
*/
|
|
124
|
+
#approvals = {}
|
|
125
|
+
|
|
126
|
+
#decimals = 18
|
|
127
|
+
|
|
128
|
+
#totalSupply = BigNumber.from(0)
|
|
129
|
+
|
|
130
|
+
// this.#privateField2 = 1
|
|
131
|
+
constructor(name, symbol, decimals = 18, state) {
|
|
132
|
+
if (!name) throw new Error(`name undefined`)
|
|
133
|
+
if (!symbol) throw new Error(`symbol undefined`)
|
|
134
|
+
|
|
135
|
+
super(state?.roles)
|
|
136
|
+
|
|
137
|
+
this.#name = name
|
|
138
|
+
this.#symbol = symbol
|
|
139
|
+
this.#decimals = decimals
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// enables snapshotting
|
|
143
|
+
// needs dev attention so nothing breaks after snapshot happens
|
|
144
|
+
// iow everything that is not static needs to be included in the stateObject
|
|
145
|
+
/**
|
|
146
|
+
* @return {Object} {holders, balances, ...}
|
|
147
|
+
*/
|
|
148
|
+
get state() {
|
|
149
|
+
return {
|
|
150
|
+
...super.state,
|
|
151
|
+
holders: this.holders,
|
|
152
|
+
balances: this.balances,
|
|
153
|
+
approvals: { ...this.#approvals },
|
|
154
|
+
totalSupply: this.totalSupply
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get totalSupply() {
|
|
159
|
+
return this.#totalSupply
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get name() {
|
|
163
|
+
return this.#name
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get symbol() {
|
|
167
|
+
return this.#symbol
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get holders() {
|
|
171
|
+
return this.#holders
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get balances() {
|
|
175
|
+
return {...this.#balances}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
mint(to, amount) {
|
|
179
|
+
if (!this.hasRole(msg.sender, 'MINT')) throw new Error('not allowed')
|
|
180
|
+
|
|
181
|
+
this.#totalSupply = this.#totalSupply.add(amount)
|
|
182
|
+
this.#increaseBalance(to, amount)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
burn(to, amount) {
|
|
186
|
+
if (!this.hasRole(msg.sender, 'BURN')) throw new Error('not allowed')
|
|
187
|
+
|
|
188
|
+
this.#totalSupply = this.#totalSupply.sub(amount)
|
|
189
|
+
this.#decreaseBalance(to, amount)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
#beforeTransfer(from, to, amount) {
|
|
193
|
+
if (!this.#balances[from] || this.#balances[from] < amount) throw new Error('amount exceeds balance')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#updateHolders(address, previousBalance) {
|
|
197
|
+
if (this.#balances[address].toHexString() === '0x00') this.#holders -= 1
|
|
198
|
+
else if (this.#balances[address].toHexString() !== '0x00' && previousBalance.toHexString() === '0x00') this.#holders += 1
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#increaseBalance(address, amount) {
|
|
202
|
+
if (!this.#balances[address]) this.#balances[address] = BigNumber.from(0)
|
|
203
|
+
const previousBalance = this.#balances[address]
|
|
204
|
+
|
|
205
|
+
this.#balances[address] = this.#balances[address].add(amount)
|
|
206
|
+
this.#updateHolders(address, previousBalance)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
#decreaseBalance(address, amount) {
|
|
210
|
+
const previousBalance = this.#balances[address]
|
|
211
|
+
this.#balances[address] = this.#balances[address].sub(amount)
|
|
212
|
+
this.#updateHolders(address, previousBalance)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
balanceOf(address) {
|
|
216
|
+
return this.#balances[address]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
setApproval(operator, amount) {
|
|
220
|
+
const owner = globalThis.msg.sender
|
|
221
|
+
if (!this.#approvals[owner]) this.#approvals[owner] = {}
|
|
222
|
+
this.#approvals[owner][operator] = amount
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
approved(owner, operator, amount) {
|
|
226
|
+
return this.#approvals[owner][operator] === amount
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
transfer(from, to, amount) {
|
|
230
|
+
// TODO: is BigNumber?
|
|
231
|
+
amount = BigNumber.from(amount)
|
|
232
|
+
this.#beforeTransfer(from, to, amount)
|
|
233
|
+
this.#decreaseBalance(from, amount)
|
|
234
|
+
this.#increaseBalance(to, amount)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
</code></pre>
|
|
240
|
+
</article>
|
|
241
|
+
</section>
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
</div>
|
|
247
|
+
|
|
248
|
+
<br class="clear">
|
|
249
|
+
|
|
250
|
+
<footer>
|
|
251
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a>
|
|
252
|
+
</footer>
|
|
253
|
+
|
|
254
|
+
<script src="scripts/linenumber.js"></script>
|
|
255
|
+
<script src="scripts/pagelocation.js"></script>
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
</body>
|
|
260
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@media only screen and (min-width: 681px) {
|
|
2
|
+
nav > ul > li:hover .methods,
|
|
3
|
+
.active .methods {
|
|
4
|
+
display: block;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.methods {
|
|
8
|
+
display: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
nav > ul > li {
|
|
12
|
+
padding: 20px 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
nav > ul > li > a {
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
nav > ul > li.active a {
|
|
20
|
+
margin-bottom: 10px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
nav > ul > li:hover > a,
|
|
24
|
+
nav > ul > li.active > a {
|
|
25
|
+
margin-bottom: 15px;
|
|
26
|
+
}
|
|
27
|
+
}
|