-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
820 lines (677 loc) · 27 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
<!DOCTYPE HTML>
<head>
<meta charset="utf-8">
<meta content='user-scalable=no, initial-scale=1, width=device-width' id='viewport' name='viewport'>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://cdn.jsdelivr.net/npm/yandex-metrica-watch/tag.js", "ym");
ym(55957516, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/55957516" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<script src = "https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src = "http://www.webglearth.com/v2/api.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/mathjs/6.2.2/math.min.js"></script>
<script src = "https://unpkg.com/[email protected]/dist/3d-force-graph.min.js" async></script>
<script src = "./js/dat.gui.min.js" ></script>
<script src = "./js/dialog.js" ></script>
<script src = "https://code.jquery.com/jquery-1.7.1.min.js" ></script>
<link rel = "icon" type="image/png" href="./img/favicon.png" sizes = "any" >
<link href = "./css/style.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Electrolize&display=swap" rel="stylesheet">
<link href = "https://use.fontawesome.com/releases/v5.1.0/css/all.css" type="text/css" rel="stylesheet"/>
<script>
var viewPortScale = 1 / window.devicePixelRatio;
$('#viewport').attr('content', 'user-scalable=yes, initial-scale='+viewPortScale+', width=device-width');
</script>
</head>
<body>
<canvas id="c"></canvas>
<div id = "vmx" v-cloak>
<div class = "hedfoot" style = "height: 60px; top:0; font-size:40px;">
<div id = "bot1" style = "width:40px;"></div>
<div class = "point" onclick="swit(1)" style = "margin-left:50px"><i class="fas fa-cogs"></i></div>
<div style="min-width: 500px;"><b>C O N T R A C T O R</b></div>
<div class = "point" onclick="swit(0)" style = "margin-right:50px"><i class="fas fa-globe"></i></div>
<div id = "bot2" style = "width:40px;"></div>
</div>
<div class="tabcontent">
<div id="map"></div>
<div class = "link point" onclick = "initButton()" style="top:10px;right:10px;">ASK ORACLE WHERE SANTA?</div>
<div class = "link point" style="bottom:20px; right:10px;" onclick="hnytok()">ADD TOKEN</div>
<div id = "hold" class = "link" style="bottom:20px; left:10px;" v-html="hold"></div>
<div class = "link" style="top:10px; left:10px;">ACCOUNT:
<span id = "meta" ></span>
</div>
</div>
<div class="tabcontent">
<div style = " background-color: rgb(1, 32, 1); width: 1000px; margin-left:calc(50% - 500px); height: calc(100vh - 90px); display: flex; align-items: center; justify-content: center;">
<div style = "background-color: rgb(1, 32, 1); width:1000px;margin-top:auto;margin-bottom: auto;">
<u>BUILD REAL-WORLD SMART CONTRACT</u> <br><br>
Select type of smart contract:
<select v-model="type">
<option v-for="con in contracts" v-bind:value="con.n">{{con.name}}</option>
</select>
<span class="point" onclick="modalv('#quest')">?</span>
<br><br>
Select Ethereum Network:
<select v-model="net">
<option v-for="n in nets" v-bind:value="n">{{n}}</option>
</select>
Cost: {{ (oracle.length * pars(urls).length)/cost[net] }} LINK per Answer
<br><br>
Select one or more Oracles:
<select v-model="oracle" multiple style="height: 90px; ">
<option v-for="or in oracles[net]" v-bind:value="or.o">{{or.n}} {{or.o}}</option>
</select>
<br><br>
<div v-if = "type == 1">
Enter Client Address :
<input placeholder="Ethereum Address" v-model = "client" style = "width:640px;height: 23px;" ></input>
<br><br>
Enter Provider Address :
<input placeholder="Ethereum Address" v-model = "provider" style = "width:640px;height: 23px;" ></input>
<br><br>
</div>
Enter API Sources :
<textarea wrap="off" placeholder="API urls separated by comma" v-model = "urls" ></textarea>
<br><br>
Enter JSON paths :
<textarea wrap="off" placeholder="Pathes separated by comma" v-model = "pathes" ></textarea>
<div class = "point" onclick="test()" style = "margin-left:130px; margin-top:20px; width:100px; height: 23px; border: 3px double yellowgreen;">T E S T</div>
<div style = "margin-left:175px; margin-top:-29px;"><textarea disabled placeholder="Response">{{result}}</textarea></div>
<br>
<!--
Select method:
<select v-model="http">
<option v-for="h in https" v-bind:value="h">{{h}}</option>
</select>
-->
Select Aggregation Method:
<select v-model="agr">
<option v-for="a in agrig" v-bind:value="a">{{a}}</option>
</select>
Enter Multiplier: <input placeholder="Integer Number" v-model = "multi" style = "width:80px;height: 23px;" ></input>
Enter Min Responses: <input placeholder="Integer Number" v-model = "count" style = "width:80px;height: 23px;" ></input>
<br>
<div v-if = "type == 1">
<br>
Condition:
<select v-model="cond" style="height: 23px; width: 50px; ">
<option v-for="c in conds" v-bind:value="c" >{{c}}</option>
</select>
Enter Threshold: <input placeholder="Integer Number" v-model = "threshold" style = "width:160px;height: 23px;" ></input>
Enter Expiration Time: <input placeholder="in seconds" v-model = "time" style = "width:160px;height: 23px;" ></input>
</div>
<br>
Select additional features:
<select v-model="feat" multiple style="height: 90px; ">
<option v-for="fe in features" v-bind:value="fe.n" >{{fe.f}}</option>
</select>
<br><br>
<div>
<div class = "point but" onclick="code(0)" >C O D E</div>
<div class = "point but" onclick="demo()" >D E M O</div>
<div class = "point but" onclick="graph()" >G R A P H</div>
</div>
</div>
</div>
</div>
<div class="tabcontent">
<div style = "background-color: rgb(1, 32, 1); width: 1000px; margin-left:calc(50% - 500px); height: calc(100vh - 90px); display: flex; align-items: center; justify-content: center;">
<div style = "background-color: rgb(1, 32, 1); width:1000px;margin-top:auto;margin-bottom: auto;">
<div class = "point" onclick = "window.open('https://t.me/contractstatebot')">JOIN to THE CONTRACT STATE BOT</div>
<br><br>
<div style = "width:500px; margin-left:calc(50% - 250px)">
This bot tracks smart contracts state, notifies if the state is changed and shows changed values (Contract Storage). In additionally, it shows LINK token info and current gas price.
</div>
<br><br>
<img style = "width:300px" src = "./img/statebot.jpg"/>
</div>
</div>
</div>
<dialog id = "graph">
<div id="dg" style = "display: flex; justify-content: center;"></div>
<div style="width:30px; position: absolute; right: 5px; top: 5px; font-size: 25px;" onclick = "modalx('#graph')" class="point">✗</div>
</dialog>
<dialog id = "quest">
<div style="position:sticky; text-align:right; top:5px; font-size: 25px;">
<span style = "margin-left:770px;" onclick = "modalx('#quest')" class="point">✗</span>
</div>
<div style="text-align: left; ">
<span v-if = "type == 0">
The contract calculates median or mean from aggregate data, using decentralized Oracles Network and different APIs sources.
Use this contract for creating requests to multiple Chainlink nodes and APIs providers and running aggregation as the contract receives answers.
<br>
Parametrs:
<br>
* Min Responses is the minimum number of responses before an answer will be calculated;<br>
* Multiplier parses the input into a float and then multiplies it by the 'Multiplier' field.
</span>
<span v-if = "type == 1">
When the contract is deployed a client, provider, and start time are specified.
Additionally a deposit is made. The end of the contract is set by the 'Expiration Time' field in seconds after the start time.
After the contract is created, resolved addresses can request updates from the oracle for the contract.
If the oracle reports that the condition set by 'Condition' and 'Threshold' fields is true then the deposit is released to the client.
If the condition is still false after the contract ends, and the deposit has not been released, the deposit is sent to the provider.
</span>
</div>
</dialog>
<dialog id = "code">
<div style="position:sticky; text-align:right; top:5px; font-size: 25px;">
<span style = "background-color: darkgrey;color:black"><span v-if = "demo == 0" > SOLIDITY CODE </span>
<span v-else class = 'point' onclick = "gits()"> DEPLOY CONTRACT </span>
</span>
<span style = "margin-left:250px;" onclick = "modalx('#code')" class="point">✗</span></div>
<div style="text-align: left; white-space: pre; overflow-x:auto;">
<span v-if = "type == 0">
pragma solidity 0.4.24;
// Use {{net}} Test Network to deploy this smart contract.
import "https://github.com/smartcontractkit/chainlink/evm/contracts/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm/contracts/vendor/SignedSafeMath.sol";
import "https://github.com/smartcontractkit/chainlink/evm/contracts/vendor/Ownable.sol";
contract AggregatorMultiSources is ChainlinkClient, Ownable {
using SignedSafeMath for int256;
struct Answer {
uint128 minimumResponses;
uint128 maxResponses;
int256[] responses;
}
event ResponseReceived(int256 indexed response, uint256 indexed answerId, address indexed sender);
event AnswerUpdated(int256 indexed current, uint256 indexed answerId);
int256 public currentAnswer;
uint256 public latestCompletedAnswer;
uint256 public updatedHeight;
uint256 private paymentAmount = 1 * LINK / {{cost[net]}};
uint128 public minimumResponses = {{count}};
string[] private jobIds = {{jobs}};
address[] private oracles = {{JSON.stringify(oracle).replace(/"/g,'')}};
string[] private urls = {{pars(urls)}};
string[] private path ={{pars(pathes)}};
uint256 private answerCounter = 1;
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">mapping(address => bool) public authorizedRequesters;</span>
mapping(bytes32 => uint256) private requestAnswers;
mapping(uint256 => Answer) private answers;
constructor()
public Ownable() {
setPublicChainlinkToken();
}
//Creates a Chainlink request for each oracle in the oracles array.
function requestRateUpdate()
external
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">ensureAuthorizedRequester()</span>
<span v-if = "feat.indexOf(1) == -1 && feat.indexOf(4) == -1">onlyOwner()</span>
{
Chainlink.Request memory request;
bytes32 requestId;
uint256 oraclePayment = paymentAmount;
for (uint j = 0; j < urls.length; j++) {
for (uint i = 0; i < oracles.length; i++) {
request = buildChainlinkRequest(stringToBytes32(jobIds[i]), this, this.chainlinkCallback.selector);
request.add("get", urls[j]);
request.add("path", path[j]);
request.addInt("times", {{multi}});
requestId = sendChainlinkRequestTo(oracles[i], request, oraclePayment);
requestAnswers[requestId] = answerCounter;
}
}
answers[answerCounter].minimumResponses = minimumResponses;
answers[answerCounter].maxResponses = uint128(oracles.length * urls.length);
answerCounter = answerCounter.add(1);
}
//Receives the answer from the Chainlink node.
function chainlinkCallback(bytes32 _clRequestId, int256 _response)
external
{
validateChainlinkCallback(_clRequestId);
uint256 answerId = requestAnswers[_clRequestId];
delete requestAnswers[_clRequestId];
answers[answerId].responses.push(_response);
emit ResponseReceived(_response, answerId, msg.sender);
updateLatestAnswer(answerId);
deleteAnswer(answerId);
}
<span v-if = "feat.indexOf(3) != -1">
// Allows the owner of the contract to withdraw any LINK balance.
function transferLINK(address _recipient, uint256 _amount)
public
onlyOwner()
{
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(_recipient, _amount), "LINK transfer failed");
}
</span>
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">
// Called by the owner to permission other addresses to generate new.
function setAuthorization(address _requester, bool _allowed)
external
onlyOwner()
{
authorizedRequesters[_requester] = _allowed;
}
</span>
<span v-if = "feat.indexOf(2) != -1">
// Called by the owner to destroy the contract. This transfers all LINK and ETH balance.
function destroy()
external
onlyOwner()
{
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
transferLINK(owner, link.balanceOf(address(this)));
selfdestruct(owner);
}
</span>
//Performs aggregation (mean, mode or median) of the answers received from the Chainlink nodes.
function updateLatestAnswer(uint256 _answerId)
private
ensureMinResponsesReceived(_answerId)
ensureOnlyLatestAnswer(_answerId)
{<span v-if = "agr == 'Median'">
uint256 responseLength = answers[_answerId].responses.length;
uint256 middleIndex = responseLength.div(2);
if (responseLength % 2 == 0) {
int256 median1 = quickselect(answers[_answerId].responses, middleIndex);
int256 median2 = quickselect(answers[_answerId].responses, middleIndex.add(1));
currentAnswer = median1.add(median2) / 2;
} else {
currentAnswer = quickselect(answers[_answerId].responses, middleIndex.add(1));
}
</span>
<span v-else>
currentAnswer = meanAgr(answers[_answerId].responses);
</span>
latestCompletedAnswer = _answerId;
updatedHeight = block.number;
emit AnswerUpdated(currentAnswer, _answerId);
}
<span v-if = "agr == 'Median'">
//MEDIAN
function quickselect(int256[] memory _a, uint256 _k)
private
pure
returns (int256)
{
int256[] memory a = _a;
uint256 k = _k;
uint256 aLen = a.length;
int256[] memory a1 = new int256[](aLen);
int256[] memory a2 = new int256[](aLen);
uint256 a1Len;
uint256 a2Len;
int256 pivot;
uint256 i;
while (true) {
pivot = a[aLen.div(2)];
a1Len = 0;
a2Len = 0;
for (i = 0; i < aLen; i++) {
if (a[i] < pivot) {
a1[a1Len] = a[i];
a1Len++;
} else if (a[i] > pivot) {
a2[a2Len] = a[i];
a2Len++;
}
}
if (k <= a1Len) {
aLen = a1Len;
(a, a1) = swap(a, a1);
} else if (k > (aLen.sub(a2Len))) {
k = k.sub(aLen.sub(a2Len));
aLen = a2Len;
(a, a2) = swap(a, a2);
} else {
return pivot;
}
}
}
</span>
<span v-else>
//MEAN
function meanAgr(int256[] memory _a)
private
pure
returns (int256)
{
int256[] memory a = _a;
int256 mean = 0;
int256 q = 0;
for (uint i = 0; i < a.length; i++) {
mean += a[i];
q++;
}
mean = mean / q;
return mean;
}
</span>
//Prevents taking an action if the minimum number of responses has not been received for an answer.
modifier ensureMinResponsesReceived(uint256 _answerId) {
if (answers[_answerId].responses.length >= answers[_answerId].minimumResponses) {
_;
}
}
// Prevents taking an action if a newer answer has been recorded.
modifier ensureOnlyLatestAnswer(uint256 _answerId) {
if (latestCompletedAnswer <= _answerId) {
_;
}
}
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">
// Reverts if `msg.sender` is not authorized to make requests.
modifier ensureAuthorizedRequester() {
require(authorizedRequesters[msg.sender] || msg.sender == owner, "Not an authorized address for creating requests");
_;
}
</span>
//Prevents taking an action if not all responses are received for an answer.
modifier ensureAllResponsesReceived(uint256 _answerId) {
if (answers[_answerId].responses.length == answers[_answerId].maxResponses) {
_;
}
}
//Swaps the pointers to two uint256 arrays in memory
function swap(int256[] memory _a, int256[] memory _b)
private
pure
returns(int256[] memory, int256[] memory)
{
return (_b, _a);
}
//Cleans up the answer record if all responses have been received.
function deleteAnswer(uint256 _answerId)
private
ensureAllResponsesReceived(_answerId)
{
delete answers[_answerId];
}
//Convert JobId string to byte32
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly {
result := mload(add(source, 32))
}
}
}
</span>
<!--SLA CONTRACT-->
<span v-if = "type == 1">
pragma solidity 0.4.24;
// Use {{net}} Test Network to deploy this smart contract.
import "https://github.com/smartcontractkit/chainlink/evm/contracts/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/evm/contracts/vendor/SignedSafeMath.sol";
import "https://github.com/smartcontractkit/chainlink/evm/contracts/vendor/Ownable.sol";
contract AggregatorMultiSources is ChainlinkClient, Ownable {
using SignedSafeMath for int256;
struct Answer {
uint128 minimumResponses;
uint128 maxResponses;
int256[] responses;
}
event ResponseReceived(int256 indexed response, uint256 indexed answerId, address indexed sender);
event AnswerUpdated(int256 indexed current, uint256 indexed answerId);
address private client = {{client}};
address private provider = {{provider}} ;
uint256 public endAt = block.timestamp.add({{time}});// contract expiration time
int256 constant public threshold = {{threshold}};
int256 public currentAnswer;
uint256 public latestCompletedAnswer;
uint256 public updatedHeight;
uint256 private paymentAmount = 1 * LINK / {{cost[net]}};
uint128 public minimumResponses = {{count}};
string[] private jobIds = {{jobs}};
address[] private oracles = {{JSON.stringify(oracle).replace(/"/g,'')}};
string[] private urls = {{pars(urls)}};
string[] private path ={{pars(pathes)}};
uint256 private answerCounter = 1;
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">mapping(address => bool) public authorizedRequesters;</span>
mapping(bytes32 => uint256) private requestAnswers;
mapping(uint256 => Answer) private answers;
constructor()
public Ownable() {
setPublicChainlinkToken();
}
//Creates a Chainlink request for each oracle in the oracles array.
function requestRateUpdate()
external
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">ensureAuthorizedRequester()</span>
<span v-if = "feat.indexOf(1) == -1 && feat.indexOf(4) == -1">onlyOwner()</span>
{
Chainlink.Request memory request;
bytes32 requestId;
uint256 oraclePayment = paymentAmount;
for (uint j = 0; j < urls.length; j++) {
for (uint i = 0; i < oracles.length; i++) {
request = buildChainlinkRequest(stringToBytes32(jobIds[i]), this, this.chainlinkCallback.selector);
request.add("get", urls[j]);
request.add("path", path[j]);
request.addInt("times", {{multi}});
requestId = sendChainlinkRequestTo(oracles[i], request, oraclePayment);
requestAnswers[requestId] = answerCounter;
}
}
answers[answerCounter].minimumResponses = minimumResponses;
answers[answerCounter].maxResponses = uint128(oracles.length * urls.length);
answerCounter = answerCounter.add(1);
}
//Receives the answer from the Chainlink node.
function chainlinkCallback(bytes32 _clRequestId, int256 _response)
external
{
validateChainlinkCallback(_clRequestId);
uint256 answerId = requestAnswers[_clRequestId];
delete requestAnswers[_clRequestId];
answers[answerId].responses.push(_response);
emit ResponseReceived(_response, answerId, msg.sender);
updateLatestAnswer(answerId);
deleteAnswer(answerId);
}
<span v-if = "feat.indexOf(3) != -1">
// Allows the owner of the contract to withdraw any LINK balance.
function transferLINK(address _recipient, uint256 _amount)
public
onlyOwner()
{
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(_recipient, _amount), "LINK transfer failed");
}
</span>
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">
// Called by the owner to permission other addresses to generate new.
function setAuthorization(address _requester, bool _allowed)
external
onlyOwner()
{
authorizedRequesters[_requester] = _allowed;
}
</span>
<span v-if = "feat.indexOf(2) != -1">
// Called by the owner to destroy the contract. This transfers all LINK and ETH balance.
function destroy()
external
onlyOwner()
{
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
transferLINK(owner, link.balanceOf(address(this)));
selfdestruct(owner);
}
</span>
//Performs aggregation (mean, mode or median) of the answers received from the Chainlink nodes.
function updateLatestAnswer(uint256 _answerId)
private
ensureMinResponsesReceived(_answerId)
ensureOnlyLatestAnswer(_answerId)
{<span v-if = "agr == 'Median'">
uint256 responseLength = answers[_answerId].responses.length;
uint256 middleIndex = responseLength.div(2);
if (responseLength % 2 == 0) {
int256 median1 = quickselect(answers[_answerId].responses, middleIndex);
int256 median2 = quickselect(answers[_answerId].responses, middleIndex.add(1));
currentAnswer = median1.add(median2) / 2;
} else {
currentAnswer = quickselect(answers[_answerId].responses, middleIndex.add(1));
}
</span>
<span v-else>
currentAnswer = meanAgr(answers[_answerId].responses);
</span>
if (currentAnswer {{cond}} threshold) {
client.transfer(address(this).balance);
} else if (block.timestamp >= endAt) {
provider.transfer(address(this).balance);
}
latestCompletedAnswer = _answerId;
updatedHeight = block.number;
emit AnswerUpdated(currentAnswer, _answerId);
}
<span v-if = "agr == 'Median'">
//MEDIAN
function quickselect(int256[] memory _a, uint256 _k)
private
pure
returns (int256)
{
int256[] memory a = _a;
uint256 k = _k;
uint256 aLen = a.length;
int256[] memory a1 = new int256[](aLen);
int256[] memory a2 = new int256[](aLen);
uint256 a1Len;
uint256 a2Len;
int256 pivot;
uint256 i;
while (true) {
pivot = a[aLen.div(2)];
a1Len = 0;
a2Len = 0;
for (i = 0; i < aLen; i++) {
if (a[i] < pivot) {
a1[a1Len] = a[i];
a1Len++;
} else if (a[i] > pivot) {
a2[a2Len] = a[i];
a2Len++;
}
}
if (k <= a1Len) {
aLen = a1Len;
(a, a1) = swap(a, a1);
} else if (k > (aLen.sub(a2Len))) {
k = k.sub(aLen.sub(a2Len));
aLen = a2Len;
(a, a2) = swap(a, a2);
} else {
return pivot;
}
}
}
</span>
<span v-else>
//MEAN
function meanAgr(int256[] memory _a)
private
pure
returns (int256)
{
int256[] memory a = _a;
int256 mean = 0;
int256 q = 0;
for (uint i = 0; i < a.length; i++) {
mean += a[i];
q++;
}
mean = mean / q;
return mean;
}
</span>
//Prevents taking an action if the minimum number of responses has not been received for an answer.
modifier ensureMinResponsesReceived(uint256 _answerId) {
if (answers[_answerId].responses.length == answers[_answerId].minimumResponses) {
_;
}
}
// Prevents taking an action if a newer answer has been recorded.
modifier ensureOnlyLatestAnswer(uint256 _answerId) {
if (latestCompletedAnswer <= _answerId) {
_;
}
}
<span v-if = "feat.indexOf(4) != -1 && feat.indexOf(1) == -1">
// Reverts if `msg.sender` is not authorized to make requests.
modifier ensureAuthorizedRequester() {
require(authorizedRequesters[msg.sender] || msg.sender == owner, "Not an authorized address for creating requests");
_;
}
</span>
//Prevents taking an action if not all responses are received for an answer.
modifier ensureAllResponsesReceived(uint256 _answerId) {
if (answers[_answerId].responses.length == answers[_answerId].maxResponses) {
_;
}
}
//Swaps the pointers to two uint256 arrays in memory
function swap(int256[] memory _a, int256[] memory _b)
private
pure
returns(int256[] memory, int256[] memory)
{
return (_b, _a);
}
//Cleans up the answer record if all responses have been received.
function deleteAnswer(uint256 _answerId)
private
ensureAllResponsesReceived(_answerId)
{
delete answers[_answerId];
}
//Convert JobId string to byte32
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly {
result := mload(add(source, 32))
}
}
function () public payable {}
}
</span>
</div>
</dialog>
<div class = "hedfoot point" style = "height: 30px; bottom:0">
<a href='https://chain.link/' target='_blank'>Powered by ChainLink & Ethereum Network</a>
</div>
</div>
<script>
//Switch tab
var tabcontent = document.getElementsByClassName("tabcontent");
swit(0);
function swit(n) {
for (var i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tabcontent[n].style.display = "block";
}
</script>
<script src = "./js/script.js"></script>
<script src = "./js/rays.js" ></script>
</body>
</html>