-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/voting-power-locales
- Loading branch information
Showing
13 changed files
with
130 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/shared/src/lib/auxiliary/blockscout/enums/blockscout-transaction-status.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum BlockscoutTransactionStatus { | ||
Ok = 'ok', | ||
Error = 'error', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './blockscout-transaction-status.enum' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './enums' | ||
export * from './interfaces' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/shared/src/lib/core/activity/utils/generateActivityFromPeristedTransaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IAccountState } from '@core/account/interfaces' | ||
import { getTransferInfoFromTransactionData } from '@core/layer-2/utils/getTransferInfoFromTransactionData' | ||
import { IChain } from '@core/network' | ||
import { PersistedTransaction, buildPersistedEvmTransactionFromBlockscoutTransaction } from '@core/transactions' | ||
import { ActivityType } from '../enums' | ||
import { Activity, PersistedEvmTransaction } from '../types' | ||
import { generateNftActivity } from './evm/generateNftActivity' | ||
import { generateSmartContractActivity } from './evm/generateSmartContractActivity' | ||
import { generateTokenActivity } from './evm/generateTokenActivity' | ||
|
||
export async function generateActivityFromPersistedTransaction( | ||
persistedTransaction: PersistedTransaction, | ||
chain: IChain, | ||
account: IAccountState | ||
): Promise<Activity | undefined> { | ||
const transaction = persistedTransaction.blockscout | ||
? buildPersistedEvmTransactionFromBlockscoutTransaction(persistedTransaction.blockscout) | ||
: (persistedTransaction.local as PersistedEvmTransaction) | ||
const transferInfo = getTransferInfoFromTransactionData(transaction, chain) | ||
if (transferInfo?.type === ActivityType.SmartContract) { | ||
return generateSmartContractActivity(transaction, chain, account) | ||
} else if (transferInfo?.type === ActivityType.Basic) { | ||
const { tokenId, rawAmount, additionalBaseTokenAmount, recipientAddress } = transferInfo | ||
return generateTokenActivity( | ||
transaction, | ||
chain, | ||
tokenId, | ||
rawAmount, | ||
additionalBaseTokenAmount, | ||
recipientAddress, | ||
account | ||
) | ||
} else if (transferInfo?.type === ActivityType.Nft) { | ||
const { nftId, additionalBaseTokenAmount, recipientAddress } = transferInfo | ||
return generateNftActivity(transaction, chain, nftId, additionalBaseTokenAmount, recipientAddress, account) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './types' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './persisted-transaction.type' |
16 changes: 16 additions & 0 deletions
16
packages/shared/src/lib/core/transactions/types/persisted-transaction.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IBlockscoutTransaction } from '@auxiliary/blockscout/interfaces' | ||
import { PersistedEvmTransaction } from '@core/activity' | ||
|
||
export type PersistedTransaction = | ||
| { | ||
blockscout: IBlockscoutTransaction | ||
local: PersistedEvmTransaction | ||
} | ||
| { | ||
blockscout?: IBlockscoutTransaction | ||
local: PersistedEvmTransaction | ||
} | ||
| { | ||
blockscout: IBlockscoutTransaction | ||
local?: PersistedEvmTransaction | ||
} |
45 changes: 45 additions & 0 deletions
45
.../src/lib/core/transactions/utils/buildPersistedEvmTransactionFromBlockscoutTransaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { IBlockscoutTransaction, BlockscoutTransactionStatus } from '@auxiliary/blockscout' | ||
import { PersistedEvmTransaction } from '@core/activity' | ||
import { LegacyTxData, TransactionType } from '@ethereumjs/tx' | ||
import { TransactionReceipt } from 'web3-core' | ||
|
||
export function buildPersistedEvmTransactionFromBlockscoutTransaction( | ||
blockscoutTransaction: IBlockscoutTransaction | ||
): PersistedEvmTransaction { | ||
const transactionReceipt: TransactionReceipt = { | ||
status: blockscoutTransaction.status === BlockscoutTransactionStatus.Ok ? true : false, | ||
transactionHash: blockscoutTransaction.hash, | ||
transactionIndex: blockscoutTransaction.position, | ||
blockHash: '', // Unknown | ||
blockNumber: blockscoutTransaction.block, | ||
from: blockscoutTransaction.from.hash.toLowerCase(), | ||
to: blockscoutTransaction.to.hash.toLowerCase(), | ||
// contractAddress?: string, | ||
cumulativeGasUsed: Number(blockscoutTransaction.gas_used), // Not sure if this is the right field | ||
gasUsed: Number(blockscoutTransaction.gas_used), | ||
effectiveGasPrice: Number(blockscoutTransaction.gas_price), | ||
logs: [], | ||
logsBloom: '', | ||
// events?: { | ||
// [eventName: string]: EventLog, | ||
// }, | ||
} | ||
|
||
const transactionData: LegacyTxData & { estimatedGas?: number; timestamp?: number } = { | ||
type: TransactionType.Legacy, | ||
...(blockscoutTransaction.nonce && { nonce: blockscoutTransaction.nonce }), | ||
...(blockscoutTransaction.gas_price && { gasPrice: blockscoutTransaction.gas_price }), | ||
...(blockscoutTransaction.gas_limit && { gasLimit: blockscoutTransaction.gas_limit }), | ||
// to?: AddressLike, // already set in transactionReceipt | ||
...(blockscoutTransaction.value && { value: blockscoutTransaction.value }), | ||
...(blockscoutTransaction.raw_input && | ||
blockscoutTransaction.raw_input !== '0x' && { data: blockscoutTransaction.raw_input }), // Not sure if this is the right field | ||
|
||
// estimatedGas?: number, // No way to know this for fetched transactions | ||
...(blockscoutTransaction.timestamp && { timestamp: new Date(blockscoutTransaction.timestamp).getTime() }), | ||
} | ||
return { | ||
...transactionReceipt, | ||
...transactionData, | ||
} as PersistedEvmTransaction | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './buildPersistedEvmTransactionFromBlockscoutTransaction' |