Skip to content

Commit

Permalink
Add stc balance check
Browse files Browse the repository at this point in the history
  • Loading branch information
sanlee42 committed Sep 28, 2022
1 parent b632aab commit 613c1a9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: D875E298A3BFD5BEDF61346227E8B91F980B3CB2C25B2FB2D5333F44988599A3
source_digest: 2CC98E1932523E6802D41756C8DBE86EA6A34E9853B32A94686B5BA2BC1F6584
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/Account.mv
Binary file not shown.
20 changes: 10 additions & 10 deletions build/StarcoinFramework/docs/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -3159,11 +3159,10 @@ It verifies:
);
<b>let</b> balance_amount_token = <a href="Account.md#0x1_Account_balance">balance</a>&lt;TokenType&gt;(txn_sender);
<b>assert</b>!(balance_amount_token &gt;= max_transaction_fee_token, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_CANT_PAY_GAS_DEPOSIT">EPROLOGUE_CANT_PAY_GAS_DEPOSIT</a>));
// FIXME: check stc amount of genesis?
/*
<b>let</b> balance_amount_stc= <a href="Account.md#0x1_Account_balance">balance</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>());
<b>assert</b>!(balance_amount_stc &gt;= max_transaction_fee_stc, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_CANT_PAY_GAS_DEPOSIT">EPROLOGUE_CANT_PAY_GAS_DEPOSIT</a>));
*/
<b>if</b> (!is_stc&lt;TokenType&gt;()){
<b>let</b> balance_amount_stc= <a href="Account.md#0x1_Account_balance">balance</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>());
<b>assert</b>!(balance_amount_stc &gt;= max_transaction_fee_stc, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_CANT_PAY_GAS_DEPOSIT">EPROLOGUE_CANT_PAY_GAS_DEPOSIT</a>));
}
};
// Check that the transaction sequence number matches the sequence number of the account
<b>assert</b>!(txn_sequence_number &gt;= sender_account.sequence_number, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_SEQUENCE_NUMBER_TOO_OLD">EPROLOGUE_SEQUENCE_NUMBER_TOO_OLD</a>));
Expand Down Expand Up @@ -3294,11 +3293,12 @@ It collects gas and bumps the sequence number
<a href="Account.md#0x1_Account_balance">balance</a>&lt;TokenType&gt;(txn_sender) &gt;= transaction_fee_amount_token,
<a href="Errors.md#0x1_Errors_limit_exceeded">Errors::limit_exceeded</a>(<a href="Account.md#0x1_Account_EINSUFFICIENT_BALANCE">EINSUFFICIENT_BALANCE</a>)
);
/*
<b>let</b> genesis_balance_amount_stc=<a href="Account.md#0x1_Account_balance">balance</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>());
<b>assert</b>!(genesis_balance_amount_stc &gt;= transaction_fee_amount_stc,
<a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_CANT_PAY_GAS_DEPOSIT">EPROLOGUE_CANT_PAY_GAS_DEPOSIT</a>)
);*/
<b>if</b> (!is_stc&lt;TokenType&gt;()){
<b>let</b> genesis_balance_amount_stc=<a href="Account.md#0x1_Account_balance">balance</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_GENESIS_ADDRESS">CoreAddresses::GENESIS_ADDRESS</a>());
<b>assert</b>!(genesis_balance_amount_stc &gt;= transaction_fee_amount_stc,
<a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Account.md#0x1_Account_EPROLOGUE_CANT_PAY_GAS_DEPOSIT">EPROLOGUE_CANT_PAY_GAS_DEPOSIT</a>)
);
};
// Load the transaction sender's account and balance resources
<b>let</b> sender_account = <b>borrow_global_mut</b>&lt;<a href="Account.md#0x1_Account">Account</a>&gt;(txn_sender);
// Bump the sequence number
Expand Down
Binary file modified build/StarcoinFramework/source_maps/Account.mvsm
Binary file not shown.
3 changes: 1 addition & 2 deletions integration-tests/account/txn_prologue_and_epilogue.move
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//# init -n dev

//# faucet --addr alice --amount 10000000

//# faucet --addr Genesis

//# faucet --addr alice --amount 10000000

//# run --signers alice
// create txn sender account
Expand Down
22 changes: 11 additions & 11 deletions sources/Account.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Account {
use StarcoinFramework::TransactionFee;
use StarcoinFramework::CoreAddresses;
use StarcoinFramework::Errors;
use StarcoinFramework::STC::{Self, STC};
use StarcoinFramework::STC::{Self, STC, is_stc};
use StarcoinFramework::BCS;
use StarcoinFramework::Math;

Expand Down Expand Up @@ -1040,11 +1040,10 @@ module Account {
);
let balance_amount_token = balance<TokenType>(txn_sender);
assert!(balance_amount_token >= max_transaction_fee_token, Errors::invalid_argument(EPROLOGUE_CANT_PAY_GAS_DEPOSIT));
// FIXME: check stc amount of genesis?
/*
let balance_amount_stc= balance<STC>(CoreAddresses::GENESIS_ADDRESS());
assert!(balance_amount_stc >= max_transaction_fee_stc, Errors::invalid_argument(EPROLOGUE_CANT_PAY_GAS_DEPOSIT));
*/
if (!is_stc<TokenType>()){
let balance_amount_stc= balance<STC>(CoreAddresses::GENESIS_ADDRESS());
assert!(balance_amount_stc >= max_transaction_fee_stc, Errors::invalid_argument(EPROLOGUE_CANT_PAY_GAS_DEPOSIT));
}
};
// Check that the transaction sequence number matches the sequence number of the account
assert!(txn_sequence_number >= sender_account.sequence_number, Errors::invalid_argument(EPROLOGUE_SEQUENCE_NUMBER_TOO_OLD));
Expand Down Expand Up @@ -1108,11 +1107,12 @@ module Account {
balance<TokenType>(txn_sender) >= transaction_fee_amount_token,
Errors::limit_exceeded(EINSUFFICIENT_BALANCE)
);
/*
let genesis_balance_amount_stc=balance<STC>(CoreAddresses::GENESIS_ADDRESS());
assert!(genesis_balance_amount_stc >= transaction_fee_amount_stc,
Errors::invalid_argument(EPROLOGUE_CANT_PAY_GAS_DEPOSIT)
);*/
if (!is_stc<TokenType>()){
let genesis_balance_amount_stc=balance<STC>(CoreAddresses::GENESIS_ADDRESS());
assert!(genesis_balance_amount_stc >= transaction_fee_amount_stc,
Errors::invalid_argument(EPROLOGUE_CANT_PAY_GAS_DEPOSIT)
);
};
// Load the transaction sender's account and balance resources
let sender_account = borrow_global_mut<Account>(txn_sender);
// Bump the sequence number
Expand Down

0 comments on commit 613c1a9

Please sign in to comment.