Skip to content

Commit

Permalink
fix: Receive funds to implicit account address (#8260)
Browse files Browse the repository at this point in the history
* feat: Sync SDK types

* feat: stop generating txs out of outputs

* fix: tx history: include account output in average txs

* fix: Fix incorrect timestamp in Incoming txs

* fix: Receive funds to implicit account address

* feat: add mana to txs in tx activities and activity details (#8263)

Co-authored-by: Marc Espin <[email protected]>
Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>

* Revert "feat: add mana to txs in tx activities and activity details (#8263)" (#8277)

This reverts commit e9e832b.

---------

Co-authored-by: cpl121 <[email protected]>
Co-authored-by: cpl121 <[email protected]>
Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
4 people authored Mar 28, 2024
1 parent c73b0e1 commit e806be8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IWalletState } from '@core/wallet/interfaces'
import { ActivityAction, ActivityType, IProcessedTransaction } from '@core/wallet'
import { ActivityAction, ActivityType, IProcessedTransaction, getSenderAddressFromInputs } from '@core/wallet'
import { Activity } from '@core/wallet/types'
import { isParticipationOutput } from '@contexts/governance/utils'
import { generateSingleAccountActivity } from './generateSingleAccountActivity'
Expand Down Expand Up @@ -33,6 +33,8 @@ async function generateActivitiesFromProcessedTransactionsWithInputs(
wallet: IWalletState
): Promise<Activity[]> {
const { outputs, wrappedInputs } = processedTransaction
const sender = getSenderAddressFromInputs(wrappedInputs)
const isSentToImplicitAccountCreationAddress = sender === (await wallet.implicitAccountCreationAddress())
const activities: Activity[] = []

const containsFoundryActivity = outputs.some((output) => output.output.type === OutputType.Foundry)
Expand Down Expand Up @@ -75,7 +77,11 @@ async function generateActivitiesFromProcessedTransactionsWithInputs(
const anchorActivities = await generateActivitiesFromAnchorOutputs(processedTransaction, wallet)
activities.push(...anchorActivities)
}
if (!containsFoundryActivity && !containsNftActivity && !containsAccountActivity && !governanceOutput) {

if (
(!containsFoundryActivity && !containsNftActivity && !containsAccountActivity && !governanceOutput) ||
isSentToImplicitAccountCreationAddress
) {
const basicActivities = await generateActivitiesFromBasicOutputs(processedTransaction, wallet)
activities.push(...basicActivities)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function generateActivitiesFromBasicOutputs(

const basicOutputs = getNonRemainderBasicOutputsFromTransaction(
processedTransaction.outputs,
wallet.depositAddress,
[wallet.depositAddress, await wallet.implicitAccountCreationAddress()],
processedTransaction.direction
)
const burnedNftInputs = getBurnedNftInputs(processedTransaction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IProcessedTransaction, IWrappedOutput } from '../../interfaces'
import { Output, OutputType, OutputWithMetadata, TransactionWithMetadata, UTXOInput } from '@iota/sdk/out/types'
// import { computeOutputId } from './computeOutputId'
import { getOutputIdFromTransactionIdAndIndex } from './getOutputIdFromTransactionIdAndIndex'
import { ActivityDirection } from '../../enums'
import { getUnixTimestampFromNodeInfoAndSlotIndex, nodeInfoProtocolParameters } from '@core/network'
Expand All @@ -18,21 +17,20 @@ export function preprocessIncomingTransaction(transaction: TransactionWithMetada
const outputs = convertTransactionsOutputTypesToWrappedOutputs(transactionId, regularTransactionEssence.outputs)

const utxoInputs = regularTransactionEssence.inputs.map((i) => i as UTXOInput)
// const inputIds = utxoInputs.map((input) => {
// const transactionId = input.transactionId
// const transactionOutputIndex = input.transactionOutputIndex
// return computeOutputId(transactionId, transactionOutputIndex)
// })
// const inputs = await Promise.all(inputIds.map((inputId) => wallet.getOutput(inputId)))
const inputs = transaction.inputs.map((input) => ({
output: input.output,
outputId: input.metadata.outputId,
metadata: input.metadata,
remainder: true,
}))

return {
outputs: outputs,
outputs,
transactionId,
direction: ActivityDirection.Incoming,
time: new Date(slotUnixTimestamp * MILLISECONDS_PER_SECOND),
inclusionState: transaction.inclusionState,
wrappedInputs: [],
// wrappedInputs: <IWrappedOutput[]>inputs,
wrappedInputs: <IWrappedOutput[]>inputs,
utxoInputs,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { CommonOutput } from '@iota/sdk/out/types'

export function getNonRemainderBasicOutputsFromTransaction(
wrappedOutputs: IWrappedOutput[],
walletDepositAddress: string,
validAddresses: string[],
direction: ActivityDirection
): IWrappedOutput[] {
return wrappedOutputs.filter((outputData) => {
const recipientAddress = getRecipientAddressFromOutput(outputData.output as CommonOutput)

if (direction === ActivityDirection.Incoming || direction === ActivityDirection.SelfTransaction) {
return !outputData.remainder && walletDepositAddress === recipientAddress
return !outputData.remainder && validAddresses.includes(recipientAddress)
} else {
return walletDepositAddress !== recipientAddress
return !validAddresses.includes(recipientAddress)
}
})
}

0 comments on commit e806be8

Please sign in to comment.