archethic-node icon indicating copy to clipboard operation
archethic-node copied to clipboard

Smart Contracts: Condition transaction check even if no trigger

Open bchamagne opened this issue 1 year ago • 2 comments

Description

The condition transaction should be checked even if there are no actions triggered_by: transaction block. So a transaction that have a recipient with the following contract:

@version 1 
condition transaction: [ 
  previous_public_key: "0001CBDCFF8AC44F24450F693743FB9C7F819985E861B13C61D98AB9A2C8E881B349",
]

can only be validated if it is the direct descendant of 0001CBDCFF8AC4...

ps: similar to https://github.com/archethic-foundation/archethic-node/issues/789 but is not quite the same thing. I believe the mentionned issue wants a condition input to be able to filter the inputs coming in (without recipient).

bchamagne avatar Jun 06 '23 14:06 bchamagne

Example of use case. We create a SC to manage a messenger discussion. Only the members of a discussion can send a transaction to the smart contract (we check the public key) If someone who is not in the member list, tries to send a tx to the SC, the tx is rejected.

For the moment we need to declare an empty actions triggered_by: to allows the SC to check the condition transaction, but we don't need to execute an action.. just filter the contract inputs

              @version 1
              condition transaction: [
                previous_public_key: List.in?([
                ${adminsPubKey.map((key) => '"$key"').join(', ')}
               ], 
                Chain.get_genesis_public_key(transaction.previous_public_key)
                )
              ]

              actions triggered_by: transaction do
              end

redDwarf03 avatar Jun 06 '23 14:06 redDwarf03

I think #789 could be integrated as well in the scope

samuelmanzanera avatar Jun 08 '23 08:06 samuelmanzanera