from app.api.resources import Get_Gm_New_Key
from app.api.resources import Get_Gm_New_Address
from app.api.resources import Decode_Raw_Tx
+from app.api.resources import Get_Testnet_Coins
+from app.api.resources import Get_Gm_Testnet_Coins
blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
api.add_resource(Get_Gm_Address, '/get_gm_address')
api.add_resource(Get_Gm_New_Key, '/get_gm_new_key')
api.add_resource(Get_Gm_New_Address, '/get_gm_new_address')
-api.add_resource(Decode_Raw_Tx, '/decode_raw_tx')
\ No newline at end of file
+api.add_resource(Decode_Raw_Tx, '/decode_raw_tx')
+api.add_resource(Get_Testnet_Coins, '/get_testnet_coins')
+api.add_resource(Get_Gm_Testnet_Coins, '/get_gm_testnet_coins')
\ No newline at end of file
from app.model.key_gm import get_gm_new_key
from app.model.receiver import get_gm_new_address
from app.model.transaction import decode_raw_tx
+from app.model.faucet import get_testnet_coins
+from app.model.faucet import get_gm_testnet_coins
parser = reqparse.RequestParser()
parser.add_argument('raw_transaction_str', type=str)
parser.add_argument('address_str', type=str)
parser.add_argument('s', type=str)
+parser.add_argument('receiver_str', type=str)
class Hello(Resource):
network = args.get('network_str')
raw_transaction = args.get('raw_transaction_str')
tx = decode_raw_tx(raw_transaction, network)
- return tx
\ No newline at end of file
+ return tx
+
+class Get_Testnet_Coins(Resource):
+
+ def post(self):
+ args = parser.parse_args()
+ receiver = args.get('receiver_str')
+ tx_id = get_testnet_coins(receiver)
+ return tx_id
+
+class Get_Gm_Testnet_Coins(Resource):
+
+ def post(self):
+ args = parser.parse_args()
+ receiver = args.get('receiver_str')
+ tx_id = get_gm_testnet_coins(receiver)
+ return tx_id
\ No newline at end of file
--- /dev/null
+import requests
+import json
+
+def get_testnet_coins(receiver_str):
+ transaction_dict = {
+ "actions":[
+ {
+ "account_id":"0KN9JNBA00A02",
+ "amount":1020000000,
+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "type":"spend_account",
+ "use_unconfirmed":True
+ },
+ {
+ "amount":1000000000,
+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "address":receiver_str,
+ "type":"control_address"
+ }
+ ],
+ "ttl":0,
+ "time_range":0
+ }
+ transaction_json = json.dumps(transaction_dict)
+ headers = {
+ "content-type": "application/json",
+ "accept": "application/json"
+ }
+ build_url = "http://127.0.0.1:9888/build-transaction"
+ response = requests.post(build_url, data=transaction_json).json()
+ built_transaction_dict = {
+ "password": "12345",
+ "transaction": response['data']
+ }
+ built_transaction_json = json.dumps(built_transaction_dict)
+ sign_url = "http://127.0.0.1:9888/sign-transaction"
+ response = requests.post(sign_url, headers=headers, data=built_transaction_json).json()
+ signed_transaction_dict = {
+ "raw_transaction": response['data']['transaction']['raw_transaction']
+ }
+ signed_transaction_json = json.dumps(signed_transaction_dict)
+ submit_url = "http://127.0.0.1:9888/submit-transaction"
+ response = requests.post(submit_url, headers=headers, data=signed_transaction_json).json()
+ return {
+ "tx_id": response['data']['tx_id']
+ }
+
+def get_gm_testnet_coins(receiver_str):
+ transaction_dict = {
+ "actions":[
+ {
+ "account_id":"0KN9JNBA00A02",
+ "amount":1020000000,
+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "type":"spend_account",
+ "use_unconfirmed":True
+ },
+ {
+ "amount":1000000000,
+ "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "address":receiver_str,
+ "type":"control_address"
+ }
+ ],
+ "ttl":0,
+ "time_range":0
+ }
+ transaction_json = json.dumps(transaction_dict)
+ headers = {
+ "content-type": "application/json",
+ "accept": "application/json"
+ }
+ build_url = "http://127.0.0.1:9889/build-transaction"
+ response = requests.post(build_url, data=transaction_json).json()
+ built_transaction_dict = {
+ "password": "12345",
+ "transaction": response['data']
+ }
+ built_transaction_json = json.dumps(built_transaction_dict)
+ sign_url = "http://127.0.0.1:9889/sign-transaction"
+ response = requests.post(sign_url, headers=headers, data=built_transaction_json).json()
+ signed_transaction_dict = {
+ "raw_transaction": response['data']['transaction']['raw_transaction']
+ }
+ signed_transaction_json = json.dumps(signed_transaction_dict)
+ submit_url = "http://127.0.0.1:9889/submit-transaction"
+ response = requests.post(submit_url, headers=headers, data=signed_transaction_json).json()
+ return {
+ "tx_id": response['data']['tx_id']
+ }