eos icon indicating copy to clipboard operation
eos copied to clipboard

Identical transactions not allowed in smart contract

Open PhillipHamnett opened this issue 8 years ago • 1 comments

I want to submit a transaction more than once with my smart contract, but this isn't allowed, giving the following error:

2018-08-18T18:42:28.712 thread-0 main.cpp:2888 main ] Failed with error: could not insert object, most likely a uniqueness constraint was violated (13)

The minimum working code to reproduce this error is:

    account_name leaser = N(myaccount);
    asset stake_net_quantity(1);
    asset stake_cpu_quantity(1);
    eosio::transaction out;
    out.actions.emplace_back(eosio::permission_level{_self, N(active) }, 
                                              N(eosio), N(delegatebw), 
                                              std::make_tuple(_self, leaser, 
                                                              stake_net_quantity, 
                                                              stake_cpu_quantity, 
                                                              false));
    out.send(1, _self, false);
    out.send(2, _self, false);

Notice that the ID for sending is different in each case, but this doesn't seem to matter.

How can I submit the same transaction more than once within the contract?

PhillipHamnett avatar Aug 18 '18 18:08 PhillipHamnett

The IDs of "1" or "2" are the user defined IDs to store and retrieve the deferred transactions. However the real transaction id is the hash of the transaction itself, as defined in transaction.cpp:

transaction_id_type transaction::id() const {
   digest_type::encoder enc;
   fc::raw::pack( enc, *this );
   return enc.result();
}

This transaction id needs to be unique as well.

taokayan avatar Aug 20 '18 06:08 taokayan