Skip to content

Commit

Permalink
Tx parsing fixed in connector signing
Browse files Browse the repository at this point in the history
  • Loading branch information
vsubhuman committed Jan 26, 2022
1 parent 9126fa1 commit d4dec47
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/yoroi-extension/chrome/extension/ergo-connector/api.js
Expand Up @@ -531,9 +531,22 @@ export async function connectorSignCardanoTx(
// eslint-disable-next-line no-unused-vars
const { tx: txHex, partialSign } = tx;

const txBody = RustModule.WalletV4.TransactionBody.from_bytes(
Buffer.from(txHex, 'hex')
);
let txBody;

try {
txBody = RustModule.WalletV4.Transaction.from_bytes(
Buffer.from(txHex, 'hex')
).body();
} catch (originalErr) {
try {
// For backward compatibility
txBody = RustModule.WalletV4.TransactionBody.from_bytes(
Buffer.from(txHex, 'hex')
);
} catch (_e) {
throw originalErr;
}
}

const withUtxos = asGetAllUtxos(publicDeriver);
if (withUtxos == null) {
Expand Down Expand Up @@ -564,10 +577,8 @@ export async function connectorSignCardanoTx(
const utxoIdSet: Set<string> = new Set();
for (let i = 0; i < txBody.inputs().len(); i++) {
const input = txBody.inputs().get(i);
utxoIdSet.add(
Buffer.from(input.transaction_id().to_bytes()).toString('hex') +
String(input.index())
);
const txHash = Buffer.from(input.transaction_id().to_bytes()).toString('hex');
utxoIdSet.add(`${txHash}${String(input.index())}`);
}
const usedUtxos = addressedUtxos.filter(utxo =>
utxoIdSet.has(utxo.utxo_id)
Expand Down

0 comments on commit d4dec47

Please sign in to comment.