4 # submit_transaction broadcast raw transaction
5 # raw_transaction_str is signed transaction,
6 # network_str is mainnet or testnet
8 # raw_transaction_str: 070100010160015e0873eddd68c4ba07c9410984799928288ae771bdccc6d974e72c95727813461fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8094ebdc030101160014052620b86a6d5e07311d5019dffa3864ccc8a6bd630240312a052f36efb9826aa1021ec91bc6f125dd07f9c4bff87014612069527e15246518806b654d57fff8b6fe91866a19d5a2fb63a5894335fce92a7b4a7fcd340720e87ca3acdebdcad9a1d0f2caecf8ce0dbfc73d060807a210c6f225488347961402013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8082eee0020116001418028ef4f8b8c278907864a1977a5ee6707b2a6b00013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80b8b872011600142935e4869d0317d9701c80a02ecf888143cb9dd200
10 def submit_transaction(raw_transaction_str, network_str):
11 raw_transaction_dict = {
12 "transaction": raw_transaction_str
14 raw_transaction_json = json.dumps(raw_transaction_dict)
16 "content-type": "application/json",
17 "accept": "application/json"
19 if network_str == "mainnet":
20 url = "https://blockmeta.com/api/v2/broadcast-transaction"
22 url = "https://blockmeta.com/api/wisdom/broadcast-transaction"
23 response = requests.post(url, headers=headers, data=raw_transaction_json)
25 "response": response.text[:-1]
29 def decode_raw_transaction(raw_transaction_str):
30 raw_transaction_dict = {
31 "raw_transaction": raw_transaction_str
33 raw_transaction_json = json.dumps(raw_transaction_dict)
35 "content-type": "application/json",
36 "accept": "application/json"
38 url = 'http://127.0.0.1:9888/decode-raw-transaction'
39 response = requests.post(url, headers=headers, data=raw_transaction_json)
41 "response": response.text[:-1]
45 def decode_raw_tx(raw_tx_str):
49 "asset_definition": {},
51 "control_program": "",
53 "spend_output_id": "",
55 "witness_arguments": []
60 "asset_definition": {},
62 "control_program": "",
76 version = int(raw_tx_str[2:4], 16)
77 time_range = int(raw_tx_str[4:6], 16)
78 tx_input_amount = int(raw_tx_str[6:8], 16)
79 tx_input_version = int(raw_tx_str[8:10], 16)
80 tx_input_length = int(raw_tx_str[10:12], 16)
81 tx_input_type = int(raw_tx_str[12:14], 16)
82 tx_input_data_spend_commit_length = int(raw_tx_str[14:16], 16)
83 tx_input_source_id = raw_tx_str[16:80]
84 tx_input_asset_id = raw_tx_str[80:144]
87 # for i in range(tx_input_amount):