Skip to content

Commit 3604fcd

Browse files
authored
Merge pull request #276 from kommitters/v0.19
Release v0.19.0
2 parents 5482acb + caefdb3 commit 3604fcd

18 files changed

+323
-49
lines changed

.github/workflows/cd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
hex.pm:443
3030
repo.hex.pm:443
3131

32-
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
33-
- uses: erlef/setup-elixir@b980a5ac9b7316a23ebc16de2bb69b7c3ad731b5 # v1.15.0
32+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
33+
- uses: erlef/setup-elixir@e3f6ffe2878180f57318bf13febd3933ee81f664 # v1.15.2
3434
with:
3535
otp-version: ${{ matrix.otp }}
3636
elixir-version: ${{ matrix.elixir }}
37-
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3.2.2
37+
- uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
3838
with:
3939
path: deps
4040
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ jobs:
3333
github.com:443
3434
repo.hex.pm:443
3535

36-
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 # v2.6.0
37-
- uses: erlef/setup-beam@b980a5ac9b7316a23ebc16de2bb69b7c3ad731b5 # v1.15.0
36+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
37+
- uses: erlef/setup-beam@e3f6ffe2878180f57318bf13febd3933ee81f664 # v1.15.2
3838
id: beam
3939
with:
4040
otp-version: "24"
4141
elixir-version: "1.13.4"
42-
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # v2.1.7
42+
- uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
4343
with:
4444
path: deps
4545
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
@@ -50,7 +50,7 @@ jobs:
5050
- name: Check Formatting
5151
run: mix format --check-formatted
5252
- name: Restore PLT cache
53-
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # v2.1.7
53+
uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
5454
id: plt_cache
5555
with:
5656
key: |

.github/workflows/scorecards.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ jobs:
3737
sigstore-tuf-root.storage.googleapis.com:443
3838

3939
- name: "Checkout code"
40-
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
40+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
4141
with:
4242
persist-credentials: false
4343

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

7070
# Upload the results to GitHub's code scanning dashboard.
7171
- name: "Upload to code-scanning"
72-
uses: github/codeql-action/upload-sarif@c7f292ea4f542c473194b33813ccd4c207a6c725 # v2.1.21
72+
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1
7373
with:
7474
sarif_file: results.sarif

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.19.0 (01.02.2023)
4+
5+
- Added [YAML Continuation command](https://github.com/kommitters/kadena.ex/issues/209)
6+
- Update all dependencies
7+
38
## 0.18.0 (31.01.2023)
49

510
- Added [YAML reader](https://github.com/kommitters/kadena.ex/issues/253)

README.md

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Add `kadena` to your list of dependencies in `mix.exs`:
2727
```elixir
2828
def deps do
2929
[
30-
{:kadena, "~> 0.18.0"}
30+
{:kadena, "~> 0.19.0"}
3131
]
3232
end
3333
```
@@ -350,17 +350,17 @@ env_data = %{accounts_admin_keyset: [keypair.pub_key]}
350350
}}
351351
```
352352

353-
#### With a `YAML` file
353+
#### From a `YAML` file
354354

355355
YAML struct:
356356

357357
- `networkId`: [NetworkID](#networkid) value.
358358
- `code`: there are two ways to set the code from the `YAML` file:
359359
- `code`: [Code](#code) value.
360-
- `codeFile`: The name of a `pact` file in the same directory as the `YAML` file.
360+
- `codeFile`: The name of a `pact` file in the same directory as the `YAML` file. For example, `code.pact`.
361361
- `data`: there are two ways to set the data from the `YAML` file:
362362
- `data`: [EnvData](#envdata) value.
363-
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file.
363+
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file. For example, `data.json`.
364364
- `nonce`: [Nonce](#nonce) value.
365365
- `publicMeta`: [Metadata](#metadata) value.
366366
- `keyPairs`: [KeyPairs](#keypairs) values.
@@ -422,7 +422,7 @@ keyPairs:
422422
```elixir
423423
alias Kadena.Pact.ExecCommand
424424

425-
"~/your_file_path"
425+
"~/example.yaml"
426426
|> ExecCommand.from_yaml()
427427
|> ExecCommand.build()
428428

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

446446
### Building a Continuation Command
447447

448+
There are two ways to create a ContCommand.
449+
450+
#### Using [attributes](#attributes) structures
451+
448452
```elixir
449453
alias Kadena.Cryptography
450454
alias Kadena.Pact
@@ -508,6 +512,107 @@ rollback = true
508512
}}
509513
```
510514

515+
#### From a `YAML` file
516+
517+
YAML struct:
518+
519+
- `networkId`: [NetworkID](#networkid) value.
520+
- `data`: there are two ways to set the data from the `YAML` file:
521+
- `data`: [EnvData](#envdata) value.
522+
- `dataFile`: The name of a `json` file in the same directory as the `YAML` file. For example, `data.json`.
523+
- `nonce`: [Nonce](#nonce) value.
524+
- `publicMeta`: [Metadata](#metadata) value.
525+
- `keyPairs`: [KeyPairs](#keypairs) values.
526+
- `signers`: [Signers](#signers) values.
527+
- `pactTxHash`: [PactTxHash](#pacttxhash-continuation-command) value.
528+
- `rollback`: [Rollback](#rollback-continuation-command) value.
529+
- `Step`: [Step](#step-continuation-command) value.
530+
- `proof`: [Proof](#proof-continuation-command) value.
531+
532+
533+
The scheme below shows how to set the different values of a `ContCommand`
534+
535+
```YAML
536+
networkId:
537+
data/dataFile:
538+
nonce:
539+
publicMeta:
540+
creationTime:
541+
chainId:
542+
gasLimit:
543+
gasPrice:
544+
ttl:
545+
sender:
546+
keyPairs:
547+
- public:
548+
secret:
549+
signers:
550+
- publicKey:
551+
scheme:
552+
addr:
553+
capsList:
554+
- name:
555+
args:
556+
-
557+
pactTxHash:
558+
step:
559+
rollback:
560+
proof:
561+
562+
```
563+
**Example**
564+
565+
YAML file:
566+
```YAML
567+
networkId: :testnet04
568+
data:
569+
accounts_admin_keyset:
570+
- 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
571+
nonce: 2023-01-01 00:00:00.000000 UTC
572+
publicMeta:
573+
creationTime: 1667249173
574+
chainId: "0"
575+
gasLimit: 2500
576+
gasPrice: 0.01
577+
ttl: 28800
578+
sender: k:6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
579+
keyPairs:
580+
- public: 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
581+
secret: 99f7e1e8f2f334ae8374aa28bebdb997271a0e0a5e92c80be9609684a3d6f0d4
582+
capsList:
583+
name: coin.GAS
584+
args:
585+
- 6ffea3fabe4e7fe6a89f88fc6d662c764ed1359fbc03a28afdac3935415347d7
586+
pactTxHash: yxM0umrtdcvSUZDc_GSjwadH6ELYFCjOqI59Jzqapi4
587+
step: 1
588+
rollback: true
589+
590+
```
591+
592+
```elixir
593+
alias Kadena.Pact.ContCommand
594+
595+
"~/example.yaml"
596+
|> ContCommand.from_yaml()
597+
|> ContCommand.build()
598+
599+
{:ok,
600+
%Kadena.Types.Command{
601+
cmd:
602+
"{\"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\"}]}",
603+
hash: %Kadena.Types.PactTransactionHash{
604+
hash: "psIXOGGneMAV1Ie3zx5O1VWMFueFZrShvaBx4YOCkjQ"
605+
},
606+
sigs: [
607+
%Kadena.Types.Signature{
608+
sig:
609+
"1ae6e796bbf8e1ddb005945508ac6fd13cc6435c4f63609cff299114865fd13879b8b5bcad13383ae377acc10411e49e745397320a2ba5bf9d1370cafbf90a06"
610+
}
611+
]
612+
}}
613+
614+
```
615+
511616
## Chainweb Pact API
512617

513618
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.
@@ -1839,14 +1944,8 @@ Chainweb.Peer.new()
18391944

18401945
## Roadmap
18411946

1842-
The latest updated branch to target a PR is `v0.19`
1843-
18441947
You can see a big picture of the roadmap here: [**ROADMAP**][roadmap]
18451948

1846-
### What we're working on now 🎉
1847-
1848-
- [Accept request commands as YAML files](https://github.com/kommitters/kadena.ex/milestone/2)
1849-
18501949
### Done - What we've already developed! 🚀
18511950

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

18771977
</details>
18781978

lib/pact/command/cont_command.ex

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Kadena.Pact.ContCommand do
66

77
alias Kadena.Chainweb.Pact.CommandPayload
88
alias Kadena.Cryptography.{Sign, Utils}
9-
alias Kadena.Pact.Command.Hash
9+
alias Kadena.Pact.Command.{Hash, YamlReader}
1010

1111
alias Kadena.Types.{
1212
Command,
@@ -103,7 +103,34 @@ defmodule Kadena.Pact.ContCommand do
103103
def new(_opts), do: %__MODULE__{}
104104

105105
@impl true
106-
def from_yaml(_path), do: new()
106+
def from_yaml(path) when is_binary(path) do
107+
with {:ok, map_result} <- YamlReader.read(path) do
108+
network_id = Map.get(map_result, "networkId")
109+
data = Map.get(map_result, "data")
110+
nonce = Map.get(map_result, "nonce", "")
111+
meta_data = Map.get(map_result, "publicMeta", MetaData.new())
112+
pact_tx_hash = Map.get(map_result, "pactTxHash", "")
113+
step = Map.get(map_result, "step", 0)
114+
proof = Map.get(map_result, "proof")
115+
rollback = Map.get(map_result, "rollback", true)
116+
keypairs = Map.get(map_result, "keyPairs", [])
117+
signers = Map.get(map_result, "signers", [])
118+
119+
%__MODULE__{}
120+
|> process_metadata(meta_data)
121+
|> process_keypairs(keypairs)
122+
|> process_signers(signers)
123+
|> set_network(network_id)
124+
|> set_data(data)
125+
|> set_nonce(nonce)
126+
|> set_pact_tx_hash(pact_tx_hash)
127+
|> set_proof(proof)
128+
|> set_step(step)
129+
|> set_rollback(rollback)
130+
end
131+
end
132+
133+
def from_yaml(_path), do: {:error, [path: :invalid]}
107134

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

314341
defp build_signatures([%SignCommand{sig: sig} | rest], result),
315342
do: build_signatures(rest, result ++ [Signature.new(sig)])
343+
344+
defp process_metadata(%__MODULE__{} = cmd_request, %MetaData{} = metadata),
345+
do: set_metadata(cmd_request, metadata)
346+
347+
defp process_metadata(%__MODULE__{} = cmd_request, %{} = metadata) do
348+
case MetaData.new(metadata) do
349+
%MetaData{} = result -> %{cmd_request | meta_data: result}
350+
{:error, reason} -> {:error, [meta_data: :invalid] ++ reason}
351+
end
352+
end
353+
354+
defp process_metadata(%__MODULE__{}, _metadata), do: {:error, [metadata: :invalid]}
355+
356+
defp process_keypairs(%__MODULE__{} = cmd_request, [%{} = keypair_data | rest]) do
357+
case KeyPair.new(keypair_data) do
358+
%KeyPair{} = result ->
359+
cmd_request
360+
|> add_keypair(result)
361+
|> process_keypairs(rest)
362+
363+
{:error, reason} ->
364+
{:error, [keypair: :invalid] ++ reason}
365+
end
366+
end
367+
368+
defp process_keypairs(%__MODULE__{} = cmd_request, []), do: cmd_request
369+
defp process_keypairs(%__MODULE__{}, _keypair), do: {:error, [keypair: :invalid]}
370+
defp process_keypairs({:error, reason}, _keypairs), do: {:error, reason}
371+
372+
defp process_signers(%__MODULE__{} = cmd_request, [%{} = signers_data | rest]) do
373+
case Signer.new(signers_data) do
374+
%Signer{} = result ->
375+
cmd_request
376+
|> add_signer(result)
377+
|> process_signers(rest)
378+
379+
{:error, reason} ->
380+
{:error, [signers: :invalid] ++ reason}
381+
end
382+
end
383+
384+
defp process_signers(%__MODULE__{} = cmd_request, []), do: cmd_request
385+
defp process_signers({:error, reason}, _signers), do: {:error, reason}
386+
defp process_signers(%__MODULE__{}, _signers), do: {:error, [signers: :invalid]}
316387
end

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Kadena.MixProject do
22
use Mix.Project
33

4-
@version "0.18.0"
4+
@version "0.19.0"
55
@github_url "https://github.com/kommitters/kadena.ex"
66

77
def project do
@@ -46,7 +46,7 @@ defmodule Kadena.MixProject do
4646
{:yaml_elixir, "~> 2.9"},
4747
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
4848
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
49-
{:ex_doc, "~> 0.24", only: :dev, runtime: false},
49+
{:ex_doc, "~> 0.29", only: :dev, runtime: false},
5050
{:excoveralls, "~> 0.15", only: :test}
5151
]
5252
end

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"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"},
66
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
77
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
8-
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
8+
"earmark_parser": {:hex, :earmark_parser, "1.4.30", "0b938aa5b9bafd455056440cdaa2a79197ca5e693830b4a982beada840513c5f", [:mix], [], "hexpm", "3b5385c2d36b0473d0b206927b841343d25adb14f95f0110062506b300cd5a1b"},
99
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
10-
"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"},
10+
"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"},
1111
"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"},
1212
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
1313
"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"},

0 commit comments

Comments
 (0)