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

WIP: Receiving blockchain transactions #1123

Merged
merged 161 commits into from
Aug 28, 2019
Merged

Conversation

T-Dnzt
Copy link

@T-Dnzt T-Dnzt commented Jul 19, 2019

Issue/Task Number:

Overview

This PR adds an AddressTracker module that handles relevant transactions, inserting them in the DB if they are related to the hot wallet address or to one of the deposit wallet address.

An HD wallet system had to be implemented to support generating deposit wallet addresses for each internal wallet.

Changes

New tables/schemas:

  • EWalletDB.BlockchainDepositWallet - Stores the address, public key and HD derivation path for each specific blockchain deposit wallets.
  • EWalletDB.BlockchainHDWallet - Keeps a reference to the Keychain.Key where the private key to a HD wallet is stored.
  • EWalletDB.BlockchainState - Keeps track of a connected blockchain's overall state. Currently tracks the latest block number.

Impacted tables/schemas:

  • EWalletDB.BlockchainWallet - Keeps track of blockchain wallets recognized by the eWallet. The eWallet does not necessary have private keys to these wallets.
  • EWalletDB.Wallet - The existing wallet now holds references to EWalletDB.BlockchainDepositWallet so funds from blockchain can be deposited directly to these internal wallets. The relationship is has_many at DB level, but exposed as has_one at application level.

New endpoint:

  • /wallet.generate_deposit_address - Generates a deposit address for an existing EWalletDB.Wallet

Impacted endpoint:

  • /transaction.create - Now supports fund transfers from a hot wallet to an external blockchain address

Added behaviours:

  • mix seed --blockchain - Added blockchain HD wallet seeding to the existing --blockchain seed.
  • EWallet.AddressTracker - Tracks a specific blockchain address for activities, e.g. new transactions, and add the state to the eWallet.
  • EWallet.TransactionTracker - Tracks a specific transaction for activities, e.g. number of block confirmations, and update the eWallet state accordingly.

Implementation Details

The majority of the implementation include:

AdminAPI:

  • Add AdminAPI.V1.WalletController.generate_deposit_address/2 and EWallet.BlockchainDepositWalletGate to handle blockchain deposit wallet generation
  • Updated AdminAPI.V1.ConfigurationController to support primary hot wallet validation
  • Update AdminAPI.ConnCase to prepare an EWalletDB.BlockchainHDWallet during test setup

EthBlockchain:

  • Add EthBlockchain.Block.get/3 and EthGethAdapter.Block.get/1 to get a block by its block number
  • Add EthBlockchain.Block.get_transactions/3 to get a list of transactions in the given block number
  • Add EthBlockchain.DumbReceivingAdapter that simulates transactions from/to the hot wallet

EWallet:

  • Add EWallet.BlockchainAddressFetcher that parses input for wallet addresses that are trackable by the eWallet
  • Add EWallet.BlockchainStateGate that retrieves the blockchain state, e.g. last transacted block number and highest block number seen, for processing.
  • Add EWallet.BlockchainLocalTransactionGate that takes a blockchain-confirmed transaction and reflect the newly confirmed transaction into the local ledger.
  • Update EWallet.BlockchainTransactionGate to start tracking blockchain transaction status
  • Add EWallet.AddressTracker that keeps track of a blockchain address and reflects any new transaction events into EWalletDB.Transaction
  • Update EWallet.DBCase to prepare an EWalletDB.BlockchainHDWallet during test setup

EWalletDB:

  • Add EWalletDB.BlockchainDepositWallet (see Changes above)
  • Add EWalletDB.BlockchainHDWallet (see Changes above)
  • Add EWalletDB.BlockchainState (see Changes above)
  • Add EWalletDB.BlockchainWallet.get_all_hot/2 to list all known hot wallets
  • Add EWalletDB.TransactionState to handle each transaction's possible transitions
  • Add EWalletDB.Token.all_blockchain/2 to list all tokens that are linked to the blockchain
  • Add EWalletDB.Transaction.get_last_blk_number/1 that returns the latest block number that has a transaction saved to the eWallet

Usage

N/A

Impact

API schema updated. DB migration required. Seeding required to enable blockchain.

@unnawut unnawut self-assigned this Aug 27, 2019
@unnawut unnawut requested a review from mederic-p August 27, 2019 03:42
@unnawut
Copy link
Contributor

unnawut commented Aug 27, 2019

@T-Dnzt All pending tests implemented 🎉

Unnawut Leepaisalsuwanna added 6 commits August 27, 2019 14:59
# Conflicts:
#	apps/eth_blockchain/lib/eth_blockchain/block.ex
#	apps/eth_blockchain/test/eth_blockchain/block_test.exs
#	apps/eth_geth_adapter/lib/eth_geth_adapter/block.ex
#	apps/ewallet_db/priv/repo/seeds_sample/00_token.exs
#	apps/ewallet_db/priv/repo/seeds_sample/01_exchange_pair.exs
eWallet automation moved this from 3-In Progress to 4-Review Aug 28, 2019
@unnawut unnawut added this to the v2.0 milestone Aug 28, 2019
@unnawut
Copy link
Contributor

unnawut commented Aug 28, 2019

PR description updated with all the changes. @T-Dnzt @mederic-p please have a look.

@unnawut
Copy link
Contributor

unnawut commented Aug 28, 2019

Github is not basing of the eth-blockchain tip. Going to switch the base branch back and forth to try fix this.

@unnawut unnawut changed the base branch from eth-blockchain to master August 28, 2019 07:48
@unnawut unnawut changed the base branch from master to eth-blockchain August 28, 2019 07:48
@unnawut unnawut changed the base branch from eth-blockchain to master August 28, 2019 07:54
@unnawut unnawut changed the base branch from master to eth-blockchain August 28, 2019 07:56
@unnawut unnawut merged commit 64f36ca into eth-blockchain Aug 28, 2019
eWallet automation moved this from 4-Review to 5-Done Aug 28, 2019
@unnawut unnawut deleted the 1087-tx-listener branch September 2, 2019 07:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
eWallet
  
5-Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants