Skip to content

Commit

Permalink
Fix store data on blockchain code
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Oct 10, 2024
1 parent af155dc commit 16dc1bf
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 32 deletions.
10 changes: 5 additions & 5 deletions blocksmurfer/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ def store_data(network): # pragma: no cover
w.scan(scan_gap_limit=1)
if w.balance():
lock_script = b'\x6a' + varstr(form.data.data)
t = w.send([Output(0, lock_script=lock_script)], fee=form.transaction_fee.data)
t = w.send([Output(0, lock_script=lock_script)], fee=form.transaction_fee.data, broadcast=True)
tzutc = timezone.utc
return render_template('explorer/store_data_send.html', title=_('Push Transaction'),
subtitle=_('Embed the data on the %s network' % srv.network.name),
transaction=t, t=t, tzutc=tzutc)
transaction=t, t=t, tzutc=tzutc, network=network)
else:
k = w.get_key()
message = "Store%20Data%20-%20Blocksmurfer"
Expand All @@ -513,11 +513,11 @@ def store_data(network): # pragma: no cover
subtitle=_('Fund the %s transaction and store data on the blockchain' %
srv.network.name),
address=k.address, tx_fee=form.transaction_fee.data, data=form.data.data,
paymentlink=paymentlink)
paymentlink=paymentlink, network=network)

return render_template('explorer/store_data.html', title=_('Store data'),
return render_template('explorer/store_data.html', title=_('Store Data'),
subtitle=_('Embed data on the %s blockchain' % srv.network.name), form=form,
tx_fee=tx_fee)
tx_fee=tx_fee, network=network)

@bp.route('/<network>/op_code/<op_code>', methods=['GET'])
def op_code(network, op_code):
Expand Down
2 changes: 1 addition & 1 deletion blocksmurfer/static/blocksmurfer.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ td {
.blocksmurfer-td-value {text-align: left;}
.blocksmurfer-table {width: 100%;}
.blocksmurfer-table-sf {width: 100%;}
}
}
43 changes: 29 additions & 14 deletions blocksmurfer/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,29 @@
<li class="pure-menu-item{% if title=='Blocks' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.blocks', network=network) }}" class="pure-menu-link">Blocks</a>
</li>
<li class="pure-menu-item{% if title=='Network' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.network', network=network) }}" class="pure-menu-link">Network</a>
</li>
<li class="pure-menu-item{% if title=='Script' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.script', network=network) }}" class="pure-menu-link">Scripts</a>
</li>
<li class="pure-menu-item{% if title=='Network' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.network', network=network) }}" class="pure-menu-link">Network</a>
<li class="pure-menu-item{% if title=='Decompose Transaction' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.transaction_decompose', network=network) }}" class="pure-menu-link">
Decompose Tx</a>
</li>
<li class="pure-menu-item{% if title=='About' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.about', network=network) }}" class="pure-menu-link">About</a>
<li class="pure-menu-item{% if title=='Send Transaction' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.transaction_broadcast', network=network) }}" class="pure-menu-link">
Broadcast Tx</a>
</li>
{% endif %}
{% if config.ENABLE_API %}
<li class="pure-menu-item{% if title=='API' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.api', network=network) }}" class="pure-menu-link">API</a>
<li class="pure-menu-item{% if title=='Store Data' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.store_data', network=network) }}" class="pure-menu-link">
Store Data &beta;</a>
</li>
{% else %}
<li class="pure-menu-item{% if title=='About' %} pure-menu-selected{% endif %}">
<a href="{{ url_for('main.about', network=network) }}" class="pure-menu-link">About</a>
</li>
{% elif config.API_BASE_URL %}
<a href="{{ config.API_BASE_URL }}" class="pure-menu-link">API</a>
{% endif %}
<li class="pure-menu-item{% if title=='Status' %} pure-menu-selected{% endif %}">
<a href="https://status.coineva.com/" class="pure-menu-link">Status</a>
</li>
</ul>
<p>&nbsp;</p>

Expand Down Expand Up @@ -125,6 +128,18 @@
{% block app_content %}{% endblock %}
</div>
<div class="footer" style="font-size: 80%">
<p>
<a href="{{ url_for('main.about', network=network) }}">About</a>
&middot;
{% if config.ENABLE_API %}
<a href="{{ url_for('main.api', network=network) }}">API</a>
&middot;
{% elif config.API_BASE_URL %}
<a href="{{ config.API_BASE_URL }}">API</a>
&middot;
{% endif %}
<a href="https://status.coineva.com/">Status</a>
</p>
<p>
Thank you for using Blocksmurfer Bitcoin block explorer!
</p>
Expand All @@ -147,4 +162,4 @@
<script type="text/javascript" src="{{url_for('static', filename='ui.js')}}"></script>

</body>
</html>
</html>
2 changes: 1 addition & 1 deletion blocksmurfer/templates/explorer/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div style="text-align: center;">
<p>
Enter the hexadecimal {{ network|upper() }} script to decompose. This will parse the script and show data,
opcoode commands and extracts keys and signatures if available.
opcode commands and extracts keys and signatures if available.
</p>
<form action="" method="post" novalidate class="pure-form">
{{ form.hidden_tag() }}
Expand Down
2 changes: 1 addition & 1 deletion blocksmurfer/templates/explorer/script_decomposed.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h2>Decompose another script</h2>
<p>{{ form.submit(class_="pure-button pure-button-primary") }}</p>
</form>
<p>
Enter the {{ network }} script to decompose. This will parse the script and show data, opcoode commands and
Enter the {{ network }} script to decompose. This will parse the script and show data, opcode commands and
extracts keys and signatures if available.
</p>
</div>
Expand Down
2 changes: 2 additions & 0 deletions blocksmurfer/templates/explorer/store_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
</p>
<p>{{ form.submit(class_="pure-button pure-button-primary") }}</p>
</form>
<p>IMPORTANT WARNING: This code is in beta stage, send funds at your own risk! No backups of private keys are stored,
in case of technical or any other kind of errors your funds are lost!</p>
{% endblock %}
log
3 changes: 3 additions & 0 deletions blocksmurfer/templates/explorer/store_data_fund.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
</p>
<p>{{ paymentlink }}</p>
<h3>Please reload page after funds have been send</h3>
<p>IMPORTANT WARNING: This code is in beta stage, send funds at your own risk! No backups of private keys are stored,
in case of technical or any other kind of errors your funds are lost! In case of errors try reloading this page.</p>

{% endblock %}
5 changes: 5 additions & 0 deletions tests/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


from datetime import datetime
import re


class CustomAssertions:
Expand Down Expand Up @@ -51,3 +52,7 @@ def assertDictEqualExt(self, result_dict, expected_dict, none_allowed=None):
continue
if result_dict[k] is not None or k not in none_allowed:
raise AssertionError("Different value for '%s': %s != %s" % (k, result_dict[k], expected_dict[k]))


def strip_html_whitespace(data):
return re.sub('<[^<]+?>', '', data.decode('utf-8')).replace(' ', '').replace('\n', '')
27 changes: 17 additions & 10 deletions tests/test_explorer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from flask import Config
from blocksmurfer import current_app
from tests.test_custom import CustomAssertions
from tests.test_custom import CustomAssertions, strip_html_whitespace
# from blocksmurfer.explorer.service import SmurferService as Service
from bitcoinlib.services.services import Service

Expand Down Expand Up @@ -150,7 +150,7 @@ def test_explorer_transaction_input(self):
'input/6')
self.assertIn(b'02ea08ccfdda6183c3e7d57c813567299efd0f0b233a3a32267ba9c2af3080aa1b', response.data)
self.assertIn(b'32c62dda4fee4fb316bc5ef46884be006c7b6810beea962fd72606557ae', response.data)
self.assertIn(b'signature key', response.data)
self.assertIn(b'signature', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_transaction_input_coinbase(self):
Expand Down Expand Up @@ -337,41 +337,48 @@ def test_explorer_scripts_p2pk(self):
def test_explorer_scripts_p2wsh(self):
data = {'script_hex': '0020e5736bf12976cc710b9833aac2e3333a5a5e9f24ac87ce49e868b496b5086023'}
response = self.app.post('/btc/script', data=data, follow_redirects=True)
self.assertIn(b'OP_0 data-32', response.data)
data_stripped = strip_html_whitespace(response.data)
self.assertIn('OP_0data-32', data_stripped)
self.assertIn(b'p2wsh', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_scripts_multisig(self):
data = {'script_hex': '5221026c80e3efcdd4247ee29ee73829023aa3bcd464b709879128085d661c5a24fe0921032840e4d6aa1bea14d964e559f7b0ac01eac27274a03333d19faae8bee33c28a12103893120d3e2bac81f5bb6dbd320feed1f57ca39dd57a8c1266b9372acae45de8a53ae'}
response = self.app.post('/btc/script', data=data, follow_redirects=True)
self.assertIn(b'OP_2 key key key OP_3 OP_CHECKMULTISIG', response.data)
self.assertIn(b'key', response.data)
self.assertIn(b'2 of 3', response.data)
self.assertIn(b'OP_CHECKMULTISIG', response.data)
self.assertIn(b'multisig', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_scripts_non_standard_1(self):
data = {'script_hex': '00473044022076521fc60292a564fcac9ecb05e78846ff0d0e1d9f9de87d23d71cc130504e5c02202b1e0b5aea07d530eab146d1db54542cb2ca2bf6dcf69e77b7ee21671e97f51c0148304502210099eef1bca6087f8f20e0f183a19d057230851ef2fa4f356f192a9745fe1711510220336610d9dc4617a9bb02bdffec0e231df6ad998c6909a7b136dcb30f4bc60953014c7252210352d50656796dd79e3e3385c29636d849b8705c9c6d9b86a1717adc38e4a567c72102f39d0b69c3b8e06030ef9dc295cf8c848f51e398fe85414e33509afdc7f01fb321027072ba2319ead2b0b387d69d36508f57b397da8d4ac76ea64676ee8a1356dae053af048e254ac175740087'}
response = self.app.post('/btc/script', data=data, follow_redirects=True)
self.assertIn(b'OP_0 signature signature redeemscript', response.data)
self.assertIn(b'OP_2 key key key OP_3 OP_CHECKMULTISIGVERIFY data-4 OP_DROP OP_DEPTH OP_0 OP_EQUAL', response.data)
data_stripped = strip_html_whitespace(response.data)
self.assertIn('OP_0signaturesignatureredeemscript', data_stripped)
self.assertIn('OP_2keykeykeyOP_3OP_CHECKMULTISIGVERIFYdata-4OP_DROPOP_DEPTHOP_0OP_EQUAL', data_stripped)
self.assertIn(b'p2sh_multisig', response.data)
self.assertIn(b'3044022076521fc60292a564fcac9ecb05e78846ff0d0e1d9f9de87d23d71cc130504e5c02202b1e', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_scripts_non_standard_2(self):
data = {'script_hex': '10d072d4494f3ff8f852f24e6c8b298f4647304402202c86a6dbde9edf8d484d7e58004afefa99aa4120f916b2719286ccf28064bb1902204c600fe5a5ab89c7c453adc3852c1aaf4cee23266b999bcda9e6f39f178a914e01514c69632102f824adc1d35bb896be9d7a67f7471b2015e54e465dbbf81702546a064069ee47ad826088a914b36cbc38155fa95bbcf25c66167de8490ee3c3b887672103195fcc71d09ddc686e91cf83f5d0de9440e4e5b88dfd03d7902abf1faa6a0fa5ad0482abbb5db168'}
response = self.app.post('/btc/script', data=data, follow_redirects=True)
self.assertIn(b'data-16 signature OP_1 redeemscript', response.data)
self.assertIn(b'OP_IF key OP_CHECKSIGVERIFY OP_SIZE OP_16 OP_EQUALVERIFY OP_HASH160 data-20 OP_EQUAL OP_ELSE key OP_CHECKSIGVERIFY data-4 OP_CHECKLOCKTIMEVERIFY OP_ENDIF', response.data)
data_stripped = strip_html_whitespace(response.data)
self.assertIn('data-16signatureOP_1redeemscript', data_stripped)
self.assertIn('OP_IFkeyOP_CHECKSIGVERIFYOP_SIZEOP_16OP_EQUALVERIFYOP_HASH160data-20OP_EQUALOP_ELSE'
'keyOP_CHECKSIGVERIFYdata-4OP_CHECKLOCKTIMEVERIFYOP_ENDIF', data_stripped)
self.assertIn(b'unknown', response.data)
self.assertIn(b' 304402202c86a6dbde9edf8d484d7e58004afefa99aa4120f916', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_scripts_p2sh_multisig(self):
data = {'script_hex': '0047304402200b0ee6c93789b7b8bbff647752d7110d2fc0e0bf913f3dec8192d5a6a1da2dc20220502920194c49986b44eebd192b561bda1d428b5821117b0fd60f0d4504026dba01483045022100d412fe60888e8069ca85f87722d6dc0384f9574cc79f4e7f0129564cb51c0a38022027ba0c114bcf867ea569a55d9eb0929c148b7fdf20f176fd10944b4e0fe7a8d9014c69522103614101c3dfc98f6a7b562cd9264cc6e0d8d9597f59feea666d4c7605493b928b2102386823b976815e4f6d7279b7b4a2113c7d9e0796fa7b1ac43caa7d464a1a06db2102e7ae0137cab0a11b49caeae853d06c9499e79029670a2d649cc2e9e58b99dc5753aea9147dae466253944bb084f8ac01343504941ae15c3287'}
response = self.app.post('/btc/script', data=data, follow_redirects=True)
data_stripped = strip_html_whitespace(response.data)
self.assertIn(b'p2sh_multisig, p2sh', response.data)
self.assertIn(b'OP_0 signature signature redeemscript OP_HASH160 data-20 OP_EQUAL', response.data)
self.assertIn(b'OP_2 key key key OP_3 OP_CHECKMULTISIG', response.data)
self.assertIn('OP_0signaturesignatureredeemscriptOP_HASH160data-20OP_EQUAL', data_stripped)
self.assertIn('OP_2keykeykeyOP_3OP_CHECKMULTISIG', data_stripped)
self.assertIn(b'20194c49986b44eebd192b561bda1d428b5821117b0fd60f0d4504026dba01', response.data)
self.assertEqual(response.status_code, 200)

Expand Down

0 comments on commit 16dc1bf

Please sign in to comment.