Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
9e476ba0
Commit
9e476ba0
authored
6 years ago
by
Sergey Pepyakin
Committed by
Gav Wood
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Query dest balance only once + doc. (#861)
parent
270d0186
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/srml/contract/src/exec.rs
+11
-2
11 additions, 2 deletions
substrate/srml/contract/src/exec.rs
with
11 additions
and
2 deletions
substrate/srml/contract/src/exec.rs
+
11
−
2
View file @
9e476ba0
...
...
@@ -201,7 +201,17 @@ fn transfer<'a, T: Trait>(
value
:
T
::
Balance
,
ctx
:
&
mut
ExecutionContext
<
'a
,
T
>
,
)
->
Result
<
(),
&
'static
str
>
{
let
would_create
=
ctx
.overlay
.get_balance
(
dest
)
.is_zero
();
let
to_balance
=
ctx
.overlay
.get_balance
(
dest
);
// This flag is totally distinct from `contract_create`, which shows if this function
// is called from `CREATE` procedure.
//
// `would_create` indicates whether the account will be created if this transfer gets executed.
// For example, we can create a contract at the address which already has some funds. In this
// case `contract_create` will be `true` but `would_create` will be `false`. Another example would
// be when this function is called from `CALL`, but `dest` doesn't exist yet. In this case
// `contract_create` will be `false` but `would_create` will be `true`.
let
would_create
=
to_balance
.is_zero
();
let
fee
:
T
::
Balance
=
if
contract_create
{
<
Module
<
T
>>
::
contract_fee
()
...
...
@@ -228,7 +238,6 @@ fn transfer<'a, T: Trait>(
}
<
T
as
balances
::
Trait
>
::
EnsureAccountLiquid
::
ensure_account_liquid
(
transactor
)
?
;
let
to_balance
=
ctx
.overlay
.get_balance
(
dest
);
let
new_to_balance
=
match
to_balance
.checked_add
(
&
value
)
{
Some
(
b
)
=>
b
,
None
=>
return
Err
(
"destination balance too high to receive value"
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment