I want to save data in the blockchain table whose format is as below:
{
"docsample": {
"id": 1,
"creationDate": "2012-05-16T18:25:43.511Z",
"contentType": "abc",
"type": "abc",
"owner": {
"name": "abc",
"certificate": {
"serialNumber": "abc",
"issuer": "abc"
}
},
"fingerprint": "abc"
}
}
In my smart contract, I declared owner
as one struct and cert
as another. I want to pass this struct as a parameter to action. Smart contract struct are:
struct [[eosio::table]] ipdoctable {
uint64_t id;
time_point_sec createdAt;
std::string contentType;
std::string type;
struct owner;
name fingerprint;
uint64_t primary_key() const { return fingerprint.value;}
};
typedef eosio::multi_index<"ipdocs"_n, ipdoctable> ipdoc_index;
struct [[eosio::table]] owner{
std::string name;
struct certificate;
};
struct [[eosio::table]] certificate{
std::string serialNumber;
std::string issuer;
};
And Action is:
[[eosio::action]]
void upsertipdoc(time_point_sec createdAt, std::string contentType, std::string type, struct ownerinfo *owner,name fingerprint) {
ipdoc_index ipdocs ( get_self(), get_first_receiver().value );
bool found = false;
for(auto itr = ipdocs.begin(); itr != ipdocs.end() && found!=true; itr++) {
if(itr->fingerprint == fingerprint) {
found = true;
ipdocs.modify(itr, _self, [&]( auto& row ) {
row.contentType = contentType,
row.type = type,
row.owner = owner,
row.fingerprint = fingerprint;
});
}
}
Apologies if any illogical mistake in the code. Not much familiar with C++. Please guide how would I save data in the given manner?