Skip to content

Commit

Permalink
Add requested changes and update stellar_base dep
Browse files Browse the repository at this point in the history
Co-authored-by: Edwin Steven Guayacan <EdwinGuayacan@users.noreply.github.com>
  • Loading branch information
Odraxs and EdwinGuayacan committed Aug 2, 2023
1 parent ee4b9a3 commit 7d2c913
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 47 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* [Upload Contract Code (WASM)](/docs/examples/soroban/upload_contract_code.md)
* [Create Contract](/docs/examples/soroban/create_contract.md)
* [Invoke Contract Function](/docs/examples/soroban/invoke_contract_functions.md)
* [Bump Footprint Expiration](/docs/examples/soroban/bump_footprint_expiration.md)
9 changes: 6 additions & 3 deletions docs/examples/soroban/bump_footprint_expiration.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Bump Footprint Expiration
Soroban smart contracts have an expiration time and they should subsidize the shared state lifetime extension fees by manually submitting bump operations, the `BumpFootprintExpirationOp` is used to extend this lifetime.

> **Warning**
> Please note that Soroban is still under development, so breaking changes may occur.
> **Note**
> All this actions require to use `simulateTransaction` and `sendTransaction` RPC endpoints when specified in the code comments to achieve the contract upload.
> All this actions require to use `simulateTransaction` and `sendTransaction` RPC endpoints when specified in the code comments to achieve the bump footprint expiration.
```elixir
alias Stellar.TxBuild.{
Expand All @@ -16,6 +17,7 @@ alias Stellar.TxBuild.{
SCVal,
SequenceNumber,
Signature,
SorobanResources,
SorobanTransactionData
}

Expand Down Expand Up @@ -45,13 +47,14 @@ contract_code = LedgerKey.new({:contract_code, [hash: hash, body_type: :data_ent
footprint = LedgerFootprint.new(read_only: [contract_data, contract_code])

soroban_data =
TxSorobanResources.new(
[
footprint: footprint,
instructions: 0,
read_bytes: 0,
write_bytes: 0,
extended_meta_data_size_bytes: 0
)
]
|> SorobanResources.new()
|> (&SorobanTransactionData.new(resources: &1, refundable_fee: 0)).()
|> SorobanTransactionData.to_xdr()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Stellar.TxBuild.Ledger.LedgerKeyContractCode do
defmodule Stellar.TxBuild.Ledger.ContractCode do
@moduledoc """
`LedgerKeyContractCode` struct definition.
`ContractCode` struct definition.
"""

alias StellarBase.XDR.{ContractEntryBodyType, Hash, LedgerKeyContractCode}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Stellar.TxBuild.Ledger.LedgerKeyContractData do
defmodule Stellar.TxBuild.Ledger.ContractData do
@moduledoc """
`LedgerKeyContractData` struct definition.
`ContractData` struct definition.
"""

import Stellar.TxBuild.Validations,
Expand Down
16 changes: 8 additions & 8 deletions lib/tx_build/ledger_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule Stellar.TxBuild.LedgerKey do
Account,
ClaimableBalance,
Data,
LedgerKeyContractCode,
LedgerKeyContractData,
ContractCode,
ContractData,
LiquidityPool,
Offer,
Trustline
Expand All @@ -35,8 +35,8 @@ defmodule Stellar.TxBuild.LedgerKey do
| LiquidityPool.t()
| Offer.t()
| Trustline.t()
| LedgerKeyContractData.t()
| LedgerKeyContractCode.t()
| ContractData.t()
| ContractCode.t()

@type t :: %__MODULE__{type: type(), entry: entry()}

Expand Down Expand Up @@ -100,8 +100,8 @@ defmodule Stellar.TxBuild.LedgerKey do
{:contract_data, args},
_opts
) do
case LedgerKeyContractData.new(args) do
%LedgerKeyContractData{} = contract_data ->
case ContractData.new(args) do
%ContractData{} = contract_data ->
%__MODULE__{type: :contract_data, entry: contract_data}

_error ->
Expand All @@ -113,8 +113,8 @@ defmodule Stellar.TxBuild.LedgerKey do
{:contract_code, args},
_opts
) do
case LedgerKeyContractCode.new(args) do
%LedgerKeyContractCode{} = contract_code ->
case ContractCode.new(args) do
%ContractCode{} = contract_code ->
%__MODULE__{type: :contract_code, entry: contract_code}

_error ->
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"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"},
"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"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"stellar_base": {:hex, :stellar_base, "0.13.0", "75bebe0401225df40336e7c510f5c36dda6ad7486011d43a63d55c5a9bc5fb14", [:mix], [{:crc, "~> 0.10.0", [hex: :crc, repo: "hexpm", optional: false]}, {:elixir_xdr, "~> 0.3.9", [hex: :elixir_xdr, repo: "hexpm", optional: false]}], "hexpm", "e92b5ca2a01bf2a4cf75bb699139626d46a3680932b2b93b594c9d54781d5827"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"stellar_base": {:hex, :stellar_base, "0.13.1", "ac3d1d6b5ad131eb27fbbdd8bfb42f998ea14c48e341a5cb091aa05a80c62deb", [:mix], [{:crc, "~> 0.10.0", [hex: :crc, repo: "hexpm", optional: false]}, {:elixir_xdr, "~> 0.3.9", [hex: :elixir_xdr, repo: "hexpm", optional: false]}], "hexpm", "8b72a9e0bb1cb13a031ace0c49ae51787ddd616f9d6333c2a3411cab068bc9c1"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Stellar.TxBuild.Ledger.LedgerKeyContractCodeTest do
defmodule Stellar.TxBuild.Ledger.ContractCodeTest do
use ExUnit.Case

alias Stellar.TxBuild.Ledger.LedgerKeyContractCode
alias Stellar.TxBuild.Ledger.ContractCode

setup do
hash = "ABC123"
Expand All @@ -16,17 +16,17 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractCodeTest do
end

test "new/1 data_entry", %{hash: hash, body_type_data_entry: body_type} do
%LedgerKeyContractCode{hash: ^hash, body_type: ^body_type} =
LedgerKeyContractCode.new(hash: hash, body_type: body_type)
%ContractCode{hash: ^hash, body_type: ^body_type} =
ContractCode.new(hash: hash, body_type: body_type)
end

test "new/1 expiration_ext", %{hash: hash, body_type_expiration_ext: body_type} do
%LedgerKeyContractCode{hash: ^hash, body_type: ^body_type} =
LedgerKeyContractCode.new([{:hash, hash}, {:body_type, body_type}])
%ContractCode{hash: ^hash, body_type: ^body_type} =
ContractCode.new([{:hash, hash}, {:body_type, body_type}])
end

test "new/1 with invalid args" do
{:error, :invalid_ledger_key_args} = LedgerKeyContractCode.new("ABC", "ABC")
{:error, :invalid_ledger_key_args} = ContractCode.new("ABC", "ABC")
end

test "to_xdr/1 data_entry", %{hash: hash, body_type_data_entry: body_type} do
Expand All @@ -35,8 +35,8 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractCodeTest do
body_type: %StellarBase.XDR.ContractEntryBodyType{identifier: :DATA_ENTRY}
} =
[{:hash, hash}, {:body_type, body_type}]
|> LedgerKeyContractCode.new()
|> LedgerKeyContractCode.to_xdr()
|> ContractCode.new()
|> ContractCode.to_xdr()
end

test "to_xdr/1 expiration_ext", %{hash: hash, body_type_expiration_ext: body_type} do
Expand All @@ -45,11 +45,11 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractCodeTest do
body_type: %StellarBase.XDR.ContractEntryBodyType{identifier: :EXPIRATION_EXTENSION}
} =
[{:hash, hash}, {:body_type, body_type}]
|> LedgerKeyContractCode.new()
|> LedgerKeyContractCode.to_xdr()
|> ContractCode.new()
|> ContractCode.to_xdr()
end

test "to_xdr/1 with invalid struct" do
{:error, :invalid_struct} = LedgerKeyContractCode.to_xdr(%{})
{:error, :invalid_struct} = ContractCode.to_xdr(%{})
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
defmodule Stellar.TxBuild.Ledger.ContractDataTest do
use ExUnit.Case

alias Stellar.TxBuild.SCAddress
alias Stellar.TxBuild.Ledger.LedgerKeyContractData
alias Stellar.TxBuild.Ledger.ContractData

setup do
contract = SCAddress.new("CCEMOFO5TE7FGOAJOA3RDHPC6RW3CFXRVIGOFQPFE4ZGOKA2QEA636SN")
Expand All @@ -28,13 +28,13 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
durability_temporary: durability,
body_type_data_entry: body_type
} do
%LedgerKeyContractData{
%ContractData{
contract: ^contract,
key: ^key,
durability: ^durability,
body_type: ^body_type
} =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: key,
durability: durability,
Expand All @@ -48,13 +48,13 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
durability_persistent: durability,
body_type_expiration_ext: body_type
} do
%LedgerKeyContractData{
%ContractData{
contract: ^contract,
key: ^key,
durability: ^durability,
body_type: ^body_type
} =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: key,
durability: durability,
Expand All @@ -64,7 +64,7 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do

test "new/1 with invalid args" do
{:error, :invalid_ledger_key_args} =
LedgerKeyContractData.new(
ContractData.new(
contract: "ABC",
key: "ABC",
durability: "invalid_durability",
Expand All @@ -78,7 +78,7 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
body_type_expiration_ext: body_type
} do
{:error, :invalid_key} =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: "invalid_key",
durability: durability,
Expand Down Expand Up @@ -108,13 +108,13 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
durability: %StellarBase.XDR.ContractDataDurability{identifier: :TEMPORARY},
body_type: %StellarBase.XDR.ContractEntryBodyType{identifier: :DATA_ENTRY}
} =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: key,
durability: durability,
body_type: body_type
)
|> LedgerKeyContractData.to_xdr()
|> ContractData.to_xdr()
end

test "to_xdr/1 expiration_ext", %{
Expand All @@ -139,16 +139,16 @@ defmodule Stellar.TxBuild.Ledger.LedgerKeyContractDataTest do
durability: %StellarBase.XDR.ContractDataDurability{identifier: :PERSISTENT},
body_type: %StellarBase.XDR.ContractEntryBodyType{identifier: :EXPIRATION_EXTENSION}
} =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: key,
durability: durability,
body_type: body_type
)
|> LedgerKeyContractData.to_xdr()
|> ContractData.to_xdr()
end

test "to_xdr/1 with invalid struct" do
{:error, :invalid_struct} = LedgerKeyContractData.to_xdr(%{})
{:error, :invalid_struct} = ContractData.to_xdr(%{})
end
end
8 changes: 4 additions & 4 deletions test/tx_build/ledger_key_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Stellar.TxBuild.LedgerKeyTest do
Account,
ClaimableBalance,
Data,
LedgerKeyContractCode,
LedgerKeyContractData,
ContractCode,
ContractData,
LiquidityPool,
Offer,
Trustline
Expand Down Expand Up @@ -200,7 +200,7 @@ defmodule Stellar.TxBuild.LedgerKeyTest do
body_type = :data_entry

contract_data =
LedgerKeyContractData.new(
ContractData.new(
contract: contract,
key: key,
durability: durability,
Expand Down Expand Up @@ -242,7 +242,7 @@ defmodule Stellar.TxBuild.LedgerKeyTest do
hash = "ABC123"
body_type = :data_entry

contract_code = LedgerKeyContractCode.new(hash: hash, body_type: body_type)
contract_code = ContractCode.new(hash: hash, body_type: body_type)

contract_code_args = [hash: hash, body_type: body_type]

Expand Down

0 comments on commit 7d2c913

Please sign in to comment.