Skip to content

Commit

Permalink
Merge branch 'rc/v0.45' into upgrade-attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Nov 21, 2023
2 parents 83f5233 + 9b2f741 commit 0b2d94e
Show file tree
Hide file tree
Showing 57 changed files with 935 additions and 322 deletions.
1 change: 0 additions & 1 deletion contracts/benchmarks/large-storage/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "large-storage-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "linked-list-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/mappers/map-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "map-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/mappers/queue-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "queue-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/mappers/set-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "set-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "single-value-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/mappers/vec-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "vec-repeat-wasm"
version = "0.0.0"
authors = ["Claudiu-Marcel Bruda <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/send-tx-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "send-tx-repeat-wasm"
version = "0.0.0"
authors = ["Dorin Iancu <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/benchmarks/str-repeat/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "str-repeat-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion contracts/core/price-aggregator/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "multiversx-price-aggregator-sc-wasm"
version = "0.0.0"
authors = [ "Claudiu-Marcel Bruda <[email protected]>",]
edition = "2021"
publish = false

Expand Down
11 changes: 4 additions & 7 deletions contracts/core/wegld-swap/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
[package]
name = "multiversx-wegld-swap-sc-wasm"
version = "0.0.0"
authors = [ "Dorin Iancu <[email protected]>",]
edition = "2021"
publish = false

[lib]
crate-type = [ "cdylib",]

[workspace]
members = [ ".",]

[dev-dependencies]
crate-type = ["cdylib"]

[profile.release]
codegen-units = 1
Expand All @@ -26,3 +20,6 @@ path = ".."
[dependencies.multiversx-sc-wasm-adapter]
version = "0.44.0"
path = "../../../../framework/wasm-adapter"

[workspace]
members = ["."]
7 changes: 6 additions & 1 deletion contracts/examples/multisig/wasm-multisig-full/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Code generated by the multiversx-sc multi-contract system. DO NOT EDIT.

# ##########################################
# ############## AUTO-GENERATED #############
# ##########################################

[package]
name = "multisig-full-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

Expand Down
7 changes: 6 additions & 1 deletion contracts/examples/multisig/wasm-multisig-view/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Code generated by the multiversx-sc multi-contract system. DO NOT EDIT.

# ##########################################
# ############## AUTO-GENERATED #############
# ##########################################

[package]
name = "multisig-view-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

Expand Down
7 changes: 6 additions & 1 deletion contracts/examples/multisig/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Code generated by the multiversx-sc multi-contract system. DO NOT EDIT.

# ##########################################
# ############## AUTO-GENERATED #############
# ##########################################

[package]
name = "multisig-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

Expand Down
30 changes: 29 additions & 1 deletion contracts/feature-tests/abi-tester/tests/abi_tester_abi_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{fs, fs::File, io::Write};

use multiversx_sc::contract_base::ContractAbiProvider;
use multiversx_sc::{
abi::{EnumVariantDescription, TypeContents},
contract_base::ContractAbiProvider,
};
use multiversx_sc_meta::{
abi_json::{self, EsdtAttributeAbiJson},
esdt_attr_file_json::serialize_esdt_attribute_json,
Expand Down Expand Up @@ -82,3 +85,28 @@ fn check_multi_contract_config() {
vec!["external_view", "payable_any_token", "label_a"]
);
}

#[test]
fn abi_deserialization_check() {
let main_json = fs::read_to_string("./abi_tester_expected_main.abi.json").unwrap();
let main_abi = multiversx_sc_meta::abi_json::deserialize_abi_from_json(&main_json).unwrap();
let abi_enum_type = main_abi
.types
.get("AbiEnum")
.unwrap()
.to_type_description("AbiEnum");
if let TypeContents::Enum(variants) = abi_enum_type.contents {
assert_eq!(variants.len(), 4);
assert_eq!(
variants[0],
EnumVariantDescription {
docs: vec![],
name: "Nothing".to_string(),
discriminant: 0,
fields: vec![]
}
);
} else {
panic!("wrong AbiEnum type contents")
}
}
2 changes: 1 addition & 1 deletion contracts/feature-tests/composability/vault/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ add-labels = ["promises-endpoint"]
[contracts.upgrade]
name = "vault-upgrade"
add-unlabelled = false
add-labels = ["upgrade"]
add-labels = ["upgrade"]
25 changes: 22 additions & 3 deletions framework/base/src/abi/contract_abi.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use super::*;
use alloc::{string::String, vec::Vec};
use alloc::{
string::{String, ToString},
vec::Vec,
};

#[derive(Debug, Default, Clone)]
pub struct ContractAbi {
pub build_info: BuildInfoAbi,
pub docs: &'static [&'static str],
pub name: &'static str,
pub docs: Vec<String>,
pub name: String,
pub constructors: Vec<EndpointAbi>,
pub endpoints: Vec<EndpointAbi>,
pub promise_callbacks: Vec<EndpointAbi>,
Expand All @@ -16,6 +19,22 @@ pub struct ContractAbi {
}

impl ContractAbi {
/// Used in code generation.
pub fn new(build_info: BuildInfoAbi, docs: &[&str], name: &str, has_callback: bool) -> Self {
ContractAbi {
build_info,
docs: docs.iter().map(|s| s.to_string()).collect(),
name: name.to_string(),
constructors: Vec::new(),
endpoints: Vec::new(),
promise_callbacks: Vec::new(),
events: Vec::new(),
esdt_attributes: Vec::new(),
has_callback,
type_descriptions: TypeDescriptionContainerImpl::new(),
}
}

pub fn coalesce(&mut self, other: Self) {
self.constructors
.extend_from_slice(other.constructors.as_slice());
Expand Down
59 changes: 47 additions & 12 deletions framework/base/src/abi/endpoint_abi.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use super::*;
use alloc::vec::Vec;
use alloc::{
string::{String, ToString},
vec::Vec,
};

#[derive(Clone, Debug)]
pub struct InputAbi {
pub arg_name: &'static str,
pub arg_name: String,
pub type_name: TypeName,
// pub original_type_name: TypeName,
pub multi_arg: bool,
}

#[derive(Clone, Debug)]
pub struct OutputAbi {
pub output_name: &'static str,
pub output_name: String,
pub type_name: TypeName,
pub multi_result: bool,
}
Expand All @@ -36,24 +39,56 @@ pub enum EndpointTypeAbi {

#[derive(Clone, Default, Debug)]
pub struct EndpointAbi {
pub docs: &'static [&'static str],
pub name: &'static str,
pub rust_method_name: &'static str,
pub docs: Vec<String>,
pub name: String,
pub rust_method_name: String,
pub only_owner: bool,
pub only_admin: bool,
pub labels: &'static [&'static str],
pub labels: Vec<String>,
pub endpoint_type: EndpointTypeAbi,
pub mutability: EndpointMutabilityAbi,
pub payable_in_tokens: &'static [&'static str],
pub payable_in_tokens: Vec<String>,
pub inputs: Vec<InputAbi>,
pub outputs: OutputAbis,
pub allow_multiple_var_args: bool,
}

impl EndpointAbi {
pub fn add_input<T: TypeAbi>(&mut self, arg_name: &'static str) {
/// Used in code generation.
///
/// TODO: replace with builder pattern to gt rid of the too many arguments.
#[allow(clippy::too_many_arguments)]
pub fn new(
docs: &[&str],
name: &str,
rust_method_name: &str,
only_owner: bool,
only_admin: bool,
mutability: EndpointMutabilityAbi,
endpoint_type: EndpointTypeAbi,
payable_in_tokens: &[&str],
labels: &[&str],
allow_multiple_var_args: bool,
) -> Self {
EndpointAbi {
docs: docs.iter().map(|s| s.to_string()).collect(),
name: name.to_string(),
rust_method_name: rust_method_name.to_string(),
only_owner,
only_admin,
labels: labels.iter().map(|s| s.to_string()).collect(),
endpoint_type,
mutability,
payable_in_tokens: payable_in_tokens.iter().map(|s| s.to_string()).collect(),
inputs: Vec::new(),
outputs: Vec::new(),
allow_multiple_var_args,
}
}

pub fn add_input<T: TypeAbi>(&mut self, arg_name: &str) {
self.inputs.push(InputAbi {
arg_name,
arg_name: arg_name.to_string(),
type_name: T::type_name(),
multi_arg: T::is_variadic(),
});
Expand All @@ -69,8 +104,8 @@ impl EndpointAbi {
labels: &'static [&'static str],
) -> Self {
EndpointAbi {
name,
labels,
name: name.to_string(),
labels: labels.iter().map(|s| s.to_string()).collect(),
endpoint_type: EndpointTypeAbi::Endpoint,
..Default::default()
}
Expand Down
9 changes: 6 additions & 3 deletions framework/base/src/abi/esdt_attribute_abi.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use alloc::string::{String, ToString};

use super::{TypeAbi, TypeDescriptionContainerImpl, TypeName};

#[derive(Clone, Debug)]
pub struct EsdtAttributeAbi {
pub ticker: &'static str,
pub ticker: String,
pub ty: TypeName,
pub type_descriptions: TypeDescriptionContainerImpl,
}

impl EsdtAttributeAbi {
pub fn new<T: TypeAbi>(arg_name: &'static str) -> EsdtAttributeAbi {
/// Used in code generation.
pub fn new<T: TypeAbi>(arg_name: &str) -> EsdtAttributeAbi {
let mut type_descriptions = TypeDescriptionContainerImpl::default();
T::provide_type_descriptions(&mut type_descriptions);
EsdtAttributeAbi {
ticker: arg_name,
ticker: arg_name.to_string(),
ty: T::type_name(),
type_descriptions,
}
Expand Down
Loading

0 comments on commit 0b2d94e

Please sign in to comment.