I reply to all queries on the forums and via email, once per day, Monday to Friday (not weekends).

If you are new here, please see some information on how to ask for support. Thank you!

Repair a missing withdrawal TXID

dashed-slug.net Forums TurtleCoin Adapter extension support Repair a missing withdrawal TXID

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #10055
    LeinAd
    Participant

    is there an easy way to set manual withdraws ( resoted wallet with keys) easy in db? or do i need to write the withdraw by hand in the db?

    #10062
    alexg
    Keymaster

    Hello,

    The recommended way to insert a new withdrawal using PHP is via the PHP API.

    You also have the option to place a withdrawal via the JSON-API. If calling from the frontend, you can directly call the API. The login cookie in your browser will provide authentication. If you are calling from elsewhere, you need to have the user’s bearer token (you can get the bearer token from the user’s profile or from a get_nonces call while logged in with cookies. See the documentation for details.

    If you want to directly insert a withdrawal into the DB you can also do this, but know that the SQL tables are going to be removed in wallets6, which will be out in a few months.

    The PHP-API and JSON-API are currently being re-engineered for the new design and will remain, marked deprecated, for a long time, to allow a smooth transition to the new architecture. In fact, part of the reason that development is taking so long is because I am doing a test-driven re-development of these two APIs to ensure compatibility.

    with regards

    #10069
    LeinAd
    Participant

    this withdraw is in history and i need it to add into the db.. when i do the way above it tricker a new withdraw then or dont?

    #10072
    alexg
    Keymaster

    If you submit a withdrawal request via the JSON-API or PHP-API, then a new withdrawal row will be entered in the DB in an unconfirmed state. The cron job will then progress it to a pending state. If the adapter is unlocked and if the hot wallet has enough unlocked funds, and if the available user balance is sufficient, then the withdrawal will be executed by a cron job. It will get the done or failed state.

    Why do you need to enter to the DB a withdrawal that has already occurred?

    If a withdrawal has already occurred on your hot wallet, independently from the plugin, this cannot be safely mapped to a user balance. This is because only the plugin knows how much balance a user has, and what portion of it is not locked into exchange orders or other pending transactions. Primarily due to the internal transfers and exchange trades features, you cannot expect a user’s balance to correspond to a particular blockchain address.

    The only deposits and withdrawals that should occur on your hot wallet besides user transactions are the cold storage transactions. That is, you can safely do transactions to control the percentage of online reserves, and these are not reflected in the DB. Do not do any other transactions with the wallet attached to the plugin.

    It sounds like you are trying to hack the db in a way that will result in lost funds.

    Please describe in more detail what you are trying to do and I will be able to provide guidance on whether what you are doing is safe and whether there is a better way.

    #10076
    LeinAd
    Participant

    Why do you need to enter to the DB a withdrawal that has already occurred?

    because this withdraw i did in a “separate” wallet files, restored with keys to try something out. btw for some reason i also have the problem that the hotwallet balance is not so hight like user balance. i am resyncing the adapter to see where the coins are, but i can only tell you more tomorrow

    #10089
    alexg
    Keymaster

    If this is a test or integration system, it’s much easier to start from scratch.

    The second problem is likely tied to the first one: If a user withdrew some funds and this is now not reflected in the DB, then of course the hot wallet balance would be less than the total of user balances. Another likelihood is if the withdrawal fee that you set in the plugin is less than the actual transaction fee paid. Again, just delete everything and start from scratch.

    If you know exactly which withdrawal is missing, and you are sure that this is your only problem, then sure, you can insert it into the DB using an insert statement. It would look something like:

    INSERT INTO wp_wallets_txs(category,account,address,txid,symbol,amount,fee,status,created_time,updated_time)
    VALUES('withdraw',$user_id,$address,$txid,$symbol,$amount,$withdrawal_fee,'done',NOW(),NOW());

    where you’d replace all the $variables with the actual values for that transaction.

    What I’d do is this:

    1. Keep a backup of the DB.

    2. Try inserting the withdrawal manually.

    3. If things look good, great.

    4. If not, start again with a new wallet. Delete all rows in the transactions table and addresses table with symbol equal to your coin’s symbol. Only deposit funds using user deposit addresses. Only withdraw funds using the plugin. If you do this, there won’t be any inconsistencies.

    Let me know if you need further help with this.

    with regards

    #10093
    LeinAd
    Participant

    INSERT INTO wp_wallets_txs(category,account,address,txid,symbol,amount,fee,status,created_time,updated_time)
    VALUES(‘withdraw’,$user_id,$address,$txid,$symbol,$amount,$withdrawal_fee,’done’,NOW(),NOW());

    when i do this, it gives the user an negative aviable balance

    #10095
    alexg
    Keymaster

    Yes, of course. You are adding a withdrawal transaction that removes from the user’s balance.

    If your balance is negative, it means that this is not the only problem with your database.

    Can you start over?

    #10098
    LeinAd
    Participant

    i mean this user here:

    Balance: NIMB 46976180.93 Available balance: NIMB 50.00
    here i did a withdraw to him direct from his wallet but with this I have “deceived” the database
    When i try to tell the wihdrwa the database (so that frontend shows correct amounts i got this:

    Balance: NIMB 6620913.93 Available balance: NIMB -40355217.00

    so it is deducted on both sides. Balance and aviable balance. but it should only be corrected in the balance.
    Do you know what I mean?

    #10102
    alexg
    Keymaster

    What you are describing is the expected behavior. If you place a new done withdrawal, then that will affect the user’s balance AND available balance.

    I think there is a misunderstanding here, so let me explain what the available balance is:

    If you enter a new transaction (categories deposit,withdraw,move,trade) in the done state for a user, it will affect the user balance. The available balance is simply the user balance minus any funds locked in pending outgoing transactions (pending withdrawals and/or pending internal transfers to other users), or in open orders if you are using the exchange extension: For example, say the user has 10 coins. Now the user has placed a pending withdrawal of 1 coin, and has placed a sell order for another 2 coins in a market, so now the available balance will be 7 coins. If later, the exchange order is cancelled, and the withdrawal fails or is cancelled, then the user’s balance will stay at 10, and the user’s available balance will again be 10 coins. Instead, if the withdrawal succeeds and the order gets filled, the users balance will become 7 coins and the available balance will stay at 7. Hope this is clearer.

    My suggestion is this:

    1. First determine what the problem is: Do you think that a withdrawal or other transaction was not recorded in the plugin’s ledger? If so, why was that? Was there a crash? Don’t try to fix a problem you don’t understand because you can make it worse.

    2. Once you determine what information is missing from the database and why, only then edit the database.

    I don’t know what happened on your system. First determine what transactions you think the user did, and which ones are missing and why. If you can do that, I can tell you how to reinsert the data to the DB.

    with regards

    #10103
    LeinAd
    Participant

    Ok, I looked into it a bit more and something is odd (unrelated to the manual retraction thing above). I was wondering why my hotwallet balance is relatively low and went through all the wallets to check. As an example, user xyz has never made a deposit to his wallet (except for a few coins from the faucet). My admin channel tells me that he has 1250 coins (from the aforementioned faucet). But the check of his wallet file showed over 10 million coins.
    I have used : curl -X GET “http://127.0.0.1:8070/transactions/hash/0224e94c93de15f63516cce79e935384aa6a59fb211aa81bc710a8809bc52f57” -H “accept: application/json” -H “X-

    and saw that the transactions were posted “wildly”. This currently affects three wallet files / addresses.

    on attachmend pics you can see what i mean. and this amount have to be on hotwallet

    Attachments:
    You must be logged in to view attached files.
    #10106
    LeinAd
    Participant

    ah and ty for response on one pic above i can better explain what was happen.. you see the picture from the wallet. I did a withdraw to the user direct in this wallet file (not this on picture – other wallet) . because i did this this withdraw cannot be in the database, the wd request didnt come over plugin.. so the plugin dont know the transaction and show the “older” balance. Thats why i asked how to fix this.

    thank you for your time and greetings from cold germany :o)

    #10120
    alexg
    Keymaster

    Hello,

    OK, this discussion is getting somewhat confusing for me, so please allow me to summarize the points I am not sure about. Please try to answer all of the questions carefully in as much detail as possible so I can understand.

    1. You mentioned that a user has 1250 coins from the faucet and has never deposited funds. You mentioned also that his wallet file showed over 10 million coins. Can you please explain what you mean by this? The wallet file is there to back the balances of all users, not just one user. Can you please summarize, from the beginning, why you believe that there is a problem with this user’s balance? Why do you think that this user has performed a withdrawal, if there is no withdrawal in the plugin’s ledger? Could it be that the withdrawals you see in the hot wallet are from other users?

    2. When you issued a curl API call to the /transactions/hash endpoint, you got back details on a specific blockchain transaction. This is unrelated to any user balances. Could this be a withdrawal initiated by another user?

    3. Furthermore, as mentioned before, the available balance will be less that the user balance, if the user has pending outgoing transactions, or if the user has placed orders on the exchange. Is this the case for your user? Did you check?

    4. I have mentioned that there is no one-to-one correlation between address balances on the blockchain and user balances, because of off-chain transactions. Can you please confirm if you understand this, or if you want me to explain it further?

    5. Can you please explain what you meant by “because this withdraw i did in a “separate” wallet files, restored with keys to try something out”?

    6. Are you only experiencing issues with withdrawals from one user? Do other users have no problems with withdrawals? Did withdrawals succeed in your integration/test environment or during development of your site?

    To summarize, unfortunately I do not know if I can help you in this situation. There are too many moving parts here.

    What I would do in your situation would be this:

    – Stop hacking the database and restore the DB backup.
    – Move all the funds out of the hot wallet.
    – Remove the empty wallet file (but keep it somewhere safe just in case!).
    – Let the adapter create a new wallet file for the site.
    – Move the funds into the base address of this new wallet file. Do not use any user deposit addresses for this.
    – Click on Wallets -> Adapters -> (your adapter) -> Renew deposit addresses.
    – Refrain from performing other transactions with this wallet file. Only move funds to and from the cold storage wallet if needed.

    This should ensure no more problems from now on. If you encounter an issue with withdrawals after doing this, do not edit the database, and notify me immediately. Let’s solve one issue at a time, so we know what we’re doing.

    with regards

    #10133
    alexg
    Keymaster

    See here for the root cause of this issue.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.