├── .github
└── ISSUE_TEMPLATE
│ └── BOUNTY.yml
├── .gitignore
├── LICENSE
├── README.md
├── aar build
└── near-android-sdk-debug.aar
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jose
│ │ └── lujan
│ │ └── near
│ │ └── android
│ │ └── sdk
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── near
│ │ │ └── android
│ │ │ └── sdk
│ │ │ ├── LoginFragment.kt
│ │ │ ├── NearDemoMainActivity.kt
│ │ │ └── TransactionFragment.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_near_demo_main.xml
│ │ ├── fragment_login.xml
│ │ └── fragment_transaction.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── values-night
│ │ └── themes.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── jose
│ └── lujan
│ └── near
│ └── android
│ └── sdk
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── knear-sdk
├── .gitignore
├── build.gradle
├── libs
│ ├── borshj-0.2.0-SNAPSHOT.jar
│ └── tweetnacl-java-1.1.2.jar
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── knear
│ └── android
│ ├── NearService.kt
│ ├── model
│ └── Account.kt
│ ├── provider
│ ├── JsonRpcProvider.kt
│ ├── NearRequest.kt
│ ├── NearRequestParamList.kt
│ ├── NearResponse.kt
│ ├── NearResponseListener.kt
│ ├── ViewAccessKeyChangesAllRequestParams.kt
│ ├── ViewAccessKeyChangesRequestParams.kt
│ ├── model
│ │ ├── BlockDetailsParams.kt
│ │ ├── ChunkDetailsParams.kt
│ │ ├── Keys.kt
│ │ ├── NearRequestParams.kt
│ │ ├── ProtocolConfigParams.kt
│ │ ├── ViewAccessKeyChangesAllParams.kt
│ │ ├── ViewAccessKeyChangesParams.kt
│ │ ├── ViewAccessKeyChangesRequest.kt
│ │ ├── ViewAccountChangesParams.kt
│ │ ├── ViewContractCodeChangesParams.kt
│ │ └── ViewContractStateChangesParams.kt
│ └── response
│ │ ├── block
│ │ ├── Block.kt
│ │ ├── Chunks.kt
│ │ ├── Header.kt
│ │ └── Result.kt
│ │ ├── blockchanges
│ │ ├── BlockChangesResult.kt
│ │ ├── Change.kt
│ │ └── Result.kt
│ │ ├── chunkdetails
│ │ ├── ChunkDetailsResult.kt
│ │ ├── Header.kt
│ │ └── Result.kt
│ │ ├── errorresponse
│ │ ├── ErrorResponse.kt
│ │ └── Info.kt
│ │ ├── functioncall
│ │ ├── FunctionCallResponse.kt
│ │ ├── Result.kt
│ │ └── transaction
│ │ │ ├── ActionError.kt
│ │ │ ├── Actions.kt
│ │ │ ├── Failure.kt
│ │ │ ├── FunctionCall.kt
│ │ │ ├── FunctionCallError.kt
│ │ │ ├── FunctionCallTransactionResponse.kt
│ │ │ ├── GasProfile.kt
│ │ │ ├── Kind.kt
│ │ │ ├── Metadata.kt
│ │ │ ├── Outcome.kt
│ │ │ ├── Proof.kt
│ │ │ ├── ReceiptsOutcome.kt
│ │ │ ├── Result.kt
│ │ │ ├── Status.kt
│ │ │ ├── Transaction.kt
│ │ │ └── TransactionOutcome.kt
│ │ ├── gasprice
│ │ ├── GasPriceResult.kt
│ │ └── Result.kt
│ │ ├── genesisconfig
│ │ ├── AccountCreationConfig.kt
│ │ ├── ActionCreationConfig.kt
│ │ ├── ActionReceiptCreationConfig.kt
│ │ ├── AddKeyCost.kt
│ │ ├── BaseCost.kt
│ │ ├── CostPerByte.kt
│ │ ├── CreateAccountCost.kt
│ │ ├── DataReceiptCreationConfig.kt
│ │ ├── DeleteAccountCost.kt
│ │ ├── DeleteKeyCost.kt
│ │ ├── DeployContractCost.kt
│ │ ├── DeployContractCostPerByte.kt
│ │ ├── ExtCosts.kt
│ │ ├── FullAccessCost.kt
│ │ ├── FunctionCallCostPerByteX.kt
│ │ ├── FunctionCallCostX.kt
│ │ ├── GenesisConfigResult.kt
│ │ ├── LimitConfig.kt
│ │ ├── Result.kt
│ │ ├── RuntimeConfig.kt
│ │ ├── StakeCost.kt
│ │ ├── StorageUsageConfig.kt
│ │ ├── TransactionCosts.kt
│ │ ├── TransferCost.kt
│ │ ├── Validator.kt
│ │ └── WasmConfig.kt
│ │ ├── networkstatus
│ │ ├── NetworkStatusResult.kt
│ │ ├── Result.kt
│ │ ├── SyncInfo.kt
│ │ ├── Validator.kt
│ │ └── Version.kt
│ │ ├── protocolconfig
│ │ ├── AccountCreationConfig.kt
│ │ ├── ActionCreationConfig.kt
│ │ ├── ActionReceiptCreationConfig.kt
│ │ ├── AddKeyCost.kt
│ │ ├── BaseCost.kt
│ │ ├── CostPerByte.kt
│ │ ├── CreateAccountCost.kt
│ │ ├── DataReceiptCreationConfig.kt
│ │ ├── DeleteAccountCost.kt
│ │ ├── DeleteKeyCost.kt
│ │ ├── DeployContractCost.kt
│ │ ├── DeployContractCostPerByte.kt
│ │ ├── ExtCosts.kt
│ │ ├── FullAccessCost.kt
│ │ ├── FunctionCallCostPerByteX.kt
│ │ ├── FunctionCallCostX.kt
│ │ ├── LimitConfig.kt
│ │ ├── ProtocolConfigResult.kt
│ │ ├── Result.kt
│ │ ├── RuntimeConfig.kt
│ │ ├── StakeCost.kt
│ │ ├── StorageUsageConfig.kt
│ │ ├── TransactionCosts.kt
│ │ ├── TransferCost.kt
│ │ └── WasmConfig.kt
│ │ ├── sendmoney
│ │ ├── Actions.kt
│ │ ├── Metadata.kt
│ │ ├── Outcome.kt
│ │ ├── ReceiptsOutcome.kt
│ │ ├── Result.kt
│ │ ├── SendMoney.kt
│ │ ├── Status.kt
│ │ ├── Transaction.kt
│ │ ├── TransactionOutcome.kt
│ │ ├── Transfer.kt
│ │ └── transactionstatus
│ │ │ └── TransactionStatus.kt
│ │ ├── viewaccesskey
│ │ ├── Result.kt
│ │ └── ViewAccessKey.kt
│ │ ├── viewaccesskeychangeall
│ │ ├── AccessKey.kt
│ │ ├── Cause.kt
│ │ ├── Change.kt
│ │ ├── ChangeX.kt
│ │ ├── Result.kt
│ │ └── ViewAccessKeyChangesAllResult.kt
│ │ ├── viewaccesskeychanges
│ │ ├── AccessKey.kt
│ │ ├── Cause.kt
│ │ ├── Change.kt
│ │ ├── ChangeX.kt
│ │ ├── Result.kt
│ │ └── ViewAccessKeyChangesResult.kt
│ │ ├── viewaccesskeylist
│ │ ├── AccessKey.kt
│ │ ├── Key.kt
│ │ ├── Result.kt
│ │ └── ViewAccessKeyList.kt
│ │ ├── viewaccount
│ │ ├── Result.kt
│ │ └── ViewAccountResult.kt
│ │ ├── viewaccountchanges
│ │ ├── Cause.kt
│ │ ├── Change.kt
│ │ ├── ChangeX.kt
│ │ ├── Result.kt
│ │ └── ViewAccountChangesResult.kt
│ │ ├── viewcontractcode
│ │ ├── Result.kt
│ │ └── ViewContractCodeResult.kt
│ │ ├── viewcontractcodechanges
│ │ ├── Cause.kt
│ │ ├── Change.kt
│ │ ├── ChangeX.kt
│ │ ├── Result.kt
│ │ └── ViewContractCodeChangesResult.kt
│ │ ├── viewcontractstate
│ │ ├── Result.kt
│ │ ├── Value.kt
│ │ └── ViewContractStateResult.kt
│ │ └── viewcontractstatechanges
│ │ ├── Cause.kt
│ │ ├── Change.kt
│ │ ├── ChangeX.kt
│ │ ├── Result.kt
│ │ └── ViewContractStateChangesResult.kt
│ ├── scheme
│ ├── KeyPair.kt
│ ├── KeyPairEd25519.kt
│ ├── KeyType.kt
│ ├── PublicKey.kt
│ ├── Signature.kt
│ ├── SignedTransaction.kt
│ ├── Transaction.kt
│ └── action
│ │ ├── Action.kt
│ │ ├── AddKeyAction.kt
│ │ ├── CreateAccountAction.kt
│ │ ├── DeleteAccountAction.kt
│ │ ├── DeleteKeyAction.kt
│ │ ├── DeployContractAction.kt
│ │ ├── FunctionCallAction.kt
│ │ ├── StakeAction.kt
│ │ └── TransferAction.kt
│ ├── service
│ ├── Account.kt
│ ├── AndroidKeyStore.kt
│ ├── MethodUtils.kt
│ ├── NearMainService.kt
│ └── StringUtils.kt
│ └── user
│ ├── NearUserInformationListener.kt
│ ├── data
│ ├── dao
│ │ └── UserDao.kt
│ ├── database
│ │ └── NearDatabase.kt
│ ├── entities
│ │ └── UserInformationEntity.kt
│ └── repositories
│ │ └── UserSessionRepository.kt
│ ├── domain
│ ├── model
│ │ └── UserInformation.kt
│ └── usecase
│ │ ├── GetAllUsersUseCase.kt
│ │ ├── RemoveUserSessionUseCase.kt
│ │ └── SaveUserSessionUseCase.kt
│ └── view
│ └── NearUserViewModel.kt
└── settings.gradle
/.github/ISSUE_TEMPLATE/BOUNTY.yml:
--------------------------------------------------------------------------------
1 | name: "Simple Bounty"
2 | description: "Use this template to create a HEROES Simple Bounty via Github bot"
3 | title: "Bounty: "
4 | labels: ["bounty"]
5 | assignees: heroes-bot-test
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | Hi! Let's set up your bounty! Please don't change the template - @heroes-bot-test won't be able to help you.
11 |
12 | - type: dropdown
13 | id: type
14 | attributes:
15 | label: What talent are you looking for?
16 | options:
17 | - Marketing
18 | - Development
19 | - Design
20 | - Other
21 | - Content
22 | - Research
23 | - Audit
24 |
25 | - type: textarea
26 | id: description
27 | attributes:
28 | label: What you need to be done?
29 |
30 | - type: dropdown
31 | id: tags
32 | attributes:
33 | label: Tags
34 | description: Add tags that match the topic of the work
35 | multiple: true
36 | options:
37 | - API
38 | - Blockchain
39 | - Community
40 | - CSS
41 | - DAO
42 | - dApp
43 | - DeFi
44 | - Design
45 | - Documentation
46 | - HTML
47 | - Javascript
48 | - NFT
49 | - React
50 | - Rust
51 | - Smart contract
52 | - Typescript
53 | - UI/UX
54 | - web3
55 | - Translation
56 | - Illustration
57 | - Branding
58 | - Copywriting
59 | - Blogging
60 | - Editing
61 | - Video Creation
62 | - Social Media
63 | - Graphic Design
64 | - Transcription
65 | - Product Design
66 | - Artificial Intelligence
67 | - Quality Assurance
68 | - Risk Assessment
69 | - Security Audit
70 | - Bug Bounty
71 | - Code Review
72 | - Blockchain Security
73 | - Smart Contract Testing
74 | - Penetration Testing
75 | - Vulnerability Assessment
76 | - BOS
77 | - News
78 | - Hackathon
79 | - NEARCON2023
80 | - NEARWEEK
81 |
82 | - type: input
83 | id: deadline
84 | attributes:
85 | label: Deadline
86 | description: "Set a deadline for your bounty. Please enter the date in format: DD.MM.YYYY"
87 | placeholder: "19.05.2027"
88 |
89 | - type: dropdown
90 | id: currencyType
91 | attributes:
92 | label: Currency
93 | description: What is the currency you want to pay?
94 | options:
95 | - USDC.e
96 | - USDT.e
97 | - DAI
98 | - wNEAR
99 | - USDt
100 | - XP
101 | - marmaj
102 | - NEKO
103 | - JUMP
104 | - USDC
105 | - NEARVIDIA
106 | default: 0
107 | validations:
108 | required: true
109 |
110 | - type: input
111 | id: currencyAmount
112 | attributes:
113 | label: Amount
114 | description: How much it will be cost?
115 |
116 | - type: markdown
117 | attributes:
118 | value: "## Advanced settings"
119 |
120 | - type: checkboxes
121 | id: kyc
122 | attributes:
123 | label: KYC
124 | description: "Use HEROES' KYC Verification, only applicants who passed HEROES' KYC can apply and work on this bounty!"
125 | options:
126 | - label: Use KYC Verification
127 |
128 | - type: markdown
129 | attributes:
130 | value: |
131 | ### This cannot be changed once the bounty is live!
132 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 José Dimas Luján Castillo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kotlin SDK
2 | This is a open source project on kotlin for NEAR protocol.
3 |
4 | # Description
5 |
6 | Near Android SDK implemented in Kotlin to interact with the NEAR blockchain.
7 |
8 | # Features
9 | * Includes Login into Near wallet
10 | * Send transactions
11 | * Retrieve information about accounts and contracts
12 | * Sign and send transactions
13 | * View access keys and more.
14 |
15 | # Requirements
16 |
17 | • Minimum android version API 26+
18 |
19 | • Minimum Java 8 version
20 |
21 | # RPC Calls
22 | We support [THIS](https://docs.near.org/api/rpc/introduction) rpc calls.
23 |
24 | ## Configuration
25 |
26 | First add dependency to your app build.gradle
27 | ```
28 | implementation 'com.github.near:near-api-kotlin:1.0.14`
29 | ```
30 |
31 | then, add the next resource in your settings.gradle
32 |
33 | ```
34 | maven { url "https://jitpack.io" }
35 | ```
36 |
37 | ## Usage
38 |
39 | In your manifest add the next permissions
40 |
41 | ```
42 |
43 |
44 | ```
45 | you should have an activity and inside you have to add an intent filter
46 |
47 | ```
48 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
62 |
63 |
64 | ```
65 |
66 | this will help your activity catch the data we need after login into your Near wallet account in your browser.
67 |
68 | # First
69 | ## Login into your account
70 |
71 | The first thing you should do before accessing all the other functions in the Near SDK library is logging into yout Near wallet account.
72 |
73 | In your activity you should create an instance of ``` NearMainService ```
74 |
75 | ```
76 | private var nearMainService: NearMainService = NearMainService(this)
77 | ```
78 |
79 | then, call login() method. This will call an Intent to open browser and login into your Near wallet account.
80 |
81 | ```
82 | nearMainService.login("yourusername.testnet")
83 | ```
84 |
85 | Finally, override the onResume() method and check if login was successfull.
86 |
87 | ```
88 | override fun onResume() {
89 | super.onResume()
90 | val uri = intent.data
91 | if (nearMainService.attemptLogin(uri)){
92 | // Do anything after logging in
93 | }
94 | }
95 | ```
96 | Once you are logged in you can use any method inside ``` NearMainService ``` class.
97 |
98 | ## Make a Transaction
99 |
100 | After user is logged in, call ``` sendTransaction() ``` method with the receiver user name and Near amount inside a ``` Coroutine ``` to wait for the response
101 |
102 | ```
103 | CoroutineScope(Dispatchers.IO).launch {
104 | val sendMoney = withContext(Dispatchers.IO) {
105 | nearMainService.sendTransaction("receiverusername.testnet", "1")
106 | }
107 | }
108 | ```
109 |
110 | and thats it, that's how you make a transaction.
111 |
112 | In this repository we have an example of how to make a transaction and also how to call a [contract method as view function][1].
113 |
114 |
115 | [1]: https://google.com
116 |
117 | ## Demo and Screenshots
118 |
119 | 
120 |
121 | 
122 |
123 |
124 |
125 | After building the demo project in you local, you will be able to see the first screen where you have to type your user name and continue to login in the browser.
126 | By clicking on the "Transaction" button 1 Near is send to "android-test-23.testnet" default account ([Transaction docs][2]) and finally prints the response in the logs and displays it on the screen.
127 |
128 |
129 | [2]: https://docs.near.org/api/rpc/transactions#send-transaction-async
130 |
131 | If you click "Call function" button, contract methods are going to be called as [view functions][3].
132 |
133 |
134 | [3]: https://docs.near.org/api/rpc/contracts#call-a-contract-function
135 |
136 | In this case we have a call for 3 different contracts that receives some parameters and returns a call back and finally it prints the response in the logs and displays it on the screen.
137 |
138 | ```
139 | private fun callFunction() {
140 | var balanceOfArgs = "{ \"tokenOwner\": \"android-test-22.testnet\" }"
141 | val contractName = "android-test-22.testnet"
142 | val balanceOfResponse = this.nearMainService.callViewFunction(contractName, "balanceOf", balanceOfArgs)
143 | if(balanceOfResponse.error == null) {
144 | val functionResult = balanceOfResponse.result.result!!.getDecodedAsciiValue()
145 | }
146 |
147 | val totalSupplyArgs = "{}"
148 | val totalSupplyResponse = this.nearMainService.callViewFunction(contractName, "totalSupply", totalSupplyArgs)
149 | if(totalSupplyResponse.error == null) {
150 | val functionResult = totalSupplyResponse.result.result!!.getDecodedAsciiValue()
151 | }
152 |
153 | val transferFromArgs = "{ \"from\": \"android-test-22.testnet\", \"to\": \"android-test-23.testnet\", \"tokens\": \"1\" }"
154 | val transferFromResponse = this.nearMainService.callViewFunction(contractName, "transferFrom", transferFromArgs)
155 | if(transferFromResponse.error == null) {
156 | val functionResult = totalSupplyResponse.result.result!!.getDecodedAsciiValue()
157 | }
158 |
159 | balanceOfArgs = "{ \"tokenOwner\": \"android-test-22.testnet\" }"
160 | val callViewFunctionTransactionResponse = this.nearMainService.callViewFunctionTransaction(contractName, "balanceOf", balanceOfArgs)
161 | if(callViewFunctionTransactionResponse.result.status.Failure == null) {
162 | callViewFunctionTransactionResponse.result.status.SuccessValue?.let {
163 | val decodedValue = String(Base64.getDecoder().decode(it))
164 | }
165 | }
166 |
167 | val invalidBalanceOfArgs = "{ tokenOwner: android-test-22.testnet }"
168 | val errorResponse = this.nearMainService.callViewFunctionTransaction(contractName, "balanceOf", invalidBalanceOfArgs)
169 | }
170 | ```
171 | In this block of code we make the calls by using ``` nearMainService.callViewFunction() ``` and ``` nearMainService.callViewFunctionTransaction() ```
172 |
--------------------------------------------------------------------------------
/aar build/near-android-sdk-debug.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/aar build/near-android-sdk-debug.aar
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-kapt'
5 | id 'kotlin-android-extensions'
6 | }
7 |
8 | android {
9 | compileSdk 33
10 |
11 | defaultConfig {
12 | applicationId "com.jose.lujan.near.android.sdk"
13 | minSdk 26
14 | targetSdk 33
15 | versionCode 1
16 | versionName "1.0"
17 |
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 |
21 | packagingOptions {
22 | exclude 'META-INF/DEPENDENCIES'
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | compileOptions {
32 | sourceCompatibility JavaVersion.VERSION_1_8
33 | targetCompatibility JavaVersion.VERSION_1_8
34 | }
35 | kotlinOptions {
36 | jvmTarget = '1.8'
37 | }
38 | packagingOptions {
39 | exclude 'META-INF/*'
40 | }
41 | }
42 |
43 | dependencies {
44 |
45 | implementation 'androidx.core:core-ktx:1.7.0'
46 | implementation 'androidx.appcompat:appcompat:1.4.1'
47 | implementation 'com.google.android.material:material:1.5.0'
48 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
49 | implementation 'com.github.near:near-api-kotlin:1.0.18'
50 | testImplementation 'junit:junit:4.+'
51 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
52 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
53 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
54 | implementation 'com.squareup.okhttp3:okhttp:4.9.0'
55 |
56 | // Enable live data and view model
57 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
58 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
59 | implementation "androidx.activity:activity-ktx:1.1.0"
60 | // Kotlin coroutines
61 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
62 | }
63 |
--------------------------------------------------------------------------------
/app/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jose/lujan/near/android/sdk/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jose.lujan.near.android.sdk
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jose.lujan.near.android.sdk", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/near/android/sdk/LoginFragment.kt:
--------------------------------------------------------------------------------
1 | package com.near.android.sdk
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import com.jose.lujan.near.android.sdk.R
9 | import kotlinx.android.synthetic.main.fragment_login.view.*
10 |
11 | class LoginFragment : Fragment() {
12 |
13 | private lateinit var v: View
14 |
15 | override fun onCreateView(
16 | inflater: LayoutInflater, container: ViewGroup?,
17 | savedInstanceState: Bundle?
18 | ): View {
19 | v = inflater.inflate(R.layout.fragment_login, container, false)
20 |
21 | v.login_btn_cv.setOnClickListener {
22 | val email = v.user_email_et.text.toString()
23 |
24 | if (email.isNotEmpty()) {
25 | (activity as NearDemoMainActivity).login()
26 | }
27 | }
28 |
29 | return v
30 | }
31 |
32 | companion object {
33 | @JvmStatic
34 | fun getInstance() = LoginFragment()
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/near/android/sdk/NearDemoMainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.near.android.sdk
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import android.util.Log
6 | import com.jose.lujan.near.android.sdk.R
7 | import com.knear.android.service.MethodUtils.Companion.getDecodedAsciiValue
8 | import com.knear.android.service.NearMainService
9 | import com.knear.android.user.NearUserInformationListener
10 | import com.knear.android.user.domain.model.UserInformation
11 | import kotlinx.coroutines.CoroutineScope
12 | import kotlinx.coroutines.Dispatchers
13 | import kotlinx.coroutines.launch
14 | import kotlinx.coroutines.withContext
15 | import java.util.*
16 |
17 | class NearDemoMainActivity : AppCompatActivity(), NearUserInformationListener {
18 |
19 | private var loginFragment: LoginFragment = LoginFragment.getInstance()
20 | private var transactionFragment: TransactionFragment = TransactionFragment.getInstance()
21 | private lateinit var nearMainService: NearMainService
22 |
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 | setContentView(R.layout.activity_near_demo_main)
26 | supportFragmentManager.beginTransaction().add(R.id.demo_fragment_container, loginFragment)
27 | .commit()
28 | nearMainService = NearMainService(this, this, this)
29 | }
30 |
31 | fun login() {
32 | nearMainService.loginOAuth()
33 | }
34 |
35 | override fun onResume() {
36 | super.onResume()
37 | val uri = intent.data
38 |
39 | if (nearMainService.attemptLogin(uri)) {
40 | supportFragmentManager.beginTransaction()
41 | .replace(R.id.demo_fragment_container, transactionFragment).commit()
42 | }
43 | }
44 |
45 | fun sendTransaction() {
46 | CoroutineScope(Dispatchers.IO).launch {
47 | val transaction = nearMainService.sendTransaction("android-test-23.testnet", "1")
48 | withContext(Dispatchers.Main) {
49 | transactionFragment.updateTxResponse(transaction)
50 | }
51 | }
52 | }
53 |
54 | fun requestCallFunction() {
55 | CoroutineScope(Dispatchers.IO).launch {
56 | val callFunctionResponse = callFunction()
57 | withContext(Dispatchers.Main) {
58 | transactionFragment.updateCallFunctionResponse(callFunctionResponse)
59 | }
60 | }
61 | }
62 |
63 | private fun callFunction(): StringBuilder {
64 | val sbResponse: StringBuilder = StringBuilder("")
65 | var balanceOfArgs = "{ \"tokenOwner\": \"android-test-22.testnet\" }"
66 | val contractName = "android-test-22.testnet"
67 | val balanceOfResponse =
68 | this.nearMainService.callViewFunction(contractName, "balanceOf", balanceOfArgs)
69 | if (balanceOfResponse.error == null) {
70 | val functionResult = balanceOfResponse.result.result!!.getDecodedAsciiValue()
71 | Log.i("NearService", "$contractName.balanceOf($balanceOfArgs): $functionResult")
72 | Log.i("NearService", "Logs: ${balanceOfResponse.result.logs}")
73 | sbResponse.appendLine("$contractName.balanceOf($balanceOfArgs): $functionResult")
74 | sbResponse.appendLine("Logs: ${balanceOfResponse.result.logs}")
75 | } else {
76 | Log.e(
77 | "NearService",
78 | "$contractName.balanceOf($balanceOfArgs) ${balanceOfResponse.error?.message}"
79 | )
80 | sbResponse.appendLine("$contractName.balanceOf($balanceOfArgs) ${balanceOfResponse.error?.message}")
81 | }
82 |
83 | val totalSupplyArgs = "{}"
84 | val totalSupplyResponse =
85 | this.nearMainService.callViewFunction(contractName, "totalSupply", totalSupplyArgs)
86 | if (totalSupplyResponse.error == null) {
87 | val functionResult = totalSupplyResponse.result.result!!.getDecodedAsciiValue()
88 | Log.i("NearService", "$contractName.totalSupply($totalSupplyArgs): $functionResult")
89 | Log.i("NearService", "Logs: ${totalSupplyResponse.result.logs}")
90 | sbResponse.appendLine("$contractName.totalSupply($totalSupplyArgs): $functionResult")
91 | sbResponse.appendLine("Logs: ${totalSupplyResponse.result.logs}")
92 | } else {
93 | Log.e(
94 | "NearService",
95 | "$contractName.totalSupply($totalSupplyArgs) ${totalSupplyResponse.error?.message}"
96 | )
97 | sbResponse.appendLine("$contractName.totalSupply($totalSupplyArgs) ${totalSupplyResponse.error?.message}")
98 | }
99 |
100 | val transferFromArgs =
101 | "{ \"from\": \"android-test-22.testnet\", \"to\": \"android-test-23.testnet\", \"tokens\": \"1\" }"
102 | val transferFromResponse =
103 | this.nearMainService.callViewFunction(contractName, "transferFrom", transferFromArgs)
104 | if (transferFromResponse.error == null) {
105 | val functionResult = totalSupplyResponse.result.result!!.getDecodedAsciiValue()
106 | Log.i("NearService", "$contractName.transferFrom($transferFromArgs): $functionResult")
107 | Log.i("NearService", "Logs: ${totalSupplyResponse.result.logs}")
108 | sbResponse.appendLine("$contractName.transferFrom($transferFromArgs): $functionResult")
109 | sbResponse.appendLine("Logs: ${totalSupplyResponse.result.logs}")
110 | } else {
111 | Log.e(
112 | "NearService",
113 | "$contractName.transferFrom($transferFromArgs) ${transferFromResponse.error?.message}"
114 | )
115 | sbResponse.appendLine("$contractName.transferFrom($transferFromArgs) ${transferFromResponse.error?.message}")
116 | }
117 |
118 | balanceOfArgs = "{ \"tokenOwner\": \"android-test-22.testnet\" }"
119 | val callViewFunctionTransactionResponse = this.nearMainService.callViewFunctionTransaction(
120 | contractName,
121 | "balanceOf",
122 | balanceOfArgs
123 | )
124 | if (callViewFunctionTransactionResponse.result.status.Failure == null) {
125 | Log.i(
126 | "NearService.",
127 | "Hash: ${callViewFunctionTransactionResponse.result.transaction.hash}"
128 | )
129 | sbResponse.appendLine("Hash: ${callViewFunctionTransactionResponse.result.transaction.hash}")
130 | callViewFunctionTransactionResponse.result.status.SuccessValue?.let {
131 | val decodedValue = String(Base64.getDecoder().decode(it))
132 | Log.i("NearService.", "SuccessValue: $decodedValue {$it}")
133 | sbResponse.appendLine("SuccessValue: $decodedValue {$it}")
134 | }
135 | }
136 |
137 | val invalidBalanceOfArgs = "{ tokenOwner: android-test-22.testnet }"
138 | val errorResponse = this.nearMainService.callViewFunctionTransaction(
139 | contractName,
140 | "balanceOf",
141 | invalidBalanceOfArgs
142 | )
143 | Log.i(
144 | "NearService.",
145 | "Hash: ${callViewFunctionTransactionResponse.result.transaction.hash}"
146 | )
147 | sbResponse.appendLine("Hash: ${callViewFunctionTransactionResponse.result.transaction.hash}")
148 | if (errorResponse.result.status.Failure != null) {
149 | Log.e(
150 | "NearService.",
151 | "Error: ${errorResponse.result.status.Failure!!.ActionError!!.kind.FunctionCallError!!.ExecutionError}"
152 | )
153 | sbResponse.appendLine("Error: ${errorResponse.result.status.Failure!!.ActionError!!.kind.FunctionCallError!!.ExecutionError}")
154 | }
155 | return sbResponse
156 | }
157 |
158 | override fun userInformationResponse(userInformation: UserInformation) {
159 |
160 | }
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/app/src/main/java/com/near/android/sdk/TransactionFragment.kt:
--------------------------------------------------------------------------------
1 | package com.near.android.sdk
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import com.knear.android.provider.response.sendmoney.SendMoney
9 | import com.jose.lujan.near.android.sdk.R
10 | import kotlinx.android.synthetic.main.fragment_transaction.view.*
11 |
12 | class TransactionFragment : Fragment() {
13 |
14 | lateinit var v: View
15 |
16 | override fun onCreateView(
17 | inflater: LayoutInflater, container: ViewGroup?,
18 | savedInstanceState: Bundle?
19 | ): View {
20 | // Inflate the layout for this fragment
21 | v = inflater.inflate(R.layout.fragment_transaction, container, false)
22 |
23 | v.transaction_btn_cv.setOnClickListener {
24 | (activity as NearDemoMainActivity).sendTransaction()
25 | v.tx_progress.visibility = View.VISIBLE
26 | }
27 | v.call_function_btn_cv.setOnClickListener {
28 | (activity as NearDemoMainActivity).requestCallFunction()
29 | v.tx_progress.visibility = View.VISIBLE
30 | }
31 |
32 | return v
33 | }
34 |
35 | fun updateTxResponse(callFunctionResponse: SendMoney) {
36 | v.tx_progress.visibility = View.GONE
37 | callFunctionResponse.result.let {
38 | v.serviceReponseTv.text = "Success with hash: $it"
39 | }
40 |
41 | callFunctionResponse.error?.let {
42 | v.serviceReponseTv.text = "Error: ${it.message}"
43 | }
44 | }
45 |
46 | fun updateCallFunctionResponse(callFunctionResponse: StringBuilder) {
47 | v.tx_progress.visibility = View.GONE
48 | callFunctionResponse.let {
49 | v.serviceReponseTv.text = "Success: $it"
50 | }
51 | }
52 |
53 | companion object {
54 | @JvmStatic
55 | fun getInstance() = TransactionFragment()
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_near_demo_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
27 |
28 |
34 |
35 |
43 |
44 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
79 |
80 |
85 |
86 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_transaction.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
34 |
35 |
41 |
42 |
47 |
48 |
54 |
55 |
56 |
57 |
58 |
59 |
74 |
75 |
80 |
81 |
88 |
89 |
90 |
91 |
92 |
93 |
109 |
110 |
115 |
116 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | near-android-sdk
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jose/lujan/near/android/sdk/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jose.lujan.near.android.sdk
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 |
4 | repositories {
5 | google()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath "com.android.tools.build:gradle:4.1.3"
10 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | task clean(type: Delete) {
18 | delete rootProject.buildDir
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | android.jetifier.blacklist=bcprov-jdk15on
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 22 11:29:31 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
3 | before_install:
4 | - ./scripts/prepareJitpackEnvironment.sh
--------------------------------------------------------------------------------
/knear-sdk/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/knear-sdk/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | id 'kotlin-android-extensions'
5 | id 'kotlin-kapt'
6 | id 'org.jetbrains.kotlin.kapt'
7 | id 'maven-publish'
8 | }
9 |
10 |
11 | ext {
12 | tweetnaclJavaVersion = '1.1.2'
13 | cryptoKeyEd25519Version = '0.2.0'
14 | kotlin_version = "1.7.20"
15 | kotlin_extensions_version = "1.7.0"
16 | appcompat_version = "1.4.1"
17 | materal_design_version = "1.5.0"
18 | constraint_layout_version = "2.1.3"
19 | retrofit_version = "2.9.0"
20 | gson_version = "2.8.6"
21 | legacy_support_version = "1.0.0"
22 | picasso_version = "2.71828"
23 | coroutines_lifecycle_version = "2.4.1"
24 | junit_test_version = "1.1.3"
25 | espresso_test_version = "3.4.0"
26 | room_version = "2.5.0"
27 | }
28 |
29 | android {
30 | compileSdk 31
31 |
32 | defaultConfig {
33 | minSdk 26
34 | targetSdk 31
35 | versionCode 1
36 | versionName "1.0"
37 |
38 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
39 | }
40 |
41 | buildTypes {
42 | release {
43 | minifyEnabled false
44 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
45 | }
46 | }
47 | compileOptions {
48 | sourceCompatibility JavaVersion.VERSION_1_8
49 | targetCompatibility JavaVersion.VERSION_1_8
50 | }
51 | kotlinOptions {
52 | jvmTarget = '1.8'
53 | }
54 | packagingOptions {
55 | exclude 'META-INF/*'
56 | }
57 | }
58 |
59 | dependencies {
60 |
61 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
62 | implementation "androidx.core:core-ktx:$kotlin_extensions_version"
63 | implementation "androidx.appcompat:appcompat:$appcompat_version"
64 | implementation "com.google.android.material:material:$materal_design_version"
65 | implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
66 |
67 | //Retrofit and GSON
68 | implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
69 | implementation "com.google.code.gson:gson:$gson_version"
70 | implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
71 | implementation "androidx.legacy:legacy-support-v4:$legacy_support_version"
72 |
73 | //picasso
74 | implementation "com.squareup.picasso:picasso:$picasso_version"
75 |
76 | //Coroutines
77 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$coroutines_lifecycle_version"
78 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$coroutines_lifecycle_version"
79 | implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$coroutines_lifecycle_version"
80 | implementation 'com.android.volley:volley:1.2.1'
81 | implementation 'com.google.code.gson:gson:2.9.0'
82 | kapt "androidx.lifecycle:lifecycle-compiler:$coroutines_lifecycle_version"
83 |
84 | implementation "com.goterl:lazysodium-android:5.0.2@aar"
85 | implementation "net.java.dev.jna:jna:5.9.0@aar"
86 |
87 | // for print the log of api's in build mode
88 | implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")
89 |
90 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
91 |
92 | //implementation "cash.z.ecc.android:kotlin-bip39:1.0.1"
93 |
94 | //Room
95 | implementation "androidx.room:room-runtime:$room_version"
96 | kapt "androidx.room:room-compiler:$room_version"
97 |
98 | //Coroutines support for Room
99 | implementation "androidx.room:room-ktx:$room_version"
100 |
101 | implementation 'com.madgag.spongycastle:prov:1.54.0.0'
102 | implementation 'com.madgag.spongycastle:pkix:1.54.0.0'
103 |
104 | testImplementation 'junit:junit:4.+'
105 | androidTestImplementation "androidx.test.ext:junit:$junit_test_version"
106 | androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_test_version"
107 |
108 | // Base 58
109 | implementation "com.syntifi.crypto:crypto-key-ed25519:$cryptoKeyEd25519Version"
110 |
111 | implementation 'com.squareup.okhttp3:okhttp:4.9.0'
112 |
113 | implementation files("libs/borshj-0.2.0-SNAPSHOT.jar")
114 | implementation files("libs/tweetnacl-java-1.1.2.jar")
115 | }
116 |
117 | afterEvaluate {
118 | publishing {
119 | publications {
120 | release(MavenPublication) {
121 | from components.release
122 | groupId = 'com.github.near'
123 | artifactId = 'near-api-kotlin'
124 | version = '1.0.19'
125 | }
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/knear-sdk/libs/borshj-0.2.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/knear-sdk/libs/borshj-0.2.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/knear-sdk/libs/tweetnacl-java-1.1.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/near/near-api-kotlin/96514ab3cc65ccd726fa9b8de162bfcf726ad6ba/knear-sdk/libs/tweetnacl-java-1.1.2.jar
--------------------------------------------------------------------------------
/knear-sdk/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/model/Account.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.model
2 |
3 | class Account (val accountId: String, val publicKey: String, val allKeys: String)
4 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/NearRequest.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | import com.google.gson.GsonBuilder
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.model.NearRequestParams
6 |
7 | class NearRequest (
8 | @SerializedName("method")
9 | private val method: String,
10 | @SerializedName("params")
11 | private val params: NearRequestParams,
12 | @SerializedName("id")
13 | private val currentId: Int
14 | ){
15 | @SerializedName("jsonrpc")
16 | private var jsonRpc: String = "2.0"
17 |
18 | override fun toString(): String {
19 | val gsonBuilder = GsonBuilder()
20 | val gson = gsonBuilder.create()
21 |
22 | return gson.toJson(this)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/NearRequestParamList.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | import com.google.gson.GsonBuilder
4 | import com.google.gson.annotations.SerializedName
5 |
6 | class NearRequestParamList (
7 | @SerializedName("method")
8 | private val method: String,
9 | @SerializedName("params")
10 | private val params: List,
11 | @SerializedName("id")
12 | private val currentId: Int
13 | ){
14 | @SerializedName("jsonrpc")
15 | private var jsonRpc: String = "2.0"
16 |
17 | override fun toString(): String {
18 | val gsonBuilder = GsonBuilder()
19 | val gson = gsonBuilder.create()
20 |
21 | return gson.toJson(this)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/NearResponse.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | open interface NearResponse {
4 | val jsonRcp: String
5 | val id: Int
6 | }
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/NearResponseListener.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | interface NearResponseListener {
4 | fun onError(error: Exception )
5 | fun onResponse(response: NearResponse)
6 | }
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/ViewAccessKeyChangesAllRequestParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | import com.google.gson.GsonBuilder
4 | import com.google.gson.annotations.SerializedName
5 |
6 | class ViewAccessKeyChangesAllRequestParams (
7 | @SerializedName("method")
8 | private val method: String,
9 | @SerializedName("params")
10 | private val params: Any,
11 | @SerializedName("id")
12 | private val currentId: Int
13 | ){
14 | @SerializedName("jsonrpc")
15 | private var jsonRpc: String = "2.0"
16 |
17 | override fun toString(): String {
18 | val gsonBuilder = GsonBuilder()
19 | val gson = gsonBuilder.create()
20 |
21 | return gson.toJson(this)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/ViewAccessKeyChangesRequestParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider
2 |
3 | import com.google.gson.GsonBuilder
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.model.ViewAccessKeyChangesParams
6 |
7 | class ViewAccessKeyChangesRequestParams (
8 | @SerializedName("method")
9 | private val method: String,
10 | @SerializedName("params")
11 | private val params: ViewAccessKeyChangesParams,
12 | @SerializedName("id")
13 | private val currentId: Int
14 | ){
15 | @SerializedName("jsonrpc")
16 | private var jsonRpc: String = "2.0"
17 |
18 | override fun toString(): String {
19 | val gsonBuilder = GsonBuilder()
20 | val gson = gsonBuilder.create()
21 |
22 | return gson.toJson(this)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/BlockDetailsParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | class BlockDetailsParams(
6 | @SerializedName("block_id")
7 | val block_id: Int = 0
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ChunkDetailsParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | class ChunkDetailsParams(
6 | @SerializedName("chunk_id")
7 | val chunk_id: String = ""
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/Keys.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class Keys(
4 | val account_id:String,
5 | val public_key:String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/NearRequestParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | class NearRequestParams(
6 | @SerializedName("finality")
7 | val finality: String? = null,
8 | @SerializedName("block_id")
9 | val blockId: String? = null,
10 | @SerializedName("request_type")
11 | val requestType: String? = null,
12 | @SerializedName("account_id")
13 | val accountId: String? = null,
14 | @SerializedName("public_key")
15 | val publicKey: String? = null,
16 | @SerializedName("method_name")
17 | val methodName: String? = null,
18 | @SerializedName("args_base64")
19 | val argsBase64: String? = null,
20 | )
21 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ProtocolConfigParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | class ProtocolConfigParams(
6 | @SerializedName("finality")
7 | val finality: String
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewAccessKeyChangesAllParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewAccessKeyChangesAllParams(
4 | val changes_type:String,
5 | val account_ids:List,
6 | val block_id:String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewAccessKeyChangesParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewAccessKeyChangesParams(
4 | val changes_type:String,
5 | val keys:List,
6 | val finality:String = "final"
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewAccessKeyChangesRequest.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewAccessKeyChangesRequest(
4 | val params: ViewAccessKeyChangesParams
5 | )
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewAccountChangesParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewAccountChangesParams(
4 | val changes_type:String,
5 | val account_ids:List,
6 | val block_id:Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewContractCodeChangesParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewContractCodeChangesParams(
4 | val changes_type:String,
5 | val account_ids:List,
6 | val block_id:Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/model/ViewContractStateChangesParams.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.model
2 |
3 | class ViewContractStateChangesParams(
4 | val changes_type:String,
5 | val account_ids:List,
6 | val key_prefix_base64:String,
7 | val block_id:Int
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/block/Block.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.block
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | class Block (
9 |
10 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
11 | @SerializedName("result") var result : Result = Result(),
12 | @SerializedName("id") var id : String? = null,
13 | @SerializedName("error") var error: ErrorResponse? = null
14 |
15 | ) {
16 | companion object {
17 | @JvmStatic
18 | @JvmName("create")
19 | fun Response.toBlock() : Block {
20 | val gson = Gson()
21 | if(this.isSuccessful) {
22 | this.body?.let {
23 | return gson.fromJson(it.string(), Block::class.java)
24 | }?: Block()
25 | }
26 | return Block()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/block/Chunks.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.block
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Chunks (
7 |
8 | @SerializedName("balance_burnt") var balanceBurnt : String? = null,
9 | @SerializedName("chunk_hash") var chunkHash : String? = null,
10 | @SerializedName("encoded_length" ) var encodedLength : Int? = null,
11 | @SerializedName("encoded_merkle_root") var encodedMerkleRoot : String? = null,
12 | @SerializedName("gas_limit") var gasLimit : Long? = null,
13 | @SerializedName("gas_used") var gasUsed : Long? = null,
14 | @SerializedName("height_created") var heightCreated : Int? = null,
15 | @SerializedName("height_included") var heightIncluded : Int? = null,
16 | @SerializedName("outcome_root") var outcomeRoot : String? = null,
17 | @SerializedName("outgoing_receipts_root") var outgoingReceiptsRoot : String? = null,
18 | @SerializedName("prev_block_hash") var prevBlockHash : String? = null,
19 | @SerializedName("prev_state_root") var prevStateRoot : String? = null,
20 | @SerializedName("rent_paid") var rentPaid : String? = null,
21 | @SerializedName("shard_id") var shardId : Int? = null,
22 | @SerializedName("signature") var signature : String? = null,
23 | @SerializedName("tx_root") var txRoot : String? = null,
24 | @SerializedName("validator_proposals") var validatorProposals : ArrayList = arrayListOf(),
25 | @SerializedName("validator_reward") var validatorReward : String? = null
26 |
27 | )
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/block/Header.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.block
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Header (
7 |
8 | @SerializedName("approvals") var approvals : ArrayList = arrayListOf(),
9 | @SerializedName("block_merkle_root") var blockMerkleRoot : String? = null,
10 | @SerializedName("block_ordinal") var blockOrdinal : Int?= null,
11 | @SerializedName("challenges_result") var challengesResult: ArrayList = arrayListOf(),
12 | @SerializedName("challenges_root") var challengesRoot: String?= null,
13 | @SerializedName("chunk_headers_root") var chunkHeadersRoot: String? = null,
14 | @SerializedName("chunk_mask") var chunkMask : ArrayList = arrayListOf(),
15 | @SerializedName("chunk_receipts_root") var chunkReceiptsRoot: String? = null,
16 | @SerializedName("chunk_tx_root") var chunkTxRoot: String? = null,
17 | @SerializedName("chunks_included") var chunksIncluded: Int? = null,
18 | @SerializedName("epoch_id" ) var epochId: String? = null,
19 | @SerializedName("epoch_sync_data_hash") var epochSyncDataHash: String? = null,
20 | @SerializedName("gas_price") var gasPrice: String? = null,
21 | @SerializedName("hash") var hash: String = "",
22 | @SerializedName("height") var height : Int? = null,
23 | @SerializedName("last_ds_final_block") var lastDsFinalBlock: String? = null,
24 | @SerializedName("last_final_block") var lastFinalBlock: String? = null,
25 | @SerializedName("latest_protocol_version") var latestProtocolVersion : Int? = null,
26 | @SerializedName("next_bp_hash") var nextBpHash: String? = null,
27 | @SerializedName("next_epoch_id") var nextEpochId: String? = null,
28 | @SerializedName("outcome_root") var outcomeRoot: String? = null,
29 | @SerializedName("prev_hash") var prevHash: String? = null,
30 | @SerializedName("prev_height") var prevHeight: Int? = null,
31 | @SerializedName("prev_state_root") var prevStateRoot: String? = null,
32 | @SerializedName("random_value") var randomValue: String? = null,
33 | @SerializedName("rent_paid") var rentPaid: String? = null,
34 | @SerializedName("signature") var signature : String? = null,
35 | @SerializedName("timestamp") var timestamp : Long? = null,
36 | @SerializedName("timestamp_nanosec") var timestampNanosec: String? = null,
37 | @SerializedName("total_supply") var totalSupply: String? = null,
38 | @SerializedName("validator_proposals") var validatorProposals : ArrayList = arrayListOf(),
39 | @SerializedName("validator_reward") var validatorReward : String? = null
40 |
41 | )
42 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/block/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.block
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Result (
7 |
8 | @SerializedName("author") var author : String? = null,
9 | @SerializedName("chunks") var chunks : ArrayList = arrayListOf(),
10 | @SerializedName("header") var header : Header = Header()
11 |
12 | )
13 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/blockchanges/BlockChangesResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.blockchanges
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | class BlockChangesResult (
9 |
10 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
11 | @SerializedName("result") var result : Result = Result(),
12 | @SerializedName("id") var id : String? = null,
13 | @SerializedName("error") var error: ErrorResponse? = null
14 |
15 | ) {
16 | companion object {
17 | @JvmStatic
18 | @JvmName("create")
19 | fun Response.toBlockChanges() : BlockChangesResult {
20 | val gson = Gson()
21 | if(this.isSuccessful) {
22 | this.body?.let {
23 | return gson.fromJson(it.string(), BlockChangesResult::class.java)
24 | }?: BlockChangesResult()
25 | }
26 | return BlockChangesResult()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/blockchanges/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.blockchanges
2 |
3 | data class Change(
4 | val account_id: String,
5 | val type: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/blockchanges/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.blockchanges
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/chunkdetails/ChunkDetailsResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.chunkdetails
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | class ChunkDetailsResult (
9 |
10 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
11 | @SerializedName("result") var result : Result = Result(),
12 | @SerializedName("id") var id : String? = null,
13 | @SerializedName("error") var error: ErrorResponse? = null
14 |
15 | ) {
16 | companion object {
17 | @JvmStatic
18 | @JvmName("create")
19 | fun Response.toChunkDetails() : ChunkDetailsResult {
20 | val gson = Gson()
21 | if(this.isSuccessful) {
22 | this.body?.let {
23 | return gson.fromJson(it.string(), ChunkDetailsResult::class.java)
24 | }?: ChunkDetailsResult()
25 | }
26 | return ChunkDetailsResult()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/chunkdetails/Header.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.chunkdetails
2 |
3 | data class Header(
4 | val balance_burnt: String,
5 | val chunk_hash: String,
6 | val encoded_length: Int,
7 | val encoded_merkle_root: String,
8 | val gas_limit: Long,
9 | val gas_used: Int,
10 | val height_created: Int,
11 | val height_included: Int,
12 | val outcome_root: String,
13 | val outgoing_receipts_root: String,
14 | val prev_block_hash: String,
15 | val prev_state_root: String,
16 | val rent_paid: String,
17 | val shard_id: Int,
18 | val signature: String,
19 | val tx_root: String,
20 | val validator_proposals: List,
21 | val validator_reward: String
22 | )
23 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/chunkdetails/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.chunkdetails
2 |
3 | data class Result(
4 | val author: String = "",
5 | var header: Header? = null,
6 | val receipts: List = listOf(),
7 | val transactions: List = listOf()
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/errorresponse/ErrorResponse.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.errorresponse
2 |
3 | data class ErrorResponse(
4 | val cause: Any = {},
5 | val code: Int = 0,
6 | val data: Any = {},
7 | val message: String = "",
8 | val name: String = ""
9 | )
10 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/errorresponse/Info.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.errorresponse
2 |
3 | data class Info(
4 | val error_message: String
5 | )
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/FunctionCallResponse.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall
2 | import com.google.gson.Gson
3 | import com.google.gson.annotations.SerializedName
4 | import com.knear.android.provider.response.errorresponse.ErrorResponse
5 | import okhttp3.Response
6 |
7 | data class FunctionCallResponse(
8 | @SerializedName("jsonrpc" ) var jsonrpc : String? = null,
9 | @SerializedName("result" ) var result : Result = Result(),
10 | @SerializedName("id" ) var id : Int? = null,
11 | @SerializedName("error") var error: ErrorResponse? = null
12 | ){
13 | companion object {
14 | @JvmStatic
15 | @JvmName("create")
16 | fun Response.toFunctionCallResponse() : FunctionCallResponse {
17 | val gson = Gson()
18 | if(this.isSuccessful) {
19 | this.body?.let {
20 | return gson.fromJson(it.string(), FunctionCallResponse::class.java)
21 | }?: FunctionCallResponse()
22 | }
23 | return FunctionCallResponse()
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall
2 | import com.google.gson.annotations.SerializedName
3 |
4 | data class Result (
5 | @SerializedName("block_hash" ) var blockHash : String? = null,
6 | @SerializedName("block_height" ) var blockHeight : Long? = null,
7 | @SerializedName("logs" ) var logs : ArrayList = arrayListOf(),
8 | @SerializedName("result" ) var result : ByteArray? = null,
9 | @SerializedName("error" ) var error : String? = null
10 | ) {
11 | override fun equals(other: Any?): Boolean {
12 | if (this === other) return true
13 | if (javaClass != other?.javaClass) return false
14 |
15 | other as Result
16 |
17 | if (blockHash != other.blockHash) return false
18 | if (blockHeight != other.blockHeight) return false
19 | if (logs != other.logs) return false
20 | if (result != null) {
21 | if (other.result == null) return false
22 | if (!result.contentEquals(other.result)) return false
23 | } else if (other.result != null) return false
24 | if (error != other.error) return false
25 |
26 | return true
27 | }
28 |
29 | override fun hashCode(): Int {
30 | var result1 = blockHash?.hashCode() ?: 0
31 | result1 = 31 * result1 + (blockHeight?.hashCode() ?: 0)
32 | result1 = 31 * result1 + logs.hashCode()
33 | result1 = 31 * result1 + (result?.contentHashCode() ?: 0)
34 | result1 = 31 * result1 + (error?.hashCode() ?: 0)
35 | return result1
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/ActionError.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class ActionError (
7 |
8 | @SerializedName("index" ) var index : Int? = null,
9 | @SerializedName("kind" ) var kind : Kind = Kind()
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Actions.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Actions (
7 |
8 | @SerializedName("FunctionCall" ) var FunctionCall : FunctionCall? = FunctionCall()
9 |
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Failure.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Failure (
7 |
8 | @SerializedName("ActionError" ) var ActionError : ActionError? = ActionError()
9 |
10 | )
11 |
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/FunctionCall.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import java.math.BigInteger
5 |
6 |
7 | data class FunctionCall (
8 |
9 | @SerializedName("args" ) var args : String? = null,
10 | @SerializedName("deposit" ) var deposit : BigInteger? = null,
11 | @SerializedName("gas" ) var gas : Long? = null,
12 | @SerializedName("method_name" ) var methodName : String? = null
13 |
14 | )
15 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/FunctionCallError.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 | import com.google.gson.annotations.SerializedName
3 |
4 | class FunctionCallError {
5 | @SerializedName("ExecutionError" ) var ExecutionError : String? = null
6 | }
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/FunctionCallTransactionResponse.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import okhttp3.Response
6 |
7 |
8 | data class FunctionCallTransactionResponse (
9 |
10 | @SerializedName("jsonrpc" ) var jsonrpc : String? = null,
11 | @SerializedName("result" ) var result : Result = Result(),
12 | @SerializedName("id" ) var id : Int? = null
13 |
14 | ){
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toFunctionCallTransactionResponse() : FunctionCallTransactionResponse {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), FunctionCallTransactionResponse::class.java)
23 | }?: FunctionCallTransactionResponse()
24 | }
25 | return FunctionCallTransactionResponse()
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/GasProfile.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class GasProfile (
7 |
8 | @SerializedName("cost" ) var cost : String? = null,
9 | @SerializedName("cost_category" ) var costCategory : String? = null,
10 | @SerializedName("gas_used" ) var gasUsed : String? = null
11 |
12 | )
13 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Kind.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 | import com.google.gson.annotations.SerializedName
3 |
4 | class Kind {
5 | @SerializedName("FunctionCallError" ) var FunctionCallError : FunctionCallError? = FunctionCallError()
6 | }
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Metadata.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Metadata (
7 |
8 | @SerializedName("gas_profile" ) var gasProfile : Any = {},
9 | @SerializedName("version" ) var version : Int? = null
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Outcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Outcome (
7 |
8 | @SerializedName("executor_id" ) var executorId : String? = null,
9 | @SerializedName("gas_burnt" ) var gasBurnt : Long? = null,
10 | @SerializedName("logs" ) var logs : ArrayList = arrayListOf(),
11 | @SerializedName("metadata" ) var metadata : Metadata? = Metadata(),
12 | @SerializedName("receipt_ids" ) var receiptIds : ArrayList = arrayListOf(),
13 | @SerializedName("status" ) var status : Status? = Status(),
14 | @SerializedName("tokens_burnt" ) var tokensBurnt : String? = null
15 |
16 | )
17 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Proof.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Proof (
7 |
8 | @SerializedName("direction" ) var direction : String? = null,
9 | @SerializedName("hash" ) var hash : String? = null
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/ReceiptsOutcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class ReceiptsOutcome (
7 |
8 | @SerializedName("block_hash" ) var blockHash : String? = null,
9 | @SerializedName("id" ) var id : String? = null,
10 | @SerializedName("outcome" ) var outcome : Outcome? = Outcome(),
11 | @SerializedName("proof" ) var proof : ArrayList = arrayListOf()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Result (
7 |
8 | @SerializedName("receipts_outcome" ) var receiptsOutcome : ArrayList = arrayListOf(),
9 | @SerializedName("status" ) var status : Status = Status(),
10 | @SerializedName("transaction" ) var transaction : Transaction = Transaction(),
11 | @SerializedName("transaction_outcome" ) var transactionOutcome : TransactionOutcome = TransactionOutcome()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Status.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Status (
7 | @SerializedName("SuccessReceiptId" ) var SuccessReceiptId : String? = null,
8 | @SerializedName("SuccessValue" ) var SuccessValue : String? = null,
9 | @SerializedName("Failure" ) var Failure : Failure? = null
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/Transaction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Transaction (
7 |
8 | @SerializedName("actions" ) var actions : ArrayList = arrayListOf(),
9 | @SerializedName("hash" ) var hash : String? = null,
10 | @SerializedName("nonce" ) var nonce : Long? = null,
11 | @SerializedName("public_key" ) var publicKey : String? = null,
12 | @SerializedName("receiver_id" ) var receiverId : String? = null,
13 | @SerializedName("signature" ) var signature : String? = null,
14 | @SerializedName("signer_id" ) var signerId : String? = null
15 |
16 | )
17 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/functioncall/transaction/TransactionOutcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.functioncall.transaction
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class TransactionOutcome (
7 |
8 | @SerializedName("block_hash" ) var blockHash : String? = null,
9 | @SerializedName("id" ) var id : String? = null,
10 | @SerializedName("outcome" ) var outcome : Outcome = Outcome(),
11 | @SerializedName("proof" ) var proof : ArrayList = arrayListOf()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/gasprice/GasPriceResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.gasprice
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class GasPriceResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.gasPriceResult() : GasPriceResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), GasPriceResult::class.java)
22 | }?: GasPriceResult()
23 | }
24 | return GasPriceResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/gasprice/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.gasprice
2 |
3 | data class Result(
4 | val gas_price: String = ""
5 | )
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/AccountCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class AccountCreationConfig(
4 | val min_allowed_top_level_account_length: Int,
5 | val registrar_account_id: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/ActionCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class ActionCreationConfig(
4 | val add_key_cost: AddKeyCost,
5 | val create_account_cost: CreateAccountCost,
6 | val delete_account_cost: DeleteAccountCost,
7 | val delete_key_cost: DeleteKeyCost,
8 | val deploy_contract_cost: DeployContractCost,
9 | val deploy_contract_cost_per_byte: DeployContractCostPerByte,
10 | val function_call_cost: FunctionCallCostX,
11 | val function_call_cost_per_byte: FunctionCallCostPerByteX,
12 | val stake_cost: StakeCost,
13 | val transfer_cost: TransferCost
14 | )
15 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/ActionReceiptCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class ActionReceiptCreationConfig(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/AddKeyCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class AddKeyCost(
4 | val full_access_cost: FullAccessCost,
5 | val function_call_cost: FunctionCallCostX,
6 | val function_call_cost_per_byte: FunctionCallCostPerByteX
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/BaseCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class BaseCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/CostPerByte.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class CostPerByte(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/CreateAccountCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class CreateAccountCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/DataReceiptCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class DataReceiptCreationConfig(
4 | val base_cost: BaseCost,
5 | val cost_per_byte: CostPerByte
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/DeleteAccountCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class DeleteAccountCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/DeleteKeyCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class DeleteKeyCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/DeployContractCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class DeployContractCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/DeployContractCostPerByte.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class DeployContractCostPerByte(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/ExtCosts.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class ExtCosts(
4 | val base: Int,
5 | val contract_compile_base: Int,
6 | val contract_compile_bytes: Int,
7 | val keccak256_base: Long,
8 | val keccak256_byte: Int,
9 | val keccak512_base: Long,
10 | val keccak512_byte: Int,
11 | val log_base: Long,
12 | val log_byte: Int,
13 | val promise_and_base: Int,
14 | val promise_and_per_promise: Int,
15 | val promise_return: Int,
16 | val read_memory_base: Long,
17 | val read_memory_byte: Int,
18 | val read_register_base: Long,
19 | val read_register_byte: Int,
20 | val sha256_base: Long,
21 | val sha256_byte: Int,
22 | val storage_has_key_base: Long,
23 | val storage_has_key_byte: Int,
24 | val storage_iter_create_from_byte: Int,
25 | val storage_iter_create_prefix_base: Int,
26 | val storage_iter_create_prefix_byte: Int,
27 | val storage_iter_create_range_base: Int,
28 | val storage_iter_create_to_byte: Int,
29 | val storage_iter_next_base: Int,
30 | val storage_iter_next_key_byte: Int,
31 | val storage_iter_next_value_byte: Int,
32 | val storage_read_base: Long,
33 | val storage_read_key_byte: Int,
34 | val storage_read_value_byte: Int,
35 | val storage_remove_base: Long,
36 | val storage_remove_key_byte: Int,
37 | val storage_remove_ret_value_byte: Int,
38 | val storage_write_base: Long,
39 | val storage_write_evicted_byte: Int,
40 | val storage_write_key_byte: Int,
41 | val storage_write_value_byte: Int,
42 | val touching_trie_node: Long,
43 | val utf16_decoding_base: Long,
44 | val utf16_decoding_byte: Int,
45 | val utf8_decoding_base: Long,
46 | val utf8_decoding_byte: Int,
47 | val validator_stake_base: Long,
48 | val validator_total_stake_base: Long,
49 | val write_memory_base: Long,
50 | val write_memory_byte: Int,
51 | val write_register_base: Long,
52 | val write_register_byte: Int
53 | )
54 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/FullAccessCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class FullAccessCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/FunctionCallCostPerByteX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class FunctionCallCostPerByteX(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/FunctionCallCostX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class FunctionCallCostX(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/GenesisConfigResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class GenesisConfigResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.getGenesisConfigResult() : GenesisConfigResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), GenesisConfigResult::class.java)
22 | }?: GenesisConfigResult()
23 | }
24 | return GenesisConfigResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/LimitConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class LimitConfig(
4 | val initial_memory_pages: Int,
5 | val max_actions_per_receipt: Int,
6 | val max_arguments_length: Int,
7 | val max_contract_size: Int,
8 | val max_gas_burnt: Long,
9 | val max_gas_burnt_view: Long,
10 | val max_length_method_name: Int,
11 | val max_length_returned_data: Int,
12 | val max_length_storage_key: Int,
13 | val max_length_storage_value: Int,
14 | val max_memory_pages: Int,
15 | val max_number_bytes_method_names: Int,
16 | val max_number_input_data_dependencies: Int,
17 | val max_number_logs: Int,
18 | val max_number_registers: Int,
19 | val max_promises_per_function_call_action: Int,
20 | val max_register_size: Int,
21 | val max_stack_height: Int,
22 | val max_total_log_length: Int,
23 | val max_total_prepaid_gas: Long,
24 | val registers_memory_limit: Int
25 | )
26 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class Result(
4 | val avg_hidden_validator_seats_per_shard: List = listOf(),
5 | val block_producer_kickout_threshold: Int = 0,
6 | val chain_id: String = "",
7 | val chunk_producer_kickout_threshold: Int = 0,
8 | val dynamic_resharding: Boolean = false,
9 | val epoch_length: Int = 0,
10 | val fishermen_threshold: String = "",
11 | val gas_limit: Long = 0L,
12 | val gas_price_adjustment_rate: List = listOf(),
13 | val genesis_height: Int = 0,
14 | val genesis_time: String = "",
15 | val max_gas_price: String = "",
16 | val max_inflation_rate: List = listOf(),
17 | val min_gas_price: String = "",
18 | val minimum_stake_divisor: Int = 0,
19 | val num_block_producer_seats: Int = 0,
20 | val num_block_producer_seats_per_shard: List = listOf(),
21 | val num_blocks_per_year: Int = 0,
22 | val online_max_threshold: List = listOf(),
23 | val online_min_threshold: List = listOf(),
24 | val protocol_reward_rate: List = listOf(),
25 | val protocol_treasury_account: String = "",
26 | val protocol_upgrade_num_epochs: Int = 0,
27 | val protocol_upgrade_stake_threshold: List = listOf(),
28 | val protocol_version: Int = 0,
29 | val runtime_config: RuntimeConfig? = null,
30 | val total_supply: String = "",
31 | val transaction_validity_period: Int = 0,
32 | val validators: List = listOf()
33 | )
34 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/RuntimeConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class RuntimeConfig(
4 | val account_creation_config: AccountCreationConfig,
5 | val storage_amount_per_byte: String,
6 | val transaction_costs: TransactionCosts,
7 | val wasm_config: WasmConfig
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/StakeCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class StakeCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/StorageUsageConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class StorageUsageConfig(
4 | val num_bytes_account: Int,
5 | val num_extra_bytes_record: Int
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/TransactionCosts.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class TransactionCosts(
4 | val action_creation_config: ActionCreationConfig,
5 | val action_receipt_creation_config: ActionReceiptCreationConfig,
6 | val burnt_gas_reward: List,
7 | val data_receipt_creation_config: DataReceiptCreationConfig,
8 | val pessimistic_gas_price_inflation_ratio: List,
9 | val storage_usage_config: StorageUsageConfig
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/TransferCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class TransferCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/Validator.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class Validator(
4 | val account_id: String,
5 | val amount: String,
6 | val public_key: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/genesisconfig/WasmConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.genesisconfig
2 |
3 | data class WasmConfig(
4 | val ext_costs: ExtCosts,
5 | val grow_mem_cost: Int,
6 | val limit_config: LimitConfig,
7 | val regular_op_cost: Int
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/networkstatus/NetworkStatusResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.networkstatus
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class NetworkStatusResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.getNetworkStatus() : NetworkStatusResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), NetworkStatusResult::class.java)
22 | }?: NetworkStatusResult()
23 | }
24 | return NetworkStatusResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/networkstatus/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.networkstatus
2 |
3 | data class Result(
4 | val chain_id: String = "",
5 | val latest_protocol_version: Int = 0,
6 | val protocol_version: Int = 0,
7 | val rpc_addr: String = "",
8 | val sync_info: SyncInfo? = null,
9 | val validator_account_id: String = "",
10 | val validators: List = listOf(),
11 | val version: Version? = null
12 | )
13 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/networkstatus/SyncInfo.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.networkstatus
2 |
3 | data class SyncInfo(
4 | val latest_block_hash: String,
5 | val latest_block_height: Int,
6 | val latest_block_time: String,
7 | val latest_state_root: String,
8 | val syncing: Boolean
9 | )
10 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/networkstatus/Validator.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.networkstatus
2 |
3 | data class Validator(
4 | val account_id: String,
5 | val is_slashed: Boolean
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/networkstatus/Version.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.networkstatus
2 |
3 | data class Version(
4 | val build: String,
5 | val version: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/AccountCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class AccountCreationConfig(
4 | val min_allowed_top_level_account_length: Int,
5 | val registrar_account_id: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/ActionCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class ActionCreationConfig(
4 | val add_key_cost: AddKeyCost,
5 | val create_account_cost: CreateAccountCost,
6 | val delete_account_cost: DeleteAccountCost,
7 | val delete_key_cost: DeleteKeyCost,
8 | val deploy_contract_cost: DeployContractCost,
9 | val deploy_contract_cost_per_byte: DeployContractCostPerByte,
10 | val function_call_cost: FunctionCallCostX,
11 | val function_call_cost_per_byte: FunctionCallCostPerByteX,
12 | val stake_cost: StakeCost,
13 | val transfer_cost: TransferCost
14 | )
15 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/ActionReceiptCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class ActionReceiptCreationConfig(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/AddKeyCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class AddKeyCost(
4 | val full_access_cost: FullAccessCost,
5 | val function_call_cost: FunctionCallCostX,
6 | val function_call_cost_per_byte: FunctionCallCostPerByteX
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/BaseCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class BaseCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/CostPerByte.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class CostPerByte(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/CreateAccountCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class CreateAccountCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/DataReceiptCreationConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class DataReceiptCreationConfig(
4 | val base_cost: BaseCost,
5 | val cost_per_byte: CostPerByte
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/DeleteAccountCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class DeleteAccountCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/DeleteKeyCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class DeleteKeyCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/DeployContractCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class DeployContractCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/DeployContractCostPerByte.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class DeployContractCostPerByte(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/ExtCosts.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class ExtCosts(
4 | val base: Int,
5 | val contract_compile_base: Int,
6 | val contract_compile_bytes: Int,
7 | val keccak256_base: Long,
8 | val keccak256_byte: Int,
9 | val keccak512_base: Long,
10 | val keccak512_byte: Int,
11 | val log_base: Long,
12 | val log_byte: Int,
13 | val promise_and_base: Int,
14 | val promise_and_per_promise: Int,
15 | val promise_return: Int,
16 | val read_memory_base: Long,
17 | val read_memory_byte: Int,
18 | val read_register_base: Long,
19 | val read_register_byte: Int,
20 | val sha256_base: Long,
21 | val sha256_byte: Int,
22 | val storage_has_key_base: Long,
23 | val storage_has_key_byte: Int,
24 | val storage_iter_create_from_byte: Int,
25 | val storage_iter_create_prefix_base: Int,
26 | val storage_iter_create_prefix_byte: Int,
27 | val storage_iter_create_range_base: Int,
28 | val storage_iter_create_to_byte: Int,
29 | val storage_iter_next_base: Int,
30 | val storage_iter_next_key_byte: Int,
31 | val storage_iter_next_value_byte: Int,
32 | val storage_read_base: Long,
33 | val storage_read_key_byte: Int,
34 | val storage_read_value_byte: Int,
35 | val storage_remove_base: Long,
36 | val storage_remove_key_byte: Int,
37 | val storage_remove_ret_value_byte: Int,
38 | val storage_write_base: Long,
39 | val storage_write_evicted_byte: Int,
40 | val storage_write_key_byte: Int,
41 | val storage_write_value_byte: Int,
42 | val touching_trie_node: Long,
43 | val utf16_decoding_base: Long,
44 | val utf16_decoding_byte: Int,
45 | val utf8_decoding_base: Long,
46 | val utf8_decoding_byte: Int,
47 | val validator_stake_base: Long,
48 | val validator_total_stake_base: Long,
49 | val write_memory_base: Long,
50 | val write_memory_byte: Int,
51 | val write_register_base: Long,
52 | val write_register_byte: Int
53 | )
54 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/FullAccessCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class FullAccessCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/FunctionCallCostPerByteX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class FunctionCallCostPerByteX(
4 | val execution: Int,
5 | val send_not_sir: Int,
6 | val send_sir: Int
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/FunctionCallCostX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class FunctionCallCostX(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/LimitConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class LimitConfig(
4 | val initial_memory_pages: Int,
5 | val max_actions_per_receipt: Int,
6 | val max_arguments_length: Int,
7 | val max_contract_size: Int,
8 | val max_gas_burnt: Long,
9 | val max_gas_burnt_view: Long,
10 | val max_length_method_name: Int,
11 | val max_length_returned_data: Int,
12 | val max_length_storage_key: Int,
13 | val max_length_storage_value: Int,
14 | val max_memory_pages: Int,
15 | val max_number_bytes_method_names: Int,
16 | val max_number_input_data_dependencies: Int,
17 | val max_number_logs: Int,
18 | val max_number_registers: Int,
19 | val max_promises_per_function_call_action: Int,
20 | val max_register_size: Int,
21 | val max_stack_height: Int,
22 | val max_total_log_length: Int,
23 | val max_total_prepaid_gas: Long,
24 | val registers_memory_limit: Int
25 | )
26 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/ProtocolConfigResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ProtocolConfigResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.getProtocolConfigResult() : ProtocolConfigResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ProtocolConfigResult::class.java)
22 | } ?: ProtocolConfigResult()
23 | }
24 | return ProtocolConfigResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class Result(
4 | val avg_hidden_validator_seats_per_shard: List = listOf(),
5 | val block_producer_kickout_threshold: Int = 0,
6 | val chain_id: String = "",
7 | val chunk_producer_kickout_threshold: Int = 0,
8 | val dynamic_resharding: Boolean? = null,
9 | val epoch_length: Int = 0,
10 | val fishermen_threshold: String = "",
11 | val gas_limit: Long = 0L,
12 | val gas_price_adjustment_rate: List = listOf(),
13 | val genesis_height: Int = 0,
14 | val genesis_time: String = "",
15 | val max_gas_price: String = "",
16 | val max_inflation_rate: List = listOf(),
17 | val min_gas_price: String = "",
18 | val minimum_stake_divisor: Int = 0,
19 | val num_block_producer_seats: Int = 0,
20 | val num_block_producer_seats_per_shard: List = listOf(),
21 | val num_blocks_per_year: Int = 0,
22 | val online_max_threshold: List = listOf(),
23 | val online_min_threshold: List = listOf(),
24 | val protocol_reward_rate: List = listOf(),
25 | val protocol_treasury_account: String = "",
26 | val protocol_upgrade_stake_threshold: List = listOf(),
27 | val protocol_version: Int = 0,
28 | val runtime_config: RuntimeConfig? = null,
29 | val transaction_validity_period: Int = 0
30 | )
31 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/RuntimeConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class RuntimeConfig(
4 | val account_creation_config: AccountCreationConfig,
5 | val storage_amount_per_byte: String,
6 | val transaction_costs: TransactionCosts,
7 | val wasm_config: WasmConfig
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/StakeCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class StakeCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/StorageUsageConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class StorageUsageConfig(
4 | val num_bytes_account: Int,
5 | val num_extra_bytes_record: Int
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/TransactionCosts.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class TransactionCosts(
4 | val action_creation_config: ActionCreationConfig,
5 | val action_receipt_creation_config: ActionReceiptCreationConfig,
6 | val burnt_gas_reward: List,
7 | val data_receipt_creation_config: DataReceiptCreationConfig,
8 | val pessimistic_gas_price_inflation_ratio: List,
9 | val storage_usage_config: StorageUsageConfig
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/TransferCost.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class TransferCost(
4 | val execution: Long,
5 | val send_not_sir: Long,
6 | val send_sir: Long
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/protocolconfig/WasmConfig.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.protocolconfig
2 |
3 | data class WasmConfig(
4 | val ext_costs: ExtCosts,
5 | val grow_mem_cost: Int,
6 | val limit_config: LimitConfig,
7 | val regular_op_cost: Int
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Actions.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Actions (
7 |
8 | @SerializedName("Transfer" ) var Transfer : Transfer? = Transfer()
9 |
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Metadata.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Metadata (
7 |
8 | @SerializedName("gas_profile") var gasProfile : List = listOf(""),
9 | @SerializedName("version") var version : Int = 0
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Outcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Outcome (
7 |
8 | @SerializedName("executor_id") var executorId : String? = null,
9 | @SerializedName("gas_burnt") var gasBurnt : Long? = null,
10 | @SerializedName("logs") var logs : ArrayList = arrayListOf(),
11 | @SerializedName("metadata") var metadata : Metadata? = Metadata(),
12 | @SerializedName("receipt_ids") var receiptIds : ArrayList = arrayListOf(),
13 | @SerializedName("status") var status : Status? = Status(),
14 | @SerializedName("tokens_burnt") var tokensBurnt : String? = null
15 |
16 | )
17 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/ReceiptsOutcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class ReceiptsOutcome (
7 |
8 | @SerializedName("block_hash") var blockHash : String? = null,
9 | @SerializedName("id") var id : String? = null,
10 | @SerializedName("outcome") var outcome : Outcome? = Outcome(),
11 | //@SerializedName("proof") var proof : ArrayList = arrayListOf()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Result (
7 |
8 | @SerializedName("receipts_outcome") var receiptsOutcome : ArrayList = arrayListOf(),
9 | @SerializedName("status") var status : Status = Status(),
10 | @SerializedName("transaction") var transaction : Transaction = Transaction(),
11 | //@SerializedName("transaction_outcome") var transactionOutcome : TransactionOutcome? = TransactionOutcome()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/SendMoney.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 |
9 | data class SendMoney (
10 |
11 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
12 | @SerializedName("result") var result : Result = Result(),
13 | @SerializedName("id") var id : String? = null,
14 | @SerializedName("error") var error: ErrorResponse? = null
15 | ) {
16 | companion object {
17 | @JvmStatic
18 | @JvmName("create")
19 | fun Response.toSendMoney() : SendMoney {
20 | if(this.isSuccessful) {
21 | val gson = Gson()
22 | val jsonString = this.body!!.string()
23 | return gson.fromJson(jsonString, SendMoney::class.java)
24 | }
25 | return SendMoney()
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Status.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Status (
7 |
8 | @SerializedName("SuccessReceiptId" ) var SuccessReceiptId : String = ""
9 |
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Transaction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Transaction (
7 |
8 | @SerializedName("actions") var actions : ArrayList = arrayListOf(),
9 | @SerializedName("hash") var hash : String? = null,
10 | @SerializedName("nonce") var nonce : Long? = null,
11 | @SerializedName("public_key") var publicKey : String? = null,
12 | @SerializedName("receiver_id") var receiverId : String? = null,
13 | @SerializedName("signature") var signature : String? = null,
14 | @SerializedName("signer_id") var signerId : String? = null
15 |
16 | )
17 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/TransactionOutcome.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class TransactionOutcome (
7 |
8 | @SerializedName("block_hash" ) var blockHash : String? = null,
9 | @SerializedName("id") var id : String? = null,
10 | @SerializedName("outcome") var outcome : Outcome? = Outcome(),
11 | @SerializedName("proof") var proof : ArrayList = arrayListOf()
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/Transfer.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Transfer (
7 |
8 | @SerializedName("deposit" ) var deposit : String? = null
9 |
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/sendmoney/transactionstatus/TransactionStatus.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.sendmoney.transactionstatus
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import com.knear.android.provider.response.sendmoney.Result
7 | import okhttp3.Response
8 |
9 | data class TransactionStatus(
10 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
11 | @SerializedName("result") var result : Result = Result(),
12 | @SerializedName("id") var id : String? = null,
13 | @SerializedName("error") var error: ErrorResponse? = null
14 | ) {
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.getTransactionStatus() : TransactionStatus {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), TransactionStatus::class.java)
23 | }?: TransactionStatus()
24 | }
25 | return TransactionStatus()
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskey/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskey
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 |
6 | data class Result (
7 | @SerializedName("block_hash") var blockHash : String? = null,
8 | @SerializedName("block_height") var blockHeight : Long = 0L,
9 | @SerializedName("nonce") var nonce : Long = 0L,
10 | @SerializedName("permission") var permission : String? = null
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskey/ViewAccessKey.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskey
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import okhttp3.Response
5 | import com.google.gson.Gson
6 | import com.knear.android.provider.response.errorresponse.ErrorResponse
7 |
8 | open class ViewAccessKey (
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.toViewAccessKey() : ViewAccessKey {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ViewAccessKey::class.java)
22 | } ?: ViewAccessKey()
23 | }
24 | return ViewAccessKey()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/AccessKey.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | data class AccessKey(
4 | val nonce: Long,
5 | val permission: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/Cause.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | data class Cause(
4 | val receipt_hash: String,
5 | val tx_hash: String,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | data class Change(
4 | val cause: Cause,
5 | val change: ChangeX,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/ChangeX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | data class ChangeX(
4 | val access_key: AccessKey,
5 | val account_id: String,
6 | val public_key: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychangeall/ViewAccessKeyChangesAllResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychangeall
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewAccessKeyChangesAllResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 |
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toViewAccessKeyChangesAll() : ViewAccessKeyChangesAllResult {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), ViewAccessKeyChangesAllResult::class.java)
23 | }?: ViewAccessKeyChangesAllResult()
24 | }
25 | return ViewAccessKeyChangesAllResult()
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/AccessKey.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | data class AccessKey(
4 | val nonce: Long,
5 | val permission: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/Cause.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | data class Cause(
4 | val tx_hash: String,
5 | val type: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | data class Change(
4 | val cause: Cause,
5 | val change: ChangeX,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/ChangeX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | data class ChangeX(
4 | val access_key: AccessKey,
5 | val account_id: String,
6 | val public_key: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | data class Result(
4 | var block_hash: String? = null,
5 | var changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeychanges/ViewAccessKeyChangesResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeychanges
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | open class ViewAccessKeyChangesResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 |
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toViewAccessKeyChanges() : ViewAccessKeyChangesResult {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), ViewAccessKeyChangesResult::class.java)
23 | }?: ViewAccessKeyChangesResult()
24 | }
25 | return ViewAccessKeyChangesResult()
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeylist/AccessKey.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeylist
2 |
3 | data class AccessKey(
4 | val nonce: Long,
5 | val permission: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeylist/Key.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeylist
2 |
3 | data class Key(
4 | val access_key: AccessKey,
5 | val public_key: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeylist/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeylist
2 |
3 | data class Result(
4 | var block_hash: String? = null,
5 | var block_height: Long = 0L,
6 | var keys: List = listOf()
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccesskeylist/ViewAccessKeyList.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccesskeylist
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | open class ViewAccessKeyList (
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.toViewAccessKeyList() : ViewAccessKeyList {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ViewAccessKeyList::class.java)
22 | }?: ViewAccessKeyList()
23 | }
24 | return ViewAccessKeyList()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccount/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccount
2 |
3 | data class Result(
4 | val amount: String = "",
5 | val block_hash: String = "",
6 | val block_height: Int = 0,
7 | val code_hash: String = "",
8 | val locked: String = "",
9 | val storage_paid_at: Int = 0,
10 | val storage_usage: Int = 0
11 | )
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccount/ViewAccountResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccount
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewAccountResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.toViewAccount() : ViewAccountResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ViewAccountResult::class.java)
22 | }?: ViewAccountResult()
23 | }
24 | return ViewAccountResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccountchanges/Cause.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccountchanges
2 |
3 | data class Cause(
4 | val receipt_hash: String,
5 | val tx_hash: String,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccountchanges/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccountchanges
2 |
3 | data class Change(
4 | val cause: Cause,
5 | val change: ChangeX,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccountchanges/ChangeX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccountchanges
2 |
3 | data class ChangeX(
4 | val account_id: String,
5 | val amount: String,
6 | val code_hash: String,
7 | val locked: String,
8 | val storage_paid_at: Int,
9 | val storage_usage: Int
10 | )
11 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccountchanges/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccountchanges
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewaccountchanges/ViewAccountChangesResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewaccountchanges
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewAccountChangesResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 |
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toViewAccountChanges() : ViewAccountChangesResult {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), ViewAccountChangesResult::class.java)
23 | }?: ViewAccountChangesResult()
24 | }
25 | return ViewAccountChangesResult()
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcode/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcode
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val block_height: Int = 0,
6 | val code_base64: String = "",
7 | val hash: String = ""
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcode/ViewContractCodeResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcode
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewContractCodeResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.toViewContractCode() : ViewContractCodeResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ViewContractCodeResult::class.java)
22 | }?: ViewContractCodeResult()
23 | }
24 | return ViewContractCodeResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcodechanges/Cause.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcodechanges
2 |
3 | data class Cause(
4 | val receipt_hash: String,
5 | val type: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcodechanges/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcodechanges
2 |
3 | data class Change(
4 | val cause: Cause,
5 | val change: ChangeX,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcodechanges/ChangeX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcodechanges
2 |
3 | data class ChangeX(
4 | val account_id: String,
5 | val code_base64: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcodechanges/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcodechanges
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractcodechanges/ViewContractCodeChangesResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractcodechanges
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewContractCodeChangesResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 |
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toViewContractCodeChanges() : ViewContractCodeChangesResult {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), ViewContractCodeChangesResult::class.java)
23 | }?: ViewContractCodeChangesResult()
24 | }
25 | return ViewContractCodeChangesResult()
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstate/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstate
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val block_height: Int = 0,
6 | val proof: List = listOf(),
7 | val values: List = listOf()
8 | )
9 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstate/Value.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstate
2 |
3 | data class Value(
4 | val key: String,
5 | val proof: List,
6 | val value: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstate/ViewContractStateResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstate
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewContractStateResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 | companion object {
15 | @JvmStatic
16 | @JvmName("create")
17 | fun Response.toViewContractState() : ViewContractStateResult {
18 | val gson = Gson()
19 | if(this.isSuccessful) {
20 | this.body?.let {
21 | return gson.fromJson(it.string(), ViewContractStateResult::class.java)
22 | }?: ViewContractStateResult()
23 | }
24 | return ViewContractStateResult()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstatechanges/Cause.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstatechanges
2 |
3 | data class Cause(
4 | val receipt_hash: String,
5 | val type: String
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstatechanges/Change.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstatechanges
2 |
3 | data class Change(
4 | val cause: Cause,
5 | val change: ChangeX,
6 | val type: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstatechanges/ChangeX.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstatechanges
2 |
3 | data class ChangeX(
4 | val account_id: String,
5 | val key_base64: String,
6 | val value_base64: String
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstatechanges/Result.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstatechanges
2 |
3 | data class Result(
4 | val block_hash: String = "",
5 | val changes: List = listOf()
6 | )
7 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/provider/response/viewcontractstatechanges/ViewContractStateChangesResult.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.provider.response.viewcontractstatechanges
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.annotations.SerializedName
5 | import com.knear.android.provider.response.errorresponse.ErrorResponse
6 | import okhttp3.Response
7 |
8 | data class ViewContractStateChangesResult(
9 | @SerializedName("jsonrpc") var jsonrpc : String? = null,
10 | @SerializedName("result") var result : Result = Result(),
11 | @SerializedName("id") var id : String? = null,
12 | @SerializedName("error") var error: ErrorResponse? = null
13 | ) {
14 |
15 | companion object {
16 | @JvmStatic
17 | @JvmName("create")
18 | fun Response.toViewContractStateChanges() : ViewContractStateChangesResult {
19 | val gson = Gson()
20 | if(this.isSuccessful) {
21 | this.body?.let {
22 | return gson.fromJson(it.string(), ViewContractStateChangesResult::class.java)
23 | }?: ViewContractStateChangesResult()
24 | }
25 | return ViewContractStateChangesResult()
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/KeyPair.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | open class KeyPair {
4 | companion object {
5 | fun fromRandom(curve: String) : KeyPairEd25519 {
6 | when(curve.uppercase()) {
7 | "ED25519" -> return KeyPairEd25519.fromRandom()
8 | else -> {
9 | throw Error("Unknown curve $curve")
10 | }
11 | }
12 | }
13 |
14 | fun removeKeyType(encodedKey: String) : String {
15 | val parts: List = encodedKey.split(':')
16 | when (parts.size) {
17 | 1 -> {
18 | return parts[0]
19 | }
20 | 2 -> {
21 | when (parts[0].uppercase()) {
22 | "ED25519" -> return parts[1]
23 | else -> {
24 | throw Error("Unknown curve $parts[0]")
25 | }
26 | }
27 | }
28 | else -> {
29 | throw Error("Invalid encoded key format, must be :")
30 | }
31 | }
32 | }
33 |
34 | fun fromString(encodedSecretKey: String, encodedPublicKey: String) : KeyPairEd25519 {
35 | val parts: List = encodedSecretKey.split (':')
36 | when (parts.size) {
37 | 1 -> {
38 | return KeyPairEd25519(parts[0], encodedPublicKey)
39 | }
40 | 2 -> {
41 | when(parts[0].uppercase()) {
42 | "ED25519" -> return KeyPairEd25519(parts[1], encodedPublicKey)
43 | else -> {
44 | throw Error("Unknown curve $parts[0]")
45 | }
46 | }
47 | }
48 | else -> {
49 | throw Error("Invalid encoded key format, must be :")
50 | }
51 | }
52 | }
53 |
54 | fun fromStringKeyPair(secretKeyEncoded: String, publicKeyEncoded : String) : KeyPairEd25519 {
55 | val keyPair = KeyPairEd25519(removeKeyType(secretKeyEncoded), removeKeyType(publicKeyEncoded))
56 | return keyPair
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/KeyPairEd25519.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | import com.iwebpp.crypto.TweetNaclFast
4 | import com.syntifi.crypto.key.Ed25519PrivateKey
5 | import com.syntifi.crypto.key.encdec.Base58
6 |
7 | class KeyPairEd25519 (ed25519SecretKey: String, ed25519PublicKey: String) : KeyPair() {
8 | var publicKey: PublicKey
9 | private var secretKey: String
10 | private var data: ByteArray
11 |
12 | init {
13 | val publicKeyAsBytes = Base58.decode(ed25519PublicKey)
14 | this.data = Base58.decode(ed25519SecretKey)
15 | this.publicKey = PublicKey(KeyType.ED25519, publicKeyAsBytes )
16 | this.secretKey = ed25519SecretKey
17 | }
18 |
19 | companion object {
20 | fun fromRandom() : KeyPairEd25519 {
21 | val keyPair = TweetNaclFast.Signature.keyPair();
22 |
23 | val encodedSecret = Base58.encode(keyPair.secretKey)
24 | val encodedPublic = Base58.encode(keyPair.publicKey)
25 | return KeyPairEd25519(encodedSecret, encodedPublic)
26 | }
27 | }
28 |
29 | fun sign(message: ByteArray): ByteArray {
30 | var privateKey = Ed25519PrivateKey(this.data);
31 | return privateKey.sign(message)
32 | /*
33 | val signature = TweetNaclFast.Signature(this.publicKey.data, decodedPrivateKey)
34 | var signedMsg = signature.detached(message)
35 | return signedMsg*/
36 | }
37 |
38 | fun verify(message: ByteArray, signature: ByteArray): Boolean {
39 | val twSignature = TweetNaclFast.Signature(this.publicKey.data, this.data)
40 |
41 | return twSignature.detached_verify(message, signature)
42 | }
43 |
44 | override fun toString() : String {
45 | return "ed25519:${this.secretKey}"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/KeyType.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | enum class KeyType {
4 | ED25519
5 | }
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/PublicKey.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | import com.syntifi.crypto.key.encdec.Base58
4 | import com.syntifi.near.borshj.Borsh
5 | import com.syntifi.near.borshj.annotation.BorshField
6 |
7 | class PublicKey (kType: KeyType, publicKey: ByteArray ) : Borsh {
8 | @BorshField(order = 1)
9 | var keyType: KeyType = kType
10 | @BorshField(order = 2)
11 | var data: ByteArray = publicKey
12 |
13 | companion object {
14 | private fun strToKeyType(value: String) : KeyType {
15 | return when(value.lowercase()) {
16 | "ed25519" -> KeyType.ED25519
17 | else -> {
18 | throw Error("Unknown key type $value")
19 | }
20 | }
21 | }
22 |
23 | fun fromString(encodedKey: String) : PublicKey {
24 | val parts: List = encodedKey.split(':')
25 | return when (parts.size) {
26 | 1 -> {
27 | val decodedPublicKey = Base58.decode(parts[0])
28 | PublicKey(KeyType.ED25519, decodedPublicKey)
29 | }
30 | 2 -> {
31 | val decodedPublicKey = Base58.decode(parts[1])
32 | PublicKey(strToKeyType(parts[0]), decodedPublicKey)
33 | }
34 | else -> {
35 | throw Error("Invalid encoded key format, must be :")
36 | }
37 | }
38 | }
39 | }
40 |
41 | private fun keyTypeToStr(kType: KeyType) : String{
42 | when(kType) {
43 | KeyType.ED25519 -> return "ed25519"
44 | else -> {
45 | throw Error("Unknown key type $kType")
46 | }
47 | }
48 | }
49 |
50 | override fun toString(): String {
51 | val publicKey = Base58.encode(this.data)
52 | return "${this.keyTypeToStr(this.keyType)}:${publicKey}"
53 | }
54 | /*
55 | fun verify(message: ByteArray, signature: ByteArray): Boolean {
56 | when(this.keyType) {
57 | KeyType.ED25519 -> {
58 | val twSignature = TweetNaclFast.Signature(this.data, )
59 | return twSignature.detached_verify(message, signature)
60 | }
61 | else -> {
62 | throw Error("Unknown key type ${this.keyType}")
63 | }
64 | }
65 | }
66 | */
67 | }
68 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/Signature.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | import com.syntifi.crypto.key.encdec.Base58
4 | import com.syntifi.near.borshj.Borsh
5 | import com.syntifi.near.borshj.annotation.BorshField
6 |
7 |
8 | class Signature (
9 | @BorshField(order = 1)
10 | var type: KeyType,
11 | @BorshField(order = 2)
12 | var data: ByteArray
13 | ) : Borsh {
14 | override fun toString(): String {
15 | return Base58.encode(data)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/SignedTransaction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | import com.syntifi.near.borshj.Borsh
4 | import com.syntifi.near.borshj.annotation.BorshField
5 |
6 | class SignedTransaction(
7 | @BorshField(order = 1)
8 | val transaction: Transaction,
9 | @BorshField(order = 2)
10 | val signature: Signature
11 | ) : Borsh
12 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/Transaction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme
2 |
3 | import com.knear.android.scheme.action.Action
4 | import com.syntifi.near.borshj.Borsh
5 | import com.syntifi.near.borshj.annotation.BorshField
6 |
7 | open class Transaction (
8 | @BorshField(order = 1)
9 | var signerId: String,
10 | @BorshField(order = 2)
11 | var publicKey: PublicKey,
12 | @BorshField(order = 3)
13 | var nonce: Long,
14 | @BorshField(order = 4)
15 | var receiverId: String,
16 | @BorshField(order = 5)
17 | var blockHash : ByteArray,
18 | @BorshField(order = 6)
19 | var actions: Collection,
20 | ) : Borsh
21 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/Action.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | import com.syntifi.near.borshj.Borsh
4 | import com.syntifi.near.borshj.annotation.BorshSubTypes
5 |
6 | @BorshSubTypes(
7 | BorshSubTypes.BorshSubType(`when` = Action.CREATE_ACCOUNT.toInt(), `use` = CreateAccountAction::class),
8 | BorshSubTypes.BorshSubType(`when` = Action.DEPLOY_CONTRACT.toInt(), use = DeployContractAction::class),
9 | BorshSubTypes.BorshSubType(`when` = Action.FUNCTION_CALL.toInt(), use = FunctionCallAction::class),
10 | BorshSubTypes.BorshSubType(`when` = Action.STAKE.toInt(), use = StakeAction::class),
11 | BorshSubTypes.BorshSubType(`when` = Action.ADD_KEY.toInt(), use = AddKeyAction::class),
12 | BorshSubTypes.BorshSubType(`when` = Action.DELETE_KEY.toInt(), use = DeleteKeyAction::class),
13 | BorshSubTypes.BorshSubType(`when` = Action.DELETE_ACCOUNT.toInt(), use = DeleteAccountAction::class),
14 | BorshSubTypes.BorshSubType(`when` = Action.TRANSFER.toInt(), `use` = TransferAction::class)
15 | )
16 | open interface Action : Borsh {
17 | companion object {
18 | const val CREATE_ACCOUNT: Byte = 0
19 | const val DEPLOY_CONTRACT: Byte = 1
20 | const val FUNCTION_CALL: Byte = 2
21 | const val TRANSFER: Byte = 3
22 | const val STAKE: Byte = 4
23 | const val ADD_KEY: Byte = 5
24 | const val DELETE_KEY: Byte = 6
25 | const val DELETE_ACCOUNT: Byte = 7
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/AddKeyAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | class AddKeyAction(
4 | private var nonce: Long
5 | ) : Action
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/CreateAccountAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | open class CreateAccountAction : Action {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/DeleteAccountAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | class DeleteAccountAction(
4 | private var beneficiaryId: String
5 | ) : Action
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/DeleteKeyAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | import com.knear.android.scheme.PublicKey
4 |
5 | class DeleteKeyAction(
6 | private var publicKey: PublicKey
7 | ) : Action
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/DeployContractAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | open class DeployContractAction(
4 | private var code: Byte
5 | ) : Action
6 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/FunctionCallAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | import com.syntifi.near.borshj.annotation.BorshField
4 | import java.math.BigInteger
5 |
6 | class FunctionCallAction(
7 | @BorshField(order = 1)
8 | private val methodName: String,
9 | @BorshField(order = 2)
10 | private val args: String,
11 | @BorshField(order = 3)
12 | private val gas: Long,
13 | @BorshField(order = 4)
14 | private val depositValue: BigInteger,
15 | ): Action
16 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/StakeAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | import com.knear.android.scheme.PublicKey
4 | import java.math.BigInteger
5 |
6 | class StakeAction(
7 | private var stake: BigInteger,
8 | private var publicKey: PublicKey
9 | ) : Action
10 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/scheme/action/TransferAction.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.scheme.action
2 |
3 | import com.syntifi.near.borshj.annotation.BorshField
4 | import java.math.BigInteger
5 |
6 | open class TransferAction(
7 | @BorshField(order = 1)
8 | private val depositValue: BigInteger
9 | ) : Action
10 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/service/Account.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.service
2 |
3 | import com.knear.android.provider.JsonRpcProvider
4 | import com.knear.android.provider.model.NearRequestParams
5 | import com.knear.android.provider.response.functioncall.FunctionCallResponse
6 | import com.knear.android.provider.response.functioncall.FunctionCallResponse.Companion.toFunctionCallResponse
7 | import com.knear.android.scheme.*
8 | import com.knear.android.provider.response.functioncall.transaction.FunctionCallTransactionResponse
9 | import com.knear.android.provider.response.functioncall.transaction.FunctionCallTransactionResponse.Companion.toFunctionCallTransactionResponse
10 | import com.knear.android.provider.response.sendmoney.SendMoney
11 | import com.knear.android.provider.response.sendmoney.SendMoney.Companion.toSendMoney
12 | import com.knear.android.scheme.action.Action
13 | import com.knear.android.scheme.action.FunctionCallAction
14 | import com.knear.android.scheme.action.TransferAction
15 | import com.knear.android.service.MethodUtils.Companion.convertAmountForSendingNear
16 | import com.syntifi.crypto.key.encdec.Base58
17 | import com.syntifi.crypto.key.hash.Sha256
18 | import com.syntifi.near.borshj.Borsh
19 | import okhttp3.Response
20 | import java.util.*
21 |
22 | class Account( private var accountId: String, private var networkId: String, private var rcpEndpoint: String, private var keyPair: KeyPairEd25519) {
23 | private val jsonRpc: JsonRpcProvider = JsonRpcProvider(rcpEndpoint)
24 |
25 |
26 | fun sendMoney(receiverId: String, amount: String): SendMoney {
27 | val actions = listOf(TransferAction(amount.convertAmountForSendingNear()))
28 | val response = this.signAndSendTransaction(receiverId, actions, "broadcast_tx_commit")
29 | return response?.toSendMoney()?: SendMoney()
30 | }
31 |
32 | private fun signAndSendTransaction(receiverId: String, actions: Collection, method: String): Response? {
33 | var signedTransaction = signTransaction(receiverId, actions)
34 |
35 | val borshTx = Borsh.serialize(signedTransaction)
36 | val params = listOf(Base64.getEncoder().encodeToString(borshTx))
37 |
38 | val signatureTx = Borsh.serialize(signedTransaction.signature)
39 | val transactionTx = Borsh.serialize(signedTransaction.transaction)
40 | val transactionActions = Borsh.serialize(signedTransaction.transaction.actions.elementAt(0))
41 |
42 | return jsonRpc.sendTransaction(method, params)
43 | }
44 |
45 | private fun signTransaction(
46 | receiverId: String,
47 | actions: Collection
48 | ): SignedTransaction {
49 | val account = jsonRpc.viewAccessKey(accountId, keyPair.publicKey.toString())
50 | val block = jsonRpc.block()
51 |
52 | val nonce = account.result.nonce
53 | val headerHash = Base58.decode(block.result.header.hash)
54 |
55 | val nextNonce = nonce + 1L
56 | val pubKey = this.keyPair.publicKey
57 |
58 | val transaction = Transaction(
59 | accountId,
60 | pubKey,
61 | nextNonce,
62 | receiverId,
63 | headerHash,
64 | actions,
65 | );
66 |
67 | val serializedTx: ByteArray = Borsh.serialize(transaction)
68 | val hashedTx: ByteArray = Sha256.digest(serializedTx)
69 | val signedTx: ByteArray = this.keyPair.sign(hashedTx)
70 |
71 | val serializedbase64 = Base64.getEncoder().encodeToString(serializedTx)
72 | val valid = this.keyPair.verify(hashedTx, signedTx )
73 |
74 | return SignedTransaction(
75 | transaction,
76 | Signature(KeyType.ED25519, signedTx)
77 | )
78 | }
79 |
80 | fun functionCallTransaction(contractId: String, methodName: String, args: String, gas: Long, attachedDeposit: String) : FunctionCallTransactionResponse {
81 |
82 | val actions: List = if (methodName == "near_withdraw"){
83 | listOf(FunctionCallAction(methodName, args, gas, attachedDeposit.toBigInteger()))
84 | } else {
85 | listOf(FunctionCallAction(methodName, args, gas, attachedDeposit.convertAmountForSendingNear()))
86 | }
87 |
88 | val response = this.signAndSendTransaction(contractId, actions, "broadcast_tx_commit")
89 | return response?.toFunctionCallTransactionResponse()?: FunctionCallTransactionResponse();
90 | }
91 |
92 | fun functionCall(contractId: String, methodName: String, args: String) : FunctionCallResponse {
93 | val encodedArgs = Base64.getEncoder().encodeToString(args.toByteArray())
94 | val block = jsonRpc.block()
95 |
96 | var requestParams = NearRequestParams(
97 | requestType = "call_function",
98 | blockId = block.result.header.hash,
99 | accountId = contractId,
100 | methodName = methodName,
101 | argsBase64 = encodedArgs
102 | )
103 | val response = this.jsonRpc.sendJsonRpc("query", requestParams);
104 | return response?.toFunctionCallResponse()?: FunctionCallResponse();
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/service/AndroidKeyStore.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.service
2 |
3 | import android.app.Activity
4 | import android.content.SharedPreferences
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.knear.android.scheme.KeyPair
7 | import com.knear.android.scheme.KeyPairEd25519
8 |
9 |
10 | class AndroidKeyStore(activityContext: Activity) {
11 | private val activityContext = activityContext
12 | private val editor: SharedPreferences.Editor
13 |
14 | init {
15 | getSharedPreference().edit().also { this.editor = it }
16 | }
17 |
18 | private fun getSharedPreference(): SharedPreferences {
19 | return activityContext.getSharedPreferences("NearAndroidKeystore", AppCompatActivity.MODE_PRIVATE)
20 | }
21 |
22 | fun setAccountId(accountId: String) {
23 | editor.putString("accountId", accountId)
24 | editor.commit()
25 | }
26 |
27 | fun getAccountId() : String? {
28 | return this.getSharedPreference().getString("accountId", "")
29 | }
30 |
31 | fun setNetworkId(networkId: String) {
32 | editor.putString("networkId", networkId)
33 | editor.commit()
34 | }
35 |
36 | fun getNetworkId(): String? {
37 | return this.getSharedPreference().getString("networkId", "")
38 | }
39 |
40 | fun setKey(networkId: String, accountId: String, secretKey: KeyPairEd25519) {
41 | editor.putString("$accountId:$networkId", secretKey.toString())
42 | editor.putString("$accountId:$networkId:public", secretKey.publicKey.toString())
43 | editor.commit()
44 | }
45 |
46 | fun getKey(networkId: String, accountId: String) : KeyPairEd25519? {
47 | val secretKey = getSharedPreference().getString("$accountId:$networkId", "")
48 | val publicKey = getSharedPreference().getString("$accountId:$networkId:public", "")
49 | if(secretKey.isNullOrEmpty()) {
50 | return null
51 | }
52 |
53 | if(publicKey.isNullOrEmpty()) {
54 | return null
55 | }
56 |
57 | return KeyPair.fromStringKeyPair(secretKey, publicKey)
58 | }
59 |
60 | fun removeKey(networkId: String, accountId: String) {
61 | editor.remove("$accountId:$networkId")
62 | editor.remove("$accountId:$networkId:public")
63 | editor.commit()
64 | }
65 |
66 | fun clear() {
67 | editor.clear()
68 | editor.commit()
69 | }
70 |
71 | override fun toString(): String {
72 | return "AndroidKeyStore"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/service/MethodUtils.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.service
2 |
3 | import com.google.gson.Gson
4 | import java.math.BigDecimal
5 | import java.math.BigInteger
6 |
7 | class MethodUtils {
8 |
9 | companion object {
10 |
11 | fun String.convertAmountForSendingNear() : BigInteger {
12 | val inputNear = this.toBigDecimal()
13 | val constValueInBI = StringUtils.HARD_CODED_FOR_CONVERTING_NEAR_VALUE.toBigDecimal()
14 | return (inputNear * constValueInBI).toBigInteger()
15 | }
16 |
17 | fun String.convertNearToAmount() : Float {
18 | val inputNear = this.toFloat()
19 | val constValueInBI = StringUtils.HARD_CODED_FOR_CONVERTING_NEAR_VALUE.toFloat()
20 | return (inputNear / constValueInBI)
21 | }
22 |
23 | fun ByteArray.getDecodedAsciiValue() : String {
24 | if (this !== null) {
25 | /**
26 | * Near returns an array of bytes as result, is an ASCII code of
27 | * near-sdk-rs and near-sdk-as
28 | */
29 | var unsignedToBytes: List = this.map { byte: Byte -> (byte.toInt() and 0xff).toByte() }
30 | val asciiValueBytes = unsignedToBytes.toByteArray()
31 | val stringValue = asciiValueBytes.toString(Charsets.US_ASCII);
32 | // Deserialized as string
33 | return Gson().fromJson(stringValue, String::class.java)
34 | }
35 | return ""
36 | }
37 |
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/service/NearMainService.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.service
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.net.Uri
6 | import androidx.lifecycle.LifecycleOwner
7 | import androidx.lifecycle.ViewModelProvider
8 | import androidx.lifecycle.ViewModelStoreOwner
9 | import com.knear.android.NearService
10 | import com.knear.android.scheme.KeyPair
11 | import com.knear.android.scheme.KeyPairEd25519
12 | import com.knear.android.user.NearUserInformationListener
13 | import com.knear.android.user.domain.model.UserInformation
14 | import com.knear.android.user.view.NearUserViewModel
15 | import com.knear.android.user.view.NearUserViewModelFactory
16 |
17 | class NearMainService(
18 | private val activity: Activity,
19 | lifecycleOwner: ViewModelStoreOwner,
20 | private val nearUserInformationListener: NearUserInformationListener?
21 | ) {
22 |
23 | private var networkId = "wallet.near.org"
24 | private var accountId: String = ""
25 | private val walletUrl = "https://wallet.near.org/login/"
26 | private val rpcEndpoint = "https://rpc.mainnet.near.org"
27 | private val redirectUri = "near://success-auth"
28 |
29 | private var allKeys: String = ""
30 | private var publicKey: String = ""
31 |
32 | private val nearUserViewModel =
33 | ViewModelProvider(lifecycleOwner, NearUserViewModelFactory(activity.application))[NearUserViewModel::class.java]
34 |
35 | private var nearService : NearService = NearService(walletUrl, rpcEndpoint, activity)
36 | private var privateKey: KeyPairEd25519 = KeyPairEd25519("","")
37 | private var androidKeyStore: AndroidKeyStore = AndroidKeyStore(activity)
38 |
39 | fun login(email:String){
40 | this.androidKeyStore.setAccountId(email)
41 | this.androidKeyStore.setNetworkId(networkId)
42 |
43 | val networkId = androidKeyStore.getNetworkId()
44 | val accountId = androidKeyStore.getAccountId();
45 |
46 | if(!networkId.isNullOrEmpty() && !accountId.isNullOrEmpty()) {
47 | this.accountId = accountId
48 | this.networkId = networkId
49 | }
50 | this.privateKey = KeyPair.fromRandom("ed25519")
51 | loginOAuth()
52 | }
53 | private fun loginOAuth() {
54 | val loggingUri = this.nearService.startLogin(this.privateKey.publicKey, redirectUri)
55 |
56 | this.androidKeyStore.setAccountId(accountId)
57 | this.androidKeyStore.setNetworkId(networkId)
58 | this.androidKeyStore.setKey(networkId, accountId, this.privateKey)
59 | val intent = Intent(Intent.ACTION_VIEW, loggingUri)
60 | activity.startActivity(intent)
61 | }
62 | fun attemptLogin(uri: Uri?):Boolean {
63 | var success = false
64 | uri?.let {
65 | if (it.toString().startsWith(redirectUri)) {
66 | val currentAccountId = uri.getQueryParameter("account_id")
67 | val currentPublicKey = uri.getQueryParameter("public_key")
68 | val currentKeys = uri.getQueryParameter("all_keys")
69 |
70 | if (!currentAccountId.isNullOrEmpty() && !currentKeys.isNullOrEmpty() && !currentPublicKey.isNullOrEmpty()) {
71 | accountId = currentAccountId
72 | allKeys = currentKeys
73 | publicKey = currentPublicKey
74 |
75 | androidKeyStore.getKey(networkId, accountId)?.let { this.privateKey = it
76 |
77 | this.nearService.finishLogging(networkId, this.privateKey, accountId)
78 | success = true
79 | }
80 | }
81 | }
82 | }
83 |
84 | if (success){
85 | saveUserSession()
86 | }
87 |
88 | return success
89 | }
90 | fun logout(){
91 | removeUserSession()
92 | }
93 | fun sendTransaction(receiver: String, amount: String) = this.nearService.sendMoney(accountId, receiver, amount)
94 | fun callViewFunction(
95 | contractName: String,
96 | methodName: String,
97 | totalSupplyArgs: String
98 | ) = nearService.callViewFunction(accountId = accountId,contractName = contractName, methodName = methodName, args = totalSupplyArgs)
99 | fun callViewFunctionTransaction(contractName: String, methodName: String, balanceOfArgs: String) =
100 | nearService.callViewFunctionTransaction(accountId, contractName, methodName, balanceOfArgs)
101 | fun callFunctionSwapNearToWNear(attachedDeposit:String) =
102 | nearService.callViewFunctionTransaction(accountId, "wrap.near", "near_deposit", "{}", attachedDeposit = attachedDeposit)
103 | fun callFunctionSwapWNearToNear(arguments:String, attachedDeposit: String) =
104 | nearService.callViewFunctionTransaction(accountId, "wrap.near", "near_withdraw", args = arguments, attachedDeposit = attachedDeposit)
105 | fun viewAccessKey() = nearService.viewAccessKey(accountId)
106 | fun viewAccessKeyLists() = nearService.viewAccessKeyList(accountId)
107 | fun viewAccessKeyChangesAll(accountIdList:List) = nearService.viewAccessKeyChangeAll(accountIdList,publicKey)
108 | fun viewAccessKeyChange(currentAccessKey:String) = nearService.viewAccessKeyChange(accountId, currentAccessKey)
109 | fun transactionStatus(txResultHash:String) = nearService.transactionStatus(txResultHash, accountId)
110 | fun viewAccount() = nearService.viewAccount(accountId)
111 | fun viewAccountChanges(accountIdList: List, blockId:Int) = nearService.viewAccountChanges(accountIdList, blockId)
112 | fun viewContractCode() = nearService.viewContractCode(accountId)
113 | fun viewContractState() = nearService.viewContractState(accountId)
114 | fun viewContractStateChanges(accountIdList: List, keyPrefix:String, blockId:Int) = nearService.viewContractStateChanges(accountIdList, keyPrefix, blockId)
115 | fun viewContractCodeChanges(accountIdList: List, blockId:Int) = nearService.viewContractCodeChanges(accountIdList, blockId)
116 | fun getBlockDetails(blockId: Int) = nearService.blockDetails(blockId)
117 | fun getBlockChanges(blockId: Int) = nearService.blockChanges(blockId)
118 | fun getChunkHash(chunksHash:String) = nearService.chunkDetails(chunksHash)
119 | fun gasPrice(blockId: Int) = nearService.gasPrice(blockId)
120 | fun getGenesisConfiguration() = nearService.getGenesisConfig()
121 | fun getProtocolConfig() = nearService.getProtocolConfig()
122 | fun getNetworkStatus() = nearService.getNetworkStatus()
123 | private fun saveUserSession() {
124 | nearUserViewModel.saveUserInformation(
125 | UserInformation(
126 | accountId = accountId,
127 | publicKey = publicKey,
128 | isLoggedIn = true
129 | )
130 | )
131 | }
132 |
133 | fun getUserInformation() {
134 | nearUserViewModel.getAllUsers.observe(activity as LifecycleOwner) { userList ->
135 | userList.map {
136 | accountId = it.accountId
137 | nearUserInformationListener?.userInformationResponse(
138 | UserInformation(
139 | it.accountId,
140 | it.publicKey,
141 | it.isLoggedIn)
142 | )
143 | }
144 | }
145 | }
146 |
147 | private fun removeUserSession() {
148 | nearUserViewModel.removeUserInformation()
149 | }
150 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/service/StringUtils.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.service
2 |
3 | class StringUtils {
4 |
5 | companion object {
6 | const val HARD_CODED_FOR_CONVERTING_NEAR_VALUE = "1000000000000000000000000"
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/NearUserInformationListener.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user
2 |
3 | import com.knear.android.user.domain.model.UserInformation
4 |
5 | interface NearUserInformationListener {
6 |
7 | fun userInformationResponse(userInformation: UserInformation)
8 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/data/dao/UserDao.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.data.dao
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Insert
5 | import androidx.room.OnConflictStrategy
6 | import androidx.room.Query
7 | import com.knear.android.user.data.entities.UserInformationEntity
8 | import kotlinx.coroutines.flow.Flow
9 |
10 | @Dao
11 | interface UserDao {
12 |
13 | @Query("SELECT * FROM user_information ORDER BY accountId ASC")
14 | fun getUserInformation(): Flow>
15 |
16 | @Insert(onConflict = OnConflictStrategy.REPLACE)
17 | suspend fun saveUserInformation(userInformation: UserInformationEntity)
18 |
19 | @Query("DELETE FROM user_information")
20 | suspend fun deleteAll():Unit
21 |
22 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/data/database/NearDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.data.database
2 |
3 | import android.app.Application
4 | import androidx.room.Database
5 | import androidx.room.Room
6 | import androidx.room.RoomDatabase
7 | import com.knear.android.user.data.dao.UserDao
8 | import com.knear.android.user.data.entities.UserInformationEntity
9 |
10 | // Annotates class to be a Room Database with a table (entity) of the Word class
11 | @Database(entities = arrayOf(UserInformationEntity::class), version = 1, exportSchema = false)
12 | abstract class NearDatabase : RoomDatabase() {
13 |
14 | abstract fun userDao(): UserDao
15 |
16 | companion object {
17 | // Singleton prevents multiple instances of database opening at the
18 | // same time.
19 | @Volatile
20 | private var INSTANCE: NearDatabase? = null
21 |
22 | fun getDatabase(application: Application): NearDatabase {
23 | // if the INSTANCE is not null, then return it,
24 | // if it is, then create the database
25 | return INSTANCE ?: synchronized(this) {
26 | val instance = Room.databaseBuilder(
27 | application,
28 | NearDatabase::class.java,
29 | "near_wallet_database"
30 | ).build()
31 | INSTANCE = instance
32 | // return instance
33 | instance
34 | }
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/data/entities/UserInformationEntity.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.data.entities
2 |
3 | import androidx.room.ColumnInfo
4 | import androidx.room.Entity
5 | import androidx.room.PrimaryKey
6 |
7 | @Entity(tableName = "user_information")
8 | data class UserInformationEntity(
9 | @PrimaryKey(autoGenerate = true) val id:Int = 0,
10 | @ColumnInfo(name = "accountId") val accountId:String,
11 | @ColumnInfo(name = "publicKey") val publicKey:String,
12 | @ColumnInfo(name = "isLoggedIn") val isLoggedIn:Boolean
13 | )
14 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/data/repositories/UserSessionRepository.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.data.repositories
2 |
3 | import android.app.Application
4 | import androidx.annotation.WorkerThread
5 | import com.knear.android.user.data.database.NearDatabase
6 | import com.knear.android.user.data.entities.UserInformationEntity
7 | import com.knear.android.user.domain.model.UserInformation
8 | import kotlinx.coroutines.flow.Flow
9 |
10 | // Declares the DAO as a private property in the constructor. Pass in the DAO
11 | // instead of the whole database, because you only need access to the DAO
12 | class UserSessionRepository(application: Application) {
13 |
14 | private val nearDatabase = NearDatabase.getDatabase(application)
15 | private val userDao = nearDatabase.userDao()
16 |
17 | // Room executes all queries on a separate thread.
18 | // Observed Flow will notify the observer when the data has changed.
19 | val getAllUsers: Flow> = userDao.getUserInformation()
20 |
21 | // By default Room runs suspend queries off the main thread, therefore, we don't need to
22 | // implement anything else to ensure we're not doing long running database work
23 | // off the main thread.
24 | @Suppress("RedundantSuspendModifier")
25 | @WorkerThread
26 | suspend fun saveUserSession(userInformation: UserInformation) {
27 | userDao.saveUserInformation(getUserInformationEntity(userInformation))
28 | }
29 |
30 | private fun getUserInformationEntity(userInformation: UserInformation) =
31 | UserInformationEntity(
32 | accountId = userInformation.accountId,
33 | publicKey = userInformation.publicKey,
34 | isLoggedIn = userInformation.isLoggedIn
35 | )
36 |
37 | suspend fun removeUserInformation() {
38 | userDao.deleteAll()
39 | }
40 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/domain/model/UserInformation.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.domain.model
2 |
3 | data class UserInformation(
4 | var accountId:String = "",
5 | var publicKey:String = "",
6 | var isLoggedIn:Boolean = false
7 | )
8 |
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/domain/usecase/GetAllUsersUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.domain.usecase
2 |
3 | import android.app.Application
4 | import com.knear.android.user.data.repositories.UserSessionRepository
5 |
6 | class GetAllUsersUseCase(application: Application) {
7 |
8 | private val nearUserRepository = UserSessionRepository(application)
9 |
10 | fun getAllUsers() = nearUserRepository.getAllUsers
11 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/domain/usecase/RemoveUserSessionUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.domain.usecase
2 |
3 | import android.app.Application
4 | import com.knear.android.user.data.repositories.UserSessionRepository
5 |
6 | class RemoveUserSessionUseCase(val application: Application) {
7 |
8 | private val nearUserRepository = UserSessionRepository(application)
9 |
10 | suspend fun removeUserInformation() {
11 | nearUserRepository.removeUserInformation()
12 | }
13 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/domain/usecase/SaveUserSessionUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.domain.usecase
2 |
3 | import android.app.Application
4 | import com.knear.android.user.data.repositories.UserSessionRepository
5 | import com.knear.android.user.domain.model.UserInformation
6 |
7 | class SaveUserSessionUseCase(val application: Application) {
8 |
9 | private val nearUserRepository = UserSessionRepository(application)
10 |
11 | suspend fun saveUserSession(userInformation: UserInformation) = nearUserRepository.saveUserSession(userInformation)
12 | }
--------------------------------------------------------------------------------
/knear-sdk/src/main/java/com/knear/android/user/view/NearUserViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.knear.android.user.view
2 |
3 | import android.app.Application
4 | import androidx.lifecycle.*
5 | import com.knear.android.user.data.entities.UserInformationEntity
6 | import com.knear.android.user.domain.model.UserInformation
7 | import com.knear.android.user.domain.usecase.GetAllUsersUseCase
8 | import com.knear.android.user.domain.usecase.RemoveUserSessionUseCase
9 | import com.knear.android.user.domain.usecase.SaveUserSessionUseCase
10 | import kotlinx.coroutines.launch
11 |
12 |
13 | class NearUserViewModel(application: Application) : AndroidViewModel(application) {
14 |
15 | private val saveUserSessionUseCase = SaveUserSessionUseCase(application)
16 | private val getAllUsersUseCase = GetAllUsersUseCase(application)
17 | private val removeUserSessionUseCase = RemoveUserSessionUseCase(application)
18 |
19 | val getAllUsers: LiveData> = getAllUsersUseCase.getAllUsers().asLiveData()
20 |
21 | /**
22 | * Launching a new coroutine to insert the data in a non-blocking way
23 | */
24 | fun saveUserInformation(userInformation: UserInformation) = viewModelScope.launch {
25 | saveUserSessionUseCase.saveUserSession(userInformation)
26 | }
27 |
28 | fun removeUserInformation() = viewModelScope.launch {
29 | removeUserSessionUseCase.removeUserInformation()
30 | }
31 | }
32 |
33 | class NearUserViewModelFactory(private val mApplication: Application) :
34 | ViewModelProvider.Factory {
35 | override fun create(modelClass: Class): T {
36 | return NearUserViewModel(mApplication) as T
37 | }
38 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | maven { url "https://jitpack.io" }
8 | }
9 | }
10 | rootProject.name = "near-android-sdk"
11 | include ':app'
12 | include ':knear-sdk' // Esto se hace para que cuando se construya el relase en jitpack lo tome el proyecot de la libreria NO REMORVER
--------------------------------------------------------------------------------