5

Usually in centralized apps we have the fields created_at and created_by to know when and who created this record and also sometimes modified_at and modified_by to register who and when was the last modification of a record.

How should we do that in our smart contracts? Should we have account_name and uint64_t added manually to the table or is there an easy way to find out through get actions?

  • yes, add them to your table – Jimmy Guo Jun 26 '18 at 2:23
4

Just add a created_at field to your table.

struct blog {
    uint64_t id;
    time created_at;

    uint64_t primary_key()const { return id; }
    EOSLIB_SERIALIZE(blog, (id)(created_at))
}
typedef multi_index<N(blog), blog> blog_index;
blog_index blogs;

When creating a record, set created_at to now().

blogs.emplace(_self, [&](auto& x) {
    x.id = blogs.available_primary_key();
    x.created_at = now();
}
| improve this answer | |
0

If you need to know this information inside the smart contract, then you should store this information in the record just like you would in a regular DB.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.