odradev / odra Goto Github PK
View Code? Open in Web Editor NEWOdra framework
License: MIT License
Odra framework
License: MIT License
While running examples tests for the Casper backend we get the following warning:
warning: variable does not need to be mutable
--> src/party_contract_wasm.rs:1:1784
|
1 | ...pes :: Address :: from (contract_package_hash) ; let mut contract_ref = odra_examples :: docs :: events :: PartyContractRef :: at (odr...
| ----^^^^^^^^^^^^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` on by default
It's required so I can use the contract defined in one file in tests in another file.
Task from the community:
Improve the discoverability of odra.dev/docs. There is no link to it. Add it to crates.io and GH.
There is support for native transfer between contract purse and user account, but what about transfer between accounts?
It should be fairly easy to implement... maybe something like below?
/// Transfers native token between accounts.
pub fn transfer_tokens_accounts<B: Into<Balance>>(from: Account, to: Address, amount: B) {
let main_purse = from.main_purse();
match to {
Address::Account(account) => {
transfer_from_purse_to_account(main_purse, account, amount.into().inner(), None)
.unwrap_or_revert();
}
Address::Contract(_) => revert(ExecutionError::can_not_transfer_to_contract())
};
}
Running getter functions should not deduct gas, so in Casper all getters should be run as a special system account.
Currently every time CSPR is passed to the contract new purse is created. It should be just one both for users and contracts.
odra-modules
.examples
.Missmatch of types in call_contract
method in Odra and Odra Casper. #[no_mangle] call_contract
in Odra Casper returns Bytes
instead of Option<Bytes>
.
Creating addresses in the test environment causes errors when switching between backends:
error[E0599]: no variant or associated item named `new` found for enum `odra::types::Address` in the current scope
--> src/erc721token.rs:99:47
|
99 | assert_eq!(erc721.balance_of(Address::new(b"Krzysztof")), U256::from(0));
| ^^^ variant or associated item not found in `Address`
odra/mock-vm/types/src/address.rs
Line 17 in c5ad96b
We are not testing the serialization of OdraTypes that contain other OdraTypes.
Because of that, we couldn't find the error in events validation.
For example, our tests don't cover the case when we have:
#[derive(OdraType)]
pub enum Status {
Created,
Cancelled,
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct StatusUpdated {
id: U256,
caller: Address,
status: Status,
}
Before #160 trying to emit the above event would cause an error.
Handle native token:
#[odra(payable)]
to mark entrypoint that accept tokens. (also in #[odra::external_contract]
?).u512
, Ethereum u256
).In test script.
let one = TestEnv::one_token();
TestEnv::with_tokens(1000 * one);
TestEnv::set_caller(user1);
contract.deposit();
assert_eq!(
TestEnv::token_balance(user1),
TestEnv::token_balance(contract.address())
)
In contract.
#[odra(init)]
#[odra(payable)]
pub fn start() {
let caller = ContracEnv::caller();
let contract_balance = ContracEnv::self_balance();
let transfered_amount = ContracEnv::attached_value();
let threshold = ContractEnv::one_token() * 100;
if contract_balance > threshold {
ContractEnv::transfer_tokens(caller, transfered_amount);
} else {
ContracEnv::with_tokens(contract_balance);
AnotherContract::at(caller).do_something();
}
}
Build getter_proxy.wasm
in build.rs
. Now it is included in the repo.
Inside an implementation block, only public functions should be converted to entry points.
Currently, a module with a private function does not compile to a wasm.
All to emit events using values or references.
Transfer::emit(&from, to, amount);
Check if only one feature is enabled. Fail the compilation if two or more featues are on.
Developer should be able to advance a block time in tests.
When trying to compile odra
package, you will get the following error:
Compiling odra-casper-getter-proxy v0.0.1 (/home/andrew/odra/odra-casper/test-env/getter_proxy)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/tmp/rustclQxL1s/symbols.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.0.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.1.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.10.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.11.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.12.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.13.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.14.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.15.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.2.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.3.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.4.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.5.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.6.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.7.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.8.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.getter_proxy.f6e1e0f3-cgu.9.rcgu.o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8.1d9zw8iy926e73k2.rcgu.o" "-Wl,--as-needed" "-L" "/home/andrew/odra/target/release/deps" "-L" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/andrew/odra/target/release/deps/libcasper_contract-a95b0d6e81a41db0.rlib" "/home/andrew/odra/target/release/deps/libwee_alloc-a06de4120280c97e.rlib" "/home/andrew/odra/target/release/deps/libmemory_units-6656abfeb480cddf.rlib" "/home/andrew/odra/target/release/deps/libcfg_if-ecbcf349e8423669.rlib" "/home/andrew/odra/target/release/deps/libcasper_types-95132b89c34e11a3.rlib" "/home/andrew/odra/target/release/deps/libuint-74883f67654e4c52.rlib" "/home/andrew/odra/target/release/deps/libcrunchy-cf317d52fa140694.rlib" "/home/andrew/odra/target/release/deps/libstatic_assertions-6865a9c0238fb2ad.rlib" "/home/andrew/odra/target/release/deps/libhex-76aab1cd215b920d.rlib" "/home/andrew/odra/target/release/deps/libhumantime-bb5aee21ebbb5b1e.rlib" "/home/andrew/odra/target/release/deps/librand_pcg-fc39ba4b3d7c5323.rlib" "/home/andrew/odra/target/release/deps/libserde_bytes-e22198d1f1061f83.rlib" "/home/andrew/odra/target/release/deps/libnum-cc034b385428a2e6.rlib" "/home/andrew/odra/target/release/deps/libnum_iter-efdd5fbd851f2223.rlib" "/home/andrew/odra/target/release/deps/libnum_complex-98d222ea8e3a0bbe.rlib" "/home/andrew/odra/target/release/deps/libblake2-7d73119b1767c9eb.rlib" "/home/andrew/odra/target/release/deps/libcrypto_mac-8f82d15f952bd19e.rlib" "/home/andrew/odra/target/release/deps/libthiserror-3d6d2a62e0e70836.rlib" "/home/andrew/odra/target/release/deps/libpem-bef14d2a83a2f2df.rlib" "/home/andrew/odra/target/release/deps/libbase64-75d0c051f9b40bdc.rlib" "/home/andrew/odra/target/release/deps/libregex-cf3da6deed4099ce.rlib" "/home/andrew/odra/target/release/deps/libregex_syntax-69b6e404f2a56e01.rlib" "/home/andrew/odra/target/release/deps/libonce_cell-0000fd7492952165.rlib" "/home/andrew/odra/target/release/deps/libk256-3b15d33dec0fd27a.rlib" "/home/andrew/odra/target/release/deps/libecdsa-ea364ef27456f8c7.rlib" "/home/andrew/odra/target/release/deps/libhmac-3b7d63603c6c7a73.rlib" "/home/andrew/odra/target/release/deps/libcrypto_mac-943433caee5730d5.rlib" "/home/andrew/odra/target/release/deps/libelliptic_curve-ef4d2bc7695ff66c.rlib" "/home/andrew/odra/target/release/deps/libgroup-b72fd8a058273c8a.rlib" "/home/andrew/odra/target/release/deps/libff-00cf8988e534e230.rlib" "/home/andrew/odra/target/release/deps/libbitvec-3e37bafaf26b94af.rlib" "/home/andrew/odra/target/release/deps/libfunty-9c6d1b02265c609e.rlib" "/home/andrew/odra/target/release/deps/libwyz-428ca5da6955de22.rlib" "/home/andrew/odra/target/release/deps/libradium-49241c57fce3f2c8.rlib" "/home/andrew/odra/target/release/deps/libhex_fmt-b929b77d419d1353.rlib" "/home/andrew/odra/target/release/deps/libed25519_dalek-d37c57b55759ee0f.rlib" "/home/andrew/odra/target/release/deps/librand-d6dba378c420f049.rlib" "/home/andrew/odra/target/release/deps/librand_chacha-7b3aaf364d03b81a.rlib" "/home/andrew/odra/target/release/deps/libsha2-a517d9baa5d4b607.rlib" "/home/andrew/odra/target/release/deps/libcpufeatures-5457743d392ed47d.rlib" "/home/andrew/odra/target/release/deps/libopaque_debug-3fb8fe017ec60bdc.rlib" "/home/andrew/odra/target/release/deps/libblock_buffer-1ac3de526be38c06.rlib" "/home/andrew/odra/target/release/deps/libcurve25519_dalek-c747021f3c5a083a.rlib" "/home/andrew/odra/target/release/deps/libsubtle-8166433165b92368.rlib" "/home/andrew/odra/target/release/deps/libzeroize-8c8c5c985ac86dd1.rlib" "/home/andrew/odra/target/release/deps/libed25519-066ada2f994592a5.rlib" "/home/andrew/odra/target/release/deps/libsignature-18a242b465cdc678.rlib" "/home/andrew/odra/target/release/deps/librand_core-bcabcffc2ffd39e0.rlib" "/home/andrew/odra/target/release/deps/libdigest-9a3ce1ad55e242e9.rlib" "/home/andrew/odra/target/release/deps/libgeneric_array-55f20840facb9292.rlib" "/home/andrew/odra/target/release/deps/libtypenum-981f6d277a13ff38.rlib" "/home/andrew/odra/target/release/deps/libderp-1d3ba3d1042235a2.rlib" "/home/andrew/odra/target/release/deps/libuntrusted-57875a268874801f.rlib" "/home/andrew/odra/target/release/deps/libbase16-cd5df35c8306177e.rlib" "/home/andrew/odra/target/release/deps/libnum_rational-8b95cdc9ec8f0932.rlib" "/home/andrew/odra/target/release/deps/libnum_bigint-5bc2c5798a034594.rlib" "/home/andrew/odra/target/release/deps/libnum_integer-6f8f9d7dbfc7fec9.rlib" "/home/andrew/odra/target/release/deps/libnum_traits-f13d42c9c0d45c99.rlib" "/home/andrew/odra/target/release/deps/libproptest-50d056b87445eda7.rlib" "/home/andrew/odra/target/release/deps/libunarray-eb54b253ec900f6a.rlib" "/home/andrew/odra/target/release/deps/libregex_syntax-a805de93c7426a1c.rlib" "/home/andrew/odra/target/release/deps/librand_xorshift-54856d605889daac.rlib" "/home/andrew/odra/target/release/deps/libbyteorder-7a1f492a3baeb993.rlib" "/home/andrew/odra/target/release/deps/librusty_fork-34201ce6ccdf1101.rlib" "/home/andrew/odra/target/release/deps/libwait_timeout-09641e442475761b.rlib" "/home/andrew/odra/target/release/deps/libtempfile-3d682db075e1909b.rlib" "/home/andrew/odra/target/release/deps/libfastrand-0fa9be8bd8905774.rlib" "/home/andrew/odra/target/release/deps/librustix-fb8351aa409b14ff.rlib" "/home/andrew/odra/target/release/deps/libio_lifetimes-56f57638c0ec520a.rlib" "/home/andrew/odra/target/release/deps/liblinux_raw_sys-a881204dac685acc.rlib" "/home/andrew/odra/target/release/deps/libfnv-c08b9f2901610392.rlib" "/home/andrew/odra/target/release/deps/libquick_error-98db65e70a8e3b45.rlib" "/home/andrew/odra/target/release/deps/libquick_error-51f3795ad37a561a.rlib" "/home/andrew/odra/target/release/deps/liblazy_static-2929070d3a17e85e.rlib" "/home/andrew/odra/target/release/deps/libbit_set-001fb33890dfda78.rlib" "/home/andrew/odra/target/release/deps/libbit_vec-0ae786a164df9930.rlib" "/home/andrew/odra/target/release/deps/libschemars-fee96ad7cb7789c5.rlib" "/home/andrew/odra/target/release/deps/libdyn_clone-6b29cf1b0239c47f.rlib" "/home/andrew/odra/target/release/deps/libserde_json-5b2775873254586b.rlib" "/home/andrew/odra/target/release/deps/libryu-62c605e50a8ff5a3.rlib" "/home/andrew/odra/target/release/deps/libitoa-08f36c8eb07be97d.rlib" "/home/andrew/odra/target/release/deps/libindexmap-f602094bff2e39bd.rlib" "/home/andrew/odra/target/release/deps/libhashbrown-12a8798d571bb070.rlib" "/home/andrew/odra/target/release/deps/libserde-e36764dadd83ef7d.rlib" "/home/andrew/odra/target/release/deps/librand-c51611b4b08b7ae8.rlib" "/home/andrew/odra/target/release/deps/librand_chacha-a6faa6760513f303.rlib" "/home/andrew/odra/target/release/deps/libppv_lite86-38a921db44f81534.rlib" "/home/andrew/odra/target/release/deps/librand_core-91737849e85b9507.rlib" "/home/andrew/odra/target/release/deps/libgetrandom-820ed952c4a15a1a.rlib" "/home/andrew/odra/target/release/deps/liblibc-b405c989bed8e1a8.rlib" "/home/andrew/odra/target/release/deps/libcfg_if-af4ed11818f18246.rlib" "/home/andrew/odra/target/release/deps/libdatasize-7d54d4c7308182b4.rlib" "/home/andrew/odra/target/release/deps/libbitflags-ab97cbe7c4be6312.rlib" "-Wl,--start-group" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-91db243dd05c003b.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-72269a4525d4f5cf.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-28d8f1c01a28b12d.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-5b78018a9f8ae4bc.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-f4160de9657f17b2.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1cd8b958acdf2395.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a4c4a7e7edfa8aea.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-061c02acc74ada37.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-2aed706f056a5dfb.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1e1f90ff4bfdca6f.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-2d16c932daf0ad41.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8f15fae89f489a33.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-81f3d85dace75e64.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-e071db8735f10456.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-6db7e05a8de4df10.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-7c03f666869e802a.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2a6a2797f7a73818.rlib" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0e3656b1fda5fd7b.rlib" "-Wl,--end-group" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-b09abe545ed38eb1.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/andrew/.rustup/toolchains/nightly-2022-06-17-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/andrew/odra/target/release/deps/getter_proxy-fb99ec4730f8cfa8" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-nodefaultlibs"
= note: /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
error: could not compile `odra-casper-getter-proxy` due to previous error
That is because getter_proxy
should be build with wasm32-unknown-unknown
target, not the default one.
When calling a constructor, MockVM should return VmError(InvalidContext)
instead of VmError(NoSuchMethod(constructor_name))
.
Example test:
#[test]
fn second_initialization_fails() {
let (owner, ownable) = setup();
TestEnv::assert_exception(OdraError::VmError(VmError::InvalidContext), || {
ownable.init(owner);
});
}
I am unable to run the latest Odra 0.2.0, because of the following compilation errors:
error[E0277]: the trait bound `casper_hashing::Digest: ToBytes` is not satisfied
error[E0599]: no function or associated item named `from_bytes` found for struct `casper_hashing::Digest` in the current scope
Full build log (from clean state): log.txt.
Rust:
Toolchain (based on rust-toolchain
):
Add ERC1155 implementation to odra-modules.
Add use of it to examples.
When we instantiate a module in a no_mange function, the module is named contract
. It may lead to name shadowing.
From #151 (comment)
#[no_mangle]
fn transfer() {
let contract = Erc20::instance("contract");
let contract = odra::casper::casper_contract::contract_api::runtime::get_named_arg(stringify!(contract));
// Erc20 instance is shadowed
}
Solution proposal:
__contract
or alike.contract
Opt for the first solution.
It should be possible to have just one *_build.rs
file in builder that produces all the *_wasm.rs
files.
It could look like that:
odra::casper::codegen::gen_contract!([
(dao::voting_contracts::AdminContract, "admin_contract"),
(dao::voting_contracts::AdminContract, "admin_contract2")
]);
The test defined in the examples/src/docs/testing.rs
file fails due to this.
Currently, when trying to define the following error using execution_error! macro:
use odra::execution_error;
execution_error! {
NoSuchMethod(String) => 1101,
}
We get a compilation error:
error: expected `=>`
--> src/errors.rs:21:21
|
21 | NoSuchMethod(String) => 1101,
| ^
It would be lovely to support such errors in the future.
Allow for:
use odra::List;
#[odra::module]
pub struct Contract {
list: List<u8>
}
#[odra::module]
impl Contract {
pub fn add(&self, value: u8) {
self.list.append(value);
}
pub fn get(&self, index: u32) -> Option<u32> {
self.list.get(index)
}
}
It should be implemented using Mapping and indexed from 0.
Consider this implementation of getter max of U256 as U512:
U512::from(<casper_types::U256 as AsPrimitive<casper_types::U512>>::as_(U256::MAX))
in
odra/odra-casper/types/src/uints.rs
Line 175 in 74bbf2c
Add tests for Mapping and Variable that runs against MockVM.
By now the only correct implementation of a module is having a struct and a single implementation block. If for some reason, a developer would like to have a module with more than one implementation block marked as odra::module
, compilation will fail.
We need to come up with a solution that gently informs a user that he should put all the entry points in a single impl block or allow having multiple blocks.
Sample logs:
execution_error! {
| ^^^^^^^^^^^^^^^^
= note: `-D clippy::from-over-into` implied by `-D warnings`
= help: consider to implement `From<erc20::Error>` instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
= note: this error originates in the attribute macro `odra::odra_error` (in Nightly builds, run with -Z macro-backtrace for more
From #151 (comment)
Add odra-modules
crate to the repo and reexport it in odra
.
odra-modules
should contain:
ERC20
token.Wrapped CSPR
based on ERC20
token.Consider allowing multiple trait implementations on a module.
trait ContractDef {
fn def() -> Vec<String>;
}
// #[odra::interface]
trait ERC20Interface {
fn transfer(&mut self);
fn balance_of(&self);
}
// #[autogenerated]
impl ContractDef for dyn ERC20Interface {
fn def() -> Vec<String> {
vec![
String::from("transfer"),
String::from("balance_of")
]
}
}
// #[odra::interface]
trait ERC20MetadataInterface {
fn name(&self);
}
// #[autogenerated]
impl ContractDef for dyn ERC20MetadataInterface {
fn def() -> Vec<String> {
vec![
String::from("name"),
]
}
}
// #[odra::module]
struct Token;
impl ERC20Interface for Token {
fn transfer(&mut self) {}
fn balance_of(&self) {}
}
impl ERC20MetadataInterface for Token {
fn name(&self) {}
}
// #[autogenerated]
impl ContractDef for Token {
fn def() -> Vec<String> {
let mut def = Vec::new();
def.extend_from_slice(&<dyn ERC20Interface as ContractDef>::def());
def.extend_from_slice(&<dyn ERC20MetadataInterface as ContractDef>::def());
def
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(Token::def(), vec![
String::from("transfer"),
String::from("balance_of"),
String::from("name"),
]);
}
}
By default compile contracts as no_std
. Allow contracts to use std
if needed.
In odra/src/lib.rs
remove all *
in exports.
When the external_contract
is wrongly defined, MockVM
should throw an error like missing argument: "b"
:
use odra::types::Address;
#[odra::module]
pub struct Contract {}
#[odra::module]
impl Contract {
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
}
#[odra::external_contract]
trait WrongInterface {
fn add(&self, a: u32, wrong_name: u32) -> u32;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
let contract = Contract::deploy();
let reference = WrongInterfaceRef::at(contract.address());
let _ = reference.add(1, 2);
}
}
If conversion U512
-> U256
is required, the value may exceed the max value of U256. This scenario should be gently handled (e.g, the state should be reverted) and tested.
The outcome should be better ints implementation.
It should be possible to use a module or another mapping as a mapping's value.
Example:
use odra::modules::tokens::ERC20;
#[odra::module]
struct Contract {
tokens: Mapping<String, ERC20>,
nested: Mapping<String, Mapping<u32, u64>>
}
cargo odra build
without params should be the same as cargo odra build -h
.cargo odra test -p casper
compiles getter_proxy
.authors = ["Jakub Płaskonka [email protected]", "Krzysztof Pobiarżyn [email protected]", "Maciej Zieliński [email protected]"]
license = "MIT"
repository = "https://github.com/odradev/odra" // set to proper
description = "High-level smart contract framework for Rust" // different for each. This one is for core.
keywords = ["wasm", "webassembly", "blockchain"]
categories = ["wasm", "smart contracts"]
Example:
#[odra::module(skip_instance, events = [KycVotingCreated])]
pub struct KycVoterContract {
refs: ContractRefsWithKycStorage,
#[using(self.refs)]
voting_engine: VotingEngine,
access_control: AccessControl,
#[using(self.refs))]
kyc: KycInfo,
}
When the #[deploy(init)]
method is specified don't generate Module::deploy()
method. It's like this here: https://github.com/odradev/odra-template/blob/3259626c1a123a295ea56f5d6070b59bc3662917/src/flipper.rs#L47
Fix odradev/odra-template
afterwards.
Implement AddAssign, SubAssign, MulAssign, DivAssign in casper-types
uints.
Then remove -A clippy::assign-op-pattern
from justfile
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.