GithubHelp home page GithubHelp logo

near / near-sdk-rs Goto Github PK

View Code? Open in Web Editor NEW
449.0 17.0 240.0 26.49 MB

Rust library for writing NEAR smart contracts

Home Page: https://near-sdk.io

License: Apache License 2.0

Rust 99.14% Shell 0.40% Dockerfile 0.02% Python 0.43%
blockchain nearprotocol rust sdk wasm

near-sdk-rs's Introduction

near-sdk

Rust library for writing NEAR smart contracts.

Previously known as near-bindgen.

Reference Documentation MSRV Crates.io version Download Join the community on Discord Join the community on Telegram

Release notes

Release notes and unreleased changes can be found in the CHANGELOG

Example

Wrap a struct in #[near] and it generates a smart contract compatible with the NEAR blockchain:

use near_sdk::{near, env};

#[near(contract_state)]
#[derive(Default)]
pub struct StatusMessage {
    records: HashMap<AccountId, String>,
}

#[near]
impl StatusMessage {
    pub fn set_status(&mut self, message: String) {
        let account_id = env::signer_account_id();
        self.records.insert(account_id, message);
    }

    pub fn get_status(&self, account_id: AccountId) -> Option<String> {
        self.records.get(&account_id).cloned()
    }
}

Features

Unit-testable

Writing unit tests is easy with near-sdk:

#[test]
fn set_get_message() {
    let mut contract = StatusMessage::default();
    contract.set_status("hello".to_string());
    assert_eq!("hello".to_string(), contract.get_status("bob_near".to_string()).unwrap());
}

Run unit test the usual way:

cargo test --package status-message

Asynchronous cross-contract calls

Asynchronous cross-contract calls allow parallel execution of multiple contracts in parallel with subsequent aggregation on another contract. env exposes the following methods:

  • promise_create -- schedules an execution of a function on some contract;
  • promise_then -- attaches the callback back to the current contract once the function is executed;
  • promise_and -- combinator, allows waiting on several promises simultaneously, before executing the callback;
  • promise_return -- treats the result of execution of the promise as the result of the current function.

Follow examples/cross-contract-high-level to see various usages of cross contract calls, including system-level actions done from inside the contract like balance transfer (examples of other system-level actions are: account creation, access key creation/deletion, contract deployment, etc).

Initialization methods

We can define an initialization method that can be used to initialize the state of the contract. #[init] verifies that the contract has not been initialized yet (the contract state doesn't exist) and will panic otherwise.

#[near]
impl StatusMessage {
    #[init]
    pub fn new(user: String, status: String) -> Self {
        let mut res = Self::default();
        res.records.insert(user, status);
        res
    }
}

Even if you have initialization method your smart contract is still expected to derive Default trait. If you don't want to disable default initialization, then you can prohibit it like this:

impl Default for StatusMessage {
    fn default() -> Self {
        near_sdk::env::panic_str("Contract should be initialized before the usage.")
    }
}

You can also prohibit Default trait initialization by using near_sdk::PanicOnDefault helper macro. E.g.:

#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct StatusMessage {
    records: HashMap<String, String>,
}

Payable methods

We can allow methods to accept token transfer together with the function call. This is done so that contracts can define a fee in tokens that needs to be paid when they are used. By the default the methods are not payable and they will panic if someone will attempt to transfer tokens to them during the invocation. This is done for safety reason, in case someone accidentally transfers tokens during the function call.

To declare a payable method simply use #[payable] decorator:

#[payable]
pub fn my_method(&mut self) {
...
}

Private methods

Usually, when a contract has to have a callback for a remote cross-contract call, this callback method should only be called by the contract itself. It's to avoid someone else calling it and messing the state. Pretty common pattern is to have an assert that validates that the direct caller (predecessor account ID) matches to the contract's account (current account ID). Macro #[private] simplifies it, by making it a single line macro instead and improves readability.

To declare a private method use #[private] decorator:

#[private]
pub fn my_method(&mut self) {
...
}
/// Which is equivalent to

pub fn my_method(&mut self ) {
    if near_sdk::env::current_account_id() != near_sdk::env::predecessor_account_id() {
        near_sdk::env::panic_str("Method my_method is private");
    }
...
}

Now, only the account of the contract itself can call this method, either directly or through a promise.

Pre-requisites

To develop Rust contracts you would need to:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Add wasm target to your toolchain:
rustup target add wasm32-unknown-unknown

Writing Rust Contract

You can follow the examples/status-message crate that shows a simple Rust contract.

The general workflow is the following:

  1. Create a crate and configure the Cargo.toml similarly to how it is configured in examples/status-message/Cargo.toml;

  2. Crate needs to have one pub struct that will represent the smart contract itself:

    • The struct needs to implement Default trait which NEAR will use to create the initial state of the contract upon its first usage;

    Here is an example of a smart contract struct:

    use near_sdk::{near, env};
    
    #[near(contract_state)]
    #[derive(Default)]
    pub struct MyContract {
        data: HashMap<u64, u64>
    }
  3. Define methods that NEAR will expose as smart contract methods:

    • You are free to define any methods for the struct but only public methods will be exposed as smart contract methods;
    • Methods need to use either &self, &mut self, or self;
    • Decorate the impl section with #[near] macro. That is where all the M.A.G.I.C. (Macros-Auto-Generated Injected Code) happens;
    • If you need to use blockchain interface, e.g. to get the current account id then you can access it with env::*;

    Here is an example of smart contract methods:

    #[near]
    impl MyContract {
        pub fn insert_data(&mut self, key: u64, value: u64) -> Option<u64> {
            self.data.insert(key)
        }
        pub fn get_data(&self, key: u64) -> Option<u64> {
            self.data.get(&key).cloned()
        }
    }

Building Rust Contract

cargo-near is an easy and recommended way to build and deploy Rust contracts.

Installation

Install prebuilt binaries via shell script (Linux, macOS)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
Install prebuilt binaries via powershell script (Windows)
irm https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.ps1 | iex
Install prebuilt binaries into your Node.js application
npm install cargo-near
Compile and install from source code (Cargo)
cargo install cargo-near

or, install the most recent version from git repository:

$ git clone https://github.com/near/cargo-near
$ cargo install --path cargo-near

Usage

See cargo near --help for a complete list of available commands or run cargo near to dive into interactive mode. Help is also available for each individual command with a --help flag, e.g. cargo near build --help.

cargo near

Starts interactive mode that will allow to explore all the available commands.

cargo near build

Builds a NEAR smart contract along with its ABI (while in the directory containing contract's Cargo.toml).

cargo near create-dev-account

Guides you through creation of a new NEAR account on testnet.

cargo near deploy

Builds the smart contract (equivalent to cargo near build) and guides you to deploy it to the blockchain.

Using cargo build

RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release

Building with reproducible builds

Since WebAssembly compiler includes a bunch of debug information into the binary, the resulting binary might be different on different machines. To be able to compile the binary in a reproducible way, we added a Dockerfile that allows to compile the binary.

Use contract-builder

NEAR contract standards

near-contract-standards crate provides a set of interfaces and implementations for NEAR's contract standards:

Versioning

Semantic Versioning

This crate follows Cargo's semver guidelines.

State breaking changes (low-level serialization format of any data type) will be avoided at all costs. If a change like this were to happen, it would come with a major version and come with a compiler error. If you encounter one that does not, open an issue!

MSRV

The minimum supported Rust version is currently 1.76. There are no guarantees that this will be upheld if a security patch release needs to come in that requires a Rust toolchain increase.

Contributing

If you are interested in contributing, please look at the contributing guidelines.

near-sdk-rs's People

Contributors

adsick avatar agostbiro avatar ailisp avatar austinabell avatar bowenwang1996 avatar chadoh avatar chaotictempest avatar davidm-d avatar dj8yfo avatar frol avatar hanakannzashi avatar iho avatar ilblackdragon avatar itegulov avatar janedegtiareva avatar k06a avatar kouprin avatar lexfrl avatar maksymzavershynskyi avatar matklad avatar mikedotexe avatar mikhailok avatar miraclx avatar olonho avatar polyprogrammist avatar ruseinov avatar sept-en avatar telezhnaya avatar uint avatar willemneal avatar

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

near-sdk-rs's Issues

Tests for promises and cross contract examples

Currently it's unclear how to actually test promises (starting from Transfer, Staking to calls for other contracts). Current examples don't provide any examples of such tests either.

Implement near::collections::*

std::collections are good for small-to-medium contracts that do not use a lot of state, which is fine for now, since state storage cost is very small. We need to provide equivalent near::collections::{HashMap, HashSet, Vec} that utilize Trie to make the storage usage as efficient as possible.

Add VMContext builder for easier tests

I keep copying my context builder to write tests easily with different contexts:


    pub struct VMContextBuilder {
        context: VMContext,
    }

    impl VMContextBuilder {
        pub fn new() -> Self {
            Self {
                context: VMContext {
                    current_account_id: "".to_string(),
                    signer_account_id: "".to_string(),
                    signer_account_pk: vec![0, 1, 2],
                    predecessor_account_id: "".to_string(),
                    input: vec![],
                    block_index: 0,
                    block_timestamp: 0,
                    account_balance: 0,
                    account_locked_balance: 0,
                    storage_usage: 10u64.pow(6),
                    attached_deposit: 0,
                    prepaid_gas: 10u64.pow(18),
                    random_seed: vec![0, 1, 2],
                    is_view: false,
                    output_data_receivers: vec![],
                },
            }
        }

        pub fn current_account_id(mut self, account_id: AccountId) -> Self {
            self.context.current_account_id = account_id;
            self
        }

        pub fn signer_account_id(mut self, account_id: AccountId) -> Self {
            self.context.signer_account_id = account_id;
            self
        }

        pub fn predecessor_account_id(mut self, account_id: AccountId) -> Self {
            self.context.predecessor_account_id = account_id;
            self
        }

        pub fn block_index(mut self, block_index: BlockHeight) -> Self {
            self.context.block_index = block_index;
            self
        }

        pub fn attached_deposit(mut self, amount: Balance) -> Self {
            self.context.attached_deposit = amount;
            self
        }

        pub fn account_balance(mut self, amount: Balance) -> Self {
            self.context.account_balance = amount;
            self
        }

        pub fn account_locked_balance(mut self, amount: Balance) -> Self {
            self.context.account_locked_balance = amount;
            self
        }

        pub fn signer_account_pk(mut self, pk: PublicKey) -> Self {
            self.context.signer_account_pk = pk;
            self
        }

        pub fn finish(self) -> VMContext {
            self.context
        }
    }

Some VMContext attributes can cause confusion

  • input is a bit vague and some documentation on this attribute would be nice.
  • I'm assuming attached_deposit is the amount of NEAR that's being send with current TX,
    this might be confusing because a deposit sounds very specific, something like transaction_value (in Solidity it's just value) might make more sense.
  • signer_account_pk confused me because I thought it stood for private key. Maybe change it to something more similar to signer_account_pub_key.

Investigate qimalloc as a replacement for wee_alloc

Currently we are using wee_alloc for Rust contracts and contracts used in benchmarking. https://github.com/wasmx/qimalloc is used by EWASM and might be potentially faster than the default wee_alloc, since qimalloc optimizes for speed and wee_alloc optimizes for code size. qimalloc however gives only 2-3kb overhead compared to wee_alloc, and in our case using qimalloc might increase the TPS which is more important.

A convenience wrapper for events

As discussed with @k06a the way the smart contract are going to be storing events is by pushing elements into a std::vec::Vec stored in a single key-value for each smart contract. Occasionally, the elements in this vector are going to be cleared out, e.g. based on whether the contract is executed in the new block.

Rust API guidebook

We need to combine documentation from https://github.com/nearprotocol/workshop and https://github.com/nearprotocol/near-bindgen/tree/master/examples/cross-contract-high-level into a single comprehensive Rust book similar to https://bheisler.github.io/criterion.rs/book/getting_started.html or http://serde.rs/ . That contains both tutorials, walkthroughs, exhaustive API documentation, also various guides on: how to write small contracts, fast contracts, JSON/Borsh interfacing contracts, non-abusable financial contracts, common mistakes/what to look for guide, similar to this section in RustWasm book: https://rustwasm.github.io/book/reference/index.html

This book needs to stay up to date so we need to figure out the process of how we do that.

Also assigning to @janedegtiareva since she has been working on Rust examples for contracts. Making it an Epic and @amgando to create subtasks as github issues for this Epic.

Support "#[self_call]" for calls

It should check whether the current account equals to the predecessor account.

    assert_eq!(env::current_account_id(), env::predecessor_account_id());

Most of the time when you implement a callback function, you have to lock it for calls from the contract itself. This method assert check is very common and probably should be supported by the SDK

build.sh always takes the same amount of time to run, even after multiple runs on the same code

If we start from a clean state in example (e.g. by removing res/*), do a build, and then build again
with no code changes, the 2nd build takes the same time as the first. This is not a great dev experience since the devs do not enjoy waiting for builds (especially when it's redundant).

To repro: (observe that both builds take the same time)

(examples/status-message)
rm res/*
./build.sh
Compiling proc-macro2 v1.0.6
Compiling unicode-xid v0.2.0
Compiling syn v1.0.5
Compiling memchr v2.2.1
Compiling serde v1.0.101
Compiling lazy_static v1.4.0
Compiling regex-syntax v0.6.12
Compiling byteorder v1.3.2
Compiling ryu v1.0.2
Compiling wee_alloc v0.4.5
Compiling near-vm-errors v0.4.3
Compiling bs58 v0.3.0
Compiling cfg-if v0.1.10
Compiling memory_units v0.4.0
Compiling itoa v0.4.4
Compiling thread_local v0.3.6
Compiling aho-corasick v0.7.6
Compiling quote v1.0.2
Compiling regex v1.3.1
Compiling Inflector v0.11.4
Compiling borsh-derive-internal v0.2.10
Compiling near-bindgen-core v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-core)
Compiling near-bindgen-promise v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-promise)
Compiling serde_derive v1.0.101
Compiling borsh-derive v0.2.10
Compiling near-bindgen-macros v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-macros)
Compiling borsh v0.2.10
Compiling near-runtime-fees v0.4.3
Compiling serde_json v1.0.40 (https://github.com/nearprotocol/json?rev=1f5779f3b0bd3d2a4b0b975abc46f3d3fe873331#1f5779f3)
Compiling near-vm-logic v0.4.3
Compiling near-bindgen v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen)
Compiling status-message v0.1.0 (/Users/evgueniadegtiareva/near/near-bindgen/examples/status-message)
Finished release [optimized] target(s) in 44.51s

./build.sh
Compiling proc-macro2 v1.0.6
Compiling unicode-xid v0.2.0
Compiling syn v1.0.5
Compiling memchr v2.2.1
Compiling lazy_static v1.4.0
Compiling serde v1.0.101
Compiling regex-syntax v0.6.12
Compiling byteorder v1.3.2
Compiling ryu v1.0.2
Compiling near-vm-errors v0.4.3
Compiling wee_alloc v0.4.5
Compiling bs58 v0.3.0
Compiling cfg-if v0.1.10
Compiling itoa v0.4.4
Compiling memory_units v0.4.0
Compiling thread_local v0.3.6
Compiling aho-corasick v0.7.6
Compiling quote v1.0.2
Compiling regex v1.3.1
Compiling Inflector v0.11.4
Compiling borsh-derive-internal v0.2.10
Compiling near-bindgen-promise v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-promise)
Compiling near-bindgen-core v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-core)
Compiling serde_derive v1.0.101
Compiling borsh-derive v0.2.10
Compiling near-bindgen-macros v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen-macros)
Compiling borsh v0.2.10
Compiling near-runtime-fees v0.4.3
Compiling serde_json v1.0.40 (https://github.com/nearprotocol/json?rev=1f5779f3b0bd3d2a4b0b975abc46f3d3fe873331#1f5779f3)
Compiling near-vm-logic v0.4.3
Compiling near-bindgen v0.3.10 (/Users/evgueniadegtiareva/near/near-bindgen/near-bindgen)
Compiling status-message v0.1.0 (/Users/evgueniadegtiareva/near/near-bindgen/examples/status-message)
Finished release [optimized] target(s) in 44.81s

Flexible contract method signatures

Currently, we only allow non-static public methods that use &self or &mut self, and accept arguments by value oppose to by the reference. Most of these limitations can be lifted by extending near_bindgen.

Postponed execution through events

As part of adding higher-level building blocks on the top of near-bindgen we can consider the following form of postponed function execution implemented through events.

Consider the contact that allows tracking some external chain by accepting transactions. This contract also allows other Near contracts to verify whether some transaction in the given block.

 struct Rollups 

 { transactions: HashMap<BlockHeight, Vec<Transaction>>, } 

impl Rollups {
 pub fn contains_transaction(&self, block_height: BlockHeight, hash: Vec<u8>) -> bool 

 { self.transactions[block_height].iter().any(|t| t.hash == hash) } 

 pub fn add_block(&mut self, block_height: BlockHeight, block: Vec<Transaction>) 

 { self.transactins.insert(block_height, block); } 

}

Unfortunately, if Alice calls Rollups::contains_transaction with block_height that was not submitted yet by a relayer we cannot verify whether the transaction made it to the block.

To improve DevX we can add the following Event helper.

struct Rollups 

{ transactions: HashMap<BlockHeight, Vec<Transaction>>, block_added_event: Event<BlockHeight>, } 

impl Rollups {
pub fn contains_transaction(&mut self, block_height: BlockHeight, hash: Vec<u8>, callback_method: Option<Vec<u8>>) -> Some<bool> {
let prepaid_gas = env::prepaid_gas();
if let Some(block) = self.transactions.get(block_height) 

{ Some(block.iter().any(|t| t.hash == hash)) } 

else if Some(callback_method) = callback_method {
let predecessor = env::predecessor_account_id();
self.block_added_event
.when(move |height| height == block_height)
.execute(move |this: &Self| {
let result = this.contains_transaction(block_height, hash, callback_method);
env::promise_create(predecessor, &callback_method,
json!(

{ "result": result } 

).to_string().as_bytes(),
0,
1_000_000,
);
});
None
}
}

pub fn add_block(&mut self, block_height: BlockHeight, block: Vec<Transaction>) 

{ self.block_added_event.register(block_height); self.transactins.insert(block_height, block); }

}

A more black-box version of the API can be the following:

struct Rollups { transactions: HashMap<BlockHeight, Vec<Transaction>>, block_added_event: Event<BlockHeight>, }

impl Rollups {

#<span class="error">[postpone_with_callback(postpone_when={!this.transactions.contains(block_height)}, wakeup_when={this.block_added_event.when(move |height| height == block_height)}]</span>

pub fn contains_transaction(&mut self, block_height: BlockHeight, hash: Vec<u8>) -> bool { self.transactions[block_height].iter().any(|t| t.hash == hash)) }

pub fn add_block(&mut self, block_height: BlockHeight, block: Vec<Transaction>) { self.block_added_event.register(block_height); self.transactins.insert(block_height, block); } 

}

./build.sh produces non optimized output which is too large to deploy, if copied

starting in examples/status-message:

modify Cargo.toml to have near-bindgen = "0.3.10"

after that:

rm res/*
cd ../../..
mkdir repro
cd repro
cp -r ../near-bindgen/examples/status-message/* .
rustup override set stable
rustup target add wasm32-unknown-unknown
./build.sh

when that finishes:
ls -lh res
-rwxr-xr-x 1 evgueniadegtiareva staff 1.8M Jan 23 14:56 status_message.wasm

1.8M is too large to deploy

Race conditions in tests

Finished dev [unoptimized + debuginfo] target(s) in 0.04s
 Running target/debug/deps/status_message-46714b88b66f7ea3

running 2 tests
test tests::set_get_message ... FAILED
test tests::get_nonexistent_message ... FAILED

failures:

---- tests::set_get_message stdout ----
thread 'tests::set_get_message' panicked at 'Register was expected to have data because we just wrote it into it.', src/libcore/option.rs:1166:5

---- tests::get_nonexistent_message stdout ----
thread 'tests::get_nonexistent_message' panicked at 'already borrowed: BorrowMutError', src/libcore/result.rs:1084:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

failures:
tests::get_nonexistent_message
tests::set_get_message

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

Finished dev [unoptimized + debuginfo] target(s) in 0.04s
 Running target/debug/deps/status_message-46714b88b66f7ea3

running 2 tests
test tests::get_nonexistent_message ... ok
test tests::set_get_message ... FAILED

failures:

---- tests::set_get_message stdout ----
thread 'tests::set_get_message' panicked at 'already borrowed: BorrowMutError', src/libcore/result.rs:1084:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

Possible callback function addition on deposit.

In Solidity a developer has the option to add a callback function to their code, what this would allow for would be the following:

 contract MyContract {
 deposit(address _from, int256 _amount ) public 

 {...} 

 // Handles deposits

 // Callback on transfer to MyContract
 function () payable 

 { // Do something here, for example: revert(); // return users money because this contract should not take any deposits without calling the deposit method } 

}

You could instead of just reverting the transaction also treat the transfers as deposits:

function () payable 

{ // Or what you could do is: deposit(msg.sender, msg.value); // Deposits the funds to the contract but also make sure to keep track of it using the deposit method } 

Taking this last example, if we have alice and a contract called bobs_contract instead of having to call the deposit method on bobs_contract(which is impossible with near-wallet/lib right now which is why I came up with this workaround for reference: [this issue](near/near-wallet#56)) alice can just transfer n amount of tokens to bobs_contract, and have it be treated as calling the deposit method.

Consider implementing our own Json serializer

There are several issues with the serde_json:

  • We had to fork it to make sure it does not produce float instructions, see: serde-rs/json#567 and https://github.com/nearprotocol/json
  • When trying to serialize an object not supported by json (e.g. a HashMap with has keys that are not primitive types) we are getting a runtime error instead of a compile-time error, because of serde framework restrictions. This leads to a lot of confusion and bad DevX as reported by users;
  • In addition to a large code foot print of serde_json it needs serde itself which is also a large piece of code. It would be nice if contract developers could use a small and simple library that they could trust because they could easily read through.
  • Serde_json has performance optimizations that might not make sense on Wasm.

build.sh in fun_token example produces a build error

./build.sh
error[E0658]: use of unstable library feature 'alloc': this library is unlikely to be stabilized in its current form or name (see issue #27783)
--> /Users/evgueniadegtiareva/.cargo/registry/src/github.com-1ecc6299db9ec823/bs58-0.3.0/src/lib.rs:76:1
|
76 | extern crate alloc;
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Support `Instant:now()`

Instant::now() should be taking the time from the corresponding block that every validator agrees on, oppose the returning the actual current time at which the contract is executed.

Troubles building with near_bindgen in macro

I tried to declare etherem_types wrappers to implement missing traits:

macro_rules! arr_declare_wrapper_and_serde {
    ($name: ident, $len: expr) => {
        #[near_bindgen]
        #[derive(Default, Clone, Copy, PartialEq, Debug, Display, From, Into)]
        pub struct $name(pub ethereum_types::$name);

        // ...
    }
}

arr_declare_wrapper_and_serde!(H64, 8);
arr_declare_wrapper_and_serde!(H128, 16);
arr_declare_wrapper_and_serde!(H160, 20);
arr_declare_wrapper_and_serde!(H256, 32);
arr_declare_wrapper_and_serde!(H512, 64);
arr_declare_wrapper_and_serde!(H520, 65);
arr_declare_wrapper_and_serde!(Bloom, 256);
error[E0428]: the name `sys` is defined multiple times
   --> src/types.rs:15:9
    |
15  |         #[near_bindgen]
    |         ^^^^^^^^^^^^^^^
    |         |
    |         `sys` redefined here
    |         previous definition of the module `sys` here
...
109 | arr_declare_wrapper_and_serde!(H64, 8);
    | --------------------------------------- in this macro invocation
    |
    = note: `sys` must be defined only once in the type namespace of this module
error[E0428]: the name `near_blockchain` is defined multiple times
   --> src/types.rs:15:9
    |
15  |         #[near_bindgen]
    |         ^^^^^^^^^^^^^^^
    |         |
    |         `near_blockchain` redefined here
    |         previous definition of the module `near_blockchain` here
...
109 | arr_declare_wrapper_and_serde!(H64, 8);
    | --------------------------------------- in this macro invocation
    |
    = note: `near_blockchain` must be defined only once in the type namespace of this module

Run CI for stable and nightly

Unfortunately stable and nightly produce different compiler errors which makes near-bindgen/compilation_tests fail because they verify that our custom compilation error messages are correct. We should surround compilation tests that check for an error with an optional compilation feature and only use that feature when we are running compilation tests on stable.

Expose keccak native function

We need to expose keccak host functions in near-bindgen so that near-bridge can start using it. This will require the following:

  • Merging near/nearcore#2045 into staging;
  • Building new version of near-vm-logic from the staging code, which requires bumping its version which is done through a PR;
  • Merging #69 and bumping the version of near-bindgen;

Error on call/{accountId}/get_status in status-message example

This is the error that is returned to javascript library.
Uncaught (in promise) Error: Querying call/jane0117/get_status failed: wasm execution failed with error: FunctionCallError(WasmTrap("unknown")).
{
"block_height": 245191,
"error": "wasm execution failed with error: FunctionCallError(WasmTrap("unknown"))",
"logs": []
}
at JsonRpcProvider.query (nearlib.js:793)
at async Account.viewFunction (nearlib.js:152)

To reproduce

  • clone [email protected]:nearprotocol/create-near-app.git
  • cd blank_rust_project
  • copy .wasm file into contract/res (I attached a most recent .wasm file that you get from running .build.sh in status-message)
  • from blank_rust_project, run yarn start
  • navigate to http://localhost:4000/ - the app makes the rpc call automatically and you can see the results in chrome dev tools.

Support file system

We should allow the smart contracts read and write from the "filesystem", where filesystem will be basically emulated on the top of the Trie.

cross-contract high level example doesn't work

When following the cross contract high level example readme, at this step

near call cross_contract simple_call "{\"account_id\": \"status_message\", \"message\":\"bonjour\"}" --accountId=test_near --gas 1000000000000000

the call failed because it exceeds the prepaid gas, but I already give the maximum prepaid gas here (10^16).

Examples do not build when copied outside the repo

Issue
When I clone the entire near-bindgen repo and enter examples/fun-token and run ./build.sh it builds correctly.
But I ran into issues when I try to copy that particular example to a separate folder.

Motivation
I would like users new to NEAR to be able to download small, individual examples of Rust smart contracts and have them build as expected. I do not want them to have to clone the near-bindgen repo and build the examples from there.

Steps to reproduce:
Copy examples/fun-token into somewhere locally ~/tmp/ or something.
Swap out this line:
https://github.com/nearprotocol/near-bindgen/blob/master/examples/fun-token/Cargo.toml#L13
with:
near-bindgen = "0.4.1" (which is the same version)
Go to ~/tmp/fun-token and run ./build
It will throw errors relating to panic() wanting bytes.

Example README not working: cross-contract high level

Tried following the README for https://github.com/nearprotocol/near-bindgen/tree/master/examples/cross-contract-high-level

A few things went wrong. One of them seems to be this:

near create_account cross_contract --masterAccount=test_near --initialBalance 10000000

It seems that the initialBalance flag now refers to NEAR tokens, not yoctoNEAR.

Replacing 10000000 with 1 succeeded.

The next line also has issues:

near deploy --accountId=cross_contract --wasmFile=../examples/cross-contract-high-level/res/cross_contract_high_level.wasm

it should be --wasmFile=./res/cross_contract_high_level.wasm instead.

Then the next line also doesn't work:

near call cross_contract deploy_status_message "{\"account_id\": \"status_message\", \"amount\":1000000000000000}" --accountId=test_near

I replaced 1000000000000000 with 1, and also the accountId and cross_contract with my respective accounts. After that I am getting:

link error: data segment does not fit

near call nfcc001 deploy_status_message "{\"account_id\": \"status_message\", \"amount\":1}" --accountId=near-friend
configPath:  /Users/mike/near/near-bindgen/examples/cross-contract-high-level/src/config
[WARNING] Didn't find config at /Users/mike/near/near-bindgen/examples/cross-contract-high-level/src/config, using default shell config
{ networkId: 'default',
  nodeUrl: 'https://rpc.nearprotocol.com',
  contractName: 'near-hello-devnet',
  walletUrl: 'https://wallet.nearprotocol.com' }
(node:21188) ExperimentalWarning: The fs.promises API is experimental
Scheduling a call: nfcc001.deploy_status_message({"account_id": "status_message", "amount":1})
aloha: signAndSendTransaction in account.js
Error:  { Error: Transaction 3F3k41ZVzMvxMbM598vEAwnLtwrhZEiJ6FLJCn6MpkWa failed. link error: data segment does not fit
    at Account.signAndSendTransaction (/Users/mike/.nvm/versions/node/v10.16.0/lib/node_modules/near-shell/node_modules/nearlib/lib/account.js:85:23)
    at process._tickCallback (internal/process/next_tick.js:68:7) type: 'ActionError::FunctionCallError' }

^ That's hard to read so here's a screenshot with colors:

Screenshot 2020-02-24 16 23 59

Master branch contracts miss batch imports

Having deployed status-message contract on the production testnet, I am getting the following errors when call methods:

wasm execution failed with error: WasmerInstantiateError(\"11 link errors: (1 of 11) Import not found, namespace: env, name: promise_batch_create (2 of 11) Import not found, namespace: env, name: promise_batch_then (3 of 11) Import not found, namespace: env, name: promise_batch_action_create_account (4 of 11) Import not found, namespace: env, name: promise_batch_action_deploy_contract (5 of 11) Import not found, namespace: env, name: promise_batch_action_function_call (6 of 11) Import not found, namespace: env, name: promise_batch_action_transfer (7 of 11) Import not found, namespace: env, name: promise_batch_action_stake (8 of 11) Import not found, namespace: env, name: promise_batch_action_add_key_with_full_access (9 of 11) Import not found, namespace: env, name: promise_batch_action_add_key_with_function_call (10 of 11) Import not found, namespace: env, name: promise_batch_action_delete_key (11 of 11) Import not found, namespace: env, name: promise_batch_action_delete_account\")

It might be just a version inconsistency with the master testnet. Reverting to the v0.2.3 resolved the issue.

Passing empty method_names in add_access_key fails

When creating promise with adding access key, there is no way to allow for no method name restriction.
Passing empty bytes doesn't work, results in EmptyMethodName error.

Repro:

        Promise::new(env::current_account_id()).add_access_key(
            pk,
            ACCESS_KEY_ALLOWANCE,
            env::current_account_id(),
            vec![]
        );

Doc strings are lacking in promise.rs

There are no explanation for the arguments and their types in promise.rs for all the methods.

For example add_access_key takes method_names as Vec<u8> but examples are presented as strings. Also doesn't cover the case of empty string for allowing all methods to be called.

Having doc strings with per-argument types and explanations of arguments would be great for developers to understand.

`ext_contract` doesn't use types

I have the following code:

type AppId = String;
type Message = String;

#[ext_contract(remote)]
pub trait RemoteSelf {
    fn post_message(&mut self, app_id: AppId, message: Message);
}

The compiler complains about types:

error[E0412]: cannot find type `AppId` in this scope
  --> src/lib.rs:67:40
   |
67 |     fn post_message(&mut self, app_id: AppId, message: Message);
   |                                        ^^^^^ not found in this scope

error[E0412]: cannot find type `Message` in this scope
  --> src/lib.rs:67:56
   |
67 |     fn post_message(&mut self, app_id: AppId, message: Message);
   |                                                        ^^^^^^^ not found in this scope

error: aborting due to 2 previous errors

It looks like types can't be used with the traits anymore (post 0.4 upgrade)

build issues in examples

from examples/status_message

command ran: RUSTFLAGS='-C link-arg=-s' cargo +nightly build --target wasm32-unknown-unknown --release

output:
Compiling bs58 v0.3.0
Compiling near-vm-errors v0.4.3
Compiling cfg-if v0.1.10
Compiling memory_units v0.4.0
Compiling itoa v0.4.4
Compiling byteorder v1.3.2
Compiling ryu v1.0.2
Compiling serde_derive v1.0.101
error[E0463]: can't find crate for core

= note: the wasm32-unknown-unknown target may not be installed

Additional notes: I've updated rust and ran
rustup override set nightly from status_message dir

End user confusion copying examples elsewhere

Problem:
As a user I don't fully understand how to write smart contracts in Rust. So I clone this repo and build the examples and am happy with them. I want to copy one of the example folders out of the cloned repo and into my Documents folder. I plan to modify the example and use it as a base. When I try โ€ฆ cargo build I get an error and am confused.

Reason:
The Cargo.toml file uses relative paths for the near-bindgen dependency.
near-bindgen = { path = "../../near-bindgen"}

Solution:
Change examples to use a version instead.
Example:
near-bindgen = "^0.4"

Possible Downside:
This may be another thing for near-bindgen core developers to remember.

Contract code size optimization

Current contract code size is on the order of 100-200Kb because of its usage of bincode and serde_json. We can allow avoiding bincode if the smart contract uses nothing but near::collections, see #2 . However serder_json is useful for making method signatures compatible across different types of contracts, e.g. TypeScript contracts. We can write a light-weight minimal version of serde_json that would not take so much space and use it for simple arguments that do not use user-defined types. Then if the contract does not return/accept user-defined types and uses near::collections for its internal state its size should be on the order of 10-40Kb.

Status-message project test failed from clean state

$ RUST_BACKTRACE=1 cargo test --package status-message --features env_test
Compiling libc v0.2.60
   Compiling crc32fast v1.2.0
   Compiling proc-macro2 v0.4.30
   Compiling cfg-if v0.1.9
   Compiling unicode-xid v0.1.0
   Compiling rle-decode-fast v1.0.1
   Compiling take_mut v0.2.2
   Compiling adler32 v1.0.3
   Compiling syn v0.15.39
   Compiling cc v1.0.41
   Compiling pkg-config v0.3.15
   Compiling serde v1.0.97
   Compiling ryu v1.0.0
   Compiling wee_alloc v0.4.5
   Compiling bs58 v0.2.4
   Compiling itoa v0.4.4
   Compiling memory_units v0.4.0
   Compiling lazy_static v1.4.0
   Compiling libflate v0.1.27
   Compiling filetime v0.2.7
   Compiling xattr v0.2.2
   Compiling quote v0.6.13
   Compiling tar v0.4.26
   Compiling libsodium-sys v0.2.2
   Compiling borsh-derive-internal v0.2.1
   Compiling near-bindgen-core v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen-core)
   Compiling serde_derive v1.0.97
   Compiling borsh-derive v0.2.1
   Compiling near-bindgen-macros v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen-macros)
   Compiling borsh v0.2.1
   Compiling near-runtime-fees v0.2.1
   Compiling serde_json v1.0.40
   Compiling sodiumoxide v0.2.2
   Compiling near-vm-logic v0.2.3
   Compiling near-bindgen v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen)
   Compiling status-message v0.1.0 (/Users/k06a/Projects/near-bindgen/examples/status-message)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 12s
     Running target/debug/deps/status_message-46bd16e624805d89

running 2 tests
test tests::get_nonexistent_message ... ok
test tests::set_get_message ... FAILED

failures:

---- tests::set_get_message stdout ----
thread 'tests::set_get_message' panicked at 'Register was expected to have data because we just wrote it into it.', src/libcore/option.rs:1190:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /Users/vsts/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /Users/vsts/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:61
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:45
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/io/mod.rs:1412
   6: std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt
             at src/libstd/io/impls.rs:141
   7: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:48
   8: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:33
   9: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
  10: std::panicking::default_hook
             at src/libstd/panicking.rs:211
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
  12: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:384
  13: rust_begin_unwind
             at src/libstd/panicking.rs:311
  14: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  15: core::option::expect_failed
             at src/libcore/option.rs:1190
  16: core::option::Option<T>::expect
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libcore/option.rs:345
  17: near_bindgen::environment::env::signer_account_id
             at /Users/k06a/Projects/near-bindgen/near-bindgen/src/environment/env.rs:95
  18: status_message::StatusMessage::set_status
             at src/lib.rs:18
  19: status_message::tests::set_get_message
             at src/lib.rs:58
  20: status_message::tests::set_get_message::{{closure}}
             at src/lib.rs:53
  21: core::ops::function::FnOnce::call_once
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libcore/ops/function.rs:227
  22: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/liballoc/boxed.rs:922
  23: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:80
  24: std::panicking::try
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panicking.rs:275
  25: std::panic::catch_unwind
             at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panic.rs:394
  26: test::run_test::run_test_inner::{{closure}}
             at src/libtest/lib.rs:1413
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    tests::set_get_message

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '-p status-message --lib'
$ RUST_BACKTRACE=full cargo test --package status-message --features env_test
   Compiling libc v0.2.60
   Compiling proc-macro2 v0.4.30
   Compiling crc32fast v1.2.0
   Compiling unicode-xid v0.1.0
   Compiling cfg-if v0.1.9
   Compiling adler32 v1.0.3
   Compiling take_mut v0.2.2
   Compiling rle-decode-fast v1.0.1
   Compiling syn v0.15.39
   Compiling cc v1.0.41
   Compiling pkg-config v0.3.15
   Compiling serde v1.0.97
   Compiling ryu v1.0.0
   Compiling wee_alloc v0.4.5
   Compiling bs58 v0.2.4
   Compiling memory_units v0.4.0
   Compiling itoa v0.4.4
   Compiling lazy_static v1.4.0
   Compiling libflate v0.1.27
   Compiling quote v0.6.13
   Compiling filetime v0.2.7
   Compiling xattr v0.2.2
   Compiling tar v0.4.26
   Compiling libsodium-sys v0.2.2
   Compiling borsh-derive-internal v0.2.1
   Compiling near-bindgen-core v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen-core)
   Compiling serde_derive v1.0.97
   Compiling borsh-derive v0.2.1
   Compiling near-bindgen-macros v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen-macros)
   Compiling borsh v0.2.1
   Compiling near-runtime-fees v0.2.1
   Compiling serde_json v1.0.40
   Compiling sodiumoxide v0.2.2
   Compiling near-vm-logic v0.2.3
   Compiling near-bindgen v0.2.2 (/Users/k06a/Projects/near-bindgen/near-bindgen)
   Compiling status-message v0.1.0 (/Users/k06a/Projects/near-bindgen/examples/status-message)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 22s
     Running target/debug/deps/status_message-46bd16e624805d89

running 2 tests
test tests::get_nonexistent_message ... ok
test tests::set_get_message ... FAILED

failures:

---- tests::set_get_message stdout ----
thread 'tests::set_get_message' panicked at 'Register was expected to have data because we just wrote it into it.', src/libcore/option.rs:1190:5
stack backtrace:
   0:        0x100ab04fc - backtrace::backtrace::libunwind::trace::ha541e1bc74dbe7dc
                               at /Users/vsts/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1:        0x100ab04fc - backtrace::backtrace::trace_unsynchronized::h8371015938fcff89
                               at /Users/vsts/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2:        0x100ab04fc - std::sys_common::backtrace::_print_fmt::h4a16805c95a7dd53
                               at src/libstd/sys_common/backtrace.rs:61
   3:        0x100ab04fc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3e21874e6a894a83
                               at src/libstd/sys_common/backtrace.rs:45
   4:        0x100aca580 - core::fmt::write::h86e4be7336e0b09c
                               at src/libcore/fmt/mod.rs:1030
   5:        0x100a02aa9 - std::io::Write::write_fmt::h060fc01673d15a33
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/io/mod.rs:1412
   6:        0x100aabf1c - std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt::he1e3aedce15eeb66
                               at src/libstd/io/impls.rs:141
   7:        0x100ab20dd - std::sys_common::backtrace::_print::h84a78bc34f92dda2
                               at src/libstd/sys_common/backtrace.rs:48
   8:        0x100ab20dd - std::sys_common::backtrace::print::hc4c7ed85ff8cea8b
                               at src/libstd/sys_common/backtrace.rs:33
   9:        0x100ab20dd - std::panicking::default_hook::{{closure}}::hf5beb31afcd84982
                               at src/libstd/panicking.rs:200
  10:        0x100ab1d83 - std::panicking::default_hook::h0f94b02abe85cace
                               at src/libstd/panicking.rs:211
  11:        0x100ab2827 - std::panicking::rust_panic_with_hook::h8bc7d846a0025752
                               at src/libstd/panicking.rs:477
  12:        0x100ab236d - std::panicking::continue_panic_fmt::h67171a0a732f962e
                               at src/libstd/panicking.rs:384
  13:        0x100ab2269 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
  14:        0x100ac7a0f - core::panicking::panic_fmt::h4329b659c9b85d91
                               at src/libcore/panicking.rs:85
  15:        0x100ac7a6e - core::option::expect_failed::hc190722a05bb9353
                               at src/libcore/option.rs:1190
  16:        0x100a400fe - core::option::Option<T>::expect::h85ad914131b99b86
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libcore/option.rs:345
  17:        0x100a428a0 - near_bindgen::environment::env::signer_account_id::h5ccc2bddb2c39c4b
                               at /Users/k06a/Projects/near-bindgen/near-bindgen/src/environment/env.rs:95
  18:        0x1009f74e7 - status_message::StatusMessage::set_status::hcf6fe63f4b936f76
                               at src/lib.rs:18
  19:        0x1009fa633 - status_message::tests::set_get_message::h3ccc1276836f4c58
                               at src/lib.rs:58
  20:        0x1009f92c1 - status_message::tests::set_get_message::{{closure}}::h83bdf38ac36c8be0
                               at src/lib.rs:53
  21:        0x1009f6591 - core::ops::function::FnOnce::call_once::h148c6ca996b57518
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libcore/ops/function.rs:227
  22:        0x100a0cc1e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hca3424fa963c6b76
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/liballoc/boxed.rs:922
  23:        0x100ab46ef - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  24:        0x100a266f7 - std::panicking::try::hf6110f214442151f
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panicking.rs:275
  25:        0x100a266f7 - std::panic::catch_unwind::he1ffea0554aff702
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panic.rs:394
  26:        0x100a266f7 - test::run_test::run_test_inner::{{closure}}::h1c9613202a5ed23d
                               at src/libtest/lib.rs:1413
  27:        0x100a02255 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb580b1ea0df1c794
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/sys_common/backtrace.rs:114
  28:        0x100a06405 - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::hb85199980dd23ae2
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/thread/mod.rs:470
  29:        0x100a06405 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hc78f38a3e45e9d73
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panic.rs:315
  30:        0x100a06405 - std::panicking::try::do_call::h50049a1b2ffba3b0
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panicking.rs:296
  31:        0x100ab46ef - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  32:        0x100a06985 - std::panicking::try::hdac98c59c865b667
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panicking.rs:275
  33:        0x100a06985 - std::panic::catch_unwind::h33dc58b4a519af4e
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/panic.rs:394
  34:        0x100a06985 - std::thread::Builder::spawn_unchecked::{{closure}}::h262bee4387cebc9d
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libstd/thread/mod.rs:469
  35:        0x100a06985 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h09ebf5fee9cc9a4c
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/libcore/ops/function.rs:227
  36:        0x100aa8b9e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h261f9f17a8661ad4
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/liballoc/boxed.rs:922
  37:        0x100ab410e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::haf9b1b18aaaab823
                               at /rustc/2b8116dced2c6c5d02e1c4359e89dc0919d6001b/src/liballoc/boxed.rs:922
  38:        0x100ab410e - std::sys_common::thread::start_thread::hbba75d4e459ee59a
                               at src/libstd/sys_common/thread.rs:13
  39:        0x100ab410e - std::sys::unix::thread::Thread::new::thread_start::h0c2494b2cab31647
                               at src/libstd/sys/unix/thread.rs:79
  40:     0x7fff66e2d2eb - <unknown>
  41:     0x7fff66e30249 - <unknown>


failures:
    tests::set_get_message

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '-p status-message --lib'

Export basic types directly instead of vm-logic

Currently basic types like BlocmHeight used inside Bindgen but also client contracts need also import them from near-vm-logic
It's very confusing and adds extra dependency that can be misaligned (like right now with crate.io having 0.4.4 whereas Bindgen depended on 0.4.3).

Ideally Bindgen should just export these types itself and client contracts don't need to depend directly on near-vm-logic.

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.