OSDN Git Service

add create_address_qrcode
authorChengcheng Zhang <943420582@qq.com>
Thu, 10 Jan 2019 08:26:38 +0000 (16:26 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 10 Jan 2019 08:26:38 +0000 (16:26 +0800)
app/api/__init__.py
app/api/resources.py
app/model/receiver.py
requirements.txt

index da6fb2e..cec8bc8 100644 (file)
@@ -19,6 +19,7 @@ from app.api.resources import Create_P2WPKH_Program
 from app.api.resources import Create_Address
 from app.api.resources import Get_Path_From_Index
 from app.api.resources import Broadcast_Transaction
+from app.api.resources import Create_Address_QRcode
 
 blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
 api = Api(blueprint)
@@ -40,4 +41,5 @@ api.add_resource(Xpub_To_Child_Xpub, '/xpub_to_child_xpub')
 api.add_resource(Create_P2WPKH_Program, '/create_P2WPKH_program')
 api.add_resource(Create_Address, '/create_address')
 api.add_resource(Get_Path_From_Index, '/get_path_from_index')
-api.add_resource(Broadcast_Transaction, '/broadcast_transaction')
\ No newline at end of file
+api.add_resource(Broadcast_Transaction, '/broadcast_transaction')
+api.add_resource(Create_Address_QRcode, '/create_address_qrcode')
\ No newline at end of file
index f6301ba..36c5091 100644 (file)
@@ -19,8 +19,10 @@ from app.model.key import xpub_to_child_xpub
 from app.model.receiver import create_P2WPKH_program
 from app.model.receiver import create_address
 from app.model.receiver import get_path_from_index
+from app.model.receiver import create_address_qrcode
 from app.model.transaction import broadcast_transaction
 
+
 parser = reqparse.RequestParser()
 parser.add_argument('private_key_str', type=str)
 parser.add_argument('message_str', type=str)
@@ -38,6 +40,7 @@ parser.add_argument('change_bool', type=inputs.boolean)
 parser.add_argument('control_program_str', type=str)
 parser.add_argument('network_str', type=str)
 parser.add_argument('raw_transaction_str', type=str)
+parser.add_argument('address_str', type=str)
 
 class Hello(Resource):
 
@@ -192,4 +195,12 @@ class Broadcast_Transaction(Resource):
         raw_transaction = args.get('raw_transaction_str')
         network = args.get('network_str')
         response = broadcast_transaction(raw_transaction, network)
-        return response
\ No newline at end of file
+        return response
+
+class Create_Address_QRcode(Resource):
+
+    def post(self):
+        args = parser.parse_args()
+        address = args.get('address_str')
+        img = create_address_qrcode(address)
+        return img
\ No newline at end of file
index 4bdae05..cff56e7 100644 (file)
@@ -1,6 +1,9 @@
 import hashlib
 from app.model.key import *
 from app.model import segwit_addr
+import qrcode
+import pybase64
+from io import BytesIO
 
 # get_path_from_index create xpub path from account key index and current address index
 # path: purpose(0x2c=44)/coin_type(btm:0x99)/account_index/change(1 or 0)/address_index
@@ -119,4 +122,12 @@ def create_address(control_program_str, network_str):
     else:
         hrp = 'sm'
     address_str = segwit_addr.encode(hrp, 0, bytes.fromhex(public_key_hash_str))
-    return address_str
\ No newline at end of file
+    return address_str
+
+# create_address_qrcode create address qrcode, then encode it to base64
+def create_address_qrcode(address_str):
+    img = qrcode.make(address_str)
+    buffered = BytesIO()
+    img.save(buffered, format="JPEG")
+    return pybase64.b64encode(buffered.getvalue()).decode("utf-8")
+
index d55d8df..8d1d0ab 100644 (file)
@@ -1,22 +1,36 @@
 aniso8601==4.0.1
 astroid==2.1.0
+atomicwrites==1.2.1
+attrs==18.2.0
 certifi==2018.11.29
 chardet==3.0.4
 Click==7.0
+Django==2.1.5
 ed25519==1.4
 Flask==1.0.2
 Flask-RESTful==0.3.7
+flask-restplus==0.12.1
 idna==2.8
+image==1.5.27
 isort==4.3.4
 itsdangerous==1.1.0
 Jinja2==2.10
+jsonschema==2.6.0
 lazy-object-proxy==1.3.1
 MarkupSafe==1.1.0
 mccabe==0.6.1
+more-itertools==4.3.0
 pbkdf2==1.3
+Pillow==5.4.1
+pluggy==0.8.0
+py==1.7.0
+pybase64==0.4.0
 pylint==2.2.2
 pysha3==1.0.2
+pytest==4.0.1
+python-dotenv==0.10.0
 pytz==2018.7
+qrcode==6.0
 requests==2.21.0
 sha3==0.2.1
 simplejson==3.16.0