kaleidoscope
修订版 | 07d47d24a1d4e0cfb9c8219c002fe749b77bed96 (tree) |
---|---|
时间 | 2019-03-11 19:18:35 |
作者 | Chengcheng Zhang <943420582@qq.c...> |
Commiter | Chengcheng Zhang |
add get_mux_id, get_output_id
@@ -93,7 +93,16 @@ def get_input_id(spend_output_id_hexstr): | ||
93 | 93 | return input_id_hexstr |
94 | 94 | |
95 | 95 | |
96 | -# def get_output_id(): | |
96 | +def get_mux_id(prepare_mux_hexstr): | |
97 | + innerhash_bytes = sha3_256(bytes.fromhex(prepare_mux_hexstr)).digest() | |
98 | + mux_id_hexstr = sha3_256(b'entryid:mux1:' + innerhash_bytes).hexdigest() | |
99 | + return mux_id_hexstr | |
100 | + | |
101 | + | |
102 | +def get_output_id(prepare_output_id_hexstr): | |
103 | + innerhash_bytes = sha3_256(bytes.fromhex(prepare_output_id_hexstr)).digest() | |
104 | + output_id_hexstr = sha3_256(b'entryid:output1:' + innerhash_bytes).hexdigest() | |
105 | + return output_id_hexstr | |
97 | 106 | |
98 | 107 | |
99 | 108 | ''' |
@@ -168,6 +177,7 @@ def decode_raw_tx(raw_tx_str, network_str): | ||
168 | 177 | offset = offset + 2 * length |
169 | 178 | tx_input_amount, length = get_uvarint(raw_tx_str[offset:offset+8]) |
170 | 179 | offset = offset + 2 * length |
180 | + prepare_mux_hexstr = (tx_input_amount).to_bytes((tx_input_amount.bit_length() + 7) // 8, 'little').hex() | |
171 | 181 | for _ in range(tx_input_amount): |
172 | 182 | tx_input = { |
173 | 183 | "address": "", |
@@ -221,10 +231,13 @@ def decode_raw_tx(raw_tx_str, network_str): | ||
221 | 231 | offset = offset + 2 * argument_length |
222 | 232 | tx_input['witness_arguments'].append(argument) |
223 | 233 | tx['inputs'].append(tx_input) |
234 | + prepare_mux_hexstr += tx_input['input_id'] + tx_input['asset_id'] + (tx_input['amount']).to_bytes(8, byteorder='little').hex() + '0000000000000000' | |
224 | 235 | elif input_type == 2: |
225 | 236 | pass |
226 | 237 | tx_output_amount, length = get_uvarint(raw_tx_str[offset:offset+16]) |
227 | 238 | offset = offset + 2 * length |
239 | + prepare_mux_hexstr += '0100000000000000' + '0151' | |
240 | + mux_id_hexstr = get_mux_id(prepare_mux_hexstr) | |
228 | 241 | for i in range(tx_output_amount): |
229 | 242 | tx_output = { |
230 | 243 | "address": "", |
@@ -255,5 +268,7 @@ def decode_raw_tx(raw_tx_str, network_str): | ||
255 | 268 | tx_output['address'] = receiver.create_address(tx_output['control_program'], network_str)['address'] |
256 | 269 | _, length = get_uvarint(raw_tx_str[offset:offset+16]) |
257 | 270 | offset = offset + 2 * length |
271 | + prepare_output_id_hexstr = mux_id_hexstr + tx_output['asset_id'] + (tx_output['amount']).to_bytes(8, byteorder='little').hex() + (i).to_bytes(8, byteorder='little').hex() + '0100000000000000' + (control_program_length).to_bytes((control_program_length.bit_length() + 7) // 8, 'little').hex() + tx_output['control_program'] | |
272 | + tx_output['id'] = get_output_id(prepare_output_id_hexstr) | |
258 | 273 | tx['outputs'].append(tx_output) |
259 | 274 | return tx |