Bug with rust compiler when building Elrond contract - elrond

I'm in the Elrond crowdfunding tutorial and I have this error when completing the init function.
I already did
erdpy contract build
once when the contract was empty and it worked.
But when adding a body to the init function the compiler panics.
I already tried to upgrade and reinstall rust.
Also tried with 1.6 nightly version but it doesn't work.
I'm on Ubuntu-Zorin.
#![no_std]
elrond_wasm::imports!();
#[elrond_wasm::contract]
pub trait Crowdfunding {
#[storage_mapper("target")]
fn target(&self) -> SingleValueMapper<BigUint>;
#[init]
fn init(&self, target: BigUint) {
self.target().set(&target);
}
}

Problem solved after deleting file content and retyping everything (instead of copy pasting from the tuto)

Related

How can I query contract info with the latest polkadot-js and substrate contracts node?

I've been unable to query my existing contract recently due to Unable to create Enum via index 128, in Alive, Tombstone when using api.query.contracts.contractInfoOf. I get this error both on the command line and in the polkadot-js apps explorer.
These are the steps I took:
Deploy a contract with a salt
Retrieve the contract deployedAddress
Use contractInfoOf
const contractInfo = await api.query.contracts.contractInfoOf(deployedAddress);
I've tried downgrading ink! to 3.0-rc5, 3.0-rc4, 3.0-rc3 and then compiling but it doesn't seem to make any difference. Whenever my contract is built it references rc6 at the top:
{"metadataVersion":"0.1.0","source":{"hash":"0x...","language":"ink! 3.0.0-rc6","compiler":"rustc 1.58.0-nightly",
Which suggests its ignoring my .toml and using rc6 to compile the contract.
I changed my cargo-contract version to 0.14 but that causes polkadot-js to fail at reading the contract abi.
I've tried using the substrate-contracts-node using the latest commit from master and also using the v0.1.0 release. Same error in both cases.
> rustup info
stable-x86_64-unknown-linux-gnu (default)
rustc 1.56.1 (59eed8a2a 2021-11-01)
There are more details in an issue on polkadot-js.
Any pointers on how to get a working setup would be very helpful!
The problem here was substrate-contracts-node using an old version of the metadata.
I was able to check out the repo before the metadata merge was reverted and build locally (cargo build).
So checkout 8d91b8e to get the node to work with versions 7.7.1 and 6.6.1 of polkadot-js packages.
> git checkout 8d91b8e578065a7c06433cbd41ac059bf478a0bd
> cargo build
> ./target/debug/substrate-contracts-node --dev --tmp --version
substrate-contracts-node 0.1.0-8d91b8e-x86_64-linux-gnu

Go broken import

I'm trying to interact with helm via the go SDK and I'm getting the following error when I try to build my code:
../../../go/pkg/mod/github.com/deislabs/oras#v0.11.1/pkg/oras/push.go:52:31: not enough arguments in call to remotes.PushContent
have (context.Context, remotes.Pusher, v1.Descriptor, "github.com/containerd/containerd/content".Store, nil, func(images.Handler) images.Handler)
want (context.Context, remotes.Pusher, v1.Descriptor, "github.com/containerd/containerd/content".Store, *semaphore.Weighted, platforms.MatchComparer, func(images.Handler) images.Handler)
I've traced it down to package helm.sh/helm/v3/pkg/action :
$ go get helm.sh/helm/v3/pkg/action
# github.com/deislabs/oras/pkg/oras
../../../go/pkg/mod/github.com/deislabs/oras#v0.11.1/pkg/oras/push.go:52:31: not enough arguments in call to remotes.PushContent
have (context.Context, remotes.Pusher, v1.Descriptor, "github.com/containerd/containerd/content".Store, nil, func(images.Handler) images.Handler)
want (context.Context, remotes.Pusher, v1.Descriptor, "github.com/containerd/containerd/content".Store, *semaphore.Weighted, platforms.MatchComparer, func(images.Handler) images.Handler)
I suspect that this is related to this change: https://github.com/helm/helm/commit/663c5698878c959805de053116581d15673e1ce3
How do I fix this? I've tried using older versions of the helm package to no avail.
The signature for github.com/containerd/containerd/remotes.PushContent was changed incompatibly in commit f8c2f0, which was released in v1.5.0. (The containerd Go API appears to be unstable, despite its apparently-semantic version v1.5.5; see containerd#3554.)
The short-term fix is to go get -d github.com/containerd/containerd#v1.4 to downgrade to the latest v1.4.* until your dependencies are compatible with the latest release.
The longer-term fix appears to be helm commit 663c56, which migrates to a different oras library whose latest release is compatible with the containerd v1.5 API. As far as I can tell that commit has not yet been included in a helm release, but you may be able to try it out using go get -d helm.sh/helm/v3/pkg/action#main; see https://golang.org/doc/modules/managing-dependencies#repo_identifier.

add pallet_assets error: ^^^ Config not found in 'pallet_assets'

I get this error when trying to compile and I seem to be unable to solve it...:
In terminal, after running 'cargo check' I get:
Compiling node-template-runtime v2.0.1 (/runtime)
error[E0405]: cannot find trait `Config` in crate `pallet_assets`
--> /runtime/src/lib.rs:360:21
|
360 | impl pallet_assets::Config for Runtime {
| ^^^^^^ not found in `pallet_assets`
error: aborting due to previous error...
I tried with 'Trait' instead of Config, but throws even more errors...?
A hint would be much appreciated. Thanks
The Config trait was introduced in version 3.0.0 of substrate. As you pointed out, it was previously Trait. It is only expected for any substrate project to be compile-able if you use all of the same major version (2.x or 3.x) for building. I highly recommend using v3+ from now on, v2 is not expected to be supported moving forward.

errorE0282# type annotations needed & could not compile `sp-arithmetic`

I am following tutorial [Implementing the Contract Trait]. Added code snip to [parameter_types!] and to [imp trait runtime].
When I run [cargo check -p node-template-runtime] receive error:
error[E0282]: type annotations needed
error: could not compile sp-arithmetic
note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
I've had this error previously and it was due to nightly?
I am using windows not mac..
Just to Add to #dundro answer. Go to the link he suggested:
https://github.com/substrate-developer-hub/substrate-node-template/commit/5769470053ba48f364100ff106e32f1beea43127
and download the "rust-toolchain" file. Then place it in the "substrate-node-template" folder. Then try to build again using the command "cargo build --release".
In my case, it solved the E0282 error and gave me a new one E0463. Searching for a fix now
I got the exactly same error, but then I just checked out master ( there is now a toolchain file since https://github.com/substrate-developer-hub/substrate-node-template/commit/5769470053ba48f364100ff106e32f1beea43127)
and with nightly-2020-10-06 the build was successful.
Good luck
Solved: I forgot to add nightly [cargo +nightly-2020-10-06 check -p node-template-runtime]..

Golang: using Windows 10 API / UWP / System.WindowsRuntime?

Using syscall in Go how can I call the UWP APIs within Windows 10? I have seen and tried many win32 examples, but when I tried using System.WindowsRuntime.dll it was a no-go; specifically, I received:
panic: Failed to load System.WindowsRuntime.dll: The specified module could not be found.
(this was at runtime, the binary built fine)
I tried building both with a standard go build as well as
go build -ldflags="-H windows"
example code:
var(
windowsRuntime = syscall.NewLazyDLL("System.WindowsRuntime.dll")
getDiskFreeSpace = windowsRuntime.NewProc("GetDiskFreeSpace")
)
Note: Other variants tried:
windowsRuntime = syscall.NewLazyDLL("System.Runtime.WindowsRuntime.dll")
&
windowsRuntime = syscall.NewLazyDLL("WindowsRuntime.dll")
Anyone been able to get this running or have any advice on the matter?
As always, greatly appreciated!!
Create a file like this:
//go:generate mkwinsyscall -output zfree.go free.go
//sys getDiskFreeSpace(pathName string, sectorsPerCluster *int, bytesPerSector *int, freeClusters *int, numberOfClusters *int) (err error) = GetDiskFreeSpaceA
package main
func main() {
var bytesPerSector, freeClusters, numberOfClusters, sectorsPerCluster int
getDiskFreeSpace(
`C:\`,
&sectorsPerCluster,
&bytesPerSector,
&freeClusters,
&numberOfClusters,
)
println("bytesPerSector", bytesPerSector)
println("freeClusters", freeClusters)
println("numberOfClusters", numberOfClusters)
println("sectorsPerCluster", sectorsPerCluster)
}
Then build:
go generate
go mod init free
go mod tidy
go build
Result:
bytesPerSector 512
freeClusters 12511186
numberOfClusters 25434879
sectorsPerCluster 8
https://github.com/golang/sys/tree/master/windows/mkwinsyscall
I have no idea where you found "System.WindowsRuntime.dll" because as far as I can tell, it doesn't exist (unless you manually made a DLL named that).
As for System.Runtime.WindowsRuntime.dll: it's part of .NET Framework, not Windows, and it is a managed DLL. You cannot load such DLLs using syscall.NewLazyDLL. What's more, that DLL doesn't really contain any Windows APIs - just glue for .NET to be able to work with them.
You're probably looking for functions like RoGetActivationFactory in combase.dll.

Resources