sero-cash / pullup

SERO decentralized light wallet for PC
pullup-ruby.vercel.app
14 stars 12 forks source link

Feature request: Import SERO Wallet keystore in SERO Pullup #4

Open kriswebdev opened 2 years ago

kriswebdev commented 2 years ago

SERO Wallet is taking a crazy amount of time to do the full node sync.

In the meantime, if the address has been used to mine/receive funds, it is impossible to transfer those funds.

It seems keystore files are incompatible between both wallets ("Do not import accounts between each other as the account files cannot be mixed") despite the fact that the keystore files look the same, which is a big concern. I understand the new light wallets rely on mnemonic phrase and perhaps that's the reason of this incompatibility but we should have a way to import an SERO Wallet in Pullup.

I can help with the dev if you explain me what to do.

EDIT: What I don't understand is why SERO Wallet uses the keyfile plain "address" (87 chars) JSON field as the "Public Address" of the account in the interface, while SERO Pullup uses something else (132 chars) as the "Main Address" of the account. This something else being mainPkr := self.createPkrHash(w.Accounts()[0].Tk.ToTk(), 1) which is a SHA-3 hash and other operations applied on the keystore "tk" JSON field. Maybe all these tokens are equivalent?

kriswebdev commented 2 years ago

Well that was really a pain to understand but I managed to work around this issue.

Base issue: Unable to view the wallet mining funds in SERO Pullup after importing the keystore. Context: The SERO Wallet "Public Address" was used for mining. It is not practical to have a SERO Wallet full node sync in a reasonable amount of time. The pool doesn't report old transaction hashes.

Lesson learnt: Don't use SERO Wallet just to have a wallet, use SERO Pullup on Windows, even if you're a Linux guy. It takes >5 weeks on SSD to get a full node sync. The node sync speed will decrease dramatically with time/additional blocks and the blockchain size is clearly over 100GB currently.

I believe SERO Wallet should not promote the use of the wallet address, while Pullup uses a non-random "PK" address as the main public key. The latter should be used for mining. If the SERO Wallet "Public Address" is used on pools like SERO Pool, the pool will generate a random PKr for payouts from the wallet address, which Pullup can't find as Pullup needs to know each PKr address to retrieve funds and it didn't generate it. A full sync SERO Wallet may be able to find those funds by analyzing each transaction. I abandoned before since SERO Wallet now takes >5 weeks to do a full sync on SSD.

So in the end the easiest way to manage this issue is to find and import each TxHash of each payout in SERO Pullup. SERO Pool unfortunately only publishes the last 30 payouts, but they tend to use a relatively fixed source payment address since early October 2021 and only process payouts twice a day. So all transactions hashes originating from this address can be found on the blockchain, using the network API, and then imported in Pullup.

Workaround: So if someone is stuck with coins in their SERO Wallet and unable to cash out due to the absence of node sync:

  1. Copy your SERO Wallet keystore file (it is in some sub-folder of your profile folder in Linux, sub-folder is named keystore) and remember your password
  2. Download SERO Pullup, install it on Windows (Mac not tested)
  3. Launch Pullup, click Backup, close Pullup
  4. Paste the keystore file on the Pullup keystore folder
  5. Launch Pullup

The wallet will be imported but without coins. Now you need to get your coins back from the TxHashes.

If you've mined with SERO Pool, you have the last 30 transactions TxHash in your payment history on their website.

  1. Import each TxHash from your mining pool payment history using Pullup "Sync Tx By Hash" button

Yes that's long and boring. :face_with_spiral_eyes: But it works. There's a mass import script in step 10 if needed.

You don't have all your TxHashes? (e.g. more than 30 payments from SERO Pool), read the rest; otherwise skip to step 11.

  1. Find the PK address that was used either by the sender or the receiver

Note: SERO Pool uses a random and changing PK address (PKr...) for the receiver when the wallet public address is provided for mining. However the payout source address doesn't change frequently so transaction IDs can be recovered from it.

If you don't have all your payouts TxHash, you need to find the "PK" address your sender/mining pool sent you coins from. Look at some recent and old payouts on the pool. Go on SERO Explorer transaction and look for the "From" address of these payouts. FYI, the transaction destination addresses are the "PKr" in the the transaction "Stx" info, but we won't use it as they are randomly generated from your wallet address so you don't know if they belong to you.

8. Convert the PK address from Hex to Base58

EDIT: From address is already in Base58 on SERO Explorer.

First you need to convert your hexadecimal PK address to Base58. Use whatever tool you want for this. That's a public address so there's no risk. Google "hex to base58 online decoder". You may need to remove leading "0x" before converting.

  1. Find the transactions' TxHash linked to the PK address

Install python and python requests:

python3 -m pip install requests

Open a python console and query the light wallet API (replace MyPKAddressHereInBase58Format by the PK address found previously):

import json
import requests
thepk='PKAddressHereInBase58Format'
z=requests.post('https://f-light.seronode.io', json={"id":0,"jsonrpc":"2.0","method":"light_getOutsByPKr","params":[[thepk],1,None]})
j=z.json()
for item in j['result']['BlockOuts']:
  print(item['Data'][0]['TxInfo']['TxHash'])

(press Enter twice)

  1. Automatically import each TxHash in Pullup (see step 6)

Copy the result of the TxHash found previously in a file (e.g. txhashes.txt), 1 line per hash.

After installing python, and python requests using pip, edit and run the following python script:

Edit the 3 variables of the following python script as per the comments then run it while SERO Pullup is launched.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
import requests
import time

filename_tx_hash=r'C:\path\to\txhashes.txt' # File containing Tx Hases to import in SERO Pullup wallet
sign='' # Get this info by opening SERO Pullup > Right click anywhere on page > Inspect > Network > Click on some request > Payload > Search for for "sign" value (64 bytes long hex encoded)
myaddress='' # Your Base58 wallet ("Account") address: Open SERO Pullup backup folder > keystore folder > open file with text editor > Search for "address" value (87 bytes long Base58 encoded)

with open(filename_tx_hash) as file_tx_hash:
    for tx_hash in file_tx_hash:
        tx_hash=tx_hash.rstrip()
        print(tx_hash,end=' ')
        try:
            z=requests.post('http://127.0.0.1:2345/tx/addOut', json={"base":{"timestamp":1234567,"sign":sign},"biz":{"from":myaddress,"tx_hash":tx_hash},"page":{}})
            j=z.json()
            print(j['base']['code']+' '+j['base']['desc'])
        except Exception as e:
            print('EXCEPTION ',end=' ')
            print(e)
        time.sleep(1) # Wait 1 sec between requests
  1. Stop using your SERO Wallet "Public address" for mining/transactions to avoid having to go though this hell again, and start to use SERO Pullup "Main address" instead.

  2. You will certainly have to redo all this if you restore your wallet somewhere else. You'd better transfer your funds to a new Pullup wallet address. Or at least keep a copy of the PK address and TxHashes previously found.