2

I am creating a non-fungible token. While I own the token, I pay ram for it. After transfer of the token the new owner should pay for it. My token contract updates the payer as soon as the new owner interacts with the token.

I would like to show the old and the new owner the status of the ram usage (like mark the token as red if ram is still payed by the old owner). Is it possible to check whether the user is paying ram for a row in a table?

0

You could use demux to track the ownership of the token in your database.

Then to show whether the user is paying ram for a row in a table, you could add a method to your contract that iterates through your contract's state preservation medium to return whether or not their account_name is present. This method could be called through eosjs.

Something like:

[[eosio::action]]
void getTokenStatus(const account_name account) {
    yourIndex name (_self, _self);

    auto iterator = name.find(account);
    // assert if account not paying for RAM
    eosio_assert(iterator != name.end(), "Account not found");

    auto tokenHolder = name.get(account);

    // using print if user is consuming row
    print("Username: ", tokenHolder.username.c_str());
    print(" Ownership Status: ", tokenHolder.ownershipStatus);
}
  • So, there is no method to check it on the table? – friedger Sep 6 '18 at 10:14
  • If by method you mean RPC API call specific to querying RAM rows by account_name, then no there is not. There is a get_table_rows call, but you cannot specify account name to query it. My example uses the RPC API by creating a method within your contract that you can then call. – Nat Sep 6 '18 at 10:55
2

you can get the ram consume before version 1.2.3 like this:

void apply_context::update_db_usage( const account_name& payer, int64_t delta ) {
   if( delta > 0 ) {
      if( !(privileged || payer == account_name(receiver)) ) {
         require_authorization( payer );
      }
   }
   dlog("the ram used is${delta}",("delta",delta));
   trx_context.add_ram_usage(payer, delta);
}

the log can show the ram update info but now the release version has updated to version 1.2.4 as a developer of eosio,we can't force user pay for the ram consume,because the system notice that the producer shold pay for ram,Cannot charge RAM to other accounts during notify:

void apply_context::update_db_usage( const account_name& payer, int64_t delta ) {
   if( delta > 0 ) {
      if( !(privileged || payer == account_name(receiver)) ) {
         EOS_ASSERT( control.is_ram_billing_in_notify_allowed() || (receiver == act.account),
                     subjective_block_production_exception, "Cannot charge RAM to other accounts during notify." );
         require_authorization( payer );
      }
   }
   trx_context.add_ram_usage(payer, delta);
}
  • Thank you for the answer, this clarifies that there is no link between a table row and the ram usage. (I accepted the other answer because that solves the token problem) – friedger Sep 7 '18 at 9:56

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.