-
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.
Partial implementation of the blockchain() function (#112)
- Loading branch information
1 parent
db6c0ef
commit 950fb75
Showing
8 changed files
with
116 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
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,55 @@ | ||
```k | ||
module MX-RUST-MODULES-BLOCKCHAIN | ||
imports private COMMON-K-CELL | ||
imports private MX-COMMON-SYNTAX | ||
imports private MX-RUST-REPRESENTATION | ||
imports private MX-RUST-REPRESENTATION-CONVERSIONS | ||
imports private RUST-EXECUTION-CONFIGURATION | ||
imports private RUST-SHARED-SYNTAX | ||
syntax Identifier ::= "MxRust#Blockchain" [token] | ||
syntax MxRustStructType ::= "blockchainType" [function, total] | ||
rule blockchainType | ||
=> rustStructType | ||
( MxRust#Blockchain | ||
, .MxRustStructFields | ||
) | ||
rule | ||
normalizedMethodCall | ||
( MxRust#Blockchain | ||
, #token("new", "Identifier"):Identifier | ||
, .PtrList | ||
) | ||
=> mxRustNewStruct | ||
( blockchainType | ||
, .CallParamsList | ||
) | ||
rule | ||
normalizedMethodCall | ||
( MxRust#Blockchain | ||
, #token("get_caller", "Identifier"):Identifier | ||
, ( ptr(_SelfId:Int) | ||
, .PtrList | ||
) | ||
) | ||
=> MX#getCaller ( .MxValueList ) | ||
~> mxValueToRust(#token("ManagedAddress", "Identifier"):Identifier) | ||
rule | ||
normalizedMethodCall | ||
( MxRust#Blockchain | ||
, #token("get_block_timestamp", "Identifier"):Identifier | ||
, ( ptr(_SelfId:Int) | ||
, .PtrList | ||
) | ||
) | ||
=> MX#getBlockTimestamp ( .MxValueList ) | ||
~> mxValueToRust(u64) | ||
endmodule | ||
``` |
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
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(); | ||
push mxStringValue("getCaller"); | ||
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("Owner") |
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,23 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait Blockchain { | ||
#[init] | ||
fn init(&self) {} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
#[endpoint(getCaller)] | ||
fn get_caller(&self) -> ManagedAddress { | ||
self.blockchain().get_caller() | ||
} | ||
|
||
#[endpoint(getBlockTimestamp)] | ||
fn get_block_timestamp(&self) -> u64 { | ||
self.blockchain().get_block_timestamp() | ||
} | ||
} |
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,14 @@ | ||
setCallee("Owner"); | ||
setBlockTimestamp(123); | ||
|
||
push mxListValue(); | ||
push mxStringValue("getBlockTimestamp"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxIntValue(123) |