6
6
import ast
7
7
8
8
import bitsource
9
- # import transactions
10
-
9
+ import transactions
10
+ import addresses
11
11
12
12
app = Flask (__name__ )
13
+ app .config ['PROPAGATE_EXCEPTIONS' ]= True
13
14
14
15
15
16
@app .route ('/' )
16
17
def something ():
17
- return "Hello there!"
18
+ response = "hey there!"
19
+ response .headers ['Access-Control-Allow-Origin' ]= '*'
20
+ return response
18
21
19
22
#GET HEX DECODED OP_RETURNS FROM A BLOCK
20
23
@app .route ('/opreturns/<blockn>' ) #WORKS
@@ -24,82 +27,106 @@ def opreturns_in_block(blockn=None):
24
27
message = bitsource .op_return_in_block (blockn )
25
28
return str (message )
26
29
27
- # #GET PARSED METADATA FOR OPEN ASSETS TRANSACTIONS IN BLOCK
28
- # @app.route('/oa/blocks/<blockn>') #WORKS, needs color address
29
- # def oas_in_block(blockn=None):
30
- # oas=bitsource.oa_in_block(int(blockn))
31
- # return str(oas)
32
- #
33
- #
34
- # @app.route('/colors/signed', methods=['POST'])
35
- # def makenewcoin():
36
- # public_address=str(request.form['public_address'])
37
- # initial_coins=float(request.form['initial_coins'])
38
- # name=str(request.form['name'])
39
- # recipient=str(request.form['recipient'])
40
- # fee_each=0.0001
41
- # private_key=str(request.form['private_keys'])
42
- #
43
- # response=transactions.make_new_coin(public_address, initial_coins, name, recipient, fee_each, private_key)
44
- # #print response
45
- # return response
46
- # #return "hi"
47
- #
48
- # @app.route('/transactions/colored', methods=['POST']) #DOESNT EXACTLY MATCH DOCS
49
- # def transfer_transaction_serverside():
50
- # fromaddr=str(request.form['public_address'])
51
- # dest=str(request.form['recipient'])
52
- # fee=float(request.form['fee']) #DOESNT MATCH DOCS
53
- # private_key=str(request.form['private_key'])
54
- # coloramt=int(request.form['coloramt'])
55
- #
56
- # inputs=json.dumps(request.form['inputs']) #INELEGANT BUT IT WORKS
57
- # inputs=ast.literal_eval(json.loads(inputs))
58
- #
59
- # inputcoloramt=int(request.form['inputcoloramt'])
60
- # response= transactions.create_transfer_tx(fromaddr, dest, fee, private_key, coloramt, inputs, inputcoloramt)
61
- # return str(response)
62
- #
63
- #
64
- # @app.route('/colors/issue/signed', methods=['POST']) #WORKS
65
- # def issuenewcoinsserverside(): #TO ONE RECIPIENT ADDRESS
66
- # private_key=str(request.form['private_keys'])
67
- # public_address=str(request.form['public_address'])
68
- # more_coins=int(request.form['initial_coins'])
69
- # recipient=str(request.form['recipients'])
70
- # fee_each=0.0001
71
- # name=str(request.form['name'])
72
- # othermeta=str(name)
73
- #
74
- # print private_key
75
- # response=transactions.create_issuing_tx(public_address, recipient, fee_each, private_key, more_coins, 0, othermeta)
76
- # return response
77
- # return str(name)
78
- #
79
- # @app.route('/colors/issue', methods = ['POST']) #WORKS
80
- # def issuenewcoins_clientside():
81
- # #JUST RETURN RAW HEX OF UNSIGNED TX
82
- # issuing_address=str(request.form['issuing_address'])
83
- # more_coins=int(request.form['more_coins'])
84
- # coin_recipients=str(request.form['coin_recipients']) #DISCREPANCY, SHOULD BE ARRAY for multiple
85
- # othermeta='COIN NAME HERE'
86
- #
87
- # fee=0.0001
88
- # print coin_recipients
89
- # print more_coins
90
- # print issuing_address
91
- # print fee
92
- # print othermeta
93
- # tx=transactions.create_issuing_tx_unsigned(issuing_address, coin_recipients, fee, more_coins,othermeta)
94
- # #return 'a'
95
- # return str(tx)
96
- #
97
- #
98
- # @app.route('/transactions', methods = ['POST'])
99
- # def pushtx():
100
- # txhex=str(request.form['transaction_hex'])
101
- # response=transactions.pushtx(txhex)
102
- # return str(response)
30
+ #GET PARSED METADATA FOR OPEN ASSETS TRANSACTIONS IN BLOCK
31
+ @app .route ('/oa/blocks/<blockn>' ) #WORKS, needs color address
32
+ def oas_in_block (blockn = None ):
33
+ oas = bitsource .oa_in_block (int (blockn ))
34
+ return str (oas )
35
+
36
+ @app .route ('/colors/signed' , methods = ['POST' ])
37
+ def makenewcoin ():
38
+ public_address = str (request .form ['public_address' ])
39
+ initial_coins = int (request .form ['initial_coins' ])
40
+ name = str (request .form ['name' ])
41
+ recipient = str (request .form ['recipient' ])
42
+ fee_each = 0.0001
43
+ private_key = str (request .form ['private_keys' ])
44
+ ticker = str (request .form ['ticker' ])
45
+ description = str (request .form ['description' ])
46
+
47
+ response = transactions .make_new_coin (public_address , initial_coins , name , recipient , fee_each , private_key , ticker , description )
48
+ #print response
49
+ return response
50
+ #return "hi"
51
+
52
+ @app .route ('/transactions/colored' , methods = ['POST' ]) #DOESNT EXACTLY MATCH DOCS
53
+ def transfer_transaction_serverside ():
54
+ fromaddr = str (request .form ['public_address' ])
55
+ dest = str (request .form ['recipient' ])
56
+ fee = float (request .form ['fee' ]) #DOESNT MATCH DOCS
57
+ private_key = str (request .form ['private_key' ])
58
+ coloramt = int (request .form ['coloramt' ])
59
+
60
+ #inputs=request.form['inputs']
61
+ inputs = str (request .form ['inputs' ])
62
+ inputs = ast .literal_eval (inputs )
63
+
64
+
65
+ inputcoloramt = int (request .form ['inputcoloramt' ])
66
+ print fromaddr
67
+ print dest
68
+ print fee
69
+ print private_key
70
+ print coloramt
71
+ print inputs
72
+ print inputcoloramt
73
+ response = transactions .create_transfer_tx (fromaddr , dest , fee , private_key , coloramt , inputs , inputcoloramt )
74
+ return str (response )
75
+ #return str(coloramt)
76
+
77
+ @app .route ('/colors/statements/<address>' ) #WORKS
78
+ def readmultistatements (address = None ):
79
+ result = addresses .read_opreturns_sent_by_address (address )
80
+ return str (result )
81
+
82
+ @app .route ('/colors/issue/signed' , methods = ['POST' ]) #WORKS
83
+ def issuenewcoinsserverside (): #TO ONE RECIPIENT ADDRESS
84
+ private_key = str (request .form ['private_keys' ])
85
+ public_address = str (request .form ['public_address' ])
86
+ more_coins = int (request .form ['initial_coins' ])
87
+ recipient = str (request .form ['recipients' ])
88
+ fee_each = 0.0001
89
+ name = str (request .form ['name' ])
90
+ othermeta = str (name )
91
+
92
+ print private_key
93
+ response = transactions .create_issuing_tx (public_address , recipient , fee_each , private_key , more_coins , 0 , othermeta )
94
+ return response
95
+ return str (name )
96
+
97
+ @app .route ('/colors/issue' , methods = ['POST' ]) #WORKS
98
+ def issuenewcoins_clientside ():
99
+ #JUST RETURN RAW HEX OF UNSIGNED TX
100
+ issuing_address = str (request .form ['issuing_address' ])
101
+ more_coins = request .form ['more_coins' ]
102
+ coin_recipients = str (request .form ['coin_recipients' ]) #DISCREPANCY, SHOULD BE ARRAY for multiple
103
+ othermeta = 'COIN NAME HERE'
104
+
105
+ fee = 0.0001
106
+ print coin_recipients
107
+ print more_coins
108
+ print issuing_address
109
+ print fee
110
+ print othermeta
111
+ tx = transactions .create_issuing_tx_unsigned (issuing_address , coin_recipients , fee , more_coins ,othermeta )
112
+ #return 'a'
113
+ return str (tx )
114
+
115
+ @app .route ('/addresses/generate' ) # WORKS
116
+ def makerandompair ():
117
+ return str (addresses .generate_secure_pair ())
118
+
119
+ @app .route ('/messages/<address>' )
120
+ def opreturns_sent_by_address (address = None ):
121
+ results = addresses .find_opreturns_sent_by_address (address )
122
+ return str (results )
123
+
124
+ @app .route ('/transactions' , methods = ['POST' ])
125
+ def pushtx ():
126
+ txhex = str (request .form ['transaction_hex' ])
127
+ response = transactions .pushtx (txhex )
128
+ return str (response )
103
129
104
130
if __name__ == '__main__' :
131
+ #app.run(host= '0.0.0.0', debug=False)
105
132
app .run ()
0 commit comments