eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

Transaction authorization messes up action authorizations

Open infohata opened this issue 8 years ago • 4 comments

When I'm trying to push the transaction with multiple actions from different contracts, if I add authorization to transaction for some users it does not work on both actions - some of them get empty authorization for buycodum. Example code:

let authorization = {'authorization': "codumjungles@active"};
try {
    console.log('authorization for transaction: ', authorization);
    buy_codum_intent = await eos.transaction([sale_acc, 'eosio.token'], contracts => {
        console.log('authorization for codumpresale buycodum: ', authorization);
        contracts.codumpresale.buycodum({
            "contributor": eos_account,
            "network": Number($('#{{ form.network.id_for_label }}').val()),
            "quantity": $('#{{ form.quantity.id_for_label }}').val() + " {{ networks|get_item:form.network.initial }}",
            "memo": $('#{{ form.memo.id_for_label }}').val()
        }, authorization);
        console.log('authorization for eosio.token transfer: ', authorization);
        contracts.eosio_token.transfer({
            "from": eos_account,
            "to": sale_acc,
            "quantity": $('#{{ form.quantity.id_for_label }}').val() + " {{ networks|get_item:form.network.initial }}",
            "memo": $('#{{ form.memo.id_for_label }}').val()
        }, authorization);
    }, authorization);
} catch (e) {
    console.log('Error: ', e);
    errordiv.text(e.message);
}

We have tested it with nsjames and Scatter, and the trouble is not on the Scatter's end.

infohata avatar Aug 02 '18 07:08 infohata

Remove this authorization, it is ignored:

    }, authorization);
} catch (e) {

Not sure, when I run this I get authorizations as expected:

eos.transaction(['eosio', 'eosio.token'], contracts => {
  contracts.eosio.voteproducer('inita', '', ['initb'], {authorization: 'initc'});
  contracts.eosio_token.transfer('inita', 'initb', '1.0000 SYS', '', {authorization: 'initd'});
}, {broadcast: false, sign: false}).then(tr => console.log(JSON.stringify(tr, null, 2)))
{
  "transaction_id": "2636c1a6bbbe4269cefc816c934eddcedc766733c9f6ac7853eb08f9f2eaa180",
  "broadcast": false,
  "transaction": {
    "compression": "none",
    "transaction": {
      "expiration": "2018-08-03T14:10:19",
      "ref_block_num": 14536,
      "ref_block_prefix": 776522054,
      "net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [
        {
          "account": "eosio",
          "name": "voteproducer",
          "authorization": [
            {
              "actor": "initc",
              "permission": "active"
            }
          ],
          "data": {
            "voter": "inita",
            "proxy": "",
            "producers": [
              "initb"
            ]
          }
        },
        {
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [
            {
              "actor": "initd",
              "permission": "active"
            }
          ],
          "data": {
            "from": "inita",
            "to": "initb",
            "quantity": "1.0000 SYS",
            "memo": ""
          }
        }
      ],
      "transaction_extensions": []
    },
    "signatures": []
  }
}

jcalfee avatar Aug 03 '18 14:08 jcalfee

Yes, removed works as intended, however in eosjs it is documented to use authorization of transaction at the top level

infohata avatar Aug 03 '18 14:08 infohata

Providing authorization to the transaction did not cause any issue, it was ignored. I can however put a warning log message there so it can help catch this mistake. I'm calling everything "options" so that can get confusing. If you look at the usage of options I think the README works. I'll look at making it easier though. Thanks for the feedbak.

jcalfee avatar Aug 03 '18 15:08 jcalfee

@infohata, do you have an opinion here? https://github.com/EOSIO/eosjs/issues/301#issuecomment-412388025

jcalfee avatar Aug 13 '18 21:08 jcalfee