22from hashlib import sha256
33import argparse
44
5- DEFAULT_URL = "http://0.0.0.0:5000/api/v1/faucet"
5+ DEFAULT_URL = "http://0.0.0.0:5000"
6+
7+ def request_settings (url ):
8+ return get ("{}/api/v1/faucet/setting" .format (url )).json ()
69
710def request_challenge (url ):
8- return get (url ).json ()
11+ return get ("{}/api/v1/faucet" . format ( url ) ).json ()
912
1013def request_transfer (url , data ):
11- return post (url , json = data )
14+ return post ("{}/api/v1/faucet" . format ( url ) , json = data )
1215
1316def is_valid_pow (solution , difficulty ):
1417 for i in range (0 , difficulty ):
@@ -32,24 +35,28 @@ def compute_pow_solution(challenge, difficulty):
3235
3336if __name__ == '__main__' :
3437 parser = argparse .ArgumentParser (description = 'Request from an amount of token from faucet.' )
35- parser .add_argument ('url' , action = 'store' , type = str , required = False , default = DEFAULT_URL , help = 'The faucet url.' )
36- parser .add_argument ('token' , action = 'store' , type = int , required = False , help = 'The token address.' )
37- parser .add_argument ('amount' , action = 'store' , type = int , required = False , default = 1000 , help = 'The token amount.' )
38- parser .add_argument ('target' , action = 'store' , type = str , required = True , help = 'The target address.' )
38+ parser .add_argument ('url' , action = 'store' , type = str , default = DEFAULT_URL , help = 'The faucet url.' )
39+ parser .add_argument ('token' , action = 'store' , type = str , help = 'The token address.' )
40+ parser .add_argument ('amount' , action = 'store' , type = int , default = 1000 , help = 'The token amount.' )
41+ parser .add_argument ('target' , action = 'store' , type = str , help = 'The target address.' )
3942
4043 args = parser .parse_args ()
4144
45+ response = request_settings (args .url )
46+ difficulty = int (response ['difficulty' ])
47+
4248 response = request_challenge (args .url )
43- solution = compute_pow_solution (args .url , response ['challenge' ], 2 )
44- response = request_transfer ({
49+ solution = compute_pow_solution (response ['challenge' ], difficulty )
50+
51+ response = request_transfer (args .url , {
4552 'solution' : solution ,
4653 'tag' : response ['tag' ],
4754 'challenge' : response ['challenge' ],
4855 'transfer' : {
4956 'target' : args .target ,
5057 'token' : args .token ,
51- 'amount' : args .amounr * 10 ** 6
58+ 'amount' : args .amount * 10 ** 6
5259 }
5360 })
5461
55- print (response .json ())
62+ # print(response.json())
0 commit comments