def _add_shielded_inputs_and_outputs(self, block): if block.has_full_transactions(): for transaction in block.transactions: if transaction.join_splits is not None and len( transaction.join_splits) > 0: for join_split in transaction.join_splits: input_value = join_split.public_input_value or 0 output_value = join_split.public_output_value or 0 if input_value > 0: input = BtcTransactionInput() input.type = ADDRESS_TYPE_SHIELDED input.value = input_value transaction.add_input(input) if output_value > 0: output = BtcTransactionOutput() output.type = ADDRESS_TYPE_SHIELDED output.value = output_value transaction.add_output(output) if transaction.value_balance is not None and transaction.value_balance != 0: if transaction.value_balance > 0: input = BtcTransactionInput() input.type = ADDRESS_TYPE_SHIELDED input.value = transaction.value_balance transaction.add_input(input) if transaction.value_balance < 0: output = BtcTransactionOutput() output.type = ADDRESS_TYPE_SHIELDED output.value = transaction.value_balance transaction.add_output(output)
def dicts_to_outputs(self, dicts): result = [] for dict in dicts: input = BtcTransactionOutput() input.index = dict.get('index') input.script_asm = dict.get('script_asm') input.script_hex = dict.get('script_hex') input.required_signatures = dict.get('required_signatures') input.type = dict.get('type') input.addresses = dict.get('addresses') input.value = dict.get('value') result.append(input) return result
def json_dict_to_output(self, json_dict): output = BtcTransactionOutput() output.index = json_dict.get('n') output.addresses = json_dict.get('addresses') output.txinwitness = json_dict.get('txinwitness') output.value = bitcoin_to_satoshi(json_dict.get('value')) if 'scriptPubKey' in json_dict: script_pub_key = json_dict.get('scriptPubKey') output.script_asm = script_pub_key.get('asm') output.script_hex = script_pub_key.get('hex') output.required_signatures = script_pub_key.get('reqSigs') output.type = script_pub_key.get('type') output.addresses = script_pub_key.get('addresses') return output
def json_dict_to_output(self, json_dict, create_transaction_id=None): output = BtcTransactionOutput() output.index = json_dict.get('n') output.addresses = json_dict.get('addresses') output.txinwitness = json_dict.get('txinwitness') output.value = bitcoin_to_satoshi(json_dict.get('value')) output.create_transaction_id = create_transaction_id if 'scriptPubKey' in json_dict: script_pub_key = json_dict.get('scriptPubKey') output.script_asm = script_pub_key.get('asm') output.script_hex = script_pub_key.get('hex') output.required_signatures = script_pub_key.get('reqSigs') output.type = script_pub_key.get('type') if script_pub_key.get('addresses') is not None and len(script_pub_key.get('addresses')) > 0: output.addresses = script_pub_key.get('addresses') elif script_pub_key.get('address') is None: output.addresses = [] else: output.addresses = [script_pub_key.get('address')] return output