Forum for discussion of mid, final term and final project

Dubbi sul COBrA

Dubbi sul COBrA

by ALESSANDRO PAGIARO -
Number of replies: 8

  1. GetMostPopularBy_(x) have to return a fixed number of element (i.e. a parameter of the Catalog?
  2. I've read in someplace that when a public variable is declared, when compiled,it is generated automatic getter to read it. Can we use this getter and avoid the declaration of specific function as GetcontentList?
  3. A Content contract have to declare the parameter item (that indicates a song, movie or a photo) as public in order to permit to read it from a Catalog. The problem is that, given the address of a Content, I can bypass the Catalog and get the content without paying any Ether, right? A solution should be use the internal visibility that reduce the visibility outside the contract but I can deploy a contract that inherit from a Content contract and, again, I'll get content. In order to stop any fraudulent access to the data, can I create a function that hide the internal parameter and then, in order to return its value, it require some Ether. But all the variable are stored on a blockchain, so I can read the value directly inside the block and bypass all the countermeasure that I've explained. How can I block the fraudulent access to the resources?
  4. I have the Content contract that has its own properties (name, author, type...). I can retrieve the Content created by an author iterating on the Catalog address content and filter by address.author or creating a support array duplicate the Catalog data in order to permit a more efficient search by parameter. About the gas usage, is a first solution cheaper (that not require to replicate the data) than the second or not (due the iteration)?
  5. Last question, the premium user has the unrestricted access for some amount of time. How can that time is calculated? A transaction is executed after some time and the confirmation done by other nodes can be run after months and it must return the same result (valid or invalid). Of course, if I use a real time, if I have to confirm a transaction after 1 months I cannot confirm that the user has the right to access to that content since his subscription is expired. So, I have to rely on the block timestamp? And, in that case, I have to model the situation in which the transaction is mined after sometime and the subscription is expired before?
In reply to ALESSANDRO PAGIARO

Re: Dubbi sul COBrA

by DAMIANO DI FRANCESCO MAESA -

1. Yes, x is fixed.

2. It depends a lot on the type of data structure you use to remember the content list. Even if in your case the default getter is enough do check that the syntax (i.e. name of the method) reflects the assignments specifications.

3. We advise to use modifiers, as explained during the course, to properly control functions access. Despite that your phrase "The problem is that, given the address of a Content, I can bypass the Catalog and get the content without paying any Ether, right?" is wrong. Your implementation should guarantee that this is never possible, having direct access to the content manager contract or not.

4. As explained yesterday in person during the question time, gas is only consumed if you have to modify the state, so if you use constant functions they are for sure cheaper form a gas point of view. The real tradeoff is between more gas consumption and faster operations versus less gas consumption and slower operations.

5. Times are discrete in a blockchain scenario. We always advise to use block height as time measurement and this is no exception.

In reply to DAMIANO DI FRANCESCO MAESA

Re: Dubbi sul COBrA

by ORLANDO LEOMBRUNI -

In the context of COBrA, the definition of "genre" is completely arbitrary, right? Is it OK to represent a content's genre as a string (or bytes32) and search for equality in the GetLatestByGenre(x) function?

(I apologize if that's already been asked/explained in class, but unfortunately I couldn't attend the lecture of May 29th.)


In reply to ORLANDO LEOMBRUNI

Re: Dubbi sul COBrA

by DAMIANO DI FRANCESCO MAESA -

Yes, gender is just a label. A possible simple implementation is to use a string (or byte array).

In reply to DAMIANO DI FRANCESCO MAESA

Re: Dubbi sul COBrA

by ORLANDO LEOMBRUNI -

Thank you for your answer. I have another doubt: I wanted to implement GetContentList() in such a way that it would have returned a list of pairs <human-readable name (description) for the content, address of the content's contract>; in Solidity, that would have been a dynamic-size array Content[], where Content is a struct that encapsulates the two fields I mentioned before. Unfortunately this doesn't work (for the same reason that returning a string[] also doesn't work).

I could simply return a bytes32[] representing the contents' descriptions (since I implemented the GetContent(x) function to take the content's description as a parameter), but I have the same problem on the GetStatistics() function where I'd like to return a list of pairs <content description, number of views>. Can you suggest an alternative way of presenting those results?

In reply to ORLANDO LEOMBRUNI

Re: Dubbi sul COBrA

by DAMIANO DI FRANCESCO MAESA -

You can always use the ultiple returns option.

look at the example for suggestions about arrays usage: http://solidity.readthedocs.io/en/v0.4.24/types.html#members .

In reply to DAMIANO DI FRANCESCO MAESA

Re: Dubbi sul COBrA

by MARCO DEGL' INNOCENTI DETTO LUCCHESI -

How we can convert a string to a bytes32?

I only found this way:


function stringToBytes32(string memory source) returns (bytes32 result) {

    bytes memory tempEmptyStringTest = bytes(source); 

    if (tempEmptyStringTest.length == 0) { 

        return 0x0; 

    }

    assembly { result := mload(add(source, 32)) }

 }