Skip to content

Commit

Permalink
Use qualified types.
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak committed Apr 4, 2024
1 parent 385577e commit 681222b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 0 additions & 4 deletions concordium-std-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Changelog

- Added MSRV (1.72)

## Unreleased changes

### Added

- Macros for creating constant values from strings for the following types:
- `AccountAddress`
- `ContractAddress`
Expand Down
2 changes: 1 addition & 1 deletion concordium-std-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/Concordium/concordium-rust-smart-contracts/"
proc-macro = true

[dependencies]
concordium-contracts-common = { path = "../concordium-rust-sdk/concordium-base/smart-contracts/contracts-common/concordium-contracts-common", features = [ "derive-serde" ] }
concordium-contracts-common = { path = "../concordium-rust-sdk/concordium-base/smart-contracts/contracts-common/concordium-contracts-common", features = [ "derive-serde" ], version = "9" }
syn = "2.0"
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
18 changes: 9 additions & 9 deletions concordium-std-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn parse_input(item: TokenStream, msg: &str) -> syn::Result<LitStr> {
fn get_token_res(
item: TokenStream,
msg: &str,
worker_fun: fn(String, Span) -> syn::Result<TokenStream>,
worker_fun: impl FnOnce(String, Span) -> syn::Result<TokenStream>,
) -> syn::Result<TokenStream> {
let input = parse_input(item, msg)?;
worker_fun(input.value(), input.span())
Expand All @@ -48,7 +48,7 @@ fn get_token_res(
fn get_token_res_env(
item: TokenStream,
msg: &str,
worker_fun: fn(String, Span) -> syn::Result<TokenStream>,
worker_fun: impl FnOnce(String, Span) -> syn::Result<TokenStream>,
) -> syn::Result<TokenStream> {
let input = parse_input(item, msg)?;
let environment_var_value = match std::env::var(input.value()) {
Expand All @@ -75,7 +75,7 @@ fn acc_address_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Err(e) => return Err(syn::Error::new(span, format!("Invalid account address: {}", e))),
};

Ok(quote!(AccountAddress(#address)).into())
Ok(quote!(concordium_std::AccountAddress(#address)).into())
}

fn pubkey_ed25519_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -84,7 +84,7 @@ fn pubkey_ed25519_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Err(e) => return Err(syn::Error::new(span, format!("Invalid Ed25519 public key: {}", e))),
};

Ok(quote!(PublicKeyEd25519(#public_key)).into())
Ok(quote!(concordium_std::PublicKeyEd25519(#public_key)).into())
}

fn pubkey_ecdsa_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -93,7 +93,7 @@ fn pubkey_ecdsa_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Err(e) => return Err(syn::Error::new(span, format!("Invalid ECDSA public key: {}", e))),
};

Ok(quote!(PublicKeyEcdsaSecp256k1(#public_key)).into())
Ok(quote!(concordium_std::PublicKeyEcdsaSecp256k1(#public_key)).into())
}

fn signature_ed25519_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -102,7 +102,7 @@ fn signature_ed25519_worker(str: String, span: Span) -> syn::Result<TokenStream>
Err(e) => return Err(syn::Error::new(span, format!("Invalid Ed25519 signature: {}", e))),
};

Ok(quote!(SignatureEd25519(#signature)).into())
Ok(quote!(concordium_std::SignatureEd25519(#signature)).into())
}

fn signature_ecdsa_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -111,7 +111,7 @@ fn signature_ecdsa_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Err(e) => return Err(syn::Error::new(span, format!("Invalid ECDSA signature: {}", e))),
};

Ok(quote!(SignatureEcdsaSecp256k1(#signature)).into())
Ok(quote!(concordium_std::SignatureEcdsaSecp256k1(#signature)).into())
}

fn contract_address_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -120,7 +120,7 @@ fn contract_address_worker(str: String, span: Span) -> syn::Result<TokenStream>
Err(e) => return Err(syn::Error::new(span, format!("Invalid contract address: {}", e))),
};

Ok(quote!(ContractAddress { index: #index, subindex: #subindex }).into())
Ok(quote!(concordium_std::ContractAddress::new(#index, #subindex)).into())
}

fn module_ref_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Expand All @@ -129,7 +129,7 @@ fn module_ref_worker(str: String, span: Span) -> syn::Result<TokenStream> {
Err(e) => return Err(syn::Error::new(span, format!("Invalid module reference: {}", e))),
};

Ok(quote!(ModuleReference::new(#module_ref)).into())
Ok(quote!(concordium_std::ModuleReference::new(#module_ref)).into())
}

/// Procedural macro for instantiating account addresses.
Expand Down
10 changes: 7 additions & 3 deletions concordium-std-derive/tests/test-programs/success.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
//! Ensure that the macros generate compilable code.
use concordium_contracts_common as concordium_std;
use concordium_contracts_common::*;
use concordium_std_derive::*;

const ACC: AccountAddress = account_address!("3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G");
const REF: ModuleReference = module_reference!("0000000000000000000000000000000000000000000000000000000000000000");
const REF: ModuleReference =
module_reference!("0000000000000000000000000000000000000000000000000000000000000000");
const CONTRACT: ContractAddress = contract_address!("<1234,0>");
const PK_25519: PublicKeyEd25519 = public_key_ed25519!("012a7e286063ae5dfcebce40636c0546d367d8c65cd4cb69aae1af77a4d61412");
const PK_ECDSA: PublicKeyEcdsaSecp256k1 = public_key_ecdsa!("0214e6a60b8fc58ea707d8ee8fa6ca7b28626d4f6f80b170982644c95d12111853");
const PK_25519: PublicKeyEd25519 =
public_key_ed25519!("012a7e286063ae5dfcebce40636c0546d367d8c65cd4cb69aae1af77a4d61412");
const PK_ECDSA: PublicKeyEcdsaSecp256k1 =
public_key_ecdsa!("0214e6a60b8fc58ea707d8ee8fa6ca7b28626d4f6f80b170982644c95d12111853");
const SG_25519: SignatureEd25519 = signature_ed25519!("ec076ae7adaf0a8b921cf2bad86a1a5b5346226618637aa0d6b30f9616f108f9f482640a4ceb14235569cd3af05fac00be2c82dc81c6f6b4a6ba4ea7c3b51a0b");
const SG_ECDSA: SignatureEcdsaSecp256k1 = signature_ecdsa!("EC076AE7ADAF0A8B921CF2BAD86A1A5B5346226618637AA0D6B30F9616F108F9F482640A4CEB14235569CD3AF05FAC00BE2C82DC81C6F6B4A6BA4EA7C3B51A0B");

Expand Down
4 changes: 2 additions & 2 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Changelog

- Bump MSRV to 1.72

## Unreleased changes

- Add support for querying the module reference and contract name of an instance,
via the `HasHost::contract_module_reference` and `HasHost::contract_name` functions.
These are only available from protocol version 7, and as such are guarded by the
`p7` feature flag.
- Add two ordered collections: `StateBTreeMap` and `StateBTreeSet`. These are based on [B-Tree](https://en.wikipedia.org/wiki/B-tree), but where each node is stored in the low-level smart contract key-value store. Use one of these when needing operations related to the ordering of the keys, such as `higher(k)` providing the smallest key in collection which is stricly greater than `k`.
- Bump MSRV to 1.73


## concordium-std 10.0.0 (2024-02-22)

Expand Down

0 comments on commit 681222b

Please sign in to comment.