diff --git a/biljeznica.ipynb b/biljeznica.ipynb index 72753ab..e5ead8d 100644 --- a/biljeznica.ipynb +++ b/biljeznica.ipynb @@ -24,20 +24,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "figa, axa = plt.subplots()\n", @@ -76,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +83,7 @@ " str(self.transactions) + str(self.previousHash)).encode('utf-8')\n", " self.hash = self.hashMyBlock().hexdigest()\n", "\n", - " def hashMyBlock(self):\n", + " def hashBlock(self):\n", " sha = hashlib.sha256()\n", " sha.update(self.encoded)\n", " return sha" @@ -105,6 +94,92 @@ "execution_count": 26, "metadata": {}, "outputs": [], + "source": [ + "class Transaction:\n", + " \n", + " def __init__(self, sender, reciever, amount):\n", + " \n", + " self.sender = sender\n", + " self.reciever = reciever\n", + " self.amount = amount\n", + " self.encoded = (str(self.sender) + str(self.reciever) + \n", + " str(self.amount) ).encode('utf-8')\n", + " self.hash = self.hashMyTransaction().hexdigest()\n", + " \n", + " \n", + " def hashTransaction(self):\n", + " \n", + " sha = hashlib.sha256()\n", + " sha.update(self.encoded)\n", + " return sha" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "class Mempool:\n", + " \n", + " def __init__(self):\n", + " \n", + " self.transactions=[]\n", + " \n", + " def addNewTransaction(self,transaction):\n", + " \n", + " self.transactions.append(transaction)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "class Node:\n", + " \n", + " def __init__(self, name):\n", + " \n", + " self.name = name\n", + " self.balance = 0\n", + " self.priKey = self.hashNode(self.name.encode('utf-8')).hexdigest()\n", + " self.priKey = self.hashNode().hexdigest()\n", + " \n", + " def hashNode(self, stringToHash):\n", + " \n", + " sha = hashlib.sha256()\n", + " sha.update(stringToHash)\n", + " return sha" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'c4b9a2dc06df9ad095ab06d4d131ece0500d3a7bf66e654a2c728931b4aed1c0'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "trans= Transaction(\"a\",\"b\",10)\n", + "trans.hash" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], "source": [ "import datetime as date\n", "\n", @@ -115,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 7, "metadata": { "scrolled": false }, @@ -123,16 +198,17 @@ { "data": { "text/plain": [ - "'a00cdb33d1a6f850488f9b37178b17a9fdaa7bb71dff3a318b76a6a430eb96b6'" + "'6afcaadbc31039de6f6d1d7a90be15cd2ac2d063ef3d1129a915726e11f466dc'" ] }, - "execution_count": 46, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "genesisBlock = Block(0, getMeTime(),\"\",[\"First block\"])\n", + "genesisBlock.hashMe()\n", "genesisBlock.hash" ] }, @@ -145,16 +221,16 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'a00cdb33d1a6f850488f9b37178b17a9fdaa7bb71dff3a318b76a6a430eb96b6'" + "''" ] }, - "execution_count": 47, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -167,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -186,7 +262,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -200,27 +276,16 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['First block']" - ] - }, - "execution_count": 80, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "genesisBlock.transactions" ] }, { "cell_type": "code", - "execution_count": 81, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -240,76 +305,31 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "============================== 0 ==============================\n", - "a00cdb33d1a6f850488f9b37178b17a9fdaa7bb71dff3a318b76a6a430eb96b6\n", - "===============================================================\n", - "First block\n" - ] - } - ], + "outputs": [], "source": [ "printBlock(genesisBlock)" ] }, { "cell_type": "code", - "execution_count": 83, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "============================== 1 ==============================\n", - "4cfab635f6c02b97274af250c512ebae051425197955f816417b00e3cf0d76bf\n", - "===============================================================\n", - "Alice Bob 50\n", - "Bob John 10\n" - ] - } - ], + "outputs": [], "source": [ "printBlock(secondBlock)" ] }, { "cell_type": "code", - "execution_count": 84, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "============================== 0 ==============================\n", - "a00cdb33d1a6f850488f9b37178b17a9fdaa7bb71dff3a318b76a6a430eb96b6\n", - "===============================================================\n", - "First block\n", - "============================== 1 ==============================\n", - "4cfab635f6c02b97274af250c512ebae051425197955f816417b00e3cf0d76bf\n", - "===============================================================\n", - "Alice Bob 50\n", - "Bob John 10\n", - "============================== 2 ==============================\n", - "f64194505b2fb4216b5fbc548a97438b208c98968826d5e48665107140caea84\n", - "===============================================================\n", - "Bob Alice 20\n", - "John Mary 5\n", - "Alice Mary 20\n" - ] - } - ], + "outputs": [], "source": [ "blockchain = Blockchain(genesisBlock)\n", "blockchain.addNewBlock(secondBlock)\n", @@ -360,12 +380,93 @@ "import matplotlib.pyplot as plt" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "test?\n" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import numpy\n", + "t=numpy.array(test.Date.values)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.test(data=)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "t=list(test.Date.values)\n", + "t" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "import matplotlib.dates as dates\n", + "datesNew = dates.date2num(t)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dates.date2num?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "numpy.datetime64?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.plot(np.linspace(2,200,1),test.Open.values[-200:])" + ] }, { "cell_type": "code",