Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
priv

/client/oracle_client/burrito_out/
.tool-versions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good if we set a specific elixir and erlang version

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same versions, Elixir 14 and Erlang 25, but I use asdf so I have problems by running the application. I modified the tools but I set it into the gitignore for not giving you problems.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'm ok including the .tool-versions though if you want. I use asdf as well

5 changes: 5 additions & 0 deletions oraclex/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import Config
config :oraclex,
ecto_repos: [Oraclex.Repo]

# Configures the pk type for migrations
config :oraclex, Oraclex.Repo,
migration_primary_key: [type: :uuid],
migration_timestamps: [type: :naive_datetime_usec]

# Configures the endpoint
config :oraclex, OraclexWeb.Endpoint,
url: [host: "localhost"],
Expand Down
23 changes: 23 additions & 0 deletions oraclex/coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"treat_no_relevant_lines_as_covered": true,
"coverage_options": {
"output_dir": "priv/static/doc/cover/",
"minimum_coverage": 85
},
"terminal_options": {
"file_column_width": 60
},
"skip_files": [
"lib/oraclex/application.ex",
"lib/oraclex/mailer.ex",
"lib/oraclex/repo.ex",
"lib/oraclex/schema.ex",
"lib/oraclex_web.ex",
"lib/oraclex_web/endpoint.ex",
"lib/oraclex_web/gettext.ex",
"lib/oraclex_web/router.ex",
"lib/oraclex_web/telemetry.ex",
"lib/oraclex_web/views",
"test"
]
}
2 changes: 1 addition & 1 deletion oraclex/lib/oraclex/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Oraclex.Application do
def start(_type, _args) do
children = [
# Start the Ecto repository
# Oraclex.Repo,
Oraclex.Repo,
# Start the Telemetry supervisor
OraclexWeb.Telemetry,
# Start the PubSub system
Expand Down
10 changes: 5 additions & 5 deletions oraclex/lib/oraclex/repo.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# defmodule Oraclex.Repo do
# use Ecto.Repo,
# otp_app: :oraclex,
# adapter: Ecto.Adapters.Postgres
# end
defmodule Oraclex.Repo do
use Ecto.Repo,
otp_app: :oraclex,
adapter: Ecto.Adapters.Postgres
end
16 changes: 16 additions & 0 deletions oraclex/lib/oraclex/schema.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule Oraclex.Schema do
@moduledoc false

defmacro __using__(_) do
quote do
use Ecto.Schema

import Ecto.Changeset

alias Rigging.Repo

@timestamps_opts [type: :naive_datetime_usec]
@type t :: %__MODULE__{}
end
end
end
161 changes: 161 additions & 0 deletions oraclex/lib/oraclex_system/debug.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
defmodule Debug do
@moduledoc """
Debugging functions for making life easier.
"""

@width 80
@color 255
@line_color 238
@time_color 247
@syntax_colors [
atom: :cyan,
binary: :white,
boolean: :magenta,
list: :white,
map: :white,
nil: :magenta,
number: :yellow,
regex: :light_red,
reset: :yellow,
string: :green,
tuple: :white
]

@doc """
Prints `input` in console within a formatted frame.

Returs `input`.

It can recieve a keyword list as options.

## Options
* `label`: A string to print on the header for identification purposes.
* `color`: Color of the label if its given. Values between 0-255.
* `width`: Number of char width of the output.
* `line_color`: Color of the header and footer lines. Values between 0-255.
* `time_color`: Color of the execution time. Values between 0-255.
* `syntax_colors`: Keyword list for term syntax color.

Keys: `:atom`, `:binary`, `:boolean`, `:list`, `:map`, `:nil`, `:number`, `:regex`, `:reset`, `:string`, `:tuple`.

Values: `:black`, `:red`, `:yellow`, `:green`, `:cyan`, `:blue`, `:magenta`, `:white`, `:light_black`, `:light_red`, `:light_yellow`, `:light_green`, `:light_cyan`, `:light_blue`, `:light_magenta`, `:light_white`.

### 256 color palette

<img title="256 color palette" alt="palette image" src="assets/256_colors.png">

## Example
iex> "Lorem-Ipsum"
...> |> String.split("-")
...> |> RiggingSystem.Debug.log(label: "Split return")
...> |> Enum.join()
...> |> String.downcase()
Split return -------------------------------------- 2022-03-10 - 00:47:07.523741
["Lorem", "Ipsum"]
------------------------------------------------------------------ Rigging v0.0.0
"loremipsum" # This is the actual pipeline return, besides de console print.
"""
@spec log(input :: any, opt :: keyword) :: any
def log(input, opt \\ []) do
if Mix.env() in [:dev, :test] do
[
header(opt),
line(),
inspect(
input,
syntax_colors: Keyword.get(opt, :syntax_colors, @syntax_colors),
pretty: true,
width: Keyword.get(opt, :width, @width)
),
line(),
footer(opt),
line()
]
|> Enum.join()
|> IO.write()
end

input
end

# === Private ================================================================

defp line(), do: "\n"

defp header(opt) when is_list(opt) do
%{
year: year,
month: month,
day: day,
hour: hour,
minute: minute,
second: second,
microsecond: {microsecond, 6}
} = NaiveDateTime.utc_now()

label = Keyword.get(opt, :label)
width = Keyword.get(opt, :width, @width)
c0 = Keyword.get(opt, :color, "#{@color}")
c1 = Keyword.get(opt, :line_color, "#{@line_color}")
c2 = Keyword.get(opt, :time_color, "#{@time_color}")

date =
"#{year}"
|> Kernel.<>("-")
|> Kernel.<>(String.pad_leading("#{month}", 2, "0"))
|> Kernel.<>("-")
|> Kernel.<>(String.pad_leading("#{day}", 2, "0"))

time =
"#{hour}"
|> String.pad_leading(2, "0")
|> Kernel.<>(":")
|> Kernel.<>(String.pad_leading("#{minute}", 2, "0"))
|> Kernel.<>(":")
|> Kernel.<>(String.pad_leading("#{second}", 2, "0"))
|> Kernel.<>(".")
|> Kernel.<>(String.pad_leading("#{microsecond}", 6, "0"))

label = if !label, do: "", else: "#{label} "

separation =
width
|> Kernel.-(String.length(label))
|> Kernel.-(String.length(date))
|> Kernel.-(String.length(time))
|> Kernel.-(4)

reset = "\e[0m"
label = "#{reset}\e[1m\e[38;5;#{c0}m#{label}#{reset}\e[38;5;#{c1}m"
date = "#{reset}\e[38;5;#{c2}m#{date}#{reset}\e[38;5;#{c1}m"
time = "#{reset}\e[38;5;#{c2}m#{time}#{reset}\e[38;5;#{c1}m"

"\e[38;5;#{c1}m"
|> Kernel.<>("#{label}")
|> Kernel.<>(String.duplicate("─", separation))
|> Kernel.<>(" #{date} - #{time}")
|> Kernel.<>(reset)
end

defp footer(opt) when is_list(opt) do
width = Keyword.get(opt, :width, @width)
c1 = Keyword.get(opt, :line_color, "#{@line_color}")
service = Mix.Project.config()[:app]
version = Mix.Project.config()[:version]

product =
service
|> Atom.to_string()
|> String.split("_")
|> Enum.map(fn e -> String.capitalize(e) end)
|> Enum.join()

sufix = " #{product} v#{version}"
separation = width - String.length(sufix)

"\e[38;5;#{c1}m"
|> Kernel.<>(String.duplicate("─", separation))
|> Kernel.<>(sufix)
|> Kernel.<>("\e[0m")
end
end
15 changes: 13 additions & 2 deletions oraclex/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ defmodule Oraclex.MixProject do
compilers: Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
deps: deps(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test
]
]
end

Expand All @@ -33,6 +40,7 @@ defmodule Oraclex.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
# Default dependencies
{:phoenix, "~> 1.6.15"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
Expand All @@ -49,9 +57,12 @@ defmodule Oraclex.MixProject do
{:gettext, "~> 0.18"},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"},
# Extended dependencies
{:poison, "~> 5.0"},
{:bitcoinex,
github: "SachinMeier/bitcoinex", branch: "sachin--add-key-only-taproot-script-creation"}
github: "SachinMeier/bitcoinex", branch: "sachin--add-key-only-taproot-script-creation"},
{:excoveralls, "~> 0.16.0", only: :test},
{:mock, "~> 0.3.7", only: :test}
]
end

Expand Down
3 changes: 3 additions & 0 deletions oraclex/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"ecto": {:hex, :ecto, "3.9.4", "3ee68e25dbe0c36f980f1ba5dd41ee0d3eb0873bccae8aeaf1a2647242bffa35", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "de5f988c142a3aa4ec18b85a4ec34a2390b65b24f02385c1144252ff6ff8ee75"},
"ecto_sql": {:hex, :ecto_sql, "3.9.2", "34227501abe92dba10d9c3495ab6770e75e79b836d114c41108a4bf2ce200ad5", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1eb5eeb4358fdbcd42eac11c1fbd87e3affd7904e639d77903c1358b2abd3f70"},
"esbuild": {:hex, :esbuild, "0.6.1", "a774bfa7b4512a1211bf15880b462be12a4c48ed753a170c68c63b2c95888150", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "569f7409fb5a932211573fc20e2a930a0d5cf3377c5b4f6506c651b1783a1678"},
"excoveralls": {:hex, :excoveralls, "0.16.0", "41f4cfbf7caaa3bc2cf411db6f89c1f53afedf0f1fe8debac918be1afa19c668", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "401205356482ab99fb44d9812cd14dd83b65de8e7ae454697f8b34ba02ecd916"},
"expo": {:hex, :expo, "0.3.0", "13127c1d5f653b2927f2616a4c9ace5ae372efd67c7c2693b87fd0fdc30c6feb", [:mix], [], "hexpm", "fb3cd4bf012a77bc1608915497dae2ff684a06f0fa633c7afa90c4d72b881823"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.34.0", "002d0cc194b48794d74711731db004fafeb328fe676976f160685262d43706a8", [:mix], [], "hexpm", "9c3a9f43f40dde00332a589bd9d389b90c1f518aef500364d00636acc5ebc99c"},
"gettext": {:hex, :gettext, "0.22.0", "a25d71ec21b1848957d9207b81fd61cb25161688d282d58bdafef74c2270bdc4", [:mix], [{:expo, "~> 0.3.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "cb0675141576f73720c8e49b4f0fd3f2c69f0cd8c218202724d4aebab8c70ace"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~> 2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mock": {:hex, :mock, "0.3.7", "75b3bbf1466d7e486ea2052a73c6e062c6256fb429d6797999ab02fa32f29e03", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "4da49a4609e41fd99b7836945c26f373623ea968cfb6282742bcb94440cf7e5c"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
Expand Down
24 changes: 12 additions & 12 deletions oraclex/test/oraclex/contract_test.exs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
defmodule Oraclex.ContractTest do
use ExUnit.Case
doctest Oraclex.ContractTest
# use ExUnit.Case
# doctest Oraclex.ContractTest

alias Oraclex.Contract
# alias Oraclex.Contract


describe "contract_id" do
# describe "contract_id" do

test "calculate temp_contract_id" do
# test "calculate temp_contract_id" do

end
# end


test "calculate contract_id" do
filename = "dlcspec_vectors/contract_id_test.json"
# test "calculate contract_id" do
# filename = "dlcspec_vectors/contract_id_test.json"

{:ok, data} = File.read(filename)
{:ok, tests} = Poison.decode(data)
# {:ok, data} = File.read(filename)
# {:ok, tests} = Poison.decode(data)


end
end
# end
# end

end
20 changes: 20 additions & 0 deletions oraclex/test/oraclex_system/debug_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule OraclexSystem.DebugTest do
use Oraclex.DataCase

import Mock

describe "[unit] log/2" do
@tag :unit
test "prints the input on console returns the input" do
with_mocks [
{Mix, [:passthrough], env: fn -> :dev end},
{IO, [:passthrough], write: fn _ -> :ok end}
] do
input = true
result = Debug.log(input)

assert result === input
end
end
end
end