def sign_transaction(self, keystore: TrezorKeyStore, tx: Transaction, xpub_path: Dict[str, str], tx_context: TransactionContext) -> None: prev_txtypes: Dict[bytes, TransactionType] = {} for prev_tx_hash, prev_tx in tx_context.prev_txs.items(): txtype = TransactionType() txtype.version = prev_tx.version txtype.lock_time = prev_tx.locktime txtype.inputs = self.tx_inputs(prev_tx, is_prev_tx=True) txtype.bin_outputs = [ TxOutputBinType(amount=tx_output.value, script_pubkey=bytes(tx_output.script_pubkey)) for tx_output in prev_tx.outputs ] # Trezor tx hashes are same byte order as the reversed hex tx id. prev_trezor_tx_hash = bytes(reversed(prev_tx_hash)) prev_txtypes[prev_trezor_tx_hash] = txtype client = self.get_client(keystore) inputs = self.tx_inputs(tx, xpub_path) outputs = self.tx_outputs(keystore, keystore.get_derivation(), tx) details = SignTx(lock_time=tx.locktime) signatures, _ = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details, prev_txes=prev_txtypes) tx.update_signatures(signatures)
def electrum_tx_to_txtype(self, tx, xpub_path): t = TransactionType() d = deserialize(tx.raw) t.version = d['version'] t.lock_time = d['lockTime'] t.inputs = self.tx_inputs(tx, xpub_path) t.bin_outputs = [ TxOutputBinType(amount=vout['value'], script_pubkey=bfh(vout['scriptPubKey'])) for vout in d['outputs'] ] return t
def electrum_tx_to_txtype(self, tx: Optional[Transaction]): t = TransactionType() if tx is None: # probably for segwit input and we don't need this prev txn return t tx.deserialize() t.version = tx.version t.lock_time = tx.locktime t.inputs = self.tx_inputs(tx) t.bin_outputs = [ TxOutputBinType(amount=o.value, script_pubkey=o.scriptpubkey) for o in tx.outputs() ] return t
def electrum_tx_to_txtype(self, tx, xpub_path): t = TransactionType() if tx is None: # probably for segwit input and we don't need this prev txn return t d = deserialize(tx.raw) t.version = d['version'] t.lock_time = d['lockTime'] t.inputs = self.tx_inputs(tx, xpub_path) t.bin_outputs = [ TxOutputBinType(amount=vout['value'], script_pubkey=bfh(vout['scriptPubKey'])) for vout in d['outputs'] ] return t
def electrum_tx_to_txtype(self, tx: Optional[Transaction]): t = TransactionType() if tx is None: # probably for segwit input and we don't need this prev txn return t tx.deserialize() t.version = tx.version t.lock_time = tx.locktime t.inputs = self.tx_inputs(tx) for o in tx.outputs(): if o.asset: raise UserFacingException(_("Trezor does not currently support asset transactions")) t.bin_outputs = [ TxOutputBinType(amount=o.value.value, script_pubkey=o.scriptpubkey) for o in tx.outputs() ] return t
def electrum_tx_to_txtype(self, tx: Optional[Transaction]): t = TransactionType() if tx is None: # probably for segwit input and we don't need this prev txn return t tx.deserialize() t.version = tx.version t.lock_time = tx.locktime t.inputs = self.tx_inputs(tx) t.bin_outputs = [ TxOutputBinType(amount=o.value, script_pubkey=o.scriptpubkey) for o in tx.outputs() ] if t.version > 2: tx_type = tx.tx_type if tx_type: t.extra_data = to_varbytes(serialize_extra_payload(tx)) t.version |= tx_type << 16 return t