This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New seed: initial user funds, exchange pairs, transaction requests an…
…d consumptions (#325) * Add account_user linking when seeding users * Add transaction request and consumption seed * Give some tokens to all seeded users * Add exchange_pair seed
- Loading branch information
Showing
8 changed files
with
298 additions
and
15 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
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
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
63 changes: 63 additions & 0 deletions
63
apps/ewallet_db/priv/repo/seeds_sample/01_exchange_pair.exs
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,63 @@ | ||
defmodule EWalletDB.Repo.Seeds.ExchangePairSeed do | ||
alias EWallet.Web.Preloader | ||
alias EWalletDB.{Token, ExchangePair} | ||
|
||
@pairs [ | ||
%{from_token_symbol: "BTC", to_token_symbol: "OEM", rate: 1_000_000}, | ||
%{from_token_symbol: "ETH", to_token_symbol: "OMG", rate: 400}, | ||
|
||
%{from_token_symbol: "OEM", to_token_symbol: "BTC", rate: 0.000001}, | ||
%{from_token_symbol: "OEM", to_token_symbol: "OMG", rate: 0.001}, | ||
|
||
%{from_token_symbol: "OMG", to_token_symbol: "OEM", rate: 1_000}, | ||
%{from_token_symbol: "OMG", to_token_symbol: "BTC", rate: 0.0010}, | ||
%{from_token_symbol: "OMG", to_token_symbol: "ETH", rate: 0.0025} | ||
] | ||
|
||
def seed do | ||
[ | ||
run_banner: "Seeding sample exchange pairs:", | ||
argsline: [], | ||
] | ||
end | ||
|
||
def run(writer, _args) do | ||
Enum.each @pairs, fn args -> | ||
run_with(writer, args) | ||
end | ||
end | ||
|
||
def run_with(writer, args) do | ||
from_token = Token.get_by(symbol: args.from_token_symbol) | ||
to_token = Token.get_by(symbol: args.to_token_symbol) | ||
|
||
case ExchangePair.get_by([from_token_uuid: from_token.uuid, to_token_uuid: to_token.uuid]) do | ||
nil -> | ||
{:ok, pair} = | ||
ExchangePair.insert(%{ | ||
from_token_uuid: from_token.uuid, | ||
to_token_uuid: to_token.uuid, | ||
rate: args.rate | ||
}) | ||
|
||
{:ok, pair} = Preloader.preload_one(pair, [:from_token, :to_token]) | ||
|
||
writer.success(""" | ||
Exchange Pair ID : #{pair.id} | ||
From Token ID : #{pair.from_token.id} | ||
To Token ID : #{pair.to_token.id} | ||
Rate : #{pair.rate} | ||
""") | ||
|
||
%ExchangePair{} = pair -> | ||
{:ok, pair} = Preloader.preload_one(pair, [:from_token, :to_token]) | ||
|
||
writer.warn(""" | ||
Exchange Pair ID : #{pair.id} | ||
From Token ID : #{pair.from_token.id} | ||
To Token ID : #{pair.to_token.id} | ||
Rate : #{pair.rate} | ||
""") | ||
end | ||
end | ||
end |
Oops, something went wrong.