Skip to content

Commit 579d45e

Browse files
committed
vin drop down. hex toggle
1 parent 36f3bf8 commit 579d45e

File tree

1 file changed

+110
-23
lines changed

1 file changed

+110
-23
lines changed

docs/index.html

Lines changed: 110 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
<meta name="keyword" content="Bootstrap,Admin,Template,Open,Source,jQuery,CSS,HTML,RWD,Dashboard">
1919
<title>Full Cycle - Bitcoin Visualizer</title>
2020
<!-- Icons-->
21-
<link href="node_modules/@coreui/icons/css/coreui-icons.min.css" rel="stylesheet">
22-
<link href="node_modules/flag-icon-css/css/flag-icon.min.css" rel="stylesheet">
21+
<link href="dist/coreui-icons.min.css" rel="stylesheet">
22+
<link href="dist/flag-icon.min.css" rel="stylesheet">
2323
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
24-
<link href="node_modules/simple-line-icons/css/simple-line-icons.css" rel="stylesheet">
24+
<!-- <link href="node_modules/simple-line-icons/css/simple-line-icons.css" rel="stylesheet"> -->
2525
<!-- Main styles for this application-->
2626
<link href="css/style.css" rel="stylesheet">
2727
<link href="vendors/pace-progress/css/pace.min.css" rel="stylesheet">
@@ -123,31 +123,61 @@
123123
<div class="card">
124124
<div class="card-header">Script Visualizer</div>
125125
<div class="card-body">
126-
<!-- /.row-->
127126

128127
<div class="card">
129128
<div class="card-header"><i class="fa fa-file-download fa-lg mt-4"></i>Load Transaction</div>
130129
<div class="card-body">
131-
<input type="text" id="txtTxid" class="col-md-8"
132-
placeholder="Enter TxId"
133-
></input>
134-
<button id="btnLoadTx">Load Tx</button>
130+
<div class="row pb-3">
131+
<input type="text" id="txtTxid" class="col-md-8 mr-3"
132+
placeholder="Enter TxId" value="95fa8f460851d7ad175e2e05711519cf796d77ff22ec346029ffabe9056cf04b"
133+
></input>
134+
<button id="btnLoadTx" class="mr-3">Load Tx</button>
135+
<button id="btnExploreTx" class="mr-3">Show in Explorer</button>
136+
</div>
137+
<div class="row">
138+
<label class="col-md-1">vin</label>
139+
<select class="col-md-2" id="vin"></select>
140+
<!-- <label class="col-md-1">vout</label>
141+
<select class="col-md-2" id="vout"></select> -->
142+
</div>
135143
</div>
136144
</div>
137145

138146
<div class="card">
139-
<div class="card-header"><i class="fa fa-unlock fa-lg mt-4"></i>Unlock Script (aka ScriptSig from Transaction Input vin)</div>
147+
<div class="card-header">
148+
<i class="fa fa-unlock fa-lg mt-4"></i>
149+
<span>Unlock Script (aka ScriptSig from Transaction Input vin)</span>
150+
<button class="btn btn-primary float-md-right" type="button" data-toggle="collapse" data-target="#hexUnlock">
151+
Hex
152+
</button>
153+
</div>
140154
<div class="card-body">
141155
<textarea id="txtUnlock" class="colspan=12 w-100">OP_1 OP_2 OP_MUL</textarea>
142156
</div>
157+
<div class="collapse" id="hexUnlock">
158+
<div class="card-body">
159+
<textarea id="txtUnlockHex" class="colspan=12 w-100"></textarea>
160+
</div>
161+
</div>
143162
</div>
144163

145164
<div class="card">
146-
<div class="card-header"><i class="fa fa-lock fa-lg mt-4"></i>Locking Script (aka ScriptPubKey from Transaction Output vout)</div>
165+
<div class="card-header">
166+
<i class="fa fa-lock fa-lg mt-4"></i>
167+
<span>Locking Script (aka ScriptPubKey from Transaction Output vout)</span>
168+
<button class="btn btn-primary float-md-right" type="button" data-toggle="collapse" data-target="#hexLock">
169+
Hex
170+
</button>
171+
</div>
147172
<div class="card-body">
148173
<textarea id="txtLock" class="colspan=12 w-100">OP_2 OP_EQUAL</textarea>
149174
</div>
150-
</div>
175+
<div class="collapse" id="hexLock">
176+
<div class="card-body">
177+
<textarea id="txtLockHex" class="colspan=12 w-100"></textarea>
178+
</div>
179+
</div>
180+
</div>
151181

152182
<div class="pb-3">
153183
<button id="scriptRun">Run Script</button>
@@ -194,12 +224,12 @@
194224
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
195225
crossorigin="anonymous"></script>
196226
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
197-
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
198-
<script src="node_modules/pace-progress/pace.min.js"></script>
227+
<script src="dist/bootstrap.min.js"></script>
228+
<script src="dist/pace.min.js"></script>
199229
<script src="node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
200-
<script src="node_modules/@coreui/coreui/dist/js/coreui.min.js"></script>
230+
<script src="dist/coreui.min.js"></script>
201231
<!-- Plugins and scripts required by this view-->
202-
<script src="node_modules/chart.js/dist/Chart.min.js"></script>
232+
<script src="js/charts.js"></script>
203233
<script src="node_modules/@coreui/coreui-plugin-chartjs-custom-tooltips/dist/js/custom-tooltips.min.js"></script>
204234
<script src="js/main.js"></script>
205235

@@ -209,24 +239,81 @@
209239
runScript()
210240
})
211241

242+
$('#btnExploreTx').click( (clk) => {
243+
let txid = $('#txtTxid').val()
244+
if (txid) {
245+
window.open(`https://bchsvexplorer.com/tx/${txid}`)
246+
}
247+
})
248+
249+
$('#txtLock').change(() => {
250+
let scriptLock = bsv.Script($('#txtLock').val())
251+
$('#txtLockHex').val(scriptLock.toBuffer().toString('hex'))
252+
})
253+
254+
$('#txtUnlock').change(() => {
255+
let scriptLock = bsv.Script($('#txtUnlock').val())
256+
$('#txtUnlockHex').val(scriptLock.toBuffer().toString('hex'))
257+
})
258+
259+
let thisTransaction = null
260+
let otherTransaction = null
261+
212262
$('#btnLoadTx').click( (clk) => {
213263
let txid = $('#txtTxid').val()
214264
if (txid) {
215265
rawtx(txid).then( unlockingTx => {
216-
let utx = unlockingTx.data
217-
console.log(utx)
218-
let selectedVin = utx.vin[0]
219-
console.log(selectedVin)
220-
$('#txtUnlock').val(selectedVin.scriptSig.asm)
221-
rawtx(selectedVin.txid).then( lockingTx => {
222-
$('#txtLock').val(lockingTx.data.vout[selectedVin.vout].scriptPubKey.asm)
223-
runScript()
266+
thisTransaction = unlockingTx.data
267+
console.log(thisTransaction)
268+
thisTransaction.vin.forEach( i => {
269+
$('#vin').append($("<option/>",{value: i.vout, text: `${i.vout}:${i.txid}`}))
224270
})
271+
whenVinSelected(0)
272+
// thisTransaction.vout.forEach( i => {
273+
// $('#vout').append($("<option/>",{value: i.n, text: i.value}))
274+
// })
225275
})
226276
}
227277
})
278+
279+
$('#vin').change( () => {
280+
whenVinSelected(parseInt($('#vin').val(),10))
281+
})
282+
283+
// $('#vout').change( () => {
284+
// whenVoutSelected(parseInt($('#vout').val(),10))
285+
// })
286+
287+
const whenVinSelected = (vinIndex) => {
288+
let selectedVin = thisTransaction.vin[vinIndex]
289+
console.log(selectedVin)
290+
let scriptUnlock = bsv.Script.fromHex(selectedVin.scriptSig.hex)
291+
$('#txtUnlock').val(scriptUnlock.toString())
292+
$('#txtUnlockHex').val(selectedVin.scriptSig.hex)
293+
rawtx(selectedVin.txid).then( lockingTx => {
294+
otherTransaction = lockingTx.data
295+
let scriptLock = bsv.Script.fromHex(lockingTx.data.vout[selectedVin.vout].scriptPubKey.hex)
296+
$('#txtLock').val(scriptLock.toString())
297+
$('#txtLockHex').val(lockingTx.data.vout[selectedVin.vout].scriptPubKey.hex)
298+
runScript()
299+
})
300+
}
228301
})
229302

303+
// const whenVoutSelected = (voutIndex) => {
304+
// let selectedVout = thisTransaction.vin[vinIndex]
305+
// console.log(selectedVout)
306+
// let scriptLock = bsv.Script.fromHex(selectedVout.scriptPubKey.hex)
307+
// $('#txtLock').val(scriptLock.toString())
308+
// rawtx(selectedVin.txid).then( lockingTx => {
309+
// otherTransaction = lockingTx.data
310+
// let scriptLock = bsv.Script.fromHex(lockingTx.data.vout[selectedVin.vout].scriptPubKey.hex)
311+
// //$('#txtLock').val(lockingTx.data.vout[selectedVin.vout].scriptPubKey.asm)
312+
// $('#txtLock').val(scriptLock.toString())
313+
// runScript()
314+
// })
315+
// }
316+
230317
const rawtx = async (tx) => {
231318
if (!tx) {
232319
console.log("nothing passed to rawtx!")

0 commit comments

Comments
 (0)