Compare commits
10 Commits
master
...
dvf/partii
Author | SHA1 | Date |
---|---|---|
Daniel van Flymen | d38a86b25f | |
Daniel van Flymen | 8cd2a13747 | |
Daniel van Flymen | acb84b81e0 | |
Daniel van Flymen | 6f34e4fd7b | |
Daniel van Flymen | d3298af019 | |
Daniel van Flymen | fd7cf5e2f9 | |
Joel Bixby | bfe4de5016 | |
Daniel van Flymen | ecef87c5de | |
Daniel van Flymen | 5021b69937 | |
Daniel van Flymen | 0df3b84428 |
|
@ -1 +0,0 @@
|
|||
__pycache__
|
|
@ -0,0 +1,63 @@
|
|||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
|
@ -103,4 +103,4 @@ ENV/
|
|||
# PyCharm
|
||||
.idea/
|
||||
|
||||
node_modules/
|
||||
*.db
|
|
@ -0,0 +1,12 @@
|
|||
language: python
|
||||
|
||||
python:
|
||||
- 3.6
|
||||
- nightly
|
||||
|
||||
install:
|
||||
- pip install pipenv
|
||||
- pipenv install --dev
|
||||
|
||||
script:
|
||||
- pipenv run python -m unittest
|
34
Dockerfile
34
Dockerfile
|
@ -1,29 +1,17 @@
|
|||
FROM python:3.8-alpine AS builder
|
||||
FROM python:3.6-alpine
|
||||
|
||||
WORKDIR /app
|
||||
ENV PATH="/root/.poetry/bin:$PATH"
|
||||
|
||||
RUN apk add --no-cache build-base libffi-dev curl \
|
||||
&& curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python \
|
||||
&& python -m venv .venv \
|
||||
&& poetry config virtualenvs.in-project true \
|
||||
&& .venv/bin/pip install --no-cache-dir -U pip setuptools
|
||||
ENV BUILD_LIST git
|
||||
|
||||
COPY pyproject.toml poetry.lock ./
|
||||
RUN poetry install --no-dev --no-root --no-interaction
|
||||
RUN apk add --update $BUILD_LIST \
|
||||
&& git clone https://github.com/dvf/blockchain.git /app \
|
||||
&& pip install pipenv \
|
||||
&& pipenv --python=python3.6 \
|
||||
&& pipenv install \
|
||||
&& apk del $BUILD_LIST \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
COPY blockchain/ ./blockchain/
|
||||
EXPOSE 5000
|
||||
|
||||
|
||||
FROM python:3.8-alpine
|
||||
|
||||
EXPOSE 80
|
||||
WORKDIR /app
|
||||
CMD ["uvicorn", "run:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
ENV PATH="/app/.venv/bin:$PATH" \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
RUN apk add --no-cache libc-dev binutils
|
||||
|
||||
COPY run.py ./
|
||||
COPY --from=builder /app/ ./
|
||||
ENTRYPOINT [ "pipenv", "run", "python", "/app/blockchain.py", "--port", "5000" ]
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
[[source]]
|
||||
|
||||
url = "https://pypi.python.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
|
||||
[requires]
|
||||
|
||||
python_version = "3.6"
|
||||
|
||||
|
||||
[packages]
|
||||
|
||||
flask = "==0.12.2"
|
||||
requests = "==2.18.4"
|
||||
sqlalchemy = "*"
|
||||
aioodbc = "*"
|
||||
sqlalchemy-aio = "*"
|
||||
sanic = "*"
|
||||
aiohttp = "*"
|
||||
miniupnpc = "*"
|
|
@ -0,0 +1,304 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash_block": {
|
||||
"sha256": "12bb22c1e036c3ea23ae6dfcd3682d0ff1f37b0e7817ba87aa3fe22ceb12ed9d"
|
||||
},
|
||||
"host-environment-markers": {
|
||||
"implementation_name": "cpython",
|
||||
"implementation_version": "3.6.2",
|
||||
"os_name": "posix",
|
||||
"platform_machine": "x86_64",
|
||||
"platform_python_implementation": "CPython",
|
||||
"platform_release": "16.7.0",
|
||||
"platform_system": "Darwin",
|
||||
"platform_version": "Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64",
|
||||
"python_full_version": "3.6.2",
|
||||
"python_version": "3.6",
|
||||
"sys_platform": "darwin"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.6"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.python.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"aiofiles": {
|
||||
"hashes": [
|
||||
"sha256:25c66ea3872d05d53292a6b3f7fa0f86691512076446d83a505d227b5e76f668",
|
||||
"sha256:852a493a877b73e11823bfd4e8e5ef2610d70d12c9eaed961bcd9124d8de8c10"
|
||||
],
|
||||
"version": "==0.3.2"
|
||||
},
|
||||
"aiohttp": {
|
||||
"hashes": [
|
||||
"sha256:1d3659809cc3cf16007a43df3c3af34a9ad8d7594bfcd651ef2d29ff21d015e3",
|
||||
"sha256:18c93827f604e3830535423f22bfaa180d7ba10baa5959a2077f2e29b320138d",
|
||||
"sha256:080c82112d93fe117a2f605d5a102191ae7fc52349c53cf6676efbfb8bd2d369",
|
||||
"sha256:a1c29fdc56e040c3c67a9fa6da7e05382d5216d1ead9ae8a4fb772a1abb0452a",
|
||||
"sha256:d8f546159ae453572c3b87d88652705c4516dfee1ade8673b47f544b2bf1b33d",
|
||||
"sha256:03085220b503bb2cf2d288e1b36cf6dcbf84fcfed550e7c73bad429a6e528084",
|
||||
"sha256:00e40b1261bdb6a1e2b986e610be8a2bb0699ce5a261f78c88d761c726e0af10",
|
||||
"sha256:fcec0a4878c27f04bf62de4b76d51f9583d45031317dd020088d2e258210fcc2",
|
||||
"sha256:52b180767e1b75ff071f316a52946fb311ba4183cb6981201fa7843611cf42e4",
|
||||
"sha256:1fbc4701639ca383dc103840fb478ce726b84c51de8d575c02b740bcb2f60262",
|
||||
"sha256:9d2e10768bca6ff8392df596754adbffee39ab4243d2536f955f9db145685cbe",
|
||||
"sha256:3ee498748106c2f8ce937ea27c05d8862118ce055ee3d074b383e927572b51b6",
|
||||
"sha256:dc922785064187c45c71eda21d7eb87c7a0b2d867e0d7c9ffc2ea2a37dcca608",
|
||||
"sha256:0415ca37ca047d4b5c2938da024abe4893fe54227b7ad36f98fb169fff4767a3",
|
||||
"sha256:08715cc8d0ae00679b7c131804ae92aacc31fd0078dd0d78c309c043a4f8aa57",
|
||||
"sha256:ed8fb8c9b16459895c6949215592df6119961a9999ade84b66594456883d2215",
|
||||
"sha256:6b2c62e6d54a08c7e4b8b00251d3c877bdf10ceec22c7ecc5d94de64d75fe699",
|
||||
"sha256:f81850cf4707a2d3d85fcb9c85c091a0df66bf4a67197530c5a4f454b8d1d950",
|
||||
"sha256:5a1c7c890ac13dd05763e3617261f528fedf3255d72ba8c41e97f7de72f3d8b6",
|
||||
"sha256:65d623d32a40826be88ecafe5a49fd0af3092b2bf7e1171aec1d3e7868c969c1",
|
||||
"sha256:222634adcdcfda1aefafff198415df77946384d10696619f1b163cb36d03bc82",
|
||||
"sha256:fe294df38e9c67374263d783a7a29c79372030f5962bd5734fa51c6f4bbfee3b"
|
||||
],
|
||||
"version": "==2.3.7"
|
||||
},
|
||||
"aioodbc": {
|
||||
"hashes": [
|
||||
"sha256:1a859a4ac7de85bb7a743e22da3942fb046c18fed27fb68bb2ac01750ed259a7"
|
||||
],
|
||||
"version": "==0.2.0"
|
||||
},
|
||||
"async-timeout": {
|
||||
"hashes": [
|
||||
"sha256:d3a195a827b0f4068d1616ae2da04aac62e365d14f2b13dbc071f9feed9db4e2",
|
||||
"sha256:c17d8ac2d735d59aa62737d76f2787a6c938f5a944ecf768a8c0ab70b0dea566"
|
||||
],
|
||||
"version": "==2.0.0"
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:244be0d93b71e93fc0a0a479862051414d0e00e16435707e5bf5000f92e04694",
|
||||
"sha256:5ec74291ca1136b40f0379e1128ff80e866597e4e2c1e755739a913bbc3613c0"
|
||||
],
|
||||
"version": "==2017.11.5"
|
||||
},
|
||||
"chardet": {
|
||||
"hashes": [
|
||||
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691",
|
||||
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
|
||||
],
|
||||
"version": "==3.0.4"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
|
||||
"sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
|
||||
],
|
||||
"version": "==6.7"
|
||||
},
|
||||
"flask": {
|
||||
"hashes": [
|
||||
"sha256:0749df235e3ff61ac108f69ac178c9770caeaccad2509cb762ce1f65570a8856",
|
||||
"sha256:49f44461237b69ecd901cc7ce66feea0319b9158743dd27a2899962ab214dac1"
|
||||
],
|
||||
"version": "==0.12.2"
|
||||
},
|
||||
"httptools": {
|
||||
"hashes": [
|
||||
"sha256:f50dcb27178416c3a4113e9e1b392be5d1ff56ae1e474fe80869ed8530505e4c"
|
||||
],
|
||||
"version": "==0.0.10"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4",
|
||||
"sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f"
|
||||
],
|
||||
"version": "==2.6"
|
||||
},
|
||||
"itsdangerous": {
|
||||
"hashes": [
|
||||
"sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519"
|
||||
],
|
||||
"version": "==0.24"
|
||||
},
|
||||
"jinja2": {
|
||||
"hashes": [
|
||||
"sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd",
|
||||
"sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"
|
||||
],
|
||||
"version": "==2.10"
|
||||
},
|
||||
"markupsafe": {
|
||||
"hashes": [
|
||||
"sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665"
|
||||
],
|
||||
"version": "==1.0"
|
||||
},
|
||||
"miniupnpc": {
|
||||
"hashes": [
|
||||
"sha256:7ea46c93486fe1bdb31f0e0c2d911d224fce70bf5ea120e4295d647dfe274931"
|
||||
],
|
||||
"version": "==2.0.2"
|
||||
},
|
||||
"multidict": {
|
||||
"hashes": [
|
||||
"sha256:d12dfcff45b5c0eb3d586289cbf928012e75f93f10f4b9d7af903acb07b3c226",
|
||||
"sha256:f7deb65a184cbe757faaf4c6d2b8f203cb1a11dd44603a34d7befc343253d5bf",
|
||||
"sha256:80ad69b8330135b52a6da7a1f0ab6a278025bb72ea08768966785c829f515a6f",
|
||||
"sha256:3261b631cd6d079e6a20def3306b433794f800ea896dce4f1d5e833ad9bf6f26",
|
||||
"sha256:80e2bd17ea98fe77867771e1ee03433a54fa492a8413966a6caa766bdd6d6e62",
|
||||
"sha256:8eb59892040198741944eafca0c34be4da6b58be7fddf6e491a2d9e7e1767548",
|
||||
"sha256:24ec0d645ca70981e1c84e97e48c874b47f4970a173c8c751be9c213a8658e40",
|
||||
"sha256:167558cfb7c43077b3d8602142109f2b52fae0841a7ff97eb0a7443db199f303",
|
||||
"sha256:80abc93d197e24fb7c5aa5a8be3eacbcbc7115a2ff64e46162a4c2b46cd2f75a",
|
||||
"sha256:ff2b92a41df2e4c5cafaefb782469f3e6053ed00026d75a398521096192d0408",
|
||||
"sha256:5cfb63f0ddfa86ce6e80eee64e4fe886f9dfdb6dbbd724997bccb66513b0e29f",
|
||||
"sha256:50dac1151e34974b04419073ee9726f4180c6daf3454fd4af258824a19ad8c1d",
|
||||
"sha256:ebf1ba2af62dbaa37cf3db346830bb43d40d05a5f1f1966888a620f9b795e7c7",
|
||||
"sha256:3f513f3bf933d7cb6f5741f6676d4fac1e96aa634161c071974f9bb86a7bbac9",
|
||||
"sha256:ef6dc6e2d51b6058aa62cdd44dbf02c250c19eee6ff0065babc0ac126b068d43",
|
||||
"sha256:90dc3b8fefc58a865d64957f8f901d724250ba2a40e02f49d0df0103e96f5afa",
|
||||
"sha256:70630854b820d73ae102440123df38c983d77cd4ae444f3930a6bb6bbda87b76",
|
||||
"sha256:faf2b6447521d2075d03fb5e7c5467bac68f67df1c69e034ebca3afb6b3c619d",
|
||||
"sha256:eb7d5d39463137726138fc14c8458131136b8f4b06ba65f1cecd7aa6abe91df1",
|
||||
"sha256:fa04df1503fae7045883c57db47ba0c07de2ebe4a91c3e64d56f20d3d99e5dc8",
|
||||
"sha256:bce16633f3ee88863e4c9bcd7e037a6133c56fd9e7e7c0776bbaeeddcf154ac4",
|
||||
"sha256:f82e61c7408ed0dce1862100db55595481911f159d6ddec0b375d35b6449509b"
|
||||
],
|
||||
"version": "==3.3.2"
|
||||
},
|
||||
"pyodbc": {
|
||||
"hashes": [
|
||||
"sha256:364621505a7488b58ac3d5ac53183425f0ba6f333fdc0500492d08485431d04c",
|
||||
"sha256:f20474fcf5f359d6079e215b196af3a3667c73712437f20cb89d72819ac7d37d",
|
||||
"sha256:ec84f3c7b13199455a42ae130815855be7a4c18ac4cf01f005785890cfcf52e5",
|
||||
"sha256:c0f1e7b814cbdaa0215ff72a17e3cb3f4da77c65806b3895bb40f3859822a57c",
|
||||
"sha256:75c31fcfa8f5f1d09485817488de60d6ebe8819593c83beacf625dd281fbe406",
|
||||
"sha256:74cd2dff259eaf3da79c5beed2818f2cb1c0d15212f3b6a02e08053f5de0e7fc",
|
||||
"sha256:3f06a002c38ad241e072bc6449c9961afcb37bbbb9feeda20f90a9d67b02fe14",
|
||||
"sha256:7139faaa8f1396883f275e7ada88e729b031f9efae335d0a9ea26e84e2eb11eb",
|
||||
"sha256:1242b5f045249835b8473565882804bb09aa54cc1c5bad24ef6cd8b7af4197d0",
|
||||
"sha256:d40b122108ae48d17531c9ba844168c1c82d76247ef22063d3f087e30fa1dde2",
|
||||
"sha256:3f119da1db79576ce15d36b8c31dc7ca1732ada47a6bfd0de0993c68440b26a0",
|
||||
"sha256:ecf9a63cd5babce5547ac1b4b8472d6dfec42ca009cd3d8c8b2777b2b4a2e2a8",
|
||||
"sha256:9655f84ca9e5cb2dfffff705601017420c840d55271ba62dd44f05383eff0329"
|
||||
],
|
||||
"version": "==4.0.21"
|
||||
},
|
||||
"represent": {
|
||||
"hashes": [
|
||||
"sha256:f599094a66ec04455bb1555f3a65c78449f647a1a1bcd513775cfa64c8067400",
|
||||
"sha256:9c12c1c60b8616f97855d3a37ea4ec60e3d5d463965a6a29b80d0b794ad4f0d8"
|
||||
],
|
||||
"version": "==1.5.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b",
|
||||
"sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e"
|
||||
],
|
||||
"version": "==2.18.4"
|
||||
},
|
||||
"sanic": {
|
||||
"hashes": [
|
||||
"sha256:18a3bd729093ac93a245849c44045c505a11e6d36da5bf231cb986bfb1e3c14c",
|
||||
"sha256:22b1a6f1dc55db8a136335cb0961afa95040ca78aa8c78425a40d91e8618e60e"
|
||||
],
|
||||
"version": "==0.7.0"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb",
|
||||
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
|
||||
],
|
||||
"version": "==1.11.0"
|
||||
},
|
||||
"sqlalchemy": {
|
||||
"hashes": [
|
||||
"sha256:7dda3e0b1b12215e3bb05368d1abbf7d747112a43738e0a4e6deb466b83fd88e"
|
||||
],
|
||||
"version": "==1.2.0"
|
||||
},
|
||||
"sqlalchemy-aio": {
|
||||
"hashes": [
|
||||
"sha256:2c2a46504c999b4ae5751c90a86aa78cee8cc216f9d432264fb850ffe2d78965",
|
||||
"sha256:736ab30fed217bc9602824b8b7daafcd52e0e19eb4cf07a940d82de5981877e8"
|
||||
],
|
||||
"version": "==0.11.0"
|
||||
},
|
||||
"ujson": {
|
||||
"hashes": [
|
||||
"sha256:f66073e5506e91d204ab0c614a148d5aa938bdbf104751be66f8ad7a222f5f86"
|
||||
],
|
||||
"version": "==1.35"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b",
|
||||
"sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"
|
||||
],
|
||||
"version": "==1.22"
|
||||
},
|
||||
"uvloop": {
|
||||
"hashes": [
|
||||
"sha256:01cf7199728867f406ba5af78cc47c80acd663ccc52cae105e737a997f1b2bca",
|
||||
"sha256:e7c871ba3edd5fcf2afb756de88a9a65245070161e24f75abe79c0a241bb8c76",
|
||||
"sha256:b057ef2b0d0162c1ef257f43a95f59bfec37ee9a75cc5412d6b7f9ac6d1d69cb",
|
||||
"sha256:89c3bfaad77625490c42a6b99af1879234767ab0c31dd193486a909506e5e549",
|
||||
"sha256:68574150720a380509a3409bf2941be0199cfdacff144a97502fb29c250ba927",
|
||||
"sha256:7fba5f390db607b2f026bc598df6b2a2a9e062bffe82910b5ffe2b88560135e5",
|
||||
"sha256:7ee14835a75c72227d3f8a3f370519a3106a6f02e5453f275f16437ebdb92953"
|
||||
],
|
||||
"version": "==0.9.1"
|
||||
},
|
||||
"websockets": {
|
||||
"hashes": [
|
||||
"sha256:f5192da704535a7cbf76d6e99c1ec4af7e8d1288252bf5a2385d414509ded0cf",
|
||||
"sha256:0c31bc832d529dc7583d324eb6c836a4f362032a1902723c112cf57883488d8c",
|
||||
"sha256:da7610a017f5343fdf765f4e0eb6fd0dfd08264ca1565212b110836d9367fc9c",
|
||||
"sha256:fd81af8cf3e69f9a97f3a6c0623a0527de0f922c2df725f00cd7646d478af632",
|
||||
"sha256:3d425ae081fb4ba1eef9ecf30472ffd79f8e868297ccc7a47993c96dbf2a819c",
|
||||
"sha256:ebdd4f18fe7e3bea9bd3bf446b0f4117739478caa2c76e4f0fb72cc45b03cbd7",
|
||||
"sha256:3859ca16c229ddb0fa21c5090e4efcb037c08ce69b0c1dfed6122c3f98cd0c22",
|
||||
"sha256:d1a0572b6edb22c9208e3e5381064e09d287d2a915f90233fef994ee7a14a935",
|
||||
"sha256:80188abdadd23edaaea05ce761dc9a2e1df31a74a0533967f0dcd9560c85add0",
|
||||
"sha256:fecf51c13195c416c22422353b306dddb9c752e4b80b21e0fa1fccbe38246677",
|
||||
"sha256:367ff945bc0950ad9634591e2afe50bf2222bc4fad1088a386c4bb700888026e",
|
||||
"sha256:6df87698022aef2596bffdfecc96d656db59c8d719708c8a471daa815ee61656",
|
||||
"sha256:341824d8c9ad53fc43cca3fa9407f294125fa258592f7676640396501448e57e",
|
||||
"sha256:64896a6b3368c959b8096b655e46f03dfa65b96745249f374bd6a35705cc3489",
|
||||
"sha256:1f3e5a52cab6daa3d432c7b0de0a14109be39d2bfaad033ee5de4a3d3e11dcdf",
|
||||
"sha256:da4d4fbe059b0453e726d6d993760065d69b823a27efc3040402a6fcfe6a1ed9"
|
||||
],
|
||||
"version": "==4.0.1"
|
||||
},
|
||||
"werkzeug": {
|
||||
"hashes": [
|
||||
"sha256:f3000aa146ce8a9da8ca3e978e0e931c2a58eb56c323a5efb6b4307f7832b549",
|
||||
"sha256:6246e5fc98a505824113fb6aca993d45ea284a2bcffdc2c65d0c538e53e4abd3"
|
||||
],
|
||||
"version": "==0.13"
|
||||
},
|
||||
"yarl": {
|
||||
"hashes": [
|
||||
"sha256:55dfe4a952fddf3e32c08e3fe004a86b77963d95a4b36c8bdb5acc68960c4767",
|
||||
"sha256:5970e4deb2ad23ececbaca8e20e7421d66d84f9a8978eb7d469b931f0a7c5bfa",
|
||||
"sha256:6594f27c81012c9bcad46693b599ae3cb6086ef0c32af68160e599e69b7ce2e6",
|
||||
"sha256:6f662ff050945163fc70f6c4361807068f66b248d60d7f7d2fe35c6dce7e1490",
|
||||
"sha256:3c90b8b89d9e163fb114f8e491f85bc44aacc528d9ade3cb4a210a2340282b15",
|
||||
"sha256:c1f6aa4f6647380dfee6a2f560079d2c2b105a6d7ab7c1ad83bc811fc0df7bb2",
|
||||
"sha256:e6c302aa976504e4cf299b5ae5385677b77f84b71f84aeddcc56b8841743b27b",
|
||||
"sha256:e04c26c4fa6717ceeada129665cf19f630ddffb2df692bc5d51595b97227a5cf",
|
||||
"sha256:15ab97fd75bd531ba6e3e2639313db177ba44ec3a68bdd3f531904782872dfe9",
|
||||
"sha256:b3b2bfd039b6a89382ad46a20647286b012db34f63e00e39e185cb4df566121f",
|
||||
"sha256:620f76a2452f502333392c86074046af6fde72b54065e43530e8417d689b1824",
|
||||
"sha256:7a2001e180f169f762f9322066685f94808db5722ce7c4827a248d3f50d88e61",
|
||||
"sha256:47622985ecd9b15335d65c1acd54aeb3ba449e6d09b36e37ecfe334c7e7b8d0b"
|
||||
],
|
||||
"version": "==0.16.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
59
README.md
59
README.md
|
@ -1,48 +1,61 @@
|
|||
# Blockchain 101
|
||||
# Learn Blockchains by Building One
|
||||
|
||||
Simple blockchain written in python
|
||||
[![Build Status](https://travis-ci.org/dvf/blockchain.svg?branch=master)](https://travis-ci.org/dvf/blockchain)
|
||||
|
||||
This is the source code for my post on [Building a Blockchain](https://medium.com/p/117428612f46).
|
||||
|
||||
## Installation
|
||||
|
||||
1. Make sure [Python 3.6+](https://www.python.org/downloads/) is installed.
|
||||
2. Install [poetry](https://github.com/sdispater/poetry).
|
||||
3. Install requirements
|
||||
1. Make sure [Python 3.6+](https://www.python.org/downloads/) is installed.
|
||||
2. Install [pipenv](https://github.com/kennethreitz/pipenv).
|
||||
|
||||
```
|
||||
$ poetry install
|
||||
$ pip install pipenv
|
||||
```
|
||||
|
||||
4. Copy `.env.example` to `.env`
|
||||
3. Create a _virtual environment_ and specify the Python version to use.
|
||||
|
||||
5. Start some nodes:
|
||||
* `$ poetry run flask run -p 5000`
|
||||
* `$ poetry run flask run -p 5001`
|
||||
```
|
||||
$ pipenv --python=python3.6
|
||||
```
|
||||
|
||||
4. Install requirements.
|
||||
|
||||
```
|
||||
$ pipenv install
|
||||
```
|
||||
|
||||
5. Run the server:
|
||||
* `$ pipenv run python blockchain.py`
|
||||
* `$ pipenv run python blockchain.py -p 5001`
|
||||
* `$ pipenv run python blockchain.py --port 5002`
|
||||
|
||||
## Docker
|
||||
|
||||
Another option for running this blockchain program is to use Docker. Follow the instructions below to create a local Docker container:
|
||||
|
||||
1. Build the docker image
|
||||
1. Clone this repository
|
||||
2. Build the docker container
|
||||
|
||||
```
|
||||
$ docker-compose build
|
||||
$ docker build -t blockchain .
|
||||
```
|
||||
|
||||
2. Run the nodes
|
||||
3. Run the container
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
$ docker run --rm -p 80:5000 blockchain
|
||||
```
|
||||
|
||||
4. To add more nodes, add a new service to the `docker-compose.yml` file
|
||||
and adjust the port number.
|
||||
4. To add more instances, vary the public port number before the colon:
|
||||
|
||||
```yaml
|
||||
node2:
|
||||
build: .
|
||||
ports:
|
||||
- 5002:80
|
||||
```
|
||||
$ docker run --rm -p 81:5000 blockchain
|
||||
$ docker run --rm -p 82:5000 blockchain
|
||||
$ docker run --rm -p 83:5000 blockchain
|
||||
```
|
||||
|
||||
## Credits
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
|
||||
[dvf](github.com/dvf/) for the original blockchain code
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from database import Block, db
|
||||
from helpers import hash_block
|
||||
|
||||
|
||||
logger = logging.getLogger('root.blockchain')
|
||||
|
||||
|
||||
class Blockchain:
|
||||
def __init__(self):
|
||||
self.current_transactions = []
|
||||
self.difficulty = 4
|
||||
|
||||
# Create the genesis block if it doesn't exist
|
||||
if not self.last_block:
|
||||
block = self.build_block()
|
||||
block['hash'] = hash_block(block)
|
||||
self.save_block(block)
|
||||
|
||||
logger.info("✨ Created genesis block")
|
||||
|
||||
logger.info("Blockchain Initiated")
|
||||
|
||||
@staticmethod
|
||||
def get_blocks(height=0):
|
||||
"""
|
||||
Returns all blocks from a given height
|
||||
|
||||
:param height: <int> The height from which to return blocks
|
||||
:return:
|
||||
"""
|
||||
|
||||
blocks = db.query(Block).filter(Block.height >= height).all()
|
||||
return [block.to_dict() for block in blocks]
|
||||
|
||||
def valid_chain(self, chain):
|
||||
"""
|
||||
Determines if a given blockchain is valid
|
||||
|
||||
:param chain: A blockchain
|
||||
:return: True if valid, False if not
|
||||
"""
|
||||
|
||||
last_block = chain[0]
|
||||
current_index = 1
|
||||
|
||||
while current_index < len(chain):
|
||||
block = chain[current_index]
|
||||
|
||||
# Check that the hash_block of the block is correct
|
||||
if block['previous_hash'] != self.hash_block(last_block):
|
||||
return False
|
||||
|
||||
# Check that the Proof of Work is correct
|
||||
if not self.valid_proof(last_block['proof'], block['proof']):
|
||||
return False
|
||||
|
||||
last_block = block
|
||||
current_index += 1
|
||||
|
||||
return True
|
||||
|
||||
def build_block(self):
|
||||
"""
|
||||
Create a new Block in the Blockchain
|
||||
"""
|
||||
last_block = self.last_block
|
||||
|
||||
return {
|
||||
'height': last_block.height + 1 if last_block else 0,
|
||||
'timestamp': datetime.utcnow(),
|
||||
'transactions': self.current_transactions,
|
||||
'previous_hash': last_block.hash if last_block else 0,
|
||||
'proof': -1,
|
||||
}
|
||||
|
||||
def save_block(self, block_dict):
|
||||
"""
|
||||
Saves Block to the database and resets outstanding transactions
|
||||
|
||||
:param block_dict: A dictionary representation of a Block
|
||||
:return:
|
||||
"""
|
||||
print(block_dict)
|
||||
block = Block(**block_dict)
|
||||
db.add(block)
|
||||
db.commit()
|
||||
|
||||
# Reset the current list of transactions
|
||||
self.current_transactions = []
|
||||
|
||||
def new_transaction(self, sender, recipient, amount):
|
||||
"""
|
||||
Creates a new transaction to go into the next mined Block
|
||||
|
||||
:param sender: Address of the Sender
|
||||
:param recipient: Address of the Recipient
|
||||
:param amount: Amount
|
||||
:return: The index of the Block that will hold this transaction
|
||||
"""
|
||||
self.current_transactions.append({
|
||||
'sender': sender,
|
||||
'recipient': recipient,
|
||||
'amount': amount,
|
||||
})
|
||||
|
||||
return self.last_block['index'] + 1
|
||||
|
||||
@property
|
||||
def last_block(self):
|
||||
"""
|
||||
Returns the last block in the Blockchain (greatest height)
|
||||
|
||||
:return: <Block>
|
||||
"""
|
||||
return db.query(Block).order_by(Block.height.desc()).first()
|
|
@ -1,35 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .blockchain import Blockchain
|
||||
|
||||
blockchain = Blockchain()
|
||||
identifier = str(uuid4()).replace('-', '')
|
||||
|
||||
|
||||
def init_routers(app):
|
||||
from .routers import misc
|
||||
app.include_router(
|
||||
misc.router,
|
||||
prefix='',
|
||||
tags=['misc'],
|
||||
)
|
||||
|
||||
from .routers import nodes
|
||||
app.include_router(
|
||||
nodes.router,
|
||||
prefix='/nodes',
|
||||
tags=['nodes'],
|
||||
)
|
||||
|
||||
|
||||
def create_app():
|
||||
app = FastAPI()
|
||||
init_routers(app)
|
||||
|
||||
return app
|
|
@ -1,204 +0,0 @@
|
|||
import hashlib
|
||||
from decimal import Decimal
|
||||
from time import time
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
from .utils import dumps, do_process_pow, valid_proof
|
||||
|
||||
DIFFICULTY = 8
|
||||
|
||||
|
||||
class Blockchain:
|
||||
def __init__(self):
|
||||
self.current_transactions = []
|
||||
self.chain = []
|
||||
self.peers = set()
|
||||
|
||||
# Create the genesis block
|
||||
self.new_block(previous_hash='1', proof=100)
|
||||
|
||||
def register_node(self, address):
|
||||
"""
|
||||
Add a new node to the list of nodes
|
||||
|
||||
:param address: Address of the node
|
||||
"""
|
||||
|
||||
parsed_url = urlparse(address)
|
||||
if parsed_url.netloc:
|
||||
self.peers.add(parsed_url.netloc)
|
||||
elif parsed_url.path:
|
||||
# Accepts an URL without scheme like '192.168.0.5:5000'.
|
||||
self.peers.add(parsed_url.path)
|
||||
else:
|
||||
raise ValueError('Invalid URL')
|
||||
|
||||
def valid_chain(self, chain):
|
||||
"""
|
||||
Determine if a given blockchain is valid
|
||||
|
||||
:param chain: A blockchain
|
||||
:return: True if valid, False if not
|
||||
"""
|
||||
|
||||
last_block = chain[0]
|
||||
current_index = 1
|
||||
|
||||
while current_index < len(chain):
|
||||
block = chain[current_index]
|
||||
# print(f'{last_block}')
|
||||
# print(f'{block}')
|
||||
# print("\n-----------\n")
|
||||
# Check that the hash of the block is correct
|
||||
last_block_hash = self.hash(last_block)
|
||||
if block['previous_hash'] != last_block_hash:
|
||||
return False
|
||||
|
||||
# Check that the Proof of Work is correct
|
||||
if not valid_proof(last_block['proof'], block['proof'], last_block_hash, DIFFICULTY):
|
||||
return False
|
||||
|
||||
last_block = block
|
||||
current_index += 1
|
||||
|
||||
return True
|
||||
|
||||
def resolve_conflicts(self):
|
||||
"""
|
||||
This is our consensus algorithm, it resolves conflicts
|
||||
by replacing our chain with the longest one in the network.
|
||||
|
||||
:return: True if our chain was replaced, False if not
|
||||
"""
|
||||
|
||||
new_chain = None
|
||||
|
||||
# We're only looking for chains longer than ours
|
||||
max_length = len(self.chain)
|
||||
|
||||
# Grab and verify the chains from all the peers in our network
|
||||
for node in self.peers:
|
||||
response = requests.get(f'http://{node}/chain')
|
||||
|
||||
if response.status_code == 200:
|
||||
length = response.json()['length']
|
||||
chain = response.json()['chain']
|
||||
|
||||
# Check if the length is longer and the chain is valid
|
||||
if length > max_length and self.valid_chain(chain):
|
||||
max_length = length
|
||||
new_chain = chain
|
||||
|
||||
# Replace our chain if we discovered a new, valid chain longer than ours
|
||||
if new_chain:
|
||||
self.chain = new_chain
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def new_block(self, proof, previous_hash):
|
||||
"""
|
||||
Create a new Block in the Blockchain
|
||||
|
||||
:param proof: The proof given by the Proof of Work algorithm
|
||||
:param previous_hash: Hash of previous Block
|
||||
:return: New Block
|
||||
"""
|
||||
|
||||
block = {
|
||||
'index': len(self.chain) + 1,
|
||||
'timestamp': time(),
|
||||
'transactions': self.current_transactions,
|
||||
'proof': proof,
|
||||
'previous_hash': previous_hash or self.hash(self.chain[-1]),
|
||||
}
|
||||
|
||||
self.current_transactions = []
|
||||
self.chain.append(block)
|
||||
|
||||
return block
|
||||
|
||||
def broadcast_transaction(self, transaction):
|
||||
for node in self.peers:
|
||||
response = requests.post(
|
||||
f'http://{node}/transactions',
|
||||
data=dumps(transaction, separators=(",", ":")),
|
||||
headers={'content-type': 'application/json'},
|
||||
)
|
||||
|
||||
if response.status_code != 202:
|
||||
print(f'Failed to send transaction to node {node}', response)
|
||||
|
||||
def new_transaction(self, sender, recipient, amount, timestamp=None, mine=False):
|
||||
"""
|
||||
Creates a new transaction to go into the next mined Block
|
||||
|
||||
:param sender: Address of the Sender
|
||||
:param recipient: Address of the Recipient
|
||||
:param amount: Amount
|
||||
:return: The index of the Block that will hold this transaction
|
||||
"""
|
||||
transaction = {
|
||||
'sender': sender,
|
||||
'recipient': recipient,
|
||||
'amount': amount,
|
||||
'timestamp': timestamp or time(),
|
||||
}
|
||||
if transaction not in self.current_transactions:
|
||||
self.current_transactions.append(transaction)
|
||||
print(f'added transaction to list {mine}')
|
||||
if not mine:
|
||||
self.broadcast_transaction(transaction)
|
||||
|
||||
@property
|
||||
def last_block(self):
|
||||
return self.chain[-1]
|
||||
|
||||
@staticmethod
|
||||
def hash(block):
|
||||
"""
|
||||
Creates a SHA-256 hash of a Block
|
||||
|
||||
:param block: Block
|
||||
"""
|
||||
block_string = dumps(block, separators=(",", ":"), sort_keys=True).encode()
|
||||
|
||||
return hashlib.sha256(block_string).hexdigest()
|
||||
|
||||
def proof_of_work(self, last_block):
|
||||
"""
|
||||
Simple Proof of Work Algorithm:
|
||||
|
||||
- Find a number p' such that hash(pp') contains leading DIFFICULTY zeroes
|
||||
- Where p is the previous proof, and p' is the new proof
|
||||
|
||||
:param last_block: <dict> last Block
|
||||
:return: <int>
|
||||
"""
|
||||
|
||||
last_proof = last_block['proof']
|
||||
last_hash = self.hash(last_block)
|
||||
|
||||
return do_process_pow(last_proof, last_hash, DIFFICULTY)
|
||||
|
||||
def get_balance(self, identifier):
|
||||
"""
|
||||
Returns the balance of a node, by iterating through all transactions
|
||||
|
||||
:param identifier: <str> node identifier
|
||||
:return: <int> balance of the node
|
||||
"""
|
||||
if not self.valid_chain(self.chain):
|
||||
return None
|
||||
|
||||
balance = Decimal(0)
|
||||
for block in self.chain:
|
||||
for transaction in block['transactions']:
|
||||
if transaction['sender'] == identifier:
|
||||
balance -= transaction['amount']
|
||||
if transaction['recipient'] == identifier:
|
||||
balance += transaction['amount']
|
||||
|
||||
return balance
|
|
@ -1,7 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2020 <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the BSD 3-Clause license.
|
|
@ -1,69 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2020 <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the BSD 3-Clause license.
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .. import blockchain, identifier
|
||||
from ..schemas import Transaction
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post('/mine', status_code=200)
|
||||
async def mine():
|
||||
last_block = blockchain.last_block
|
||||
proof = blockchain.proof_of_work(last_block)
|
||||
blockchain.new_transaction(
|
||||
sender='0',
|
||||
recipient=identifier,
|
||||
amount=Decimal(1),
|
||||
timestamp=None,
|
||||
mine=True,
|
||||
)
|
||||
|
||||
previous_hash = blockchain.hash(last_block)
|
||||
block = blockchain.new_block(proof, previous_hash)
|
||||
|
||||
return {
|
||||
'msg': 'New Block Forged',
|
||||
'index': block['index'],
|
||||
'transactions': block['transactions'],
|
||||
'proof': block['proof'],
|
||||
'previous_hash': block['previous_hash'],
|
||||
}
|
||||
|
||||
|
||||
@router.post('/transactions', status_code=202)
|
||||
async def create_transaction(request: Transaction):
|
||||
blockchain.new_transaction(
|
||||
request.sender,
|
||||
request.recipient,
|
||||
request.amount,
|
||||
request.timestamp,
|
||||
)
|
||||
|
||||
return {
|
||||
'msg': f'Transaction sent'
|
||||
}
|
||||
|
||||
|
||||
@router.get('/chain', status_code=200)
|
||||
async def full_chain():
|
||||
return {
|
||||
'chain': blockchain.chain,
|
||||
'length': len(blockchain.chain),
|
||||
}
|
||||
|
||||
|
||||
@router.get('/identifier', status_code=200)
|
||||
async def get_identifier():
|
||||
return {
|
||||
'identifier': identifier
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2020 <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the BSD 3-Clause license.
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .. import blockchain
|
||||
from ..schemas import NodeList
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get('/', status_code=200)
|
||||
async def get_nodes():
|
||||
return {
|
||||
'nodes': list(blockchain.peers),
|
||||
}
|
||||
|
||||
|
||||
@router.get('/{identifier}/balance', status_code=200)
|
||||
async def get_balance(identifier: str):
|
||||
balance = blockchain.get_balance(identifier)
|
||||
if balance is None:
|
||||
return {
|
||||
'msg': 'Chain is not valid',
|
||||
}, 500
|
||||
|
||||
return {
|
||||
'identifier': identifier,
|
||||
'balance': balance,
|
||||
}
|
||||
|
||||
|
||||
@router.post('/register', status_code=201)
|
||||
async def register_nodes(request: NodeList):
|
||||
if None in (request.nodes,):
|
||||
return {'msg': 'No valid list of nodes'}, 400
|
||||
|
||||
for node in request.nodes:
|
||||
blockchain.register_node(node)
|
||||
|
||||
return {
|
||||
'msg': 'New peers have been added',
|
||||
'peers': list(blockchain.peers),
|
||||
}
|
||||
|
||||
|
||||
@router.post('/resolve', status_code=200)
|
||||
async def consensus():
|
||||
replaced = blockchain.resolve_conflicts()
|
||||
|
||||
if replaced:
|
||||
message = 'Our chain was replaced'
|
||||
else:
|
||||
message = 'Our chain is authoritative'
|
||||
|
||||
return {
|
||||
'msg': message,
|
||||
'chain': blockchain.chain,
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2020 <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the BSD 3-Clause license.
|
||||
|
||||
from decimal import Decimal
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class NodeList(BaseModel):
|
||||
nodes: List[str]
|
||||
|
||||
|
||||
class Transaction(BaseModel):
|
||||
sender: str
|
||||
recipient: str
|
||||
amount: Decimal
|
||||
timestamp: float = None
|
|
@ -1,110 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2020 <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the BSD 3-Clause license.
|
||||
|
||||
import hashlib
|
||||
import itertools
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from multiprocessing import (
|
||||
cpu_count,
|
||||
Pool,
|
||||
Process,
|
||||
Queue
|
||||
)
|
||||
|
||||
|
||||
class DecimalJsonEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return super(DecimalJsonEncoder, self).default(obj)
|
||||
|
||||
|
||||
def dumps(*data, **kwargs):
|
||||
return json.dumps(
|
||||
data,
|
||||
cls=DecimalJsonEncoder,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
def do_pooled_pow(last_proof, last_hash, difficulty):
|
||||
queue = Queue()
|
||||
with Pool(1) as p:
|
||||
result = p.starmap_async(pool_worker, ((
|
||||
queue,
|
||||
i,
|
||||
last_proof,
|
||||
last_hash,
|
||||
difficulty,
|
||||
) for i in itertools.count()), chunksize=100)
|
||||
|
||||
proof = queue.get()
|
||||
result.wait()
|
||||
p.terminate()
|
||||
|
||||
return proof
|
||||
|
||||
|
||||
def pool_worker(queue, proof, last_proof, last_hash, difficulty):
|
||||
if valid_proof(last_proof, proof, last_hash):
|
||||
queue.put(proof)
|
||||
return proof
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def do_process_pow(last_proof, last_hash, difficulty):
|
||||
queue = Queue()
|
||||
processes = [
|
||||
Process(
|
||||
target=process_worker,
|
||||
args=(
|
||||
queue,
|
||||
last_proof,
|
||||
last_hash,
|
||||
difficulty,
|
||||
step,
|
||||
)
|
||||
) for step in range(cpu_count())
|
||||
]
|
||||
for p in processes:
|
||||
p.start()
|
||||
|
||||
proof = queue.get()
|
||||
for p in processes:
|
||||
p.terminate()
|
||||
|
||||
return proof
|
||||
|
||||
|
||||
def process_worker(queue, last_proof, last_hash, difficulty, step):
|
||||
proof = step
|
||||
while not valid_proof(last_proof, proof, last_hash, difficulty):
|
||||
proof += step
|
||||
|
||||
queue.put(proof)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def valid_proof(last_proof, proof, last_hash, difficulty):
|
||||
"""
|
||||
Validates the Proof
|
||||
|
||||
:param last_proof: <int> Previous Proof
|
||||
:param proof: <int> Current Proof
|
||||
:param last_hash: <str> The hash of the Previous Block
|
||||
:return: <bool> True if correct, False if not.
|
||||
"""
|
||||
|
||||
guess = f'{last_proof}{proof}{last_hash}'.encode()
|
||||
guess_hash = hashlib.sha256(guess)
|
||||
binary_hash = ''.join(format(n, '08b') for n in guess_hash.digest())
|
||||
|
||||
return binary_hash[:difficulty] == '0' * difficulty
|
|
@ -0,0 +1,57 @@
|
|||
from sqlalchemy import Column, DateTime, Integer, PickleType, String, create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base, declared_attr
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
|
||||
|
||||
# Set up the Database
|
||||
engine = create_engine('sqlite:///electron.db')
|
||||
db = scoped_session(sessionmaker(bind=engine))
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class BaseModel(Base):
|
||||
__abstract__ = True
|
||||
|
||||
@declared_attr
|
||||
def __tablename__(self):
|
||||
"""
|
||||
Ensures all tables have the same name as their models (below)
|
||||
"""
|
||||
return self.__name__.lower()
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Helper method to convert any database row to dict
|
||||
"""
|
||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||
|
||||
|
||||
class Peer(BaseModel):
|
||||
identifier = Column(String(32), primary_key=True)
|
||||
hostname = Column(String, index=True, unique=True)
|
||||
timestamp = Column(DateTime, index=True)
|
||||
|
||||
|
||||
class Block(BaseModel):
|
||||
height = Column(Integer, primary_key=True)
|
||||
timestamp = Column(DateTime, index=True)
|
||||
transactions = Column(PickleType)
|
||||
previous_hash = Column(String(64))
|
||||
proof = Column(String(64))
|
||||
hash = Column(String(64))
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
key = Column(String(64), primary_key=True, unique=True)
|
||||
value = Column(PickleType)
|
||||
|
||||
|
||||
def reset_db():
|
||||
"""
|
||||
Drops and Re-creates the Database
|
||||
"""
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
version: '3'
|
||||
services:
|
||||
node0:
|
||||
build: .
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5000:80
|
||||
|
||||
node1:
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5001:80
|
||||
|
||||
node2:
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5002:80
|
||||
|
||||
node3:
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5003:80
|
||||
|
||||
node4:
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5004:80
|
||||
|
||||
node5:
|
||||
image: blockchain
|
||||
ports:
|
||||
- 5005:80
|
||||
|
||||
# node6:
|
||||
# image: blockchain
|
||||
# ports:
|
||||
# - 5006:80
|
||||
|
||||
# node7:
|
||||
# image: blockchain
|
||||
# ports:
|
||||
# - 5007:80
|
||||
|
||||
# node8:
|
||||
# image: blockchain
|
||||
# ports:
|
||||
# - 5008:80
|
||||
|
||||
# node9:
|
||||
# image: blockchain
|
||||
# ports:
|
||||
# - 5009:80
|
|
@ -0,0 +1,52 @@
|
|||
from hashlib import sha256
|
||||
|
||||
from sqlalchemy import func
|
||||
|
||||
from database import Config, Peer, db
|
||||
|
||||
|
||||
def set_config(key, value, replace=False):
|
||||
config_value = get_config(key)
|
||||
|
||||
if config_value is None:
|
||||
db.add(Config(key=key, value=value))
|
||||
db.commit()
|
||||
return value
|
||||
|
||||
if config_value != value and replace is True:
|
||||
db.add(Config(key=key, value=value))
|
||||
db.commit()
|
||||
return value
|
||||
|
||||
return config_value
|
||||
|
||||
|
||||
def get_config(key, default=None):
|
||||
config = db.query(Config).filter_by(key=key).first()
|
||||
if config:
|
||||
return config.value
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def get_random_peers(limit=10):
|
||||
"""
|
||||
Returns random peers
|
||||
|
||||
:param limit: How many peers to return
|
||||
:return:
|
||||
"""
|
||||
return db.query(Peer).order_by(func.random()).limit(limit)
|
||||
|
||||
|
||||
def hash_block(block):
|
||||
"""
|
||||
Creates a SHA-256 hash_block of the fields for a Block
|
||||
"""
|
||||
byte_array = f"{block['height']}" \
|
||||
f"{block['timestamp']}" \
|
||||
f"{block['transactions']}" \
|
||||
f"{block['previous_hash']}" \
|
||||
f"{block['proof']}".encode()
|
||||
|
||||
return sha256(byte_array).hexdigest()
|
46
init
46
init
|
@ -1,46 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function register_nodes() {
|
||||
from=$1
|
||||
to_list=$2
|
||||
for to in $to_list; do
|
||||
http POST localhost:500$from/nodes/register \
|
||||
nodes:="[\"http://node$to\"]"
|
||||
done
|
||||
}
|
||||
|
||||
function synchronise_nodes() {
|
||||
http POST localhost:5000/nodes/resolve
|
||||
http POST localhost:5001/nodes/resolve
|
||||
}
|
||||
|
||||
NODE0_ID=$(http localhost:5000/identifier | jq -r ".identifier")
|
||||
NODE1_ID=$(http localhost:5001/identifier | jq -r ".identifier")
|
||||
|
||||
register_nodes "0" "1 3 4"
|
||||
register_nodes "1" "0 5"
|
||||
register_nodes "2" "5"
|
||||
register_nodes "3" "0 4"
|
||||
register_nodes "4" "0 3 5"
|
||||
register_nodes "5" "1 2 4"
|
||||
|
||||
# # Mine a few initial blocks
|
||||
http POST localhost:5000/mine
|
||||
http POST localhost:5000/mine
|
||||
http POST localhost:5001/nodes/resolve
|
||||
http POST localhost:5003/nodes/resolve
|
||||
http POST localhost:5005/nodes/resolve
|
||||
http POST localhost:5002/nodes/resolve
|
||||
# synchronise_nodes >/dev/null
|
||||
|
||||
# http POST localhost:5000/transactions sender=$NODE0_ID recipient=$NODE1_ID amount=1.3
|
||||
# http POST localhost:5000/mine
|
||||
# synchronise_nodes >/dev/null
|
||||
|
||||
# http localhost:5000/nodes/$NODE0_ID/balance
|
||||
# http localhost:5000/nodes/$NODE1_ID/balance
|
||||
|
||||
# echo node0: $NODE0_ID
|
||||
# echo node1: $NODE1_ID
|
|
@ -0,0 +1,75 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import multiprocessing
|
||||
from datetime import datetime
|
||||
|
||||
from helpers import hash_block
|
||||
from tasks import we_should_still_be_mining
|
||||
|
||||
|
||||
log = logging.getLogger('root.mining')
|
||||
|
||||
|
||||
def proof_of_work(current_block, difficulty, event):
|
||||
"""
|
||||
Simple Proof of Work Algorithm
|
||||
|
||||
:param current_block: The partially complete block currently being mined
|
||||
:param difficulty: The minimum number of leading zeros
|
||||
"""
|
||||
|
||||
# String of 64 f's replaced with 3 leading zeros (if the difficulty is 3): 000fff...f
|
||||
target = str.ljust("0" * difficulty, 64, "f")
|
||||
|
||||
guess_hash = hash_block(current_block)
|
||||
|
||||
while guess_hash > target:
|
||||
# Check if we should still be mining
|
||||
# if not event.is_set():
|
||||
# raise Exception("STOP MINING")
|
||||
current_block['timestamp'] = datetime.utcnow()
|
||||
current_block['proof'] += 1
|
||||
guess_hash = hash_block(current_block)
|
||||
|
||||
current_block['hash'] = guess_hash
|
||||
return current_block
|
||||
|
||||
|
||||
def miner(pipe, event):
|
||||
while True:
|
||||
task = pipe.recv()
|
||||
log.debug(f"Received new mining task with difficulty {task['difficulty']}")
|
||||
|
||||
if task:
|
||||
found_block = proof_of_work(task['block'], task['difficulty'], event)
|
||||
pipe.send({'found_block': found_block})
|
||||
|
||||
|
||||
async def mining_controller(app):
|
||||
pipe, remote_pipe = multiprocessing.Pipe()
|
||||
event = multiprocessing.Event()
|
||||
|
||||
# Spawn a new process consisting of the miner() function
|
||||
# and send the right end of the pipe to it
|
||||
process = multiprocessing.Process(target=miner, args=(remote_pipe, event))
|
||||
process.start()
|
||||
|
||||
pipe.send({'block': app.blockchain.build_block(), 'difficulty': 5})
|
||||
|
||||
while True:
|
||||
event.set()
|
||||
|
||||
# We'll check the pipe every 100 ms
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
# Check if we should still be mining
|
||||
if not we_should_still_be_mining():
|
||||
event.clear()
|
||||
|
||||
if pipe.poll():
|
||||
result = pipe.recv()
|
||||
found_block = result['found_block']
|
||||
|
||||
app.blockchain.save_block(found_block)
|
||||
log.info(f"Mined Block {found_block['height']} containing {len(found_block['transactions'])} transactions")
|
||||
pipe.send({'block': app.blockchain.build_block(), 'difficulty': 5})
|
|
@ -0,0 +1,65 @@
|
|||
import miniupnpc
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
log = logging.getLogger('root.networking')
|
||||
|
||||
|
||||
class PortMapper(object):
|
||||
def __init__(self):
|
||||
client = miniupnpc.UPnP()
|
||||
client.discoverdelay = 200
|
||||
|
||||
try:
|
||||
log.info('Searching for Internet Gateway Devices... (timeout: %sms)', client.discoverdelay)
|
||||
device_count = client.discover()
|
||||
|
||||
log.info('Found %s devices', device_count)
|
||||
|
||||
self.client = client
|
||||
self.device_count = device_count
|
||||
self.internal_ip = None
|
||||
self.external_ip = None
|
||||
self.external_port = None
|
||||
|
||||
except Exception as e:
|
||||
log.error('An unexpected error occurred: %s', e)
|
||||
self.client = None
|
||||
|
||||
def add_portmapping(self, internal_port, external_port, protocol, label=''):
|
||||
if self.client is None:
|
||||
log.error('No uPnP devices were found on the network')
|
||||
return
|
||||
|
||||
try:
|
||||
self.client.selectigd()
|
||||
|
||||
self.internal_ip = self.client.lanaddr
|
||||
self.external_ip = self.client.externalipaddress()
|
||||
|
||||
log.info('Internal IP: %s', self.internal_ip)
|
||||
log.info('External IP: %s', self.external_ip)
|
||||
|
||||
log.info('Attempting %s redirect: %s:%s -> %s:%s', protocol,
|
||||
self.external_ip, external_port,
|
||||
self.internal_ip, internal_port)
|
||||
|
||||
# Find an available port for the redirect
|
||||
port_mapping = self.client.getspecificportmapping(external_port, protocol)
|
||||
while port_mapping is None and external_port < 65536:
|
||||
external_port += 1
|
||||
port_mapping = self.client.getspecificportmapping(external_port, protocol)
|
||||
|
||||
success = self.client.addportmapping(external_port, protocol, self.internal_ip, internal_port, label, '')
|
||||
|
||||
if success:
|
||||
log.info('Successful %s redirect: %s:%s -> %s:%s', protocol,
|
||||
self.external_ip, external_port,
|
||||
self.internal_ip, internal_port)
|
||||
self.external_port = external_port
|
||||
else:
|
||||
log.error('Failed to map a port')
|
||||
|
||||
except Exception as e:
|
||||
log.error('An unexpected error occurred: %s', e)
|
|
@ -0,0 +1,41 @@
|
|||
from sanic import Sanic
|
||||
from sanic.response import json
|
||||
from sqlalchemy import func
|
||||
|
||||
from database import Peer, db, reset_db
|
||||
from tasks import initiate_node, peer_discovery
|
||||
from mining import mining_controller
|
||||
|
||||
|
||||
app = Sanic()
|
||||
|
||||
reset_db()
|
||||
initiate_node(app)
|
||||
|
||||
app.add_task(peer_discovery(app))
|
||||
app.add_task(mining_controller(app))
|
||||
|
||||
|
||||
@app.route("/")
|
||||
async def peers(request):
|
||||
random_peers = db.query(Peer).order_by(func.random()).limit(256).all()
|
||||
return json(random_peers)
|
||||
|
||||
|
||||
@app.route("/transactions")
|
||||
async def current_transactions(request):
|
||||
if request.method == 'GET':
|
||||
return json(app.blockchain.current_transactions)
|
||||
elif request.method == 'POST':
|
||||
return json({"text": "thanks for your transaction"})
|
||||
|
||||
|
||||
@app.route("/blocks")
|
||||
async def blocks(request):
|
||||
# height = request.parsed_args['height']
|
||||
random_blocks = app.blockchain.get_blocks()
|
||||
return json(random_blocks)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=False, host="0.0.0.0", port=8080)
|
|
@ -1,267 +0,0 @@
|
|||
[[package]]
|
||||
category = "main"
|
||||
description = "Python package for providing Mozilla's CA Bundle."
|
||||
name = "certifi"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "2019.11.28"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Universal encoding detector for Python 2 and 3"
|
||||
name = "chardet"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "3.0.4"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Composable command line interface toolkit"
|
||||
name = "click"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
||||
version = "7.0"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
|
||||
name = "fastapi"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
version = "0.48.0"
|
||||
|
||||
[package.dependencies]
|
||||
pydantic = ">=0.32.2,<2.0.0"
|
||||
starlette = "0.12.9"
|
||||
|
||||
[package.extras]
|
||||
all = ["requests", "aiofiles", "jinja2", "python-multipart", "itsdangerous", "pyyaml", "graphene", "ujson", "email-validator", "uvicorn", "async-exit-stack", "async-generator"]
|
||||
dev = ["pyjwt", "passlib", "autoflake", "flake8", "uvicorn", "graphene"]
|
||||
doc = ["mkdocs", "mkdocs-material", "markdown-include"]
|
||||
test = ["pytest (>=4.0.0)", "pytest-cov", "mypy", "black", "isort", "requests", "email-validator", "sqlalchemy", "peewee", "databases", "orjson", "async-exit-stack", "async-generator"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1"
|
||||
name = "h11"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.9.0"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "A collection of framework independent HTTP protocol utils."
|
||||
marker = "sys_platform != \"win32\" and sys_platform != \"cygwin\" and platform_python_implementation != \"pypy\""
|
||||
name = "httptools"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.0.13"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||
name = "idna"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
||||
version = "2.8"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Data validation and settings management using python 3.6 type hinting"
|
||||
name = "pydantic"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
version = "1.4"
|
||||
|
||||
[package.extras]
|
||||
dotenv = ["python-dotenv (>=0.10.4)"]
|
||||
email = ["email-validator (>=1.0.3)"]
|
||||
typing_extensions = ["typing-extensions (>=3.7.2)"]
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "Add .env support to your django/flask apps in development and deployments"
|
||||
name = "python-dotenv"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.10.5"
|
||||
|
||||
[package.extras]
|
||||
cli = ["click (>=5.0)"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Python HTTP for Humans."
|
||||
name = "requests"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
version = "2.22.0"
|
||||
|
||||
[package.dependencies]
|
||||
certifi = ">=2017.4.17"
|
||||
chardet = ">=3.0.2,<3.1.0"
|
||||
idna = ">=2.5,<2.9"
|
||||
urllib3 = ">=1.21.1,<1.25.0 || >1.25.0,<1.25.1 || >1.25.1,<1.26"
|
||||
|
||||
[package.extras]
|
||||
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)"]
|
||||
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "The little ASGI library that shines."
|
||||
name = "starlette"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
version = "0.12.9"
|
||||
|
||||
[package.extras]
|
||||
full = ["aiofiles", "graphene", "itsdangerous", "jinja2", "python-multipart", "pyyaml", "requests", "ujson"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
name = "urllib3"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
|
||||
version = "1.25.8"
|
||||
|
||||
[package.extras]
|
||||
brotli = ["brotlipy (>=0.6.0)"]
|
||||
secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
|
||||
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "The lightning-fast ASGI server."
|
||||
name = "uvicorn"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.11.2"
|
||||
|
||||
[package.dependencies]
|
||||
click = ">=7.0.0,<8.0.0"
|
||||
h11 = ">=0.8,<0.10"
|
||||
httptools = "0.0.13"
|
||||
uvloop = ">=0.14.0"
|
||||
websockets = ">=8.0.0,<9.0.0"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "Fast implementation of asyncio event loop on top of libuv"
|
||||
marker = "sys_platform != \"win32\" and sys_platform != \"cygwin\" and platform_python_implementation != \"pypy\""
|
||||
name = "uvloop"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.14.0"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)"
|
||||
name = "websockets"
|
||||
optional = false
|
||||
python-versions = ">=3.6.1"
|
||||
version = "8.1"
|
||||
|
||||
[metadata]
|
||||
content-hash = "bd7659287574f6e4041d1f1a687f7ed818fdebcb9ea3ddd9fdf16ede2279db6f"
|
||||
python-versions = "^3.8"
|
||||
|
||||
[metadata.files]
|
||||
certifi = [
|
||||
{file = "certifi-2019.11.28-py2.py3-none-any.whl", hash = "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3"},
|
||||
{file = "certifi-2019.11.28.tar.gz", hash = "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"},
|
||||
]
|
||||
chardet = [
|
||||
{file = "chardet-3.0.4-py2.py3-none-any.whl", hash = "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"},
|
||||
{file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"},
|
||||
]
|
||||
click = [
|
||||
{file = "Click-7.0-py2.py3-none-any.whl", hash = "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13"},
|
||||
{file = "Click-7.0.tar.gz", hash = "sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"},
|
||||
]
|
||||
fastapi = [
|
||||
{file = "fastapi-0.48.0-py3-none-any.whl", hash = "sha256:87d409d3ac3957713c016ba3b28fa5214e0903d4351cc3fe486b170d29e8aacd"},
|
||||
{file = "fastapi-0.48.0.tar.gz", hash = "sha256:2e00347f6a84291a5f04302733fbcf7c2ad9c674c0d0448cbee661db0e01ca16"},
|
||||
]
|
||||
h11 = [
|
||||
{file = "h11-0.9.0-py2.py3-none-any.whl", hash = "sha256:4bc6d6a1238b7615b266ada57e0618568066f57dd6fa967d1290ec9309b2f2f1"},
|
||||
{file = "h11-0.9.0.tar.gz", hash = "sha256:33d4bca7be0fa039f4e84d50ab00531047e53d6ee8ffbc83501ea602c169cae1"},
|
||||
]
|
||||
httptools = [
|
||||
{file = "httptools-0.0.13.tar.gz", hash = "sha256:e00cbd7ba01ff748e494248183abc6e153f49181169d8a3d41bb49132ca01dfc"},
|
||||
]
|
||||
idna = [
|
||||
{file = "idna-2.8-py2.py3-none-any.whl", hash = "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"},
|
||||
{file = "idna-2.8.tar.gz", hash = "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407"},
|
||||
]
|
||||
pydantic = [
|
||||
{file = "pydantic-1.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:07911aab70f3bc52bb845ce1748569c5e70478ac977e106a150dd9d0465ebf04"},
|
||||
{file = "pydantic-1.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:012c422859bac2e03ab3151ea6624fecf0e249486be7eb8c6ee69c91740c6752"},
|
||||
{file = "pydantic-1.4-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:61d22d36808087d3184ed6ac0d91dd71c533b66addb02e4a9930e1e30833202f"},
|
||||
{file = "pydantic-1.4-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:f863456d3d4bf817f2e5248553dee3974c5dc796f48e6ddb599383570f4215ac"},
|
||||
{file = "pydantic-1.4-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:bbbed364376f4a0aebb9ea452ff7968b306499a9e74f4db69b28ff2cd4043a11"},
|
||||
{file = "pydantic-1.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e27559cedbd7f59d2375bfd6eea29a330ea1a5b0589c34d6b4e0d7bec6027bbf"},
|
||||
{file = "pydantic-1.4-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:50e4e948892a6815649ad5a9a9379ad1e5f090f17842ac206535dfaed75c6f2f"},
|
||||
{file = "pydantic-1.4-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:8848b4eb458469739126e4c1a202d723dd092e087f8dbe3104371335f87ba5df"},
|
||||
{file = "pydantic-1.4-cp38-cp38-manylinux1_i686.whl", hash = "sha256:831a0265a9e3933b3d0f04d1a81bba543bafbe4119c183ff2771871db70524ab"},
|
||||
{file = "pydantic-1.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:47b8db7024ba3d46c3d4768535e1cf87b6c8cf92ccd81e76f4e1cb8ee47688b3"},
|
||||
{file = "pydantic-1.4-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:51f11c8bbf794a68086540da099aae4a9107447c7a9d63151edbb7d50110cf21"},
|
||||
{file = "pydantic-1.4-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:6100d7862371115c40be55cc4b8d766a74b1d0dbaf99dbfe72bb4bac0faf89ed"},
|
||||
{file = "pydantic-1.4-py36.py37.py38-none-any.whl", hash = "sha256:72184c1421103cca128300120f8f1185fb42a9ea73a1c9845b1c53db8c026a7d"},
|
||||
{file = "pydantic-1.4.tar.gz", hash = "sha256:f17ec336e64d4583311249fb179528e9a2c27c8a2eaf590ec6ec2c6dece7cb3f"},
|
||||
]
|
||||
python-dotenv = [
|
||||
{file = "python-dotenv-0.10.5.tar.gz", hash = "sha256:f254bfd0c970d64ccbb6c9ebef3667ab301a71473569c991253a481f1c98dddc"},
|
||||
{file = "python_dotenv-0.10.5-py2.py3-none-any.whl", hash = "sha256:440c7c23d53b7d352f9c94d6f70860242c2f071cf5c029dd661ccb22d64ae42b"},
|
||||
]
|
||||
requests = [
|
||||
{file = "requests-2.22.0-py2.py3-none-any.whl", hash = "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"},
|
||||
{file = "requests-2.22.0.tar.gz", hash = "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4"},
|
||||
]
|
||||
starlette = [
|
||||
{file = "starlette-0.12.9.tar.gz", hash = "sha256:c2ac9a42e0e0328ad20fe444115ac5e3760c1ee2ac1ff8cdb5ec915c4a453411"},
|
||||
]
|
||||
urllib3 = [
|
||||
{file = "urllib3-1.25.8-py2.py3-none-any.whl", hash = "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc"},
|
||||
{file = "urllib3-1.25.8.tar.gz", hash = "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc"},
|
||||
]
|
||||
uvicorn = [
|
||||
{file = "uvicorn-0.11.2-py3-none-any.whl", hash = "sha256:4a35496af38e4deeec911f4af99b0bace19669c986210b0a950ad2b7bfd5737a"},
|
||||
{file = "uvicorn-0.11.2.tar.gz", hash = "sha256:11f397855c7f35dc034a3d288883382a4c16afdfe6675b70896f55bd6051da64"},
|
||||
]
|
||||
uvloop = [
|
||||
{file = "uvloop-0.14.0-cp35-cp35m-macosx_10_11_x86_64.whl", hash = "sha256:08b109f0213af392150e2fe6f81d33261bb5ce968a288eb698aad4f46eb711bd"},
|
||||
{file = "uvloop-0.14.0-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:4544dcf77d74f3a84f03dd6278174575c44c67d7165d4c42c71db3fdc3860726"},
|
||||
{file = "uvloop-0.14.0-cp36-cp36m-macosx_10_11_x86_64.whl", hash = "sha256:b4f591aa4b3fa7f32fb51e2ee9fea1b495eb75b0b3c8d0ca52514ad675ae63f7"},
|
||||
{file = "uvloop-0.14.0-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:f07909cd9fc08c52d294b1570bba92186181ca01fe3dc9ffba68955273dd7362"},
|
||||
{file = "uvloop-0.14.0-cp37-cp37m-macosx_10_11_x86_64.whl", hash = "sha256:afd5513c0ae414ec71d24f6f123614a80f3d27ca655a4fcf6cabe50994cc1891"},
|
||||
{file = "uvloop-0.14.0-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:e7514d7a48c063226b7d06617cbb12a14278d4323a065a8d46a7962686ce2e95"},
|
||||
{file = "uvloop-0.14.0-cp38-cp38-macosx_10_11_x86_64.whl", hash = "sha256:bcac356d62edd330080aed082e78d4b580ff260a677508718f88016333e2c9c5"},
|
||||
{file = "uvloop-0.14.0-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:4315d2ec3ca393dd5bc0b0089d23101276778c304d42faff5dc4579cb6caef09"},
|
||||
{file = "uvloop-0.14.0.tar.gz", hash = "sha256:123ac9c0c7dd71464f58f1b4ee0bbd81285d96cdda8bc3519281b8973e3a461e"},
|
||||
]
|
||||
websockets = [
|
||||
{file = "websockets-8.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:3762791ab8b38948f0c4d281c8b2ddfa99b7e510e46bd8dfa942a5fff621068c"},
|
||||
{file = "websockets-8.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:3db87421956f1b0779a7564915875ba774295cc86e81bc671631379371af1170"},
|
||||
{file = "websockets-8.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4f9f7d28ce1d8f1295717c2c25b732c2bc0645db3215cf757551c392177d7cb8"},
|
||||
{file = "websockets-8.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:295359a2cc78736737dd88c343cd0747546b2174b5e1adc223824bcaf3e164cb"},
|
||||
{file = "websockets-8.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:1d3f1bf059d04a4e0eb4985a887d49195e15ebabc42364f4eb564b1d065793f5"},
|
||||
{file = "websockets-8.1-cp36-cp36m-win32.whl", hash = "sha256:2db62a9142e88535038a6bcfea70ef9447696ea77891aebb730a333a51ed559a"},
|
||||
{file = "websockets-8.1-cp36-cp36m-win_amd64.whl", hash = "sha256:0e4fb4de42701340bd2353bb2eee45314651caa6ccee80dbd5f5d5978888fed5"},
|
||||
{file = "websockets-8.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:9b248ba3dd8a03b1a10b19efe7d4f7fa41d158fdaa95e2cf65af5a7b95a4f989"},
|
||||
{file = "websockets-8.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:ce85b06a10fc65e6143518b96d3dca27b081a740bae261c2fb20375801a9d56d"},
|
||||
{file = "websockets-8.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:965889d9f0e2a75edd81a07592d0ced54daa5b0785f57dc429c378edbcffe779"},
|
||||
{file = "websockets-8.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:751a556205d8245ff94aeef23546a1113b1dd4f6e4d102ded66c39b99c2ce6c8"},
|
||||
{file = "websockets-8.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3ef56fcc7b1ff90de46ccd5a687bbd13a3180132268c4254fc0fa44ecf4fc422"},
|
||||
{file = "websockets-8.1-cp37-cp37m-win32.whl", hash = "sha256:7ff46d441db78241f4c6c27b3868c9ae71473fe03341340d2dfdbe8d79310acc"},
|
||||
{file = "websockets-8.1-cp37-cp37m-win_amd64.whl", hash = "sha256:20891f0dddade307ffddf593c733a3fdb6b83e6f9eef85908113e628fa5a8308"},
|
||||
{file = "websockets-8.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:c1ec8db4fac31850286b7cd3b9c0e1b944204668b8eb721674916d4e28744092"},
|
||||
{file = "websockets-8.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:5c01fd846263a75bc8a2b9542606927cfad57e7282965d96b93c387622487485"},
|
||||
{file = "websockets-8.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:9bef37ee224e104a413f0780e29adb3e514a5b698aabe0d969a6ba426b8435d1"},
|
||||
{file = "websockets-8.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:d705f8aeecdf3262379644e4b55107a3b55860eb812b673b28d0fbc347a60c55"},
|
||||
{file = "websockets-8.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:c8a116feafdb1f84607cb3b14aa1418424ae71fee131642fc568d21423b51824"},
|
||||
{file = "websockets-8.1-cp38-cp38-win32.whl", hash = "sha256:e898a0863421650f0bebac8ba40840fc02258ef4714cb7e1fd76b6a6354bda36"},
|
||||
{file = "websockets-8.1-cp38-cp38-win_amd64.whl", hash = "sha256:f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b"},
|
||||
{file = "websockets-8.1.tar.gz", hash = "sha256:5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f"},
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
[tool.poetry]
|
||||
name = "blockchain"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Pavle Portic <pavle.portic@tilda.center>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8"
|
||||
requests = "^2.22.0"
|
||||
fastapi = {extras = ["uvicorn"], version = "^0.48.0"}
|
||||
uvicorn = "^0.11.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
python-dotenv = "^0.10.5"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry>=0.12"]
|
||||
build-backend = "poetry.masonry.api"
|
|
@ -1,79 +0,0 @@
|
|||
certifi==2019.11.28 \
|
||||
--hash=sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3 \
|
||||
--hash=sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f
|
||||
chardet==3.0.4 \
|
||||
--hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \
|
||||
--hash=sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae
|
||||
click==7.0 \
|
||||
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
|
||||
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7
|
||||
fastapi==0.48.0 \
|
||||
--hash=sha256:87d409d3ac3957713c016ba3b28fa5214e0903d4351cc3fe486b170d29e8aacd \
|
||||
--hash=sha256:2e00347f6a84291a5f04302733fbcf7c2ad9c674c0d0448cbee661db0e01ca16
|
||||
h11==0.9.0 \
|
||||
--hash=sha256:4bc6d6a1238b7615b266ada57e0618568066f57dd6fa967d1290ec9309b2f2f1 \
|
||||
--hash=sha256:33d4bca7be0fa039f4e84d50ab00531047e53d6ee8ffbc83501ea602c169cae1
|
||||
httptools==0.0.13; sys_platform != "win32" and sys_platform != "cygwin" and platform_python_implementation != "pypy" \
|
||||
--hash=sha256:e00cbd7ba01ff748e494248183abc6e153f49181169d8a3d41bb49132ca01dfc
|
||||
idna==2.8 \
|
||||
--hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \
|
||||
--hash=sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407
|
||||
pydantic==1.4 \
|
||||
--hash=sha256:07911aab70f3bc52bb845ce1748569c5e70478ac977e106a150dd9d0465ebf04 \
|
||||
--hash=sha256:012c422859bac2e03ab3151ea6624fecf0e249486be7eb8c6ee69c91740c6752 \
|
||||
--hash=sha256:61d22d36808087d3184ed6ac0d91dd71c533b66addb02e4a9930e1e30833202f \
|
||||
--hash=sha256:f863456d3d4bf817f2e5248553dee3974c5dc796f48e6ddb599383570f4215ac \
|
||||
--hash=sha256:bbbed364376f4a0aebb9ea452ff7968b306499a9e74f4db69b28ff2cd4043a11 \
|
||||
--hash=sha256:e27559cedbd7f59d2375bfd6eea29a330ea1a5b0589c34d6b4e0d7bec6027bbf \
|
||||
--hash=sha256:50e4e948892a6815649ad5a9a9379ad1e5f090f17842ac206535dfaed75c6f2f \
|
||||
--hash=sha256:8848b4eb458469739126e4c1a202d723dd092e087f8dbe3104371335f87ba5df \
|
||||
--hash=sha256:831a0265a9e3933b3d0f04d1a81bba543bafbe4119c183ff2771871db70524ab \
|
||||
--hash=sha256:47b8db7024ba3d46c3d4768535e1cf87b6c8cf92ccd81e76f4e1cb8ee47688b3 \
|
||||
--hash=sha256:51f11c8bbf794a68086540da099aae4a9107447c7a9d63151edbb7d50110cf21 \
|
||||
--hash=sha256:6100d7862371115c40be55cc4b8d766a74b1d0dbaf99dbfe72bb4bac0faf89ed \
|
||||
--hash=sha256:72184c1421103cca128300120f8f1185fb42a9ea73a1c9845b1c53db8c026a7d \
|
||||
--hash=sha256:f17ec336e64d4583311249fb179528e9a2c27c8a2eaf590ec6ec2c6dece7cb3f
|
||||
requests==2.22.0 \
|
||||
--hash=sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31 \
|
||||
--hash=sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4
|
||||
starlette==0.12.9 \
|
||||
--hash=sha256:c2ac9a42e0e0328ad20fe444115ac5e3760c1ee2ac1ff8cdb5ec915c4a453411
|
||||
urllib3==1.25.8 \
|
||||
--hash=sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc \
|
||||
--hash=sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc
|
||||
uvicorn==0.11.2 \
|
||||
--hash=sha256:4a35496af38e4deeec911f4af99b0bace19669c986210b0a950ad2b7bfd5737a \
|
||||
--hash=sha256:11f397855c7f35dc034a3d288883382a4c16afdfe6675b70896f55bd6051da64
|
||||
uvloop==0.14.0; sys_platform != "win32" and sys_platform != "cygwin" and platform_python_implementation != "pypy" \
|
||||
--hash=sha256:08b109f0213af392150e2fe6f81d33261bb5ce968a288eb698aad4f46eb711bd \
|
||||
--hash=sha256:4544dcf77d74f3a84f03dd6278174575c44c67d7165d4c42c71db3fdc3860726 \
|
||||
--hash=sha256:b4f591aa4b3fa7f32fb51e2ee9fea1b495eb75b0b3c8d0ca52514ad675ae63f7 \
|
||||
--hash=sha256:f07909cd9fc08c52d294b1570bba92186181ca01fe3dc9ffba68955273dd7362 \
|
||||
--hash=sha256:afd5513c0ae414ec71d24f6f123614a80f3d27ca655a4fcf6cabe50994cc1891 \
|
||||
--hash=sha256:e7514d7a48c063226b7d06617cbb12a14278d4323a065a8d46a7962686ce2e95 \
|
||||
--hash=sha256:bcac356d62edd330080aed082e78d4b580ff260a677508718f88016333e2c9c5 \
|
||||
--hash=sha256:4315d2ec3ca393dd5bc0b0089d23101276778c304d42faff5dc4579cb6caef09 \
|
||||
--hash=sha256:123ac9c0c7dd71464f58f1b4ee0bbd81285d96cdda8bc3519281b8973e3a461e
|
||||
websockets==8.1 \
|
||||
--hash=sha256:3762791ab8b38948f0c4d281c8b2ddfa99b7e510e46bd8dfa942a5fff621068c \
|
||||
--hash=sha256:3db87421956f1b0779a7564915875ba774295cc86e81bc671631379371af1170 \
|
||||
--hash=sha256:4f9f7d28ce1d8f1295717c2c25b732c2bc0645db3215cf757551c392177d7cb8 \
|
||||
--hash=sha256:295359a2cc78736737dd88c343cd0747546b2174b5e1adc223824bcaf3e164cb \
|
||||
--hash=sha256:1d3f1bf059d04a4e0eb4985a887d49195e15ebabc42364f4eb564b1d065793f5 \
|
||||
--hash=sha256:2db62a9142e88535038a6bcfea70ef9447696ea77891aebb730a333a51ed559a \
|
||||
--hash=sha256:0e4fb4de42701340bd2353bb2eee45314651caa6ccee80dbd5f5d5978888fed5 \
|
||||
--hash=sha256:9b248ba3dd8a03b1a10b19efe7d4f7fa41d158fdaa95e2cf65af5a7b95a4f989 \
|
||||
--hash=sha256:ce85b06a10fc65e6143518b96d3dca27b081a740bae261c2fb20375801a9d56d \
|
||||
--hash=sha256:965889d9f0e2a75edd81a07592d0ced54daa5b0785f57dc429c378edbcffe779 \
|
||||
--hash=sha256:751a556205d8245ff94aeef23546a1113b1dd4f6e4d102ded66c39b99c2ce6c8 \
|
||||
--hash=sha256:3ef56fcc7b1ff90de46ccd5a687bbd13a3180132268c4254fc0fa44ecf4fc422 \
|
||||
--hash=sha256:7ff46d441db78241f4c6c27b3868c9ae71473fe03341340d2dfdbe8d79310acc \
|
||||
--hash=sha256:20891f0dddade307ffddf593c733a3fdb6b83e6f9eef85908113e628fa5a8308 \
|
||||
--hash=sha256:c1ec8db4fac31850286b7cd3b9c0e1b944204668b8eb721674916d4e28744092 \
|
||||
--hash=sha256:5c01fd846263a75bc8a2b9542606927cfad57e7282965d96b93c387622487485 \
|
||||
--hash=sha256:9bef37ee224e104a413f0780e29adb3e514a5b698aabe0d969a6ba426b8435d1 \
|
||||
--hash=sha256:d705f8aeecdf3262379644e4b55107a3b55860eb812b673b28d0fbc347a60c55 \
|
||||
--hash=sha256:c8a116feafdb1f84607cb3b14aa1418424ae71fee131642fc568d21423b51824 \
|
||||
--hash=sha256:e898a0863421650f0bebac8ba40840fc02258ef4714cb7e1fd76b6a6354bda36 \
|
||||
--hash=sha256:f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b \
|
||||
--hash=sha256:5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f
|
7
run.py
7
run.py
|
@ -1,7 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
|
||||
from blockchain import create_app
|
||||
|
||||
app = create_app()
|
|
@ -0,0 +1,64 @@
|
|||
import asyncio
|
||||
import logging
|
||||
from uuid import uuid4
|
||||
|
||||
import aiohttp
|
||||
|
||||
from blockchain import Blockchain
|
||||
from database import db
|
||||
from helpers import get_config, get_random_peers, set_config
|
||||
from networking import PortMapper
|
||||
|
||||
|
||||
log = logging.getLogger('root.tasks')
|
||||
|
||||
|
||||
def initiate_node(app):
|
||||
# Set up TCP Redirect (Port Forwarding)
|
||||
# port_mapper = PortMapper()
|
||||
# port_mapper.add_portmapping(8080, 8080, 'TCP', 'Electron')
|
||||
|
||||
# Set the identifier (unique Id) for our node (if it doesn't exist)
|
||||
node_identifier = set_config(key='node_identifier', value=uuid4().hex)
|
||||
|
||||
# app.request_headers = {
|
||||
# 'content-type': 'application/json',
|
||||
# 'x-node-identifier': node_identifier,
|
||||
# 'x-node-ip': port_mapper.external_ip,
|
||||
# 'x-node-port': port_mapper.external_port,
|
||||
# }
|
||||
|
||||
log.info('Node Identifier: %s', node_identifier)
|
||||
|
||||
# Add the Blockchain helper class to the app
|
||||
app.blockchain = Blockchain()
|
||||
|
||||
|
||||
async def peer_discovery(app):
|
||||
"""
|
||||
Ask random peers to return peers they know about
|
||||
"""
|
||||
while True:
|
||||
peers = get_random_peers()
|
||||
|
||||
for peer in peers:
|
||||
try:
|
||||
response = await aiohttp.request('GET', 'peer.hostname', headers=app.request_headers)
|
||||
print(f'Made request: {response.status}')
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
db.delete(peer)
|
||||
db.commit()
|
||||
print(f'{peer.hostname}: Deleted node')
|
||||
|
||||
await asyncio.sleep(10)
|
||||
|
||||
|
||||
async def watch_blockchain(app):
|
||||
while True:
|
||||
print(f'TXN: {app.blockchain.current_transactions}')
|
||||
await asyncio.sleep(2)
|
||||
|
||||
|
||||
def we_should_still_be_mining():
|
||||
return True
|
|
@ -11,7 +11,7 @@ class BlockchainTestCase(TestCase):
|
|||
self.blockchain = Blockchain()
|
||||
|
||||
def create_block(self, proof=123, previous_hash='abc'):
|
||||
self.blockchain.new_block(proof, previous_hash)
|
||||
self.blockchain.build_block(proof, previous_hash)
|
||||
|
||||
def create_transaction(self, sender='a', recipient='b', amount=1):
|
||||
self.blockchain.new_transaction(
|
||||
|
@ -101,4 +101,4 @@ class TestHashingAndProofs(BlockchainTestCase):
|
|||
new_hash = hashlib.sha256(new_block_json).hexdigest()
|
||||
|
||||
assert len(new_hash) == 64
|
||||
assert new_hash == self.blockchain.hash(new_block)
|
||||
assert new_hash == self.blockchain.hash_block(new_block)
|
||||
|
|
Loading…
Reference in New Issue