Decoding event log issue

So I have this weird thing going on. I have a simple Sophia function with following implementation:

stateful entrypoint add_wallet(wallet: address) =
        only_owner()
        put(state{ activeWallets[wallet] = true })
        Chain.event(WalletAdded(wallet))

I called this function on testnet: th_Qthc5exifqSCHMJrgvsFPPEAvuqzfLkdiU5ogZx6oHWpqmLUT

When I decode call data I get following output:

call data decoded {
  arguments: [
    {
      type: 'address',
      value: 'ak_168AFjUnvqaSc3Ghwrair3DNhy85ohBAersvFGsvkd2UafVo1'
    }
  ],
  function: 'add_wallet'
}

And this is fine, address ak_168AFjUnvqaSc3Ghwrair3DNhy85ohBAersvFGsvkd2UafVo1 is indeed the address I provided when calling add_wallet() function. Now here’s the thing. Add wallet function emits an event, it’s simply the same address parameter provided while calling the function.

But when I fetch tx info for this transaction I get this log data:

info.log [
  {
    address: 'ct_uqcLxANrQPjhMP7ejQusQkMx4MNkGpsV95u4X9EyBJCCHmwLU',
    data: 'cb_Xfbg4g==',
    topics: [
      '10290170136087658066813070938628590437785932593845968247138772986276878049142',
      '90723028085888713405399571369897167020939216238564042413234018321205193469'
    ]
  }
]

Now I try to decode this log data using by calling Crypto.addressFromDecimal(topics[1]) (docs) and as a result I get:

ak_68AFjUnvqaSc3Ghwrair3DNhy85ohBAersvFGsvkd2VN29fH

It is different address than the one provided while calling add_wallet() function, but I also noticed some parts of these addresses overlap and are quite similar. I’m not sure why the decoded address is different and I’d like to know this because I rely heavily on decoding event logs on the platform that we’re building, and so far it was working as expected. This is the first example where I noticed this issue.
One additional thing I noticed, this address that I get when I decode event is not a valid Aeternity address at all! I checked this using Crypto.isAddressValid(). I’d appreciate any help here really, or maybe I’m doing something wrong… Thanks

My best bet is that whatever tool/code you are using have issues with big numbers, as you say, indeed it looks almost correct…

I did double check in a known good language and all seems to be fine:

(aeternity_ct@localhost)17> IntAddress = 90723028085888713405399571369897167020939216238564042413234018321205193469.
90723028085888713405399571369897167020939216238564042413234018321205193469
(aeternity_ct@localhost)18> aeser_api_encoder:encode(account_pubkey, <<IntAddress:256>>).
<<"ak_168AFjUnvqaSc3Ghwrair3DNhy85ohBAersvFGsvkd2UafVo1">>
2 Likes

There are some helper functions in the JS SDK, maybe they can help you aepp-sdk-js/contract-events.md at master · aeternity/aepp-sdk-js · GitHub

1 Like

Thanks guys! I didn’t make much progress though…

@hanssv.chain I see what you mean, but, I’m not using any tools/libraries whatsoever. I take string which I get from tx info (using sdk) and I provide that string as a function parameter to addressFromDecimal() function (again this is also sdk function accepting string, so I know for sure it works and it works well for all the other events I have ever tried decoding). I mean, I don’t do any conversion, processing or something like that.

@philipp.chain I tried those helper functions but I get the same incorrect address again… Here’s the output. I’m so confused right now and starting to think there’s some deeper issue here.

decoded [
  {
    address: 'ct_uqcLxANrQPjhMP7ejQusQkMx4MNkGpsV95u4X9EyBJCCHmwLU',
    data: 'cb_Xfbg4g==',
    topics: [
      '10290170136087658066813070938628590437785932593845968247138772986276878049142',
      '90723028085888713405399571369897167020939216238564042413234018321205193469'
    ],
    name: 'WalletAdded',
    decoded: [ '68AFjUnvqaSc3Ghwrair3DNhy85ohBAersvFGsvkd2VN29fH' ]
  }
]

So, if the function works why don’t you get the right result? I think your definition of works is perhaps wrong?

I’m encoding the same data as you are, and we get different results when using elixir-sdk or js-sdk, so that would be my definition of “doesn’t work” :slight_smile:
Thanks anyway, I’ll try to hack my way around