forked from monkins1010/Verusbridgekeeper
-
Notifications
You must be signed in to change notification settings - Fork 14
/
notarization.js
183 lines (137 loc) · 7.04 KB
/
notarization.js
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
var constants = require('./constants');
const util = require('./utils.js');
const notarizationFlags = function (notarization) {
if (parseInt(notarization.flags & constants.FLAG_START_NOTARIZATION) == constants.FLAG_START_NOTARIZATION) {
notarization.launchcleared = true;
}
else {
notarization.launchcleared = false;
}
if (parseInt(notarization.flags & constants.FLAG_LAUNCH_CONFIRMED) == constants.FLAG_LAUNCH_CONFIRMED) {
notarization.launchconfirmed = true;
}
else {
notarization.launchconfirmed = false;
}
if (parseInt(notarization.flags & constants.FLAG_LAUNCH_COMPLETE) == constants.FLAG_LAUNCH_COMPLETE) {
notarization.launchcomplete = true;
}
else {
notarization.launchcomplete = false;
}
if (parseInt(notarization.flags & constants.FLAG_ACCEPTED_MIRROR) == constants.FLAG_ACCEPTED_MIRROR) {
notarization.ismirror = true;
}
if (parseInt(notarization.flags & constants.FLAG_CONTRACT_UPGRADE) == constants.FLAG_CONTRACT_UPGRADE) {
notarization.contractupgrade = true;
}
return notarization;
}
const completeCurrencyStateToVerus = function (input) {
let currencyState = {};
notKEys = Object.keys(input);
for (const vals of notKEys)
{
if(isNaN(vals))
{
currencyState[vals] = input[vals];
}
}
currencyState.currencyid = util.uint160ToVAddress(currencyState.currencyid, constants.IADDRESS);
let tempReserveOrLaunch = [];
for (let i = 0; i < currencyState.weights.length; i++) {
let tempreserve = {};
tempreserve.currencyid = util.uint160ToVAddress(currencyState.currencies[i], constants.IADDRESS);
tempreserve.weight = util.uint64ToVerusFloat(currencyState.weights[i]);
tempreserve.reserves = util.uint64ToVerusFloat(currencyState.reserves[i]);
tempReserveOrLaunch.push(tempreserve);
}
if (parseInt(currencyState.flags) & constants.FLAG_FRACTIONAL == constants.FLAG_FRACTIONAL) {
currencyState.reservecurrencies = tempReserveOrLaunch;
}
else {
currencyState.launchcurrencies = tempReserveOrLaunch;
}
let currenciesiaddress = {};
if (currencyState.currencies.length > 0) {
for (let i = 0; i < currencyState.currencies.length; i++) {
let tempiaddress = util.uint160ToVAddress(currencyState.currencies[i], constants.IADDRESS);
currenciesiaddress[tempiaddress] = {};
currenciesiaddress[tempiaddress].reservein = util.uint64ToVerusFloat(currencyState.reservein[i]);
currenciesiaddress[tempiaddress].primarycurrencyin = util.uint64ToVerusFloat(currencyState.primarycurrencyin[i]);
currenciesiaddress[tempiaddress].reserveout = util.uint64ToVerusFloat(currencyState.reserveout[i]);
currenciesiaddress[tempiaddress].lastconversionprice = util.uint64ToVerusFloat(currencyState.conversionprice[i]);
currenciesiaddress[tempiaddress].viaconversionprice = util.uint64ToVerusFloat(currencyState.viaconversionprice[i]);
currenciesiaddress[tempiaddress].fees = util.uint64ToVerusFloat(currencyState.fees[i]);
currenciesiaddress[tempiaddress].conversionfees = util.uint64ToVerusFloat(currencyState.conversionfees[i]);
currenciesiaddress[tempiaddress].priorweights = util.uint64ToVerusFloat(currencyState.priorweights[i]);
}
currencyState.currencies = currenciesiaddress;
}
currencyState.initialsupply = util.uint64ToVerusFloat(currencyState.initialsupply);
currencyState.supply = util.uint64ToVerusFloat(currencyState.supply);
currencyState.emitted = util.uint64ToVerusFloat(currencyState.emitted);
currencyState.primarycurrencyout = util.uint64ToVerusFloat(currencyState.primarycurrencyout);
currencyState.preconvertedout = util.uint64ToVerusFloat(currencyState.preconvertedout);
currencyState.primarycurrencyfees = util.uint64ToVerusFloat(currencyState.primarycurrencyfees);
currencyState.primarycurrencyconversionfees = util.uint64ToVerusFloat(currencyState.primarycurrencyconversionfees);
return currencyState;
}
const createNotarization = function (input) {
let tempnotarization = {};
notKEys = Object.keys(input);
for (const vals of notKEys)
{
if(isNaN(vals))
{
tempnotarization[vals] = input[vals];
}
}
let notarization = notarizationFlags(tempnotarization);
let tempPropser = {};
tempPropser.type = notarization.proposer.destinationtype;
tempPropser.address = util.hexAddressToBase58(notarization.proposer.destinationtype, notarization.proposer.destinationaddress);
notarization.proposer = tempPropser;
notarization.currencyid = util.uint160ToVAddress(notarization.currencyid, constants.IADDRESS);
notarization.currencystate = completeCurrencyStateToVerus(notarization.currencystate);
notarization.hashprevcrossnotarization = util.removeHexLeader(notarization.hashprevnotarization);
delete notarization.hashprevnotarization;
notarization.prevnotarizationtxid = util.removeHexLeader(notarization.prevnotarization.hash);
notarization.prevnotarizationout = notarization.prevnotarization.n;
delete notarization.prevnotarization;
delete notarization.txid;
let tempcurr = []
for (let i = 0; i < notarization.currencystates.length; i++)
{
let tempcurrname = util.uint160ToVAddress(notarization.currencystates[i].currencyid, constants.IADDRESS);
let currencyItem = {};
currencyItem[tempcurrname] = completeCurrencyStateToVerus(notarization.currencystates[i].currencystate);
tempcurr.push(currencyItem);
}
notarization.currencystates = tempcurr;
let tempProofRoots = [];
for (let i = 0; i < notarization.proofroots.length; i++)
{
let tempProofRoot = {};
tempProofRoot.version = notarization.proofroots[i].version;
tempProofRoot.systemid = util.uint160ToVAddress(notarization.proofroots[i].systemid, constants.IADDRESS);
tempProofRoot.stateroot = util.removeHexLeader(notarization.proofroots[i].stateroot);
tempProofRoot.blockhash = util.removeHexLeader(notarization.proofroots[i].blockhash);
tempProofRoot.power = util.removeHexLeader(notarization.proofroots[i].compactpower);
tempProofRoot.type = notarization.proofroots[i].cprtype;
if (tempProofRoot.type == 2) //TODO: CHANGE TO TYPETH
tempProofRoot.gasprice = util.uint64ToVerusFloat(notarization.proofroots[i].gasprice);
tempProofRoot.height = notarization.proofroots[i].rootheight;
tempProofRoots.push(tempProofRoot);
}
let tempnodes = []
for (let i = 0; i < notarization.nodes.length; i++)
{
tempnodes.push({networkaddress: notarization.nodes[i].networkaddress, nodeidentity : util.uint160ToVAddress(notarization.nodes[i].nodeidentity, constants.IADDRESS)});
}
notarization.nodes = tempnodes;
notarization.proofroots = tempProofRoots;
return notarization;
}
exports.createNotarization = createNotarization;
exports.notarizationFlags = notarizationFlags;