- Remove memo_from and memo_to fields from the transfers db table.
- Added method to obtain WIF key from the authorities db table. - Make use of WIF in TransfersLoader to decrypt memo messages before saving them into the db.
This commit is contained in:
parent
61aeca0575
commit
d4e96f98e6
6 changed files with 39 additions and 16 deletions
|
@ -293,7 +293,7 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
|||
|
||||
val authority = Authority(0, userId, authorityType, encryptedWIF, encryptedBrainKey, encryptedSequenceNumber)
|
||||
|
||||
val authorityRepository = AuthorityRepository(application)
|
||||
val authorityRepository = AuthorityRepository(this)
|
||||
authorityRepository.insert(authority)
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import androidx.room.Dao
|
|||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import cy.agorise.bitsybitshareswallet.entities.Authority
|
||||
import io.reactivex.Single
|
||||
|
||||
@Dao
|
||||
interface AuthorityDao {
|
||||
|
@ -12,5 +13,8 @@ interface AuthorityDao {
|
|||
fun insert(authority: Authority)
|
||||
|
||||
@Query("SELECT * FROM authorities")
|
||||
fun getAllAuthorities(): LiveData<List<Authority>>
|
||||
fun getAll(): LiveData<List<Authority>>
|
||||
|
||||
@Query("SELECT encrypted_wif FROM authorities WHERE user_id=:userId AND authority_type=:authorityType")
|
||||
fun getWIF(userId: String, authorityType: Int): Single<String>
|
||||
}
|
|
@ -21,7 +21,7 @@ interface TransferDao {
|
|||
fun getCount(): Single<Int>
|
||||
|
||||
@Query("SELECT * FROM transfers")
|
||||
fun getAllTransfers(): LiveData<List<Transfer>>
|
||||
fun getAll(): LiveData<List<Transfer>>
|
||||
|
||||
@Query("DELETE FROM transfers")
|
||||
fun deleteAll()
|
||||
|
|
|
@ -16,7 +16,5 @@ data class Transfer (
|
|||
@ColumnInfo(name = "destination") val destination: String, // TODO should be foreign key to UserAccount
|
||||
@ColumnInfo(name = "transfer_amount") val transferAmount: Long,
|
||||
@ColumnInfo(name = "transfer_asset_id") val transferAssetId: String, // TODO should be foreign key to Asset
|
||||
@ColumnInfo(name = "memo") val memo: String,
|
||||
@ColumnInfo(name = "memo_from_key") val memoFromKey: String,
|
||||
@ColumnInfo(name = "memo_to_key") val memoToKey: String
|
||||
@ColumnInfo(name = "memo") val memo: String
|
||||
)
|
|
@ -12,8 +12,10 @@ import androidx.lifecycle.LifecycleObserver
|
|||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import cy.agorise.bitsybitshareswallet.entities.Transfer
|
||||
import cy.agorise.bitsybitshareswallet.models.HistoricalOperationEntry
|
||||
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
|
||||
import cy.agorise.bitsybitshareswallet.repositories.TransferRepository
|
||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
|
||||
import cy.agorise.graphenej.*
|
||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||
import cy.agorise.graphenej.api.android.NetworkService
|
||||
|
@ -31,6 +33,7 @@ import io.reactivex.schedulers.Schedulers
|
|||
import org.bitcoinj.core.DumpedPrivateKey
|
||||
import org.bitcoinj.core.ECKey
|
||||
import java.util.*
|
||||
import javax.crypto.AEADBadTagException
|
||||
|
||||
/**
|
||||
* This class is responsible for loading the local database with all past transfer operations of the
|
||||
|
@ -49,6 +52,9 @@ import java.util.*
|
|||
class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Lifecycle) : LifecycleObserver {
|
||||
private val TAG = this.javaClass.name
|
||||
|
||||
/** Constant that specifies if we are on debug mode */
|
||||
private val DEBUG = false
|
||||
|
||||
/* Constant used to fix the number of historical transfers to fetch from the network in one batch */
|
||||
private val HISTORICAL_TRANSFER_BATCH_SIZE = 100
|
||||
|
||||
|
@ -83,6 +89,9 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
|||
/** Repository to access and update Transfers */
|
||||
private var transferRepository: TransferRepository? = null
|
||||
|
||||
/** Repository to access and update Transfers */
|
||||
private var authorityRepository: AuthorityRepository? = null
|
||||
|
||||
/* Network service connection */
|
||||
private var mNetworkService: NetworkService? = null
|
||||
|
||||
|
@ -123,8 +132,6 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
|||
*/
|
||||
private var mShouldUnbindNetwork: Boolean = false
|
||||
|
||||
private val DEBUG = false
|
||||
|
||||
private var lastId: Long = 0
|
||||
|
||||
private var lastEquivalentValueBlockNum: Long = 0
|
||||
|
@ -161,12 +168,23 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
|||
init {
|
||||
this.mLifeCycle.addObserver(this)
|
||||
transferRepository = TransferRepository(mContext!!)
|
||||
authorityRepository = AuthorityRepository(mContext!!)
|
||||
|
||||
val pref = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
val userId = pref.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")
|
||||
if (userId != "") {
|
||||
mCurrentAccount = UserAccount(userId)
|
||||
// wifkey = database.getWif(mContext, mCurrentAccount, AuthorityType.MEMO) TODO RESTORE
|
||||
val disposable = authorityRepository!!.getWIF(userId!!, AuthorityType.MEMO.ordinal)
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { encryptedWIF ->
|
||||
try {
|
||||
wifKey = CryptoUtils.decrypt(mContext!!, encryptedWIF)
|
||||
} catch (e: AEADBadTagException) {
|
||||
Log.e(TAG, "AEADBadTagException. Class: " + e.javaClass + ", Msg: " + e.message)
|
||||
}
|
||||
|
||||
}
|
||||
mDisposable = RxBus.getBusInstance()
|
||||
.asFlowable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -364,11 +382,8 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
|||
op.to.objectId,
|
||||
op.assetAmount.amount.toLong(),
|
||||
op.assetAmount.asset.objectId,
|
||||
memo.plaintextMessage,
|
||||
memo.source.toString(),
|
||||
memo.destination.toString()
|
||||
memo.plaintextMessage
|
||||
)
|
||||
// TODO build transfer object, save Wif in ImportBrainkeyActivity
|
||||
|
||||
transfers.add(transfer)
|
||||
}
|
||||
|
@ -624,6 +639,7 @@ class TransfersLoader(private var mContext: Context?, private val mLifeCycle: Li
|
|||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
internal fun onDestroy() {
|
||||
Log.d(TAG, "Destroying TransfersLoader")
|
||||
if (mDisposable != null && !mDisposable!!.isDisposed) mDisposable!!.dispose()
|
||||
if (mShouldUnbindNetwork) {
|
||||
mContext!!.unbindService(mNetworkServiceConnection)
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package cy.agorise.bitsybitshareswallet.repositories
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.os.AsyncTask
|
||||
import cy.agorise.bitsybitshareswallet.daos.AuthorityDao
|
||||
import cy.agorise.bitsybitshareswallet.daos.BitsyDatabase
|
||||
import cy.agorise.bitsybitshareswallet.entities.Authority
|
||||
import io.reactivex.Single
|
||||
|
||||
class AuthorityRepository internal constructor(application: Application) {
|
||||
class AuthorityRepository internal constructor(context: Context) {
|
||||
|
||||
private val mAuthorityDao: AuthorityDao
|
||||
|
||||
init {
|
||||
val db = BitsyDatabase.getDatabase(application)
|
||||
val db = BitsyDatabase.getDatabase(context)
|
||||
mAuthorityDao = db!!.authorityDao()
|
||||
}
|
||||
|
||||
|
@ -19,6 +20,10 @@ class AuthorityRepository internal constructor(application: Application) {
|
|||
insertAsyncTask(mAuthorityDao).execute(authority)
|
||||
}
|
||||
|
||||
fun getWIF(userId: String, authorityType: Int): Single<String> {
|
||||
return mAuthorityDao.getWIF(userId, authorityType)
|
||||
}
|
||||
|
||||
private class insertAsyncTask internal constructor(private val mAsyncTaskDao: AuthorityDao) :
|
||||
AsyncTask<Authority, Void, Void>() {
|
||||
|
||||
|
|
Loading…
Reference in a new issue