-
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
Mx blockchain hooks #67
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
```k | ||
|
||
module MX-ACCOUNTS-CONFIGURATION | ||
imports INT-SYNTAX | ||
imports STRING-SYNTAX | ||
|
||
configuration | ||
<mx-accounts> | ||
<mx-account multiplicity="*" type="Map"> | ||
// TODO: The address should be bytes. | ||
<mx-account-address> "" </mx-account-address> | ||
<mx-esdt-datas> | ||
<mx-esdt-data multiplicity="*" type="Map"> | ||
// TODO: The esdt-id should be bytes. | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> "" </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> 0 </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> 0 </mx-esdt-balance> | ||
</mx-esdt-data> | ||
</mx-esdt-datas> | ||
</mx-account> | ||
</mx-accounts> | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
```k | ||
|
||
module MX-ACCOUNTS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-ACCOUNTS-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
|
||
rule | ||
<k> MX#bigIntGetESDTExternalBalance | ||
( mxStringValue(Owner:String) | ||
, mxStringValue(TokenId:String) | ||
, mxIntValue(Nonce:Int) | ||
, .MxHookArgs | ||
) => MX#bigIntNew(mxIntValue(Balance)) ... </k> | ||
<mx-account-address> Owner </mx-account-address> | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> TokenId </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> Nonce </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> Balance:Int </mx-esdt-balance> | ||
[priority(50)] | ||
|
||
rule | ||
<k> MX#bigIntGetESDTExternalBalance | ||
( mxStringValue(Owner:String) | ||
, mxStringValue(TokenId:String) | ||
, mxIntValue(Nonce:Int) | ||
, .MxHookArgs | ||
) => MX#bigIntNew(mxIntValue(0)) ... </k> | ||
<mx-account-address> Owner </mx-account-address> | ||
[priority(100)] | ||
|
||
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
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,15 @@ | ||
```k | ||
|
||
module MX-BLOCKS-CONFIGURATION | ||
imports INT-SYNTAX | ||
|
||
configuration | ||
<mx-blocks> | ||
<mx-current-block> | ||
<mx-current-block-timestamp> 0 </mx-current-block-timestamp> | ||
</mx-current-block> | ||
</mx-blocks> | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
|
||
module MX-BLOCKS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-BLOCKS-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
|
||
rule | ||
<k> MX#getBlockTimestamp ( .MxHookArgs ) => mxIntValue(T) ... </k> | ||
<mx-current-block-timestamp> T </mx-current-block-timestamp> | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
```k | ||
|
||
module MX-CALL-CONFIGURATION | ||
imports STRING | ||
|
||
configuration | ||
<mx-call-data> | ||
<mx-caller> "" </mx-caller> | ||
</mx-call-data> | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
|
||
module MX-CALLS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-CALL-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
|
||
rule | ||
<k> MX#getCaller ( .MxHookArgs ) => mxStringValue(Caller) ... </k> | ||
<mx-caller> Caller:String </mx-caller> | ||
|
||
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
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
```k | ||
|
||
requires "accounts/hooks.md" | ||
requires "biguint/hooks.md" | ||
requires "blocks/hooks.md" | ||
requires "calls/hooks.md" | ||
|
||
module MX-COMMON | ||
imports private MX-ACCOUNTS-HOOKS | ||
imports private MX-BIGUINT-HOOKS | ||
imports private MX-BLOCKS-HOOKS | ||
imports private MX-CALLS-HOOKS | ||
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
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,3 @@ | ||
setBlockTimestamp(1234); | ||
call 0 MX#getBlockTimestamp; | ||
check_eq mxIntValue(1234) |
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,3 @@ | ||
setCaller("Owner"); | ||
call 0 MX#getCaller; | ||
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,17 @@ | ||
addAccount("Owner"); | ||
|
||
push mxIntValue(0); | ||
push mxStringValue("MyToken"); | ||
push mxStringValue("Owner"); | ||
call 3 MX#bigIntGetESDTExternalBalance; | ||
get_big_int; | ||
check_eq mxIntValue(0); | ||
|
||
setBalance("Owner", "MyToken", 0, 1234); | ||
|
||
push mxIntValue(0); | ||
push mxStringValue("MyToken"); | ||
push mxStringValue("Owner"); | ||
call 3 MX#bigIntGetESDTExternalBalance; | ||
get_big_int; | ||
check_eq mxIntValue(1234) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Right now my understanding is that our timing information is arbitrary, as we do not compute time at the moment, correct?
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.
Yes, that's correct. However, we need to be able to simulate time for the lending contract, which uses
self.blockchain().get_block_timestamp()
. Arguably, maybe I shouldn't have implemented this hook now since our priority is the swap contract, but it was quite easy, so whatever.