Skip to content

Commit

Permalink
not asserting withdrawals to be strictly local
Browse files Browse the repository at this point in the history
  • Loading branch information
vsubhuman committed Dec 11, 2024
1 parent 7c29b97 commit c26869a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,37 @@ function formatLedgerWithdrawals(
for (const [rewardAddress, withdrawalAmount] of iterateLenGetMap(withdrawals).nonNullValue()) {
const rewardAddressPayload = rewardAddress.to_address().to_hex();
const addressing = addressingMap(rewardAddressPayload);
if (addressing == null) {
throw new Error(`${nameof(formatLedgerWithdrawals)} Ledger can only withdraw from own address ${rewardAddressPayload}`);
let stakeCredential;
if (addressing != null) {
stakeCredential = {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
};
} else {
const cred = rewardAddress.payment_cred();
const maybeKeyHash = cred.to_keyhash();
const maybeScriptHash = cred.to_scripthash();
if (maybeKeyHash) {
stakeCredential = {
type: CredentialParamsType.KEY_HASH,
keyHashHex: maybeKeyHash.to_hex(),
};
} else if (maybeScriptHash) {
stakeCredential = {
type: CredentialParamsType.SCRIPT_HASH,
keyHashHex: maybeScriptHash.to_hex(),
};
}
}
if (stakeCredential == null) {
throw new Error('Failed to resolve credential type for reward address: ' + rewardAddressPayload);
}
result.push({
amount: withdrawalAmount.to_str(),
stakeCredential: {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
},
stakeCredential,
});
}
// $FlowIgnore[incompatible-return]
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,13 @@ export function toTrezorSignRequest(
for (const [rewardAddress, withdrawalAmount] of iterateLenGetMap(withdrawals).nonNullValue()) {
const rewardAddressPayload = rewardAddress.to_address().to_hex();
const path = ownAddressMap(rewardAddressPayload);
if (path != null) {
result.push({
amount: withdrawalAmount.to_str(),
path,
});
if (path == null) {
throw new Error('foreign withdrawal reward address');
}
result.push({
amount: withdrawalAmount.to_str(),
path,
});
}
formattedWithdrawals = result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ export default class ConnectorStore extends Store<StoresMap, ActionsMap> {
addressedUtxos,
);
} catch (e) {
console.error('Failed to construct the Ledger sign request: ', e);
console.error('toTrezorSignRequest failed: ', e);
runInAction(() => {
this.hwWalletError = unsupportedTransactionError;
this.isHwWalletErrorRecoverable = false;
Expand Down

0 comments on commit c26869a

Please sign in to comment.