-
Notifications
You must be signed in to change notification settings - Fork 99
/
page-accept.php
224 lines (188 loc) · 6.52 KB
/
page-accept.php
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
<?php
if (@$_POST['unlockoutputs'])
if (no_displayed_error_result($result, multichain('lockunspent', true)))
output_success_text('All outputs successfully unlocked');
$decoded=null;
function ask_offer_to_assets($askoffer)
{
$assets=array();
foreach ($askoffer['assets'] as $asset)
$assets[$asset['name']]=$asset['qty'];
if (!count($assets))
$assets=0; // to prevent it being converted to empty JSON array instead of object
return $assets;
}
if (@$_POST['decodeoffer'] || @$_POST['completeoffer']) {
if (no_displayed_error_result($decoded, multichain('decoderawexchange', $_POST['hex']))) {
if (@$_POST['completeoffer']) {
if (no_displayed_error_result($prepare, multichain('preparelockunspentfrom', $_POST['from'], ask_offer_to_assets($decoded['ask'])))) {
// output_success_text('Exchange successfully prepared using transaction '.$prepare['txid']);
if (no_displayed_error_result($rawexchange, multichain('appendrawexchange', $_POST['hex'],
$prepare['txid'], $prepare['vout'], ask_offer_to_assets($decoded['offer'])))) {
if (no_displayed_error_result($sendtxid, multichain('sendrawtransaction', $rawexchange['hex'])))
output_success_text('Exchange successfully completed in transaction '.$sendtxid);
}
}
}
}
}
?>
<div class="row">
<div class="col-sm-5">
<h3>Available Balances</h3>
<?php
$sendaddresses=array();
$usableaddresses=array();
$keymyaddresses=array();
$keyusableassets=array();
$allassets=array();
$haslocked=false;
$getinfo=multichain_getinfo();
$labels=array();
if (no_displayed_error_result($getaddresses, multichain('getaddresses', true))) {
if (no_displayed_error_result($listpermissions,
multichain('listpermissions', 'send', implode(',', array_get_column($getaddresses, 'address')))
))
$sendaddresses=array_get_column($listpermissions, 'address');
foreach ($getaddresses as $address)
if ($address['ismine'])
$keymyaddresses[$address['address']]=true;
$labels=multichain_labels();
if (no_displayed_error_result($listassets, multichain('listassets')))
$allassets=array_get_column($listassets, 'name');
foreach ($sendaddresses as $address) {
if (no_displayed_error_result($allbalances, multichain('getaddressbalances', $address, 0, true))) {
if (count($allbalances)) {
$assetunlocked=array();
if (no_displayed_error_result($unlockedbalances, multichain('getaddressbalances', $address, 0, false))) {
if (count($unlockedbalances))
$usableaddresses[]=$address;
foreach ($unlockedbalances as $balance)
$assetunlocked[$balance['name']]=$balance['qty'];
}
$label=@$labels[$address];
?>
<table class="table table-bordered table-condensed table-break-words <?php echo ($address==@$getnewaddress) ? 'bg-success' : 'table-striped'?>">
<?php
if (isset($label)) {
?>
<tr>
<th style="width:25%;">Label</th>
<td><?php echo html($label)?></td>
</tr>
<?php
}
?>
<tr>
<th style="width:20%;">Address</th>
<td class="td-break-words small"><?php echo html($address)?></td>
</tr>
<?php
foreach ($allbalances as $balance) {
$unlockedqty=floatval($assetunlocked[$balance['name']]);
$lockedqty=$balance['qty']-$unlockedqty;
if ($lockedqty>0)
$haslocked=true;
if ($unlockedqty>0)
$keyusableassets[$balance['name']]=true;
?>
<tr>
<th><?php echo html($balance['name'])?></th>
<td><?php echo html($unlockedqty)?><?php echo ($lockedqty>0) ? (' ('.$lockedqty.' locked)') : ''?></td>
</tr>
<?php
}
?>
</table>
<?php
}
}
}
}
if ($haslocked) {
?>
<form class="form-horizontal" method="post" action="./?chain=<?php echo html($_GET['chain'])?>&page=<?php echo html($_GET['page'])?>">
<input class="btn btn-default" type="submit" name="unlockoutputs" value="Unlock all outputs">
</form>
<?php
}
?>
</div>
<?php
if (is_array($decoded)) {
?>
<div class="col-sm-7">
<h3>Complete Offer</h3>
<form class="form-horizontal" method="post" action="./?chain=<?php echo html($_GET['chain'])?>&page=<?php echo html($_GET['page'])?>">
<?php
foreach ($decoded['offer']['assets'] as $index => $offer) {
?>
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo $index ? '' : 'Offer'?>:</label>
<div class="col-sm-9">
<p class="form-control-static"><?php echo html($offer['name'])?> – <?php echo html($offer['qty'])?></p>
</div>
</div>
<?php
}
foreach ($decoded['ask']['assets'] as $index => $ask) {
?>
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo $index ? '' : 'Ask'?>:</label>
<div class="col-sm-9">
<p class="form-control-static"><?php echo html($ask['name'])?> – <?php echo html($ask['qty'])?></p>
</div>
</div>
<?php
}
?>
<div class="form-group">
<label for="from" class="col-sm-3 control-label">Use address:</label>
<div class="col-sm-9">
<select class="form-control" name="from" id="from">
<?php
foreach ($usableaddresses as $address) {
?>
<option value="<?php echo html($address)?>"><?php echo format_address_html($address, true, $labels)?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<input class="btn btn-default" type="submit" name="completeoffer" value="Complete Offer">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Offer hexadecimal:</label>
<div class="col-sm-9">
<textarea class="form-control" rows="5" name="hex" readonly><?php echo html($_POST['hex'])?></textarea>
</div>
</div>
</form>
</div>
<?php
} else {
?>
<div class="col-sm-7">
<h3>Decode Offer</h3>
<form class="form-horizontal" method="post" action="./?chain=<?php echo html($_GET['chain'])?>&page=<?php echo html($_GET['page'])?>">
<div class="form-group">
<label for="hex" class="col-sm-3 control-label">Offer hexadecimal:</label>
<div class="col-sm-9">
<textarea class="form-control" rows="10" name="hex" id="hex"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<input class="btn btn-default" type="submit" name="decodeoffer" value="Decode Offer">
</div>
</div>
</form>
</div>
<?php
}
?>
</div>