-
Notifications
You must be signed in to change notification settings - Fork 2
/
payment.html
231 lines (171 loc) · 9.44 KB
/
payment.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
<html style='height:100%'>
<head>
<title>Qora Payment Processor</title>
<script src="jquery-2.2.0.js"></script>
<script src="nacl-fast.js" charset="utf-8"></script>
<script src="Base58.js" charset="utf-8"></script>
<script src="sha256.js" charset="utf-8"></script>
<script src="ripemd160.js" charset="utf-8"></script>
<script src="qora.js" charset="utf-8"></script>
<script src="common.js" charset="utf-8"></script>
<link href="bootstrap.css" rel="stylesheet">
<link href="common.css" rel="stylesheet">
</head>
<style>
</style>
<script type="text/javascript">
var casheBase58addressSeed = '';
var casheBase58SenderAccountAddress = '';
var casheBase58RecipientAccountAddress = '';
var casheTimestamp = '';
var casheFee = '';
var casheAmount = '';
function doUpdate()
{
var base58addressSeed = $('#base58SenderAccountSeed').val();
if ((base58addressSeed != '') && (casheBase58addressSeed != base58addressSeed)) {
casheBase58addressSeed = base58addressSeed;
if (Base58.decode(base58addressSeed).length == 32) {
keyPair = getKeyPairFromSeed(base58addressSeed, false);
var base58SenderAccountAddress = getAccountAddressFromPublicKey(keyPair.publicKey);
$('#base58SenderAccountAddress').val(base58SenderAccountAddress);
} else {
$('#base58SenderAccountAddress').val('');
}
}
var base58SenderAccountAddress = $('#base58SenderAccountAddress').val();
if ((base58SenderAccountAddress != '') && (casheBase58SenderAccountAddress != base58SenderAccountAddress)) {
casheBase58SenderAccountAddress = base58SenderAccountAddress;
doLoadBalance(base58SenderAccountAddress, $('#senderBalance'));
}
var base58RecipientAccountAddress = $('#base58RecipientAccountAddress').val();
if ((base58RecipientAccountAddress != '') && (casheBase58RecipientAccountAddress != base58RecipientAccountAddress)) {
casheBase58RecipientAccountAddress = base58RecipientAccountAddress;
doLoadBalance(base58RecipientAccountAddress, $('#recipientBalance'));
}
var timestamp = $('#timestamp').val();
if (!(timestamp == '' || casheTimestamp == timestamp)) {
casheTimestamp = timestamp;
if (! isNaN(casheTimestamp)) {
var date = new Date(parseInt(casheTimestamp));
$('#datetime').val(date.toLocaleDateString() + ' ' + date.toLocaleTimeString());
} else {
$('#datetime').val('');
}
}
if($('#fee').val() != casheFee) {
var caretPosition = getTextCursorPosition($('#fee'))
var removeCommasBuf = removeAllexceptDotAndNumbers($('#fee').val());
if(removeCommasBuf != $('#fee').val()) {
$('#fee').val(removeCommasBuf);
setTextCursorPosition($('#fee'), caretPosition - 1);
}
casheFee = $('#fee').val();
}
if($('#amount').val() != casheAmount) {
var caretPosition = getTextCursorPosition($('#amount'))
var removeCommasBuf = removeAllexceptDotAndNumbers($('#amount').val());
if(removeCommasBuf != $('#amount').val()) {
$('#amount').val(removeCommasBuf);
setTextCursorPosition($('#amount'), caretPosition - 1);
}
casheAmount = $('#amount').val();
}
}
function doPaymentTransaction() {
var base58SenderAccountSeed = document.getElementById('base58SenderAccountSeed').value;
var senderAccountSeed = Base58.decode(base58SenderAccountSeed);
if(senderAccountSeed.length != 32) {
$('#base58SenderAccountAddress').val('');
$("#output").val("invalid seed!");
return;
}
keyPair = getKeyPairFromSeed(senderAccountSeed);
var base58SenderAccountAddress = getAccountAddressFromPublicKey(keyPair.publicKey);
$('#base58SenderAccountAddress').val(base58SenderAccountAddress);
if($('#base58LastReferenceOfAccount').val() == "" || $('#base58LastReferenceOfAccount').val() == 'false') {
doLoadLastReference();
sleep(200);
}
if($('#timestamp').val() == "") {
doNowTime();
}
var recipientAccountAddress = Base58.decode($('#base58RecipientAccountAddress').val());
var base58LastReferenceOfAccount = [];
try {
base58LastReferenceOfAccount = Base58.decode($('#base58LastReferenceOfAccount').val());
} catch (err) {
base58LastReferenceOfAccount = [];
}
if(base58LastReferenceOfAccount.length != 64) {
$("#output").val("invalid reference!");
return;
}
var amount = parseFloat($('#amount').val());
var fee = parseFloat($('#fee').val());
var timestamp = parseInt($('#timestamp').val());
signature = generateSignaturePaymentTransaction(keyPair, base58LastReferenceOfAccount, recipientAccountAddress, amount, fee, timestamp);
paymentTransactionRaw = generatePaymentTransaction(keyPair, base58LastReferenceOfAccount, recipientAccountAddress, amount, fee, timestamp, signature);
$("#txRaw").val(Base58.encode(paymentTransactionRaw));
}
function onLoad()
{
$("#nodeUrl").val(nodeUrl);
setInterval(doUpdate, 300);
if (/test/.test(window.location.hash))
{
$("#base58SenderAccountSeed").val('3dnubGUuxK5oLhURK4WLtFL7rWgSKCj5MJc48AKD6FdD');
$("#base58LastReferenceOfAccount").val('YWv9Gyi2xxEyEe6ztrGGuAPhmUD86s7h8CANQAcmsxdeS3pU5BvQKnbeyXjnXXd8HgLaDvYBBz6im3dDYTR817F');
$("#base58RecipientAccountAddress").val('QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ');
$("#timestamp").val('1455849866776');
$("#amount").val('100.00000000');
$("#fee").val('1.00000000');
$("#output").val('111C87H8Ud2M9kriW66fcZ6KVDx88n5eHQW4tMEaUmzoLibTm8QVB2fRJx88xctEhHg9g5vfJX396HBjc5TNG64Ewz8MRcyjnRvg5RpSnomHpcX2n8HgRUTNqq18MtEkceSMqWbATtH9uu5pBnMzdu4MjFf87he2smq39RVtwMJnuw4qgaVwNYCwSxZrRgsT6RGpGkBHZPzoYYh8qXffmLzHvawYJqp4xN41uMPpe7J4xxbPdN2av4HKjCNtB82sygUbbt6QDBW5wMFcJyGYMn3mJVmhsFonM');
$("#generateTransaction").click();
if($("#output").val() == $("#txRaw").val()) {
$("#txRaw").css({"color": "green"});
} else {
$("#txRaw").css({"color": "red"});
}
console.log("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ " + getAccountAddressType("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ"));
console.log("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQf " + getAccountAddressType("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQf"));
console.log("QTz6fSV2VNc2wjwwsw57аwQzgQhmGw5idQ " + getAccountAddressType("QTz6fSV2VNc2wjwwsw57аwQzgQhmGw5idQ"));
console.log("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ " + isValidAddress("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ"));
console.log("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ1 " + isValidAddress("QTz6fSV2VNc2wjwwsw57kwQzgQhmGw5idQ1"));
console.log("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK7 " + getAccountAddressType("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK7"));
console.log("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK71 " + getAccountAddressType("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK71"));
console.log("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK7 " + isValidAddress("AGvtqUUWEpBM8CeDFcPP7a9s42nE4RKwK7"));
}
}
</script>
<body style="margin:4; padding:25" onload="onLoad()">
<center>
<div style='height: 140px;' id='menu'></div>
<h3>Qora Payment</h3>
<table>
<tr><td>
<b>Sender:</b><br>
<span style='width:110px; display: inline-block;'>Account Seed:</span> <input autofocus style='width:400px;' type="text" value="" id="base58SenderAccountSeed"/><br>
<span style='width:110px; display: inline-block;'>Account addr:</span> <input style='width:400px;' type="text" value="" id="base58SenderAccountAddress"/><br>
<span style='width:110px; display: inline-block;'>Balance:</span> <input style='width:360px;' class='readonly' readonly type="text" value="" id="senderBalance"/><span style='width:40px; display: inline-block;'> Qora</span><br>
<span style='width:110px; display: inline-block;'>Reference:</span> <input style='width:360px;' type="text" value="" id="base58LastReferenceOfAccount"/><input style='width:40px; padding: 1px;' type="button" value="Get" OnClick="doLoadLastReference()"/><br>
<br><b>Recipient:</b><br>
<span style='width:110px; display: inline-block;'>Account addr:</span> <input style='width:400px;' type="text" value="" id="base58RecipientAccountAddress"/><br>
<span style='width:110px; display: inline-block;'>Balance:</span> <input style='width:360px;' class='readonly' readonly type="text" value="" id="recipientBalance"/><span style='width:40px; display: inline-block;'> Qora</span><br>
<br>
<span style='width:110px; display: inline-block;'>Amount:</span>
<input style='width:165px;' type="text" value="0.00000000" id="amount"/><span style='width:50px; display: inline-block;'> Qora</span><span style='width:40px; display: inline-block;'> Fee:</span><input style='width:105px;' type="text" value="1.00000000" id="fee"/><span style='width:40px; display: inline-block;'> Qora</span>
<br><br>
<span style='width:110px; display: inline-block;'>Timestamp:</span> <input style='width:122px;' type="text" value="" id="timestamp"/><span style='width:80px; display: inline-block;'> DateTime:</span><input style='width:158px;' class='readonly' readonly type="text" value="" id="datetime"/><input style='width:40px; padding: 1px;' type="button" value="Now" OnClick="doNowTime()"/><br>
<br><br>
<input style='width:515px;' type="button" id='generateTransaction' value="Generate Transaction" OnClick="doPaymentTransaction()"/><br>
<textarea style='width:515px; height: 115px;' id=txRaw></textarea><br>
<span style='width:110px; display: inline-block;'> via node:</span> <input style='width:400px;' type="text" value="" id="nodeUrl"/><br>
<input style='width:515px;' type="button" value="Process" OnClick="doProcess()"/><br><br>
Result:<br>
<textarea style='width:515px; height: 115px;' id=output></textarea><br>
<br>
</table>
<div id='bottom'></div>
</center>
</body>