-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewriting constants #73
Changes from 2 commits
cc5af4e
bf9debf
cef53d4
071c3fe
569fb69
2b2771a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,14 @@ module RUST-CONSTANTS | |
</constant> | ||
... | ||
</constants> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule should actually be in a new file, called |
||
rule <k> Name:Identifier::.PathExprSegments => V ... </k> | ||
<constant-name> Name </constant-name> | ||
<constant-value> V:Value </constant-value> | ||
|
||
rule <k> Name:Identifier::_:Identifier::.PathExprSegments => V ... </k> | ||
<constant-name> Name </constant-name> | ||
<constant-value> V:Value </constant-value> | ||
|
||
endmodule | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
new ConstantValueLookup; | ||
call ConstantValueLookup.lookup_constant; | ||
return_value; | ||
check_eq 7_000_u64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
new ConstantValueLookup; | ||
call ConstantValueLookup.lookup_constant_with_type; | ||
return_value; | ||
check_eq 7_000_u64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
pub const YEARLY_INTEREST: u64 = 7_000; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait ConstantValueLookup { | ||
#[init] | ||
fn init(&self) { | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
fn lookup_constant(&self) -> u64 { YEARLY_INTEREST } | ||
|
||
fn lookup_constant_with_type(&self) -> u64 { | ||
let x = YEARLY_INTEREST::u64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually work if you try to compile it with rustc? Shouldn't this be |
||
x } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New line after x? |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty space change, it may be worth removing.