ArkEcosystem / core

The ARK Core Blockchain Framework. Check https://learn.ark.dev for more information.
https://ark.io
MIT License
338 stars 286 forks source link

Empty wallet created when querying transactions on v1 #1949

Closed alexbarnsley closed 5 years ago

alexbarnsley commented 5 years ago

Describe the bug When querying the v1 /api/transactions endpoint, it creates an empty wallet. I have not tested on v2 endpoints

To Reproduce Steps to reproduce the behavior:

  1. Go to https://dexplorer.ark.io:8443/api/accounts?address=<COLD_WALLET_ADDRESS> - it will return "Account not found"
  2. Go to https://dexplorer.ark.io:8443/api/transactions?recipientId=<COLD_WALLET_ADDRESS>&senderId=<COLD_WALLET_ADDRESS>&orderBy=timestamp:desc&offset=0&limit=50
  3. Go back to https://dexplorer.ark.io:8443/api/accounts?address=<COLD_WALLET_ADDRESS> - it will return a cold wallet object response (see below)
{
  "account": {
    "address": "DLWeBuwSBFYtUFj8kFB8CFswfvN2ht3yKn",
    "publicKey": null,
    "secondPublicKey": null,
    "username": null,
    "balance": "0",
    "unconfirmedBalance": "0",
    "multisignatures": [

    ],
    "u_multisignatures": [

    ],
    "unconfirmedSignature": 0,
    "secondSignature": 0
  },
  "success": true
}

Expected behavior The wallet should return "Account not found" still

tpscrpt commented 5 years ago

https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/versions/1/accounts/transformer.ts

tpscrpt commented 5 years ago

boiled it down to senderId, as running the above queries without it doesn't seem to respond with the template model

tpscrpt commented 5 years ago

this.database.manager.findByAddress() might be caching upon conversion from senderId to senderPublicKey

tpscrpt commented 5 years ago
    public findByAddress(address) {
        if (!this.byAddress[address]) {
            this.byAddress[address] = new Wallet(address);
        }

        return this.byAddress[address];
    }

Then on subsequent round would not create a new wallet, but return the newly created wallet?

Btw, this is definitely cached behaviour as I tried with the address you provided and is was not found

tpscrpt commented 5 years ago

after running the second command but only with senderId, the third command indeed returns a

{
  "account": {
    "address": "DLWeBuwSBFYtUFj8kFB8CFswfvN2ht3yKn",
    "publicKey": null,
    "secondPublicKey": null,
    "username": null,
    "balance": "0",
    "unconfirmedBalance": "0",
    "multisignatures": [],
    "u_multisignatures": [],
    "unconfirmedSignature": 0,
    "secondSignature": 0
  },
  "success": true
}
tpscrpt commented 5 years ago

So, from what I can tell: querying legacy with senderId triggers the creation of a Wallet object in this.byAddress of core-database/wallet-manager set to a default. Then, a query to accounts?address=COLD will database.wallets.findById() it and return the empty object, but not before transforming it to fit the v1 spec.

I could be miles off in any of these statements, this is some preliminary detective work for the team.

tpscrpt commented 5 years ago

Get transactions: https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/versions/1/transactions/methods.ts#L5

FindAllLegacy: https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/repositories/transactions.ts#L70

PublicKeyFromAddress: https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/repositories/transactions.ts#L486

FindByAddress (caches new crypto model): https://github.com/ArkEcosystem/core/blob/develop/packages/core-database/src/wallet-manager.ts#L70

Crypto Model: https://github.com/ArkEcosystem/core/blob/develop/packages/crypto/src/models/wallet.ts#L48

FindById on v1: https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/versions/1/accounts/methods.ts#L19

Transformer: https://github.com/ArkEcosystem/core/blob/develop/packages/core-api/src/versions/1/accounts/transformer.ts

tpscrpt commented 5 years ago

I will not be fixing this today.