Skip to content

Commit

Permalink
Merge pull request #317 from kommitters/v0.16
Browse files Browse the repository at this point in the history
Release v0.16.0
  • Loading branch information
Odraxs authored Jul 25, 2023
2 parents ff444b7 + 094123d commit 0b783ef
Show file tree
Hide file tree
Showing 77 changed files with 3,152 additions and 3,300 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -30,8 +30,8 @@ jobs:
repo.hex.pm:443
builds.hex.pm:443
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: erlef/setup-elixir@c2e02f777c158310fc6d3d4e11b36a52d2d52db8 # v1.15.4
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: erlef/setup-elixir@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
MIX_ENV: test
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -32,8 +32,8 @@ jobs:
repo.hex.pm:443
builds.hex.pm:443
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: erlef/setup-elixir@c2e02f777c158310fc6d3d4e11b36a52d2d52db8 # v1.15.4
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: erlef/setup-elixir@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -37,12 +37,12 @@ jobs:
sigstore-tuf-root.storage.googleapis.com:443
- name: "Checkout code"
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@80e868c13c90f172d68d1f4501dee99e2479f7af # v2.1.3
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -69,6 +69,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@f3feb00acb00f31a6f60280e6ace9ca31d91c76a # v2.3.2
uses: github/codeql-action/upload-sarif@1813ca74c3faaa3a2da2070b9b8a0b3e7373a0d8 # v2.21.0
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.16.0 (25.07.2023)

* Add support for contract function invocation with Soroban Preview 10.
* Update all dependencies.

## 0.15.1 (13.06.2023)

* Fix `SCAddress` contract type.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** +
```elixir
def deps do
[
{:stellar_sdk, "~> 0.15.1"}
{:stellar_sdk, "~> 0.16.0"}
]
end
```
Expand Down
82 changes: 37 additions & 45 deletions docs/examples/soroban/invoke_contract_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,24 @@ alias Stellar.TxBuild.{
BaseFee,
InvokeHostFunction,
HostFunction,
HostFunctionArgs,
SCVal,
SCVec,
SequenceNumber,
Signature
}

alias Stellar.Horizon.Accounts
alias Stellar.KeyPair

contract_id = "5099ae2fa8453c363a9a71cdf8198ca258d12fa44bb5dc68ae0225595f461d37"
function_name = "hello"
args = [SCVal.new(string: "world")]

function_args =
HostFunctionArgs.new(
type: :invoke,
contract_id: contract_id,
function_name: function_name,
args: args
)
contract_address =
"CD3HNKU3ERTEYLBBBVTSOYE4ZL2ZWV7NHLQIZRRKC4CBNMZXC7ISBXHV"
|> SCAddress.new()
|> (&SCVal.new(address: &1)).()
function_name = SCVal.new(symbol: "hello")
args = SCVec.new([contract_address, function_name, SCVal.new(string: "dev")])

function = HostFunction.new(args: function_args)
invoke_host_function_op = InvokeHostFunction.new(functions: [function])
host_function = HostFunction.new(invoke_contract: args)
invoke_host_function_op = InvokeHostFunction.new(host_function: host_function)
keypair = {public_key, _secret} = Stellar.KeyPair.from_secret_seed("SDR...Q24")
source_account = Account.new(public_key)
{:ok, seq_num} = Accounts.fetch_next_sequence_number(public_key)
Expand All @@ -55,8 +50,8 @@ source_account
soroban_data =
"AAAAAgAAAAZQma4vqEU8Njqacc34GYyiWNEvpEu13GiuAiVZX0YdNwAAABQAAAAHRhmB7Imi4CwJhmzp1r/d76UShPJrO5PSHOV2Z9tPbE8AAAAAABJ8KwAAE3AAAAAAAAAAAAAAAAAAAAAAAAAAAA=="

min_resource_fee = 28_231
fee = BaseFee.new(min_resource_fee + 100)
min_resource_fee = 51_470
fee = BaseFee.new(min_resource_fee)

# Use the XDR generated here to send it to the futurenet
source_account
Expand All @@ -73,12 +68,10 @@ source_account

```elixir
alias Stellar.TxBuild.{
ContractAuth,
AuthorizedInvocation,
InvokeHostFunction,
HostFunction,
HostFunctionArgs,
SCVal,
SCVec,
SCAddress,
SequenceNumber,
Signature
Expand All @@ -87,48 +80,47 @@ alias Stellar.TxBuild.{
alias Stellar.Horizon.Accounts
alias Stellar.KeyPair

contract_id = "5099ae2fa8453c363a9a71cdf8198ca258d12fa44bb5dc68ae0225595f461d37"
function_name = "inc"
contract_address =
"CD3HNKU3ERTEYLBBBVTSOYE4ZL2ZWV7NHLQIZRRKC4CBNMZXC7ISBXHV"
|> SCAddress.new()
|> (&SCVal.new(address: &1)).()
function_name = SCVal.new(symbol: "inc")
keypair = {public_key, _secret} = Stellar.KeyPair.from_secret_seed("SDR...Q24")
address_type = SCAddress.new(public_key)
address = SCVal.new(address: address_type)
args = [address, SCVal.new(u128: %{hi: 0, lo: 2})]

function_args =
HostFunctionArgs.new(
type: :invoke,
contract_id: contract_id,
function_name: function_name,
args: args
)

auth_invocation =
AuthorizedInvocation.new(
contract_id: contract_id,
function_name: function_name,
args: args,
sub_invocations: []
)
args =
SCVec.new([
contract_address,
function_name,
address,
SCVal.new(u128: %{hi: 0, lo: 2})
])

contract_auth = ContractAuth.new(authorized_invocation: auth_invocation)
function = HostFunction.new(args: function_args, auth: [contract_auth])
invoke_host_function_op = InvokeHostFunction.new(functions: [function])
host_function = HostFunction.new(invoke_contract: args)
invoke_host_function_op = InvokeHostFunction.new(host_function: host_function)
source_account = Stellar.TxBuild.Account.new(public_key)
{:ok, seq_num} = Accounts.fetch_next_sequence_number(public_key)
sequence_number = SequenceNumber.new(seq_num)
signature = Stellar.TxBuild.Signature.new(keypair)

# Use this XDR to simulate the transaction and get the soroban_data and min_resource_fee
# Use this XDR to simulate the transaction and get the soroban_data, the invoke_host_function auth
# and the min_resource_fee
source_account
|> Stellar.TxBuild.new(sequence_number: sequence_number)
|> Stellar.TxBuild.add_operation(invoke_host_function_op)
|> Stellar.TxBuild.envelope()

# Simulate Transaction
soroban_data =
"AAAAAgAAAAZQma4vqEU8Njqacc34GYyiWNEvpEu13GiuAiVZX0YdNwAAABQAAAAHRhmB7Imi4CwJhmzp1r/d76UShPJrO5PSHOV2Z9tPbE8AAAABAAAABlCZri+oRTw2OppxzfgZjKJY0S+kS7XcaK4CJVlfRh03AAAAEAAAAAEAAAACAAAADwAAAAdDb3VudGVyAAAAABMAAAAAAAAAAFo7IZ8b8ZTqK07QSVwodwWpVL59s3lsa3DTIMLBYrHaABOFdgAAFGQAAAD0AAAB6AAAAAAAAABgAAAAAA=="
"AAAAAAAAAAEAAAAHmDXys1KuBimD87u2AiUG/jb5CqOkQW/qASpb6gMVRlsAAAAAAAAAAQAAAAYAAAAB9naqmyRmTCwhDWcnYJzK9ZtX7TrgjMYqFwQWszcX0SAAAAAUAAAAAQAAAAAANnOcAAAUOAAAAQQAAAK8AAAAAAAAAIk="

min_resource_fee = 60_839
auth = [
"AAAAAAAAAAAAAAAB9naqmyRmTCwhDWcnYJzK9ZtX7TrgjMYqFwQWszcX0SAAAAADaW5jAAAAAAIAAAASAAAAAAAAAABaOyGfG/GU6itO0ElcKHcFqVS+fbN5bGtw0yDCwWKx2gAAAAkAAAAAAAAAAAAAAAAAAAACAAAAAA=="
]

invoke_host_function_op = InvokeHostFunction.set_auth(invoke_host_function_op, auth)
min_resource_fee = 78_281
fee = BaseFee.new(min_resource_fee + 100)

# Use the XDR generated here to send it to the futurenet
Expand All @@ -141,7 +133,7 @@ source_account
|> Stellar.TxBuild.envelope()
```

### With Stellar Account Authorization
### With Stellar Account Authorization (WIP: Preview 10 support)

```elixir
alias StellarBase.XDR.{SorobanResources, SorobanTransactionData, UInt32}
Expand Down Expand Up @@ -249,4 +241,4 @@ source_account
|> Stellar.TxBuild.sign(signature)
|> Stellar.TxBuild.envelope()

```
```
3 changes: 1 addition & 2 deletions lib/tx_build/account_merge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Stellar.TxBuild.AccountMerge do
import Stellar.TxBuild.Validations, only: [validate_account: 1, validate_optional_account: 1]

alias Stellar.TxBuild.{Account, OptionalAccount}
alias StellarBase.XDR.{OperationBody, OperationType, Operations.AccountMerge}
alias StellarBase.XDR.{OperationBody, OperationType}

@behaviour Stellar.TxBuild.XDR

Expand Down Expand Up @@ -35,7 +35,6 @@ defmodule Stellar.TxBuild.AccountMerge do

destination
|> Account.to_xdr()
|> AccountMerge.new()
|> OperationBody.new(op_type)
end
end
56 changes: 0 additions & 56 deletions lib/tx_build/address_with_nonce.ex

This file was deleted.

Loading

0 comments on commit 0b783ef

Please sign in to comment.