Skip to content

Commit

Permalink
Merge pull request #7 from assetMantleOne/avkr003/date
Browse files Browse the repository at this point in the history
Adding Date class RFC3339 standard
  • Loading branch information
avkr003 authored Jan 28, 2022
2 parents 82498a5 + a1e73a8 commit f3ec4f9
Show file tree
Hide file tree
Showing 46 changed files with 263 additions and 217 deletions.
12 changes: 6 additions & 6 deletions .run/explorer.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<map>
<entry key="ASCENDEX_URL" value="https://ascendex.com/api/pro/v1"/>
<entry key="BAND_CHAIN_URL" value="guanyu-devnet.bandchain.org"/>
<entry key="BLOCKCHAIN_ACCOUNT_PREFIX" value="persistence"/>
<entry key="BLOCKCHAIN_RPC_URL" value="https://rpc.testnet.persistence.one"/>
<entry key="BLOCKCHAIN_REST_URL" value="https://rest.testnet.persistence.one"/>
<entry key="CHAIN_ID" value="test-core-1"/>
<entry key="BLOCKCHAIN_ACCOUNT_PREFIX" value="cosmos"/>
<entry key="BLOCKCHAIN_RPC_URL" value="http://127.0.0.1:26657"/>
<entry key="BLOCKCHAIN_REST_URL" value="http://127.0.0.1:1317"/>
<entry key="CHAIN_ID" value="test"/>
<entry key="COINGECKO_URL" value="https://api.coingecko.com/api/v3"/>
<entry key="COMDEX_URL" value="http://localhost:9000"/>
<entry key="DOCU_SIGN_BASE_PATH" value="https://demo.docusign.net/restapi"/>
<entry key="DOCU_SIGN_OAUTH_BASE_PATH" value="https://account-d.docusign.com/oauth/token"/>
<entry key="GENESIS_FILE_PATH" value="$USER_HOME$/go/src/github.com/persistenceOne/genesisTransactions/test-core-1/final_genesis.json"/>
<entry key="GENESIS_FILE_PATH" value="$USER_HOME$/.gaia/config/genesis.json"/>
<entry key="KEY_STORE_FILE_PATH" value="$USER_HOME$/pClientKeyStore"/>
<entry key="KEY_STORE_PASSWORD" value="123123123"/>
<entry key="MAILGUN_PASSWORD" value="dsfkjbsdkjfbksjdbfsbdkjfbsdjkfbkjsdbfkjbsdjkfbkjsdbfs"/>
Expand All @@ -29,7 +29,7 @@
<entry key="POSTGRES_PASSWORD" value="persistence"/>
<entry key="POSTGRES_USER" value="persistence"/>
<entry key="ROOT_FILE_PATH" value="$USER_HOME$/"/>
<entry key="STAKING_DENOM" value="uxprt"/>
<entry key="STAKING_DENOM" value="stake"/>
<entry key="TRULIOO_URL" value="https://api.globalgateway.io"/>
<entry key="WEB_APP_URL" value="http://localhost:9000"/>
</map>
Expand Down
1 change: 1 addition & 0 deletions app/constants/View.scala
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ object View {
val PERIOD_RESET = "PERIOD_RESET"
val ALLOWED_MESSAGES = "ALLOWED_MESSAGES"
val STAKE_AUTHORIZATION_TYPE = "STAKE_AUTHORIZATION_TYPE"
val NO_EXPIRY_DATE = "NO_EXPIRY_DATE"

val AuthzAuthorizationMap: Map[String, String] = Map(
constants.Blockchain.Authz.SEND_AUTHORIZATION -> "SEND_AUTHORIZATION",
Expand Down
5 changes: 3 additions & 2 deletions app/models/Abstract/FeeGrant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package models.Abstract
import models.common.FeeGrant.{AllowedMsgAllowance, BasicAllowance, PeriodicAllowance}
import models.common.Serializable.Coin
import play.api.libs.json.{Json, Writes}
import utilities.Date.RFC3339

object FeeGrant {
abstract class FeeAllowance {
def getExpiration: Option[String]
def getExpiration: Option[RFC3339]

def validate(blockTime: String, fees: Seq[Coin]): (Boolean, FeeAllowance)
def deleteAndUpdate(blockTime: RFC3339, fees: Seq[Coin]): (Boolean, FeeAllowance)
}

implicit val feeAllowanceWrites: Writes[FeeAllowance] = {
Expand Down
9 changes: 5 additions & 4 deletions app/models/blockchain/Authorization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import queries.responses.common.Header
import slick.jdbc.JdbcProfile
import utilities.Date.RFC3339

import java.sql.Timestamp
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

case class Authorization(granter: String, grantee: String, msgTypeURL: String, grantedAuthorization: Authz.Authorization, expiration: String, createdBy: Option[String] = None, createdOn: Option[Timestamp] = None, createdOnTimeZone: Option[String] = None, updatedBy: Option[String] = None, updatedOn: Option[Timestamp] = None, updatedOnTimeZone: Option[String] = None) extends Logged
case class Authorization(granter: String, grantee: String, msgTypeURL: String, grantedAuthorization: Authz.Authorization, expiration: RFC3339, createdBy: Option[String] = None, createdOn: Option[Timestamp] = None, createdOnTimeZone: Option[String] = None, updatedBy: Option[String] = None, updatedOn: Option[Timestamp] = None, updatedOnTimeZone: Option[String] = None) extends Logged

@Singleton
class Authorizations @Inject()(
Expand All @@ -37,10 +38,10 @@ class Authorizations @Inject()(
private[models] val authorizationTable = TableQuery[AuthorizationTable]

case class AuthorizationSerialized(granter: String, grantee: String, msgTypeURL: String, grantedAuthorization: String, expiration: String, createdBy: Option[String], createdOn: Option[Timestamp], createdOnTimeZone: Option[String], updatedBy: Option[String], updatedOn: Option[Timestamp], updatedOnTimeZone: Option[String]) {
def deserialize: Authorization = Authorization(granter = granter, grantee = grantee, msgTypeURL = msgTypeURL, grantedAuthorization = utilities.JSON.convertJsonStringToObject[Authz.Authorization](grantedAuthorization), expiration = expiration, createdBy, createdOn = createdOn, createdOnTimeZone = createdOnTimeZone, updatedBy = updatedBy, updatedOn = updatedOn, updatedOnTimeZone = updatedOnTimeZone)
def deserialize: Authorization = Authorization(granter = granter, grantee = grantee, msgTypeURL = msgTypeURL, grantedAuthorization = utilities.JSON.convertJsonStringToObject[Authz.Authorization](grantedAuthorization), expiration = RFC3339(expiration), createdBy, createdOn = createdOn, createdOnTimeZone = createdOnTimeZone, updatedBy = updatedBy, updatedOn = updatedOn, updatedOnTimeZone = updatedOnTimeZone)
}

def serialize(authorization: Authorization): AuthorizationSerialized = AuthorizationSerialized(granter = authorization.granter, grantee = authorization.grantee, msgTypeURL = authorization.msgTypeURL, grantedAuthorization = Json.toJson(authorization.grantedAuthorization).toString, expiration = authorization.expiration, createdBy = authorization.createdBy, createdOn = authorization.createdOn, createdOnTimeZone = authorization.createdOnTimeZone, updatedBy = authorization.updatedBy, updatedOn = authorization.updatedOn, updatedOnTimeZone = authorization.updatedOnTimeZone)
def serialize(authorization: Authorization): AuthorizationSerialized = AuthorizationSerialized(granter = authorization.granter, grantee = authorization.grantee, msgTypeURL = authorization.msgTypeURL, grantedAuthorization = Json.toJson(authorization.grantedAuthorization).toString, expiration = authorization.expiration.toString, createdBy = authorization.createdBy, createdOn = authorization.createdOn, createdOnTimeZone = authorization.createdOnTimeZone, updatedBy = authorization.updatedBy, updatedOn = authorization.updatedOn, updatedOnTimeZone = authorization.updatedOnTimeZone)

private def add(authorization: Authorization): Future[String] = db.run((authorizationTable returning authorizationTable.map(_.granter) += serialize(authorization)).asTry).map {
case Success(result) => result
Expand Down Expand Up @@ -105,7 +106,7 @@ class Authorizations @Inject()(

object Service {

def create(granter: String, grantee: String, msgTypeURL: String, grantedAuthorization: Authz.Authorization, expiration: String): Future[String] = add(Authorization(granter = granter, grantee = grantee, msgTypeURL = msgTypeURL, grantedAuthorization = grantedAuthorization, expiration = expiration))
def create(granter: String, grantee: String, msgTypeURL: String, grantedAuthorization: Authz.Authorization, expiration: RFC3339): Future[String] = add(Authorization(granter = granter, grantee = grantee, msgTypeURL = msgTypeURL, grantedAuthorization = grantedAuthorization, expiration = expiration))

def tryGet(granter: String, grantee: String, msgTypeURL: String): Future[Authorization] = findByGranterGranteeAndMsgType(granter = granter, grantee = grantee, msgTypeURL = msgTypeURL).map(_.deserialize)

Expand Down
18 changes: 9 additions & 9 deletions app/models/blockchain/Block.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package models.blockchain

import java.sql.Timestamp
import exceptions.BaseException
import javax.inject.{Inject, Singleton}
import models.Trait.Logged
import org.postgresql.util.PSQLException
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import play.api.{Configuration, Logger}
import slick.jdbc.JdbcProfile
import utilities.Date.RFC3339

import java.time.Duration
import java.sql.Timestamp
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

case class Block(height: Int, time: String, proposerAddress: String, validators: Seq[String], createdBy: Option[String] = None, createdOn: Option[Timestamp] = None, createdOnTimeZone: Option[String] = None, updatedBy: Option[String] = None, updatedOn: Option[Timestamp] = None, updatedOnTimeZone: Option[String] = None) extends Logged
case class Block(height: Int, time: RFC3339, proposerAddress: String, validators: Seq[String], createdBy: Option[String] = None, createdOn: Option[Timestamp] = None, createdOnTimeZone: Option[String] = None, updatedBy: Option[String] = None, updatedOn: Option[Timestamp] = None, updatedOnTimeZone: Option[String] = None) extends Logged

@Singleton
class Blocks @Inject()(
Expand All @@ -41,10 +41,10 @@ class Blocks @Inject()(
private[models] val blockTable = TableQuery[BlockTable]

case class BlockSerialized(height: Int, time: String, proposerAddress: String, validators: String, createdBy: Option[String], createdOn: Option[Timestamp], createdOnTimeZone: Option[String], updatedBy: Option[String], updatedOn: Option[Timestamp], updatedOnTimeZone: Option[String]) {
def deserialize: Block = Block(height = height, time = time, proposerAddress = proposerAddress, validators = utilities.JSON.convertJsonStringToObject[Seq[String]](validators), createdBy = createdBy, createdOn = createdOn, createdOnTimeZone = createdOnTimeZone, updatedBy = updatedBy, updatedOn = updatedOn, updatedOnTimeZone = updatedOnTimeZone)
def deserialize: Block = Block(height = height, time = RFC3339(time), proposerAddress = proposerAddress, validators = utilities.JSON.convertJsonStringToObject[Seq[String]](validators), createdBy = createdBy, createdOn = createdOn, createdOnTimeZone = createdOnTimeZone, updatedBy = updatedBy, updatedOn = updatedOn, updatedOnTimeZone = updatedOnTimeZone)
}

def serialize(block: Block): BlockSerialized = BlockSerialized(height = block.height, time = block.time, proposerAddress = block.proposerAddress, validators = Json.toJson(block.validators).toString, createdBy = block.createdBy, createdOn = block.createdOn, createdOnTimeZone = block.createdOnTimeZone, updatedBy = block.updatedBy, updatedOn = block.updatedOn, updatedOnTimeZone = block.updatedOnTimeZone)
def serialize(block: Block): BlockSerialized = BlockSerialized(height = block.height, time = block.time.toString, proposerAddress = block.proposerAddress, validators = Json.toJson(block.validators).toString, createdBy = block.createdBy, createdOn = block.createdOn, createdOnTimeZone = block.createdOnTimeZone, updatedBy = block.updatedBy, updatedOn = block.updatedOn, updatedOnTimeZone = block.updatedOnTimeZone)

private def add(block: Block): Future[String] = db.run((blockTable returning blockTable.map(_.height) += serialize(block)).asTry).map {
case Success(result) => result.toString
Expand Down Expand Up @@ -117,9 +117,9 @@ class Blocks @Inject()(

object Service {

def create(height: Int, time: String, proposerAddress: String, validators: Seq[String]): Future[String] = add(Block(height = height, time = time, proposerAddress = proposerAddress, validators = validators))
def create(height: Int, time: RFC3339, proposerAddress: String, validators: Seq[String]): Future[String] = add(Block(height = height, time = time, proposerAddress = proposerAddress, validators = validators))

def insertOrUpdate(height: Int, time: String, proposerAddress: String, validators: Seq[String]): Future[Int] = upsert(Block(height = height, time = time, proposerAddress = proposerAddress, validators = validators))
def insertOrUpdate(height: Int, time: RFC3339, proposerAddress: String, validators: Seq[String]): Future[Int] = upsert(Block(height = height, time = time, proposerAddress = proposerAddress, validators = validators))

def tryGet(height: Int): Future[Block] = tryGetBlockByHeight(height).map(_.deserialize)

Expand Down Expand Up @@ -164,7 +164,7 @@ class Blocks @Inject()(
(for {
lastBlock <- lastBlock
firstBlock <- getFirstBlock(lastBlock)
} yield utilities.NumericOperation.roundOff(Duration.between(utilities.Date.bcTimestampToZonedDateTime(lastBlock.time), utilities.Date.bcTimestampToZonedDateTime(firstBlock.time)).abs().toSeconds.toDouble / (lastBlock.height - firstBlock.height))
} yield utilities.NumericOperation.roundOff(lastBlock.time.difference(firstBlock.time).abs().toSeconds.toDouble / (lastBlock.height - firstBlock.height))
).recover {
case baseException: BaseException => throw baseException
}
Expand Down
Loading

0 comments on commit f3ec4f9

Please # to comment.