eos icon indicating copy to clipboard operation
eos copied to clipboard

When does the account require the eosio.code permission to do some action on its own?

Open NeverLandFly opened this issue 8 years ago • 5 comments

I have run a contract on user1 and get the following error. Exception Details: 3090003 unsatisfied_authorization: Provided keys, permissions, and delays do not satisfy declared authorizations transaction declares authority '{"actor":"user1","permission":"owner"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [{"actor":"user1","permission":"eosio.code"}], It seems weird, and after I add the permission [email protected]. The nodeos still reported the same error.

NeverLandFly avatar Jul 27 '18 07:07 NeverLandFly

So if you do cleos get account user1, do you see [email protected] satisfying user1@active? Please note that [email protected] must be the satisfying permission for user1@active here, not as a child permission.

andriantolie avatar Jul 27 '18 08:07 andriantolie

@andriantolie It worked! Thanks

NeverLandFly avatar Jul 27 '18 13:07 NeverLandFly

@NeverLandFly How you solved this?

gberlian avatar Aug 19 '18 21:08 gberlian

Solved like this

const addAuthToAccountPermission = async({
  eosInstance,
  accountName, permissionName,
  accountAuth = null, keyAuth = null
}) => {
  if (!accountName || !permissionName) throw new Error()
  if (accountAuth == null && keyAuth == null) throw new Error()

  const account = await eosInstance.getAccount(accountName)

  const { required_auth, parent, perm_name } = account.permissions
    .find(p => p.perm_name === permissionName)

  let update_auth = {
    accounts: [],
    keys: []
  }

  if (typeof accountAuth === 'object') {
    update_auth.accounts.push({
      permission: accountAuth,
      weight: 1
    })
  }

  if (typeof keyAuth === 'string') {
    update_auth.keys.push({
      key: keyAuth,
      weight: 1
    })
  }

  const transaction = await eosInstance.transaction(tx => {
    tx.updateauth({
      account: accountName,
      permission: perm_name,
      parent: parent,
      auth: {
        threshold: required_auth.threshold,
        waits: required_auth.waits,
        accounts: [
          ...required_auth.accounts,
          ...update_auth.accounts
        ],
        keys: [
          ...required_auth.keys,
          ...update_auth.keys
        ]
      }
    }, { authorization: `${accountName}@active` })
  })

  return transaction
}

gberlian avatar Aug 19 '18 22:08 gberlian

@7flash nice solution!

NeverLandFly avatar Aug 20 '18 01:08 NeverLandFly