-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0c040b
commit d0c0125
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
mx-rust-semantics/main/modules/egld-or-esdt-token-identifier.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
```k | ||
module MX-RUST-MODULES-EGLD-OR-ESDT-TOKEN-IDENTIFIER | ||
imports private MX-COMMON-SYNTAX | ||
imports private MX-RUST-REPRESENTATION | ||
imports private MX-RUST-REPRESENTATION-CONVERSIONS | ||
imports private RUST-SHARED-SYNTAX | ||
rule | ||
normalizedMethodCall | ||
( #token("EgldOrEsdtTokenIdentifier", "Identifier"):Identifier | ||
, #token("from", "Identifier"):Identifier | ||
, ( ptr(ValueId:Int) | ||
, .PtrList | ||
) | ||
) | ||
// TODO: Should check that V >= 0 | ||
=> ( | ||
let #token("x", "Identifier"):Identifier = newEgldOrEsdtTokenIdentifier(); | ||
#token("x", "Identifier") . #token("mx_token_identifier", "Identifier") | ||
= ptr(ValueId) . #token("mx_token_identifier", "Identifier"); | ||
#token("x", "Identifier"):Expression | ||
):Statements | ||
// -------------------------------------- | ||
syntax MxRustType ::= "egldOrEsdtTokenIdentifierType" [function, total] | ||
rule egldOrEsdtTokenIdentifierType | ||
=> rustStructType | ||
( #token("EgldOrEsdtTokenIdentifier", "Identifier"):Identifier | ||
, ( mxRustStructField | ||
( #token("mx_token_identifier", "Identifier"):Identifier | ||
, str | ||
) | ||
, .MxRustStructFields | ||
) | ||
) | ||
rule mxRustEmptyValue(rustType(#token("EgldOrEsdtTokenIdentifier", "Identifier"))) | ||
=> mxToRustTyped(egldOrEsdtTokenIdentifierType, mxListValue(mxStringValue(""))) | ||
rule mxValueToRust(#token("EgldOrEsdtTokenIdentifier", "Identifier"), V:MxValue) | ||
=> mxToRustTyped(egldOrEsdtTokenIdentifierType, mxListValue(V)) | ||
rule rustValueToMx | ||
( struct | ||
( #token("EgldOrEsdtTokenIdentifier", "Identifier"):Identifier | ||
, #token("mx_token_identifier", "Identifier"):Identifier |-> TokenValueId:Int | ||
.Map | ||
) | ||
) | ||
=> ptr(TokenValueId) ~> rustValueToMx | ||
// -------------------------------------- | ||
syntax Expression ::= "newEgldOrEsdtTokenIdentifier" | ||
rule newEgldOrEsdtTokenIdentifier => mxRustEmptyValue(rustType(#token("EgldOrEsdtTokenIdentifier", "Identifier"))) | ||
endmodule | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(mxStringValue("MyToken")); | ||
push mxStringValue("eoeTokenIdentifier"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxStringValue("MyToken") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait Contract { | ||
#[init] | ||
fn init(&self) {} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
#[endpoint(eoeTokenIdentifier)] | ||
fn eoe_token_identifier(&self, t: TokenIdentifier) -> EgldOrEsdtTokenIdentifier { | ||
EgldOrEsdtTokenIdentifier::from(t) | ||
} | ||
} |