@leofcoin/chain 1.0.22 → 1.0.23
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 +26563 -9162
- package/dist/chain.js +479 -118
- package/dist/node.browser.js +3603 -3912
- package/dist/node.js +1 -1
- package/dist/protons.browser.js +7818 -175
- package/dist/wrtc.browser.js +1 -1
- package/docs/@leofcoin/chain/1.0.22/chain.js.html +377 -223
- package/docs/@leofcoin/chain/1.0.22/contracts_factory.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_nameService.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_factoryProxy.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nameServiceProxy.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_nativeTokenProxy.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_validatorsProxy.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_proxies_votingProxy.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/contracts_validators.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Bold-webfont.svg +1829 -1829
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Italic-webfont.svg +1829 -1829
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Light-webfont.svg +1830 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Regular-webfont.svg +1830 -1830
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-Semibold-webfont.svg +1829 -1829
- package/docs/@leofcoin/chain/1.0.22/fonts/OpenSans-SemiboldItalic-webfont.svg +1829 -1829
- package/docs/@leofcoin/chain/1.0.22/global.html +1804 -1152
- package/docs/@leofcoin/chain/1.0.22/icons/home.svg +3 -3
- package/docs/@leofcoin/chain/1.0.22/icons/search.svg +3 -3
- package/docs/@leofcoin/chain/1.0.22/index.html +124 -124
- package/docs/@leofcoin/chain/1.0.22/machine.js.html +133 -129
- package/docs/@leofcoin/chain/1.0.22/scripts/linenumber.js +23 -23
- package/docs/@leofcoin/chain/1.0.22/scripts/pagelocation.js +89 -89
- package/docs/@leofcoin/chain/1.0.22/standards_roles.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/standards_token.js.html +123 -123
- package/docs/@leofcoin/chain/1.0.22/styles/collapse.css +27 -27
- package/docs/@leofcoin/chain/1.0.22/styles/jsdoc-default.css +953 -953
- package/docs/@leofcoin/chain/1.0.22/styles/prettify-jsdoc.css +111 -111
- package/docs/@leofcoin/chain/1.0.22/styles/prettify-tomorrow.css +138 -138
- package/package.json +8 -5
- package/rollup.config.js +1 -2
- package/src/chain.js +254 -100
- package/src/config/config.js +6 -2
- package/src/machine.js +10 -6
- package/src/node.js +2 -34
- package/src/state.js +8 -3
- package/src/transactions/transaction.js +3 -0
- package/test/chain.js +39 -60
- package/webpack.config.js +3 -3
|
@@ -1,107 +1,114 @@
|
|
|
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
|
-
chain.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#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
|
-
chain.js
|
|
94
|
-
</h1>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<section>
|
|
101
|
-
<article>
|
|
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
|
+
chain.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
|
+
chain.js
|
|
94
|
+
</h1>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
<section>
|
|
101
|
+
<article>
|
|
102
102
|
<pre class="prettyprint source linenums"><code>import { BigNumber, formatUnits, parseUnits } from '@leofcoin/utils'
|
|
103
|
-
import Machine from './machine'
|
|
104
|
-
import { ContractMessage, TransactionMessage, BlockMessage, BWMessage, BWRequestMessage } from '
|
|
103
|
+
import Machine from './machine.js'
|
|
104
|
+
import { ContractMessage, TransactionMessage, BlockMessage, BWMessage, BWRequestMessage } from './../../messages/src/messages'
|
|
105
|
+
import { addresses } from './../../addresses/src/addresses'
|
|
106
|
+
import { contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage, calculateFee } from './../../lib/src/lib'
|
|
107
|
+
import MultiWallet from '@leofcoin/multi-wallet'
|
|
108
|
+
import {CodecHash} from '@leofcoin/codec-format-interface/dist/index'
|
|
109
|
+
import bs32 from '@vandeurenglenn/base32'
|
|
110
|
+
import config from './config/config'
|
|
111
|
+
import { formatBytes } from '../../utils/src/utils.js'
|
|
105
112
|
|
|
106
113
|
globalThis.BigNumber = BigNumber
|
|
107
114
|
|
|
@@ -126,7 +133,7 @@ export default class Chain {
|
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
get nativeToken() {
|
|
129
|
-
return
|
|
136
|
+
return addresses.nativeToken
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
get validators() {
|
|
@@ -139,28 +146,39 @@ export default class Chain {
|
|
|
139
146
|
|
|
140
147
|
async hasTransactionToHandle() {
|
|
141
148
|
const size = await transactionPoolStore.size()
|
|
149
|
+
console.log({size});
|
|
142
150
|
if (size > 0) return true
|
|
143
151
|
return false
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
async #runEpoch() {
|
|
147
|
-
|
|
155
|
+
this.#runningEpoch = true
|
|
156
|
+
console.log('epoch');
|
|
157
|
+
const validators = await this.staticCall(addresses.validators, 'validators')
|
|
148
158
|
if (!validators[peernet.id]?.active) return
|
|
159
|
+
console.log('active');
|
|
149
160
|
|
|
150
|
-
|
|
161
|
+
|
|
151
162
|
const start = new Date().getTime()
|
|
152
|
-
|
|
163
|
+
try {
|
|
164
|
+
await this.#createBlock()
|
|
165
|
+
} catch (e) {
|
|
166
|
+
console.error(e);
|
|
167
|
+
}
|
|
168
|
+
|
|
153
169
|
const end = new Date().getTime()
|
|
154
|
-
console.log((end - start) / 1000 + ' s');
|
|
170
|
+
console.log(((end - start) / 1000) + ' s');
|
|
171
|
+
|
|
155
172
|
if (await this.hasTransactionToHandle()) return this.#runEpoch()
|
|
156
173
|
this.#runningEpoch = false
|
|
174
|
+
// if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
|
|
157
175
|
}
|
|
158
176
|
|
|
159
177
|
async #setup() {
|
|
160
|
-
await contractStore.put(
|
|
161
|
-
await contractStore.put(
|
|
162
|
-
await contractStore.put(
|
|
163
|
-
await contractStore.put(
|
|
178
|
+
await contractStore.put(addresses.contractFactory, contractFactoryMessage)
|
|
179
|
+
await contractStore.put(addresses.nativeToken, nativeTokenMessage)
|
|
180
|
+
await contractStore.put(addresses.validators, validatorsMessage)
|
|
181
|
+
await contractStore.put(addresses.nameService, nameServiceMessage)
|
|
164
182
|
console.log('handle native contracts');
|
|
165
183
|
// handle native contracts
|
|
166
184
|
}
|
|
@@ -179,7 +197,6 @@ export default class Chain {
|
|
|
179
197
|
|
|
180
198
|
promises = await Promise.allSettled(promises)
|
|
181
199
|
promises = promises.reduce((set, c) => {
|
|
182
|
-
console.log({c});
|
|
183
200
|
if (c.index > set.index) {
|
|
184
201
|
set.index = c.index
|
|
185
202
|
set.hash = c.hash
|
|
@@ -192,7 +209,8 @@ export default class Chain {
|
|
|
192
209
|
async #init() {
|
|
193
210
|
// this.node = await new Node()
|
|
194
211
|
this.participants = []
|
|
195
|
-
|
|
212
|
+
this.participating = false
|
|
213
|
+
const initialized = await contractStore.has(addresses.contractFactory)
|
|
196
214
|
if (!initialized) await this.#setup()
|
|
197
215
|
|
|
198
216
|
this.#machine = await new Machine()
|
|
@@ -202,7 +220,7 @@ export default class Chain {
|
|
|
202
220
|
let localBlock = await chainStore.get('lastBlock')
|
|
203
221
|
localBlock = await peernet.get(new TextDecoder().decode(localBlock))
|
|
204
222
|
localBlock = await await new BlockMessage(localBlock)
|
|
205
|
-
this.#lastBlock = {...localBlock.decoded, hash: localBlock.hash}
|
|
223
|
+
this.#lastBlock = {...localBlock.decoded, hash: await localBlock.hash}
|
|
206
224
|
// console.log(this.lastBlock.decoded.transactions);
|
|
207
225
|
} catch (e) {
|
|
208
226
|
await this.#sync()
|
|
@@ -218,15 +236,7 @@ export default class Chain {
|
|
|
218
236
|
|
|
219
237
|
peernet.subscribe('add-block', this.#addBlock.bind(this))
|
|
220
238
|
|
|
221
|
-
peernet.subscribe('add-transaction',
|
|
222
|
-
try {
|
|
223
|
-
transaction = await new TransactionMessage(transaction)
|
|
224
|
-
await transactionPoolStore.put(transaction.hash, transaction.encoded)
|
|
225
|
-
if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
|
|
226
|
-
} catch (e) {
|
|
227
|
-
throw Error('invalid transaction')
|
|
228
|
-
}
|
|
229
|
-
})
|
|
239
|
+
peernet.subscribe('add-transaction', this.#addTransaction.bind(this))
|
|
230
240
|
|
|
231
241
|
pubsub.subscribe('peer:connected', this.#peerConnected.bind(this))
|
|
232
242
|
|
|
@@ -260,27 +270,40 @@ export default class Chain {
|
|
|
260
270
|
const start = (this.#blocks.length) - blocksSynced
|
|
261
271
|
await this.#loadBlocks(this.#blocks)
|
|
262
272
|
const message = await new BlockMessage(this.lastBlock)
|
|
263
|
-
await blockStore.put(message.hash, message.encoded)
|
|
273
|
+
await blockStore.put(await message.hash, message.encoded)
|
|
264
274
|
await chainStore.put('lastBlock', new TextEncoder().encode(this.lastBlock.hash))
|
|
265
275
|
}
|
|
266
276
|
}
|
|
267
277
|
|
|
268
|
-
|
|
269
|
-
|
|
278
|
+
#epochTimeout
|
|
279
|
+
|
|
280
|
+
async #addTransaction(transaction) {
|
|
281
|
+
try {
|
|
282
|
+
transaction = await new TransactionMessage(transaction)
|
|
283
|
+
const has = await transactionPoolStore.has(await transaction.hash)
|
|
284
|
+
if (!has) await transactionPoolStore.put(await transaction.hash, transaction.encoded)
|
|
285
|
+
if (this.participating && !this.#runningEpoch) this.#runEpoch()
|
|
286
|
+
} catch (e) {
|
|
287
|
+
throw Error('invalid transaction')
|
|
270
288
|
}
|
|
289
|
+
}
|
|
271
290
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
291
|
+
async #lastBlockHandler() {
|
|
292
|
+
return new peernet.protos['peernet-response']({response: new TextEncoder().encode(JSON.stringify({ hash: this.lastBlock?.hash, index: this.lastBlock?.index }))})
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async resolveBlock(hash) {
|
|
296
|
+
let block = await peernet.get(hash, 'block')
|
|
297
|
+
if (!await peernet.has(hash, 'block')) await peernet.put(hash, block, 'block')
|
|
298
|
+
block = await new BlockMessage(block)
|
|
299
|
+
const size = block.encoded.length || block.encoded.byteLength
|
|
300
|
+
block = {...block.decoded, hash}
|
|
301
|
+
this.#blocks[block.index] = block
|
|
302
|
+
console.log(`loaded block: ${hash} @${block.index} ${formatBytes(size)}`);
|
|
303
|
+
if (block.index !== 0) {
|
|
304
|
+
return this.resolveBlock(block.previousHash)
|
|
283
305
|
}
|
|
306
|
+
}
|
|
284
307
|
|
|
285
308
|
async resolveBlocks() {
|
|
286
309
|
try {
|
|
@@ -360,15 +383,15 @@ export default class Chain {
|
|
|
360
383
|
// transaction = new TransactionMessage(transaction)
|
|
361
384
|
// return transaction
|
|
362
385
|
// }
|
|
363
|
-
await Promise.all(blockMessage.decoded.transactions
|
|
364
|
-
.map(transaction => transactionPoolStore.delete(transaction.hash)))
|
|
365
|
-
|
|
386
|
+
const deletions = await Promise.all(blockMessage.decoded.transactions
|
|
387
|
+
.map(async transaction => transactionPoolStore.delete(await transaction.hash)))
|
|
388
|
+
const hash = await blockMessage.hash
|
|
366
389
|
// let transactions = blockMessage.decoded.transactions.map(tx => transactionJob(tx))
|
|
367
390
|
// transactions = await Promise.all(transactions)
|
|
368
|
-
this.#lastBlock = {
|
|
369
|
-
await blockStore.put(
|
|
370
|
-
await chainStore.put('lastBlock', new TextEncoder().encode(
|
|
371
|
-
debug(`added block: ${
|
|
391
|
+
this.#lastBlock = { hash, ...blockMessage.decoded }
|
|
392
|
+
await blockStore.put(hash, blockMessage.encoded)
|
|
393
|
+
await chainStore.put('lastBlock', new TextEncoder().encode(hash))
|
|
394
|
+
debug(`added block: ${hash}`)
|
|
372
395
|
let promises = []
|
|
373
396
|
let contracts = []
|
|
374
397
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
@@ -379,7 +402,10 @@ export default class Chain {
|
|
|
379
402
|
}
|
|
380
403
|
try {
|
|
381
404
|
promises = await Promise.allSettled(promises)
|
|
382
|
-
|
|
405
|
+
for (let transaction of blockMessage.decoded.transactions) {
|
|
406
|
+
await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)))
|
|
407
|
+
}
|
|
408
|
+
|
|
383
409
|
// todo finish state
|
|
384
410
|
// for (const contract of contracts) {
|
|
385
411
|
// const state = await this.#machine.get(contract, 'state')
|
|
@@ -393,6 +419,10 @@ export default class Chain {
|
|
|
393
419
|
|
|
394
420
|
}
|
|
395
421
|
|
|
422
|
+
async #updateState() {
|
|
423
|
+
|
|
424
|
+
}
|
|
425
|
+
|
|
396
426
|
|
|
397
427
|
|
|
398
428
|
async participate() {
|
|
@@ -402,56 +432,72 @@ export default class Chain {
|
|
|
402
432
|
// introduce peer-reputation
|
|
403
433
|
// peerReputation(peerId)
|
|
404
434
|
// {bandwith: {up, down}, uptime}
|
|
405
|
-
|
|
406
|
-
if (await this.
|
|
435
|
+
this.participating = true
|
|
436
|
+
if (!await this.staticCall(addresses.validators, 'has', [peernet.id])) await this.createTransactionFrom(peernet.id, addresses.validators, 'addValidator', [peernet.id])
|
|
437
|
+
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch()
|
|
438
|
+
|
|
439
|
+
// const runEpoch = () => setTimeout(async () => {
|
|
440
|
+
// if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch()
|
|
441
|
+
// runEpoch()
|
|
442
|
+
// }, 5000)
|
|
443
|
+
// runEpoch()
|
|
407
444
|
}
|
|
408
445
|
|
|
409
446
|
calculateFee(transaction) {
|
|
410
447
|
// excluded from fees
|
|
411
|
-
if (transaction.decoded.to ===
|
|
448
|
+
// if (transaction.decoded.to === addresses.validators) return 0
|
|
412
449
|
// fee per gb
|
|
413
450
|
return (transaction.encoded.length / 1024) / 1e-6
|
|
414
451
|
}
|
|
415
452
|
|
|
453
|
+
async getTransactions (transactions) {
|
|
454
|
+
return new Promise(async (resolve, reject) => {
|
|
455
|
+
let size = 0
|
|
456
|
+
const _transactions = []
|
|
457
|
+
const promises = await Promise.all(Object.values(transactions)
|
|
458
|
+
.map(tx => new TransactionMessage(new Uint8Array(tx, tx.byteOffset, tx.byteLength))))
|
|
459
|
+
|
|
460
|
+
for (let transaction of promises) {
|
|
461
|
+
size += transaction.encoded.length
|
|
462
|
+
if ((size / 1024) / 1024 <= 1.15 ) _transactions.push({...transaction.decoded, hash: await transaction.hash })
|
|
463
|
+
else return resolve(_transactions)
|
|
464
|
+
|
|
465
|
+
}
|
|
466
|
+
return resolve(_transactions)
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
}
|
|
416
470
|
async #createBlock() {
|
|
417
471
|
let transactions = await transactionPoolStore.get()
|
|
418
472
|
|
|
419
473
|
if (Object.keys(transactions)?.length === 0 ) return
|
|
474
|
+
|
|
420
475
|
let block = {
|
|
421
476
|
transactions: [],
|
|
422
477
|
validators: [],
|
|
423
478
|
fees: 0
|
|
424
479
|
}
|
|
425
480
|
|
|
426
|
-
let _transactions = []
|
|
427
|
-
|
|
428
481
|
// exclude failing tx
|
|
429
|
-
|
|
430
|
-
transaction = await new TransactionMessage(new Uint8Array(transaction, transaction.byteOffset, transaction.byteLength))
|
|
482
|
+
transactions = await this.getTransactions(transactions)
|
|
431
483
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
transactions = _transactions.sort((a, b) => a.nonce - b.nonce)
|
|
437
|
-
_transactions = []
|
|
438
|
-
for (let transaction of transactions) {
|
|
484
|
+
transactions = transactions.sort((a, b) => a.nonce - b.nonce)
|
|
485
|
+
for (let transaction of transactions) {
|
|
439
486
|
try {
|
|
440
487
|
await this.#executeTransaction(transaction)
|
|
441
|
-
|
|
488
|
+
block.transactions.push(transaction)
|
|
489
|
+
block.fees += Number(calculateFee(transaction))
|
|
490
|
+
await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)))
|
|
442
491
|
} catch (e) {
|
|
492
|
+
console.error(e)
|
|
443
493
|
transaction = await new TransactionMessage(transaction)
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
494
|
+
await transactionPoolStore.delete(await transaction.hash)
|
|
495
|
+
console.log(e);
|
|
447
496
|
}
|
|
448
497
|
}
|
|
449
|
-
transactions = _transactions
|
|
450
498
|
// don't add empty block
|
|
451
|
-
if (transactions.length === 0) return
|
|
452
|
-
|
|
453
|
-
block.transactions = transactions
|
|
454
|
-
const validators = await this.staticCall(lib.validators, 'validators')
|
|
499
|
+
if (block.transactions.length === 0) return
|
|
500
|
+
const validators = await this.staticCall(addresses.validators, 'validators')
|
|
455
501
|
console.log({validators});
|
|
456
502
|
// block.validators = Object.keys(block.validators).reduce((set, key) => {
|
|
457
503
|
// if (block.validators[key].active) {
|
|
@@ -492,7 +538,7 @@ export default class Chain {
|
|
|
492
538
|
|
|
493
539
|
}
|
|
494
540
|
|
|
495
|
-
console.log(block.validators);
|
|
541
|
+
console.log({validators: block.validators});
|
|
496
542
|
|
|
497
543
|
block.reward = 150
|
|
498
544
|
block.validators = block.validators.map(validator => {
|
|
@@ -500,7 +546,7 @@ export default class Chain {
|
|
|
500
546
|
delete validator.bw
|
|
501
547
|
return validator
|
|
502
548
|
})
|
|
503
|
-
// block.validators =
|
|
549
|
+
// block.validators = calculateValidatorReward(block.validators, block.fees)
|
|
504
550
|
|
|
505
551
|
block.index = this.lastBlock?.index
|
|
506
552
|
if (block.index === undefined) block.index = 0
|
|
@@ -525,21 +571,44 @@ export default class Chain {
|
|
|
525
571
|
|
|
526
572
|
try {
|
|
527
573
|
let blockMessage = await new BlockMessage(block)
|
|
528
|
-
|
|
574
|
+
const hash = await blockMessage.hash
|
|
575
|
+
await Promise.all(blockMessage.decoded.transactions
|
|
576
|
+
.map(async transaction => transactionPoolStore.delete(await transaction.hash)))
|
|
577
|
+
|
|
578
|
+
this.#lastBlock = { hash, ...blockMessage.decoded }
|
|
579
|
+
await blockStore.put(hash, blockMessage.encoded)
|
|
580
|
+
await chainStore.put('lastBlock', new TextEncoder().encode(hash))
|
|
581
|
+
debug(`created block: ${hash}`)
|
|
582
|
+
|
|
529
583
|
peernet.publish('add-block', blockMessage.encoded)
|
|
530
|
-
this.#
|
|
584
|
+
this.#updateState(blockMessage)
|
|
531
585
|
} catch (e) {
|
|
586
|
+
console.log(e);
|
|
532
587
|
throw Error(`invalid block ${block}`)
|
|
533
588
|
}
|
|
534
589
|
// data = await this.#machine.execute(to, method, params)
|
|
535
590
|
// transactionStore.put(message.hash, message.encoded)
|
|
536
591
|
}
|
|
537
592
|
|
|
538
|
-
async
|
|
593
|
+
async promiseTransactions(transactions) {
|
|
594
|
+
transactions = await Promise.all(transactions.map(tx => new TransactionMessage(tx)))
|
|
595
|
+
return transactions
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
async promiseTransactionsContent(transactions) {
|
|
599
|
+
transactions = await Promise.all(transactions.map(tx => new Promise(async (resolve, reject) => {
|
|
600
|
+
resolve({ ...tx.decoded, hash: await tx.hash })
|
|
601
|
+
})))
|
|
602
|
+
|
|
603
|
+
return transactions
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
async #getNonceFallback(address) {
|
|
539
607
|
let transactions = await transactionPoolStore.get()
|
|
540
|
-
transactions =
|
|
608
|
+
transactions = await this.promiseTransactions(Object.values(transactions))
|
|
541
609
|
transactions = transactions.filter(tx => tx.decoded.from === address)
|
|
542
|
-
transactions =
|
|
610
|
+
transactions = await this.promiseTransactionsContent(transactions)
|
|
611
|
+
|
|
543
612
|
if (this.lastBlock && transactions.length === 0) {
|
|
544
613
|
let block = await peernet.get(this.lastBlock.hash)
|
|
545
614
|
block = await new BlockMessage(block)
|
|
@@ -562,6 +631,16 @@ export default class Chain {
|
|
|
562
631
|
return transactions[transactions.length - 1].nonce
|
|
563
632
|
}
|
|
564
633
|
|
|
634
|
+
async getNonce(address) {
|
|
635
|
+
if (!await accountsStore.has(address)) {
|
|
636
|
+
const nonce = await this.#getNonceFallback(address)
|
|
637
|
+
await accountsStore.put(address, new TextEncoder().encode(String(nonce)))
|
|
638
|
+
}
|
|
639
|
+
let nonce = await accountsStore.get(address)
|
|
640
|
+
nonce = new TextDecoder().decode(nonce)
|
|
641
|
+
return Number(nonce)
|
|
642
|
+
}
|
|
643
|
+
|
|
565
644
|
/**
|
|
566
645
|
* whenever method = createContract params should hold the contract hash
|
|
567
646
|
*
|
|
@@ -573,9 +652,74 @@ export default class Chain {
|
|
|
573
652
|
* @param {Array} params - array of paramters to apply to the contract method
|
|
574
653
|
* @param {Number} nonce - total transaction count [optional]
|
|
575
654
|
*/
|
|
576
|
-
createTransaction(to, method, params, nonce) {
|
|
655
|
+
async createTransaction(to, method, params, nonce, signature) {
|
|
577
656
|
return this.createTransactionFrom(peernet.id, to, method, params, nonce)
|
|
578
657
|
}
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
*
|
|
663
|
+
* @param {Object} transaction {}
|
|
664
|
+
* @param {String} transaction.from address
|
|
665
|
+
* @param {String} transaction.to address
|
|
666
|
+
* @param {Object} transaction.params {}
|
|
667
|
+
* @param {String} transaction.params.method get, call
|
|
668
|
+
* @param {Buffer} transaction.params.data
|
|
669
|
+
* @returns
|
|
670
|
+
*/
|
|
671
|
+
async createTransactionHash(transaction) {
|
|
672
|
+
// todo: validate
|
|
673
|
+
const peernetHash = await new CodecHash(transaction, {name: 'transaction-message'})
|
|
674
|
+
return peernetHash.digest
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* @params {object} transaction -
|
|
679
|
+
* @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
|
|
680
|
+
*/
|
|
681
|
+
async #signTransaction (transaction, wallet) {
|
|
682
|
+
return wallet.sign(await this.createTransactionHash(transaction))
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
async signTransaction(transaction, signer) {
|
|
686
|
+
let identity = await walletStore.get('identity')
|
|
687
|
+
identity = JSON.parse(new TextDecoder().decode(identity))
|
|
688
|
+
const wallet = new MultiWallet(peernet.network)
|
|
689
|
+
wallet.recover(identity.mnemonic)
|
|
690
|
+
const account = wallet.account(0).external(0)
|
|
691
|
+
transaction.signature = await this.#signTransaction(transaction, wallet)
|
|
692
|
+
transaction.signature = bs32.encode(transaction.signature)
|
|
693
|
+
return transaction
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
*
|
|
698
|
+
* @param {Object} transaction
|
|
699
|
+
* @param {Address} transaction.from
|
|
700
|
+
* @param {Address} transaction.to
|
|
701
|
+
* @param {String} transaction.method
|
|
702
|
+
* @param {Array} transaction.params
|
|
703
|
+
* @param {Number} transaction.nonce
|
|
704
|
+
*
|
|
705
|
+
* @returns {Object} transaction
|
|
706
|
+
*/
|
|
707
|
+
async createRawTransaction(transaction) {
|
|
708
|
+
if (!transaction.from) transaction.from = peernet.id
|
|
709
|
+
transaction.timestamp = Date.now()
|
|
710
|
+
|
|
711
|
+
if (transaction.nonce === undefined) {
|
|
712
|
+
transaction.nonce = await this.getNonce(transaction.from)
|
|
713
|
+
transaction.nonce += 1
|
|
714
|
+
await accountsStore.put(transaction.from, new TextEncoder().encode(String(transaction.nonce)))
|
|
715
|
+
} else {
|
|
716
|
+
let nonce = await accountsStore.get(transaction.from)
|
|
717
|
+
nonce = new TextDecoder().decode(nonce)
|
|
718
|
+
if (transaction.nonce < nonce) throw Error(`a transaction with a higher nonce already exists`)
|
|
719
|
+
if (transaction.nonce === nonce) throw Error(`a transaction with the same nonce already exists`)
|
|
720
|
+
}
|
|
721
|
+
return transaction
|
|
722
|
+
}
|
|
579
723
|
/**
|
|
580
724
|
* every tx done is trough contracts so no need for amount
|
|
581
725
|
* data is undefined when nothing is returned
|
|
@@ -588,31 +732,41 @@ export default class Chain {
|
|
|
588
732
|
* @param {Number} nonce - total transaction count [optional]
|
|
589
733
|
*/
|
|
590
734
|
async createTransactionFrom(from, to, method, params, nonce) {
|
|
591
|
-
if (nonce === undefined) {
|
|
592
|
-
nonce = await this.getNonce(from)
|
|
593
|
-
nonce += 1
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
let data
|
|
597
|
-
let message = await new TransactionMessage({timestamp: new Date().getTime(), from, to, nonce, method, params})
|
|
598
735
|
try {
|
|
736
|
+
|
|
737
|
+
const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params})
|
|
738
|
+
const transaction = await this.signTransaction(rawTransaction, from)
|
|
739
|
+
const message = await new TransactionMessage(transaction)
|
|
740
|
+
|
|
741
|
+
let data
|
|
599
742
|
// await transactionPoolStore.put(message.hash, new TextEncoder().encode(JSON.stringify({signature, message: message.encoded})))
|
|
600
|
-
|
|
743
|
+
const wait = () => new Promise(async (resolve, reject) => {
|
|
744
|
+
if (pubsub.subscribers[`transaction.completed.${await message.hash}`]) {
|
|
745
|
+
const result = pubsub.subscribers[`transaction.completed.${await message.hash}`].value
|
|
746
|
+
result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error})
|
|
747
|
+
} else {
|
|
748
|
+
const completed = async result => {
|
|
749
|
+
result.status === 'fulfilled' ? resolve(await result.hash) : reject({hash: await result.hash, error: result.error})
|
|
750
|
+
|
|
751
|
+
setTimeout(async () => {
|
|
752
|
+
pubsub.unsubscribe(`transaction.completed.${await message.hash}`, completed)
|
|
753
|
+
}, 10000)
|
|
754
|
+
}
|
|
755
|
+
pubsub.subscribe(`transaction.completed.${await message.hash}`, completed)
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
})
|
|
760
|
+
|
|
761
|
+
await transactionPoolStore.put(await message.hash, message.encoded)
|
|
601
762
|
peernet.publish('add-transaction', message.encoded)
|
|
763
|
+
this.#addTransaction(message.encoded)
|
|
764
|
+
return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
|
|
602
765
|
} catch (e) {
|
|
766
|
+
console.log(e);
|
|
603
767
|
throw e
|
|
604
768
|
}
|
|
605
|
-
|
|
606
|
-
const completed = result => {
|
|
607
|
-
result.status === 'fulfilled' ? resolve(result.hash) : reject({hash: result.hash, error: result.error})
|
|
608
|
-
|
|
609
|
-
pubsub.unsubscribe(`transaction.completed.${message.hash}`, completed)
|
|
610
|
-
}
|
|
611
|
-
pubsub.subscribe(`transaction.completed.${message.hash}`, completed)
|
|
612
|
-
})
|
|
613
|
-
|
|
614
|
-
if (await this.hasTransactionToHandle() && !this.#runningEpoch) this.#runEpoch()
|
|
615
|
-
return {hash: message.hash, data, fee: lib.calculateFee(message), wait}
|
|
769
|
+
|
|
616
770
|
}
|
|
617
771
|
|
|
618
772
|
async createContractMessage(creator, contract, constructorParameters = []) {
|
|
@@ -638,7 +792,7 @@ export default class Chain {
|
|
|
638
792
|
const hash = await this.createContractAddress(creator, contract, params)
|
|
639
793
|
|
|
640
794
|
try {
|
|
641
|
-
const tx = await this.createTransactionFrom(peernet.id,
|
|
795
|
+
const tx = await this.createTransactionFrom(peernet.id, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters])
|
|
642
796
|
} catch (e) {
|
|
643
797
|
throw e
|
|
644
798
|
}
|
|
@@ -685,15 +839,15 @@ export default class Chain {
|
|
|
685
839
|
}
|
|
686
840
|
|
|
687
841
|
mint(to, amount) {
|
|
688
|
-
return this.call(
|
|
842
|
+
return this.call(addresses.nativeToken, 'mint', [to, amount])
|
|
689
843
|
}
|
|
690
844
|
|
|
691
845
|
transfer(from, to, amount) {
|
|
692
|
-
return this.call(
|
|
846
|
+
return this.call(addresses.nativeToken, 'transfer', [from, to, amount])
|
|
693
847
|
}
|
|
694
848
|
|
|
695
849
|
get balances() {
|
|
696
|
-
return this.staticCall(
|
|
850
|
+
return this.staticCall(addresses.nativeToken, 'balances')
|
|
697
851
|
}
|
|
698
852
|
|
|
699
853
|
deleteAll() {
|
|
@@ -710,28 +864,28 @@ export default class Chain {
|
|
|
710
864
|
* @example chain.lookup('myCoolContractName') // qmqsfddfdgfg...
|
|
711
865
|
*/
|
|
712
866
|
lookup(name) {
|
|
713
|
-
return this.call(
|
|
867
|
+
return this.call(addresses.nameService, 'lookup', [name])
|
|
714
868
|
}
|
|
715
869
|
}
|
|
716
|
-
</code></pre>
|
|
717
|
-
</article>
|
|
718
|
-
</section>
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
</div>
|
|
724
|
-
|
|
725
|
-
<br class="clear">
|
|
726
|
-
|
|
727
|
-
<footer>
|
|
728
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.
|
|
729
|
-
</footer>
|
|
730
|
-
|
|
731
|
-
<script src="scripts/linenumber.js"></script>
|
|
732
|
-
<script src="scripts/pagelocation.js"></script>
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
</body>
|
|
737
|
-
</html>
|
|
870
|
+
</code></pre>
|
|
871
|
+
</article>
|
|
872
|
+
</section>
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
</div>
|
|
878
|
+
|
|
879
|
+
<br class="clear">
|
|
880
|
+
|
|
881
|
+
<footer>
|
|
882
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a>
|
|
883
|
+
</footer>
|
|
884
|
+
|
|
885
|
+
<script src="scripts/linenumber.js"></script>
|
|
886
|
+
<script src="scripts/pagelocation.js"></script>
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
</body>
|
|
891
|
+
</html>
|