Skip to content

Commit

Permalink
Merge branch 'develop' into YV-47-alt
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Dec 17, 2024
2 parents f5a120b + 01e4a1c commit d18f2de
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions apps/wallet-mobile/src/features/Discover/common/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,47 @@ async function formatLedgerWithdrawals(
): Promise<Array<Withdrawal>> {
const result: Array<Withdrawal> = []

const withdrawalKeys = await withdrawals.keys()
for (let i = 0; i < (await withdrawalKeys.len()); i++) {
const rewardAddress = await withdrawalKeys.get(i)
const keys = await withdrawals.keys()
const keysLength = await keys.len()
for (let i = 0; i < keysLength; i++) {
const rewardAddress = await keys.get(i)
const withdrawalAmount = await withdrawals.get(rewardAddress)
if (withdrawalAmount == null) {
throw new Error(`formatLedgerWithdrawals should never happen`)
}

const rewardAddressPayload = Buffer.from(await rewardAddress.toAddress().then((a) => a.toBytes())).toString('hex')
const rewardAddressPayload = await (await rewardAddress.toAddress()).toHex()
const addressing = addressingMap(rewardAddressPayload)
if (addressing == null) {
throw new Error(`formatLedgerWithdrawals Ledger can only withdraw from own address ${rewardAddressPayload}`)
let stakeCredential: null | Withdrawal['stakeCredential'] = null
if (addressing != null) {
stakeCredential = {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
}
} else {
const cred = await rewardAddress.paymentCred()
const maybeKeyHash = await cred.toKeyhash()
const maybeScriptHash = await cred.toScripthash()
if (maybeKeyHash) {
stakeCredential = {
type: CredentialParamsType.KEY_HASH,
keyHashHex: await maybeKeyHash.toHex(),
}
} else if (maybeScriptHash) {
stakeCredential = {
type: CredentialParamsType.SCRIPT_HASH,
scriptHashHex: await maybeScriptHash.toHex(),
}
}
}
if (stakeCredential === null) {
throw new Error('Failed to resolve credential type for reward address: ' + rewardAddressPayload)
}
result.push({
amount: await withdrawalAmount.toStr(),
stakeCredential: {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
},
stakeCredential,
})
}

return result
}
async function formatLedgerCertificates(
Expand Down

0 comments on commit d18f2de

Please sign in to comment.