Code Monkey home page Code Monkey logo

mx-sdk-rs's Introduction

The MultiversX Rust Tool Set

Build Status Dependency Status Contributors

This repository contains a wide variety of tools, aimed primarily at smart contract developers.

The repo contains:

  • The most complete smart contract framework on MultiversX:
    • The base framework;
    • A complete build system, which relies on the smart contract code directly;
    • A powerful debugger, based on a partial implementation of the MultiversX VM, in Rust.
    • A framework for writing both black-box and white-box tests. They rely on the standard MultiversX blockchain scenario format.
    • The official data serializer and deserializer for smart contract data. Can be used both on- and off-chain.
  • A large collection of smart contract examples and feature tests, together with some of the core smart contracts used on the blockchain (e.g. the wrapped egld swap, multisig, etc.).
  • A framework for interacting with the blockchain, based on the smart contract logic, especially suitable for developers.
  • A code snippet generator.

Documentation

Most documentation can be found at https://docs.multiversx.com/developers/overview/

Getting started

The crowdfunding tutorial is a great place to start: https://docs.multiversx.com/developers/tutorials/crowdfunding-p1/

IDE

The framework is designed to be easiest to use with the IDE VSCode extension: https://marketplace.visualstudio.com/items?itemName=Elrond.vscode-elrond-ide

Building contracts

A comprehensive build guide can be found here: https://docs.multiversx.com/developers/developer-reference/sc-build-reference/

Debugging contracts

The debugger guide: https://docs.multiversx.com/developers/developer-reference/sc-debugging/

mx-sdk-rs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mx-sdk-rs's Issues

no bigInt under the given handle

Hi! I've got an error "no bigInt under the given handle" when running a contract with erdpy contract test command, but everything is ok when testing with Rust Testing Framework.

It seems to be a compiler issue because the error disappears when I delete some code which have nothing to do with the function that produce the error.

I created a repo in order to reproduce the error.

https://github.com/gfusee/no-bigint-handle-bug-reproduction

[Feature Request] Warnings on build, when storage mappers have clashing names

I'm always having a bad feeling when I decide on the names of my storage mappers, because there is the problem of theoretical name clashes. In my opinion, we should change that to help our devs to not name there storage mappers the wrong way in the future.

I would like to get a contract build warning, if some of my storage mappers have names, that clash with each other (same prefixes). Is this possible to implement?

Please let me know if this is the wrong repository for this issue. I will copy it over to the right one if it is.

Crypto to string

I'm trying to get a u32 => sha256 => String

let hash = self.crypto().sha256(&[1u8, 2u8, 3u8]);
if (String::from_utf8(hash.to_vec()).is_err()) {
uri.append_bytes("error".as_bytes());
}

Am I doing something wrong? It's always giving an error. When printed, I get some gibberish like: D�z�G��a�w9��M��y��;oȠc��!

&[1u8, 2u8, 3u8] this is just an example, but I tried a bunch of options

let mut serialized_attributes = Vec::new();
"123".top_encode(&mut serialized_attributes).unwrap();

or 123u32. to_be_bytes()
or 123u32.to_string().to_bytes()

all same result.

Can something be wrong with .sha256() function?

Naming a parameter `amount` in a proxy remote call definition results in no data being passed

I came across this strange bug. If I define a proxy trait to make a cross contract call as follows

#[elrond_wasm_derive::callable(TestProxyImpl)]
pub trait TestProxy {
    #[callback(remote_call_callback)]
    fn remote_call(&self,
        amount: BigUint
    );
}

The call appears to work but no data is passed to the remote function.

Changing the parameter name to anything else e.g.

#[elrond_wasm_derive::callable(TestProxyImpl)]
pub trait TestProxy {
    #[callback(remote_call_callback)]
    fn remote_call(&self,
        token_amount: BigUint
    );
}

allows the calls to work correctly.

An minimal example to replicate the issue can be found here https://github.com/willemolding/elrond-callback-example/tree/amount-param-error

panic - get_argument_big_uint not yet implemented when making contract call using elrond-wasm-debug

Using version 0.5.2

This issue can be replicated by running the debug tests in the sc-examples simple-coin contract.

Making a call to a contract function that does not use a BigUint seems to work fine (I have only tested calling contracts that take Address in their parameters)

Calling a function with a param that is a BigUint causes the following panic:"

thread 'main' panicked at 'get_argument_big_uint not yet implemented', /home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs:13:23

TxResult returned from the execute_tx method on BlockchainStateWrapper issues on async smart contract to smart contract calls

For context I have these endpoint and callback in my contract code

  1. Endpoint
    #[endpoint]
    fn register(&self) {
        let caller: ManagedAddress = self.blockchain().get_caller();
        let delegation_addr = self.delegation_sc_addr().get();
    
        self.delegation_proxy(delegation_addr)
            .get_user_active_stake(&caller)
            .async_call()
            .with_callback(self.callbacks().process_registration())
            .call_and_exit();
    }
  2. Callback
      #[callback]
     fn process_registration(&self, #[call_result] result: ManagedAsyncCallResult<BigUint>) {
         // address must have active stake on the delegation contract
         match result {
             ManagedAsyncCallResult::Ok(active_stake) => {
                 require!(
                     active_stake != BigUint::from(0usize),
                     "no active stake for user"
                 );
             }
             ManagedAsyncCallResult::Err(err) => {
                 sc_panic!(&err.err_msg);
             }
         };
     }

Then, I have this Rust test snippet

    let not_staked_address = blockchain_wrapper.create_user_account(&rust_zero);
    blockchain_wrapper
        .execute_tx(&not_staked_address, &cg_wrapper, &rust_zero, |sc| {
            sc.register();
        })
        .assert_error(4, "no active stake for user");

For this case, the test should pass with the expected error no active stake for user, but it fails saying that the transaction was successful.

If I change the call from being asynchronous (i.e using the execute_on_dest_context method), then the test passes.

Seems the testing framework is not doing all the necessary checks or am I doing something wrong?

Cannot set name of NFT in Elrond Rust testing framework

I am writing tests for my smart contract using elrond-wasm 0.32.0.

My issue is that sc.blockchain().get_sc_address(/*args*/).name returns me the identifier of the ESDT, while I am expecting the name

Detailed steps

I am setting my ESDT token's name like so:

    blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
        &cf_wrapper.address_ref(),
        &ITEM_TO_EQUIP_ID,
        ITEM_TO_EQUIP_NONCE,
        &rust_biguint!(2u64),
        &Empty,
        0,
        Option::Some(&owner_address),
        Option::Some(ITEM_TO_EQUIP_NAME),
        Option::Some(b""),
        &[],
    );

Then, I get my ESDT token's name :

blockchain_wrapper
        .execute_query(&cf_wrapper, |sc| {
            let data = sc.blockchain().get_esdt_token_data(
                &ManagedAddress::from_address(&cf_wrapper.address_ref()),
                &TokenIdentifier::from_esdt_bytes(ITEM_TO_EQUIP_ID),
                ITEM_TO_EQUIP_NONCE,
            );

            // data.name equals ITEM_TO_EQUIP_ID, so it fail
            assert_eq!(data.name, ManagedBuffer::new_from_bytes(ITEM_TO_EQUIP_NAME));
        })
        .assert_ok();

Complete snippet

#[test]
fn set_name_test() {
    const WASM_PATH: &'static str = "sc-customize-nft/output/customize_nft.wasm";

    const ITEM_TO_EQUIP_ID: &[u8] = b"ITEM-a1a1a1";
    const ITEM_TO_EQUIP_NAME: &[u8] = b"item name";
    const ITEM_TO_EQUIP_NONCE: u64 = 1;

    let rust_zero = rust_biguint!(0u64);
    let mut blockchain_wrapper = BlockchainStateWrapper::new();
    let owner_address = blockchain_wrapper.create_user_account(&rust_zero);
    let cf_wrapper = blockchain_wrapper.create_sc_account(
        &rust_zero,
        Some(&owner_address),
        customize_nft::contract_obj,
        WASM_PATH,
    );

    // deploy contract
    blockchain_wrapper
        .execute_tx(&owner_address, &cf_wrapper, &rust_zero, |sc| {
            let result = sc.init(managed_token_id!(PENGUIN_TOKEN_ID));
            assert_eq!(result, SCResult::Ok(()));
        })
        .assert_ok();
    blockchain_wrapper.add_mandos_set_account(cf_wrapper.address_ref());

    blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
        &cf_wrapper.address_ref(),
        &ITEM_TO_EQUIP_ID,
        ITEM_TO_EQUIP_NONCE,
        &rust_biguint!(2u64),
        &Empty,
        0,
        Option::Some(&owner_address),
        Option::Some(ITEM_TO_EQUIP_NAME),
        Option::Some(b""),
        &[],
    );

    blockchain_wrapper
        .execute_query(&cf_wrapper, |sc| {
            let data = sc.blockchain().get_esdt_token_data(
                &ManagedAddress::from_address(&cf_wrapper.address_ref()),
                &TokenIdentifier::from_esdt_bytes(ITEM_TO_EQUIP_ID),
                ITEM_TO_EQUIP_NONCE,
            );

            println!("Name is {:?}", data.name);
            assert_eq!(data.name, ManagedBuffer::new_from_bytes(ITEM_TO_EQUIP_NAME));
        })
        .assert_ok();
}

Improve json ABI with stateMutability property or similar

Hi devs, I am looking for a way to know in ABI json what is view function (don't change state) and what is function that change state.
I need this in order to automatically generate function signature and function body in an Elixir module.
For instance view function call is rest call to gateway that automatically convert response to right Erlang VM type
and change state function in SC will be pure function in Elixir module that return Transaction struct with right encoded data in transaction data field.
Only difference that I can se now is "outputs": [] for change state function.
Example:

"endpoints": [
        {
            "name": "setCostPerByte",
            "inputs": [
                {
                    "name": "cost_per_byte",
                    "type": "BigUint"
                }
            ],
            "outputs": []
        },
        {
            "name": "factorial",
            "inputs": [
                {
                    "name": "value",
                    "type": "BigUint"
                }
            ],
            "outputs": [
                {
                    "type": "BigUint"
                }
            ]
        }
    ]

I want to mention Solidity json ABI format has stateMutability property that has value like ‘pure’, ‘view’, ‘nonpayable’ , ‘payable’

Equivalent Ethereum's ABI Interface is implemented in
https://hex.pm/packages/ex_abi
that is parsed in function_selector struct https://github.com/poanetwork/ex_abi/blob/master/lib/abi/function_selector.ex
This help a lot for in conversion and out conversion.

Thanks!
@elrondex

Unpredictable behaviour when using the `elrond-wasm-rs` framework

See ctindogarus4f/elrond-smart-contracts#1 ctindogarus4f/elrond-smart-contracts#2 and for more context.

There are 3 branches involved:

  • allow-premature-unstake-fail
  • allow-premature-unstake-less-calls
  • allow-premature-unstake-no-require

erdpy contract test should pass on all the 3 branches, however it doesn't pass on the allow-premature-unstake-fail. There is literally no difference between the branches in terms of logic, so the only possible explanation why the allow-premature-unstake-fail branch fails is that what you see in the code it is not what's get compiled by erdpy. You write some logic in your function and it appears that other random logic gets executed...

It tooks me 2 full days to debug this and I still have no clue why allow-premature-unstake-fail fails but the other 2 do not. It literally doesn't make any sense.

PS: There is nothing wrong with the mandos suite tests, because I manually test it as well, and indeed the logic is different on allow-premature-unstake-fail for reasons that I cannot explain.

SC send() is not reflected on wallet transactions feed

Hi devs,

I was supprised when i was testing the direct_egld() function on devnet, that it is not shown on the transactions feed on the devnet-wallet.

So currently if someone receive funds from a SC, the wallet owner have to way to know that he received it. Excepte the balance increase. I'm guessing there is no notification on the maiar app either.

And for example if i just want to send a message from a SC to an address to say "You can withdraw your fund now", it just doesn't show up, and doesn't notify on the app.

Can you implement that ?
Thank you

[MultisigContract] Should check if the quorum is positive

Description

The MultisigContract is initialized by defining the quorum size and the board address list.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/7f9d1b5d9cc90f22dfb067913ddcfe52fbcbb451/contracts/examples/multisig/src/lib.rs#L70-L71

The quorum size is checked to be at most the board size, because we need at least the quorum size to pass any proposal.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/7f9d1b5d9cc90f22dfb067913ddcfe52fbcbb451/contracts/examples/multisig/src/lib.rs#L72

However, the quorum or the board size are not checked to be >= 0. In this case, no proposal can be created because no user will pass the can_propose check.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/7f9d1b5d9cc90f22dfb067913ddcfe52fbcbb451/contracts/examples/multisig/src/user_role.rs#L11-L13

This check is necessary because, in order to create a proposal, this check needs to pass.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/7f9d1b5d9cc90f22dfb067913ddcfe52fbcbb451/contracts/examples/multisig/src/lib.rs#L95-L98

If the quorum is zero, the deployed multisig contract will not be able to execute any actions.

Recommendation

Add a check to make sure the quorum is positive, larger than zero.

Failed to get `elrond-wasm`

Hi! I'm new and I'm playing with the examples.

I've downloaded nft-minter and following this steps https://www.youtube.com/watch?v=IdkgvlK3rb8&list=PLQVcheGWwBRUTaG59ZybxJsPhMKS1pkHM&index=2 when I run erdpy contract build it throws this error.

error: failed to get `elrond-wasm` as a dependency of package `nft-minter-meta v0.0.0 (/home/zozel/dApp/NFTMinter/meta)`

Caused by:
failed to load source for dependency `elrond-wasm`

Caused by:
Unable to update /home/elrond-wasm

Caused by:
failed to read `/home/elrond-wasm/Cargo.toml`

With ping-pong example the contract is build and deployed without any problems.

Airdrop smart contract issue while sending tokens

I'm doing airdrop sc in rust but elrond network fails tx
image1
image2

#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi)]
pub struct Row<M: ManagedTypeApi> {
    pub address: ManagedAddress<M>,
    pub amount: BigUint<M>,
}

#[elrond_wasm::contract]
pub trait Airdrop {
    #[only_owner]
    #[endpoint]
    fn distribution(&self, table: Vec<Row<Self::Api>>) {
        let (output_token, _) = self.output_token().get();
        for row in &table {
            self.send().direct(&row.address, &output_token, 0, &row.amount, &[]);
        }
    }
}

[MultisigContract] Rewrite the UserRole `can_*` methods to account for all possible scenarios

Description

Right now, the user roles are defined as a list of individual checks.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/user_role.rs#L10-L18

This forces the developer to make sure it accounts for all possible scenarios, checking for all enum types.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/user_role.rs#L4-L8

A better way to do this is to use Rust's match operator which exhaustively checks if all of the options have been accounted for.

https://doc.rust-lang.org/book/ch06-02-match.html#matches-are-exhaustive

Recommendation

[MultisigContract] Add the ability to send a message when sending eGLD

Description

When sending eGLD, an empty string is sent as part of the transaction.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/893105cd34907ae3792aa6b1fb6b1ce09f406221/contracts/examples/multisig/src/lib.rs#L333-L335

However, this is not specified when the proposal is created. Hence, it will always be an empty string.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/893105cd34907ae3792aa6b1fb6b1ce09f406221/contracts/examples/multisig/src/lib.rs#L135-L138

Recommendation

To increase interoperability, add the possibility to specify this string when proposing a transaction.

Reimplement execute_on_dest_context_custom_range

Hi,

elrond-wasm-rs 0.31.0 removed execute_on_dest_context_custom_range. This function was the only way to get nested contracts calls results. This feature was very useful to interact with some complex contracts (like maiar dex). Is it possible to reimplement this function?

Thank you

Exception while checking contract balance : fatal error: exitsyscall: syscall frame is no longer valid

In mandos test ,
when contract calls blockchain api to get esdt balance of the contract , the following exception happens, even though in the test, I updated token balance of the contract using setState

ERROR
Scenario: withdraw.scen.json ... fatal error: exitsyscall: syscall frame is no longer valid

Mandos setstate updates contract esdt balance

      "sc:test_contract”: {
            …
            "esdt":{
                "str:TICKER-0a1b2c":"400,000,000,000"
            }
       }

The line that causes the error is this

self.blockchain().get_sc_balance(&token, 0)

FULL EXCEPTION

Scenario: withdraw.scen.json ... fatal error: exitsyscall: syscall frame is no longer valid

goroutine 1 [running, locked to thread]:
runtime.throw(0x45fc36b, 0x2d)
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/runtime/panic.go:1116 +0x72 fp=0xc00051afc8 sp=0xc00051af98 pc=0x4037112
runtime.exitsyscall()
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/runtime/proc.go:3225 +0x22c fp=0xc00051aff8 sp=0xc00051afc8 pc=0x406536c
runtime.cgocall(0x4460ca0, 0xc00051b060, 0x1)
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/runtime/cgocall.go:152 +0x9e fp=0xc00051b030 sp=0xc00051aff8 pc=0x4005fbe
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer._Cfunc_wasmer_instance_call(0x600000c0e6d0, 0x600000008dc0, 0xc0002e8ae0, 0x0, 0xc0002e8b00, 0xc000000000, 0xc000000002)
_cgo_gotypes.go:449 +0x4d fp=0xc00051b060 sp=0xc00051b030 pc=0x4304ced
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.cWasmerInstanceCall(...)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/wasmer/bridge.go:241
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.callWasmFunction(0x600000c0e6d0, 0xc0005fcd78, 0x8, 0x0, 0x4a96fa8, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/wasmer/function_wrapper_helpers.go:82 +0x1bf fp=0xc00051b0d8 sp=0xc00051b060 pc=0x4300f9f
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.createExportedFunctionWrapper.func1(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/wasmer/instance_helpers.go:144 +0x190 fp=0xc00051b190 sp=0xc00051b0d8 pc=0x4307370
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).callSCMethod(0xc0003500f0, 0xc00006b000, 0x4c75)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwen/host/execution.go:874 +0x494 fp=0xc00051b268 sp=0xc00051b190 pc=0x43f3f34
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).doRunSmartContractCall(0xc0003500f0, 0xc0000a81e0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwen/host/execution.go:186 +0x6d7 fp=0xc00051b3a0 sp=0xc00051b268 pc=0x43edff7
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).RunSmartContractCall.func2()
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwen/host/arwen.go:353 +0x3c fp=0xc00051b3d0 sp=0xc00051b3a0 pc=0x43f4e3c
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.TryCatch(0xc00051b480, 0xc00051b470, 0x45f1b50, 0x1a)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwen/host/arwen.go:384 +0x6c fp=0xc00051b420 sp=0xc00051b3d0 pc=0x43e466c
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).RunSmartContractCall(0xc0003500f0, 0xc0000a81e0, 0x0, 0x0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwen/host/arwen.go:365 +0x24b fp=0xc00051b4e0 sp=0xc00051b420 pc=0x43e452b
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).scCall(0xc000130240, 0xc0004527a1, 0xd, 0xc00013e120, 0x5f5e100, 0x0, 0x0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwenmandos/stepRunTx.go:240 +0x342 fp=0xc00051b668 sp=0xc00051b4e0 pc=0x445d222
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).executeTx(0xc000130240, 0xc0004527a1, 0xd, 0xc00013e120, 0x0, 0x0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwenmandos/stepRunTx.go:81 +0x1d2 fp=0xc00051b7f8 sp=0xc00051b668 pc=0x445b112
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteTxStep(0xc000130240, 0xc0002eaac0, 0xc00051b8a0, 0x445f982, 0xc00014e930)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwenmandos/execScenario.go:138 +0x125 fp=0xc00051b868 sp=0xc00051b7f8 pc=0x4451265
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteStep(0xc000130240, 0x4794760, 0xc0002eaac0, 0x0, 0x0)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwenmandos/execScenario.go:57 +0x111 fp=0xc00051b8b0 sp=0xc00051b868 pc=0x4450351
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteScenario(0xc000130240, 0xc0001b9f40, 0x479e660, 0xc0001286c0, 0x5d, 0xc0001b9f40)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/arwenmandos/execScenario.go:31 +0x1e5 fp=0xc00051b938 sp=0xc00051b8b0 pc=0x4450165
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunSingleJSONScenario(0xc00051bf38, 0xc0001aa1e0, 0x5d, 0xc000132301, 0x5d, 0x208f4ae87)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/mandos-go/controller/scenarioOne.go:38 +0xc8 fp=0xc00051b988 sp=0xc00051b938 pc=0x4419f68
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunAllJSONScenariosInDirectory.func1(0xc0001aa1e0, 0x5d, 0x47a0a60, 0xc00011d860, 0x0, 0x0, 0x12, 0xc00051bb10)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/mandos-go/controller/scenarioDir.go:33 +0x334 fp=0xc00051ba88 sp=0xc00051b988 pc=0x441ab54
path/filepath.walk(0xc0001aa1e0, 0x5d, 0x47a0a60, 0xc00011d860, 0xc00051bd60, 0x0, 0x0)
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:360 +0x423 fp=0xc00051bb60 sp=0xc00051ba88 pc=0x40ead63
path/filepath.walk(0xc00012c140, 0x4a, 0x47a0a60, 0xc00011d6c0, 0xc00051bd60, 0x0, 0x4a)
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:384 +0x2fe fp=0xc00051bc38 sp=0xc00051bb60 pc=0x40eac3e
path/filepath.Walk(0xc00012c140, 0x4a, 0xc000159d60, 0xc00012c140, 0x4a)
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:406 +0x105 fp=0xc00051bc98 sp=0xc00051bc38 pc=0x40eaea5
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunAllJSONScenariosInDirectory(0xc000159f38, 0x208f4ae87, 0x4a, 0x0, 0x0, 0x45e8b81, 0xa, 0xc000159e40, 0x0, 0x0, ...)
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/mandos-go/controller/scenarioDir.go:24 +0x1d4 fp=0xc00051bdd8 sp=0xc00051bc98 pc=0x4419a54
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/cmd/mandostestcli.MandosTestCLI()
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/cmd/mandostestcli/mandosTestCLI.go:71 +0x894 fp=0xc00051bf78 sp=0xc00051bdd8 pc=0x4460774
main.main()
/Users/myuser/elrondsdk/vmtools/v1.4.32/wasm-vm-1.4.32/cmd/test/mandosTestLegacy.go:7 +0x25 fp=0xc00051bf88 sp=0xc00051bf78 pc=0x4460905
runtime.main()
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/runtime/proc.go:204 +0x209 fp=0xc00051bfe0 sp=0xc00051bf88 pc=0x40398e9
runtime.goexit()
/Users/myuser/elrondsdk/golang/go1.15.2/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00051bfe8 sp=0xc00051bfe0 pc=0x4069721

Mandos test failing when struct is represented as JSON maps, but passes when pain Concatenation is used

I have this struct in my contract

#[derive(TopEncode, TopDecode, TypeAbi)]
pub struct Reward<M>
where
    M: ManagedTypeApi,
{
    pub id: u64,
    pub batch_period: u64,
    pub profile_rank: ProfileRank<M>,
    pub egld_staked: BigUint<M>,
    pub egld_to_reward: BigUint<M>,
    pub reward_boost: BigUint<M>,
    pub reward_gained: BigUint<M>,
    pub reward_credited: BigUint<M>,
    pub epochs_locked: u64,
    pub epochs_credited: u64,
    pub eol: u64
}Ï

ProfileRank is just a type alias for BigUint with an implementation of another trait.

pub type ProfileRank<M> = BigUint<M>;

impl<M: ManagedTypeApi> ProfileRankTrait<M> for ProfileRank<M> {}

I wrote a Mandos scenario file, and the storage value for this struct resulted to this hex value:
0x00000000000000010000000000000001000000080de0b6b3a7640000000000080de0b6b3a7640000000000080de0b6b3a7640000000000081bc16d674ec800000000000000000000000000000000000a00000000000000000000000000002ee0.

If I write in the mandos test file following the concatenation style

"u64:1|u64:1|biguint:1,000,000,000,000,000,000|biguint:1,000,000,000,000,000,000|biguint:1,000,000,000,000,000,000|biguint:2,000,000,000,000,000,000|biguint:0|biguint:0|u64:10|u64:0|u64:12,000"

my test passes.

But if I write the mandos test file following the JSON maps method

{
              "0-id": "u64:1",
              "1-batch_period": "u64:1",
              "2-profile_rank": "biguint:1,000,000,000,000,000,000",
              "3-egld_staked": "biguint:1,000,000,000,000,000,000",
              "4-egld_to_reward": "biguint:1,000,000,000,000,000,000",
              "5-reward_boost": "biguint:2,000,000,000,000,000,000",
              "6-reward_gained": "biguint:0",
              "7-reward_credited": "biguint:0",
              "8-epochs_locked": "u64:10",
              "9-epochs_credited": "u64:0",
              "10-eol": "u64:12,000"
 }

the test fails.

Interestingly, if I remove the pub eol: u64 property from the struct and run the test with both styles, everything works fine. I have tried different permutations to know what the cause of the discrepancy is to no avail.

Maybe there's a bug in elrond-wasm-rs that's causing this??

I made a repo: https://github.com/newtmex/mandos_ish

ManagedVecItem throws error: Missing required bounds on Ref

ManagedVecItem throws error: "Missing required bounds" on Ref while building in
https://github.com/ElrondNetwork/elrond-wasm-rs/blob/0a4067ed0ca4916d2d0223da815901cc37b05071/elrond-wasm/src/types/managed/wrapped/managed_vec_item.rs#L38

i simply changed the line (as suggested) to:
type Ref<'a>: Borrow<Self> where Self: 'a;

This worked, but tbh, i am fairly new to rust, so i am not sure, if this is a legit issue or was caused by my setup.
Should i open a pull request?

Br

[MultisigContract] Sign should check actions exists

Description

A board member can call sign to add their signature for an action.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/aab253b7bd5e4fc9d74c1dca9fce069c99b13384/contracts/examples/multisig/src/lib.rs#L212-L215

However, the sign method does not check if the action exists before adding the signature to the list, thus the board member could, in theory, sign a transaction without knowing what the transaction will do.

Recommendation

Check the transaction exists and its type is valid, before signing the transaction.

A similar check should be done for unsign for good measure.

Mandos test fails if I use self.blockchain().get_sc_balance

Hi everyone,

I'm using elrond-wasm 0.20.1 and noticed that my mandos tests are now crashing.
I could pinpoint it to the following line:

        let sc_token_balance = self.blockchain().get_sc_balance(&token_ident, 0u64);
        //let sc_token_balance = BigUint::from(0u64);

Commenting out the first line and using the second line instead fixes the error.

This is the error i get for the first line.


goroutine 69 [running, locked to thread]:
runtime.throw(0xa2860a, 0x2d)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/runtime/panic.go:1116 +0x72 fp=0xc00004cb20 sp=0xc00004caf0 pc=0x45c752
runtime.exitsyscall()
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/runtime/proc.go:3225 +0x22a fp=0xc00004cb50 sp=0xc00004cb20 pc=0x48c4ca
runtime.cgocall(0x88e830, 0xc00004cbb8, 0xbb4670)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/runtime/cgocall.go:152 +0x9e fp=0xc00004cb88 sp=0xc00004cb50 pc=0x42ab1e
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer._Cfunc_wasmer_instance_call(0x7f63982adfd0, 0x1a57190, 0xc0001820c0, 0x0, 0xc0001820e0, 0xc000000000, 0xc000000002)
        _cgo_gotypes.go:457 +0x4d fp=0xc00004cbb8 sp=0xc00004cb88 pc=0x72e32d
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.cWasmerInstanceCall(...)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/wasmer/bridge.go:241
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.callWasmFunction(0x7f63982adfd0, 0xc0000b0474, 0x9, 0x0, 0xedec88, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/wasmer/function_wrapper_helpers.go:82 +0x1bf fp=0xc00004cc30 sp=0xc00004cbb8 pc=0x72a5bf
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/wasmer.createExportedFunctionWrapper.func1(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/wasmer/instance_helpers.go:144 +0x190 fp=0xc00004cce8 sp=0xc00004cc30 pc=0x730a70
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).callSCMethod(0xc000130300, 0xc00020a000, 0x4967)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwen/host/execution.go:871 +0x502 fp=0xc00004cdd0 sp=0xc00004cce8 pc=0x8202a2
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).doRunSmartContractCall(0xc000130300, 0xc00013c780, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwen/host/execution.go:182 +0x6d7 fp=0xc00004cf08 sp=0xc00004cdd0 pc=0x81a1f7
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).RunSmartContractCall.func1(0xc0000b6840, 0xc00013c780, 0xc000130300, 0xc0000105b0, 0xc00008e420)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwen/host/arwen.go:424 +0xbc fp=0xc00004cfb8 sp=0xc00004cf08 pc=0x8217fc
runtime.goexit()
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00004cfc0 sp=0xc00004cfb8 pc=0x490581
created by github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).RunSmartContractCall
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwen/host/arwen.go:411 +0x3be

goroutine 1 [select]:
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwen/host.(*vmHost).RunSmartContractCall(0xc000130300, 0xc00013c780, 0x0, 0x0, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwen/host/arwen.go:441 +0x49f
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).scCall(0xc0000b6240, 0xc0004fc851, 0xa, 0xc0000c05a0, 0x100000, 0x0, 0x0, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwenmandos/stepRunTx.go:240 +0x342
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).executeTx(0xc0000b6240, 0xc0004fc851, 0xa, 0xc0000c05a0, 0x0, 0x0, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwenmandos/stepRunTx.go:81 +0x1d2
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteTxStep(0xc0000b6240, 0xc0000c2580, 0xc0001457c8, 0x88d642, 0xc0000ccb60)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwenmandos/execScenario.go:149 +0x125
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteStep(0xc0000b6240, 0xbc1060, 0xc0000c2580, 0x0, 0x0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwenmandos/execScenario.go:68 +0x111
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/arwenmandos.(*ArwenTestExecutor).ExecuteScenario(0xc0000b6240, 0xc0000d3bd0, 0xbcb0a0, 0xc0000a85c0, 0x5f, 0xc0000d3bd0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/arwenmandos/execScenario.go:42 +0x1e5
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunSingleJSONScenario(0xc000145f38, 0xc00008e120, 0x5f, 0xc0000b0301, 0x5f, 0x7fff55461f85)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/mandos-go/controller/scenarioOne.go:38 +0xc8
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunAllJSONScenariosInDirectory.func1(0xc00008e120, 0x5f, 0xbcd3a0, 0xc0001505b0, 0x0, 0x0, 0x4fa5bd, 0xc0001505b0)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/mandos-go/controller/scenarioDir.go:33 +0x334
path/filepath.walk(0xc00008e120, 0x5f, 0xbcd3a0, 0xc0001505b0, 0xc000145d60, 0x0, 0x0)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:360 +0x423
path/filepath.walk(0xc0000b20a0, 0x4b, 0xbcd3a0, 0xc00022e000, 0xc000145d60, 0x0, 0x0)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:384 +0x2fe
path/filepath.walk(0xc0000b20f0, 0x46, 0xbcd3a0, 0xc00009d380, 0xc000145d60, 0x0, 0x46)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:384 +0x2fe
path/filepath.Walk(0xc0000b20f0, 0x46, 0xc0000d7d60, 0xc0000b20f0, 0x46)
        /home/wagnerm/elrondsdk/golang/go1.15.2/go/src/path/filepath/path.go:406 +0x105
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/mandos-go/controller.(*ScenarioRunner).RunAllJSONScenariosInDirectory(0xc0000d7f38, 0x7fff55461f85, 0x46, 0x0, 0x0, 0xa14897, 0xa, 0xc0000d7e40, 0x0, 0x0, ...)
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/mandos-go/controller/scenarioDir.go:24 +0x1d4
github.com/ElrondNetwork/arwen-wasm-vm/v1_4/cmd/mandostestcli.MandosTestCLI()
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/cmd/mandostestcli/mandosTestCLI.go:71 +0x845
main.main()
        /home/wagnerm/elrondsdk/vmtools/v1.4.42/wasm-vm-1.4.42/cmd/test/mandosTestLegacy.go:7 +0x25

Just wanted to let you know :)
Ultimately I executed the tests just to make sure everything runs well before I update the elrond-wasm version.
So nothing that needs immediate fixing.

ModuleNotFoundError: No module named 'erdpy.environments'

hey, I'm new to elrond network and trying to setup workspace by docs. However, for some reason can't use python bindings to test adder example with playground.py. I managed to interact with the contract using bash script, but not python

[/mnt/tmpfs/elrond-playground]$ python3 ./adder/interaction/playground.py 
Traceback (most recent call last):
  File "./adder/interaction/playground.py", line 8, in <module>
    from erdpy.environments import TestnetEnvironment
ModuleNotFoundError: No module named 'erdpy.environments'

$ tree -L 1 /mnt/tmpfs/elrond-playground
/mnt/tmpfs/elrond-playground
├── adder
├── elrond.workspace.json
└── erdjs-snippets

2 directories, 1 file

[MultisigContract] Calling an external contract leaves the state unclean

Description

When performing an Action::SCCall, this needs to be done using async_call. This ends the transaction right then and there, waiting for the result of that call to continue the execution.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/893105cd34907ae3792aa6b1fb6b1ce09f406221/contracts/examples/multisig/src/lib.rs#L351-L362

This means that all of the action cleanup isn't done until the execution is finished. This can let a malicious user, execute an action multiple times.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/893105cd34907ae3792aa6b1fb6b1ce09f406221/contracts/examples/multisig/src/lib.rs#L351-L369

Recommendation

Move the action cleanup immediately above the action matching.

Specifically, between these 2 lines.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/893105cd34907ae3792aa6b1fb6b1ce09f406221/contracts/examples/multisig/src/lib.rs#L314-L315

"No such file or directory" error in Mandos go Test

I tried running this test https://github.com/ElrondNetwork/elrond-wasm-rs/blob/886ea0e953c700da74cc0693ab04e7d0d30c52b5/contracts/examples/multisig/tests/multisig_mandos_go_test.rs#L2 with the mandos-go-tests feature enabled and got the error "No such file or directory".

I am experiencing this in my contract (the file exists and relative path is correct), so I tried this one here and got same error.

Is there some other config I have to set or there's a bug?

[MultisigContract] Add a view function to return if an action can be executed

Description

In order to find out if an action can be executed, an external actor, or a contract has to do a few actions:

  • get all signer ids
  • iterate over all signer ids and check if they still are part of the board member, to validate their signature
  • check if the valid signatures is higher or equal to the quorum

This creates friction and it is prone to missing some of the checks or doing them incorrectly, because this functionality is not provided by the MultisigContract itself, and it has to be done externally.

All of these checks are already part of the contract before performing an action.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/aab253b7bd5e4fc9d74c1dca9fce069c99b13384/contracts/examples/multisig/src/lib.rs#L294-L306

Recommendation

Create a view function that returns if an action can be executed.

Based on the discussion we had (with @andrei-marinica), a possible definition of this view function could be quorum_reached(action_id) -> bool.

Store whitelisted addresses inside the smart contract init function

Hi Elrond fellows developer,

I search to store whitelisted addresses inside a SC but I want to do it the most optimized way could you provide some examples for the community ?

On my side I chosen to fill a storage mapper in init like this :

// in top of file
use elrond_wasm::hex_literal::hex;

// in init function
self.allowlist().insert(ManagedAddress::from_address(&Address::from(ManagedByteArray::from_raw_handle(hex!("1ff238d3d35e0f942abcdefxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")))));

// in sc function when we need to control if address is whitelisted
require!(
    self.allowlist().contains(&caller),
    "caller not whitelisted"
);

// Storage
#[storage_mapper("allowlist")]
fn allowlist(&self) -> SetMapper<ManagedAddress>;

Obviously that code works but is not optimized at all since it has allocator.

How could you do that without using the heap mem regarding the best practices here : https://docs.elrond.com/developers/developer-reference/smart-contract-developer-best-practices/#the-dynamic-allocation-problem

Thanks by advance for your responses,

an happy Elrond builder.

Rust 2021 warnings

Just installed erdpy from scratch. When I build my code against a local clone of elrond-wasm-rs I get lots of these:

warning: panic message is not a string literal
--> /Users/ram/dev/elrond/elrond-wasm-rs/elrond-wasm-debug/src/api/send_api_mock.rs:78:11
|
78 |               panic!(TxPanic {
|  ____________________^
79 | |                 status: 10,
80 | |                 message: b"insufficient funds".to_vec(),
81 | |             });
| |_____________^
|
= note: this is no longer accepted in Rust 2021

[MultisigContract] A board member can block the actions of all the other board members

Description

An action has to go through a number of steps in order to be executed.

The first step is proposing an action. A board member or a proposer can propose an action.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L99-L106

The second step is signing that action. Any board members can sign that action.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L212-L217

The third step is executing the action, once the quorum was reached.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L305-L306

Before the action is executed, any board member can withdraw their signature by calling unsign.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L228-L233

The unsign method, to remove blockchain state bloat, removes the action once all of the board members withdrew all of their signatures.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L245-L248

This creates a race condition issue where one of the board members, if they don't agree with an action, watch the blockchain for that action to be proposed, are the first ones to sign the action, and immediately unsign the action, removing the possibility for any other board member to sign and execute that action.

Even if the other board members want to remove the misbehaving board member from the quorum, they need to go through the same process of proposing, signing and executing the action. If the misbehaving board member watches the contract for that proposal can race against all the other board members sign and unsign the action, removing it from the proposed actions. This way the board members, if they are successfully fronrun, they can't perform any actions in the MultisigContract they should have control over.

Recommendation

Do not empty the state if there are no signers left.

Referrences

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L245-L248

error when compiling `elrond-wasm` v0.26.0

Description:
Bounds of 'a are probably not defined in this scope.

Reference:
https://github.com/ElrondNetwork/elrond-wasm-rs/blob/d39c38ca220bc8ebd4658968bcbf3b3fda38de3f/elrond-wasm/src/types/managed/managed_vec_item.rs#L35

error: Missing required bounds on Ref
--> /.../vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-wasm-0.26.0/src/types/managed/managed_vec_item.rs:35:5
|
35 |     type Ref<'a>: Borrow<Self>;
|     ^^^^^^^^^^^^^^^^^^^^^^^^^^-
|                               |
|                               help: add the required where clauses: `where Self: 'a`

Getting gas price in SC context

How I can get gas price in SC?
I not found any functions for this.
Can you implement that?
Something like

self.blockchain().get_gas_price()

how to freeze assets?

hello,
as i could not find any example, i would like to know how to freeze a token.

https://docs.rs/elrond-wasm/latest/elrond_wasm/esdt/struct.ESDTSystemSmartContractProxy.html#method.freeze

so far i have:

        self.send()
            .esdt_system_sc_proxy()
            .freeze(&token_id, &address)
            .async_call()
            .with_callback(self.callbacks().tmp_freeze_callback())
            .call_and_exit()
    fn tmp_freeze_callback(&self, #[call_result] result: ManagedAsyncCallResult<()>) {
        match result {
            ManagedAsyncCallResult::Ok(()) => {}
            ManagedAsyncCallResult::Err(_) => {
                // this can only fail if the kitty_ownership contract address is invalid
                // nothing to revert in case of error
            }
        }
    }

but the testing suite crashes as soon as i call that function. do you have a working example at hand that i can have a look at?

thank you

Allow ContractBase to be specified in contracts and modules traits

Hi! Allowing to specify ContractBase can be very convenient for those who don't use VSCode & Elrond IDE plugin. This enable auto-completion and make IDEs smarter since after macro processing the trait is a ContractBase.

I purpose to modify derives macros to not throw errors when elrond_wasm::contract_base::ContractBase is specified in a trait by user. This will make the following code valid :

#[elrond_wasm::contract]
pub trait MyContract : elrond_wasm::contract_base::ContractBase + path::to::MyModule {
    // contract code
}
#[elrond_wasm::module]
pub trait MyModule : elrond_wasm::contract_base::ContractBase {
    // module code
}

I can make the PR if it can help you.

Which nonce to provide when calling esdt_local_burn?

Hi!

Some internal methods like esdt_local_burn require a "nonce" parameter.

Are we supposed to provide the nonce of the transaction itself (e.g. the current nonce of the wallet signing the tx)? If yes, for relayed txs should it be the nonce of wallet signing the internal tx OR the nonce of the wallet paying for the gas fee?

Or is it the nonce returned by the esdt_nft_create function? In that case, is there a built-in function to retrieve the NFT nonce by the token identifier (I suspect not otherwise these internal methods wouldn't need the nonce param in the first place), just asking to make sure, otherwise I'll need to store it somehow (maybe with attributes OR just a mapping).

Thanks!

Cannot run erdpy contract build on a Manually Created SC on Rust due to Compiling issue

Hello

I am trying to go through creation a Smart Contract, from scratch, using Rust. I tried creating the crates and building out similar file structures in your teams examples i.e. src.rs, meta, wasm, etc. And I the the listed out below when running erdpy contract deploy.

My environment I am working with is the following:

rustc 1.65.0-nightly (228710758 2022-09-10)
erdpy 2.0.1
[dependencies.elrond-wasm-node]
version = "0.34.1"
[dependencies.elrond-wasm-output]
version = "0.34.1"

It looks like it is running into an error trying to compile the elrond codec/wasm? I have tried other online solutions that mentioned trying to run it in nightly. I have even added the rust-toolchain file. Any help would greatly be appreciated.

INFO:myprocess:run_process_async: ['cargo', 'run', 'build', '--target=wasm32-unknown-unknown', '--release', '--out-dir', '/home/anon/Desktop/elrond-dev/smart_contracts/helloworld/hello_world/output', '--target-dir', '/home/anon/elrondsdk/default_cargo_target'], in folder: /home/anon/Desktop/elrond-dev/smart_contracts/helloworld/hello_world/meta
Compiling elrond-wasm-derive v0.34.1
Compiling serde v1.0.144
Compiling elrond-codec v0.12.0
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-codec-0.12.0/src/lib.rs:2:1
|
2 | #![feature(try_trait_v2)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-codec-0.12.0/src/lib.rs:3:1
|
3 | #![feature(never_type)]
| ^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-codec-0.12.0/src/lib.rs:4:1
|
4 | #![feature(exhaustive_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-codec-0.12.0/src/lib.rs:5:1
|
5 | #![feature(auto_traits)]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-codec-0.12.0/src/lib.rs:6:1
|
6 | #![feature(negative_impls)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `elrond-codec` due to 5 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0554]: `#![feature]` may not be used on the stable release channel
--> /home/anon/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-wasm-derive-0.34.1/src/lib.rs:4:12
|
4 | #![feature(proc_macro_quote)]
|            ^^^^^^^^^^^^^^^^

error: build failed
CRITICAL:cli:Build error: error code = 101, see output.

blockchain().get_gas_limit() implementation of BlockchainApi for DebugApi

Is there a reason for this cap on gas_limit for async_callback_tx_input as seen here?
https://github.com/ElrondNetwork/elrond-wasm-rs/blob/296e34ae4ffd8333c7a2cb39b105dd2d0c5c5db4/elrond-wasm-debug/src/tx_mock/tx_async_call_data.rs#L59

When self.blockchain().get_gas_limit() is called in a smart contract's callback that is called after an async call, this value defaults to 1000 in the Rust Framework test.

Is this hard cap for a reason? Shouldn't it be set by the user?

@andrei-marinica

[MultisigContract] Use same naming convention for board and proposer member size

Description

With the pull request #62, a new view function getNumProposers was added to the contract, which returns the number of the users which have the UserRole::Proposer permissions.

https://github.com/ElrondNetwork/elrond-wasm-rs/blob/87e769e6107278b23fbd4887e3e7c3c7cd0aa154/contracts/examples/multisig/src/lib.rs#L43-L45

This is similar to the already existing function getBoardSize, which returns the number of users who have the UserRole::BoardMember permissions.

It will increase readability, the ability to maintain the code, and interactions with the MultisigContract if the naming convention is consistent.

Recommendation

Rename one or both getBoardSize and getNumProposers view functions to adhere to a consistent naming convention.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.