diff --git a/HaveAMagicalDay/.gitignore b/HaveAMagicalDay/.gitignore index a595408..214f3c9 100644 --- a/HaveAMagicalDay/.gitignore +++ b/HaveAMagicalDay/.gitignore @@ -13,4 +13,5 @@ .externalNativeBuild .cxx local.properties -*.jar \ No newline at end of file +*.jar +app/bin/* diff --git a/HaveAMagicalDay/app/build.gradle.kts b/HaveAMagicalDay/app/build.gradle.kts index 89d7549..590e176 100644 --- a/HaveAMagicalDay/app/build.gradle.kts +++ b/HaveAMagicalDay/app/build.gradle.kts @@ -4,6 +4,7 @@ import java.util.TimeZone plugins { id("org.jetbrains.kotlin.jvm").version("1.8.10") + id("org.jlleitschuh.gradle.ktlint") version "11.0.0" } dependencies { diff --git a/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/App.kt b/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/App.kt index e9ba043..e5c2a31 100644 --- a/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/App.kt +++ b/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/App.kt @@ -1,42 +1,63 @@ package com.michaeltchuang.cron -import com.algorand.algosdk.account.Account -import com.algorand.algosdk.builder.transaction.PaymentTransactionBuilder -import com.algorand.algosdk.crypto.Address -import com.algorand.algosdk.transaction.SignedTransaction -import com.algorand.algosdk.util.Encoder -import com.algorand.algosdk.v2.client.Utils import com.algorand.algosdk.v2.client.common.AlgodClient -import com.algorand.algosdk.v2.client.model.PendingTransactionResponse -import com.algorand.algosdk.v2.client.model.TransactionParametersResponse import com.michaeltchuang.cron.data.AlgorandRepository import com.michaeltchuang.cron.utils.Constants - +import java.time.LocalDate +import java.time.Period +import java.time.format.DateTimeFormatter +import java.util.TimeZone private val TAG: String = "AlgorandRepository" - private var client: AlgodClient = AlgodClient( - Constants.ALGOD_API_ADDR, - Constants.ALGOD_PORT, - Constants.ALGOD_API_TOKEN, - Constants.ALGOD_API_TOKEN_KEY - ) - - val txHeaders = arrayOf("Content-Type") - val txValues = arrayOf("application/x-binary") - - fun main() { -// Security.removeProvider("BC") -// Security.insertProviderAt(BouncyCastleProvider(), 0) - val repository = AlgorandRepository() - val account = repository.recoverAccount(Constants.TEST_PASSPHRASE) - println() - - if(account == null) { - throw Exception("Could not find account") - } else { - account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT) } +private var client: AlgodClient = AlgodClient( + Constants.ALGOD_API_ADDR, + Constants.ALGOD_PORT, + Constants.ALGOD_API_TOKEN, + Constants.ALGOD_API_TOKEN_KEY +) + +val txHeaders = arrayOf("Content-Type") +val txValues = arrayOf("application/x-binary") + +fun main() { + val repository = AlgorandRepository() + val account = repository.recoverAccount(Constants.TEST_PASSPHRASE) + + if (account == null) { + throw Exception("Could not find account") + } else { + account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, + Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT, getGreeting(false)) } + + //send twice if Mondays - 8th vlog + val tz = TimeZone.getTimeZone("America/Los_Angeles") + if(LocalDate.now(tz.toZoneId()).dayOfWeek.value == 1) { + account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, + Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT, getGreeting(true)) } } } - - - +} + +fun getGreeting(isEighth: Boolean) : String { + var vlogNum = calculateVlogNum(isEighth) + + val note = "Volume 2 Vlog ${vlogNum}, have a magical day everyone! - Michael T Chuang" + println(note) + return note +} + +fun calculateVlogNum(isEighth: Boolean) : Int { + val tz = TimeZone.getTimeZone("America/Los_Angeles") + val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(tz.toZoneId()) + val from = LocalDate.parse("20230220", dateFormatter) + val to = LocalDate.now(tz.toZoneId()) + val period = Period.between(from, to) + val weeks = period.days / 8 + println("${period.days} days is ${weeks} weeks since Feb 21, 2023") + + if(!isEighth) { + return ((weeks * 8) + (period.days % 7)) + } else { + return (weeks * 8) + 8 + } +} diff --git a/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/data/AlgorandRepository.kt b/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/data/AlgorandRepository.kt index be1d982..1fd5616 100644 --- a/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/data/AlgorandRepository.kt +++ b/HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/data/AlgorandRepository.kt @@ -5,17 +5,14 @@ import com.algorand.algosdk.builder.transaction.PaymentTransactionBuilder import com.algorand.algosdk.crypto.Address import com.algorand.algosdk.transaction.SignedTransaction import com.algorand.algosdk.util.Encoder - import com.algorand.algosdk.v2.client.Utils import com.algorand.algosdk.v2.client.common.AlgodClient import com.algorand.algosdk.v2.client.model.PendingTransactionResponse import com.algorand.algosdk.v2.client.model.TransactionParametersResponse import com.michaeltchuang.cron.txHeaders import com.michaeltchuang.cron.txValues - import com.michaeltchuang.cron.utils.Constants - class AlgorandRepository() { private val TAG: String = "AlgorandRepository" private var client: AlgodClient = AlgodClient( @@ -25,7 +22,7 @@ class AlgorandRepository() { Constants.ALGOD_API_TOKEN_KEY ) - fun recoverAccount(passPhrase : String) : Account? { + fun recoverAccount(passPhrase: String): Account? { try { return Account(passPhrase) } catch (e: Exception) { @@ -34,7 +31,7 @@ class AlgorandRepository() { } } - fun sendPayment(account: Account, appId: Long, amount: Int) : PendingTransactionResponse? { + fun sendPayment(account: Account, appId: Long, amount: Int, note: String): PendingTransactionResponse? { try { val respAcct = client.AccountInformation(account.getAddress()).execute() if (!respAcct.isSuccessful) { @@ -48,7 +45,6 @@ class AlgorandRepository() { } val sp: TransactionParametersResponse = resp.body() ?: throw java.lang.Exception("Params retrieval error") - val note = "Have a magical day everyone" // Create a transaction val ptxn = PaymentTransactionBuilder.Builder() @@ -69,9 +65,9 @@ class AlgorandRepository() { // Wait for transaction confirmation val pTrx: PendingTransactionResponse = Utils.waitForConfirmation(client, txnId, 10) - println("${account.address} sent ${amount} microAlgos to ${Address.forApplication(appId)} for transaction ${txnId}") + println("${account.address} sent $amount microAlgos to ${Address.forApplication(appId)} for transaction $txnId") return pTrx - } catch(e: Exception) { + } catch (e: Exception) { println(e.toString()) return null } diff --git a/HaveAMagicalDay/release.config.js b/HaveAMagicalDay/release.config.js index 16d6260..557aa06 100644 --- a/HaveAMagicalDay/release.config.js +++ b/HaveAMagicalDay/release.config.js @@ -7,6 +7,7 @@ module.exports = { { preset: "angular", releaseRules: [ + {type: 'breaking', release: 'major'}, {type: 'feat', release: 'minor'}, {type: 'ci', release: 'patch'}, {type: 'fix', release: 'patch'}, @@ -26,6 +27,11 @@ module.exports = { preset: "conventionalcommits", presetConfig: { types: [ + { + "type": "breaking", + "section": "Breaking", + "hidden": false + }, { "type": "feat", "section": "Features",