Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gstd v1.3.0 support #5

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "."
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "."
schedule:
interval: "daily"
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ env:

jobs:
build:
name: Build project
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: "ACTIONS: Checkout"
uses: actions/checkout@v4

- name: Install rust toolchain
- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: Cache
- name: "ACTIONS: Setup caching"
uses: Swatinem/rust-cache@v2

- name: Cargo build
- name: "Build"
run: cargo build --release

- name: Cargo test
- name: "Test"
run: cargo test --release

- name: Cargo clippy
- name: "Test: Doc examples"
run: cargo test --release --doc

- name: "Check clippy"
run: cargo clippy --release --all-targets -- -D warnings

- name: Cargo fmt
- name: "Check formatting"
run: cargo fmt -- --check
32 changes: 32 additions & 0 deletions .github/workflows/crates-io.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Crates IO

on:
workflow_dispatch:
inputs:
publish:
description: "If publish packages"
type: boolean
default: false

env:
CARGO_TERM_COLOR: always

jobs:
check:
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- name: "ACTIONS: Checkout"
uses: actions/checkout@v4

- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: "Check packages"
if: ${{ !inputs.publish }}
run: cargo publish --dry-run

- name: "Publish packages"
if: ${{ inputs.publish }}
run: cargo publish
50 changes: 0 additions & 50 deletions .github/workflows/docs.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Sync version

on:
workflow_dispatch:

permissions:
contents: write

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: "ACTIONS: Checkout"
uses: actions/checkout@v4

- name: "Versioning: Sync version with gstd"
run: |
CRATE_NAME="gstd"
GSTD_VERSION=$(
curl -s https://crates.io/api/v1/crates/$CRATE_NAME/versions |
jq -r '.versions[] | .num' | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" |
head -n 1
)

# version = "x.y.z" -> version = "$GSTD_VERSION"
sed -i 's/\(^version = "\)\([0-9]\+\.[0-9]\+\.[0-9]\+\)/\1'$GSTD_VERSION'/' Cargo.toml
# gstd = { version = "=x.y.z", ... } -> gstd = { version = "=$GSTD_VERSION", ... }
sed -i 's/\(gstd = { version = "=\)\([0-9]\+\.[0-9]\+\.[0-9]\+\)/\1'$GSTD_VERSION'/' Cargo.toml

- name: "ACTIONS: Create commit"
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: >-
chore(deps): sync with latest gstd version
file_pattern: Cargo.toml
14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gstd-fluent"
version = "0.1.0"
version = "1.3.0"
authors = ["Gear Technologies"]
edition = "2021"
description = "A wrapper over gstd that provides a fluent interface to interact with the Gear Protocol"
Expand All @@ -10,7 +10,17 @@ keywords = ["gstd", "smart-contracts", "gear-tech", "gear-foundation"]
categories = ["api-bindings", "no-std"]

[dependencies]
gstd = { git = "https://github.com/gear-tech/gear.git", rev = "946ac47" }
gstd = { version = "=1.3.0", default-features = false }

[features]
default = ["panic-message"]

panic-handler = ["gstd/panic-handler"]
panic-message = ["gstd/panic-message"]
panic-location = ["gstd/panic-location"]

nightly = ["gstd/nightly"]
panic-info-message = ["gstd/panic-info-message"]
oom-handler = ["gstd/oom-handler"]

debug = ["gstd/debug"]
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
[lic_badge]: https://img.shields.io/badge/License-MIT-success
[lic_href]: LICENSE

[docs_badge]: https://img.shields.io/badge/Docs-online-5023dd
[docs_href]: https://dapp.rs/gstd-fluent/gstd_fluent/
[docs_badge]: https://img.shields.io/badge/Docs-online-5023dd?logo=rust
[docs_href]: https://docs.rs/gstd-fluent/

A wrapper over [gstd](https://github.com/gear-tech/gear/tree/master/gstd)
that provides a fluent interface to interact with the Gear Protocol.

To use the default implementation, you should replace `gstd` with `gstd-fluent` in your `Cargo.toml` file:

```toml
gstd-fluent = { git = "https://github.com/gear-foundation/gstd-fluent.git" }
```diff
- gstd = "x.y.z"
+ gstd-fluent = "x.y.z"
```

Then update your code like this:
Expand Down
5 changes: 2 additions & 3 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[toolchain]
channel = "nightly-2023-04-25"
channel = "stable"
targets = ["wasm32-unknown-unknown"]
profile = "minimal"
components = ["rustfmt", "clippy"]
profile = "default"
10 changes: 9 additions & 1 deletion src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ pub fn send_input<Range: RangeBounds<usize>>(
}

/// Creates a builder that allows to create a new program from the already existing on-chain code.
pub fn create_program<Buffer: AsRef<[u8]>>(
pub fn create_program_bytes<Buffer: AsRef<[u8]>>(
code_id: CodeId,
payload: Buffer,
) -> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>, (), (), ())> {
CreateProgramBuilder::bytes(code_id, payload)
}

/// Creates a builder that allows to create a new program from the already existing on-chain code.
pub fn create_program<Encodable: Encode>(
code_id: CodeId,
payload: Encodable,
) -> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, (), (), ())> {
CreateProgramBuilder::encode(code_id, payload)
}
76 changes: 70 additions & 6 deletions src/generated/create_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ impl<Buffer: AsRef<[u8]>> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>,
}
}

impl<Encodable: Encode> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, (), (), ())> {
pub fn encode(code_id: CodeId, payload: Encodable) -> Self {
Self {
fields: (CodeIdW(code_id), PayloadEncodableW(payload), (), (), ()),
}
}
}

impl<CodeId, Payload, Delay, GasLimit> CreateProgramBuilder<(CodeId, Payload, (), Delay, GasLimit)> {
pub fn with_value(self, value: u128) -> CreateProgramBuilder<(CodeId, Payload, ValueW, Delay, GasLimit)> {
let (code_id, payload, _, delay, gas_limit) = self.fields;
Expand Down Expand Up @@ -65,27 +73,55 @@ impl<CodeId, Payload, Value, GasLimit> CreateProgramBuilder<(CodeId, Payload, Va
impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>, Value, (), ())> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, _, _) = self.fields;
ProgramGenerator::create_program(code_id, payload, value.into().0)
ProgramGenerator::create_program_bytes(code_id, payload, value.into().0)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>, Value, (), GasLimitW)> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, _, GasLimitW(gas_limit)) = self.fields;
ProgramGenerator::create_program_with_gas(code_id, payload, gas_limit, value.into().0)
ProgramGenerator::create_program_bytes_with_gas(code_id, payload, gas_limit, value.into().0)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>, Value, DelayW, ())> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, DelayW(delay), _) = self.fields;
ProgramGenerator::create_program_delayed(code_id, payload, value.into().0, delay)
ProgramGenerator::create_program_bytes_delayed(code_id, payload, value.into().0, delay)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadBytesW<Buffer>, Value, DelayW, GasLimitW)> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, DelayW(delay), GasLimitW(gas_limit)) = self.fields;
ProgramGenerator::create_program_bytes_with_gas_delayed(code_id, payload, gas_limit, value.into().0, delay)
}
}

impl<Encodable: Encode, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, Value, (), ())> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, _, _) = self.fields;
ProgramGenerator::create_program(code_id, payload, value.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, Value, (), GasLimitW)> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, _, GasLimitW(gas_limit)) = self.fields;
ProgramGenerator::create_program_with_gas(code_id, payload, gas_limit, value.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, Value, DelayW, ())> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, DelayW(delay), _) = self.fields;
ProgramGenerator::create_program_delayed(code_id, payload, value.into().0, delay)
}
}

impl<Encodable: Encode, Value: Into<ValueW>> CreateProgramBuilder<(CodeIdW, PayloadEncodableW<Encodable>, Value, DelayW, GasLimitW)> {
pub fn execute(self) -> Result<(MessageId, ActorId)> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, DelayW(delay), GasLimitW(gas_limit)) = self.fields;
ProgramGenerator::create_program_with_gas_delayed(code_id, payload, gas_limit, value.into().0, delay)
}
}
Expand All @@ -111,27 +147,55 @@ impl<CodeId, Payload, Value, GasLimit, Decodable> CreateProgramBuilderForReply<(
impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>> CreateProgramBuilderForReply<(CodeIdW, PayloadBytesW<Buffer>, Value, (), ReplyDeposit, ())> {
pub fn execute(self) -> Result<CreateProgramFuture> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, _, reply_deposit, _) = self.fields;
ProgramGenerator::create_program_for_reply(code_id, payload, value.into().0, reply_deposit.into().0)
ProgramGenerator::create_program_bytes_for_reply(code_id, payload, value.into().0, reply_deposit.into().0)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>> CreateProgramBuilderForReply<(CodeIdW, PayloadBytesW<Buffer>, Value, GasLimitW, ReplyDeposit, ())> {
pub fn execute(self) -> Result<CreateProgramFuture> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, GasLimitW(gas_limit), reply_deposit, _) = self.fields;
ProgramGenerator::create_program_with_gas_for_reply(code_id, payload, gas_limit, value.into().0, reply_deposit.into().0)
ProgramGenerator::create_program_bytes_with_gas_for_reply(code_id, payload, gas_limit, value.into().0, reply_deposit.into().0)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>, Decodable: Decode> CreateProgramBuilderForReply<(CodeIdW, PayloadBytesW<Buffer>, Value, (), ReplyDeposit, DecodableW<Decodable>)> {
pub fn execute(self) -> Result<CodecCreateProgramFuture<Decodable>> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, _, reply_deposit, _) = self.fields;
ProgramGenerator::create_program_for_reply_as(code_id, payload, value.into().0, reply_deposit.into().0)
ProgramGenerator::create_program_bytes_for_reply_as(code_id, payload, value.into().0, reply_deposit.into().0)
}
}

impl<Buffer: AsRef<[u8]>, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>, Decodable: Decode> CreateProgramBuilderForReply<(CodeIdW, PayloadBytesW<Buffer>, Value, GasLimitW, ReplyDeposit, DecodableW<Decodable>)> {
pub fn execute(self) -> Result<CodecCreateProgramFuture<Decodable>> {
let (CodeIdW(code_id), PayloadBytesW(payload), value, GasLimitW(gas_limit), reply_deposit, _) = self.fields;
ProgramGenerator::create_program_bytes_with_gas_for_reply_as(code_id, payload, gas_limit, value.into().0, reply_deposit.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>> CreateProgramBuilderForReply<(CodeIdW, PayloadEncodableW<Encodable>, Value, (), ReplyDeposit, ())> {
pub fn execute(self) -> Result<CreateProgramFuture> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, _, reply_deposit, _) = self.fields;
ProgramGenerator::create_program_for_reply(code_id, payload, value.into().0, reply_deposit.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>> CreateProgramBuilderForReply<(CodeIdW, PayloadEncodableW<Encodable>, Value, GasLimitW, ReplyDeposit, ())> {
pub fn execute(self) -> Result<CreateProgramFuture> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, GasLimitW(gas_limit), reply_deposit, _) = self.fields;
ProgramGenerator::create_program_with_gas_for_reply(code_id, payload, gas_limit, value.into().0, reply_deposit.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>, Decodable: Decode> CreateProgramBuilderForReply<(CodeIdW, PayloadEncodableW<Encodable>, Value, (), ReplyDeposit, DecodableW<Decodable>)> {
pub fn execute(self) -> Result<CodecCreateProgramFuture<Decodable>> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, _, reply_deposit, _) = self.fields;
ProgramGenerator::create_program_for_reply_as(code_id, payload, value.into().0, reply_deposit.into().0)
}
}

impl<Encodable: Encode, Value: Into<ValueW>, ReplyDeposit: Into<ReplyDepositW>, Decodable: Decode> CreateProgramBuilderForReply<(CodeIdW, PayloadEncodableW<Encodable>, Value, GasLimitW, ReplyDeposit, DecodableW<Decodable>)> {
pub fn execute(self) -> Result<CodecCreateProgramFuture<Decodable>> {
let (CodeIdW(code_id), PayloadEncodableW(payload), value, GasLimitW(gas_limit), reply_deposit, _) = self.fields;
ProgramGenerator::create_program_with_gas_for_reply_as(code_id, payload, gas_limit, value.into().0, reply_deposit.into().0)
}
}
Loading