Questions tagged [rust]

Questions about the Rust programming language, the primary language used in the Substrate ecosystem.

Filter by
Sorted by
Tagged with
1 vote
0 answers
27 views

Polkadot-v1.0.0: sc-network is failing to compile

When specifying sc-network as a dependency: sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } I get a compile error: error[E0433]: ...
0 votes
1 answer
30 views

Multiple test mock runtimes with slightly different configs based off common base?

We have some custom pallet unit tests that use multiple mock runtimes that are configured slightly differently. The problem is that when we have to make changes to the runtime, we have to apply those ...
1 vote
1 answer
29 views

Calculation gives the wrong result

After doing a simple calculation in rust ink! 4.0 smart contract, the result is incorrect and doesn't match the expected result. Here is the simple formula: let a0_balance_mul:U256 = U256::from(...
0 votes
2 answers
2k views

error: linking with `cc` failed: exit status: 1 (Mac m1)

Not able to build a project because of this issue: error: linking with `cc` failed: exit status: 1 | = note: "cc" "-arch" "arm64" "/var/folders/5w/...
3 votes
1 answer
109 views

Code coverage setup in Substrate

At my current company we are using Substrate for our developments, we have an automated setup with test and whatnot. We are now evaulating our options regarding code coverage. We are thinking of a ...
0 votes
1 answer
194 views

Build error on substrate-node-template

I'm met with an error when running this command cargo build --release on substrate-note-template. I haven't really done anything other than git clone to my directory and executed the cargo build ...
0 votes
2 answers
98 views

How to set timestamp in benchmarks?

Is it possible to use std for benchmarks? If not, how can I get timestamps in a benchmark? I tried using this but it didn't compile: #[cfg(feature = "runtime-benchmarks")] extern crate std;...
1 vote
0 answers
18 views

I am having issues with implementing swap fees on transfer for DEX

Below is my lib.rs file for the token contract and it uses the Cardinal Cryptography PSP22 sample at https://github.com/Cardinal-Cryptography/PSP22 I am trying to implement swap for the transfer taxes ...
1 vote
2 answers
36 views

How to print / output from within async tokio test

I am writing a new test and when I run this code, the println's do not output in the terminal. #[tokio::test] async fn can_fetch_child_keys() { if std::option_env!("TEST_WS").is_none() { ...
4 votes
1 answer
18 views

error[E0282]: type annotations needed --> /libp2p-noise-0.32.0/src/protocol/x25519.rs:221:45

While running this project https://github.com/jimmychu0807/substrate-offchain-worker-demo I'm geting this error: error[E0282]: type annotations needed --> /libp2p-noise-0.32.0/src/protocol/x25519....
0 votes
1 answer
27 views

How can I access a value obtained at runtime in primitives npos elections?

I want to change the weight/score of targets on the basis of values got during runtime, in my research I found the score of a target is being calculated in primitives/npos-elections/phragmen.rs in fn ...
2 votes
1 answer
39 views

What is the use of Get trait here?

In the referenda pallet, type Tracks uses two trait, Get and TracksInfo substrate/frame/referenda/src/lib.rs /// Information concerning the different referendum tracks. #[pallet::constant] ...
1 vote
0 answers
22 views

How to change the gas cost in ink! e2e tests

I want to be able to adjust the gas cost used in specific ink! end-to-end (e2e) tests, but my attempts to do so have consistently resulted in a return value of zero when using the weight_to_fee ...
0 votes
1 answer
36 views

Build fails when trying to create workspace from selected pallets and primitives

I want to put some pallets and primitive code in a workspace. Here is my code https://github.com/zeitgeistpm/external However this does not build, neither workspace builds nor individual components. ...
1 vote
1 answer
27 views

Issues with Cross Contracts calls

I am trying to compile my Rust (ink!) source code for an AMM DEX on Substrate (Aleph Zero), but this is the error I am receiving from the logs: The following are the files: [azero_trading_pair/cargo....
3 votes
0 answers
25 views

How to use enum with associated value(s) in ink smart contract

I have an ink smart contract message that takes an enum as argument. The code is shown below; #[derive(Encode, Decode)] #[cfg_attr( feature = "std", derive(Debug, PartialEq, Eq, ...
1 vote
0 answers
14 views

How to Modify static buffer size for my ink smart contract to Resolving 'OutputBufferTooSmall' Error for Larger Vectors in ink smart contract

I'm facing an 'OutputBufferTooSmall' error in my [Language/Framework] code when working with larger vectors. I suspect this is related to the maximum allowed input/output sizes. I need guidance on how ...
3 votes
1 answer
272 views

build failed with substrate chain on rocksdb in linux

I followed this tutorial https://docs.substrate.io/tutorials/get-started/build-local-blockchain/. I got the below error when run cargo build --release. How can I fix it? cargo build -v --release ...
1 vote
0 answers
14 views

"ContractTrapped" Error even with successful cross-contract call

let result_call = ink::env::call::build_call::<Environment>() .call(self.escrow_address) .gas_limit(0) .transferred_value(0) ...
0 votes
1 answer
32 views

How to handle all the characters in Vec<u8>?

I am using vec to storing the string data on the chain. So when any user passing few special character it just convert it into the binary data and storing that binary data on the chain. Which we ...
3 votes
1 answer
88 views

Division operation in `u128` results false value

In my node, Balance type is u128. I have following variable let per_block = 100_000_000_000_000_000_u128; let total = 50_000_000_000_000_000_000_000_u128; let ratio = per_block.checked_div(total); ...
2 votes
2 answers
83 views

How to Retrieve Value by Single Key from StorageDoubleMap in Substrate?

I'm developing a Substrate-based blockchain and using StorageDoubleMap to store label details. The StorageDoubleMap is defined as follows: #[pallet::storage] #[pallet::unbounded] #[pallet::getter(fn ...
1 vote
1 answer
44 views

Trait Bound f64: scale_info::TypeInfo Is Not Satisfied

I'm working on a Substrate-based blockchain project and I've run into an issue related to type information and encoding. Specifically, I'm trying to use an f64 field within a struct that also uses ...
0 votes
1 answer
66 views

how to remove Mapping storage when tuple is used as input

Lets assume we have an ink! smart contract On a vanilla Mapping alpha: Mapping<[u8;32], Astruct> we can use self.alpha.remove(&somehash) My question is this: if we have the following ...
0 votes
1 answer
43 views

How to get typed keys when querying a storage map via subxt

The example here https://github.com/paritytech/subxt/blob/master/subxt/examples/storage_iterating.rs use subxt::{OnlineClient, PolkadotConfig}; #[subxt::subxt(runtime_metadata_path = "../...
1 vote
1 answer
29 views

Need help in Ink e2e tests

I need help with that code. Can anyone pls help me out ?? mod p{ #[ink(storage)] pub struct Foobar { /// Stores a single `bool` value on the storage. value: ...
0 votes
1 answer
70 views

Scalecodec: How can I get the equivalent of Decode in Python, instead of DecodeAll?

When using the Python script: timestamp = ScaleDecoder.get_decoder_class('Timestamp', ScaleBytes(timestamp_bytes_array)).decode() it seems that the decoder expects the size of the array to be exactly ...
2 votes
1 answer
43 views

Is there a simple MHT (Merkel Hash Tree) in-place algorithm?

I want to write a low memory usage algorithm to calculate MHT
2 votes
1 answer
60 views

MultiAddress to Address String

I'm trying to retrieve the author's address as a string, and I've successfully obtained the MultiAddress using the following code: let validator_address = if let Some(author_multi_address) = ...
1 vote
3 answers
113 views

Unable to deploy the open-brush contracts build using toolchain nightly-2023-02-07 on substrate node

As you can see in following link . I was not able to build contract using latest rust nighly ( rustc 1.70.0-nightly (17c116721 2023-03-29)) toolchain. ERROR: Loading of original wasm failed I got the ...
1 vote
1 answer
101 views

Building my substrate pallet - Rust errors

I am a beginner at learning Rust/substrate/Polkadot. I am trying to build my custom substrate pallet My goal is, Create a custom Substrate pallet that allows only the Root origin account to control ...
2 votes
1 answer
107 views

Problem with timestamps in governance platform

I have governance platform written in ink!, where I can create poll with pollId, number of options, and with poll_start_time and poll_end_time. And this is fine. So when poll is started I can't call ...
1 vote
1 answer
48 views

Calculate Session/Epoch time remaining

I've seen some websites display the estimated time remaining for the current session/epoch. Is there a Rust call for this? Is there a sample of that code?
0 votes
1 answer
34 views

Deriving Contract Reference from `ink::trait_definition`

Is it possible to create a Contract Reference to perform a Cross-Contract call from ink::trait_definition? If it is, how can I do so? If it is not, why it is not possible? It seems strange that we can ...
0 votes
0 answers
53 views

Rust Compile Error: Unresolved imports crate::pallet, crate::types::Types::Config

I am working on a Rust project where I have multiple modules. I'm facing an issue with unresolved imports when I try to compile my code. Here's the relevant code structure: types.rs pub mod Types { ...
2 votes
1 answer
98 views

Is it permissible to retrieve the value of a private field within a struct from one pallet while working with another pallet?

I am developing a cross-chain NFT transfer pallet that involves transferring both item metadata and collection metadata. To accomplish this, I need to access the data field within the ItemMetadata ...
2 votes
1 answer
84 views

How to fix "module group is private" error when using frame-support-procedural-tools v3.0.0?

I'm trying to use orml-tokens in my Substrate project and encountered the following error: error[E0603]: module `group` is private --> /home/kianoush/.cargo/registry/src/github.com-...
1 vote
1 answer
28 views

Get the block timestamp using subxt

I am using subxt to get the block details, including the block number, hash, parent hash, timestamp, events and the extrinsics. I am able to find most details, except the timestamp. Is there a way to ...
5 votes
1 answer
268 views

Build a docker file/image for my new pallet

I am using substrate-node-template and recently I added a new pallet. Now I need to build a docker file because I would like to send it for testing. Any information? Thank you.
2 votes
1 answer
112 views

How can I decode this error message {"ok":{"flags":["Revert"],"data":"0x000110"}}?

I'm using polkadotjs to call my ink! smart contracts and I seem to be having trouble with calls that require parameters. For the call below I am getting the revert flag {"ok":{"flags&...
1 vote
1 answer
30 views

How to get and modify cross-chain asset in contract?

I am preparing to create a smart-contract on Astar using ink! programming language. The contract's main logic involves modifying the cross-chain asset USDT on the statemint chain. After going through ...
2 votes
1 answer
94 views

panicked at 'assertion failed: `(left == right)`

I am having a setup of relay chain and two parachains are connected to it, I was running some test cases and during that i encounter an error thread 'test::...
2 votes
1 answer
62 views

Incompatibility between subxt_signer and subxt

https://github.com/paritytech/subxt/blob/master/subxt/examples/tx_basic.rs I want to call a function in my substrate pallet. I am using the substrate-node-template subxt subxt_signer use subxt::{...
1 vote
1 answer
31 views

Substrate node template build errors and rustup version

Once in a while, doing a rustup update will break the substrate node template, the challenge then becomes to identify the rustup release compatible with the latest node-template and downgrade. is this ...
0 votes
1 answer
66 views

Encountered incremental compilation error

I have encountered following error from time to time while compiling substrate-node-template error: internal compiler error: encountered incremental compilation error with mir_built(76e5305fbe3bf3e0-...
10 votes
4 answers
1k views

ERROR: Loading of original wasm failed

I having some trouble running the Flipper example from the Ink! webpage. The cargo contract build outputs the following error log: ERROR: Loading of original wasm failed Caused by: 0: Loading of ...
1 vote
2 answers
87 views

Reading contract value returns null

Facing an issue while trying to query for a value in my contract. The value keeps getting retuned as null with an error. However, it works fine on substrate Contracts UI Front end Dapp : const ...
1 vote
1 answer
275 views

How to connect substrate node to metamask?

My node is compatible with EVM and I would like to connect it to metamask? How can I do it? What should I put in RPC URL and chain id? (Where can I find my chain id)
3 votes
2 answers
179 views

Specialization impl does not specialize any associated items

I'm fairly new to Rust and ink! itself. I'm trying to compile and build an extremely basic PSP22 Contract. I get the following error when I compile & build: (running cargo +nightly contract build) ...
1 vote
3 answers
59 views

How to call PSP22::approve function from Frontend

Any guidance on how to call my psp22 approve function from the front end ? This is currently how I'm doing it but it doesn't seem to give increased allowance (although its successful) : import { ...

1
2 3 4 5 6