Comments (2)
@turbolent can this be done with the current version of cadence?
the function is: (
) // Returns megabytes
pub fun calculateAccountCapacity(_ accountAddress: Address): UFix64 {
let balanceRef = getAccount(accountAddress)
.getCapability<&FlowToken.Vault{FungibleToken.Balance}>(/public/flowTokenBalance)!
.borrow() ?? panic("Could not borrow FLOW balance capability")
// get address token balance
if balanceRef.balance < self.minimumStorageReservation {
// if < then minimum return 0
return 0.0
} else {
// return balance multiplied with megabytes per flow
return balanceRef.balance * self.storageMegaBytesPerReservedFLOW
}
}
The last part balanceRef.balance * self.storageMegaBytesPerReservedFLOW
should return max UFix64 if the multiplication result is more than max UFix64.
from flow-core-contracts.
I think what we would want is saturating multiply, that results in the min/max value instead of underflowing/overflow. We don't have that in Cadence, but it could be easily added. For example, Rust has saturating_mul
: https://doc.rust-lang.org/std/primitive.u32.html#method.saturating_mul
Alternatively, the same behaviour could be implemented by dividing from the max value and checking if the multiplication would result in an overflow. There are currently no max/min constants of number types exposed (e.g. UFix.max
), but again this could be easily added, and alternatively defined as a constant in the Cadence program itself (e.g. let UFix64Max = ...
.
I'll create issues for both.
from flow-core-contracts.
Related Issues (20)
- Add support to Staking contract to separate operational from financial capabilities HOT 4
- Refactor rewards calculation and payment to be done in batches HOT 1
- Introduce Delegator Staking Minimums
- Move `resetEpoch()` to the Epoch Admin resource
- Implement FungibleTokenMetadataViews in FlowToken HOT 3
- Add logic to maintain 8 access node slots every epoch
- Refactor `FlowEpoch.getEpochMetadata` to avoid the dictionary-copy HOT 2
- Replace `while` loop with `for` loop once references are allowed
- Revisit `Account` entitlements in `FlowStakingCollection.CollectionOwner.registerNode` HOT 1
- RandomBeaconHistory.getRandomSourceHistoryPage() performs impure function under Cadence 1.0 HOT 1
- [FLIP 204] Update `FlowEpoch` smart contract to specify target end time for epoch
- LockedTokens getLockedAccountBalance underflows HOT 3
- Update docs site and README with addresses of important contracts
- SoR history gaps when heartbeat call fails HOT 1
- Port a the SoR History fix to Stable Cadence HOT 1
- Use semantic versioning and tags HOT 3
- Require proof of possession of the staking private key from staking nodes
- Improve Fisher-Yates random distribution HOT 1
- Make iterating through delegators in staking contract more efficient
- Use service account Admin resource to set weights
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow-core-contracts.