New answers tagged

2

You are right about avoiding iteration. The trick is to ensure a finite maximum cost at any scale. Generally, that means organizing things so data is handy with limited iteration and recursion. pragma solidity 0.5.16; import "./HitchensOrderStatisticsTree.sol"; contract Nearest { using HitchensOrderStatisticsTreeLib for ...


3

It's a bit of a dilemma. You need mappings for random access and arrays for iteration. You should aim to avoid loops at all costs, for O(1) complexity so the contract scales. This library helps with CRUD ops on sets, including delete. There is a quick explainer-style walk-though over here, with links back to the detailed tutorial that explains how it works ...


3

For those who actually find themselves in the same situation as I did, take a look at this answer, it answers my dilemma. Credits to @goodvibration


1

You cannot have an optional struct layout. You can accomplish something similar with related structs. └── Operations (struct) ├── date_begining (uint) └── date_end (uint) └── responsible (address) └── typeID (bytes32) └── typeSchema (refer to the class that applies) Define the four types: └── Observation (struct) └── Production ...


1

if the array is only being used below foo[n], and the length is longer than n, is anything above foo[n] adding storage costs? No. Arrays use the same storage scheme as mappings. The slots to write to are hashes of the contract address, the position of the variable established at compile-time, and the index. Uninitialized values are not written and they ...


0

For storage it should be the same. I presume you're asking theoretically. If you actually create one of these things, it will enable you to access the whole of the storage available to the contract via the array - which means you could overwrite other storage variables. I've seen this trick used a few times in "Hack this contract" competitions, and is one ...


0

You can also check out EthAir Balloons npm package which is a JS library offerin a model level of abstraction above smart contracts, allowing you to save data on ethereum network without writing a Solidity smart contract


0

No, but yes. The important thing to realize is that storage is laid out to accomodate the structs you defined. Not setting means they will retain their initial values, 0x000... according to type and length (i.e. false, 0, length=0, etc.). In practice, you don't need to write 0's, but you will be unable to instantiate a partial instance. This will not ...


0

As always, it depends on what the dApp is supposed to do. From your example implementation, I see serialNumber and that leads me to surmise that "product" as you understand it, is an individual item and not an inventory item that can exist in quantity or be in stock and owned by many people at the same time. But think that through and be sure the latter isn'...


Top 50 recent answers are included