@leofcoin/chain 1.0.25 → 1.0.26
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/demo/151.browser.js +271 -0
- package/demo/205.browser.js +215 -0
- package/demo/427.browser.js +8092 -0
- package/demo/560.browser.js +3 -0
- package/demo/911.browser.js +11024 -0
- package/{dist → demo}/chain.browser.js +6765 -24141
- package/demo/index.html +4 -4
- package/demo/main.browser.js +8163 -0
- package/{dist → demo}/node.browser.js +3157 -2582
- package/{dist → demo}/pako.browser.js +0 -0
- package/demo/peernet-worker.browser.js +11330 -0
- package/demo/workers/machine-worker.js +12544 -0
- package/{dist → demo}/wrtc.browser.js +0 -0
- package/dist/chain.js +235 -138
- package/dist/module/chain.js +1189 -0
- package/dist/module/node.js +1 -0
- package/dist/module/workers/machine-worker.js +491 -0
- package/dist/node.js +1 -1
- package/package.json +11 -19
- package/rollup.config.js +87 -3
- package/src/chain.js +94 -61
- package/src/machine.js +96 -57
- package/src/node.js +2 -1
- package/src/workers/block-worker.js +71 -0
- package/src/workers/machine-worker.js +160 -0
- package/src/workers/pool-worker.js +37 -0
- package/src/workers/transaction-worker.js +26 -0
- package/test/chain.js +14 -14
- package/test/create-genesis.js +13 -5
- package/webpack.config.js +49 -6
- package/workers/block-worker.js +1 -0
- package/workers/machine-worker.js +1 -0
- package/workers/pool-worker.js +1 -0
- package/workers/transaction-worker.js +1 -0
- package/dist/protons.browser.js +0 -11429
- package/docs/@leofcoin/chain/1.0.22/chain.js.html +0 -891
- package/docs/@leofcoin/chain/1.0.22/contracts_factory.js.html +0 -182
- package/docs/@leofcoin/chain/1.0.22/contracts_nameService.js.html +0 -231
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_factoryProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nameServiceProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nativeTokenProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_validatorsProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_votingProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.22/contracts_validators.js.html +0 -242
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.22/global.html +0 -1805
- package/docs/@leofcoin/chain/1.0.22/icons/home.svg +0 -4
- package/docs/@leofcoin/chain/1.0.22/icons/search.svg +0 -4
- package/docs/@leofcoin/chain/1.0.22/index.html +0 -125
- package/docs/@leofcoin/chain/1.0.22/machine.js.html +0 -255
- package/docs/@leofcoin/chain/1.0.22/scripts/linenumber.js +0 -23
- package/docs/@leofcoin/chain/1.0.22/scripts/pagelocation.js +0 -89
- package/docs/@leofcoin/chain/1.0.22/standards_roles.js.html +0 -188
- package/docs/@leofcoin/chain/1.0.22/standards_token.js.html +0 -260
- package/docs/@leofcoin/chain/1.0.22/styles/collapse.css +0 -27
- package/docs/@leofcoin/chain/1.0.22/styles/jsdoc-default.css +0 -953
- package/docs/@leofcoin/chain/1.0.22/styles/prettify-jsdoc.css +0 -111
- package/docs/@leofcoin/chain/1.0.22/styles/prettify-tomorrow.css +0 -138
- package/docs/@leofcoin/chain/1.0.24/chain.js.html +0 -891
- package/docs/@leofcoin/chain/1.0.24/contracts_factory.js.html +0 -182
- package/docs/@leofcoin/chain/1.0.24/contracts_nameService.js.html +0 -231
- package/docs/@leofcoin/chain/1.0.24/contracts_proxies_factoryProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nameServiceProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.24/contracts_proxies_nativeTokenProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.24/contracts_proxies_validatorsProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.24/contracts_proxies_votingProxy.js.html +0 -135
- package/docs/@leofcoin/chain/1.0.24/contracts_validators.js.html +0 -242
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/@leofcoin/chain/1.0.24/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/@leofcoin/chain/1.0.24/global.html +0 -1805
- package/docs/@leofcoin/chain/1.0.24/icons/home.svg +0 -4
- package/docs/@leofcoin/chain/1.0.24/icons/search.svg +0 -4
- package/docs/@leofcoin/chain/1.0.24/index.html +0 -125
- package/docs/@leofcoin/chain/1.0.24/machine.js.html +0 -255
- package/docs/@leofcoin/chain/1.0.24/scripts/linenumber.js +0 -23
- package/docs/@leofcoin/chain/1.0.24/scripts/pagelocation.js +0 -89
- package/docs/@leofcoin/chain/1.0.24/standards_roles.js.html +0 -188
- package/docs/@leofcoin/chain/1.0.24/standards_token.js.html +0 -260
- package/docs/@leofcoin/chain/1.0.24/styles/collapse.css +0 -27
- package/docs/@leofcoin/chain/1.0.24/styles/jsdoc-default.css +0 -953
- package/docs/@leofcoin/chain/1.0.24/styles/prettify-jsdoc.css +0 -111
- package/docs/@leofcoin/chain/1.0.24/styles/prettify-tomorrow.css +0 -138
|
@@ -1,188 +0,0 @@
|
|
|
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/tree/main/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#createRawTransaction">createRawTransaction</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#createTransactionHash">createTransactionHash</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.11</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>
|
|
@@ -1,260 +0,0 @@
|
|
|
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/tree/main/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#createRawTransaction">createRawTransaction</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#createTransactionHash">createTransactionHash</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.11</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>
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|