• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-kit: Commit

kaleidoscope


Commit MetaInfo

Revisionfd95cb145c13fc339e057ce59d17aa395893ff2e (tree)
Time2019-04-02 19:57:16
AuthorChengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

add faucet

Change Summary

Incremental Difference

--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -36,6 +36,8 @@ from app.api.resources import Get_Gm_Address
3636 from app.api.resources import Get_Gm_New_Key
3737 from app.api.resources import Get_Gm_New_Address
3838 from app.api.resources import Decode_Raw_Tx
39+from app.api.resources import Get_Testnet_Coins
40+from app.api.resources import Get_Gm_Testnet_Coins
3941
4042
4143 blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
@@ -75,4 +77,6 @@ api.add_resource(Get_Gm_P2WPKH_Program, '/get_gm_P2WPKH_program')
7577 api.add_resource(Get_Gm_Address, '/get_gm_address')
7678 api.add_resource(Get_Gm_New_Key, '/get_gm_new_key')
7779 api.add_resource(Get_Gm_New_Address, '/get_gm_new_address')
78-api.add_resource(Decode_Raw_Tx, '/decode_raw_tx')
\ No newline at end of file
80+api.add_resource(Decode_Raw_Tx, '/decode_raw_tx')
81+api.add_resource(Get_Testnet_Coins, '/get_testnet_coins')
82+api.add_resource(Get_Gm_Testnet_Coins, '/get_gm_testnet_coins')
\ No newline at end of file
--- a/app/api/resources.py
+++ b/app/api/resources.py
@@ -36,6 +36,8 @@ from app.model.receiver import get_gm_address
3636 from app.model.key_gm import get_gm_new_key
3737 from app.model.receiver import get_gm_new_address
3838 from app.model.transaction import decode_raw_tx
39+from app.model.faucet import get_testnet_coins
40+from app.model.faucet import get_gm_testnet_coins
3941
4042
4143 parser = reqparse.RequestParser()
@@ -57,6 +59,7 @@ parser.add_argument('network_str', type=str)
5759 parser.add_argument('raw_transaction_str', type=str)
5860 parser.add_argument('address_str', type=str)
5961 parser.add_argument('s', type=str)
62+parser.add_argument('receiver_str', type=str)
6063
6164 class Hello(Resource):
6265
@@ -368,4 +371,20 @@ class Decode_Raw_Tx(Resource):
368371 network = args.get('network_str')
369372 raw_transaction = args.get('raw_transaction_str')
370373 tx = decode_raw_tx(raw_transaction, network)
371- return tx
\ No newline at end of file
374+ return tx
375+
376+class Get_Testnet_Coins(Resource):
377+
378+ def post(self):
379+ args = parser.parse_args()
380+ receiver = args.get('receiver_str')
381+ tx_id = get_testnet_coins(receiver)
382+ return tx_id
383+
384+class Get_Gm_Testnet_Coins(Resource):
385+
386+ def post(self):
387+ args = parser.parse_args()
388+ receiver = args.get('receiver_str')
389+ tx_id = get_gm_testnet_coins(receiver)
390+ return tx_id
\ No newline at end of file
--- /dev/null
+++ b/app/model/faucet.py
@@ -0,0 +1,90 @@
1+import requests
2+import json
3+
4+def get_testnet_coins(receiver_str):
5+ transaction_dict = {
6+ "actions":[
7+ {
8+ "account_id":"0KN9JNBA00A02",
9+ "amount":1020000000,
10+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
11+ "type":"spend_account",
12+ "use_unconfirmed":True
13+ },
14+ {
15+ "amount":1000000000,
16+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
17+ "address":receiver_str,
18+ "type":"control_address"
19+ }
20+ ],
21+ "ttl":0,
22+ "time_range":0
23+ }
24+ transaction_json = json.dumps(transaction_dict)
25+ headers = {
26+ "content-type": "application/json",
27+ "accept": "application/json"
28+ }
29+ build_url = "http://127.0.0.1:9888/build-transaction"
30+ response = requests.post(build_url, data=transaction_json).json()
31+ built_transaction_dict = {
32+ "password": "12345",
33+ "transaction": response['data']
34+ }
35+ built_transaction_json = json.dumps(built_transaction_dict)
36+ sign_url = "http://127.0.0.1:9888/sign-transaction"
37+ response = requests.post(sign_url, headers=headers, data=built_transaction_json).json()
38+ signed_transaction_dict = {
39+ "raw_transaction": response['data']['transaction']['raw_transaction']
40+ }
41+ signed_transaction_json = json.dumps(signed_transaction_dict)
42+ submit_url = "http://127.0.0.1:9888/submit-transaction"
43+ response = requests.post(submit_url, headers=headers, data=signed_transaction_json).json()
44+ return {
45+ "tx_id": response['data']['tx_id']
46+ }
47+
48+def get_gm_testnet_coins(receiver_str):
49+ transaction_dict = {
50+ "actions":[
51+ {
52+ "account_id":"0KN9JNBA00A02",
53+ "amount":1020000000,
54+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
55+ "type":"spend_account",
56+ "use_unconfirmed":True
57+ },
58+ {
59+ "amount":1000000000,
60+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
61+ "address":receiver_str,
62+ "type":"control_address"
63+ }
64+ ],
65+ "ttl":0,
66+ "time_range":0
67+ }
68+ transaction_json = json.dumps(transaction_dict)
69+ headers = {
70+ "content-type": "application/json",
71+ "accept": "application/json"
72+ }
73+ build_url = "http://127.0.0.1:9889/build-transaction"
74+ response = requests.post(build_url, data=transaction_json).json()
75+ built_transaction_dict = {
76+ "password": "12345",
77+ "transaction": response['data']
78+ }
79+ built_transaction_json = json.dumps(built_transaction_dict)
80+ sign_url = "http://127.0.0.1:9889/sign-transaction"
81+ response = requests.post(sign_url, headers=headers, data=built_transaction_json).json()
82+ signed_transaction_dict = {
83+ "raw_transaction": response['data']['transaction']['raw_transaction']
84+ }
85+ signed_transaction_json = json.dumps(signed_transaction_dict)
86+ submit_url = "http://127.0.0.1:9889/submit-transaction"
87+ response = requests.post(submit_url, headers=headers, data=signed_transaction_json).json()
88+ return {
89+ "tx_id": response['data']['tx_id']
90+ }
Show on old repository browser