UnexpectedCharacter
UnexpectedCharacter

Reputation: 129

How can emit a event that is called inside other transaction

I'm trying to emit an event when other transaction has been called. But I can't execute my intentions.

I have the following piece of code:

event TransactionAssetEvent {
  o BlastAsset eventAsset
  o String eventCalledFromTransaction
}

In the logic.js file I have a function that works fine:

async function Transfer(transfer) {
    //Some logic with a asset object

    TransactionAssetEvent(asset, 'Transfer');

    return updateAsset(asset);
}

 /**
 * Emit a notification that a transaction has occurred
 * @param {Object} asset
 * @param {String} eventCalledFromTransaction
 * @transaction
 */
async function TransactionAssetEvent(asset, eventCalledFromTransaction) {
    const factory = getFactory();
    let event = factory.newEvent(org.test', 'TransactionAssetEvent');
    event.eventAsset = asset;
    event.eventCalledFromTransaction = eventCalledFromTransaction;
    emit(event);
}

But I have the following error:

Error: t: Transaction processing function TransactionAssetEvent must have 1 function argument of type transaction.

How can emit an event successfully?

I'm implementing a great flow with the events? Or I'm using in a bad way the events?

I look for other post's but I can't implemented the commented flow

Upvotes: 0

Views: 132

Answers (1)

Chromeium
Chromeium

Reputation: 264

let event = factory.newEvent(org.test', 'TransactionAssetEvent');

should be

let event = factory.newEvent('namespace*', 'TransactionAssetEvent');

namespace is basically the namespace of the file where event TransactionAssetEvent is saved

so for example your line will be

let event = factory.newEvent('org.test.eventModelFile', 'TransactionAssetEvent');

Also you missed a ' in factory.newEvent(org.test', 'TransactionAssetEvent'); it should be factory.newEvent('org.test', 'TransactionAssetEvent');

Upvotes: 2

Related Questions