kaleidoscope
Revision | fd95cb145c13fc339e057ce59d17aa395893ff2e (tree) |
---|---|
Time | 2019-04-02 19:57:16 |
Author | Chengcheng Zhang <943420582@qq.c...> |
Commiter | Chengcheng Zhang |
add faucet
@@ -36,6 +36,8 @@ from app.api.resources import Get_Gm_Address | ||
36 | 36 | from app.api.resources import Get_Gm_New_Key |
37 | 37 | from app.api.resources import Get_Gm_New_Address |
38 | 38 | 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 | |
39 | 41 | |
40 | 42 | |
41 | 43 | blueprint = Blueprint('api', __name__, url_prefix='/api/v1') |
@@ -75,4 +77,6 @@ api.add_resource(Get_Gm_P2WPKH_Program, '/get_gm_P2WPKH_program') | ||
75 | 77 | api.add_resource(Get_Gm_Address, '/get_gm_address') |
76 | 78 | api.add_resource(Get_Gm_New_Key, '/get_gm_new_key') |
77 | 79 | 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 |
@@ -36,6 +36,8 @@ from app.model.receiver import get_gm_address | ||
36 | 36 | from app.model.key_gm import get_gm_new_key |
37 | 37 | from app.model.receiver import get_gm_new_address |
38 | 38 | 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 | |
39 | 41 | |
40 | 42 | |
41 | 43 | parser = reqparse.RequestParser() |
@@ -57,6 +59,7 @@ parser.add_argument('network_str', type=str) | ||
57 | 59 | parser.add_argument('raw_transaction_str', type=str) |
58 | 60 | parser.add_argument('address_str', type=str) |
59 | 61 | parser.add_argument('s', type=str) |
62 | +parser.add_argument('receiver_str', type=str) | |
60 | 63 | |
61 | 64 | class Hello(Resource): |
62 | 65 |
@@ -368,4 +371,20 @@ class Decode_Raw_Tx(Resource): | ||
368 | 371 | network = args.get('network_str') |
369 | 372 | raw_transaction = args.get('raw_transaction_str') |
370 | 373 | 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 |
@@ -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 | + } |