@@ -95,4 +95,108 @@ def build_tx_info(tmp_tx_file):
95
95
witness = "0x5500000010000000550000005500000041000000" + tx ['signatures' ][sign_keys ][0 ][2 :]
96
96
tx_msg = tx ['transaction' ]
97
97
tx_msg ['witnesses' ] = [witness ]
98
- return tx_msg
98
+ return tx_msg
99
+
100
+ def build_tx_info_err (tmp_tx_file ):
101
+ with open (tmp_tx_file , "r" ) as file :
102
+ tx_info_str = file .read ()
103
+ tx = json .loads (tx_info_str )
104
+ sign_keys = list (tx ['signatures' ].keys ())[0 ]
105
+ witness = "0x0500000010000000550000005500000041000000" + tx ['signatures' ][sign_keys ][0 ][2 :]
106
+ tx_msg = tx ['transaction' ]
107
+ tx_msg ['witnesses' ] = [witness ]
108
+ return tx_msg
109
+
110
+ def build_tx_info_err2 (tmp_tx_file ):
111
+ with open (tmp_tx_file , "r" ) as file :
112
+ tx_info_str = file .read ()
113
+ tx = json .loads (tx_info_str )
114
+ tx ['transaction' ]['cell_deps' ][0 ]['out_point' ]['index' ] = '0x11'
115
+ sign_keys = list (tx ['signatures' ].keys ())[0 ]
116
+ witness = "0x5500000010000000550000005500000041000000" + tx ['signatures' ][sign_keys ][0 ][2 :]
117
+ tx_msg = tx ['transaction' ]
118
+ tx_msg ['witnesses' ] = [witness ]
119
+ return tx_msg
120
+
121
+ def build_send_transfer_self_tx_with_input_err (input_tx_hash_list , input_tx_index_list , sign_private , data = "0x" ,
122
+
123
+ fee = 5000 , output_count = 1 ,
124
+ api_url = "http://127.0.0.1:8114" , dep_cells = []):
125
+ # tx file init
126
+
127
+ tmp_tx_file = f"/tmp/demo{ time .time ()} -{ random .randint (0 , 100000000 )} .json"
128
+ tx_init (tmp_tx_file , api_url )
129
+ account = util_key_info_by_private_key (sign_private )
130
+ account_address = account ["address" ]["testnet" ]
131
+ tx_add_multisig_config (account_address , tmp_tx_file , api_url )
132
+ # add input
133
+ output_cell_capacity_total = 0
134
+ input_cell_template : any
135
+ for i in range (len (input_tx_hash_list )):
136
+ input_tx_index = input_tx_index_list [i ]
137
+ input_tx_hash = input_tx_hash_list [i ]
138
+ print (f"input_tx_index:{ input_tx_index } " )
139
+ tx_add_input (input_tx_hash , int (input_tx_index , 16 ), tmp_tx_file , api_url )
140
+ # add output
141
+ input_cell = RPCClient (api_url ).get_transaction (input_tx_hash )["transaction" ]["outputs" ][
142
+ int (input_tx_index , 16 )]
143
+ output_cell_capacity = int (int (input_cell ["capacity" ], 16 ) - fee )
144
+ output_cell_capacity_total += output_cell_capacity
145
+ input_cell_template = input_cell
146
+ min_output_count = min (int (output_cell_capacity_total / (100 * 100000000 )), output_count )
147
+ min_output_count = max (min_output_count , 1 )
148
+ output_cell_capacity = int (output_cell_capacity_total / min_output_count )
149
+ for i in range (min_output_count ):
150
+ tx_add_type_out_put (input_cell_template ["lock" ]["code_hash" ], input_cell_template ["lock" ]["hash_type" ],
151
+ input_cell_template ["lock" ]["args" ],
152
+ hex (output_cell_capacity ), data , tmp_tx_file , False )
153
+ for i in range (len (dep_cells )):
154
+ tx_add_cell_dep (dep_cells [i ]['tx_hash' ],dep_cells [i ]['index_hex' ],tmp_tx_file )
155
+
156
+ # sign
157
+ sign_data = tx_sign_inputs (sign_private , tmp_tx_file , api_url )
158
+ tx_add_signature (sign_data [0 ]['lock-arg' ], sign_data [0 ]['signature' ], tmp_tx_file , api_url )
159
+ tx_info (tmp_tx_file , api_url )
160
+ # send tx return hash
161
+ return build_tx_info_err (tmp_tx_file )
162
+
163
+ def build_send_transfer_self_tx_with_input_err2 (input_tx_hash_list , input_tx_index_list , sign_private , data = "0x" ,
164
+ fee = 5000 , output_count = 1 ,
165
+ api_url = "http://127.0.0.1:8114" , dep_cells = []):
166
+ # tx file init
167
+
168
+ tmp_tx_file = f"/tmp/demo{ time .time ()} -{ random .randint (0 , 100000000 )} .json"
169
+ tx_init (tmp_tx_file , api_url )
170
+ account = util_key_info_by_private_key (sign_private )
171
+ account_address = account ["address" ]["testnet" ]
172
+ tx_add_multisig_config (account_address , tmp_tx_file , api_url )
173
+ # add input
174
+ output_cell_capacity_total = 0
175
+ input_cell_template : any
176
+ for i in range (len (input_tx_hash_list )):
177
+ input_tx_index = input_tx_index_list [i ]
178
+ input_tx_hash = input_tx_hash_list [i ]
179
+ print (f"input_tx_index:{ input_tx_index } " )
180
+ tx_add_input (input_tx_hash , int (input_tx_index , 16 ), tmp_tx_file , api_url )
181
+ # add output
182
+ input_cell = RPCClient (api_url ).get_transaction (input_tx_hash )["transaction" ]["outputs" ][
183
+ int (input_tx_index , 16 )]
184
+ output_cell_capacity = int (int (input_cell ["capacity" ], 16 ) - fee )
185
+ output_cell_capacity_total += output_cell_capacity
186
+ input_cell_template = input_cell
187
+ min_output_count = min (int (output_cell_capacity_total / (100 * 100000000 )), output_count )
188
+ min_output_count = max (min_output_count , 1 )
189
+ output_cell_capacity = int (output_cell_capacity_total / min_output_count )
190
+ for i in range (min_output_count ):
191
+ tx_add_type_out_put (input_cell_template ["lock" ]["code_hash" ], input_cell_template ["lock" ]["hash_type" ],
192
+ input_cell_template ["lock" ]["args" ],
193
+ hex (output_cell_capacity ), data , tmp_tx_file , False )
194
+ for i in range (len (dep_cells )):
195
+ tx_add_cell_dep (dep_cells [i ]['tx_hash' ],dep_cells [i ]['index_hex' ],tmp_tx_file )
196
+
197
+ # sign
198
+ sign_data = tx_sign_inputs (sign_private , tmp_tx_file , api_url )
199
+ tx_add_signature (sign_data [0 ]['lock-arg' ], sign_data [0 ]['signature' ], tmp_tx_file , api_url )
200
+ tx_info (tmp_tx_file , api_url )
201
+ # send tx return hash
202
+ return build_tx_info_err2 (tmp_tx_file )
0 commit comments