Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from input-output-hk/etcm-205-use-checkpoints-…
Browse files Browse the repository at this point in the history
…in-history

[ETCM-205] Add information about checkpointed transactions in history
  • Loading branch information
qwhex committed Dec 3, 2020
2 parents 1e46bc5 + bed4d1d commit 7db69be
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 23 deletions.
Binary file modified image-snapshots/dark-transaction-history--interactive-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mantis
Submodule mantis updated 31 files
+3 −1 project/Dependencies.scala
+128 −0 repo.nix
+1 −1 src/main/resources/application.conf
+6 −0 src/main/scala/io/iohk/ethereum/domain/Address.scala
+4 −9 src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala
+1 −0 src/main/scala/io/iohk/ethereum/jsonrpc/MantisJsonMethodImplicits.scala
+13 −7 src/main/scala/io/iohk/ethereum/ledger/BlockImport.scala
+0 −1 src/main/scala/io/iohk/ethereum/ledger/Ledger.scala
+11 −4 src/main/scala/io/iohk/ethereum/transactions/TransactionHistoryService.scala
+19 −3 src/test/scala/io/iohk/ethereum/BlockHelpers.scala
+5 −2 src/test/scala/io/iohk/ethereum/Mocks.scala
+0 −1 src/test/scala/io/iohk/ethereum/ObjectGenerators.scala
+6 −2 src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala
+13 −3 src/test/scala/io/iohk/ethereum/blockchain/sync/PivotBlockSelectorSpec.scala
+18 −18 src/test/scala/io/iohk/ethereum/blockchain/sync/SyncSchedulerSpec.scala
+7 −1 src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncPeers.scala
+7 −1 src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala
+1 −5 src/test/scala/io/iohk/ethereum/cli/CliCommandsSpec.scala
+60 −10 src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala
+5 −1 src/test/scala/io/iohk/ethereum/crypto/ECDSASignatureSpec.scala
+5 −1 src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala
+8 −2 src/test/scala/io/iohk/ethereum/jsonrpc/MantisJRCSpec.scala
+1 −1 src/test/scala/io/iohk/ethereum/jsonrpc/MantisServiceSpec.scala
+19 −16 src/test/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServerSpec.scala
+9 −2 src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala
+14 −7 src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala
+5 −1 src/test/scala/io/iohk/ethereum/network/p2p/MessageDecodersSpec.scala
+4 −2 src/test/scala/io/iohk/ethereum/network/p2p/PeerActorSpec.scala
+6 −1 src/test/scala/io/iohk/ethereum/network/p2p/messages/MessagesSerializationSpec.scala
+5 −1 src/test/scala/io/iohk/ethereum/network/p2p/messages/ReceiptsSpec.scala
+97 −26 src/test/scala/io/iohk/ethereum/transactions/TransactionHistoryServiceSpec.scala
8 changes: 4 additions & 4 deletions src/common/wallet-state.test.ts
Expand Up @@ -26,10 +26,10 @@ const createTestTx = (

it('calculates next nonce from transactions', () => {
const transactions: Transaction[] = [
createTestTx('outgoing', 'persisted', 100, 1),
createTestTx('outgoing', 'persisted_checkpoint', 100, 1),
createTestTx('outgoing', 'confirmed', 100, 1),
createTestTx('outgoing', 'pending', 100, 1),
createTestTx('incoming', 'persisted', 100, 1),
createTestTx('incoming', 'persisted_depth', 100, 1),
createTestTx('incoming', 'confirmed', 100, 1),
createTestTx('incoming', 'pending', 100, 1),
]
Expand All @@ -44,9 +44,9 @@ it('calculates next nonce from transactions', () => {

const pendingTestBaseTransactions: Transaction[] = [
createTestTx('incoming', 'confirmed', 100, 1),
createTestTx('incoming', 'persisted', 100, 1),
createTestTx('incoming', 'persisted_depth', 100, 1),
createTestTx('outgoing', 'confirmed', 100, 1),
createTestTx('outgoing', 'persisted', 100, 1),
createTestTx('outgoing', 'persisted_checkpoint', 100, 1),
]
const pending1 = createTestTx('outgoing', 'pending', 100, 10)
const pending2 = createTestTx('outgoing', 'pending', 200, 10)
Expand Down
16 changes: 7 additions & 9 deletions src/common/wallet-state.ts
Expand Up @@ -67,7 +67,7 @@ export interface Transaction {
fee: Wei
gas: number
direction: 'outgoing' | 'incoming'
status: 'pending' | 'confirmed' | 'persisted' | 'failed'
status: 'pending' | 'confirmed' | 'persisted_depth' | 'persisted_checkpoint' | 'failed'
contractAddress: string | null
}

Expand Down Expand Up @@ -205,13 +205,11 @@ export const canResetWallet = (
walletState.walletStatus === 'ERROR' ||
walletState.walletStatus === 'NO_WALLET'

const getStatus = (
currentBlock: number,
txBlock: number | null,
isPending: boolean,
): Transaction['status'] => {
if (isPending || txBlock === null) return 'pending'
return currentBlock - txBlock >= DEPTH_FOR_PERSISTENCE ? 'persisted' : 'confirmed'
const getStatus = (tx: AccountTransaction, currentBlock: number): Transaction['status'] => {
if (tx.isPending || tx.blockNumber === null) return 'pending'
else if (tx.isCheckpointed) return 'persisted_checkpoint'
else if (currentBlock - tx.blockNumber >= DEPTH_FOR_PERSISTENCE) return 'persisted_depth'
else return 'confirmed'
}

function useWalletState(initialState?: Partial<WalletStateParams>): WalletData {
Expand Down Expand Up @@ -453,7 +451,7 @@ function useWalletState(initialState?: Partial<WalletStateParams>): WalletData {
? asWei(new BigNumber(tx.gasPrice).times(tx.gasUsed || tx.gas))
: asWei(0),
direction: tx.isOutgoing ? 'outgoing' : 'incoming',
status: getStatus(currentBlock, tx.blockNumber, tx.isPending || false),
status: getStatus(tx, currentBlock),
contractAddress:
tx.to == null
? (await web3.eth.getTransactionReceipt(tx.hash))?.contractAddress || null
Expand Down
17 changes: 16 additions & 1 deletion src/storybook-util/dummies.ts
Expand Up @@ -19,7 +19,7 @@ export const dummyTransactions: Transaction[] = [
gasUsed: 21000,
fee: asWei(0),
direction: 'incoming',
status: 'persisted',
status: 'persisted_depth',
contractAddress: null,
},
{
Expand Down Expand Up @@ -67,6 +67,21 @@ export const dummyTransactions: Transaction[] = [
status: 'failed',
contractAddress: null,
},
{
hash: '5',
from: address1,
to: address2,
blockNumber: 1,
timestamp: new Date(1585118001),
value: asEther(123),
gasPrice: asWei(1e9),
gas: 21000,
gasUsed: 21000,
fee: asWei(0),
direction: 'incoming',
status: 'persisted_checkpoint',
contractAddress: null,
},
]

export const estimateFeesWithRandomDelay = (amount?: BigNumber): Promise<FeeEstimates> =>
Expand Down
6 changes: 4 additions & 2 deletions src/translations/en/renderer.json
Expand Up @@ -160,11 +160,13 @@
"transactionStatus": {
"pending": "Pending",
"confirmed": "Confirmed",
"persisted": "Persisted",
"persisted_depth": "Persisted (Depth)",
"persisted_checkpoint": "Persisted (Checkpoint)",
"failed": "Failed",
"pendingDescription": "Transaction waiting to be added to a block in the chain",
"confirmedDescription": "Transaction has been added to a block in the chain",
"persistedDescription": "Transaction cannot be rolled back",
"persistedDepthDescription": "Transaction cannot be rolled back - sufficient number of confirmations",
"persistedCheckpointDescription": "Transaction cannot be rolled back - block containing it has been checkpointed",
"failedDescription": "Transaction has failed to reach the chain and wallet doesn’t expect it to proceed",
"notPersistedDescription": "This transaction is not yet persisted"
},
Expand Down
17 changes: 16 additions & 1 deletion src/wallets/TransactionHistory.stories.tsx
Expand Up @@ -64,7 +64,7 @@ export const interactive = (): JSX.Element => {
gasUsed: 21000,
fee: asWei(0),
direction: 'incoming',
status: 'persisted',
status: 'persisted_depth',
contractAddress: null,
}),
object<Transaction>('Transaction 2', {
Expand Down Expand Up @@ -97,6 +97,21 @@ export const interactive = (): JSX.Element => {
status: 'pending',
contractAddress: null,
}),
object<Transaction>('Transaction 1', {
hash: '4',
from: '0x00112233445566778899aabbccddeeff00112233',
to: '0xffeeddccbbaa0011223344556677889988776655',
blockNumber: 1,
timestamp: new Date(1585118001),
value: asEther(123),
gasPrice: asWei(1e9),
gas: 21000,
gasUsed: 21000,
fee: asWei(0),
direction: 'incoming',
status: 'persisted_checkpoint',
contractAddress: null,
}),
]}
accounts={dummyAccounts}
availableBalance={some(ether('Available Balance', 1000))}
Expand Down
3 changes: 2 additions & 1 deletion src/wallets/TransactionList.tsx
Expand Up @@ -103,7 +103,8 @@ const TX_STATUS_ORDER: Record<Transaction['status'], number> = {
failed: 0,
pending: 1,
confirmed: 2,
persisted: 3,
persisted_depth: 3,
persisted_checkpoint: 4,
} as const

const orderConfigs: Record<SortableProperty, Ord<Transaction>> = {
Expand Down
3 changes: 2 additions & 1 deletion src/wallets/TransactionRow.scss
Expand Up @@ -30,7 +30,8 @@
}
}

&.persisted {
&.persisted_depth,
&.persisted_checkpoint {
@include themify($themes) {
fill: themed('success-color');
}
Expand Down
9 changes: 6 additions & 3 deletions src/wallets/TransactionRow.tsx
Expand Up @@ -28,21 +28,24 @@ export interface TransactionCellProps {
const ICON_PER_TX_STATUS: Record<Transaction['status'], string> = {
pending: clockIcon,
confirmed: checkIcon,
persisted: checkDoubleIcon,
persisted_depth: checkDoubleIcon,
persisted_checkpoint: checkDoubleIcon,
failed: crossIcon,
}

const DESCRIPTION_PER_TX_STATUS: Record<Transaction['status'], TKeyRenderer> = {
pending: ['wallet', 'transactionStatus', 'pendingDescription'],
confirmed: ['wallet', 'transactionStatus', 'confirmedDescription'],
persisted: ['wallet', 'transactionStatus', 'persistedDescription'],
persisted_depth: ['wallet', 'transactionStatus', 'persistedDepthDescription'],
persisted_checkpoint: ['wallet', 'transactionStatus', 'persistedCheckpointDescription'],
failed: ['wallet', 'transactionStatus', 'failedDescription'],
}

const TX_STATUS_TRANSLATION: Record<Transaction['status'], TKeyRenderer> = {
pending: ['wallet', 'transactionStatus', 'pending'],
confirmed: ['wallet', 'transactionStatus', 'confirmed'],
persisted: ['wallet', 'transactionStatus', 'persisted'],
persisted_depth: ['wallet', 'transactionStatus', 'persisted_depth'],
persisted_checkpoint: ['wallet', 'transactionStatus', 'persisted_checkpoint'],
failed: ['wallet', 'transactionStatus', 'failed'],
}

Expand Down
1 change: 1 addition & 0 deletions src/web3.ts
Expand Up @@ -42,6 +42,7 @@ export const CustomErrors = T.readonlyArray(CustomError)

export interface AccountTransaction extends Transaction {
isOutgoing: boolean
isCheckpointed: boolean | null
isPending: boolean
timestamp: Date | null
gasUsed: number | null
Expand Down

0 comments on commit 7db69be

Please sign in to comment.