├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── Dependencies.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── protonsdk ├── .gitignore ├── build.gradle.kts ├── consumer-rules.pro ├── lint.xml ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── metallicus │ │ └── protonsdk │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── metallicus │ │ │ └── protonsdk │ │ │ ├── AccountModule.kt │ │ │ ├── ActionsModule.kt │ │ │ ├── ChainProviderModule.kt │ │ │ ├── CurrencyBalancesModule.kt │ │ │ ├── Proton.kt │ │ │ ├── TokenContractsModule.kt │ │ │ ├── WorkersModule.kt │ │ │ ├── api │ │ │ ├── ESRCallbackService.kt │ │ │ ├── ProtonChainService.kt │ │ │ └── ProtonChainStatsService.kt │ │ │ ├── common │ │ │ ├── Prefs.kt │ │ │ ├── ProtonError.kt │ │ │ ├── ProtonException.kt │ │ │ ├── Resource.kt │ │ │ ├── SecureKeys.kt │ │ │ ├── SingletonHolder.kt │ │ │ └── Status.kt │ │ │ ├── db │ │ │ ├── AccountContactDao.kt │ │ │ ├── AccountDao.kt │ │ │ ├── ActionDao.kt │ │ │ ├── ChainProviderDao.kt │ │ │ ├── DefaultTypeConverters.kt │ │ │ ├── EOSTypeConverters.kt │ │ │ ├── ESRSessionDao.kt │ │ │ ├── ProtonDb.kt │ │ │ ├── ProtonTypeConverters.kt │ │ │ └── TokenContractDao.kt │ │ │ ├── di │ │ │ ├── DaggerInjector.kt │ │ │ ├── ProtonComponent.kt │ │ │ ├── ProtonModule.kt │ │ │ ├── WorkerAssistedModule.kt │ │ │ ├── WorkerKey.kt │ │ │ └── WorkerModule.kt │ │ │ ├── eosio │ │ │ └── commander │ │ │ │ ├── Base58.java │ │ │ │ ├── BitUtils.java │ │ │ │ ├── CryptUtil.java │ │ │ │ ├── GsonEosTypeAdapterFactory.java │ │ │ │ ├── HexUtils.java │ │ │ │ ├── Hmac.java │ │ │ │ ├── PRNGFixes.java │ │ │ │ ├── RefValue.java │ │ │ │ ├── StringUtils.java │ │ │ │ ├── Utils.java │ │ │ │ ├── digest │ │ │ │ ├── GeneralDigest.java │ │ │ │ ├── Ripemd160.java │ │ │ │ ├── Sha256.java │ │ │ │ └── Sha512.java │ │ │ │ ├── ec │ │ │ │ ├── CurveParam.java │ │ │ │ ├── EcCurve.java │ │ │ │ ├── EcDsa.java │ │ │ │ ├── EcFieldElement.java │ │ │ │ ├── EcPoint.java │ │ │ │ ├── EcSignature.java │ │ │ │ ├── EcTools.java │ │ │ │ ├── EosEcUtil.java │ │ │ │ ├── EosPrivateKey.java │ │ │ │ └── EosPublicKey.java │ │ │ │ └── model │ │ │ │ ├── chain │ │ │ │ ├── Action.java │ │ │ │ ├── PackedTransaction.java │ │ │ │ ├── SignedTransaction.java │ │ │ │ ├── Transaction.java │ │ │ │ └── TransactionHeader.java │ │ │ │ └── types │ │ │ │ ├── EosByteReader.java │ │ │ │ ├── EosByteWriter.java │ │ │ │ ├── EosTransfer.java │ │ │ │ ├── EosType.java │ │ │ │ ├── TypeAccountName.java │ │ │ │ ├── TypeActionName.java │ │ │ │ ├── TypeAsset.java │ │ │ │ ├── TypeChainId.java │ │ │ │ ├── TypeName.java │ │ │ │ ├── TypePermissionLevel.java │ │ │ │ ├── TypePermissionName.java │ │ │ │ ├── TypeScopeName.java │ │ │ │ └── TypeSymbol.java │ │ │ ├── model │ │ │ ├── Account.kt │ │ │ ├── AccountContact.kt │ │ │ ├── AccountCpuLimit.kt │ │ │ ├── AccountNetLimit.kt │ │ │ ├── AccountPermission.kt │ │ │ ├── AccountPermissionKey.kt │ │ │ ├── AccountPermissionRequiredAuth.kt │ │ │ ├── AccountRefundsXPRInfo.kt │ │ │ ├── AccountSelfDelegatedBandwidth.kt │ │ │ ├── AccountTotalResources.kt │ │ │ ├── AccountVoterInfo.kt │ │ │ ├── AccountVotersXPRInfo.kt │ │ │ ├── Action.kt │ │ │ ├── ActiveAccount.kt │ │ │ ├── ChainAccount.kt │ │ │ ├── ChainInfo.kt │ │ │ ├── ChainProvider.kt │ │ │ ├── ChainUrlInfo.kt │ │ │ ├── CurrencyBalance.kt │ │ │ ├── EOSError.kt │ │ │ ├── EOSErrorDetail.kt │ │ │ ├── EOSServerError.kt │ │ │ ├── ESRAction.kt │ │ │ ├── ESRSession.kt │ │ │ ├── ESRSessionMessage.kt │ │ │ ├── JsonToBinResponse.kt │ │ │ ├── KYCProvider.kt │ │ │ ├── KeyAccount.kt │ │ │ ├── ProtonESR.kt │ │ │ ├── RequiredKeysResponse.kt │ │ │ ├── SwapPool.kt │ │ │ ├── TokenContract.kt │ │ │ ├── TokenContractRate.kt │ │ │ └── TokenCurrencyBalance.kt │ │ │ ├── repository │ │ │ ├── AccountContactRepository.kt │ │ │ ├── AccountRepository.kt │ │ │ ├── ActionRepository.kt │ │ │ ├── ChainProviderRepository.kt │ │ │ ├── CurrencyBalanceRepository.kt │ │ │ ├── ESRRepository.kt │ │ │ └── TokenContractRepository.kt │ │ │ ├── securestorage │ │ │ ├── KeystoreTool.java │ │ │ ├── PRNGFixes.java │ │ │ ├── SecretKeyTool.java │ │ │ ├── SecurePreferences.java │ │ │ └── SecureStorageException.java │ │ │ └── workers │ │ │ ├── ChildWorkerFactory.kt │ │ │ ├── InitActiveAccountWorker.kt │ │ │ ├── InitChainProviderWorker.kt │ │ │ ├── InitChainUrlStatsWorker.kt │ │ │ ├── InitTokenContractsWorker.kt │ │ │ └── ProtonWorkerFactory.kt │ └── res │ │ └── values │ │ └── strings.xml │ ├── orchid │ └── resources │ │ ├── config.yml │ │ └── homepage.md │ └── test │ └── java │ └── com │ └── metallicus │ └── protonsdk │ └── ExampleUnitTest.kt └── settings.gradle.kts /.gitattributes: -------------------------------------------------------------------------------- 1 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/* linguist-vendored 2 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/digest/* linguist-vendored 3 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/* linguist-vendored 4 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/* linguist-vendored 5 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/chain/* linguist-vendored 6 | protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/* linguist-vendored 7 | 8 | protonsdk/src/main/java/com/metallicus/protonsdk/securestorage/* linguist-vendored -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | 4 | ### Android ### 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | *.aab 9 | 10 | *.iml 11 | 12 | # Idea 13 | .idea/ 14 | 15 | # Files for the Dalvik VM 16 | *.dex 17 | 18 | # Java class files 19 | *.class 20 | 21 | # Generated files 22 | bin/ 23 | gen/ 24 | 25 | # Gradle files 26 | .gradle/ 27 | build/ 28 | gradle.properties 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | #Log Files 37 | *.log 38 | 39 | #Backup Files 40 | *.ab -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Proton Chain LLC, Delaware 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | classpath(BuildPlugins.androidGradlePlugin) 11 | } 12 | } 13 | 14 | plugins { 15 | kotlin("jvm") version kotlinVersion 16 | id(BuildPlugins.dokka) version BuildPlugins.Versions.dokka 17 | id(BuildPlugins.orchid) version orchidVersion 18 | `maven-publish` 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | mavenLocal() 24 | 25 | google() 26 | mavenCentral() 27 | jcenter() // for orchid 28 | 29 | maven { 30 | name = "ProtonKotlinSdk" 31 | url = uri("https://maven.pkg.github.com/ProtonProtocol/ProtonKotlin") 32 | credentials { 33 | username = gradleLocalProperties(rootDir).getProperty("github.username") 34 | password = gradleLocalProperties(rootDir).getProperty("github.token") 35 | } 36 | } 37 | } 38 | } 39 | 40 | dependencies { 41 | orchidRuntimeOnly(Libraries.orchidDocs) 42 | orchidRuntimeOnly(Libraries.orchidKotlindoc) 43 | orchidRuntimeOnly(Libraries.orchidPluginDocs) 44 | orchidRuntimeOnly(Libraries.orchidGithub) 45 | } 46 | 47 | orchid { 48 | theme = "Editorial" 49 | version = ProtonSdk.versionName 50 | srcDir = "protonsdk/src/orchid/resources" 51 | destDir = "protonsdk/build/docs/orchid" 52 | baseUrl = "https://protonprotocol.github.io/ProtonKotlin" 53 | 54 | githubToken = gradleLocalProperties(rootDir).getProperty("github.token") 55 | } 56 | 57 | tasks.register("cleanAll").configure { 58 | delete("build", "buildSrc/build", "protonsdk/build") 59 | } -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | kotlinDslPluginOptions { 10 | experimentalWarning.set(false) 11 | } -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "DSL" -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XPRNetwork/ProtonKotlin/08e6f58f771634d1b2a44e71df901307eff7da66/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 24 14:37:00 EDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /protonsdk/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /protonsdk/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XPRNetwork/ProtonKotlin/08e6f58f771634d1b2a44e71df901307eff7da66/protonsdk/consumer-rules.pro -------------------------------------------------------------------------------- /protonsdk/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /protonsdk/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /protonsdk/src/androidTest/java/com/metallicus/protonsdk/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4 4 | import androidx.test.platform.app.InstrumentationRegistry 5 | import org.hamcrest.CoreMatchers.containsString 6 | import org.junit.Assert.assertThat 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import timber.log.Timber 10 | import java.security.InvalidAlgorithmParameterException 11 | import java.security.InvalidKeyException 12 | import java.security.NoSuchAlgorithmException 13 | import java.util.* 14 | import javax.crypto.BadPaddingException 15 | import javax.crypto.Cipher 16 | import javax.crypto.IllegalBlockSizeException 17 | import javax.crypto.NoSuchPaddingException 18 | import javax.crypto.spec.IvParameterSpec 19 | import javax.crypto.spec.SecretKeySpec 20 | 21 | /** 22 | * Instrumented test, which will execute on an Android device. 23 | * 24 | * See [testing documentation](http://d.android.com/tools/testing). 25 | */ 26 | @RunWith(AndroidJUnit4::class) 27 | class ExampleInstrumentedTest { 28 | @Test 29 | fun checkPackage() { 30 | // Context of the app under test. 31 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 32 | assertThat(appContext.packageName, containsString("com.metallicus.protonsdk")) 33 | } 34 | 35 | @Test 36 | fun checkAESDecrypt() { 37 | val cipherTextHex = 38 | "2a2049eee14c2bf2d73eae16d84affa1084e942f361ba846eb726ce56299e489d9d8afdcbd41bbca2fedc36c2ba5aef9373d757225e43654a2e98c99413c5f034f15bf7b9013b2dbe52951d2a4c537a5443a87914a5904571e7370a1c6d493cb9ce1a1d48dd80857a4d90bfe72b54ead940896192d6314d287606473734c17d75e988ce651e846286b9d2a06ecf100fd1832003948dd913e97cdde47cd6a1e9d06a1bd6397c55712721c627b9cc3c543f39cf6043da4241db23a6e7dfb14afe544da8bcffa26e078bf4a9580e54e044ab85b09ecabdc57ba9c5bc7008365be51" 39 | val keyHex = "728f6bb27af36663bc51f3f7786d132d9ebf52bc7a46a4090e63a91ad058895a" 40 | val ivHex = "4126bb121c0896cecf271af079c8c2d9" 41 | 42 | val cipherTextByteArray = cipherTextHex.hexStringToByteArray2() 43 | val keyByteArray = keyHex.hexStringToByteArray2() 44 | val ivByteArray = ivHex.hexStringToByteArray2() 45 | 46 | val decryptedByteArray: ByteArray = try { 47 | cipherTextByteArray.aesDecrypt(keyByteArray, ivByteArray) 48 | } catch (e: Exception) { 49 | Timber.e(e) 50 | byteArrayOf(0) 51 | } 52 | 53 | assert(decryptedByteArray.isNotEmpty()) 54 | } 55 | 56 | private fun String.hexStringToByteArray(): ByteArray { 57 | val s = toUpperCase(Locale.ROOT) 58 | val len = s.length 59 | val result = ByteArray(len / 2) 60 | for (i in 0 until len step 2) { 61 | val firstIndex = indexOf(s[i]) 62 | val secondIndex = indexOf(s[i + 1]) 63 | 64 | val octet = firstIndex.shl(4).or(secondIndex) 65 | result[i.shr(1)] = octet.toByte() 66 | } 67 | return result 68 | } 69 | 70 | private fun String.hexStringToByteArray2(): ByteArray { 71 | val s = toUpperCase(Locale.ROOT) 72 | val len = s.length 73 | val data = ByteArray(len / 2) 74 | var i = 0 75 | while (i < len) { 76 | data[i / 2] = ((Character.digit(s[i], 16) shl 4) + Character.digit(s[i + 1], 16)).toByte() 77 | i += 2 78 | } 79 | return data 80 | } 81 | 82 | @Throws( 83 | NoSuchAlgorithmException::class, 84 | NoSuchPaddingException::class, 85 | InvalidKeyException::class, 86 | InvalidAlgorithmParameterException::class, 87 | IllegalBlockSizeException::class, 88 | BadPaddingException::class 89 | ) 90 | private fun ByteArray.aesDecrypt(key: ByteArray, iv: ByteArray): ByteArray { 91 | val keySpec = SecretKeySpec(key, "AES") 92 | val ivSpec = IvParameterSpec(iv) 93 | val cipher = Cipher.getInstance("AES/CBC/PKCS7Padding") 94 | cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec) 95 | return cipher.doFinal(this) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /protonsdk/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/ChainProviderModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk 23 | 24 | import android.content.Context 25 | import com.google.gson.JsonObject 26 | import com.metallicus.protonsdk.api.TableRowsIndexPosition 27 | import com.metallicus.protonsdk.common.Prefs 28 | import com.metallicus.protonsdk.common.Resource 29 | import com.metallicus.protonsdk.di.DaggerInjector 30 | import com.metallicus.protonsdk.model.ChainProvider 31 | import com.metallicus.protonsdk.repository.ChainProviderRepository 32 | import javax.inject.Inject 33 | 34 | /** 35 | * Helper class used for [ChainProvider] based operations 36 | */ 37 | class ChainProviderModule { 38 | @Inject 39 | lateinit var context: Context 40 | 41 | @Inject 42 | lateinit var chainProviderRepository: ChainProviderRepository 43 | 44 | @Inject 45 | lateinit var prefs: Prefs 46 | 47 | init { 48 | DaggerInjector.component.inject(this) 49 | } 50 | 51 | suspend fun getActiveChainProvider(): ChainProvider { 52 | val chainId = prefs.activeChainId 53 | return chainProviderRepository.getChainProvider(chainId) 54 | } 55 | 56 | suspend fun updateChainProvider(chainProvider: ChainProvider) { 57 | chainProviderRepository.updateChainProvider(chainProvider) 58 | } 59 | 60 | suspend fun updateChainUrl(chainId: String, chainUrl: String) { 61 | chainProviderRepository.updateChainUrl(chainId, chainUrl) 62 | } 63 | 64 | suspend fun updateHyperionHistoryUrl(chainId: String, hyperionHistoryUrl: String) { 65 | chainProviderRepository.updateHyperionHistoryUrl(chainId, hyperionHistoryUrl) 66 | } 67 | 68 | suspend fun getTableRows( 69 | chainUrl: String, 70 | scope: String, 71 | code: String, 72 | name: String, 73 | lowerBound: String = "", 74 | upperBound: String = "", 75 | limit: Long = 1, 76 | indexPosition: String = TableRowsIndexPosition.PRIMARY.indexPositionName, 77 | reverse: Boolean = false 78 | ): Resource { 79 | return try { 80 | val response = chainProviderRepository.getTableRows(chainUrl, scope, code, name, lowerBound, upperBound, limit, indexPosition, reverse) 81 | if (response.isSuccessful) { 82 | Resource.success(response.body()) 83 | } else { 84 | val msg = response.errorBody()?.string() 85 | val errorMsg = if (msg.isNullOrEmpty()) { 86 | response.message() 87 | } else { 88 | msg 89 | } 90 | Resource.error(errorMsg) 91 | } 92 | } catch (e: Exception) { 93 | Resource.error(e.localizedMessage.orEmpty()) 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/TokenContractsModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk 23 | 24 | import android.content.Context 25 | import com.google.gson.Gson 26 | import com.metallicus.protonsdk.common.Prefs 27 | import com.metallicus.protonsdk.di.DaggerInjector 28 | import com.metallicus.protonsdk.model.ChainProvider 29 | import com.metallicus.protonsdk.model.TokenContract 30 | import com.metallicus.protonsdk.model.TokenContractRate 31 | import com.metallicus.protonsdk.repository.TokenContractRepository 32 | import timber.log.Timber 33 | import javax.inject.Inject 34 | 35 | /** 36 | * Helper class used for [TokenContract] based operations 37 | */ 38 | class TokenContractsModule { 39 | @Inject 40 | lateinit var context: Context 41 | 42 | @Inject 43 | lateinit var tokenContractRepository: TokenContractRepository 44 | 45 | @Inject 46 | lateinit var prefs: Prefs 47 | 48 | init { 49 | DaggerInjector.component.inject(this) 50 | } 51 | 52 | suspend fun getTokenContract(tokenContractId: String): TokenContract { 53 | return tokenContractRepository.getTokenContract(tokenContractId) 54 | } 55 | 56 | suspend fun getTokenContracts(): List { 57 | return tokenContractRepository.getTokenContracts() 58 | } 59 | 60 | suspend fun updateExchangeRates(exchangeRatesUrl: String, tokenContractsMap: Map) { 61 | try { 62 | val exchangeRatesResponse = tokenContractRepository.fetchExchangeRates(exchangeRatesUrl) 63 | if (exchangeRatesResponse.isSuccessful) { 64 | val exchangeRatesJsonArray = exchangeRatesResponse.body() 65 | exchangeRatesJsonArray?.forEach { 66 | val exchangeRate = it.asJsonObject 67 | val contract = exchangeRate.get("contract").asString 68 | val symbol = exchangeRate.get("symbol").asString 69 | val rank = exchangeRate.get("rank").asInt 70 | 71 | val ratesMap = mutableMapOf() 72 | 73 | val ratesJsonArray = exchangeRate.get("rates").asJsonArray 74 | ratesJsonArray.forEach { rateJsonElement -> 75 | val rateJsonObj = rateJsonElement.asJsonObject 76 | val currency = rateJsonObj.get("counterCurrency").asString 77 | val rate = Gson().fromJson(rateJsonObj, TokenContractRate::class.java) 78 | ratesMap[currency] = rate 79 | } 80 | 81 | val tokenContractId = "$contract:$symbol" 82 | if (tokenContractsMap.containsKey(tokenContractId)) { 83 | tokenContractsMap[tokenContractId]?.rates = ratesMap 84 | 85 | tokenContractRepository.updateRates(tokenContractId, ratesMap, rank) 86 | } 87 | } 88 | } 89 | } catch (e: Exception) { 90 | Timber.d(e.localizedMessage) 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/api/ESRCallbackService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.api 23 | 24 | import retrofit2.Response 25 | import retrofit2.http.* 26 | 27 | data class CancelAuthorizeESRBody(val rejected: String) 28 | 29 | interface ESRCallbackService { 30 | @POST 31 | suspend fun cancelAuthorizeESR( 32 | @Url url: String, 33 | @Body body: CancelAuthorizeESRBody): Response 34 | 35 | @POST 36 | suspend fun authorizeESR( 37 | @Url url: String, 38 | @Body body: Map): Response 39 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/api/ProtonChainStatsService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.api 23 | 24 | import com.google.gson.JsonObject 25 | import com.metallicus.protonsdk.model.* 26 | import retrofit2.Response 27 | import retrofit2.http.* 28 | 29 | interface ProtonChainStatsService { 30 | @POST//("/v1/chain/get_info") 31 | suspend fun getChainInfo(@Url url: String): Response 32 | 33 | @GET//("/v2/health") 34 | suspend fun getHealth(@Url url: String): Response 35 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/Prefs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.common 23 | 24 | import android.content.Context 25 | import android.content.SharedPreferences 26 | import androidx.core.content.edit 27 | 28 | class Prefs(context: Context) { 29 | companion object { 30 | const val SHARED_PREFS_FILENAME = "protonsdk.prefs" 31 | 32 | const val HAS_CHAIN_PROVIDER = "has_chain_provider" 33 | const val HAS_TOKEN_CONTRACTS = "has_token_contracts" 34 | const val HAS_CHAIN_URL_STATS = "has_chain_url_stats" 35 | 36 | const val ACTIVE_CHAIN_ID = "active_chain_id" 37 | const val ACTIVE_ACCOUNT_NAME = "active_account_name" 38 | 39 | const val HAS_ACTIVE_ACCOUNT = "has_active_account" 40 | } 41 | 42 | //private val backupManager: BackupManager = BackupManager(context) 43 | private val prefs: SharedPreferences = context.getSharedPreferences(SHARED_PREFS_FILENAME, 0) 44 | 45 | var hasChainProvider: Boolean 46 | get() = prefs.getBoolean(HAS_CHAIN_PROVIDER, false) 47 | set(value) { 48 | value.let { 49 | prefs.edit { putBoolean(HAS_CHAIN_PROVIDER, it) } 50 | } 51 | } 52 | 53 | var hasTokenContracts: Boolean 54 | get() = prefs.getBoolean(HAS_TOKEN_CONTRACTS, false) 55 | set(value) { 56 | value.let { 57 | prefs.edit { putBoolean(HAS_TOKEN_CONTRACTS, it) } 58 | } 59 | } 60 | 61 | var hasChainUrlStats: Boolean 62 | get() = prefs.getBoolean(HAS_CHAIN_URL_STATS, false) 63 | set(value) { 64 | value.let { 65 | prefs.edit { putBoolean(HAS_CHAIN_URL_STATS, it) } 66 | } 67 | } 68 | 69 | var activeChainId: String 70 | get() = prefs.getString(ACTIVE_CHAIN_ID, "").orEmpty() 71 | set(value) { 72 | value.let { 73 | prefs.edit { putString(ACTIVE_CHAIN_ID, it) } 74 | } 75 | } 76 | 77 | fun getActiveAccountName(): String { 78 | return prefs.getString(ACTIVE_ACCOUNT_NAME, "").orEmpty() 79 | } 80 | 81 | fun getActivePublicKey(): String { 82 | val activeAccountName = getActiveAccountName() 83 | return prefs.getString(activeAccountName, "").orEmpty() 84 | } 85 | 86 | fun setActiveAccount(publicKey: String, accountName: String) { 87 | prefs.edit { 88 | putString(ACTIVE_ACCOUNT_NAME, accountName) 89 | putString(accountName, publicKey) 90 | } 91 | } 92 | 93 | var hasActiveAccount: Boolean 94 | get() = prefs.getBoolean(HAS_ACTIVE_ACCOUNT, false) 95 | set(value) { 96 | value.let { 97 | prefs.edit { putBoolean(HAS_ACTIVE_ACCOUNT, it) } 98 | } 99 | } 100 | 101 | fun clearInit() { 102 | prefs.edit { 103 | remove(HAS_CHAIN_PROVIDER) 104 | remove(HAS_TOKEN_CONTRACTS) 105 | remove(HAS_ACTIVE_ACCOUNT) 106 | remove(HAS_CHAIN_URL_STATS) 107 | } 108 | } 109 | 110 | fun clearAll() { 111 | clearInit() 112 | 113 | prefs.edit { remove(ACTIVE_CHAIN_ID) } 114 | 115 | prefs.edit { remove(ACTIVE_ACCOUNT_NAME) } 116 | 117 | //backupManager.dataChanged() 118 | } 119 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/ProtonError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.common 23 | 24 | import androidx.work.Data 25 | 26 | class ProtonError( 27 | var message: String, 28 | var code: Int = DEFAULT_ERROR 29 | ) { 30 | companion object { 31 | const val ERROR_MESSAGE_KEY = "errorMessage" 32 | const val ERROR_CODE_KEY = "errorCode" 33 | 34 | // Error Codes 35 | const val NO_ERROR = 0 36 | const val DEFAULT_ERROR = -1 37 | const val ACCOUNT_NOT_FOUND = -2 38 | } 39 | 40 | constructor(errorData: Data?) : this( 41 | errorData?.getString(ERROR_MESSAGE_KEY).orEmpty(), 42 | errorData?.getInt(ERROR_CODE_KEY, DEFAULT_ERROR) ?: DEFAULT_ERROR) 43 | } 44 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/ProtonException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.common 23 | 24 | import androidx.work.Data 25 | 26 | class ProtonException : Exception { 27 | var code: Int = ProtonError.DEFAULT_ERROR 28 | 29 | constructor(message: String, code: Int) : super(message) { this.code = code } 30 | constructor(error: ProtonError) : super(error.message) { this.code = error.code } 31 | constructor(errorData: Data?) : this(ProtonError(errorData)) 32 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/Resource.kt: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.common 2 | 3 | /** 4 | * A generic class that emulates loading, success, and error states with optional data and messages. 5 | */ 6 | data class Resource(val status: Status, val data: T?, val message: String?, val code: Int?) { 7 | companion object { 8 | fun success(data: T?): Resource { 9 | return Resource( 10 | Status.SUCCESS, 11 | data, 12 | null, 13 | ProtonError.NO_ERROR 14 | ) 15 | } 16 | 17 | fun error(msg: String): Resource { 18 | return Resource( 19 | Status.ERROR, 20 | null, 21 | msg, 22 | ProtonError.DEFAULT_ERROR 23 | ) 24 | } 25 | 26 | fun error(msg: String, code: Int): Resource { 27 | return Resource( 28 | Status.ERROR, 29 | null, 30 | msg, 31 | code 32 | ) 33 | } 34 | 35 | fun error(error: ProtonError): Resource { 36 | return Resource( 37 | Status.ERROR, 38 | null, 39 | error.message, 40 | error.code 41 | ) 42 | } 43 | 44 | fun error(exception: ProtonException): Resource { 45 | return Resource( 46 | Status.ERROR, 47 | null, 48 | exception.message, 49 | exception.code 50 | ) 51 | } 52 | 53 | fun loading(): Resource { 54 | return Resource( 55 | Status.LOADING, 56 | null, 57 | null, 58 | ProtonError.DEFAULT_ERROR 59 | ) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/SingletonHolder.kt: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.common 2 | 3 | open class SingletonHolder(creator: (A) -> T) { 4 | private var creator: ((A) -> T)? = creator 5 | @Volatile private var instance: T? = null 6 | 7 | fun getInstance(arg: A): T { 8 | val checkInstance = instance 9 | if (checkInstance != null) { 10 | return checkInstance 11 | } 12 | 13 | return synchronized(this) { 14 | val checkInstanceAgain = instance 15 | if (checkInstanceAgain != null) { 16 | checkInstanceAgain 17 | } else { 18 | val created = creator!!(arg) 19 | instance = created 20 | creator = null 21 | created 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/common/Status.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.common 23 | 24 | enum class Status { 25 | SUCCESS, 26 | ERROR, 27 | LOADING 28 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/AccountContactDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.* 25 | import com.metallicus.protonsdk.model.AccountContact 26 | 27 | /** 28 | * Interface for database access for [AccountContact] related operations 29 | */ 30 | @Dao 31 | interface AccountContactDao { 32 | @Insert(onConflict = OnConflictStrategy.IGNORE) 33 | suspend fun insert(accountContact: AccountContact) 34 | 35 | @Update 36 | suspend fun update(accountContact: AccountContact) 37 | 38 | @Query("SELECT * FROM accountContact WHERE accountName = :accountName") 39 | suspend fun findByAccountName(accountName: String): List 40 | 41 | @Query("DELETE FROM accountContact") 42 | suspend fun removeAll() 43 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/AccountDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.* 25 | import com.metallicus.protonsdk.model.Account 26 | import com.metallicus.protonsdk.model.ChainAccount 27 | 28 | /** 29 | * Interface for database access for [Account] related operations 30 | */ 31 | @Dao 32 | interface AccountDao { 33 | @Insert(onConflict = OnConflictStrategy.REPLACE) 34 | suspend fun insert(account: Account) 35 | 36 | @Update 37 | suspend fun update(account: Account) 38 | 39 | @Transaction 40 | @Query("SELECT * FROM account WHERE accountName = :accountName") 41 | suspend fun findByAccountName(accountName: String): ChainAccount 42 | 43 | @Query("DELETE FROM account") 44 | suspend fun removeAll() 45 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/ActionDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.Dao 25 | import androidx.room.Insert 26 | import androidx.room.OnConflictStrategy 27 | import androidx.room.Query 28 | import com.metallicus.protonsdk.model.Action 29 | 30 | /** 31 | * Interface for database access for [Action] related operations 32 | */ 33 | @Dao 34 | interface ActionDao { 35 | @Insert(onConflict = OnConflictStrategy.REPLACE) 36 | suspend fun insert(action: Action) 37 | 38 | @Query("SELECT * FROM `action` " + 39 | "WHERE accountName = :accountName " + 40 | "AND ((action_trace_act_account = :contract AND action_trace_act_data_quantity LIKE '% ' || :symbol) OR action_trace_act_account = 'eosio')") 41 | suspend fun findBySystemTokenContract(accountName: String, contract: String, symbol: String): List 42 | 43 | @Query("SELECT * FROM `action` " + 44 | "WHERE accountName = :accountName " + 45 | "AND action_trace_act_account = :contract " + 46 | "AND action_trace_act_data_quantity LIKE '% ' || :symbol") 47 | suspend fun findByTokenContract(accountName: String, contract: String, symbol: String): List 48 | 49 | @Query("DELETE FROM `action`") 50 | suspend fun removeAll() 51 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/ChainProviderDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.* 25 | import com.metallicus.protonsdk.model.ChainProvider 26 | 27 | /** 28 | * Interface for database access for [ChainProvider] related operations 29 | */ 30 | @Dao 31 | interface ChainProviderDao { 32 | @Insert(onConflict = OnConflictStrategy.REPLACE) 33 | suspend fun insert(chainProvider: ChainProvider) 34 | 35 | @Update 36 | suspend fun update(chainProvider: ChainProvider) 37 | 38 | @Query("SELECT * FROM chainProvider WHERE chainId = :id") 39 | suspend fun findById(id: String): ChainProvider 40 | 41 | @Query("SELECT * FROM chainProvider") 42 | suspend fun findAll(): List 43 | 44 | @Query("UPDATE chainProvider SET chainUrl = :chainUrl WHERE chainId = :chainId") 45 | suspend fun updateChainUrl(chainId: String, chainUrl: String) 46 | 47 | @Query("UPDATE chainProvider SET hyperionHistoryUrl = :hyperionHistoryUrl WHERE chainId = :chainId") 48 | suspend fun updateHyperionHistoryUrl(chainId: String, hyperionHistoryUrl: String) 49 | 50 | @Query("DELETE FROM chainProvider") 51 | suspend fun removeAll() 52 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.TypeConverter 25 | import com.google.gson.Gson 26 | import com.google.gson.reflect.TypeToken 27 | import timber.log.Timber 28 | 29 | object DefaultTypeConverters { 30 | @TypeConverter 31 | @JvmStatic 32 | fun stringToIntList(data: String?): List? { 33 | return data?.let { str -> 34 | str.split(",").map { 35 | try { 36 | it.toInt() 37 | } catch (ex: NumberFormatException) { 38 | Timber.e(ex, "Cannot convert $it to number") 39 | null 40 | } 41 | } 42 | }?.filterNotNull() 43 | } 44 | 45 | @TypeConverter 46 | @JvmStatic 47 | fun intListToString(ints: List?): String? { 48 | return ints?.joinToString(",") 49 | } 50 | 51 | @TypeConverter 52 | @JvmStatic 53 | fun stringToStringList(data: String?): List? { 54 | return data?.let { str -> 55 | str.split(",").map { it } 56 | } 57 | } 58 | 59 | @TypeConverter 60 | @JvmStatic 61 | fun stringListToString(strings: List?): String? { 62 | return strings?.joinToString(",") 63 | } 64 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/EOSTypeConverters.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.TypeConverter 25 | import com.google.gson.Gson 26 | import com.google.gson.reflect.TypeToken 27 | import com.metallicus.protonsdk.model.AccountPermission 28 | import com.metallicus.protonsdk.model.ActionTraceActAuthorization 29 | 30 | object EOSTypeConverters { 31 | @TypeConverter 32 | @JvmStatic 33 | fun stringToAccountPermissionList(value: String): List { 34 | val type = object : TypeToken>() {}.type 35 | return Gson().fromJson(value, type) 36 | } 37 | 38 | @TypeConverter 39 | @JvmStatic 40 | fun accountPermissionListToString(value: List): String { 41 | val type = object : TypeToken>() {}.type 42 | return Gson().toJson(value, type) 43 | } 44 | 45 | @TypeConverter 46 | @JvmStatic 47 | fun stringToActionTraceActAuthorizationList(value: String): List { 48 | val type = object : TypeToken>() {}.type 49 | return Gson().fromJson(value, type) 50 | } 51 | 52 | @TypeConverter 53 | @JvmStatic 54 | fun actionTraceActAuthorizationListToString(value: List): String { 55 | val type = object : TypeToken>() {}.type 56 | return Gson().toJson(value, type) 57 | } 58 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/ESRSessionDao.kt: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.db 2 | 3 | import androidx.room.* 4 | import com.metallicus.protonsdk.model.ESRSession 5 | 6 | /** 7 | * Interface for database access for [ESRSession] related operations 8 | */ 9 | @Dao 10 | interface ESRSessionDao { 11 | @Insert(onConflict = OnConflictStrategy.REPLACE) 12 | suspend fun insert(esrSession: ESRSession) 13 | 14 | @Update 15 | suspend fun update(esrSession: ESRSession) 16 | 17 | @Query("SELECT * FROM esrSession WHERE id = :id") 18 | suspend fun findById(id: String): ESRSession 19 | 20 | @Query("SELECT * FROM esrSession") 21 | suspend fun findAll(): List 22 | 23 | @Query("DELETE FROM esrSession WHERE id = :id") 24 | suspend fun remove(id: String) 25 | 26 | @Query("DELETE FROM esrSession") 27 | suspend fun removeAll() 28 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.Database 25 | import androidx.room.RoomDatabase 26 | import androidx.room.TypeConverters 27 | import com.metallicus.protonsdk.model.* 28 | 29 | @Database( 30 | entities = [ 31 | ChainProvider::class, 32 | TokenContract::class, 33 | Account::class, 34 | //AccountContact::class, 35 | //CurrencyBalance::class, 36 | Action::class, 37 | ESRSession::class], 38 | version = 32, 39 | exportSchema = false 40 | ) 41 | @TypeConverters(DefaultTypeConverters::class, EOSTypeConverters::class, ProtonTypeConverters::class) 42 | abstract class ProtonDb : RoomDatabase() { 43 | abstract fun chainProviderDao(): ChainProviderDao 44 | abstract fun tokenContractDao(): TokenContractDao 45 | abstract fun accountDao(): AccountDao 46 | // abstract fun currencyBalanceDao(): CurrencyBalanceDao 47 | // abstract fun accountContactDao(): AccountContactDao 48 | abstract fun actionDao(): ActionDao 49 | abstract fun esrSessionDao(): ESRSessionDao 50 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/db/TokenContractDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.db 23 | 24 | import androidx.room.* 25 | import com.metallicus.protonsdk.model.TokenContract 26 | import com.metallicus.protonsdk.model.TokenContractRate 27 | 28 | /** 29 | * Interface for database access for [TokenContract] related operations 30 | */ 31 | @Dao 32 | interface TokenContractDao { 33 | @Insert(onConflict = OnConflictStrategy.REPLACE) 34 | suspend fun insert(tokenContract: TokenContract) 35 | 36 | @Update 37 | suspend fun update(tokenContract: TokenContract) 38 | 39 | @Query("SELECT * FROM tokenContract WHERE id = :id") 40 | suspend fun findById(id: String): TokenContract 41 | 42 | @Query("SELECT * FROM tokenContract") 43 | suspend fun findAll(): List 44 | 45 | @Query("UPDATE tokenContract SET rates = :rates, rank = :rank WHERE id = :tokenContractId") 46 | suspend fun updateRates(tokenContractId: String, rates: Map, rank: Int) 47 | 48 | @Query("DELETE FROM tokenContract") 49 | suspend fun removeAll() 50 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/di/DaggerInjector.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.di 23 | 24 | import android.content.Context 25 | 26 | class DaggerInjector { 27 | companion object { 28 | lateinit var component: ProtonComponent 29 | 30 | fun buildComponent(context: Context): ProtonComponent { 31 | component = DaggerProtonComponent.builder().context(context).build() 32 | return component 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/di/ProtonComponent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.di 23 | 24 | import android.content.Context 25 | import com.metallicus.protonsdk.* 26 | import dagger.BindsInstance 27 | import dagger.Component 28 | import javax.inject.Singleton 29 | 30 | @Singleton 31 | @Component(modules = [ 32 | WorkerAssistedModule::class, 33 | WorkerModule::class, 34 | ProtonModule::class 35 | ]) 36 | interface ProtonComponent { 37 | @Component.Builder 38 | interface Builder { 39 | @BindsInstance 40 | fun context(context: Context): Builder 41 | 42 | fun build(): ProtonComponent 43 | } 44 | 45 | fun inject(protonModule: ProtonModule) 46 | 47 | fun inject(workersModule: WorkersModule) 48 | fun inject(chainProviderModule: ChainProviderModule) 49 | fun inject(tokenContractsModule: TokenContractsModule) 50 | fun inject(accountModule: AccountModule) 51 | fun inject(currencyBalancesModule: CurrencyBalancesModule) 52 | fun inject(actionModule: ActionsModule) 53 | } 54 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/di/WorkerAssistedModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.di 23 | 24 | import com.squareup.inject.assisted.dagger2.AssistedModule 25 | import dagger.Module 26 | 27 | @Module(includes = [AssistedInject_WorkerAssistedModule::class]) 28 | @AssistedModule 29 | interface WorkerAssistedModule -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/di/WorkerKey.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.di 23 | 24 | import androidx.work.ListenableWorker 25 | import dagger.MapKey 26 | import kotlin.reflect.KClass 27 | 28 | @MapKey 29 | @Retention(AnnotationRetention.RUNTIME) 30 | @Target(AnnotationTarget.FUNCTION) 31 | annotation class WorkerKey(val value: KClass) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/di/WorkerModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.di 23 | 24 | import androidx.work.WorkerFactory 25 | import com.metallicus.protonsdk.workers.* 26 | import dagger.Binds 27 | import dagger.Module 28 | import dagger.multibindings.IntoMap 29 | 30 | @Suppress("unused") 31 | @Module 32 | abstract class WorkerModule { 33 | @Binds 34 | @IntoMap 35 | @WorkerKey(InitChainProviderWorker::class) 36 | abstract fun bindInitChainProvidersWorker(factory: InitChainProviderWorker.Factory): ChildWorkerFactory 37 | 38 | @Binds 39 | @IntoMap 40 | @WorkerKey(InitTokenContractsWorker::class) 41 | abstract fun bindInitTokenContractsWorker(factory: InitTokenContractsWorker.Factory): ChildWorkerFactory 42 | 43 | @Binds 44 | @IntoMap 45 | @WorkerKey(InitActiveAccountWorker::class) 46 | abstract fun bindInitActiveAccountWorker(factory: InitActiveAccountWorker.Factory): ChildWorkerFactory 47 | 48 | @Binds 49 | @IntoMap 50 | @WorkerKey(InitChainUrlStatsWorker::class) 51 | abstract fun bindInitChainUrlStatsWorker(factory: InitChainUrlStatsWorker.Factory): ChildWorkerFactory 52 | 53 | @Binds 54 | abstract fun bindWorkerFactory(factory: ProtonWorkerFactory): WorkerFactory 55 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/CryptUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander; 25 | 26 | import java.security.InvalidAlgorithmParameterException; 27 | import java.security.InvalidKeyException; 28 | import java.security.NoSuchAlgorithmException; 29 | import java.util.Arrays; 30 | 31 | import javax.crypto.BadPaddingException; 32 | import javax.crypto.Cipher; 33 | import javax.crypto.IllegalBlockSizeException; 34 | import javax.crypto.NoSuchPaddingException; 35 | import javax.crypto.SecretKey; 36 | import javax.crypto.spec.IvParameterSpec; 37 | import javax.crypto.spec.SecretKeySpec; 38 | 39 | 40 | /** 41 | * Created by swapnibble on 2017-08-09. 42 | */ 43 | 44 | public class CryptUtil { 45 | 46 | public static byte[] aesEncrypt(byte[] key, byte[] data, byte[] iv) { 47 | 48 | byte[] encrypted = null; 49 | 50 | try { 51 | 52 | SecretKey secureKey = new SecretKeySpec(key, "AES"); 53 | Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); 54 | 55 | c.init(Cipher.ENCRYPT_MODE, secureKey, new IvParameterSpec(iv)); 56 | 57 | encrypted = c.doFinal(data); 58 | 59 | } catch (NoSuchPaddingException e) { 60 | e.printStackTrace(); 61 | } catch (InvalidAlgorithmParameterException e) { 62 | e.printStackTrace(); 63 | } catch (NoSuchAlgorithmException e) { 64 | e.printStackTrace(); 65 | } catch (InvalidKeyException e) { 66 | e.printStackTrace(); 67 | } catch (BadPaddingException e) { 68 | e.printStackTrace(); 69 | } catch (IllegalBlockSizeException e) { 70 | e.printStackTrace(); 71 | } 72 | 73 | return encrypted; 74 | } 75 | 76 | public static byte[] aesDecrypt(byte[] key, byte[] data, byte[] iv) { 77 | byte[] decrypted = null; 78 | try { 79 | SecretKey secureKey = new SecretKeySpec(key, "AES"); 80 | Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); 81 | 82 | if (iv.length > 16) { 83 | iv = Arrays.copyOf(iv, 16); // aes/cbc 에선 iv 는 16-byte ! 84 | } 85 | 86 | c.init(Cipher.DECRYPT_MODE, secureKey, new IvParameterSpec(iv)); 87 | 88 | decrypted = c.doFinal(data); 89 | 90 | } catch (NoSuchPaddingException e) { 91 | e.printStackTrace(); 92 | } catch (InvalidAlgorithmParameterException e) { 93 | e.printStackTrace(); 94 | } catch (NoSuchAlgorithmException e) { 95 | e.printStackTrace(); 96 | } catch (InvalidKeyException e) { 97 | e.printStackTrace(); 98 | } catch (BadPaddingException e) { 99 | e.printStackTrace(); 100 | } catch (IllegalBlockSizeException e) { 101 | e.printStackTrace(); 102 | } 103 | 104 | return decrypted; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/GsonEosTypeAdapterFactory.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.TypeAdapter; 5 | import com.google.gson.TypeAdapterFactory; 6 | import com.google.gson.reflect.TypeToken; 7 | import com.google.gson.stream.JsonReader; 8 | import com.google.gson.stream.JsonToken; 9 | import com.google.gson.stream.JsonWriter; 10 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeAccountName; 11 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeActionName; 12 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeAsset; 13 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeName; 14 | import com.metallicus.protonsdk.eosio.commander.model.types.TypePermissionName; 15 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeScopeName; 16 | 17 | import java.io.IOException; 18 | import java.lang.reflect.Constructor; 19 | import java.lang.reflect.InvocationTargetException; 20 | import java.util.LinkedHashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * Created by swapnibble on 2018-04-04. 25 | */ 26 | 27 | public class GsonEosTypeAdapterFactory implements TypeAdapterFactory { 28 | 29 | private Map, TypeAdapter> adapters = new LinkedHashMap<>(); 30 | 31 | { 32 | adapters.put(TypeName.class, new TypeNameAdapter<>(TypeName.class)); 33 | adapters.put(TypeAccountName.class, new TypeNameAdapter<>(TypeAccountName.class)); 34 | adapters.put(TypeActionName.class, new TypeNameAdapter<>(TypeActionName.class)); 35 | adapters.put(TypePermissionName.class, new TypeNameAdapter<>(TypePermissionName.class)); 36 | adapters.put(TypeScopeName.class, new TypeNameAdapter<>(TypeScopeName.class)); 37 | 38 | adapters.put(TypeAsset.class, new TypeNameAdapter<>(TypeAsset.class)); 39 | } 40 | 41 | @Override 42 | @SuppressWarnings("unchecked") 43 | public TypeAdapter create(Gson gson, TypeToken typeToken) { 44 | TypeAdapter typeAdapter = null; 45 | Class currentType = Object.class; 46 | for (Class type : adapters.keySet()) { 47 | if (type.isAssignableFrom(typeToken.getRawType())) { 48 | if (currentType.isAssignableFrom(type)) { 49 | currentType = type; 50 | typeAdapter = (TypeAdapter) adapters.get(type); 51 | } 52 | } 53 | } 54 | return typeAdapter; 55 | } 56 | 57 | public static class TypeNameAdapter extends TypeAdapter { 58 | 59 | private Class clazz; 60 | 61 | public TypeNameAdapter(Class clazz) { 62 | this.clazz = clazz; 63 | } 64 | 65 | @Override 66 | public C read(JsonReader in) throws IOException { 67 | if (in.peek() == JsonToken.NULL) { 68 | in.nextNull(); 69 | return null; 70 | } 71 | 72 | try { 73 | Constructor constructor = clazz.getConstructor(String.class); 74 | return constructor.newInstance(in.nextString()); 75 | } catch (NoSuchMethodException e) { 76 | e.printStackTrace(); 77 | } catch (IllegalAccessException e) { 78 | e.printStackTrace(); 79 | } catch (InstantiationException e) { 80 | e.printStackTrace(); 81 | } catch (InvocationTargetException e) { 82 | e.printStackTrace(); 83 | } 84 | 85 | return null; 86 | } 87 | 88 | @Override 89 | public void write(JsonWriter out, C value) throws IOException { 90 | if (value == null) { 91 | out.nullValue(); 92 | return; 93 | } 94 | 95 | out.value(value.toString()); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/HexUtils.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander; 2 | 3 | /** 4 | * Utilities for going to and from ASCII-HEX representation. 5 | */ 6 | public class HexUtils { 7 | 8 | /** 9 | * Encodes an array of bytes as hex symbols. 10 | * 11 | * @param bytes the array of bytes to encode 12 | * @return the resulting hex string 13 | */ 14 | public static String toHex(byte[] bytes) { 15 | return toHex(bytes, null); 16 | } 17 | 18 | /** 19 | * Encodes an array of bytes as hex symbols. 20 | * 21 | * @param bytes the array of bytes to encode 22 | * @param separator the separator to use between two bytes, can be null 23 | * @return the resulting hex string 24 | */ 25 | public static String toHex(byte[] bytes, String separator) { 26 | return toHex(bytes, 0, bytes.length, separator); 27 | } 28 | 29 | /** 30 | * Encodes an array of bytes as hex symbols. 31 | * 32 | * @param bytes the array of bytes to encode 33 | * @param offset the start offset in the array of bytes 34 | * @param length the number of bytes to encode 35 | * @return the resulting hex string 36 | */ 37 | public static String toHex(byte[] bytes, int offset, int length) { 38 | return toHex(bytes, offset, length, null); 39 | } 40 | 41 | /** 42 | * Encodes a single byte to hex symbols. 43 | * 44 | * @param b the byte to encode 45 | * @return the resulting hex string 46 | */ 47 | public static String toHex(byte b) { 48 | StringBuilder sb = new StringBuilder(); 49 | appendByteAsHex(sb, b); 50 | return sb.toString(); 51 | } 52 | 53 | 54 | /** 55 | * Encodes an array of bytes as hex symbols. 56 | * 57 | * @param bytes the array of bytes to encode 58 | * @param offset the start offset in the array of bytes 59 | * @param length the number of bytes to encode 60 | * @param separator the separator to use between two bytes, can be null 61 | * @return the resulting hex string 62 | */ 63 | public static String toHex(byte[] bytes, int offset, int length, String separator) { 64 | StringBuilder result = new StringBuilder(); 65 | for (int i = 0; i < length; i++) { 66 | int unsignedByte = bytes[i + offset] & 0xff; 67 | 68 | if (unsignedByte < 16) { 69 | result.append("0"); 70 | } 71 | 72 | result.append(Integer.toHexString(unsignedByte)); 73 | if (separator != null && i + 1 < length) { 74 | result.append(separator); 75 | } 76 | } 77 | return result.toString(); 78 | } 79 | 80 | /** 81 | * Get the byte representation of an ASCII-HEX string. 82 | * 83 | * @param hexString The string to convert to bytes 84 | * @return The byte representation of the ASCII-HEX string. 85 | */ 86 | public static byte[] toBytes(String hexString) { 87 | if (hexString == null || hexString.length() % 2 != 0) { 88 | throw new RuntimeException("Input string must contain an even number of characters"); 89 | } 90 | char[] hex = hexString.toCharArray(); 91 | int length = hex.length / 2; 92 | byte[] raw = new byte[length]; 93 | for (int i = 0; i < length; i++) { 94 | int high = Character.digit(hex[i * 2], 16); 95 | int low = Character.digit(hex[i * 2 + 1], 16); 96 | if (high < 0 || low < 0) { 97 | throw new RuntimeException("Invalid hex digit " + hex[i * 2] + hex[i * 2 + 1]); 98 | } 99 | int value = (high << 4) | low; 100 | if (value > 127) 101 | value -= 256; 102 | raw[i] = (byte) value; 103 | } 104 | return raw; 105 | } 106 | 107 | public static byte[] toBytesReversed(String hexString) { 108 | byte[] rawBytes = toBytes(hexString); 109 | 110 | for (int i = 0; i < rawBytes.length / 2; i++) { 111 | byte temp = rawBytes[rawBytes.length - i - 1]; 112 | rawBytes[rawBytes.length - i - 1] = rawBytes[i]; 113 | rawBytes[i] = temp; 114 | } 115 | 116 | return rawBytes; 117 | } 118 | 119 | public static void appendByteAsHex(StringBuilder sb, byte b) { 120 | int unsignedByte = b & 0xFF; 121 | if (unsignedByte < 16) { 122 | sb.append("0"); 123 | } 124 | sb.append(Integer.toHexString(unsignedByte)); 125 | } 126 | } 127 | 128 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/RefValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander; 25 | 26 | /** 27 | * Created by swapnibble on 2017-09-28. 28 | */ 29 | 30 | public class RefValue { 31 | public T data; 32 | 33 | public RefValue() { 34 | data = null; 35 | } 36 | 37 | public RefValue(T initialVal) { 38 | data = initialVal; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander; 25 | 26 | 27 | public class StringUtils { 28 | public static boolean isEmpty(CharSequence data) { 29 | return (null == data) || (data.length() <= 0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/digest/GeneralDigest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, 2014 Megion Research & Development GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.metallicus.protonsdk.eosio.commander.digest; 18 | 19 | /** 20 | * base implementation of MD4 family style digest as outlined in 21 | * "Handbook of Applied Cryptography", pages 344 - 347. 22 | */ 23 | public abstract class GeneralDigest { 24 | private static final int BYTE_LENGTH = 64; 25 | private byte[] xBuf; 26 | private int xBufOff; 27 | 28 | private long byteCount; 29 | 30 | /** 31 | * Standard constructor 32 | */ 33 | protected GeneralDigest() { 34 | xBuf = new byte[4]; 35 | xBufOff = 0; 36 | } 37 | 38 | /** 39 | * Copy constructor. We are using copy constructors in place of the 40 | * Object.clone() interface as this interface is not supported by J2ME. 41 | */ 42 | protected GeneralDigest(GeneralDigest t) { 43 | xBuf = new byte[t.xBuf.length]; 44 | System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length); 45 | 46 | xBufOff = t.xBufOff; 47 | byteCount = t.byteCount; 48 | } 49 | 50 | public void update(byte in) { 51 | xBuf[xBufOff++] = in; 52 | 53 | if (xBufOff == xBuf.length) { 54 | processWord(xBuf, 0); 55 | xBufOff = 0; 56 | } 57 | 58 | byteCount++; 59 | } 60 | 61 | public void update(byte[] in, int inOff, int len) { 62 | // 63 | // fill the current word 64 | // 65 | while ((xBufOff != 0) && (len > 0)) { 66 | update(in[inOff]); 67 | 68 | inOff++; 69 | len--; 70 | } 71 | 72 | // 73 | // process whole words. 74 | // 75 | while (len > xBuf.length) { 76 | processWord(in, inOff); 77 | 78 | inOff += xBuf.length; 79 | len -= xBuf.length; 80 | byteCount += xBuf.length; 81 | } 82 | 83 | // 84 | // load in the remainder. 85 | // 86 | while (len > 0) { 87 | update(in[inOff]); 88 | 89 | inOff++; 90 | len--; 91 | } 92 | } 93 | 94 | public void finish() { 95 | long bitLength = (byteCount << 3); 96 | 97 | // 98 | // add the pad bytes. 99 | // 100 | update((byte) 128); 101 | 102 | while (xBufOff != 0) { 103 | update((byte) 0); 104 | } 105 | 106 | processLength(bitLength); 107 | 108 | processBlock(); 109 | } 110 | 111 | public void reset() { 112 | byteCount = 0; 113 | 114 | xBufOff = 0; 115 | for (int i = 0; i < xBuf.length; i++) { 116 | xBuf[i] = 0; 117 | } 118 | } 119 | 120 | public int getByteLength() { 121 | return BYTE_LENGTH; 122 | } 123 | 124 | protected abstract void processWord(byte[] in, int inOff); 125 | 126 | protected abstract void processLength(long bitLength); 127 | 128 | protected abstract void processBlock(); 129 | } 130 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/digest/Sha256.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander.digest; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.metallicus.protonsdk.eosio.commander.HexUtils; 5 | 6 | import java.security.MessageDigest; 7 | import java.security.NoSuchAlgorithmException; 8 | import java.util.Arrays; 9 | 10 | /** 11 | * represents the result of a SHA256 hashing operation prefer to use the static 12 | * factory methods. 13 | */ 14 | public class Sha256 { 15 | 16 | public static final int HASH_LENGTH = 32; 17 | public static final Sha256 ZERO_HASH = new Sha256(new byte[HASH_LENGTH]); 18 | 19 | final private byte[] mHashBytes; 20 | 21 | /** 22 | * create Sha256 from raw hash bytes. 23 | * 24 | * @param bytes 25 | */ 26 | public Sha256(byte[] bytes) { 27 | Preconditions.checkArgument(bytes.length == HASH_LENGTH); 28 | this.mHashBytes = bytes; 29 | } 30 | 31 | public static MessageDigest getSha256Digest() { 32 | try { 33 | return MessageDigest.getInstance("SHA-256"); 34 | } catch (NoSuchAlgorithmException e) { 35 | throw new RuntimeException(e); //cannot happen 36 | } 37 | } 38 | 39 | public static Sha256 from(byte[] data) { 40 | MessageDigest digest; 41 | digest = getSha256Digest(); 42 | digest.update(data, 0, data.length); 43 | return new Sha256(digest.digest()); 44 | } 45 | 46 | public static Sha256 from(byte[] data, int offset, int length) { 47 | MessageDigest digest; 48 | digest = getSha256Digest(); 49 | digest.update(data, offset, length); 50 | return new Sha256(digest.digest()); 51 | } 52 | 53 | public static Sha256 from(byte[] data1, byte[] data2) { 54 | MessageDigest digest; 55 | digest = getSha256Digest(); 56 | digest.update(data1, 0, data1.length); 57 | digest.update(data2, 0, data2.length); 58 | return new Sha256(digest.digest()); 59 | 60 | } 61 | 62 | public static Sha256 doubleHash(byte[] data, int offset, int length) { 63 | MessageDigest digest; 64 | digest = getSha256Digest(); 65 | digest.update(data, offset, length); 66 | return new Sha256(digest.digest(digest.digest())); 67 | } 68 | 69 | 70 | @Override 71 | public boolean equals(Object other) { 72 | if (other == this) { 73 | return true; 74 | } 75 | if (!(other instanceof Sha256)) 76 | return false; 77 | return Arrays.equals(mHashBytes, ((Sha256) other).mHashBytes); 78 | } 79 | 80 | 81 | @Override 82 | public String toString() { 83 | return HexUtils.toHex(mHashBytes); 84 | } 85 | 86 | public byte[] getBytes() { 87 | return mHashBytes; 88 | } 89 | 90 | public boolean equalsFromOffset(byte[] toCompareData, int offsetInCompareData, int len) { 91 | if ((null == toCompareData) || (offsetInCompareData < 0) 92 | || (len < 0) || (mHashBytes.length <= len) 93 | || (toCompareData.length <= offsetInCompareData)) { 94 | return false; 95 | } 96 | 97 | for (int i = 0; i < len; i++) { 98 | 99 | if (mHashBytes[i] != toCompareData[offsetInCompareData + i]) { 100 | return false; 101 | } 102 | } 103 | 104 | return true; 105 | } 106 | 107 | public int length() { 108 | return HASH_LENGTH; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/digest/Sha512.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander.digest; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.primitives.Ints; 5 | import com.metallicus.protonsdk.eosio.commander.HexUtils; 6 | 7 | import java.security.MessageDigest; 8 | import java.security.NoSuchAlgorithmException; 9 | import java.util.Arrays; 10 | 11 | public class Sha512 implements Comparable { 12 | 13 | public static final int HASH_LENGTH = 64; 14 | public static final Sha512 ZERO_HASH = new Sha512(new byte[HASH_LENGTH]); 15 | 16 | final private byte[] mHashBytes; 17 | 18 | public Sha512(byte[] bytes) { 19 | Preconditions.checkArgument(bytes.length == HASH_LENGTH); 20 | this.mHashBytes = bytes; 21 | } 22 | 23 | public static Sha512 from(byte[] data) { 24 | MessageDigest digest; 25 | try { 26 | digest = MessageDigest.getInstance("SHA-512"); 27 | } catch (NoSuchAlgorithmException e) { 28 | throw new RuntimeException(e); //cannot happen 29 | } 30 | 31 | digest.update(data, 0, data.length); 32 | 33 | return new Sha512(digest.digest()); 34 | } 35 | 36 | 37 | private Sha512(byte[] bytes, int offset) { 38 | //defensive copy, since incoming bytes is of arbitrary length 39 | mHashBytes = new byte[HASH_LENGTH]; 40 | System.arraycopy(bytes, offset, mHashBytes, 0, HASH_LENGTH); 41 | } 42 | 43 | @Override 44 | public boolean equals(Object other) { 45 | if (other == this) { 46 | return true; 47 | } 48 | if (!(other instanceof Sha512)) 49 | return false; 50 | return Arrays.equals(mHashBytes, ((Sha512) other).mHashBytes); 51 | } 52 | 53 | 54 | @Override 55 | public String toString() { 56 | return HexUtils.toHex(mHashBytes); 57 | } 58 | 59 | public byte[] getBytes() { 60 | return mHashBytes; 61 | } 62 | 63 | @Override 64 | public int compareTo(Sha512 o) { 65 | for (int i = 0; i < HASH_LENGTH; i++) { 66 | byte myByte = mHashBytes[i]; 67 | byte otherByte = o.mHashBytes[i]; 68 | 69 | final int compare = Ints.compare(myByte, otherByte); 70 | if (compare != 0) 71 | return compare; 72 | } 73 | return 0; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/CurveParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.metallicus.protonsdk.eosio.commander.ec; 26 | 27 | import com.metallicus.protonsdk.eosio.commander.HexUtils; 28 | 29 | import java.math.BigInteger; 30 | 31 | /** 32 | * Created by swapnibble on 2018-02-02. 33 | */ 34 | 35 | public class CurveParam { 36 | public static final int SECP256_K1 = 0; 37 | public static final int SECP256_R1 = 1; 38 | 39 | private final int curveParamType; 40 | private final EcCurve curve; 41 | private final EcPoint G; 42 | private final BigInteger n; 43 | //private final BigInteger h; 44 | 45 | private final BigInteger HALF_CURVE_ORDER; 46 | 47 | public CurveParam(int curveParamType, String pInHex, String aInHex, String bInHex, String GxInHex, String GyInHex, String nInHex) { 48 | this.curveParamType = curveParamType; 49 | BigInteger p = new BigInteger(pInHex, 16); //p 50 | BigInteger b = new BigInteger(bInHex, 16); 51 | BigInteger a = new BigInteger(aInHex, 16); 52 | curve = new EcCurve(p, a, b); 53 | 54 | G = curve.decodePoint(HexUtils.toBytes("04" + GxInHex + GyInHex)); 55 | n = new BigInteger(nInHex, 16); 56 | //h = BigInteger.ONE; 57 | 58 | HALF_CURVE_ORDER = n.shiftRight(1); 59 | } 60 | 61 | public int getCurveParamType() { 62 | return curveParamType; 63 | } 64 | 65 | public boolean isType(int paramType) { 66 | return curveParamType == paramType; 67 | } 68 | 69 | 70 | public EcPoint G() { 71 | return this.G; 72 | } 73 | 74 | public BigInteger n() { 75 | return this.n; 76 | } 77 | 78 | public BigInteger halfCurveOrder() { 79 | return HALF_CURVE_ORDER; 80 | } 81 | 82 | public EcCurve getCurve() { 83 | return curve; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/EcCurve.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, 2014 Megion Research & Development GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * modified by swapnibble from plactal.io 19 | * This code was extracted from the Java cryptography library from 20 | * www.bouncycastle.org. The code has been formatted to comply with the rest of 21 | * the formatting in this library. 22 | */ 23 | package com.metallicus.protonsdk.eosio.commander.ec; 24 | 25 | import java.math.BigInteger; 26 | 27 | /** 28 | * An elliptic curve 29 | */ 30 | public class EcCurve { 31 | 32 | private EcFieldElement _a; 33 | private EcFieldElement _b; 34 | private BigInteger _q; 35 | private EcPoint _infinity; 36 | 37 | public EcCurve(BigInteger q, BigInteger a, BigInteger b) { 38 | this._q = q; 39 | this._a = fromBigInteger(a); 40 | this._b = fromBigInteger(b); 41 | this._infinity = new EcPoint(this, null, null); 42 | } 43 | 44 | public EcFieldElement getA() { 45 | return _a; 46 | } 47 | 48 | public EcFieldElement getB() { 49 | return _b; 50 | } 51 | 52 | public BigInteger getQ() { 53 | return _q; 54 | } 55 | 56 | public EcPoint getInfinity() { 57 | return _infinity; 58 | } 59 | 60 | public int getFieldSize() { 61 | return _q.bitLength(); 62 | } 63 | 64 | public EcFieldElement fromBigInteger(BigInteger x) { 65 | return new EcFieldElement(this._q, x); 66 | } 67 | 68 | 69 | public EcPoint decodePoint(byte[] encodedPoint) { 70 | EcPoint p = null; 71 | // Switch on encoding type 72 | switch (encodedPoint[0]) { 73 | case 0x00: 74 | p = getInfinity(); 75 | break; 76 | case 0x02: 77 | case 0x03: 78 | int ytilde = encodedPoint[0] & 1; 79 | byte[] i = new byte[encodedPoint.length - 1]; 80 | System.arraycopy(encodedPoint, 1, i, 0, i.length); 81 | EcFieldElement x = new EcFieldElement(this._q, new BigInteger(1, i)); 82 | EcFieldElement alpha = x.multiply(x.square().add(_a)).add(_b); 83 | EcFieldElement beta = alpha.sqrt(); 84 | if (beta == null) { 85 | throw new RuntimeException("Invalid compression"); 86 | } 87 | int bit0 = (beta.toBigInteger().testBit(0) ? 1 : 0); 88 | if (bit0 == ytilde) { 89 | p = new EcPoint(this, x, beta, true); 90 | } else { 91 | p = new EcPoint(this, x, new EcFieldElement(this._q, _q.subtract(beta.toBigInteger())), true); 92 | } 93 | break; 94 | case 0x04: 95 | case 0x06: 96 | case 0x07: 97 | byte[] xEnc = new byte[(encodedPoint.length - 1) / 2]; 98 | byte[] yEnc = new byte[(encodedPoint.length - 1) / 2]; 99 | System.arraycopy(encodedPoint, 1, xEnc, 0, xEnc.length); 100 | System.arraycopy(encodedPoint, xEnc.length + 1, yEnc, 0, yEnc.length); 101 | p = new EcPoint(this, new EcFieldElement(this._q, new BigInteger(1, xEnc)), new EcFieldElement(this._q, 102 | new BigInteger(1, yEnc))); 103 | break; 104 | default: 105 | throw new RuntimeException("Invalid encoding 0x" + Integer.toString(encodedPoint[0], 16)); 106 | } 107 | return p; 108 | } 109 | 110 | @Override 111 | public boolean equals(Object obj) { 112 | if (obj == this) { 113 | return true; 114 | } 115 | if (!(obj instanceof EcCurve)) { 116 | return false; 117 | } 118 | EcCurve other = (EcCurve) obj; 119 | return this._q.equals(other._q) && _a.equals(other._a) && _b.equals(other._b); 120 | } 121 | 122 | @Override 123 | public int hashCode() { 124 | return _a.hashCode() ^ _b.hashCode() ^ _q.hashCode(); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/chain/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander.model.chain; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.metallicus.protonsdk.eosio.commander.model.types.EosType; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by swapnibble on 2018-03-19. 11 | */ 12 | 13 | public class Transaction extends TransactionHeader { 14 | @Expose 15 | private List context_free_actions = new ArrayList<>(); 16 | 17 | @Expose 18 | private List actions = null; 19 | 20 | // Extensions are prefixed with type and are a buffer that can be interpreted by code that is aware and ignored by unaware code. 21 | @Expose 22 | private List transaction_extensions = new ArrayList<>(); 23 | 24 | public Transaction() { 25 | super(); 26 | } 27 | 28 | public Transaction(Transaction other) { 29 | super(other); 30 | this.context_free_actions = deepCopyOnlyContainer(other.context_free_actions); 31 | this.actions = deepCopyActions(other.actions); 32 | this.transaction_extensions = other.transaction_extensions; 33 | } 34 | 35 | public void addAction(Action msg) { 36 | if (null == actions) { 37 | actions = new ArrayList<>(1); 38 | } 39 | 40 | actions.add(msg); 41 | } 42 | 43 | 44 | public List getActions() { 45 | return actions; 46 | } 47 | 48 | public void setActions(List actions) { 49 | this.actions = actions; 50 | } 51 | 52 | public int getContextFreeActionCount() { 53 | return (actions == null ? 0 : actions.size()); 54 | } 55 | 56 | 57 | List deepCopyOnlyContainer(List srcList) { 58 | if (null == srcList) { 59 | return null; 60 | } 61 | 62 | List newList = new ArrayList<>(srcList.size()); 63 | newList.addAll(srcList); 64 | 65 | return newList; 66 | } 67 | 68 | // Added by joey-harward on 8/7/19 69 | private List deepCopyActions(List actions) { 70 | if (null == actions) { 71 | return null; 72 | } 73 | 74 | List newList = new ArrayList<>(actions.size()); 75 | 76 | for (Action action : actions) { 77 | Action actionDeepCopy = new Action(action); 78 | newList.add(actionDeepCopy); 79 | } 80 | 81 | return newList; 82 | } 83 | 84 | @Override 85 | public void pack(EosType.Writer writer) { 86 | super.pack(writer); 87 | 88 | writer.putCollection(context_free_actions); 89 | writer.putCollection(actions); 90 | //writer.putCollection(transaction_extensions); 91 | writer.putVariableUInt(transaction_extensions.size()); 92 | if (transaction_extensions.size() > 0) { 93 | // TODO 구체적 코드가 나오면 확인후 구현할 것. 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/chain/TransactionHeader.java: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk.eosio.commander.model.chain; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.metallicus.protonsdk.eosio.commander.BitUtils; 5 | import com.metallicus.protonsdk.eosio.commander.HexUtils; 6 | import com.metallicus.protonsdk.eosio.commander.model.types.EosType; 7 | 8 | import java.math.BigInteger; 9 | import java.text.DateFormat; 10 | import java.text.ParseException; 11 | import java.text.SimpleDateFormat; 12 | import java.util.Date; 13 | import java.util.Locale; 14 | import java.util.TimeZone; 15 | 16 | /** 17 | * Created by swapnibble on 2018-03-19. 18 | */ 19 | 20 | public class TransactionHeader implements EosType.Packer { 21 | @Expose 22 | private String expiration; 23 | 24 | @Expose 25 | private int ref_block_num = 0; // uint16_t 26 | 27 | @Expose 28 | private long ref_block_prefix = 0;// uint32_t 29 | 30 | @Expose 31 | private long max_net_usage_words; // fc::unsigned_int 32 | 33 | @Expose 34 | private long max_cpu_usage_ms; // fc::unsigned_int 35 | 36 | @Expose 37 | private long delay_sec; // fc::unsigned_int 38 | 39 | public TransactionHeader() { 40 | } 41 | 42 | public TransactionHeader(TransactionHeader other) { 43 | this.expiration = other.expiration; 44 | this.ref_block_num = other.ref_block_num; 45 | this.ref_block_prefix = other.ref_block_prefix; 46 | this.max_net_usage_words = other.max_net_usage_words; 47 | this.max_cpu_usage_ms = other.max_cpu_usage_ms; 48 | this.delay_sec = other.delay_sec; 49 | } 50 | 51 | public String getExpiration() { 52 | return expiration; 53 | } 54 | 55 | public void setExpiration(String expiration) { 56 | this.expiration = expiration; 57 | } 58 | 59 | public void setReferenceBlock(String refBlockIdAsSha256) { 60 | ref_block_num = new BigInteger(1, HexUtils.toBytes(refBlockIdAsSha256.substring(0, 8))).intValue(); 61 | 62 | ref_block_prefix = //new BigInteger( 1, HexUtils.toBytesReversed( refBlockIdAsSha256.substring(16,24))).longValue(); 63 | BitUtils.uint32ToLong(HexUtils.toBytes(refBlockIdAsSha256.substring(16, 24)), 0); 64 | // BitUtils treats bytes in little endian, so no need to reverse bytes. 65 | } 66 | 67 | public int getRefBlockNum() { 68 | return ref_block_num; 69 | } 70 | 71 | public long getRefBlockPrefix() { 72 | return ref_block_prefix; 73 | } 74 | 75 | private Date getExpirationAsDate(String dateStr) { 76 | DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US); 77 | try { 78 | sdf.setTimeZone(TimeZone.getTimeZone("UTC")); 79 | return sdf.parse(dateStr); 80 | 81 | } catch (ParseException e) { 82 | e.printStackTrace(); 83 | return new Date(); 84 | } 85 | } 86 | 87 | public Long getMaxNetUsageWords() { 88 | return max_net_usage_words; 89 | } 90 | 91 | public void setMaxNetUsageWords(long netUsage) { 92 | this.max_net_usage_words = netUsage; 93 | } 94 | 95 | public Long getMaxCpuUsageMs() { 96 | return max_cpu_usage_ms; 97 | } 98 | 99 | public void setMaxCpuUsageMs(long kCpuUsage) { 100 | this.max_cpu_usage_ms = kCpuUsage; 101 | } 102 | 103 | public Long getDelaySec() { 104 | return delay_sec; 105 | } 106 | 107 | public void setDelaySec(long delaySec) { 108 | this.delay_sec = delaySec; 109 | } 110 | 111 | @Override 112 | public void pack(EosType.Writer writer) { 113 | writer.putIntLE((int) (getExpirationAsDate(expiration).getTime() / 1000)); // ms -> sec 114 | 115 | writer.putShortLE((short) (ref_block_num & 0xFFFF)); // uint16 116 | writer.putIntLE((int) (ref_block_prefix & 0xFFFFFFFF));// uint32 117 | 118 | // fc::unsigned_int 119 | writer.putVariableUInt(max_net_usage_words); 120 | writer.putVariableUInt(max_cpu_usage_ms); 121 | writer.putVariableUInt(delay_sec); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/EosByteReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | public class EosByteReader implements EosType.Reader { 27 | 28 | private byte[] _buf; 29 | private int _index; 30 | 31 | public EosByteReader(byte[] buf) { 32 | _buf = buf; 33 | _index = 0; 34 | } 35 | 36 | public EosByteReader(byte[] buf, int index) { 37 | _buf = buf; 38 | _index = index; 39 | } 40 | 41 | @Override 42 | public byte get() throws EosType.InsufficientBytesException { 43 | checkAvailable(1); 44 | return _buf[_index++]; 45 | } 46 | 47 | 48 | @Override 49 | public int getShortLE() throws EosType.InsufficientBytesException { 50 | checkAvailable(2); 51 | return (((_buf[_index++] & 0xFF)) | ((_buf[_index++] & 0xFF) << 8)) & 0xFFFF; 52 | } 53 | 54 | @Override 55 | public int getIntLE() throws EosType.InsufficientBytesException { 56 | checkAvailable(4); 57 | return ((_buf[_index++] & 0xFF)) | ((_buf[_index++] & 0xFF) << 8) | ((_buf[_index++] & 0xFF) << 16) 58 | | ((_buf[_index++] & 0xFF) << 24); 59 | } 60 | 61 | 62 | @Override 63 | public long getLongLE() throws EosType.InsufficientBytesException { 64 | checkAvailable(8); 65 | return ((_buf[_index++] & 0xFFL)) | ((_buf[_index++] & 0xFFL) << 8) | ((_buf[_index++] & 0xFFL) << 16) 66 | | ((_buf[_index++] & 0xFFL) << 24) | ((_buf[_index++] & 0xFFL) << 32) | ((_buf[_index++] & 0xFFL) << 40) 67 | | ((_buf[_index++] & 0xFFL) << 48) | ((_buf[_index++] & 0xFFL) << 56); 68 | } 69 | 70 | @Override 71 | public byte[] getBytes(int size) throws EosType.InsufficientBytesException { 72 | checkAvailable(size); 73 | byte[] bytes = new byte[size]; 74 | System.arraycopy(_buf, _index, bytes, 0, size); 75 | _index += size; 76 | return bytes; 77 | } 78 | 79 | @Override 80 | public String getString() throws EosType.InsufficientBytesException { 81 | int size = (int) (getVariableUint() & 0x7FFFFFFF); // put 에서 variable uint 로 넣음. 82 | byte[] bytes = getBytes(size); 83 | return new String(bytes); 84 | } 85 | 86 | @Override 87 | public long getVariableUint() throws EosType.InsufficientBytesException { 88 | 89 | long v = 0; 90 | byte b, by = 0; 91 | do { 92 | b = get(); 93 | v |= (b & 0x7F) << by; 94 | by += 7; 95 | } 96 | while ((b & 0x80) != 0); 97 | 98 | return v; 99 | } 100 | 101 | 102 | private void checkAvailable(int num) throws EosType.InsufficientBytesException { 103 | if (_buf.length - _index < num) { 104 | throw new EosType.InsufficientBytesException(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/EosTransfer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import com.google.gson.JsonElement; 27 | import com.google.gson.JsonParser; 28 | import com.google.gson.annotations.Expose; 29 | import com.metallicus.protonsdk.eosio.commander.HexUtils; 30 | import com.metallicus.protonsdk.eosio.commander.Utils; 31 | 32 | /** 33 | * Created by swapnibble on 2017-09-15. 34 | */ 35 | 36 | public class EosTransfer implements EosType.Packer { 37 | @Expose 38 | private TypeAccountName from; 39 | 40 | @Expose 41 | private TypeAccountName to; 42 | 43 | @Expose 44 | private TypeAsset quantity; 45 | 46 | @Expose 47 | private String memo; 48 | 49 | public EosTransfer(String from, String to, long quantity, String memo) { 50 | this(new TypeAccountName(from), new TypeAccountName(to), quantity, memo); 51 | } 52 | 53 | public EosTransfer(TypeAccountName from, TypeAccountName to, long quantity, String memo) { 54 | this.from = from; 55 | this.to = to; 56 | this.quantity = new TypeAsset(quantity); 57 | this.memo = memo != null ? memo : ""; 58 | } 59 | 60 | public EosTransfer(String from, String to, String quantity, String memo) { 61 | this(new TypeAccountName(from), new TypeAccountName(to), quantity, memo); 62 | } 63 | 64 | public EosTransfer(TypeAccountName from, TypeAccountName to, String quantity, String memo) { 65 | this.from = from; 66 | this.to = to; 67 | this.quantity = new TypeAsset(quantity); 68 | this.memo = memo != null ? memo : ""; 69 | } 70 | 71 | public String getAction() { 72 | return "transfer"; 73 | } 74 | 75 | public String[] getActivePermission() { 76 | return new String[]{from + "@active"}; 77 | } 78 | 79 | @Override 80 | public void pack(EosType.Writer writer) { 81 | 82 | from.pack(writer); 83 | to.pack(writer); 84 | 85 | writer.putLongLE(quantity.getAmount()); 86 | 87 | writer.putString(memo); 88 | } 89 | 90 | public String getAsHex() { 91 | EosType.Writer writer = new EosByteWriter(128); 92 | pack(writer); 93 | 94 | return HexUtils.toHex(writer.toBytes()); 95 | } 96 | 97 | // Added by joey-harward on 7/1/20 98 | public String jsonToBinArgs() { 99 | return Utils.prettyPrintJson(this); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/EosType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import java.util.Collection; 27 | 28 | /** 29 | * Created by swapnibble on 2017-09-12. 30 | */ 31 | 32 | public interface EosType { 33 | class InsufficientBytesException extends Exception { 34 | 35 | private static final long serialVersionUID = 1L; 36 | } 37 | 38 | interface Packer { 39 | void pack(Writer writer); 40 | } 41 | 42 | interface Unpacker { 43 | void unpack(Reader reader) throws InsufficientBytesException; 44 | } 45 | 46 | interface Reader { 47 | byte get() throws InsufficientBytesException; 48 | 49 | int getShortLE() throws InsufficientBytesException; 50 | 51 | int getIntLE() throws InsufficientBytesException; 52 | 53 | long getLongLE() throws InsufficientBytesException; 54 | 55 | byte[] getBytes(int size) throws InsufficientBytesException; 56 | 57 | String getString() throws InsufficientBytesException; 58 | 59 | long getVariableUint() throws InsufficientBytesException; 60 | } 61 | 62 | interface Writer { 63 | void put(byte b); 64 | 65 | void putShortLE(short value); 66 | 67 | void putIntLE(int value); 68 | 69 | void putLongLE(long value); 70 | 71 | void putBytes(byte[] value); 72 | 73 | void putString(String value); 74 | 75 | byte[] toBytes(); 76 | 77 | int length(); 78 | 79 | void putCollection(Collection collection); 80 | 81 | void putVariableUInt(long val); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypeAccountName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import com.metallicus.protonsdk.eosio.commander.StringUtils; 27 | 28 | /** 29 | * Created by swapnibble on 2017-09-12. 30 | */ 31 | 32 | public class TypeAccountName extends TypeName { 33 | private static final int MAX_ACCOUNT_NAME_LEN = 12; 34 | 35 | // private static final char CHAR_NOT_ALLOWED = '.'; 36 | 37 | public TypeAccountName(String name) { 38 | super(name); 39 | 40 | if (!StringUtils.isEmpty(name)) { 41 | if (name.length() > MAX_ACCOUNT_NAME_LEN) { 42 | throw new IllegalArgumentException("account name can only be 12 chars long: " + name); // changed from dawn3 43 | } 44 | 45 | // if ( (name.indexOf( CHAR_NOT_ALLOWED) >= 0) && ! name.startsWith("eosio.") ){ 46 | // throw new IllegalArgumentException("account name must not contain '.': " + name); 47 | // } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypeActionName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | 27 | /** 28 | * Created by swapnibble on 2017-09-12. 29 | */ 30 | public class TypeActionName extends TypeName { 31 | public TypeActionName(long nameAsLong) { 32 | super(nameAsLong); 33 | } 34 | 35 | public TypeActionName(String name) { 36 | super(name); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypeChainId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import com.metallicus.protonsdk.eosio.commander.digest.Sha256; 27 | 28 | /** 29 | * Created by swapnibble on 2017-10-30. 30 | */ 31 | 32 | public class TypeChainId { 33 | private final Sha256 mId; 34 | 35 | public TypeChainId() { 36 | mId = Sha256.ZERO_HASH; 37 | } 38 | 39 | byte[] getSha256FromHexStr(String str) { 40 | int len = str.length(); 41 | byte[] bytes = new byte[32]; 42 | for (int i = 0; i < len; i += 2) { 43 | String strIte = str.substring(i, i + 2); 44 | Integer n = Integer.parseInt(strIte, 16) & 0xFF; 45 | ; 46 | bytes[i / 2] = n.byteValue(); 47 | } 48 | return bytes; 49 | } 50 | 51 | public TypeChainId(String str) { 52 | mId = new Sha256(getSha256FromHexStr(str)); 53 | } 54 | 55 | public byte[] getBytes() { 56 | return mId.getBytes(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypeName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import java.util.Arrays; 27 | 28 | /** 29 | * Created by swapnibble on 2017-09-12. 30 | */ 31 | 32 | public class TypeName implements EosType.Packer { 33 | private static final String CHAR_MAP = ".12345abcdefghijklmnopqrstuvwxyz"; 34 | 35 | private static final int MAX_NAME_IDX = 12; 36 | private long mValue; 37 | 38 | static byte char_to_symbol(char c) { 39 | if (c >= 'a' && c <= 'z') 40 | return (byte) ((c - 'a') + 6); 41 | if (c >= '1' && c <= '5') 42 | return (byte) ((c - '1') + 1); 43 | 44 | return (byte) 0; 45 | } 46 | 47 | static public long string_to_name(String str) { 48 | if (null == str) { 49 | return 0L; 50 | } 51 | 52 | int len = str.length(); 53 | long value = 0; 54 | 55 | for (int i = 0; i <= MAX_NAME_IDX; i++) { 56 | long c = 0; 57 | 58 | if (i < len && i <= MAX_NAME_IDX) c = char_to_symbol(str.charAt(i)); 59 | 60 | if (i < MAX_NAME_IDX) { 61 | c &= 0x1f; 62 | c <<= 64 - 5 * (i + 1); 63 | } else { 64 | c &= 0x0f; 65 | } 66 | 67 | value |= c; 68 | } 69 | 70 | return value; 71 | } 72 | 73 | static public String name_to_string(long nameAsLong) { 74 | long tmp = nameAsLong; 75 | 76 | char[] result = new char[MAX_NAME_IDX + 1]; 77 | Arrays.fill(result, ' '); 78 | 79 | for (int i = 0; i <= MAX_NAME_IDX; ++i) { 80 | char c = CHAR_MAP.charAt((int) (tmp & (i == 0 ? 0x0f : 0x1f))); 81 | result[MAX_NAME_IDX - i] = c; 82 | tmp >>= (i == 0 ? 4 : 5); 83 | } 84 | 85 | return String.valueOf(result).replaceAll("[.]+$", ""); // remove trailing dot 86 | } 87 | 88 | public TypeName(long nameAsLong) { 89 | mValue = nameAsLong; 90 | } 91 | 92 | public TypeName(String name) { 93 | mValue = string_to_name(name); 94 | } 95 | 96 | @Override 97 | public void pack(EosType.Writer writer) { 98 | writer.putLongLE(mValue); 99 | } 100 | 101 | @Override 102 | public String toString() { 103 | return name_to_string(mValue); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypePermissionLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | import com.google.gson.annotations.Expose; 27 | 28 | 29 | /** 30 | * Created by swapnibble on 2017-09-12. 31 | */ 32 | 33 | public class TypePermissionLevel implements EosType.Packer { 34 | 35 | @Expose 36 | private TypeAccountName actor; 37 | 38 | @Expose 39 | private TypePermissionName permission; 40 | 41 | public TypePermissionLevel(String accountName, String permissionName) { 42 | actor = new TypeAccountName(accountName); 43 | permission = new TypePermissionName(permissionName); 44 | } 45 | 46 | public String getAccount() { 47 | return actor.toString(); 48 | } 49 | 50 | public void setAccount(String accountName) { 51 | actor = new TypeAccountName(accountName); 52 | } 53 | 54 | public String getPermission() { 55 | return permission.toString(); 56 | } 57 | 58 | public void setPermission(String permissionName) { 59 | permission = new TypePermissionName(permissionName); 60 | } 61 | 62 | @Override 63 | public void pack(EosType.Writer writer) { 64 | 65 | actor.pack(writer); 66 | permission.pack(writer); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypePermissionName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | /** 27 | * Created by swapnibble on 2017-09-12. 28 | */ 29 | 30 | public class TypePermissionName extends TypeName { 31 | public TypePermissionName(String name) { 32 | super(name); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/model/types/TypeScopeName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2018 PLACTAL. 3 | * 4 | * The MIT License 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.metallicus.protonsdk.eosio.commander.model.types; 25 | 26 | /** 27 | * Created by swapnibble on 2018-04-04. 28 | */ 29 | 30 | public class TypeScopeName extends TypeName { 31 | public TypeScopeName(String name) { 32 | super(name); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/Account.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import androidx.room.* 25 | import com.google.gson.annotations.SerializedName 26 | 27 | @Entity 28 | data class Account( 29 | @PrimaryKey 30 | @SerializedName("account_name") val accountName: String, 31 | 32 | @SerializedName("head_block_num") val headBlockNum: Int, 33 | @SerializedName("head_block_time") val headBlockTime: String, 34 | @SerializedName("privileged") val privileged: Boolean, 35 | @SerializedName("last_code_update") val lastCodeUpdate: String, 36 | @SerializedName("created") val created: String, 37 | @SerializedName("core_liquid_balance") val coreLiquidBalance: String?, 38 | @SerializedName("ram_quota") val ramQuota: Int, 39 | @SerializedName("net_weight") val netWeight: Long, 40 | @SerializedName("cpu_weight") val cpuWeight: Long, 41 | @SerializedName("ram_usage") val ramUsage: Long, 42 | 43 | @SerializedName("net_limit") 44 | @Embedded(prefix = "net_limit_") val netLimit: AccountNetLimit, 45 | 46 | @SerializedName("cpu_limit") 47 | @Embedded(prefix = "cpu_limit_") val cpuLimit: AccountCpuLimit, 48 | 49 | @SerializedName("permissions") val permissions: List, 50 | 51 | @SerializedName("total_resources") 52 | @Embedded(prefix = "total_resources_") val totalResources: AccountTotalResources, 53 | 54 | @SerializedName("self_delegated_bandwidth") 55 | @Embedded(prefix = "self_delegated_bandwidth_") val selfDelegatedBandwidth: AccountSelfDelegatedBandwidth?, 56 | 57 | @SerializedName("voter_info") 58 | @Embedded(prefix = "voter_info_") val voterInfo: AccountVoterInfo? 59 | ) { 60 | lateinit var accountChainId: String 61 | 62 | lateinit var accountContact: AccountContact 63 | 64 | lateinit var votersXPRInfo: AccountVotersXPRInfo 65 | 66 | lateinit var refundsXPRInfo: AccountRefundsXPRInfo 67 | 68 | fun getBalance(): String { 69 | return coreLiquidBalance ?: "0" 70 | } 71 | 72 | fun getDelegatedCPU(): Double { 73 | var delegatedCPU = 0.00 74 | if (selfDelegatedBandwidth != null) { 75 | delegatedCPU = 76 | totalResources.cpuWeightToDouble() - selfDelegatedBandwidth.cpuWeightToDouble() 77 | } 78 | return delegatedCPU 79 | } 80 | 81 | fun getDelegatedNet(): Double { 82 | var delegatedNet = 0.00 83 | if (selfDelegatedBandwidth != null) { 84 | delegatedNet = 85 | totalResources.netWeightToDouble() - selfDelegatedBandwidth.netWeightToDouble() 86 | } 87 | return delegatedNet 88 | } 89 | 90 | fun getSelfDelegatedResources(): Double { 91 | var selfDelegatedResources = 0.00 92 | if (selfDelegatedBandwidth != null) { 93 | selfDelegatedResources = 94 | selfDelegatedBandwidth.cpuWeightToDouble() + selfDelegatedBandwidth.netWeightToDouble() 95 | } 96 | return selfDelegatedResources 97 | } 98 | 99 | fun getStakedXPR(): Double { 100 | return votersXPRInfo.getStakedAmount() 101 | } 102 | 103 | fun getRefundsXPR(): Double { 104 | return refundsXPRInfo.quantityToDouble() 105 | } 106 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountContact.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import android.util.Base64 25 | import androidx.annotation.NonNull 26 | 27 | //@Entity( 28 | // indices = [(Index("id", "accountName"))], 29 | // primaryKeys = ["id", "accountName"] 30 | //) 31 | data class AccountContact( 32 | val id: String, // accountName 33 | var name: String = "", 34 | var avatar: String = "", 35 | var verified: Boolean = false, 36 | var verifiedFields: List? = null 37 | ) { 38 | @NonNull 39 | lateinit var accountName: String // owner accountName 40 | 41 | fun getDisplayName(): String { 42 | return name.ifEmpty { id } 43 | } 44 | 45 | fun getAvatarByteArray(): ByteArray { 46 | return if (avatar.isEmpty()) ByteArray(0) else Base64.decode(avatar, Base64.DEFAULT) 47 | } 48 | 49 | fun isLightKYCVerified(): Boolean { 50 | val lightKYC = listOf( 51 | "lastname", 52 | "firstname", 53 | "birthdate", 54 | "address" 55 | ) 56 | 57 | return verifiedFields?.containsAll(lightKYC) ?: false 58 | } 59 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountCpuLimit.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountCpuLimit( 27 | @SerializedName("used") val used: Long, 28 | @SerializedName("available") val available: Long, 29 | @SerializedName("max") val max: Long 30 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountNetLimit.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountNetLimit( 27 | @SerializedName("used") val used: Long, 28 | @SerializedName("available") val available: Long, 29 | @SerializedName("max") val max: Long 30 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountPermission.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountPermission( 27 | @SerializedName("perm_name") val permName: String, 28 | @SerializedName("parent") val parent: String, 29 | @SerializedName("required_auth") val requiredAuth: AccountPermissionRequiredAuth 30 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountPermissionKey.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountPermissionKey( 27 | @SerializedName("key") val key: String, 28 | @SerializedName("weight") val weight: Int 29 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountPermissionRequiredAuth.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountPermissionRequiredAuth( 27 | @SerializedName("threshold") val threshold: Int, 28 | @SerializedName("keys") val keys: List 29 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountRefundsXPRInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountRefundsXPRInfo( 27 | @SerializedName("owner") val owner: String? = "", 28 | @SerializedName("quantity") val quantity: String? = "", 29 | @SerializedName("request_time") val requestTime: String? = "" 30 | ) { 31 | fun quantityToDouble(): Double { 32 | var quantityDouble = 0.0 33 | if (quantity != "") { 34 | quantityDouble = quantity?.substringBefore(" ")?.toDouble() ?: 0.0 35 | } 36 | return quantityDouble 37 | } 38 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountSelfDelegatedBandwidth.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountSelfDelegatedBandwidth( 27 | @SerializedName("from") val from: String, 28 | @SerializedName("to") val to: String, 29 | @SerializedName("net_weight") val netWeight: String, 30 | @SerializedName("cpu_weight") val cpuWeight: String 31 | ) { 32 | fun netWeightToDouble(): Double { 33 | return netWeight.substringBefore(" ").toDouble() 34 | } 35 | 36 | fun cpuWeightToDouble(): Double { 37 | return cpuWeight.substringBefore(" ").toDouble() 38 | } 39 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountTotalResources.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountTotalResources( 27 | @SerializedName("owner") val owner: String, 28 | @SerializedName("net_weight") val netWeight: String, 29 | @SerializedName("cpu_weight") val cpuWeight: String, 30 | @SerializedName("ram_bytes") val ramBytes: Int 31 | ) { 32 | fun netWeightToDouble(): Double { 33 | return netWeight.substringBefore(" ").toDouble() 34 | } 35 | 36 | fun cpuWeightToDouble(): Double { 37 | return cpuWeight.substringBefore(" ").toDouble() 38 | } 39 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountVoterInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class AccountVoterInfo( 27 | @SerializedName("owner") val owner: String, 28 | @SerializedName("proxy") val proxy: String, 29 | @SerializedName("staked") val staked: Long, 30 | @SerializedName("last_vote_weight") val lastVoteWeight: String, 31 | @SerializedName("proxied_vote_weight") val proxiedVoteWeight: String, 32 | @SerializedName("is_proxy") val isProxy: Int 33 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountVotersXPRInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeAsset 26 | import com.metallicus.protonsdk.eosio.commander.model.types.TypeSymbol 27 | 28 | data class AccountVotersXPRInfo( 29 | @SerializedName("owner") val owner: String? = "", 30 | @SerializedName("staked") val staked: Long? = 0, 31 | @SerializedName("isqualified") val isQualified: Long? = 0, 32 | @SerializedName("claimamount") val claimAmount: Long? = 0, 33 | @SerializedName("lastclaim") val lastClaim: String? = "" 34 | ) { 35 | fun getStakedAmount(): Double { 36 | var stakedAmount = 0.0 37 | if (staked != null) { 38 | val stakedAsset = TypeAsset(staked, TypeSymbol.fromString("4,XPR")) 39 | stakedAmount = stakedAsset.toString().substringBefore(" ").toDouble() 40 | } 41 | return stakedAmount 42 | } 43 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ActiveAccount.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.metallicus.protonsdk.eosio.commander.ec.EosPrivateKey 25 | 26 | //fun activeAccount(accountName: String, builder: ActiveAccount.Builder.() -> Unit): ActiveAccount = 27 | // ActiveAccount.Builder(accountName).apply(builder).create() 28 | 29 | class ActiveAccount(builder: Builder) { 30 | val accountName: String = builder.accountName 31 | val privateKey: String = builder.privateKey 32 | val pin: String = builder.pin 33 | 34 | fun hasPrivateKey(): Boolean { 35 | return privateKey.isNotEmpty() && pin.isNotEmpty() 36 | } 37 | 38 | fun getPublicKey(): String { 39 | return EosPrivateKey.getPublicKey(privateKey) 40 | } 41 | 42 | class Builder(val accountName: String) { 43 | var privateKey: String = "" 44 | var pin: String = "" 45 | 46 | fun setPrivateKey(privateKeyStr: String, pin: String): Builder { 47 | this.privateKey = privateKeyStr 48 | this.pin = pin 49 | return this 50 | } 51 | 52 | fun create(): ActiveAccount { 53 | return ActiveAccount(this) 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ChainAccount.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import androidx.room.* 25 | 26 | data class ChainAccount( 27 | @Embedded 28 | val account: Account, 29 | 30 | @Relation( 31 | parentColumn = "accountChainId", 32 | entityColumn = "chainId" 33 | ) 34 | val chainProvider: ChainProvider) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ChainInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | import java.text.ParseException 26 | import java.text.SimpleDateFormat 27 | import java.util.* 28 | 29 | data class ChainInfo( 30 | @SerializedName("server_version") val serverVersion: String, 31 | @SerializedName("chain_id") val chainId: String, 32 | @SerializedName("head_block_num") val headBlockNum: Int, 33 | @SerializedName("last_irreversible_block_num") val lastIrreversibleBlockNum: Int, 34 | @SerializedName("last_irreversible_block_id") val lastIrreversibleBlockId: String, 35 | @SerializedName("head_block_id") val headBlockId: String, 36 | @SerializedName("head_block_time") val headBlockTime: String, 37 | @SerializedName("head_block_producer") val headBlockProducer: String, 38 | @SerializedName("virtual_block_cpu_limit") val virtualBlockCpuLimit: Int, 39 | @SerializedName("virtual_block_net_limit") val virtualBlockNetLimit: Int, 40 | @SerializedName("block_cpu_limit") val blockCpuLimit: Int, 41 | @SerializedName("block_net_limit") val blockNetLimit: Int 42 | ) { 43 | fun getTimeAfterHeadBlockTime(diffInMilSec: Int): String { 44 | val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US) 45 | return try { 46 | sdf.timeZone = TimeZone.getTimeZone("UTC") 47 | 48 | val date = sdf.parse(headBlockTime) 49 | date?.let { 50 | val c = Calendar.getInstance() 51 | c.time = it 52 | c.add(Calendar.MILLISECOND, diffInMilSec) 53 | sdf.format(c.time) 54 | } ?: headBlockTime 55 | } catch (e: ParseException) { 56 | e.printStackTrace() 57 | 58 | headBlockTime 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ChainProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import androidx.room.Entity 25 | import androidx.room.PrimaryKey 26 | import com.google.gson.annotations.SerializedName 27 | 28 | @Entity 29 | data class ChainProvider( 30 | @PrimaryKey 31 | @SerializedName("chainId") val chainId: String, 32 | 33 | @SerializedName("name") val name: String, 34 | @SerializedName("description") val description: String, 35 | @SerializedName("iconUrl") val iconUrl: String, 36 | @SerializedName("isTestnet") val isTestnet: Boolean, 37 | @SerializedName("chainUrl") var chainUrl: String, 38 | @SerializedName("hyperionHistoryUrl") var hyperionHistoryUrl: String, 39 | 40 | @SerializedName("explorerName") val explorerName: String, 41 | @SerializedName("explorerUrl") val explorerUrl: String, 42 | 43 | @SerializedName("resourceTokenSymbol") val resourceTokenSymbol: String, 44 | @SerializedName("resourceTokenContract") val resourceTokenContract: String, 45 | @SerializedName("systemTokenSymbol") val systemTokenSymbol: String, 46 | @SerializedName("systemTokenContract") val systemTokenContract: String, 47 | 48 | @SerializedName("createAccountPath") val createAccountPath: String, 49 | @SerializedName("updateAccountAvatarPath") val updateAccountAvatarPath: String, 50 | @SerializedName("updateAccountNamePath") val updateAccountNamePath: String, 51 | @SerializedName("exchangeRatePath") val exchangeRatePath: String, 52 | 53 | @SerializedName("chainUrls") val chainUrls: List, 54 | @SerializedName("hyperionHistoryUrls") val hyperionHistoryUrls: List 55 | ) { 56 | lateinit var protonChainUrl: String 57 | lateinit var kycProviders: List 58 | 59 | lateinit var chainUrlStats: List 60 | lateinit var hyperionHistoryUrlStats: List 61 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ChainUrlInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | data class ChainUrlInfo( 25 | val url: String, 26 | 27 | val responseTimeMillis: Long, 28 | val blockDiff: Long, 29 | 30 | val inSync: Boolean = false 31 | ) { 32 | companion object { 33 | const val ACCEPTABLE_CHAIN_BLOCK_DIFF = 350L 34 | const val ACCEPTABLE_HYPERION_HISTORY_BLOCK_DIFF = 30L 35 | } 36 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/CurrencyBalance.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class CurrencyBalance( 27 | @SerializedName("contract") val contract: String, 28 | @SerializedName("symbol") val symbol: String, 29 | @SerializedName("amount") var amount: String = "0.0" 30 | ) { 31 | fun getAmountDouble(): Double { 32 | return amount.toDouble() 33 | } 34 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/EOSError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class EOSError( 27 | @SerializedName("code") val code: Int, 28 | @SerializedName("name") val name: String, 29 | @SerializedName("what") val what: String, 30 | @SerializedName("details") val details: List 31 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/EOSErrorDetail.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class EOSErrorDetail( 27 | @SerializedName("message") val message: String, 28 | @SerializedName("file") val file: String, 29 | @SerializedName("line_number") val lineNumber: Int, 30 | @SerializedName("method") val method: String 31 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/EOSServerError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class EOSServerError( 27 | @SerializedName("code") val code: Int, 28 | @SerializedName("message") val message: String, 29 | @SerializedName("error") val error: EOSError 30 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ESRAction.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | enum class Type { 25 | TRANSFER, 26 | CUSTOM 27 | } 28 | 29 | class ESRAction( 30 | val type: Type, 31 | val name: String, 32 | val accountName: String, 33 | val data: Map?, 34 | private val tokenContract: TokenContract?=null 35 | ) { 36 | fun isTransfer(): Boolean { 37 | return (type==Type.TRANSFER) 38 | } 39 | 40 | fun getActionName(): String { 41 | return if (isTransfer()) "Transfer" else name 42 | } 43 | 44 | fun getActionAccountName(): String { 45 | return if (isTransfer()) tokenContract?.name.orEmpty() else "@$accountName" 46 | } 47 | 48 | fun getIconUrl(): String { 49 | return tokenContract?.iconUrl.orEmpty() 50 | } 51 | 52 | fun getTransferQuantity(): String? { 53 | return data?.get("quantity") as String? 54 | } 55 | 56 | fun getTransferQuantityAmount(): String { 57 | val transferQuantity = getTransferQuantity() 58 | return transferQuantity?.split(" ")?.get(0).orEmpty() 59 | } 60 | 61 | fun getTransferQuantitySymbol(): String { 62 | val transferQuantity = getTransferQuantity() 63 | return transferQuantity?.split(" ")?.get(1).orEmpty() 64 | } 65 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ESRSession.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import androidx.room.Embedded 25 | import androidx.room.Entity 26 | import androidx.room.PrimaryKey 27 | import androidx.room.RoomWarnings 28 | import com.google.gson.annotations.SerializedName 29 | 30 | @SuppressWarnings(RoomWarnings.PRIMARY_KEY_FROM_EMBEDDED_IS_DROPPED) 31 | @Entity 32 | class ESRSession( 33 | @PrimaryKey 34 | @SerializedName("id") 35 | var id: String, 36 | @SerializedName("signer") 37 | var signer: String, 38 | @SerializedName("callbackUrl") 39 | var callbackUrl: String, 40 | @SerializedName("receiveKey") 41 | var receiveKey: String, 42 | @SerializedName("receiveChannelUrl") 43 | var receiveChannelUrl: String, 44 | @SerializedName("createdAt") 45 | var createdAt: Long, 46 | @SerializedName("updatedAt") 47 | var updatedAt: Long, 48 | 49 | @SerializedName("requester") 50 | @Embedded(prefix = "requester_") 51 | var requester: Account? = null 52 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ESRSessionMessage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | data class ESRSessionMessage(val esrSession: ESRSession, val message: String) 25 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/JsonToBinResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class JsonToBinResponse( 27 | @SerializedName("binargs") val binArgs: String, 28 | @SerializedName("required_scope") val requiredScope: List, 29 | @SerializedName("required_auth") val requiredAuth: List 30 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/KYCProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class KYCProvider( 27 | @SerializedName("kyc_provider") val kycProvider: String, 28 | 29 | @SerializedName("desc") val description: String, 30 | @SerializedName("url") val url: String, 31 | @SerializedName("iconurl") val iconurl: String, 32 | @SerializedName("name") val name: String, 33 | @SerializedName("blisted") val blackListed: Int 34 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/KeyAccount.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class KeyAccount( 27 | @SerializedName("account_names") val accountNames: List 28 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/ProtonESR.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.greymass.esr.SigningRequest 25 | 26 | class ProtonESR( 27 | val signingAccount: ChainAccount, 28 | val signingRequest: SigningRequest, 29 | val originESRUrlScheme: String, 30 | val requestAccount: Account? = null, 31 | val returnPath: String? = "", 32 | val requestKey: String? = "", 33 | val actions: List = emptyList() 34 | ) { 35 | fun getRequestAccountDisplayName(): String { 36 | return requestAccount?.accountContact?.getDisplayName() ?: "Unknown Requester" 37 | } 38 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/RequiredKeysResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | class RequiredKeysResponse( 27 | @SerializedName("required_keys") val requiredKeys: List 28 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/SwapPool.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class SwapPool( 27 | @SerializedName("lt_symbol") val symbol: String, 28 | @SerializedName("creator") val creator: String, 29 | @SerializedName("memo") val memo: String, 30 | @SerializedName("pool1") var pool1: SwapPoolAsset, 31 | @SerializedName("pool2") var pool2: SwapPoolAsset, 32 | @SerializedName("hash") val hash: String, 33 | @SerializedName("fee") val fee: SwapPoolFee, 34 | @SerializedName("active") val active: Int, 35 | @SerializedName("reserved") val reserved: Int 36 | ) { 37 | fun getPool1Amount(): Double { 38 | return pool1.quantity.substringBefore(" ").toDouble() 39 | } 40 | 41 | fun getPool2Amount(): Double { 42 | return pool2.quantity.substringBefore(" ").toDouble() 43 | } 44 | 45 | fun getPool1Symbol(): String { 46 | return pool1.quantity.substringAfter(" ") 47 | } 48 | 49 | fun getPool2Symbol(): String { 50 | return pool2.quantity.substringAfter(" ") 51 | } 52 | 53 | fun getPool1Contract(): String { 54 | return pool1.contract 55 | } 56 | 57 | fun getPool2Contract(): String { 58 | return pool2.contract 59 | } 60 | 61 | fun getFee(): Int { 62 | return fee.exchangeFee.toInt() 63 | } 64 | 65 | fun deepCopy(): SwapPool { 66 | return SwapPool( 67 | symbol, 68 | creator, 69 | memo, 70 | SwapPoolAsset(pool1.quantity, pool1.contract), 71 | SwapPoolAsset(pool2.quantity, pool2.contract), 72 | hash, 73 | SwapPoolFee(fee.exchangeFee, fee.addLiquidityFee, fee.removeLiquidityFee), 74 | active, 75 | reserved 76 | ) 77 | } 78 | } 79 | 80 | data class SwapPoolAsset( 81 | @SerializedName("quantity") val quantity: String, 82 | @SerializedName("contract") val contract: String 83 | ) 84 | 85 | data class SwapPoolFee( 86 | @SerializedName("exchange_fee") val exchangeFee: Long, 87 | @SerializedName("add_liquidity_fee") val addLiquidityFee: Long, 88 | @SerializedName("remove_liquidity_fee") val removeLiquidityFee: Long 89 | ) 90 | 91 | data class SwapPoolData( 92 | val swapPools: List, 93 | val swapPoolTokens: List 94 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/TokenContractRate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import com.google.gson.annotations.SerializedName 25 | 26 | data class TokenContractRate( 27 | @SerializedName("price") val price: Double = 0.0, 28 | @SerializedName("priceChangePercent") val priceChangePercent: Double = 0.0, 29 | @SerializedName("marketCap") val marketCap: Double = 0.0, 30 | @SerializedName("volume") val volume: Double = 0.0, 31 | @SerializedName("timestamp") val timestamp: Long = 0L 32 | ) -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/model/TokenCurrencyBalance.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.model 23 | 24 | import java.text.NumberFormat 25 | import java.util.* 26 | 27 | data class TokenCurrencyBalance( 28 | val tokenContract: TokenContract, 29 | val currencyBalance: CurrencyBalance 30 | ) { 31 | fun isSystemToken(): Boolean { 32 | return (tokenContract.isSystemToken) 33 | } 34 | 35 | private fun getBalanceDouble(adjustments: Double = 0.0): Double { 36 | return currencyBalance.getAmountDouble() + adjustments 37 | } 38 | 39 | fun formatBalance(adjustments: Double = 0.0): String { 40 | val balance = getBalanceDouble(adjustments) 41 | val nf = NumberFormat.getNumberInstance(Locale.US) 42 | nf.minimumFractionDigits = tokenContract.getPrecision() 43 | nf.maximumFractionDigits = tokenContract.getPrecision() 44 | return nf.format(balance) 45 | } 46 | 47 | fun getBalanceForCurrencyDouble(currency: String, adjustments: Double = 0.0): Double { 48 | val amount = getBalanceDouble(adjustments) 49 | val rate = tokenContract.getRate(currency) 50 | return amount.times(rate) 51 | } 52 | 53 | fun formatBalanceForCurrency(currency: String, adjustments: Double = 0.0): String { 54 | val amountCurrency = getBalanceForCurrencyDouble(currency, adjustments) 55 | 56 | val nf = NumberFormat.getCurrencyInstance(Locale.US) 57 | return nf.format(amountCurrency) 58 | } 59 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/AccountContactRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonObject 25 | import com.metallicus.protonsdk.api.ProtonChainService 26 | import com.metallicus.protonsdk.api.TableRowsBody 27 | import retrofit2.Response 28 | import javax.inject.Inject 29 | import javax.inject.Singleton 30 | 31 | @Singleton 32 | class AccountContactRepository @Inject constructor( 33 | // private val accountContactDao: AccountContactDao, 34 | private val protonChainService: ProtonChainService 35 | ) { 36 | // suspend fun addAccountContact(accountContact: AccountContact) { 37 | // accountContactDao.insert(accountContact) 38 | // } 39 | // 40 | // suspend fun updateAccountContact(accountContact: AccountContact) { 41 | // accountContactDao.update(accountContact) 42 | // } 43 | // 44 | // suspend fun getAccountContacts(accountName: String): List { 45 | // return accountContactDao.findByAccountName(accountName) 46 | // } 47 | 48 | suspend fun fetchAccountContact(chainUrl: String, accountName: String, usersInfoTableScope: String, usersInfoTableCode: String, usersInfoTableName: String): Response { 49 | return protonChainService.getTableRows("$chainUrl/v1/chain/get_table_rows", TableRowsBody(usersInfoTableScope, usersInfoTableCode, usersInfoTableName, accountName, accountName)) 50 | } 51 | 52 | suspend fun fetchAccountVotersXPRInfo(chainUrl: String, accountName: String, votersXPRInfoTableScope: String, votersXPRInfoTableCode: String, votersXPRInfoTableName: String): Response { 53 | return protonChainService.getTableRows("$chainUrl/v1/chain/get_table_rows", TableRowsBody(votersXPRInfoTableScope, votersXPRInfoTableCode, votersXPRInfoTableName, accountName, accountName)) 54 | } 55 | 56 | suspend fun fetchAccountRefundsXPRInfo(chainUrl: String, accountName: String, refundsXPRInfoTableScope: String, refundsXPRInfoTableCode: String, refundsXPRInfoTableName: String): Response { 57 | return protonChainService.getTableRows("$chainUrl/v1/chain/get_table_rows", TableRowsBody(refundsXPRInfoTableScope, refundsXPRInfoTableCode, refundsXPRInfoTableName, accountName, accountName)) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/AccountRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonObject 25 | import com.metallicus.protonsdk.api.AccountBody 26 | import com.metallicus.protonsdk.api.ProtonChainService 27 | import com.metallicus.protonsdk.api.UserNameBody 28 | import com.metallicus.protonsdk.db.AccountDao 29 | import com.metallicus.protonsdk.model.* 30 | import okhttp3.MediaType.Companion.toMediaTypeOrNull 31 | import okhttp3.MultipartBody 32 | import okhttp3.RequestBody.Companion.toRequestBody 33 | import retrofit2.Response 34 | import javax.inject.Inject 35 | import javax.inject.Singleton 36 | 37 | @Singleton 38 | class AccountRepository @Inject constructor( 39 | private val accountDao: AccountDao, 40 | private val protonChainService: ProtonChainService 41 | ) { 42 | suspend fun removeAll() { 43 | accountDao.removeAll() 44 | } 45 | 46 | suspend fun addAccount(account: Account) { 47 | accountDao.insert(account) 48 | } 49 | 50 | suspend fun updateAccount(account: Account) { 51 | accountDao.update(account) 52 | } 53 | 54 | suspend fun updateAccountName(updateAccountNameUrl: String, accountName: String, signature: String, name: String): Response { 55 | val url = updateAccountNameUrl.replace("{{account}}", accountName) 56 | return protonChainService.updateUserName(url, "Bearer $signature", UserNameBody(name)) 57 | } 58 | 59 | suspend fun updateAccountAvatar(updateAccountAvatarUrl: String, accountName: String, signature: String, imageByteArray: ByteArray): Response { 60 | val url = updateAccountAvatarUrl.replace("{{account}}", accountName) 61 | 62 | val builder = MultipartBody.Builder().setType(MultipartBody.FORM) 63 | 64 | builder 65 | .addFormDataPart("img", "img.jpeg", imageByteArray.toRequestBody("image/jpeg".toMediaTypeOrNull())) 66 | 67 | val multipartBody = builder.build() 68 | 69 | return protonChainService.uploadUserAvatar(url, "Bearer $signature", multipartBody) 70 | } 71 | 72 | suspend fun getChainAccount(accountName: String): ChainAccount { 73 | return accountDao.findByAccountName(accountName) 74 | } 75 | 76 | suspend fun fetchKeyAccount(hyperionHistoryUrl: String, publicKey: String): Response { 77 | return protonChainService.getKeyAccounts("$hyperionHistoryUrl/v2/state/get_key_accounts", publicKey) 78 | } 79 | 80 | suspend fun fetchAccount(chainUrl: String, accountName: String): Response { 81 | return protonChainService.getAccount("$chainUrl/v1/chain/get_account", AccountBody(accountName)) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/ActionRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonElement 25 | import com.google.gson.JsonObject 26 | import com.metallicus.protonsdk.api.JsonToBinBody 27 | import com.metallicus.protonsdk.api.ProtonChainService 28 | import com.metallicus.protonsdk.api.RequiredKeysBody 29 | import com.metallicus.protonsdk.db.ActionDao 30 | import com.metallicus.protonsdk.eosio.commander.model.chain.PackedTransaction 31 | import com.metallicus.protonsdk.model.* 32 | import retrofit2.Response 33 | import javax.inject.Inject 34 | import javax.inject.Singleton 35 | 36 | @Singleton 37 | class ActionRepository @Inject constructor( 38 | private val actionDao: ActionDao, 39 | private val protonChainService: ProtonChainService 40 | ) { 41 | suspend fun addAction(action: Action) { 42 | if (action.isTransfer()) { 43 | actionDao.insert(action) 44 | } 45 | } 46 | 47 | suspend fun fetchAccountTokenActions(hyperionHistoryUrl: String, accountName: String, symbol: String, skip: Int=0, limit: Int=250): Response { 48 | return protonChainService.getActions("$hyperionHistoryUrl/v2/history/get_actions", accountName, symbol, skip, limit) 49 | } 50 | 51 | suspend fun getAccountSystemTokenActions(accountName: String, contract: String, symbol: String): List { 52 | return actionDao.findBySystemTokenContract(accountName, contract, symbol) 53 | } 54 | 55 | suspend fun getAccountTokenActions(accountName: String, contract: String, symbol: String): List { 56 | return actionDao.findByTokenContract(accountName, contract, symbol) 57 | } 58 | 59 | suspend fun jsonToBin(chainUrl: String, code: String, action: String, args: JsonElement): Response { 60 | return protonChainService.jsonToBin("$chainUrl/v1/chain/abi_json_to_bin", JsonToBinBody(code, action, args)) 61 | } 62 | 63 | suspend fun getRequiredKeys(chainUrl: String, requiredKeysBody: RequiredKeysBody): Response { 64 | return protonChainService.getRequiredKeys("$chainUrl/v1/chain/get_required_keys", requiredKeysBody) 65 | } 66 | 67 | suspend fun pushTransaction(chainUrl: String, packedTransaction: PackedTransaction): Response { 68 | return protonChainService.pushTransaction("$chainUrl/v1/chain/push_transaction", packedTransaction) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/ChainProviderRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonObject 25 | import com.metallicus.protonsdk.api.* 26 | import com.metallicus.protonsdk.db.ChainProviderDao 27 | import com.metallicus.protonsdk.model.ChainInfo 28 | import com.metallicus.protonsdk.model.ChainProvider 29 | import retrofit2.Response 30 | import javax.inject.Inject 31 | import javax.inject.Singleton 32 | 33 | @Singleton 34 | class ChainProviderRepository @Inject constructor( 35 | private val chainProviderDao: ChainProviderDao, 36 | private val protonChainService: ProtonChainService, 37 | private val protonChainStatsService: ProtonChainStatsService 38 | ) { 39 | suspend fun removeAll() { 40 | chainProviderDao.removeAll() 41 | } 42 | 43 | suspend fun addChainProvider(chainProvider: ChainProvider) { 44 | chainProviderDao.insert(chainProvider) 45 | } 46 | 47 | suspend fun updateChainProvider(chainProvider: ChainProvider) { 48 | chainProviderDao.update(chainProvider) 49 | } 50 | 51 | suspend fun updateChainUrl(chainId: String, chainUrl: String) { 52 | chainProviderDao.updateChainUrl(chainId, chainUrl) 53 | } 54 | 55 | suspend fun updateHyperionHistoryUrl(chainId: String, hyperionHistory: String) { 56 | chainProviderDao.updateHyperionHistoryUrl(chainId, hyperionHistory) 57 | } 58 | 59 | suspend fun fetchChainProvider(protonChainUrl: String): Response { 60 | return protonChainService.getChainProvider("$protonChainUrl/v1/chain/info") 61 | } 62 | 63 | suspend fun fetchKYCProviders(chainUrl: String, kycProvidersTableScope: String, kycProvidersTableCode: String, kycProvidersTableName: String): Response { 64 | return protonChainService.getTableRows("$chainUrl/v1/chain/get_table_rows", TableRowsBody(kycProvidersTableScope, kycProvidersTableCode, kycProvidersTableName, "", "", 100)) 65 | } 66 | 67 | suspend fun getChainProvider(id: String): ChainProvider { 68 | return chainProviderDao.findById(id) 69 | } 70 | 71 | suspend fun getChainInfo(chainUrl: String): Response { 72 | return protonChainStatsService.getChainInfo("$chainUrl/v1/chain/get_info") 73 | } 74 | 75 | suspend fun getHealth(chainUrl: String): Response { 76 | return protonChainStatsService.getHealth("$chainUrl/v2/health") 77 | } 78 | 79 | suspend fun getAbi(chainUrl: String, accountName: String): Response { 80 | return protonChainService.getAbi("$chainUrl/v1/chain/get_abi", AccountBody(accountName)) 81 | } 82 | 83 | suspend fun getTableRows( 84 | chainUrl: String, 85 | scope: String, 86 | code: String, 87 | name: String, 88 | lowerBound: String = "", 89 | upperBound: String = "", 90 | limit: Long = 1, 91 | indexPosition: String = TableRowsIndexPosition.PRIMARY.indexPositionName, 92 | reverse: Boolean = false 93 | ): Response { 94 | return protonChainService.getTableRows( 95 | "$chainUrl/v1/chain/get_table_rows", 96 | TableRowsBody(scope, code, name, lowerBound, upperBound, limit, indexPosition, reverse)) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/CurrencyBalanceRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonObject 25 | import com.metallicus.protonsdk.api.ProtonChainService 26 | import retrofit2.Response 27 | import javax.inject.Inject 28 | import javax.inject.Singleton 29 | 30 | @Singleton 31 | class CurrencyBalanceRepository @Inject constructor( 32 | private val protonChainService: ProtonChainService 33 | ) { 34 | suspend fun fetchCurrencyBalances(chainUrl: String, accountName: String): Response { 35 | return protonChainService.getCurrencyBalances("$chainUrl/v2/state/get_tokens", accountName) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/ESRRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.metallicus.protonsdk.api.* 25 | import com.metallicus.protonsdk.db.ESRSessionDao 26 | import com.metallicus.protonsdk.model.ESRSession 27 | import retrofit2.Response 28 | import javax.inject.Inject 29 | import javax.inject.Singleton 30 | 31 | @Singleton 32 | class ESRRepository @Inject constructor( 33 | private val esrCallbackService: ESRCallbackService, 34 | private val esrSessionDao: ESRSessionDao 35 | ) { 36 | suspend fun cancelAuthorizeESR(url: String, error: String): Response { 37 | return esrCallbackService.cancelAuthorizeESR(url, CancelAuthorizeESRBody(error)) 38 | } 39 | 40 | suspend fun authorizeESR(url: String, params: Map): Response { 41 | return esrCallbackService.authorizeESR(url, params) 42 | } 43 | 44 | suspend fun getESRSession(id: String): ESRSession { 45 | return esrSessionDao.findById(id) 46 | } 47 | 48 | suspend fun getESRSessions(): List { 49 | return esrSessionDao.findAll() 50 | } 51 | 52 | suspend fun addESRSession(esrSession: ESRSession) { 53 | esrSessionDao.insert(esrSession) 54 | } 55 | 56 | suspend fun updateESRSession(esrSession: ESRSession) { 57 | esrSessionDao.update(esrSession) 58 | } 59 | 60 | suspend fun removeESRSession(esrSession: ESRSession) { 61 | esrSessionDao.remove(esrSession.id) 62 | } 63 | 64 | suspend fun removeAllESRSessions() { 65 | esrSessionDao.removeAll() 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/repository/TokenContractRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.repository 23 | 24 | import com.google.gson.JsonArray 25 | import com.google.gson.JsonObject 26 | import com.metallicus.protonsdk.api.ProtonChainService 27 | import com.metallicus.protonsdk.api.TableRowsBody 28 | import com.metallicus.protonsdk.db.TokenContractDao 29 | import com.metallicus.protonsdk.model.TokenContract 30 | import com.metallicus.protonsdk.model.TokenContractRate 31 | import retrofit2.Response 32 | import javax.inject.Inject 33 | import javax.inject.Singleton 34 | 35 | @Singleton 36 | class TokenContractRepository @Inject constructor( 37 | private val tokenContractDao: TokenContractDao, 38 | private val protonChainService: ProtonChainService 39 | ) { 40 | suspend fun removeAll() { 41 | tokenContractDao.removeAll() 42 | } 43 | 44 | suspend fun addTokenContract(tokenContract: TokenContract) { 45 | tokenContractDao.insert(tokenContract) 46 | } 47 | 48 | suspend fun fetchTokenContracts(chainUrl: String, tokensTableScope: String, tokensTableCode: String, tokensTableName: String): Response { 49 | return protonChainService.getTableRows("$chainUrl/v1/chain/get_table_rows", TableRowsBody(tokensTableScope, tokensTableCode, tokensTableName, "", "", 100)) 50 | } 51 | 52 | suspend fun getTokenContract(tokenContractId: String): TokenContract { 53 | return tokenContractDao.findById(tokenContractId) 54 | } 55 | 56 | suspend fun getTokenContracts(): List { 57 | return tokenContractDao.findAll() 58 | } 59 | 60 | suspend fun fetchExchangeRates(exchangeRateUrl: String): Response { 61 | return protonChainService.getExchangeRates("$exchangeRateUrl/info") 62 | } 63 | 64 | suspend fun updateRates(tokenContractId: String, rates: Map, rank: Int) { 65 | return tokenContractDao.updateRates(tokenContractId, rates, rank) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/securestorage/SecureStorageException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 adorsys GmbH & Co. KG 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.metallicus.protonsdk.securestorage; 18 | 19 | public class SecureStorageException extends Exception { 20 | public final ExceptionType type; 21 | 22 | public SecureStorageException(String detailMessage, Throwable cause, ExceptionType type) { 23 | super(detailMessage, cause); 24 | this.type = type; 25 | } 26 | 27 | public enum ExceptionType { 28 | /** 29 | * If this exception type is defined you cannot use the keystore / this library on the current device. 30 | * This is fatal and most likely due to native key store issues. 31 | */ 32 | KEYSTORE_EXCEPTION, 33 | /** 34 | * If this exception type is defined a problem during encryption has occurred. 35 | * Most likely this is due to using an invalid key for encryption or decryption. 36 | */ 37 | CRYPTO_EXCEPTION, 38 | /** 39 | * If this exception type is set it means simply that the keystore cannot be used on the current device as it is not supported by this library. 40 | * This probably means that you are targeting a device prior to api 23 or any not supported fingerprint sensors of Samsung 41 | */ 42 | KEYSTORE_NOT_SUPPORTED_EXCEPTION, 43 | /** 44 | * If this exception type is set it means that something with this library is wrong. 45 | */ 46 | INTERNAL_LIBRARY_EXCEPTION 47 | } 48 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/workers/ChildWorkerFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.workers 23 | 24 | import android.content.Context 25 | import androidx.work.ListenableWorker 26 | import androidx.work.WorkerParameters 27 | 28 | interface ChildWorkerFactory { 29 | fun create(context: Context, params: WorkerParameters): ListenableWorker 30 | } -------------------------------------------------------------------------------- /protonsdk/src/main/java/com/metallicus/protonsdk/workers/ProtonWorkerFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Proton Chain LLC, Delaware 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | package com.metallicus.protonsdk.workers 23 | 24 | import android.content.Context 25 | import androidx.work.ListenableWorker 26 | import androidx.work.WorkerFactory 27 | import androidx.work.WorkerParameters 28 | import timber.log.Timber 29 | import javax.inject.Inject 30 | import javax.inject.Provider 31 | 32 | class ProtonWorkerFactory @Inject constructor( 33 | private val workerFactory: Map, @JvmSuppressWildcards Provider> 34 | ) : WorkerFactory() { 35 | override fun createWorker( 36 | context: Context, 37 | workerClassName: String, 38 | workerParameters: WorkerParameters 39 | ): ListenableWorker? { 40 | return try { 41 | val factoryEntry = workerFactory.entries.find { Class.forName(workerClassName).isAssignableFrom(it.key) } 42 | 43 | if (factoryEntry != null) { 44 | val factoryProvider = factoryEntry.value 45 | factoryProvider.get().create(context, workerParameters) 46 | } else { // fallback if no factory was found 47 | val workerClass = Class.forName(workerClassName).asSubclass(ListenableWorker::class.java) 48 | val constructor = workerClass.getDeclaredConstructor(Context::class.java, WorkerParameters::class.java) 49 | constructor.newInstance(context, workerParameters) 50 | } 51 | } catch (e: ClassNotFoundException) { 52 | Timber.d("Worker class not found: $workerClassName") 53 | null 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /protonsdk/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0 3 | https://proton.cryptolions.io/ 4 | https://cb.anchor.link/ 5 | 6 | eosio 7 | eosio 8 | votersxpr 9 | 10 | eosio 11 | refundsxpr 12 | 13 | eosio.proton 14 | eosio.proton 15 | usersinfo 16 | 17 | token.proton 18 | token.proton 19 | tokens 20 | 21 | eosio.proton 22 | eosio.proton 23 | kycproviders 24 | 25 | proton.swaps 26 | proton.swaps 27 | pools 28 | 29 | KeyPair already exists! 30 | KeyPair does not exist in Keystore 31 | Problem during encryption 32 | -------------------------------------------------------------------------------- /protonsdk/src/orchid/resources/config.yml: -------------------------------------------------------------------------------- 1 | site: 2 | about: 3 | siteName: Proton Kotlin SDK 4 | siteDescription: Kotlin library for handling Proton Chain operations. 5 | 6 | Editorial: 7 | primaryColor: '#582ACB' 8 | legacySearch: false 9 | social: 10 | github: 'ProtonProtocol/ProtonKotlin' 11 | metaComponents: # this is the replacement for the deprecated automatic search addition 12 | - type: 'orchidSearch' 13 | menu: 14 | - type: 'separator' 15 | title: 'API Docs' 16 | - type: 'sourcedocPages' 17 | moduleType: 'kotlindoc' 18 | node: 'classes' 19 | asSubmenu: true 20 | submenuTitle: 'Classes' 21 | - type: 'sourcedocPages' 22 | moduleType: 'kotlindoc' 23 | node: 'packages' 24 | asSubmenu: true 25 | submenuTitle: 'Packages' 26 | 27 | kotlindoc: 28 | sourceDirs: 29 | - './../../../../protonsdk/src/main/java' 30 | sourcePages: 31 | menu: 32 | - type: 'sourcedocPageLinks' 33 | moduleType: 'kotlindoc' 34 | itemTitleType: 'SIGNATURE' 35 | includeItems: true 36 | 37 | services: 38 | publications: 39 | stages: 40 | - type: 'githubPages' 41 | username: 'joey-harward' 42 | repo: 'ProtonProtocol/ProtonKotlin' -------------------------------------------------------------------------------- /protonsdk/src/orchid/resources/homepage.md: -------------------------------------------------------------------------------- 1 | --- 2 | components: 3 | - type: 'pageContent' 4 | - type: 'readme' 5 | --- -------------------------------------------------------------------------------- /protonsdk/src/test/java/com/metallicus/protonsdk/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.metallicus.protonsdk 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Test 5 | 6 | /** 7 | * Example local unit test, which will execute on the development machine (host). 8 | * 9 | * See [testing documentation](http://d.android.com/tools/testing). 10 | */ 11 | class ExampleUnitTest { 12 | @Test 13 | fun addition_isCorrect() { 14 | val expected = 4 15 | val actual = 2+2 16 | assertEquals(expected, actual) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "ProtonKotlinSDK" 2 | 3 | include(":protonsdk") 4 | 5 | pluginManagement { 6 | repositories { 7 | gradlePluginPortal() 8 | maven("https://dl.bintray.com/kotlin/kotlin-eap") 9 | } 10 | } --------------------------------------------------------------------------------