dashed-slug.net › Forums › TurtleCoin Adapter extension support › Repair a missing withdrawal TXID
Tagged: custom code, json api, php api, withdrawal
- This topic has 13 replies, 2 voices, and was last updated 2 years ago by alexg.
February 24, 2021 at 10:42 am #10055
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?February 25, 2021 at 7:19 am #10062
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 regardsFebruary 25, 2021 at 9:57 am #10069
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?February 25, 2021 at 11:19 am #10072
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
unconfirmedstate. The cron job will then progress it to a
pendingstate. 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
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.February 25, 2021 at 2:34 pm #10076
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 tomorrowFebruary 26, 2021 at 9:53 am #10089
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
$variableswith 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 regardsFebruary 26, 2021 at 12:07 pm #10093
INSERT INTO wp_wallets_txs(category,account,address,txid,symbol,amount,fee,status,created_time,updated_time)
when i do this, it gives the user an negative aviable balanceFebruary 26, 2021 at 12:26 pm #10095
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?February 26, 2021 at 1:39 pm #10098
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?February 26, 2021 at 5:03 pm #10102
What you are describing is the expected behavior. If you place a new
donewithdrawal, 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
trade) in the
donestate 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 regardsFebruary 26, 2021 at 6:25 pm #10103
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.February 26, 2021 at 6:30 pm #10106
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)March 1, 2021 at 8:29 am #10120
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/hashendpoint, 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 regardsMarch 2, 2021 at 7:42 am #10133
- You must be logged in to reply to this topic.