Skip to content

Commit

Permalink
Merge pull request #276 from kommitters/v0.19
Browse files Browse the repository at this point in the history
Release v0.19.0
  • Loading branch information
Odraxs authored Feb 1, 2023
2 parents 5482acb + caefdb3 commit 3604fcd
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
hex.pm:443
repo.hex.pm:443
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
- uses: erlef/setup-elixir@b980a5ac9b7316a23ebc16de2bb69b7c3ad731b5 # v1.15.0
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: erlef/setup-elixir@e3f6ffe2878180f57318bf13febd3933ee81f664 # v1.15.2
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3.2.2
- uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ jobs:
github.com:443
repo.hex.pm:443
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 # v2.6.0
- uses: erlef/setup-beam@b980a5ac9b7316a23ebc16de2bb69b7c3ad731b5 # v1.15.0
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: erlef/setup-beam@e3f6ffe2878180f57318bf13febd3933ee81f664 # v1.15.2
id: beam
with:
otp-version: "24"
elixir-version: "1.13.4"
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # v2.1.7
- uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Check Formatting
run: mix format --check-formatted
- name: Restore PLT cache
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # v2.1.7
uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
id: plt_cache
with:
key: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ jobs:
sigstore-tuf-root.storage.googleapis.com:443
- name: "Checkout code"
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -61,14 +61,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@c7f292ea4f542c473194b33813ccd4c207a6c725 # v2.1.21
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1
with:
sarif_file: results.sarif
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.19.0 (01.02.2023)

- Added [YAML Continuation command](https://github.com/kommitters/kadena.ex/issues/209)
- Update all dependencies

## 0.18.0 (31.01.2023)

- Added [YAML reader](https://github.com/kommitters/kadena.ex/issues/253)
Expand Down
122 changes: 111 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Add `kadena` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:kadena, "~> 0.18.0"}
{:kadena, "~> 0.19.0"}
]
end
```
Expand Down Expand Up @@ -350,17 +350,17 @@ env_data = %{accounts_admin_keyset: [keypair.pub_key]}
}}
```

#### With a `YAML` file
#### From a `YAML` file

YAML struct:

- `networkId`: [NetworkID](#networkid) value.
- `code`: there are two ways to set the code from the `YAML` file:
- `code`: [Code](#code) value.
- `codeFile`: The name of a `pact` file in the same directory as the `YAML` file.
- `codeFile`: The name of a `pact` file in the same directory as the `YAML` file. For example, `code.pact`.
- `data`: there are two ways to set the data from the `YAML` file:
- `data`: [EnvData](#envdata) value.
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file.
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file. For example, `data.json`.
- `nonce`: [Nonce](#nonce) value.
- `publicMeta`: [Metadata](#metadata) value.
- `keyPairs`: [KeyPairs](#keypairs) values.
Expand Down Expand Up @@ -422,7 +422,7 @@ keyPairs:
```elixir
alias Kadena.Pact.ExecCommand

"~/your_file_path"
"~/example.yaml"
|> ExecCommand.from_yaml()
|> ExecCommand.build()

Expand All @@ -445,6 +445,10 @@ alias Kadena.Pact.ExecCommand

### Building a Continuation Command

There are two ways to create a ContCommand.

#### Using [attributes](#attributes) structures

```elixir
alias Kadena.Cryptography
alias Kadena.Pact
Expand Down Expand Up @@ -508,6 +512,107 @@ rollback = true
}}
```

#### From a `YAML` file

YAML struct:

- `networkId`: [NetworkID](#networkid) value.
- `data`: there are two ways to set the data from the `YAML` file:
- `data`: [EnvData](#envdata) value.
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file. For example, `data.json`.
- `nonce`: [Nonce](#nonce) value.
- `publicMeta`: [Metadata](#metadata) value.
- `keyPairs`: [KeyPairs](#keypairs) values.
- `signers`: [Signers](#signers) values.
- `pactTxHash`: [PactTxHash](#pacttxhash-continuation-command) value.
- `rollback`: [Rollback](#rollback-continuation-command) value.
- `Step`: [Step](#step-continuation-command) value.
- `proof`: [Proof](#proof-continuation-command) value.


The scheme below shows how to set the different values of a `ContCommand`

```YAML
networkId:
data/dataFile:
nonce:
publicMeta:
creationTime:
chainId:
gasLimit:
gasPrice:
ttl:
sender:
keyPairs:
- public:
secret:
signers:
- publicKey:
scheme:
addr:
capsList:
- name:
args:
-
pactTxHash:
step:
rollback:
proof:

```
**Example**
YAML file:
```YAML
networkId: :testnet04
data:
accounts_admin_keyset:
- 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
nonce: 2023-01-01 00:00:00.000000 UTC
publicMeta:
creationTime: 1667249173
chainId: "0"
gasLimit: 2500
gasPrice: 0.01
ttl: 28800
sender: k:6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
keyPairs:
- public: 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
secret: 99f7e1e8f2f334ae8374aa28bebdb997271a0e0a5e92c80be9609684a3d6f0d4
capsList:
name: coin.GAS
args:
- 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
pactTxHash: yxM0umrtdcvSUZDc_GSjwadH6ELYFCjOqI59Jzqapi4
step: 1
rollback: true

```
```elixir
alias Kadena.Pact.ContCommand

"~/example.yaml"
|> ContCommand.from_yaml()
|> ContCommand.build()

{:ok,
%Kadena.Types.Command{
cmd:
"{\"meta\":{\"chainId\":\"0\",\"creationTime\":1667249173,\"gasLimit\":2500,\"gasPrice\":0.01,\"sender\":\"k:6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7\",\"ttl\":28800},\"networkId\":\"testnet04\",\"nonce\":\"2023-01-01 00:00:00.000000 UTC\",\"payload\":{\"cont\":{\"data\":{\"accounts_admin_keyset\":[\"6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7\"]},\"pactId\":\"\",\"proof\":null,\"rollback\":true,\"step\":0}},\"signers\":[{\"addr\":null,\"clist\":[{\"args\":[\"6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7\"],\"name\":\"coin.GAS\"}],\"pubKey\":\"6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7\",\"scheme\":\"ED25519\"}]}",
hash: %Kadena.Types.PactTransactionHash{
hash: "psIXOGGneMAV1Ie3zx5O1VWMFueFZrShvaBx4YOCkjQ"
},
sigs: [
%Kadena.Types.Signature{
sig:
"1ae6e796bbf8e1ddb005945508ac6fd13cc6435c4f63609cff299114865fd13879b8b5bcad13383ae377acc10411e49e745397320a2ba5bf9d1370cafbf90a06"
}
]
}}

```

## Chainweb Pact API

Interaction with [Chainweb Pact API][chainweb_pact_api_doc] is done through the [**Kadena.Chainweb.Pact**][chainweb_pact_api] module using simple functions to access endpoints.
Expand Down Expand Up @@ -1839,14 +1944,8 @@ Chainweb.Peer.new()

## Roadmap

The latest updated branch to target a PR is `v0.19`

You can see a big picture of the roadmap here: [**ROADMAP**][roadmap]

### What we're working on now 🎉

- [Accept request commands as YAML files](https://github.com/kommitters/kadena.ex/milestone/2)

### Done - What we've already developed! 🚀

<details>
Expand All @@ -1873,6 +1972,7 @@ You can see a big picture of the roadmap here: [**ROADMAP**][roadmap]
- [Pact Commands Builder](https://github.com/kommitters/kadena.ex/issues/131)
- [Chainweb](https://github.com/kommitters/kadena.ex/issues/57)
- [Chainweb P2P API](https://github.com/kommitters/kadena.ex/milestone/1)
- [Accept request commands as YAML files](https://github.com/kommitters/kadena.ex/milestone/2)

</details>

Expand Down
75 changes: 73 additions & 2 deletions lib/pact/command/cont_command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Kadena.Pact.ContCommand do

alias Kadena.Chainweb.Pact.CommandPayload
alias Kadena.Cryptography.{Sign, Utils}
alias Kadena.Pact.Command.Hash
alias Kadena.Pact.Command.{Hash, YamlReader}

alias Kadena.Types.{
Command,
Expand Down Expand Up @@ -103,7 +103,34 @@ defmodule Kadena.Pact.ContCommand do
def new(_opts), do: %__MODULE__{}

@impl true
def from_yaml(_path), do: new()
def from_yaml(path) when is_binary(path) do
with {:ok, map_result} <- YamlReader.read(path) do
network_id = Map.get(map_result, "networkId")
data = Map.get(map_result, "data")
nonce = Map.get(map_result, "nonce", "")
meta_data = Map.get(map_result, "publicMeta", MetaData.new())
pact_tx_hash = Map.get(map_result, "pactTxHash", "")
step = Map.get(map_result, "step", 0)
proof = Map.get(map_result, "proof")
rollback = Map.get(map_result, "rollback", true)
keypairs = Map.get(map_result, "keyPairs", [])
signers = Map.get(map_result, "signers", [])

%__MODULE__{}
|> process_metadata(meta_data)
|> process_keypairs(keypairs)
|> process_signers(signers)
|> set_network(network_id)
|> set_data(data)
|> set_nonce(nonce)
|> set_pact_tx_hash(pact_tx_hash)
|> set_proof(proof)
|> set_step(step)
|> set_rollback(rollback)
end
end

def from_yaml(_path), do: {:error, [path: :invalid]}

@impl true
def set_network(%__MODULE__{} = cmd_request, network) do
Expand Down Expand Up @@ -313,4 +340,48 @@ defmodule Kadena.Pact.ContCommand do

defp build_signatures([%SignCommand{sig: sig} | rest], result),
do: build_signatures(rest, result ++ [Signature.new(sig)])

defp process_metadata(%__MODULE__{} = cmd_request, %MetaData{} = metadata),
do: set_metadata(cmd_request, metadata)

defp process_metadata(%__MODULE__{} = cmd_request, %{} = metadata) do
case MetaData.new(metadata) do
%MetaData{} = result -> %{cmd_request | meta_data: result}
{:error, reason} -> {:error, [meta_data: :invalid] ++ reason}
end
end

defp process_metadata(%__MODULE__{}, _metadata), do: {:error, [metadata: :invalid]}

defp process_keypairs(%__MODULE__{} = cmd_request, [%{} = keypair_data | rest]) do
case KeyPair.new(keypair_data) do
%KeyPair{} = result ->
cmd_request
|> add_keypair(result)
|> process_keypairs(rest)

{:error, reason} ->
{:error, [keypair: :invalid] ++ reason}
end
end

defp process_keypairs(%__MODULE__{} = cmd_request, []), do: cmd_request
defp process_keypairs(%__MODULE__{}, _keypair), do: {:error, [keypair: :invalid]}
defp process_keypairs({:error, reason}, _keypairs), do: {:error, reason}

defp process_signers(%__MODULE__{} = cmd_request, [%{} = signers_data | rest]) do
case Signer.new(signers_data) do
%Signer{} = result ->
cmd_request
|> add_signer(result)
|> process_signers(rest)

{:error, reason} ->
{:error, [signers: :invalid] ++ reason}
end
end

defp process_signers(%__MODULE__{} = cmd_request, []), do: cmd_request
defp process_signers({:error, reason}, _signers), do: {:error, reason}
defp process_signers(%__MODULE__{}, _signers), do: {:error, [signers: :invalid]}
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Kadena.MixProject do
use Mix.Project

@version "0.18.0"
@version "0.19.0"
@github_url "https://github.com/kommitters/kadena.ex"

def project do
Expand Down Expand Up @@ -46,7 +46,7 @@ defmodule Kadena.MixProject do
{:yaml_elixir, "~> 2.9"},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.24", only: :dev, runtime: false},
{:ex_doc, "~> 0.29", only: :dev, runtime: false},
{:excoveralls, "~> 0.15", only: :test}
]
end
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
"earmark_parser": {:hex, :earmark_parser, "1.4.30", "0b938aa5b9bafd455056440cdaa2a79197ca5e693830b4a982beada840513c5f", [:mix], [], "hexpm", "3b5385c2d36b0473d0b206927b841343d25adb14f95f0110062506b300cd5a1b"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.29.0", "4a1cb903ce746aceef9c1f9ae8a6c12b742a5461e6959b9d3b24d813ffbea146", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "f096adb8bbca677d35d278223361c7792d496b3fc0d0224c9d4bc2f651af5db1"},
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
"excoveralls": {:hex, :excoveralls, "0.15.0", "ac941bf85f9f201a9626cc42b2232b251ad8738da993cf406a4290cacf562ea4", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9631912006b27eca30a2f3c93562bc7ae15980afb014ceb8147dc5cdd8f376f1"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"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"},
Expand Down
Loading

0 comments on commit 3604fcd

Please sign in to comment.