-
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
Send tokens #70
Merged
Merged
Send tokens #70
Changes from 1 commit
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
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,152 @@ | ||
```k | ||
|
||
module MX-ACCOUNTS-TOOLS | ||
imports private BOOL | ||
imports private COMMON-K-CELL | ||
imports private INT | ||
imports private MX-ACCOUNTS-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
imports private STRING | ||
imports private MX-ACCOUNTS-STACK-CONFIGURATION | ||
|
||
syntax MxInstructions ::= transferESDT | ||
( source: String | ||
, destination: String | ||
, token: String | ||
, nonce: Int | ||
, value: Int | ||
) | ||
| checkAccountExists(address: String) | ||
| checkESDTBalance(account: String, token: String, value: Int) | ||
| addToESDTBalance(account: String, token: String, delta: Int, allowNew: Bool) | ||
|
||
// ------------------------------------------------------ | ||
|
||
rule transferESDTs(... transfers: .MxEsdtTransferList) => .K | ||
rule (.K => transferESDT | ||
(... source: Source, destination: Destination | ||
, token: TokenName, nonce: Nonce, value: Value | ||
) | ||
) ~> transferESDTs | ||
(... source: Source:String | ||
, destination: Destination:String | ||
, transfers: | ||
( mxTransferValue | ||
(... token: TokenName:String | ||
, nonce: Nonce:Int | ||
, value: Value:Int | ||
) | ||
, Ts:MxEsdtTransferList | ||
) => Ts | ||
) | ||
|
||
rule transferESDT | ||
(... source: Source:String, destination: Destination:String | ||
, token: TokenName:String, nonce: 0, value: Value:Int | ||
) | ||
=> checkAccountExists(Source) | ||
~> checkAccountExists(Destination) | ||
~> checkESDTBalance(Source, TokenName, Value) | ||
~> addToESDTBalance(Source, TokenName, 0 -Int Value, false) | ||
~> addToESDTBalance(Destination, TokenName, Value, true) | ||
|
||
// ------------------------------------------------------ | ||
|
||
rule [checkAccountExists-pass]: | ||
<k> checkAccountExists(Address:String) => .K ... </k> | ||
<mx-account-address> Address </mx-account-address> | ||
[priority(50)] | ||
|
||
rule [checkAccountExists-fail]: | ||
<k> checkAccountExists(Address:String) | ||
=> #exception(ExecutionFailed, "account not found: " +String Address) | ||
... | ||
</k> | ||
[priority(100)] | ||
|
||
|
||
// ------------------------------------------------------ | ||
rule [checkESDTBalance]: | ||
<k> checkESDTBalance(Account:String, TokenName:String, Value:Int) | ||
=> .K | ||
... | ||
</k> | ||
<mx-account-address> Account </mx-account-address> | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> TokenName </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> 0 </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> OriginalFrom:Int </mx-esdt-balance> | ||
requires Value <=Int OriginalFrom | ||
[priority(50)] | ||
|
||
// VALUE > ORIGFROM or TOKEN does not exist | ||
rule [checkESDTBalance-oof-instrs-empty]: | ||
<k> checkESDTBalance(_, _, _) => #exception(OutOfFunds, "") ... </k> | ||
[priority(100)] | ||
|
||
// ------------------------------------------------------ | ||
rule [addToESDTBalance]: | ||
<k> | ||
addToESDTBalance | ||
(... account: Account:String | ||
, token: TokenName:String | ||
, delta: Delta:Int | ||
, allowNew: _:Bool | ||
) | ||
=> .K | ||
... | ||
</k> | ||
<mx-account-address> Account </mx-account-address> | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> TokenName </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> 0 </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> OriginalFrom:Int => OriginalFrom +Int Delta </mx-esdt-balance> | ||
[priority(50)] | ||
|
||
rule [addToESDTBalance-new-esdtData]: | ||
<k> | ||
addToESDTBalance | ||
(... account: Account:String | ||
, token: TokenName:String | ||
, delta: Delta:Int | ||
, allowNew: true | ||
) | ||
=> .K | ||
... | ||
</k> | ||
<mx-account-address> Account </mx-account-address> | ||
( .Bag => | ||
<mx-esdt-data> | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> TokenName </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> 0 </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> Delta </mx-esdt-balance> | ||
</mx-esdt-data> | ||
) | ||
[priority(100), preserves-definedness] | ||
|
||
rule [addToESDTBalance-new-err-instrs-empty]: | ||
addToESDTBalance(... account: _:String, token: _:String, delta: _:Int, allowNew: false) | ||
=> #exception(ExecutionFailed, "new ESDT data on sender") | ||
[priority(100), preserves-definedness] | ||
|
||
// ------------------------------------------------------ | ||
rule [pushWorldState]: | ||
<k> pushWorldState => .K ... </k> | ||
<mx-world-stack> (.List => ListItem(ACCTDATA)) ... </mx-world-stack> | ||
<mx-accounts> ACCTDATA </mx-accounts> | ||
rule [dropWorldState]: | ||
<k> dropWorldState => .K ... </k> | ||
<mx-world-stack> (ListItem(_) => .List) ... </mx-world-stack> | ||
|
||
// ------------------------------------------------------ | ||
rule transferFunds(... from: From:String, to: To:String, amount: 0) | ||
=> checkAccountExists(From) | ||
~> checkAccountExists(To) | ||
|
||
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,12 +1,27 @@ | ||
```k | ||
|
||
module MX-CALL-CONFIGURATION | ||
imports STRING | ||
imports INT-SYNTAX | ||
imports MX-COMMON-SYNTAX | ||
imports STRING-SYNTAX | ||
|
||
configuration | ||
<mx-call-data> | ||
<mx-callee> "" </mx-callee> | ||
<mx-caller> "" </mx-caller> | ||
<mx-call-args> .MxValueList </mx-call-args> | ||
<mx-egld-value> 0 </mx-egld-value> | ||
<mx-esdt-transfers> .MxEsdtTransferList </mx-esdt-transfers> | ||
<mx-gas-provided> 0 </mx-gas-provided> | ||
<mx-gas-price> 0 </mx-gas-price> | ||
</mx-call-data> | ||
endmodule | ||
|
||
module MX-CALL-RESULT-CONFIGURATION | ||
imports MX-COMMON-SYNTAX | ||
|
||
configuration | ||
<mx-call-result> .MxCallResult </mx-call-result> | ||
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
Oops, something went wrong.
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.
Do we intend to have negative deltas to
addToESDTBalance
? If it is only intended to add amounts to the total balance, then perhaps we should haverequires
in the rules preventing modifications by negative values and possibly negative balances. Or perhaps change the naming fromaddToESDTBalance
to something likemodifyESDTBalanceByDelta
.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, the deltas can be negative, see https://github.com/Pi-Squared-Inc/rust-demo-semantics/pull/70/files#diff-39d9f39de40db7c63b5cb4ada9dfd2b5c889ffadbae02c26a7db378356ef234cR50-R51. I copied the name from the existing mx-semantics. I renamed it, is it better now?
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.
It is, @virgil-serbanuta . Thank you!