Current section
2 Versions
Jump to
Current section
2 Versions
Compare versions
19
files changed
+1497
additions
-70
deletions
| @@ -1,26 +1,45 @@ | |
| 1 1 | # Sutra |
| 2 2 | |
| 3 | - ** Offchain transaction builder framework for cardano using Elixir.** |
| 4 | - |
| 5 | - > [!WARNING] |
| 6 | - > SDK is under heavy development and API might change until we have stable version. |
| 3 | + **Offchain transaction builder framework for Cardano using Elixir.** |
| 7 4 | |
| 8 5 | ## Installation |
| 9 6 | |
| 10 | - If [available in Hex](https://hex.pm/docs/publish), the package can be installed |
| 11 | - by adding `sutra_offchain` to your list of dependencies in `mix.exs`: |
| 12 7 | |
| 13 8 | ```elixir |
| 14 9 | def deps do |
| 15 10 | [ |
| 16 | - {:sutra, "~> 0.2.0"} |
| 11 | + {:sutra_cardano, "~> 0.2.4"} |
| 17 12 | ] |
| 18 13 | end |
| 19 14 | ``` |
| 20 15 | |
| 21 16 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) |
| 22 17 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can |
| 23 | - be found at <https://hexdocs.pm/sutra_offchain>. |
| 18 | + be found at <https://hexdocs.pm/sutra_cardano>. |
| 19 | + |
| 20 | + ## Usage |
| 21 | + |
| 22 | + Sutra provides a pipe-friendly API to build transactions. |
| 23 | + |
| 24 | + ```elixir |
| 25 | + import Sutra |
| 26 | + |
| 27 | + # 1. Create a new transaction |
| 28 | + tx = |
| 29 | + new_tx() |
| 30 | + |> use_provider(MyProvider) # Configure your provider (Blockfrost, Yaci, etc.) |
| 31 | + |> add_input(utxos) |
| 32 | + |> add_output(friend_address, 10_000_000) |
| 33 | + |
| 34 | + # 2. Build and Sign |
| 35 | + signed_tx = |
| 36 | + tx |
| 37 | + |> build_tx!() |
| 38 | + |> sign_tx(private_key) |
| 39 | + |
| 40 | + # 3. Submit |
| 41 | + submit_tx(signed_tx) |
| 42 | + ``` |
| 24 43 | |
| 25 44 | ## Supported Providers |
| @@ -1,57 +1,55 @@ | |
| 1 1 | {<<"links">>, |
| 2 2 | [{<<"GitHub">>,<<"https://github.com/txbody-org/sutra-cardano">>}]}. |
| 3 3 | {<<"name">>,<<"sutra_cardano">>}. |
| 4 | - {<<"version">>,<<"0.2.4">>}. |
| 4 | + {<<"version">>,<<"0.2.5">>}. |
| 5 5 | {<<"description">>, |
| 6 6 | <<"A User-Friendly Component-Based Cardano SDK for Elixir.">>}. |
| 7 7 | {<<"elixir">>,<<"~> 1.15">>}. |
| 8 | - {<<"app">>,<<"sutra">>}. |
| 8 | + {<<"app">>,<<"sutra_cardano">>}. |
| 9 9 | {<<"licenses">>,[<<"MIT">>]}. |
| 10 10 | {<<"files">>, |
| 11 | - [<<"lib">>,<<"lib/sutra">>,<<"lib/sutra/blake_2b.ex">>, |
| 12 | - <<"lib/sutra/cardano">>,<<"lib/sutra/cardano/address">>, |
| 13 | - <<"lib/sutra/cardano/address/parser.ex">>,<<"lib/sutra/cardano/common">>, |
| 14 | - <<"lib/sutra/cardano/common/drep.ex">>, |
| 15 | - <<"lib/sutra/cardano/common/stake_pool.ex">>, |
| 16 | - <<"lib/sutra/cardano/common/pool_relay.ex">>,<<"lib/sutra/cardano/script">>, |
| 17 | - <<"lib/sutra/cardano/script/native_script.ex">>, |
| 18 | - <<"lib/sutra/cardano/transaction">>, |
| 19 | - <<"lib/sutra/cardano/transaction/output_reference.ex">>, |
| 20 | - <<"lib/sutra/cardano/transaction/tx_builder">>, |
| 21 | - <<"lib/sutra/cardano/transaction/tx_builder/collateral.ex">>, |
| 22 | - <<"lib/sutra/cardano/transaction/tx_builder/error.ex">>, |
| 23 | - <<"lib/sutra/cardano/transaction/tx_builder/certificate_helper.ex">>, |
| 24 | - <<"lib/sutra/cardano/transaction/tx_builder/internal.ex">>, |
| 25 | - <<"lib/sutra/cardano/transaction/tx_builder/tx_config.ex">>, |
| 26 | - <<"lib/sutra/cardano/transaction/tx_body.ex">>, |
| 27 | - <<"lib/sutra/cardano/transaction/output.ex">>, |
| 28 | - <<"lib/sutra/cardano/transaction/datum.ex">>, |
| 29 | - <<"lib/sutra/cardano/transaction/witness.ex">>, |
| 30 | - <<"lib/sutra/cardano/transaction/certificate.ex">>, |
| 31 | - <<"lib/sutra/cardano/transaction/tx_builder.ex">>, |
| 32 | - <<"lib/sutra/cardano/types.ex">>,<<"lib/sutra/cardano/utils.ex">>, |
| 33 | - <<"lib/sutra/cardano/address.ex">>,<<"lib/sutra/cardano/gov.ex">>, |
| 34 | - <<"lib/sutra/cardano/script.ex">>,<<"lib/sutra/cardano/transaction.ex">>, |
| 35 | - <<"lib/sutra/cardano/asset.ex">>,<<"lib/sutra/cardano/blueprint.ex">>, |
| 36 | - <<"lib/sutra/cardano/blueprint">>, |
| 37 | - <<"lib/sutra/cardano/blueprint/code_generator.ex">>, |
| 11 | + [<<"lib">>,<<"lib/mix">>,<<"lib/mix/tasks">>, |
| 12 | + <<"lib/mix/tasks/sutra.blueprint.gen.ex">>,<<"lib/sutra.ex">>, |
| 13 | + <<"lib/sutra">>,<<"lib/sutra/blake_2b.ex">>,<<"lib/sutra/cardano">>, |
| 14 | + <<"lib/sutra/cardano/address.ex">>,<<"lib/sutra/cardano/address">>, |
| 15 | + <<"lib/sutra/cardano/address/parser.ex">>,<<"lib/sutra/cardano/asset.ex">>, |
| 16 | + <<"lib/sutra/cardano/blueprint.ex">>,<<"lib/sutra/cardano/blueprint">>, |
| 38 17 | <<"lib/sutra/cardano/blueprint/common.ex">>, |
| 39 18 | <<"lib/sutra/cardano/blueprint/parser.ex">>, |
| 19 | + <<"lib/sutra/cardano/blueprint/code_generator.ex">>, |
| 20 | + <<"lib/sutra/cardano/common">>,<<"lib/sutra/cardano/common/drep.ex">>, |
| 21 | + <<"lib/sutra/cardano/common/pool_relay.ex">>, |
| 22 | + <<"lib/sutra/cardano/common/stake_pool.ex">>,<<"lib/sutra/cardano/gov.ex">>, |
| 23 | + <<"lib/sutra/cardano/script.ex">>,<<"lib/sutra/cardano/script">>, |
| 24 | + <<"lib/sutra/cardano/script/native_script.ex">>, |
| 25 | + <<"lib/sutra/cardano/transaction.ex">>,<<"lib/sutra/cardano/transaction">>, |
| 26 | + <<"lib/sutra/cardano/transaction/certificate.ex">>, |
| 27 | + <<"lib/sutra/cardano/transaction/datum.ex">>, |
| 28 | + <<"lib/sutra/cardano/transaction/output.ex">>, |
| 29 | + <<"lib/sutra/cardano/transaction/output_reference.ex">>, |
| 30 | + <<"lib/sutra/cardano/transaction/tx_body.ex">>, |
| 31 | + <<"lib/sutra/cardano/transaction/tx_builder.ex">>, |
| 32 | + <<"lib/sutra/cardano/transaction/tx_builder">>, |
| 33 | + <<"lib/sutra/cardano/transaction/tx_builder/certificate_helper.ex">>, |
| 34 | + <<"lib/sutra/cardano/transaction/tx_builder/collateral.ex">>, |
| 35 | + <<"lib/sutra/cardano/transaction/tx_builder/error.ex">>, |
| 36 | + <<"lib/sutra/cardano/transaction/tx_builder/internal.ex">>, |
| 37 | + <<"lib/sutra/cardano/transaction/tx_builder/tx_config.ex">>, |
| 38 | + <<"lib/sutra/cardano/transaction/witness.ex">>, |
| 39 | + <<"lib/sutra/cardano/types.ex">>,<<"lib/sutra/cardano/utils.ex">>, |
| 40 40 | <<"lib/sutra/coin_selection.ex">>,<<"lib/sutra/coin_selection">>, |
| 41 | - <<"lib/sutra/coin_selection/largest_first.ex">>,<<"lib/sutra/crypto">>, |
| 42 | - <<"lib/sutra/crypto/key.ex">>,<<"lib/sutra/data">>, |
| 43 | - <<"lib/sutra/data/macro_helper">>, |
| 41 | + <<"lib/sutra/coin_selection/largest_first.ex">>,<<"lib/sutra/common.ex">>, |
| 42 | + <<"lib/sutra/crypto.ex">>,<<"lib/sutra/crypto">>, |
| 43 | + <<"lib/sutra/crypto/key.ex">>,<<"lib/sutra/data.ex">>,<<"lib/sutra/data">>, |
| 44 | + <<"lib/sutra/data/cbor.ex">>,<<"lib/sutra/data/decoder.ex">>, |
| 45 | + <<"lib/sutra/data/macro_helper.ex">>,<<"lib/sutra/data/macro_helper">>, |
| 44 46 | <<"lib/sutra/data/macro_helper/enum_macro.ex">>, |
| 45 47 | <<"lib/sutra/data/macro_helper/object_macro.ex">>, |
| 46 | - <<"lib/sutra/data/macro_helper/type_macro.ex">>, |
| 47 48 | <<"lib/sutra/data/macro_helper/schema_builder.ex">>, |
| 48 | - <<"lib/sutra/data/cbor.ex">>,<<"lib/sutra/data/macro_helper.ex">>, |
| 49 | - <<"lib/sutra/data/option.ex">>,<<"lib/sutra/data/decoder.ex">>, |
| 50 | - <<"lib/sutra/data/plutus.ex">>,<<"lib/sutra/protocol_params.ex">>, |
| 51 | - <<"lib/sutra/slot_config.ex">>,<<"lib/sutra/common.ex">>, |
| 52 | - <<"lib/sutra/crypto.ex">>,<<"lib/sutra/emulator_trace.ex">>, |
| 53 | - <<"lib/sutra/uplc.ex">>,<<"lib/sutra/data.ex">>, |
| 54 | - <<"lib/sutra/privnet_test.ex">>,<<"lib/sutra/provider.ex">>, |
| 49 | + <<"lib/sutra/data/macro_helper/type_macro.ex">>, |
| 50 | + <<"lib/sutra/data/option.ex">>,<<"lib/sutra/data/plutus.ex">>, |
| 51 | + <<"lib/sutra/emulator_trace.ex">>,<<"lib/sutra/privnet_test.ex">>, |
| 52 | + <<"lib/sutra/protocol_params.ex">>,<<"lib/sutra/provider.ex">>, |
| 55 53 | <<"lib/sutra/provider">>,<<"lib/sutra/provider/blockfrost">>, |
| 56 54 | <<"lib/sutra/provider/blockfrost/blockfrost.ex">>, |
| 57 55 | <<"lib/sutra/provider/blockfrost/client.ex">>, |
| @@ -62,10 +60,21 @@ | |
| 62 60 | <<"lib/sutra/provider/maestro">>,<<"lib/sutra/provider/maestro/client.ex">>, |
| 63 61 | <<"lib/sutra/provider/maestro/maestro.ex">>,<<"lib/sutra/provider/yaci">>, |
| 64 62 | <<"lib/sutra/provider/yaci/client.ex">>, |
| 65 | - <<"lib/sutra/provider/yaci/yaci.ex">>,<<"lib/sutra.ex">>,<<"lib/test">>, |
| 66 | - <<"lib/mix">>,<<"lib/mix/tasks">>, |
| 67 | - <<"lib/mix/tasks/sutra.blueprint.gen.ex">>,<<".formatter.exs">>, |
| 68 | - <<"mix.exs">>,<<"README.md">>,<<"LICENSE">>]}. |
| 63 | + <<"lib/sutra/provider/yaci/yaci.ex">>,<<"lib/sutra/slot_config.ex">>, |
| 64 | + <<"lib/sutra/uplc.ex">>,<<"priv">>,<<"priv/blueprint_generator">>, |
| 65 | + <<"priv/blueprint_generator/datum.eex">>, |
| 66 | + <<"priv/blueprint_generator/enum_module.eex">>, |
| 67 | + <<"priv/blueprint_generator/module.eex">>, |
| 68 | + <<"priv/blueprint_generator/record_module.eex">>, |
| 69 | + <<"priv/blueprint_generator/redeemer.eex">>, |
| 70 | + <<"priv/blueprint_generator/redeemer_simple.eex">>, |
| 71 | + <<"priv/blueprint_generator/unit_module.eex">>,<<"priv/native">>, |
| 72 | + <<"priv/native/libsutra_uplc.so">>,<<"native">>,<<"native/sutra_uplc">>, |
| 73 | + <<"native/sutra_uplc/.cargo">>,<<"native/sutra_uplc/.cargo/config.toml">>, |
| 74 | + <<"native/sutra_uplc/.gitignore">>,<<"native/sutra_uplc/Cargo.lock">>, |
| 75 | + <<"native/sutra_uplc/Cargo.toml">>,<<"native/sutra_uplc/README.md">>, |
| 76 | + <<"native/sutra_uplc/src">>,<<"native/sutra_uplc/src/lib.rs">>, |
| 77 | + <<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>]}. |
| 69 78 | {<<"requirements">>, |
| 70 79 | [[{<<"name">>,<<"cbor">>}, |
| 71 80 | {<<"app">>,<<"cbor">>}, |
| @@ -27,34 +27,53 @@ defmodule Sutra.Cardano.Blueprint.CodeGenerator do | |
| 27 27 | # ============================================================================ |
| 28 28 | |
| 29 29 | # Compile templates at compile time for better performance |
| 30 | - @module_template File.read!(Path.join(:code.priv_dir(:sutra), "blueprint_generator/module.eex")) |
| 30 | + @module_template File.read!( |
| 31 | + Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator/module.eex") |
| 32 | + ) |
| 31 33 | @redeemer_template File.read!( |
| 32 | - Path.join(:code.priv_dir(:sutra), "blueprint_generator/redeemer.eex") |
| 34 | + Path.join( |
| 35 | + :code.priv_dir(:sutra_cardano), |
| 36 | + "blueprint_generator/redeemer.eex" |
| 37 | + ) |
| 33 38 | ) |
| 34 | - @datum_template File.read!(Path.join(:code.priv_dir(:sutra), "blueprint_generator/datum.eex")) |
| 39 | + @datum_template File.read!( |
| 40 | + Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator/datum.eex") |
| 41 | + ) |
| 35 42 | @unit_module_template File.read!( |
| 36 | - Path.join(:code.priv_dir(:sutra), "blueprint_generator/unit_module.eex") |
| 43 | + Path.join( |
| 44 | + :code.priv_dir(:sutra_cardano), |
| 45 | + "blueprint_generator/unit_module.eex" |
| 46 | + ) |
| 37 47 | ) |
| 38 48 | @record_module_template File.read!( |
| 39 49 | Path.join( |
| 40 | - :code.priv_dir(:sutra), |
| 50 | + :code.priv_dir(:sutra_cardano), |
| 41 51 | "blueprint_generator/record_module.eex" |
| 42 52 | ) |
| 43 53 | ) |
| 44 54 | @redeemer_simple_template File.read!( |
| 45 55 | Path.join( |
| 46 | - :code.priv_dir(:sutra), |
| 56 | + :code.priv_dir(:sutra_cardano), |
| 47 57 | "blueprint_generator/redeemer_simple.eex" |
| 48 58 | ) |
| 49 59 | ) |
| 50 60 | |
| 51 61 | # Mark external resources so module recompiles when templates change |
| 52 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/module.eex") |
| 53 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/redeemer.eex") |
| 54 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/redeemer_simple.eex") |
| 55 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/datum.eex") |
| 56 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/unit_module.eex") |
| 57 | - @external_resource Path.join(:code.priv_dir(:sutra), "blueprint_generator/record_module.eex") |
| 62 | + @external_resource Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator/module.eex") |
| 63 | + @external_resource Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator/redeemer.eex") |
| 64 | + @external_resource Path.join( |
| 65 | + :code.priv_dir(:sutra_cardano), |
| 66 | + "blueprint_generator/redeemer_simple.eex" |
| 67 | + ) |
| 68 | + @external_resource Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator/datum.eex") |
| 69 | + @external_resource Path.join( |
| 70 | + :code.priv_dir(:sutra_cardano), |
| 71 | + "blueprint_generator/unit_module.eex" |
| 72 | + ) |
| 73 | + @external_resource Path.join( |
| 74 | + :code.priv_dir(:sutra_cardano), |
| 75 | + "blueprint_generator/record_module.eex" |
| 76 | + ) |
| 58 77 | |
| 59 78 | # ============================================================================ |
| 60 79 | # Public API |
| @@ -100,7 +119,7 @@ defmodule Sutra.Cardano.Blueprint.CodeGenerator do | |
| 100 119 | Returns the path to the templates directory. |
| 101 120 | """ |
| 102 121 | def templates_dir do |
| 103 | - Path.join(:code.priv_dir(:sutra), "blueprint_generator") |
| 122 | + Path.join(:code.priv_dir(:sutra_cardano), "blueprint_generator") |
| 104 123 | end |
| 105 124 | |
| 106 125 | # ============================================================================ |
| @@ -8,7 +8,7 @@ defmodule Sutra.Uplc do | |
| 8 8 | alias Sutra.Cardano.Transaction.{Input, Output, OutputReference, TxBody, Witness} |
| 9 9 | alias Sutra.Data |
| 10 10 | |
| 11 | - use Rustler, otp_app: :sutra, crate: "sutra_uplc" |
| 11 | + use Rustler, otp_app: :sutra_cardano, crate: "sutra_uplc" |
| 12 12 | |
| 13 13 | def evaluate_raw(tx_cbor, inputs, %CostModels{} = cost_models, slot_config) |
| 14 14 | when is_binary(tx_cbor) do |
| @@ -3,8 +3,8 @@ defmodule Sutra.MixProject do | |
| 3 3 | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 | - app: :sutra, |
| 7 | - version: "0.2.4", |
| 6 | + app: :sutra_cardano, |
| 7 | + version: "0.2.5", |
| 8 8 | elixir: "~> 1.15", |
| 9 9 | elixirc_paths: elixirc_paths(Mix.env()), |
| 10 10 | start_permanent: Mix.env() == :prod, |
| @@ -12,7 +12,7 @@ defmodule Sutra.MixProject do | |
| 12 12 | consolidate_protocols: Mix.env() != :test, |
| 13 13 | |
| 14 14 | # Docs |
| 15 | - name: "Sutra", |
| 15 | + name: "sutra_cardano", |
| 16 16 | source_url: "https://github.com/txbody-org/sutra-cardano", |
| 17 17 | homepage_url: "https://github.com/txbody-org/sutra-cardano", |
| 18 18 | docs: &docs/0, |
| @@ -46,6 +46,7 @@ defmodule Sutra.MixProject do | |
| 46 46 | {:ex_sodium, "~> 0.1.2"}, |
| 47 47 | {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, |
| 48 48 | {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, |
| 49 | + {:makeup_html, ">= 0.0.0", only: :dev, runtime: false} |
| 49 50 | ] |
| 50 51 | end |
| 51 52 | |
| @@ -58,7 +59,7 @@ defmodule Sutra.MixProject do | |
| 58 59 | name: "sutra_cardano", |
| 59 60 | licenses: ["MIT"], |
| 60 61 | links: %{"GitHub" => "https://github.com/txbody-org/sutra-cardano"}, |
| 61 | - files: ~w(lib .formatter.exs mix.exs README.md LICENSE) |
| 62 | + files: ~w(lib priv native .formatter.exs mix.exs README.md LICENSE) |
| 62 63 | ] |
| 63 64 | end |
Loading more files…